forked from len0rd/rockbox
Removed a ton of tabs, fixed some indentation and removed some unneeded includes.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7606 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
6dfe98e196
commit
1290e05641
1 changed files with 52 additions and 54 deletions
|
@ -18,9 +18,7 @@
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "codec.h"
|
#include "codec.h"
|
||||||
#include "playback.h"
|
|
||||||
#include "lib/codeclib.h"
|
#include "lib/codeclib.h"
|
||||||
#include "dsp.h"
|
|
||||||
#include "inttypes.h"
|
#include "inttypes.h"
|
||||||
|
|
||||||
/* This codec support WAVE files with the following formats:
|
/* This codec support WAVE files with the following formats:
|
||||||
|
@ -91,7 +89,7 @@ enum
|
||||||
/* for 44.1kHz stereo 16bits, this represents 0.023s ~= 1/50s */
|
/* for 44.1kHz stereo 16bits, this represents 0.023s ~= 1/50s */
|
||||||
#define WAV_CHUNK_SIZE (1024*2)
|
#define WAV_CHUNK_SIZE (1024*2)
|
||||||
|
|
||||||
#ifndef SIMULATOR
|
#ifdef USE_IRAM
|
||||||
extern char iramcopy[];
|
extern char iramcopy[];
|
||||||
extern char iramstart[];
|
extern char iramstart[];
|
||||||
extern char iramend[];
|
extern char iramend[];
|
||||||
|
@ -224,14 +222,14 @@ enum codec_status codec_start(struct codec_api* api)
|
||||||
uint16_t formattag = 0;
|
uint16_t formattag = 0;
|
||||||
uint16_t blockalign = 0;
|
uint16_t blockalign = 0;
|
||||||
uint32_t avgbytespersec = 0;
|
uint32_t avgbytespersec = 0;
|
||||||
off_t firstblockposn; /* position of the first block in file */
|
off_t firstblockposn; /* position of the first block in file */
|
||||||
int shortorlong = 1; /* do we output shorts (1) or longs (2)? */
|
int shortorlong = 1; /* do we output shorts (1) or longs (2)? */
|
||||||
int32_t * const int32_samples = (int32_t*)int16_samples;
|
int32_t * const int32_samples = (int32_t*)int16_samples;
|
||||||
|
|
||||||
/* Generic codec initialisation */
|
/* Generic codec initialisation */
|
||||||
TEST_CODEC_API(api);
|
TEST_CODEC_API(api);
|
||||||
|
|
||||||
#ifndef SIMULATOR
|
#ifdef USE_IRAM
|
||||||
rb->memcpy(iramstart, iramcopy, iramend-iramstart);
|
rb->memcpy(iramstart, iramcopy, iramend-iramstart);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -244,7 +242,7 @@ enum codec_status codec_start(struct codec_api* api)
|
||||||
next_track:
|
next_track:
|
||||||
|
|
||||||
if (codec_init(api)) {
|
if (codec_init(api)) {
|
||||||
return CODEC_ERROR;
|
return CODEC_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!*rb->taginfo_ready)
|
while (!*rb->taginfo_ready)
|
||||||
|
@ -253,10 +251,10 @@ enum codec_status codec_start(struct codec_api* api)
|
||||||
/* assume the WAV header is less than 1024 bytes */
|
/* assume the WAV header is less than 1024 bytes */
|
||||||
buf=rb->request_buffer(&n,1024);
|
buf=rb->request_buffer(&n,1024);
|
||||||
if (n<44) {
|
if (n<44) {
|
||||||
return CODEC_ERROR;
|
return CODEC_ERROR;
|
||||||
}
|
}
|
||||||
if ((memcmp(buf,"RIFF",4)!=0) || (memcmp(&buf[8],"WAVE",4)!=0)) {
|
if ((memcmp(buf,"RIFF",4)!=0) || (memcmp(&buf[8],"WAVE",4)!=0)) {
|
||||||
return CODEC_ERROR;
|
return CODEC_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf += 12;
|
buf += 12;
|
||||||
|
@ -287,33 +285,33 @@ enum codec_status codec_start(struct codec_api* api)
|
||||||
if (formattag != WAVE_FORMAT_PCM) {
|
if (formattag != WAVE_FORMAT_PCM) {
|
||||||
uint16_t size;
|
uint16_t size;
|
||||||
if (i<18) {
|
if (i<18) {
|
||||||
/* this is not a fatal error with some formats,
|
/* this is not a fatal error with some formats,
|
||||||
* we'll see later if we can't decode it */
|
* we'll see later if we can't decode it */
|
||||||
DEBUGF("CODEC_WARNING: non-PCM WAVE (formattag=0x%x) "
|
DEBUGF("CODEC_WARNING: non-PCM WAVE (formattag=0x%x) "
|
||||||
"doesn't have ext. fmt descr (chunksize=%d<18).\n",
|
"doesn't have ext. fmt descr (chunksize=%d<18).\n",
|
||||||
formattag, i);
|
formattag, i);
|
||||||
}
|
}
|
||||||
size = buf[24]|(buf[25]<<8);
|
size = buf[24]|(buf[25]<<8);
|
||||||
if (formattag == WAVE_FORMAT_DVI_ADPCM) {
|
if (formattag == WAVE_FORMAT_DVI_ADPCM) {
|
||||||
if (size < 2) {
|
if (size < 2) {
|
||||||
DEBUGF("CODEC_ERROR: dvi_adpcm is missing "
|
DEBUGF("CODEC_ERROR: dvi_adpcm is missing "
|
||||||
"SamplesPerBlock value\n");
|
"SamplesPerBlock value\n");
|
||||||
return CODEC_ERROR;
|
return CODEC_ERROR;
|
||||||
}
|
}
|
||||||
samplesperblock = buf[26]|(buf[27]<<8);
|
samplesperblock = buf[26]|(buf[27]<<8);
|
||||||
}
|
}
|
||||||
else if (formattag == WAVE_FORMAT_EXTENSIBLE) {
|
else if (formattag == WAVE_FORMAT_EXTENSIBLE) {
|
||||||
if (size < 22) {
|
if (size < 22) {
|
||||||
DEBUGF("CODEC_ERROR: WAVE_FORMAT_EXTENSIBLE is "
|
DEBUGF("CODEC_ERROR: WAVE_FORMAT_EXTENSIBLE is "
|
||||||
"missing extension\n");
|
"missing extension\n");
|
||||||
return CODEC_ERROR;
|
return CODEC_ERROR;
|
||||||
}
|
}
|
||||||
/* wValidBitsPerSample */
|
/* wValidBitsPerSample */
|
||||||
bitspersample = buf[26]|(buf[27]<<8);
|
bitspersample = buf[26]|(buf[27]<<8);
|
||||||
/* skipping dwChannelMask (4bytes) */
|
/* skipping dwChannelMask (4bytes) */
|
||||||
/* SubFormat (only get the first two bytes) */
|
/* SubFormat (only get the first two bytes) */
|
||||||
formattag = buf[32]|(buf[33]<<8);
|
formattag = buf[32]|(buf[33]<<8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (memcmp(buf,"data",4)==0) {
|
else if (memcmp(buf,"data",4)==0) {
|
||||||
|
@ -328,11 +326,11 @@ enum codec_status codec_start(struct codec_api* api)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DEBUGF("unknown WAVE chunk: '%c%c%c%c', size=%lu\n",
|
DEBUGF("unknown WAVE chunk: '%c%c%c%c', size=%lu\n",
|
||||||
buf[0], buf[1], buf[2], buf[3],i);
|
buf[0], buf[1], buf[2], buf[3],i);
|
||||||
}
|
}
|
||||||
/* go to next chunk (even chunk sizes must be padded) */
|
/* go to next chunk (even chunk sizes must be padded) */
|
||||||
if (i & 0x01)
|
if (i & 0x01)
|
||||||
i++;
|
i++;
|
||||||
buf += i+8;
|
buf += i+8;
|
||||||
if (n < (i+8)) {
|
if (n < (i+8)) {
|
||||||
DEBUGF("CODEC_ERROR: WAVE header size > 1024\n");
|
DEBUGF("CODEC_ERROR: WAVE header size > 1024\n");
|
||||||
|
@ -368,7 +366,7 @@ enum codec_status codec_start(struct codec_api* api)
|
||||||
}
|
}
|
||||||
if (formattag == WAVE_FORMAT_PCM && bitspersample > 32) {
|
if (formattag == WAVE_FORMAT_PCM && bitspersample > 32) {
|
||||||
DEBUGF("CODEC_ERROR: pcm with more than 32 bitspersample "
|
DEBUGF("CODEC_ERROR: pcm with more than 32 bitspersample "
|
||||||
"is unsupported\n");
|
"is unsupported\n");
|
||||||
return CODEC_ERROR;
|
return CODEC_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -396,15 +394,15 @@ enum codec_status codec_start(struct codec_api* api)
|
||||||
|
|
||||||
if (totalsamples == 0) {
|
if (totalsamples == 0) {
|
||||||
if (formattag == WAVE_FORMAT_PCM ||
|
if (formattag == WAVE_FORMAT_PCM ||
|
||||||
formattag == WAVE_FORMAT_ALAW || formattag == WAVE_FORMAT_MULAW ||
|
formattag == WAVE_FORMAT_ALAW || formattag == WAVE_FORMAT_MULAW ||
|
||||||
formattag == IBM_FORMAT_ALAW || formattag == IBM_FORMAT_MULAW) {
|
formattag == IBM_FORMAT_ALAW || formattag == IBM_FORMAT_MULAW) {
|
||||||
/* for PCM and derived formats only */
|
/* for PCM and derived formats only */
|
||||||
bytespersample=(((bitspersample-1)/8+1)*channels);
|
bytespersample=(((bitspersample-1)/8+1)*channels);
|
||||||
totalsamples=numbytes/bytespersample;
|
totalsamples=numbytes/bytespersample;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DEBUGF("CODEC_ERROR: cannot compute totalsamples\n");
|
DEBUGF("CODEC_ERROR: cannot compute totalsamples\n");
|
||||||
return CODEC_ERROR;
|
return CODEC_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -426,7 +424,7 @@ enum codec_status codec_start(struct codec_api* api)
|
||||||
/ (uint64_t)avgbytespersec >= WAV_CHUNK_SIZE) {
|
/ (uint64_t)avgbytespersec >= WAV_CHUNK_SIZE) {
|
||||||
chunksize = ((uint64_t)WAV_CHUNK_SIZE * avgbytespersec
|
chunksize = ((uint64_t)WAV_CHUNK_SIZE * avgbytespersec
|
||||||
/ ((uint64_t)rb->id3->frequency * channels * shortorlong
|
/ ((uint64_t)rb->id3->frequency * channels * shortorlong
|
||||||
* blockalign)) * blockalign;
|
* blockalign)) * blockalign;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!endofstream) {
|
while (!endofstream) {
|
||||||
|
@ -434,32 +432,32 @@ enum codec_status codec_start(struct codec_api* api)
|
||||||
|
|
||||||
rb->yield();
|
rb->yield();
|
||||||
if (rb->stop_codec || rb->reload_codec) {
|
if (rb->stop_codec || rb->reload_codec) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rb->seek_time) {
|
if (rb->seek_time) {
|
||||||
uint32_t newpos;
|
uint32_t newpos;
|
||||||
|
|
||||||
/* use avgbytespersec to round to the closest blockalign multiple,
|
/* use avgbytespersec to round to the closest blockalign multiple,
|
||||||
add firstblockposn. 64-bit casts to avoid overflows. */
|
add firstblockposn. 64-bit casts to avoid overflows. */
|
||||||
newpos = (((uint64_t)avgbytespersec * rb->seek_time)
|
newpos = (((uint64_t)avgbytespersec * rb->seek_time)
|
||||||
/ (1000LL*blockalign)) * blockalign;
|
/ (1000LL*blockalign)) * blockalign;
|
||||||
if (newpos > numbytes)
|
if (newpos > numbytes)
|
||||||
break;
|
break;
|
||||||
if (rb->seek_buffer(firstblockposn + newpos)) {
|
if (rb->seek_buffer(firstblockposn + newpos)) {
|
||||||
bytesdone = newpos;
|
bytesdone = newpos;
|
||||||
}
|
}
|
||||||
rb->seek_time = 0;
|
rb->seek_time = 0;
|
||||||
}
|
}
|
||||||
wavbuf=rb->request_buffer(&n,chunksize);
|
wavbuf=rb->request_buffer(&n,chunksize);
|
||||||
wavbuf8 = (uint8_t*)wavbuf;
|
wavbuf8 = (uint8_t*)wavbuf;
|
||||||
|
|
||||||
if (n==0)
|
if (n==0)
|
||||||
break; /* End of stream */
|
break; /* End of stream */
|
||||||
|
|
||||||
if (bytesdone + n > numbytes) {
|
if (bytesdone + n > numbytes) {
|
||||||
n = numbytes - bytesdone;
|
n = numbytes - bytesdone;
|
||||||
endofstream = 1;
|
endofstream = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
wavbufsize = sizeof(int16_samples);
|
wavbufsize = sizeof(int16_samples);
|
||||||
|
@ -467,15 +465,15 @@ enum codec_status codec_start(struct codec_api* api)
|
||||||
if (formattag == WAVE_FORMAT_PCM) {
|
if (formattag == WAVE_FORMAT_PCM) {
|
||||||
if (bitspersample > 24) {
|
if (bitspersample > 24) {
|
||||||
for (i=0;i<n;i+=4) {
|
for (i=0;i<n;i+=4) {
|
||||||
int32_samples[i/4]=(int32_t)(wavbuf8[i]|(wavbuf8[i+1]<<8)|
|
int32_samples[i/4]=(int32_t)(wavbuf8[i]|(wavbuf8[i+1]<<8)|
|
||||||
(wavbuf8[i+2]<<16)|(wavbuf8[i+3]<<24));
|
(wavbuf8[i+2]<<16)|(wavbuf8[i+3]<<24));
|
||||||
}
|
}
|
||||||
wavbufsize = n;
|
wavbufsize = n;
|
||||||
}
|
}
|
||||||
else if (bitspersample > 16) {
|
else if (bitspersample > 16) {
|
||||||
for (i=0;i<n;i+=3) {
|
for (i=0;i<n;i+=3) {
|
||||||
int32_samples[i/3]=(int32_t)((wavbuf8[i]<<8)|
|
int32_samples[i/3]=(int32_t)((wavbuf8[i]<<8)|
|
||||||
(wavbuf8[i+1]<<16)|(wavbuf8[i+2]<<24));
|
(wavbuf8[i+1]<<16)|(wavbuf8[i+2]<<24));
|
||||||
}
|
}
|
||||||
wavbufsize = n*4/3;
|
wavbufsize = n*4/3;
|
||||||
}
|
}
|
||||||
|
@ -527,7 +525,7 @@ enum codec_status codec_start(struct codec_api* api)
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!rb->pcmbuf_insert((char*)int16_samples, wavbufsize)) {
|
while (!rb->pcmbuf_insert((char*)int16_samples, wavbufsize)) {
|
||||||
rb->yield();
|
rb->yield();
|
||||||
}
|
}
|
||||||
|
|
||||||
rb->advance_buffer(n);
|
rb->advance_buffer(n);
|
||||||
|
@ -540,7 +538,7 @@ enum codec_status codec_start(struct codec_api* api)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rb->request_next_track())
|
if (rb->request_next_track())
|
||||||
goto next_track;
|
goto next_track;
|
||||||
|
|
||||||
return CODEC_OK;
|
return CODEC_OK;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue