git-svn-id: https://svn.musicpd.org/mpd/trunk@194 09075e82-0dd4-0310-85a5-a0d7c8717e4f

This commit is contained in:
Warren Dukes 2004-03-04 20:45:49 +00:00
parent 0d22fa6e64
commit 4893e94dae
2 changed files with 23 additions and 11 deletions

View File

@ -38,6 +38,7 @@
#define READ_BUFFER_SIZE 40960
#define DECODE_SKIP -3
#define DECODE_BREAK -2
#define DECODE_CONT -1
#define DECODE_OK 0
@ -180,6 +181,7 @@ int decodeNextFrameHeader(mp3DecodeData * data) {
}
}
if(mad_header_decode(&data->frame.header,&data->stream)) {
if((data->stream).error==MAD_ERROR_LOSTSYNC) return DECODE_SKIP;
if(MAD_RECOVERABLE((data->stream).error)) return DECODE_CONT;
else {
if((data->stream).error==MAD_ERROR_BUFLEN) return DECODE_CONT;
@ -204,6 +206,7 @@ int decodeNextFrame(mp3DecodeData * data) {
}
}
if(mad_frame_decode(&data->frame,&data->stream)) {
if((data->stream).error==MAD_ERROR_LOSTSYNC) return DECODE_SKIP;
if(MAD_RECOVERABLE((data->stream).error)) return DECODE_CONT;
else {
if((data->stream).error==MAD_ERROR_BUFLEN) return DECODE_CONT;
@ -282,14 +285,23 @@ int decodeFirstFrame(mp3DecodeData * data) {
struct stat filestat;
struct xing xing;
int ret;
int skip;
memset(&xing,0,sizeof(struct xing));
xing.flags = 0;
while((ret = decodeNextFrameHeader(data))==DECODE_CONT);
if(ret!=DECODE_OK) return -1;
while((ret = decodeNextFrame(data))==DECODE_CONT);
if(ret!=DECODE_OK) return -1;
skip = 0;
while(1) {
printf("HERE 1\n");
while((ret = decodeNextFrameHeader(data))==DECODE_CONT);
if(ret==DECODE_SKIP) skip = 1;
if(ret==DECODE_BREAK) return -1;
while((ret = decodeNextFrame(data))==DECODE_CONT);
if(ret==DECODE_BREAK) return -1;
if(ret==DECODE_SKIP) skip = 1;
else if(skip && ret==DECODE_OK) skip = 0;
else if(!skip && ret==DECODE_OK) break;
}
if(parse_xing(&xing,data->stream.anc_ptr,data->stream.anc_bitlen)) {
if(xing.flags & XING_FRAMES) {
@ -464,9 +476,11 @@ int mp3Read(mp3DecodeData * data, Buffer * cb, DecoderControl * dc) {
}
if(data->muteFrame) {
while((ret=decodeNextFrameHeader(data))==DECODE_CONT);
while((ret=decodeNextFrameHeader(data))==DECODE_CONT ||
ret==DECODE_SKIP);
}
else while((ret=decodeNextFrame(data))==DECODE_CONT);
else while((ret=decodeNextFrame(data))==DECODE_CONT ||
ret==DECODE_SKIP);
return ret;
}

View File

@ -96,8 +96,7 @@ void pcm_add(char * buffer1, char * buffer2, size_t bufferSize1,
switch(format->bits) {
case 16:
while(bufferSize1>0 && bufferSize2>0) {
temp32 = *buffer16_1;
temp32+= *buffer16_2;
temp32 = *buffer16_1+*buffer16_2;
*buffer16_1 = temp32>32767 ? 32767 :
(temp32<-32768 ? -32768 : temp32);
buffer16_1++;
@ -105,12 +104,11 @@ void pcm_add(char * buffer1, char * buffer2, size_t bufferSize1,
bufferSize1-=2;
bufferSize2-=2;
}
if(bufferSize2>0) memcpy(buffer8_1,buffer8_2,bufferSize2);
if(bufferSize2>0) memcpy(buffer16_1,buffer16_2,bufferSize2);
break;
case 8:
while(bufferSize1>0 && bufferSize2>0) {
temp32 = *buffer8_1;
temp32+= *buffer8_2;
temp32 = *buffer8_1+*buffer8_2;
*buffer8_1 = temp32>127 ? 127 :
(temp32<-128 ? -128 : temp32);
buffer8_1++;