summaryrefslogtreecommitdiff
path: root/apps/codecs
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2006-02-01 17:58:10 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2006-02-01 17:58:10 +0000
commitf5f000fe03d6fe5f4ac85a8796e31463174d3077 (patch)
tree79e409f232b100b9edb650fdb93107196417b244 /apps/codecs
parentfbd8e5d29c34c3c389ee32b5fedb613716985545 (diff)
downloadrockbox-f5f000fe03d6fe5f4ac85a8796e31463174d3077.tar.gz
rockbox-f5f000fe03d6fe5f4ac85a8796e31463174d3077.zip
Minor code policing
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8525 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs')
-rw-r--r--apps/codecs/aiff.c69
1 files changed, 34 insertions, 35 deletions
diff --git a/apps/codecs/aiff.c b/apps/codecs/aiff.c
index 091e621bb7..764655f776 100644
--- a/apps/codecs/aiff.c
+++ b/apps/codecs/aiff.c
@@ -56,10 +56,10 @@ enum codec_status codec_start(struct codec_api* api)
56{ 56{
57 struct codec_api* ci; 57 struct codec_api* ci;
58 uint32_t numbytes, bytesdone; 58 uint32_t numbytes, bytesdone;
59 uint16_t numChannels = 0; 59 uint16_t num_channels = 0;
60 uint32_t numSampleFrames = 0; 60 uint32_t num_sample_frames = 0;
61 uint16_t sampleSize = 0; 61 uint16_t sample_size = 0;
62 uint32_t sampleRate = 0; 62 uint32_t sample_rate = 0;
63 uint32_t i; 63 uint32_t i;
64 size_t n, aifbufsize; 64 size_t n, aifbufsize;
65 int endofstream; 65 int endofstream;
@@ -67,7 +67,7 @@ enum codec_status codec_start(struct codec_api* api)
67 uint16_t* aifbuf; 67 uint16_t* aifbuf;
68 long chunksize; 68 long chunksize;
69 uint32_t offset2snd = 0; 69 uint32_t offset2snd = 0;
70 uint16_t blockSize = 0; 70 uint16_t block_size = 0;
71 uint32_t avgbytespersec = 0; 71 uint32_t avgbytespersec = 0;
72 off_t firstblockposn; /* position of the first block in file */ 72 off_t firstblockposn; /* position of the first block in file */
73 int shortorlong = 1; /* do we output shorts (1) or longs (2)? */ 73 int shortorlong = 1; /* do we output shorts (1) or longs (2)? */
@@ -122,35 +122,35 @@ enum codec_status codec_start(struct codec_api* api)
122 i = CODEC_ERROR; 122 i = CODEC_ERROR;
123 goto exit; 123 goto exit;
124 } 124 }
125 /* numChannels */ 125 /* num_channels */
126 numChannels = ((buf[8]<<8)|buf[9]); 126 num_channels = ((buf[8]<<8)|buf[9]);
127 /* numSampleFrames */ 127 /* num_sample_frames */
128 numSampleFrames = ((buf[10]<<24)|(buf[11]<<16)|(buf[12]<<8)|buf[13]); 128 num_sample_frames = ((buf[10]<<24)|(buf[11]<<16)|(buf[12]<<8)|buf[13]);
129 /* sampleSize */ 129 /* sample_size */
130 sampleSize = ((buf[14]<<8)|buf[15]); 130 sample_size = ((buf[14]<<8)|buf[15]);
131 /* sampleRate (don't use last 4 bytes, only integer fs) */ 131 /* sample_rate (don't use last 4 bytes, only integer fs) */
132 if (buf[16] != 0x40) { 132 if (buf[16] != 0x40) {
133 DEBUGF("CODEC_ERROR: wierd sampling rate (no @)\n",i); 133 DEBUGF("CODEC_ERROR: wierd sampling rate (no @)\n",i);
134 i = CODEC_ERROR; 134 i = CODEC_ERROR;
135 goto exit; 135 goto exit;
136 } 136 }
137 sampleRate = ((buf[18]<<24)|(buf[19]<<16)|(buf[20]<<8)|buf[21])+1; 137 sample_rate = ((buf[18]<<24)|(buf[19]<<16)|(buf[20]<<8)|buf[21])+1;
138 sampleRate = sampleRate >> (16+14-buf[17]); 138 sample_rate = sample_rate >> (16+14-buf[17]);
139 /* calc average bytes per second */ 139 /* calc average bytes per second */
140 avgbytespersec = sampleRate*numChannels*sampleSize/8; 140 avgbytespersec = sample_rate*num_channels*sample_size/8;
141 } 141 }
142 else if (memcmp(buf,"SSND",4)==0) { 142 else if (memcmp(buf,"SSND",4)==0) {
143 if (sampleSize == 0) { 143 if (sample_size == 0) {
144 DEBUGF("CODEC_ERROR: unsupported chunk order\n"); 144 DEBUGF("CODEC_ERROR: unsupported chunk order\n");
145 i = CODEC_ERROR; 145 i = CODEC_ERROR;
146 goto exit; 146 goto exit;
147 } 147 }
148 /* offset2snd */ 148 /* offset2snd */
149 offset2snd = ((buf[8]<<8)|buf[9]); 149 offset2snd = ((buf[8]<<8)|buf[9]);
150 /* blockSize */ 150 /* block_size */
151 blockSize = ((buf[10]<<8)|buf[11]); 151 block_size = ((buf[10]<<8)|buf[11]);
152 if (blockSize == 0) 152 if (block_size == 0)
153 blockSize = numChannels*sampleSize; 153 block_size = num_channels*sample_size;
154 numbytes = i-8-offset2snd; 154 numbytes = i-8-offset2snd;
155 i = 8+offset2snd; /* advance to the beginning of data */ 155 i = 8+offset2snd; /* advance to the beginning of data */
156 } 156 }
@@ -170,7 +170,7 @@ enum codec_status codec_start(struct codec_api* api)
170 n -= i+8; 170 n -= i+8;
171 } /* while 'SSND' */ 171 } /* while 'SSND' */
172 172
173 if (numChannels == 0) { 173 if (num_channels == 0) {
174 DEBUGF("CODEC_ERROR: 'COMM' chunk not found or 0-channels file\n"); 174 DEBUGF("CODEC_ERROR: 'COMM' chunk not found or 0-channels file\n");
175 i = CODEC_ERROR; 175 i = CODEC_ERROR;
176 goto exit; 176 goto exit;
@@ -180,7 +180,7 @@ enum codec_status codec_start(struct codec_api* api)
180 i = CODEC_ERROR; 180 i = CODEC_ERROR;
181 goto exit; 181 goto exit;
182 } 182 }
183 if (sampleSize > 24) { 183 if (sample_size > 24) {
184 DEBUGF("CODEC_ERROR: PCM with more than 24 bits per sample " 184 DEBUGF("CODEC_ERROR: PCM with more than 24 bits per sample "
185 "is unsupported\n"); 185 "is unsupported\n");
186 i = CODEC_ERROR; 186 i = CODEC_ERROR;
@@ -190,7 +190,7 @@ enum codec_status codec_start(struct codec_api* api)
190 ci->configure(CODEC_DSP_ENABLE, (bool *)true); 190 ci->configure(CODEC_DSP_ENABLE, (bool *)true);
191 ci->configure(DSP_SET_FREQUENCY, (long *)(ci->id3->frequency)); 191 ci->configure(DSP_SET_FREQUENCY, (long *)(ci->id3->frequency));
192 192
193 if (sampleSize <= 16) { 193 if (sample_size <= 16) {
194 ci->configure(DSP_SET_SAMPLE_DEPTH, (int *)(16)); 194 ci->configure(DSP_SET_SAMPLE_DEPTH, (int *)(16));
195 } else { 195 } else {
196 shortorlong = 2; 196 shortorlong = 2;
@@ -200,9 +200,9 @@ enum codec_status codec_start(struct codec_api* api)
200 ci->configure(DSP_SET_CLIP_MIN, (long *) (-2147483647-1)); 200 ci->configure(DSP_SET_CLIP_MIN, (long *) (-2147483647-1));
201 } 201 }
202 202
203 if (numChannels == 2) { 203 if (num_channels == 2) {
204 ci->configure(DSP_SET_STEREO_MODE, (int *)STEREO_INTERLEAVED); 204 ci->configure(DSP_SET_STEREO_MODE, (int *)STEREO_INTERLEAVED);
205 } else if (numChannels == 1) { 205 } else if (num_channels == 1) {
206 ci->configure(DSP_SET_STEREO_MODE, (int *)STEREO_MONO); 206 ci->configure(DSP_SET_STEREO_MODE, (int *)STEREO_MONO);
207 } else { 207 } else {
208 DEBUGF("CODEC_ERROR: more than 2 channels unsupported\n"); 208 DEBUGF("CODEC_ERROR: more than 2 channels unsupported\n");
@@ -221,14 +221,14 @@ enum codec_status codec_start(struct codec_api* api)
221 /* chunksize is computed so that one chunk is about 1/50s. 221 /* chunksize is computed so that one chunk is about 1/50s.
222 * this make 4096 for 44.1kHz 16bits stereo. 222 * this make 4096 for 44.1kHz 16bits stereo.
223 * It also has to be a multiple of blockalign */ 223 * It also has to be a multiple of blockalign */
224 chunksize = (1 + avgbytespersec / (50*blockSize)) * blockSize; 224 chunksize = (1 + avgbytespersec / (50*block_size)) * block_size;
225 /* check that the output buffer is big enough (convert to samplespersec, 225 /* check that the output buffer is big enough (convert to samplespersec,
226 then round to the blockSize multiple below) */ 226 then round to the block_size multiple below) */
227 if (((uint64_t)chunksize*ci->id3->frequency*numChannels*shortorlong) 227 if (((uint64_t)chunksize*ci->id3->frequency*num_channels*shortorlong)
228 / (uint64_t)avgbytespersec >= AIF_CHUNK_SIZE) { 228 / (uint64_t)avgbytespersec >= AIF_CHUNK_SIZE) {
229 chunksize = ((uint64_t)AIF_CHUNK_SIZE * avgbytespersec 229 chunksize = ((uint64_t)AIF_CHUNK_SIZE * avgbytespersec
230 / ((uint64_t)ci->id3->frequency * numChannels * shortorlong 230 / ((uint64_t)ci->id3->frequency * num_channels * shortorlong
231 * blockSize)) * blockSize; 231 * block_size)) * block_size;
232 } 232 }
233 233
234 while (!endofstream) { 234 while (!endofstream) {
@@ -245,7 +245,7 @@ enum codec_status codec_start(struct codec_api* api)
245 /* use avgbytespersec to round to the closest blockalign multiple, 245 /* use avgbytespersec to round to the closest blockalign multiple,
246 add firstblockposn. 64-bit casts to avoid overflows. */ 246 add firstblockposn. 64-bit casts to avoid overflows. */
247 newpos = (((uint64_t)avgbytespersec * (ci->seek_time - 1)) 247 newpos = (((uint64_t)avgbytespersec * (ci->seek_time - 1))
248 / (1000LL*blockSize)) * blockSize; 248 / (1000LL*block_size)) * block_size;
249 if (newpos > numbytes) 249 if (newpos > numbytes)
250 break; 250 break;
251 if (ci->seek_buffer(firstblockposn + newpos)) { 251 if (ci->seek_buffer(firstblockposn + newpos)) {
@@ -266,19 +266,19 @@ enum codec_status codec_start(struct codec_api* api)
266 266
267 aifbufsize = sizeof(int16_samples); 267 aifbufsize = sizeof(int16_samples);
268 268
269 if (sampleSize > 24) { 269 if (sample_size > 24) {
270 for (i=0;i<n;i+=4) { 270 for (i=0;i<n;i+=4) {
271 int32_samples[i/4]=(int32_t)((aifbuf8[i]<<24)| 271 int32_samples[i/4]=(int32_t)((aifbuf8[i]<<24)|
272 (aifbuf8[i+1]<<16)|(aifbuf8[i+2]<<8)|aifbuf8[i+3]); 272 (aifbuf8[i+1]<<16)|(aifbuf8[i+2]<<8)|aifbuf8[i+3]);
273 } 273 }
274 aifbufsize = n; 274 aifbufsize = n;
275 } else if (sampleSize > 16) { 275 } else if (sample_size > 16) {
276 for (i=0;i<n;i+=3) { 276 for (i=0;i<n;i+=3) {
277 int32_samples[i/3]=(int32_t)((aifbuf8[i]<<24)| 277 int32_samples[i/3]=(int32_t)((aifbuf8[i]<<24)|
278 (aifbuf8[i+1]<<16)|(aifbuf8[i+2]<<8)); 278 (aifbuf8[i+1]<<16)|(aifbuf8[i+2]<<8));
279 } 279 }
280 aifbufsize = n*4/3; 280 aifbufsize = n*4/3;
281 } else if (sampleSize > 8) { 281 } else if (sample_size > 8) {
282 /* copy data. */ 282 /* copy data. */
283 for (i=0;i<n;i+=2) { 283 for (i=0;i<n;i+=2) {
284 int16_samples[i/2]=(int16_t)((aifbuf8[i]<<8)|aifbuf8[i+1]); 284 int16_samples[i/2]=(int16_t)((aifbuf8[i]<<8)|aifbuf8[i+1]);
@@ -311,4 +311,3 @@ enum codec_status codec_start(struct codec_api* api)
311exit: 311exit:
312 return i; 312 return i;
313} 313}
314