1
0
Fork 0
forked from len0rd/rockbox

stop the compiler bitching

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@725 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Robert Hak 2002-05-27 08:08:54 +00:00
parent b395c145bd
commit ece50cd3a5
2 changed files with 128 additions and 137 deletions

View file

@ -119,17 +119,15 @@ signed int dither(mad_fixed_t sample, struct dither *dither)
#define INPUT_BUFFER_SIZE (5*8192) #define INPUT_BUFFER_SIZE (5*8192)
#define OUTPUT_BUFFER_SIZE 8192 /* Must be an integer multiple of 4. */ #define OUTPUT_BUFFER_SIZE 8192 /* Must be an integer multiple of 4. */
int mpeg_play(char* fname) void mpeg_play(char* fname)
{ {
unsigned char InputBuffer[INPUT_BUFFER_SIZE], unsigned char InputBuffer[INPUT_BUFFER_SIZE],
OutputBuffer[OUTPUT_BUFFER_SIZE], OutputBuffer[OUTPUT_BUFFER_SIZE],
*OutputPtr=OutputBuffer; *OutputPtr=OutputBuffer;
const unsigned char *OutputBufferEnd=OutputBuffer+OUTPUT_BUFFER_SIZE; const unsigned char *OutputBufferEnd=OutputBuffer+OUTPUT_BUFFER_SIZE;
int Status=0, int Status=0, i, fd;
i;
unsigned long FrameCount=0; unsigned long FrameCount=0;
sound_t sound; sound_t sound;
int fd;
mp3entry mp3; mp3entry mp3;
register signed int s0, s1; register signed int s0, s1;
static struct dither d0, d1; static struct dither d0, d1;
@ -142,10 +140,9 @@ int mpeg_play(char* fname)
some sound cards don't support mono */ some sound cards don't support mono */
config_sound(&sound,mp3.frequency,2); config_sound(&sound,mp3.frequency,2);
fd=open(fname,O_RDONLY); if ((fd=open(fname,O_RDONLY)) < 0) {
if (fd < 0) {
fprintf(stderr,"could not open %s\n",fname); fprintf(stderr,"could not open %s\n",fname);
return 0; return;
} }
/* First the structures used by libmad must be initialized. */ /* First the structures used by libmad must be initialized. */
@ -154,30 +151,26 @@ int mpeg_play(char* fname)
mad_synth_init(&Synth); mad_synth_init(&Synth);
mad_timer_reset(&Timer); mad_timer_reset(&Timer);
do do {
{ if (button_get())
if (button_get()) break; /* Return if a key is pressed */ break;
if(Stream.buffer==NULL || Stream.error==MAD_ERROR_BUFLEN) if (Stream.buffer==NULL || Stream.error==MAD_ERROR_BUFLEN) {
{
size_t ReadSize,Remaining; size_t ReadSize,Remaining;
unsigned char *ReadStart; unsigned char *ReadStart;
if(Stream.next_frame!=NULL) if(Stream.next_frame!=NULL) {
{
Remaining=Stream.bufend-Stream.next_frame; Remaining=Stream.bufend-Stream.next_frame;
memmove(InputBuffer,Stream.next_frame,Remaining); memmove(InputBuffer,Stream.next_frame,Remaining);
ReadStart=InputBuffer+Remaining; ReadStart=InputBuffer+Remaining;
ReadSize=INPUT_BUFFER_SIZE-Remaining; ReadSize=INPUT_BUFFER_SIZE-Remaining;
} } else {
else
ReadSize=INPUT_BUFFER_SIZE, ReadSize=INPUT_BUFFER_SIZE,
ReadStart=InputBuffer, ReadStart=InputBuffer,
Remaining=0; Remaining=0;
}
ReadSize=read(fd,ReadStart,ReadSize); if ((ReadSize=read(fd,ReadStart,ReadSize)) < 0) {
if(ReadSize<=0)
{
fprintf(stderr,"end of input stream\n"); fprintf(stderr,"end of input stream\n");
break; break;
} }
@ -187,13 +180,11 @@ int mpeg_play(char* fname)
} }
if(mad_frame_decode(&Frame,&Stream)) { if(mad_frame_decode(&Frame,&Stream)) {
if(MAD_RECOVERABLE(Stream.error)) if(MAD_RECOVERABLE(Stream.error)) {
{
fprintf(stderr,"recoverable frame level error\n"); fprintf(stderr,"recoverable frame level error\n");
fflush(stderr); fflush(stderr);
continue; continue;
} } else {
else
if(Stream.error==MAD_ERROR_BUFLEN) { if(Stream.error==MAD_ERROR_BUFLEN) {
continue; continue;
} else { } else {
@ -202,14 +193,14 @@ int mpeg_play(char* fname)
break; break;
} }
} }
}
FrameCount++; FrameCount++;
mad_timer_add(&Timer,Frame.header.duration); mad_timer_add(&Timer,Frame.header.duration);
mad_synth_frame(&Synth,&Frame); mad_synth_frame(&Synth,&Frame);
for(i=0;i<Synth.pcm.length;i++) for(i=0;i<Synth.pcm.length;i++) {
{
unsigned short Sample; unsigned short Sample;
/* Left channel */ /* Left channel */
@ -220,16 +211,17 @@ int mpeg_play(char* fname)
/* Right channel. If the decoded stream is monophonic then /* Right channel. If the decoded stream is monophonic then
* the right output channel is the same as the left one. * the right output channel is the same as the left one.
*/ */
if(MAD_NCHANNELS(&Frame.header)==2) if(MAD_NCHANNELS(&Frame.header)==2) {
Sample=scale(Synth.pcm.samples[1][i],&d1); Sample=scale(Synth.pcm.samples[1][i],&d1);
}
*(OutputPtr++)=Sample&0xff; *(OutputPtr++)=Sample&0xff;
*(OutputPtr++)=Sample>>8; *(OutputPtr++)=Sample>>8;
/* Flush the buffer if it is full. */ /* Flush the buffer if it is full. */
if(OutputPtr==OutputBufferEnd) if (OutputPtr==OutputBufferEnd) {
{ if (output_sound(&sound, OutputBuffer,
if(output_sound(&sound,OutputBuffer,OUTPUT_BUFFER_SIZE)!=OUTPUT_BUFFER_SIZE) OUTPUT_BUFFER_SIZE)!=OUTPUT_BUFFER_SIZE) {
{
fprintf(stderr,"PCM write error.\n"); fprintf(stderr,"PCM write error.\n");
Status=2; Status=2;
break; break;
@ -247,8 +239,7 @@ int mpeg_play(char* fname)
mad_stream_finish(&Stream); mad_stream_finish(&Stream);
/* If the output buffer is not empty and no error occured during /* If the output buffer is not empty and no error occured during
* the last write, then flush it. * the last write, then flush it. */
*/
if(OutputPtr!=OutputBuffer && Status!=2) if(OutputPtr!=OutputBuffer && Status!=2)
{ {
size_t BufferSize=OutputPtr-OutputBuffer; size_t BufferSize=OutputPtr-OutputBuffer;
@ -272,7 +263,7 @@ int mpeg_play(char* fname)
close_sound(&sound); close_sound(&sound);
/* That's the end of the world (in the H. G. Wells way). */ /* That's the end of the world (in the H. G. Wells way). */
return(Status); return;
} }

View file

@ -18,6 +18,6 @@
#ifdef MPEG_PLAY #ifdef MPEG_PLAY
int mpeg_play(char* fname); void mpeg_play(char* fname);
#endif #endif