Flac refactor WIP

Signed-off-by: Mahyar Koshkouei <deltabeard@users.noreply.github.com>
This commit is contained in:
Mahyar Koshkouei
2017-01-10 20:55:21 +00:00
parent cdf964f5b1
commit 27ee6af2e1
9 changed files with 282 additions and 275 deletions

View File

@@ -16,12 +16,9 @@
#include <unistd.h>
#include "all.h"
#include "flac.h"
#include "main.h"
#include "mp3.h"
#include "opus.h"
#include "playback.h"
#include "wav.h"
int main(int argc, char **argv)
{
@@ -73,7 +70,10 @@ int main(int argc, char **argv)
kHeld = hidKeysHeld();
if(kDown & KEY_START)
{
puts("Test.");
break;
}
#ifdef DEBUG
consoleSelect(&topScreen);
@@ -191,33 +191,10 @@ int main(int argc, char **argv)
else
{
consoleSelect(&topScreen);
/* Move this to playback.c */
switch(getFileType(file))
{
case FILE_TYPE_WAV:
playWav(file);
break;
case FILE_TYPE_FLAC:
playFlac(file);
break;
case FILE_TYPE_OPUS:
playFile(file);
break;
case FILE_TYPE_MP3:
playMp3(file);
break;
default:
consoleSelect(&bottomScreen);
printf("Unsupported File type.\n");
}
playFile(file);
consoleSelect(&bottomScreen);
}
consoleSelect(&bottomScreen);
free(file);
free(wd);
@@ -228,12 +205,18 @@ int main(int argc, char **argv)
err_print("Unable to open directory.");
}
}
#ifdef DEBUG
consoleSelect(&topScreen);
printf("\rNum: %d, Max: %d, from: %d ", fileNum, fileMax, from);
consoleSelect(&bottomScreen);
#endif
out:
puts("Exiting...");
gfxExit();
sdmcExit();
puts("Return");
return 0;
err:
@@ -345,94 +328,3 @@ err:
ret = -1;
goto out;
}
/**
* Obtains file type.
*
* \param file File location.
* \return File type, else negative.
*/
int getFileType(const char *file)
{
FILE* ftest = fopen(file, "rb");
int fileSig = 0;
enum file_types file_type = FILE_TYPE_ERROR;
if(ftest == NULL)
{
err_print("Opening file failed.");
printf("file: %s\n", file);
return -1;
}
if(fread(&fileSig, 4, 1, ftest) == 0)
{
err_print("Unable to read file.");
fclose(ftest);
return -1;
}
switch(fileSig)
{
// "RIFF"
case 0x46464952:
if(fseek(ftest, 4, SEEK_CUR) != 0)
{
err_print("Unable to seek.");
break;
}
// "WAVE"
// Check required as AVI file format also uses "RIFF".
if(fread(&fileSig, 4, 1, ftest) == 0)
{
err_print("Unable to read potential WAV file.");
break;
}
if(fileSig != 0x45564157)
break;
file_type = FILE_TYPE_WAV;
printf("File type is WAV.");
break;
// "fLaC"
case 0x43614c66:
file_type = FILE_TYPE_FLAC;
printf("File type is FLAC.");
break;
// "OggS"
case 0x5367674f:
if(isOpus(file) == 0)
{
printf("\nFile type is Opus.");
file_type = FILE_TYPE_OPUS;
}
else
{
file_type = FILE_TYPE_OGG;
printf("\nFile type is OGG.");
}
break;
default:
/*
* MP3 without ID3 tag, ID3v1 tag is at the end of file, or MP3
* with ID3 tag at the beginning of the file.
*/
if((fileSig << 16) == 0xFBFF0000 || (fileSig << 8) == 0x33444900)
{
puts("File type is MP3.");
file_type = FILE_TYPE_MP3;
break;
}
printf("Unknown magic number: %#010x\n.", fileSig);
}
fclose(ftest);
return file_type;
}