File: vbap.h

package info (click to toggle)
python-pyo 1.0.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,332 kB
  • sloc: python: 135,133; ansic: 127,822; javascript: 16,116; sh: 395; makefile: 388; cpp: 242
file content (124 lines) | stat: -rw-r--r-- 3,681 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
 * Functions for 3D VBAP processing based on work by Ville Pulkki.
 * (c) Ville Pulkki - 2.2.1999 Helsinki University of Technology.
 * Updated by belangeo, 2017.
 */

#ifndef __VBAP_H
#define __VBAP_H

#ifdef __cplusplus
extern "C" {
#endif

#define MAX_LS_AMOUNT 256
#define MAX_TRIPLET_AMOUNT 128
#define MIN_VOL_P_SIDE_LGTH 0.01

typedef struct
{
    int dimension;      /* Number of dimension, always 3. */
    int count;          /* Number of speakers. */
    float *azimuth;     /* Azimuth angle of speakers. */
    float *elevation;   /* Elevation angle of speakers. */
} SPEAKERS_SETUP;

/* Cartesian vector for a speaker position. */
typedef struct
{
    float x;
    float y;
    float z;
} CART_VEC;

/* Angular vector for a speaker position. */
typedef struct
{
    float azi;
    float ele;
    float length;
} ANG_VEC;

/* A struct for a loudspeaker triplet or pair (set). */
typedef struct
{
    int ls_nos[3];
    float inv_mx[9];
    float set_gains[3];
    float smallest_wt;
    int neg_g_am;
} LS_SET;

/* A struct for a loudspeaker instance. */
typedef struct
{
    CART_VEC coords;
    ANG_VEC angles;
} ls; // TODO: rename this struct.

/* VBAP structure of n loudspeaker panning */
typedef struct
{
    int out_patches[MAX_LS_AMOUNT];     /* Physical outputs (starts at 1). */
    float gains[MAX_LS_AMOUNT];         /* Loudspeaker gains. */
    float y[MAX_LS_AMOUNT];             /* Loudspeaker gains smoothing. */
    int dimension;                      /* Dimensions, 2 or 3. */
    LS_SET *ls_sets;                    /* Loudspeaker triplet structure. */
    int ls_out;                         /* Number of output patches. */
    int ls_am;                          /* Number of loudspeakers. */
    int ls_set_am;                      /* Number of triplets. */
    ANG_VEC ang_dir;                    /* Angular direction. */
    CART_VEC cart_dir;                  /* Cartesian direction. */
    CART_VEC spread_base;               /* Spreading vector. */
} VBAP_DATA;

/* Fill a SPEAKERS_SETUP structure from values.
 */
SPEAKERS_SETUP * load_speakers_setup(int cnt, float *azi, float *ele);

/* Fill a SPEAKERS_SETUP structure from the content of a text file.
 *
 * File format:
 *
 * First line starts with an integer which is the number of speakers.
 * Remaining lines (must be equal to the number of speakers) starts with
 * two floats. They give the azimuth and elevation for each speakers.
 */
SPEAKERS_SETUP * load_speakers_setup_from_file(const char *filename);

/* Properly free a previously allocated SPEAKERS_SETUP structure.
 */
void free_speakers_setup(SPEAKERS_SETUP *setup);

/* Initialize a VBAP_DATA structure from a loudspeakers setup and
 * an optional matrix of user-defined triplets.
 */
VBAP_DATA * init_vbap_data(SPEAKERS_SETUP *setup, int **triplets);

VBAP_DATA * init_vbap_from_speakers(ls *lss, int count,
                                    int dim, int *outputPatches,
                                    int maxOutputPatch, int **triplets);

VBAP_DATA * copy_vbap_data(VBAP_DATA *data);

/* Properly free a previously allocated VBAP_DATA structure.
 */
void free_vbap_data(VBAP_DATA *data);

/* Calculates gain factors using loudspeaker setup and angle direction.
 */
void vbap(float azi, float ele, float spread, VBAP_DATA *data);
void vbap2(float azi, float ele, float sp_azi,
           float sp_ele, VBAP_DATA *data);
void vbap_flip_y_z(float azi, float ele, float spread, VBAP_DATA *data);
void vbap2_flip_y_z(float azi, float ele, float sp_azi,
                    float sp_ele, VBAP_DATA *data);

int vbap_get_triplets(VBAP_DATA *data, int ***triplets);

#ifdef __cplusplus
}
#endif

#endif /* __VBAP_H */