2.5: warning fixes
[blender.git] / intern / audaspace / intern / AUD_ConverterReader.cpp
1 /*
2  * $Id$
3  *
4  * ***** BEGIN LGPL LICENSE BLOCK *****
5  *
6  * Copyright 2009 Jörg Hermann Müller
7  *
8  * This file is part of AudaSpace.
9  *
10  * AudaSpace is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * AudaSpace is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with AudaSpace.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  * ***** END LGPL LICENSE BLOCK *****
24  */
25
26 #include "AUD_ConverterReader.h"
27 #include "AUD_Buffer.h"
28
29 AUD_ConverterReader::AUD_ConverterReader(AUD_IReader* reader, AUD_Specs specs) :
30                 AUD_EffectReader(reader)
31 {
32         m_specs = reader->getSpecs();
33
34         int bigendian = 1;
35         bigendian = (((char*)&bigendian)[0]) ? 0: 1; // 1 if Big Endian
36
37         switch(m_specs.format)
38         {
39         case AUD_FORMAT_U8:
40                 switch(specs.format)
41                 {
42                 case AUD_FORMAT_U8:
43                         m_convert = AUD_convert_copy<unsigned char>;
44                         break;
45                 case AUD_FORMAT_S16:
46                         m_convert = AUD_convert_u8_s16;
47                         break;
48                 case AUD_FORMAT_S24:
49                         if(bigendian)
50                                 m_convert = AUD_convert_u8_s24_be;
51                         else
52                                 m_convert = AUD_convert_u8_s24_le;
53                         break;
54                 case AUD_FORMAT_S32:
55                         m_convert = AUD_convert_u8_s32;
56                         break;
57                 case AUD_FORMAT_FLOAT32:
58                         m_convert = AUD_convert_u8_float;
59                         break;
60                 case AUD_FORMAT_FLOAT64:
61                         m_convert = AUD_convert_u8_double;
62                         break;
63                 default:
64                         break;
65                 }
66                 break;
67         case AUD_FORMAT_S16:
68                 switch(specs.format)
69                 {
70                 case AUD_FORMAT_U8:
71                         m_convert = AUD_convert_s16_u8;
72                         break;
73                 case AUD_FORMAT_S16:
74                         m_convert = AUD_convert_copy<int16_t>;
75                         break;
76                 case AUD_FORMAT_S24:
77                         if(bigendian)
78                                 m_convert = AUD_convert_s16_s24_be;
79                         else
80                                 m_convert = AUD_convert_s16_s24_le;
81                         break;
82                 case AUD_FORMAT_S32:
83                         m_convert = AUD_convert_s16_s32;
84                         break;
85                 case AUD_FORMAT_FLOAT32:
86                         m_convert = AUD_convert_s16_float;
87                         break;
88                 case AUD_FORMAT_FLOAT64:
89                         m_convert = AUD_convert_s16_double;
90                         break;
91                 default:
92                         break;
93                 }
94                 break;
95         case AUD_FORMAT_S24:
96                 if(bigendian)
97                         switch(specs.format)
98                         {
99                         case AUD_FORMAT_U8:
100                                 m_convert = AUD_convert_u8_s24_be;
101                                 break;
102                         case AUD_FORMAT_S16:
103                                 m_convert = AUD_convert_s16_s24_be;
104                                 break;
105                         case AUD_FORMAT_S24:
106                                 m_convert = AUD_convert_s24_s24;
107                                 break;
108                         case AUD_FORMAT_S32:
109                                 m_convert = AUD_convert_s32_s24_be;
110                                 break;
111                         case AUD_FORMAT_FLOAT32:
112                                 m_convert = AUD_convert_float_s24_be;
113                                 break;
114                         case AUD_FORMAT_FLOAT64:
115                                 m_convert = AUD_convert_double_s24_be;
116                                 break;
117                         default:
118                                 break;
119                         }
120                 else
121                         switch(specs.format)
122                         {
123                         case AUD_FORMAT_U8:
124                                 m_convert = AUD_convert_u8_s24_le;
125                                 break;
126                         case AUD_FORMAT_S16:
127                                 m_convert = AUD_convert_s16_s24_le;
128                                 break;
129                         case AUD_FORMAT_S24:
130                                 m_convert = AUD_convert_s24_s24;
131                                 break;
132                         case AUD_FORMAT_S32:
133                                 m_convert = AUD_convert_s32_s24_le;
134                                 break;
135                         case AUD_FORMAT_FLOAT32:
136                                 m_convert = AUD_convert_float_s24_le;
137                                 break;
138                         case AUD_FORMAT_FLOAT64:
139                                 m_convert = AUD_convert_double_s24_le;
140                                 break;
141                         default:
142                                 break;
143                         }
144                 break;
145         case AUD_FORMAT_S32:
146                 switch(specs.format)
147                 {
148                 case AUD_FORMAT_U8:
149                         m_convert = AUD_convert_s32_u8;
150                         break;
151                 case AUD_FORMAT_S16:
152                         m_convert = AUD_convert_s32_s16;
153                         break;
154                 case AUD_FORMAT_S24:
155                         if(bigendian)
156                                 m_convert = AUD_convert_s32_s24_be;
157                         else
158                                 m_convert = AUD_convert_s32_s24_le;
159                         break;
160                 case AUD_FORMAT_S32:
161                         m_convert = AUD_convert_copy<int32_t>;
162                         break;
163                 case AUD_FORMAT_FLOAT32:
164                         m_convert = AUD_convert_s32_float;
165                         break;
166                 case AUD_FORMAT_FLOAT64:
167                         m_convert = AUD_convert_s32_double;
168                         break;
169                 default:
170                         break;
171                 }
172                 break;
173         case AUD_FORMAT_FLOAT32:
174                 switch(specs.format)
175                 {
176                 case AUD_FORMAT_U8:
177                         m_convert = AUD_convert_float_u8;
178                         break;
179                 case AUD_FORMAT_S16:
180                         m_convert = AUD_convert_float_s16;
181                         break;
182                 case AUD_FORMAT_S24:
183                         if(bigendian)
184                                 m_convert = AUD_convert_float_s24_be;
185                         else
186                                 m_convert = AUD_convert_float_s24_le;
187                         break;
188                 case AUD_FORMAT_S32:
189                         m_convert = AUD_convert_float_s32;
190                         break;
191                 case AUD_FORMAT_FLOAT32:
192                         m_convert = AUD_convert_copy<float>;
193                         break;
194                 case AUD_FORMAT_FLOAT64:
195                         m_convert = AUD_convert_float_double;
196                         break;
197                 default:
198                         break;
199                 }
200                 break;
201         case AUD_FORMAT_FLOAT64:
202                 switch(specs.format)
203                 {
204                 case AUD_FORMAT_U8:
205                         m_convert = AUD_convert_double_u8;
206                         break;
207                 case AUD_FORMAT_S16:
208                         m_convert = AUD_convert_double_s16;
209                         break;
210                 case AUD_FORMAT_S24:
211                         if(bigendian)
212                                 m_convert = AUD_convert_double_s24_be;
213                         else
214                                 m_convert = AUD_convert_double_s24_le;
215                         break;
216                 case AUD_FORMAT_S32:
217                         m_convert = AUD_convert_double_s32;
218                         break;
219                 case AUD_FORMAT_FLOAT32:
220                         m_convert = AUD_convert_double_float;
221                         break;
222                 case AUD_FORMAT_FLOAT64:
223                         m_convert = AUD_convert_copy<double>;
224                         break;
225                 default:
226                         break;
227                 }
228                 break;
229         default:
230                 break;
231         }
232
233         m_specs.format = specs.format;
234
235         m_buffer = new AUD_Buffer(); AUD_NEW("buffer")
236 }
237
238 AUD_ConverterReader::~AUD_ConverterReader()
239 {
240         delete m_buffer; AUD_DELETE("buffer")
241 }
242
243 AUD_Specs AUD_ConverterReader::getSpecs()
244 {
245         return m_specs;
246 }
247
248 void AUD_ConverterReader::read(int & length, sample_t* & buffer)
249 {
250         m_reader->read(length, buffer);
251
252         int samplesize = AUD_SAMPLE_SIZE(m_specs);
253
254         if(m_buffer->getSize() < length*samplesize)
255                 m_buffer->resize(length*samplesize);
256
257         m_convert(m_buffer->getBuffer(), buffer, length*m_specs.channels);
258
259         buffer = m_buffer->getBuffer();
260 }