• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Siren Encoder/Decoder library
3  *
4  *   @author: Youness Alaoui <kakaroto@kakaroto.homelinux.net>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21 
22 
23 #ifndef _SIREN_COMMON_H
24 #define _SIREN_COMMON_H
25 
26 typedef struct {
27   unsigned int RiffId;
28   unsigned int RiffSize;
29 } RiffHeader;
30 
31 typedef struct  {
32   unsigned short Format;
33   unsigned short Channels;
34   unsigned int SampleRate;
35   unsigned int ByteRate;
36   unsigned short BlockAlign;
37   unsigned short BitsPerSample;
38 } FmtChunk;
39 
40 
41 typedef struct  {
42   FmtChunk fmt;
43   unsigned short ExtraSize;
44   unsigned short DctLength;
45 } SirenFmtChunk;
46 
47 typedef struct {
48   RiffHeader riff;
49   unsigned int WaveId;
50 
51   unsigned int FmtId;
52   unsigned int FmtSize;
53 
54   SirenFmtChunk fmt;
55 
56   unsigned int FactId;
57   unsigned int FactSize;
58   unsigned int Samples;
59 
60   unsigned int DataId;
61   unsigned int DataSize;
62 } SirenWavHeader;
63 
64 typedef struct {
65   RiffHeader riff;
66   unsigned int WaveId;
67 
68   unsigned int FmtId;
69   unsigned int FmtSize;
70 
71   FmtChunk fmt;
72 
73   unsigned int FactId;
74   unsigned int FactSize;
75   unsigned int Samples;
76 
77   unsigned int DataId;
78   unsigned int DataSize;
79 } PCMWavHeader;
80 
81 #define RIFF_ID 0x46464952
82 #define WAVE_ID 0x45564157
83 #define FMT__ID 0x20746d66
84 #define DATA_ID 0x61746164
85 #define FACT_ID 0x74636166
86 
87 
88 extern int region_size;
89 extern float region_size_inverse;
90 extern float standard_deviation[64];
91 extern float deviation_inverse[64];
92 extern float region_power_table_boundary[63];
93 extern int expected_bits_table[8];
94 extern int vector_dimension[8];
95 extern int number_of_vectors[8];
96 extern float dead_zone[8];
97 extern int max_bin[8];
98 extern float step_size[8];
99 extern float step_size_inverse[8];
100 
101 
102 
103 extern void siren_init(void);
104 extern int categorize_regions(int number_of_regions, int number_of_available_bits, int *absolute_region_power_index, int *power_categories, int *category_balance);
105 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 );
106 
107 
108 #ifdef __BIG_ENDIAN__
109 
110 #define POW_2_8 256
111 #define POW_2_16 65536
112 #define POW_2_24 16777216
113 
114 #define IDX(val, i) ((unsigned int) ((unsigned char *) &val)[i])
115 
116 
117 
118 #define ME_FROM_LE16(val) ( (unsigned short) ( IDX(val, 0) + IDX(val, 1) * 256 ))
119 #define ME_FROM_LE32(val) ( (unsigned int) (IDX(val, 0) + IDX(val, 1) * 256 + \
120           IDX(val, 2) * 65536 + IDX(val, 3) * 16777216))
121 
122 
123 #define ME_TO_LE16(val) ( (unsigned short) (                    \
124           (((unsigned short)val % 256) & 0xff) << 8 |           \
125           ((((unsigned short)val / POW_2_8) % 256) & 0xff) ))
126 
127 #define ME_TO_LE32(val) ( (unsigned int) (                              \
128           ((((unsigned int) val           ) % 256)  & 0xff) << 24 |     \
129           ((((unsigned int) val / POW_2_8 ) % 256) & 0xff) << 16|       \
130           ((((unsigned int) val / POW_2_16) % 256) & 0xff) << 8 |       \
131           ((((unsigned int) val / POW_2_24) % 256) & 0xff) ))
132 
133 #else
134 
135 #define ME_TO_LE16(val) ( (unsigned short) (val))
136 #define ME_TO_LE32(val) ( (unsigned int) (val))
137 #define ME_FROM_LE16(val) ( (unsigned short) (val))
138 #define ME_FROM_LE32(val) ( (unsigned int) (val))
139 
140 
141 #endif
142 
143 
144 
145 #endif /* _SIREN_COMMON_H */
146 
147