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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
/*
* Siren Encoder/Decoder library
*
* @author: Youness Alaoui <kakaroto@kakaroto.homelinux.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef _SIREN_COMMON_H
#define _SIREN_COMMON_H
typedef struct {
unsigned int RiffId;
unsigned int RiffSize;
} RiffHeader;
typedef struct {
unsigned short Format;
unsigned short Channels;
unsigned int SampleRate;
unsigned int ByteRate;
unsigned short BlockAlign;
unsigned short BitsPerSample;
} FmtChunk;
typedef struct {
FmtChunk fmt;
unsigned short ExtraSize;
unsigned short DctLength;
} SirenFmtChunk;
typedef struct {
RiffHeader riff;
unsigned int WaveId;
unsigned int FmtId;
unsigned int FmtSize;
SirenFmtChunk fmt;
unsigned int FactId;
unsigned int FactSize;
unsigned int Samples;
unsigned int DataId;
unsigned int DataSize;
} SirenWavHeader;
typedef struct {
RiffHeader riff;
unsigned int WaveId;
unsigned int FmtId;
unsigned int FmtSize;
FmtChunk fmt;
unsigned int FactId;
unsigned int FactSize;
unsigned int Samples;
unsigned int DataId;
unsigned int DataSize;
} PCMWavHeader;
#define RIFF_ID 0x46464952
#define WAVE_ID 0x45564157
#define FMT__ID 0x20746d66
#define DATA_ID 0x61746164
#define FACT_ID 0x74636166
extern int region_size;
extern float region_size_inverse;
extern float standard_deviation[64];
extern float deviation_inverse[64];
extern float region_power_table_boundary[63];
extern int expected_bits_table[8];
extern int vector_dimension[8];
extern int number_of_vectors[8];
extern float dead_zone[8];
extern int max_bin[8];
extern float step_size[8];
extern float step_size_inverse[8];
extern void siren_init(void);
extern int categorize_regions(int number_of_regions, int number_of_available_bits, int *absolute_region_power_index, int *power_categories, int *category_balance);
extern int GetSirenCodecInfo(int flag, int sample_rate, int *number_of_coefs, int *sample_rate_bits, int *rate_control_bits, int *rate_control_possibilities, int *checksum_bits, int *esf_adjustment, int *scale_factor, int *number_of_regions, int *sample_rate_code, int *bits_per_frame );
#ifdef __BIG_ENDIAN__
#define POW_2_8 256
#define POW_2_16 65536
#define POW_2_24 16777216
#define IDX(val, i) ((unsigned int) ((unsigned char *) &val)[i])
#define ME_FROM_LE16(val) ( (unsigned short) ( IDX(val, 0) + IDX(val, 1) * 256 ))
#define ME_FROM_LE32(val) ( (unsigned int) (IDX(val, 0) + IDX(val, 1) * 256 + \
IDX(val, 2) * 65536 + IDX(val, 3) * 16777216))
#define ME_TO_LE16(val) ( (unsigned short) ( \
(((unsigned short)val % 256) & 0xff) << 8 | \
((((unsigned short)val / POW_2_8) % 256) & 0xff) ))
#define ME_TO_LE32(val) ( (unsigned int) ( \
((((unsigned int) val ) % 256) & 0xff) << 24 | \
((((unsigned int) val / POW_2_8 ) % 256) & 0xff) << 16| \
((((unsigned int) val / POW_2_16) % 256) & 0xff) << 8 | \
((((unsigned int) val / POW_2_24) % 256) & 0xff) ))
#else
#define ME_TO_LE16(val) ( (unsigned short) (val))
#define ME_TO_LE32(val) ( (unsigned int) (val))
#define ME_FROM_LE16(val) ( (unsigned short) (val))
#define ME_FROM_LE32(val) ( (unsigned int) (val))
#endif
#endif /* _SIREN_COMMON_H */
|