#include #include #include #include #include #include #include "mp3dec.h" #define MAX_BUFFER_LEN (MAX_NSAMP * MAX_NGRAN * MAX_NCHAN) int16_t audiodata[MAX_BUFFER_LEN]; typedef struct { char *ptr, *end; } stream; #define READ_PTR(stream) ((void*)((stream)->ptr)) #define BYTES_LEFT(stream) ((stream)->end - (stream)->ptr) #define CONSUME(stream, n) ((stream)->ptr += n) void skip_id3v2(stream* self) { if (BYTES_LEFT(self) < 10) { return; } uint8_t *data = READ_PTR(self); if (!( data[0] == 'I' && data[1] == 'D' && data[2] == '3' && data[3] != 0xff && data[4] != 0xff && (data[5] & 0x1f) == 0 && (data[6] & 0x80) == 0 && (data[7] & 0x80) == 0 && (data[8] & 0x80) == 0 && (data[9] & 0x80) == 0)) { return; } uint32_t size = (data[6] << 21) | (data[7] << 14) | (data[8] << 7) | (data[9]); size += 10; // size excludes the "header" (but not the "extended header") CONSUME(self, size + 10); } bool mp3file_find_sync_word(stream* self) { int offset = MP3FindSyncWord(READ_PTR(self), BYTES_LEFT(self)); if (offset >= 0) { CONSUME(self, offset); return true; } return false; } void fatal(const char *msg) { fprintf(stderr, "%s\n", msg); exit(1); } void perror_fatal(const char *msg) { perror(msg); exit(1); } bool probable_overflow(int16_t a, int16_t b) { if(a > 32700 && b < -32700) { return true; } else if(b > 32700 && a < -32700) { return true; } else { return false; } } void look_for_overflow(int16_t *ptr, size_t os, int frame) { for(size_t i=2; i