Fix some whitespace horrors!

This commit is contained in:
Jay Oster 2014-06-29 22:37:40 -07:00
parent 174d9d96e6
commit 050db8b445
2 changed files with 3757 additions and 4931 deletions

1884
menu.c

File diff suppressed because it is too large Load Diff

120
mp3.c
View File

@ -39,13 +39,8 @@ extern char path[1024];
extern void c2wstrcpy(void *dst, void *src);
extern void c2wstrcat(void *dst, void *src);
static int mp3_seek(char* fd, int offset, int whence)
{
static int mp3_seek(char* fd, int offset, int whence) {
//todo filesize and mp3File_fptr;
long offs = 0;
// libff routine
switch (whence)
@ -64,11 +59,9 @@ static int mp3_seek(char* fd, int offset, int whence)
mp3File_fptr=offs;
return offs;
}
static int mp3_size(char* fd)
{
static int mp3_size(char* fd) {
FatRecord rec_tmpf;
u8 resp=0;
resp = fatOpenFileByeName(fd, 0); //err if not found ^^
@ -77,12 +70,9 @@ static int mp3_size(char* fd)
mp3File_fsize = fsize;
//todo filesize
return mp3File_fsize;
}
static void _f_read(char* fname, unsigned char *readBuffer, int size){
/*
FatRecord rec_tmpf;
u8 resp=0;
@ -91,8 +81,6 @@ static void _f_read(char* fname, unsigned char *readBuffer, int size){
int fsize = file.sec_available*512; //fsize in bytes
mp3File_fsize = fsize;
//injecting in buffer... slow but working :/
if(file.sec_available*512>=size){
resp = fatReadPartialFile(readBuffer, size/512, mp3File_fptr);
@ -101,10 +89,7 @@ static void _f_read(char* fname, unsigned char *readBuffer, int size){
}
//dma_write_s(buffer, 0xb0000000, fsize);
*/
}
static int mp3_read(char* fd, unsigned char *ptr, int size)
@ -112,11 +97,9 @@ static int mp3_read(char* fd, unsigned char *ptr, int size)
int ts=size;
_f_read(fd, ptr, size);
return ts;
}
static int id3_tag_size(unsigned char const *buf, int remaining)
{
static int id3_tag_size(unsigned char const *buf, int remaining) {
int size;
if (remaining < 10)
@ -169,8 +152,7 @@ static int MP3_SkipHdr(char* fd)
mp3_seek(fd, offset, SEEK_SET);
//now seek for a sync
while(1)
{
while(1) {
offset = mp3_seek(fd, 0, SEEK_CUR);
size = mp3_read(fd, buf, sizeof(buf));
@ -184,11 +166,9 @@ static int MP3_SkipHdr(char* fd)
}
pBuffer = buf;
for( i = 0; i < size; i++)
{
for( i = 0; i < size; i++) {
//if this is a valid frame sync (0xe0 is for mpeg version 2.5,2+1)
if ( (pBuffer[i] == 0xff) && ((pBuffer[i+1] & 0xE0) == 0xE0) )
{
if ( (pBuffer[i] == 0xff) && ((pBuffer[i+1] & 0xE0) == 0xE0) ) {
offset += i;
mp3_seek(fd, offset, SEEK_SET);
return offset;
@ -199,8 +179,7 @@ static int MP3_SkipHdr(char* fd)
}
}
static short convertSample(mad_fixed_t Fixed)
{
static short convertSample(mad_fixed_t Fixed) {
/* Clipping */
if (Fixed >= MAD_F_ONE)
return (32767);
@ -209,11 +188,11 @@ static short convertSample(mad_fixed_t Fixed)
/* Conversion. */
Fixed = Fixed >> (MAD_F_FRACBITS - 15);
return ((short)Fixed);
}
static int fillFileBuffer()
{
static int fillFileBuffer() {
int leftOver = Stream.bufend - Stream.next_frame;
int want = INPUT_BUFFER_SIZE - leftOver;
@ -223,8 +202,7 @@ static int fillFileBuffer()
// fill remainder of buffer
unsigned char* bufferPos = fileBuffer + leftOver;
while (want > 0)
{
while (want > 0) {
int got = mp3_read(mp3Fd, bufferPos, want);
if (got <= 0)
return 1; // EOF
@ -235,25 +213,19 @@ static int fillFileBuffer()
return 0;
}
static void decode()
{
while (mad_frame_decode(&Frame, &Stream) == -1)
{
if ((Stream.error == MAD_ERROR_BUFLEN) || (Stream.error == MAD_ERROR_BUFPTR))
{
if (fillFileBuffer())
{
static void decode() {
while (mad_frame_decode(&Frame, &Stream) == -1) {
if ((Stream.error == MAD_ERROR_BUFLEN) || (Stream.error == MAD_ERROR_BUFPTR)) {
if (fillFileBuffer()) {
eos = 1;
break;
}
mad_stream_buffer(&Stream, fileBuffer, INPUT_BUFFER_SIZE);
}
else if (Stream.error == MAD_ERROR_LOSTSYNC)
{
else if (Stream.error == MAD_ERROR_LOSTSYNC) {
/* LOSTSYNC - due to ID3 tags? */
int tagsize = id3_tag_size(Stream.this_frame, Stream.bufend - Stream.this_frame);
if (tagsize > 0)
{
if (tagsize > 0) {
mad_stream_skip (&Stream, tagsize);
continue;
}
@ -264,45 +236,38 @@ static void decode()
mad_synth_frame(&Synth, &Frame);
}
static void convertLeftSamples(Sample* first, Sample* last, const mad_fixed_t* src)
{
static void convertLeftSamples(Sample* first, Sample* last, const mad_fixed_t* src) {
for (Sample *dst = first; dst != last; ++dst)
dst->left = convertSample(*src++);
}
static void convertRightSamples(Sample* first, Sample* last, const mad_fixed_t* src)
{
static void convertRightSamples(Sample* first, Sample* last, const mad_fixed_t* src) {
for (Sample *dst = first; dst != last; ++dst)
dst->right = convertSample(*src++);
}
static void MP3_Callback(void *buffer, unsigned int samplesToWrite)
{
static void MP3_Callback(void *buffer, unsigned int samplesToWrite) {
Sample *destination = (Sample*)buffer;
while (samplesToWrite > 0)
{
while (samplesToWrite > 0) {
while (!eos && (Synth.pcm.length == 0))
decode();
if (eos)
{
if (eos) {
// done
memset(destination, 0, samplesToWrite*4);
break;
}
unsigned int samplesAvailable = Synth.pcm.length - samplesRead;
if (samplesAvailable > samplesToWrite)
{
if (samplesAvailable > samplesToWrite) {
convertLeftSamples(destination, destination + samplesToWrite, &Synth.pcm.samples[0][samplesRead]);
convertRightSamples(destination, destination + samplesToWrite, &Synth.pcm.samples[1][samplesRead]);
samplesRead += samplesToWrite;
samplesToWrite = 0;
}
else
{
else {
convertLeftSamples(destination, destination + samplesAvailable, &Synth.pcm.samples[0][samplesRead]);
convertRightSamples(destination, destination + samplesAvailable, &Synth.pcm.samples[1][samplesRead]);
@ -315,8 +280,7 @@ static void MP3_Callback(void *buffer, unsigned int samplesToWrite)
}
}
static void MP3_Init()
{
static void MP3_Init() {
/* First the structures used by libmad must be initialized. */
mad_stream_init(&Stream);
mad_header_init(&Header);
@ -325,16 +289,14 @@ static void MP3_Init()
mad_timer_reset(&Timer);
}
static void MP3_Exit()
{
static void MP3_Exit() {
mad_synth_finish(&Synth);
mad_header_finish(&Header);
mad_frame_finish(&Frame);
mad_stream_finish(&Stream);
}
static void MP3_GetInfo(long long *samples, int *rate)
{
static void MP3_GetInfo(long long *samples, int *rate) {
unsigned long FrameCount = 0;
int bufferSize = 1024*512;
unsigned char *localBuffer;
@ -351,8 +313,7 @@ static void MP3_GetInfo(long long *samples, int *rate)
localBuffer = (unsigned char *)malloc(bufferSize);
for (int i=0; i<3; i++)
{
for (int i=0; i<3; i++) {
memset(localBuffer, 0, bufferSize);
if (count > bufferSize)
@ -365,18 +326,15 @@ static void MP3_GetInfo(long long *samples, int *rate)
mad_stream_buffer (&stream, localBuffer, red);
while (1)
{
if (mad_header_decode(&header, &stream) == -1)
{
if (stream.buffer == NULL || stream.error == MAD_ERROR_BUFLEN)
while (1) {
if (mad_header_decode(&header, &stream) == -1) {
if (stream.buffer == NULL || stream.error == MAD_ERROR_BUFLEN) {
break;
else if (MAD_RECOVERABLE(stream.error))
{
}
else if (MAD_RECOVERABLE(stream.error)) {
continue;
}
else
{
else {
break;
}
}
@ -400,12 +358,9 @@ static void MP3_GetInfo(long long *samples, int *rate)
}
void start_mp3(char *fname, long long *samples, int *rate, int *channels)
{
void start_mp3(char *fname, long long *samples, int *rate, int *channels) {
sprintf(mp3Fd, "%s", fname);
//if (mp3Fd[0]!=0)
//{
useReadBuffer = 0;
@ -420,11 +375,9 @@ void start_mp3(char *fname, long long *samples, int *rate, int *channels)
//}
//*samples = 0;
//return;
}
void stop_mp3(void)
{
void stop_mp3(void) {
MP3_Exit();
mp3File_fptr=0;
/*
@ -439,8 +392,7 @@ void stop_mp3(void)
*/
}
int update_mp3(char *buf, int bytes)
{
int update_mp3(char *buf, int bytes) {
MP3_Callback(buf, bytes/4);
return eos ? 0 : 1;
}