Flac refactor WIP
Signed-off-by: Mahyar Koshkouei <deltabeard@users.noreply.github.com>
This commit is contained in:
@@ -15,7 +15,7 @@ struct decoder_fn
|
||||
{
|
||||
int (* init)(const char* file);
|
||||
uint32_t (* rate)(void);
|
||||
uint8_t channels;
|
||||
uint8_t (*channels)(void);
|
||||
int buffSize;
|
||||
uint64_t (* decode)(void*);
|
||||
void (* exit)(void);
|
||||
|
||||
189
source/flac.c
189
source/flac.c
@@ -3,129 +3,74 @@
|
||||
#define DR_FLAC_IMPLEMENTATION
|
||||
#include <./dr_libs/dr_flac.h>
|
||||
#include "all.h"
|
||||
#include "flac.h"
|
||||
|
||||
#define SAMPLES_TO_READ (16 * 1024)
|
||||
static drflac* pFlac;
|
||||
static const int buffSize = 16 * 1024;
|
||||
|
||||
int playFlac(const char* in)
|
||||
/**
|
||||
* Set decoder parameters for flac.
|
||||
*
|
||||
* \param decoder Structure to store parameters.
|
||||
*/
|
||||
void setFlac(struct decoder_fn* decoder)
|
||||
{
|
||||
drflac* pFlac = drflac_open_file(in);
|
||||
s16* buffer1 = linearAlloc(SAMPLES_TO_READ * sizeof(s16));
|
||||
s16* buffer2 = linearAlloc(SAMPLES_TO_READ * sizeof(s16));
|
||||
ndspWaveBuf waveBuf[2];
|
||||
bool playing = true;
|
||||
bool lastbuf = false;
|
||||
|
||||
if (pFlac == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(R_FAILED(ndspInit()))
|
||||
{
|
||||
printf("Initialising ndsp failed.");
|
||||
goto out;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("\nRate: %lu\tChan: %d\n", pFlac->sampleRate,
|
||||
pFlac->channels);
|
||||
#endif
|
||||
|
||||
ndspChnReset(CHANNEL);
|
||||
ndspChnWaveBufClear(CHANNEL);
|
||||
ndspSetOutputMode(NDSP_OUTPUT_STEREO);
|
||||
ndspChnSetInterp(CHANNEL, NDSP_INTERP_POLYPHASE);
|
||||
ndspChnSetRate(CHANNEL, pFlac->sampleRate);
|
||||
ndspChnSetFormat(CHANNEL, pFlac->channels == 2 ? NDSP_FORMAT_STEREO_PCM16 :
|
||||
NDSP_FORMAT_MONO_PCM16);
|
||||
|
||||
memset(waveBuf, 0, sizeof(waveBuf));
|
||||
waveBuf[0].nsamples =
|
||||
drflac_read_s16(pFlac, SAMPLES_TO_READ, buffer1) / pFlac->channels;
|
||||
waveBuf[0].data_vaddr = &buffer1[0];
|
||||
ndspChnWaveBufAdd(CHANNEL, &waveBuf[0]);
|
||||
|
||||
waveBuf[1].nsamples =
|
||||
drflac_read_s16(pFlac, SAMPLES_TO_READ, buffer2) / pFlac->channels;
|
||||
waveBuf[1].data_vaddr = &buffer2[0];
|
||||
ndspChnWaveBufAdd(CHANNEL, &waveBuf[1]);
|
||||
|
||||
printf("Playing %s\n", in);
|
||||
/**
|
||||
* There may be a chance that the music has not started by the time we get
|
||||
* to the while loop. So we ensure that music has started here.
|
||||
*/
|
||||
while(ndspChnIsPlaying(CHANNEL) == false);
|
||||
|
||||
while(playing == false || ndspChnIsPlaying(CHANNEL) == true)
|
||||
{
|
||||
u32 kDown;
|
||||
|
||||
/* Number of bytes read from file.
|
||||
* Static only for the purposes of the printf debug at the bottom.
|
||||
*/
|
||||
static size_t read = 0;
|
||||
|
||||
gfxSwapBuffers();
|
||||
gfxFlushBuffers();
|
||||
gspWaitForVBlank();
|
||||
|
||||
hidScanInput();
|
||||
kDown = hidKeysDown();
|
||||
|
||||
if(kDown & KEY_B)
|
||||
break;
|
||||
|
||||
if(kDown & (KEY_A | KEY_R))
|
||||
{
|
||||
playing = !playing;
|
||||
printf("\33[2K\r%s", playing == false ? "Paused" : "");
|
||||
}
|
||||
|
||||
if(playing == false || lastbuf == true)
|
||||
continue;
|
||||
|
||||
if(waveBuf[0].status == NDSP_WBUF_DONE)
|
||||
{
|
||||
read = drflac_read_s16(pFlac, SAMPLES_TO_READ, buffer1);
|
||||
|
||||
if(read == 0)
|
||||
{
|
||||
lastbuf = true;
|
||||
continue;
|
||||
}
|
||||
else if(read < SAMPLES_TO_READ)
|
||||
waveBuf[0].nsamples = read / pFlac->channels;
|
||||
|
||||
ndspChnWaveBufAdd(CHANNEL, &waveBuf[0]);
|
||||
}
|
||||
|
||||
if(waveBuf[1].status == NDSP_WBUF_DONE)
|
||||
{
|
||||
read = drflac_read_s16(pFlac, SAMPLES_TO_READ, buffer2);
|
||||
|
||||
if(read == 0)
|
||||
{
|
||||
lastbuf = true;
|
||||
continue;
|
||||
}
|
||||
else if(read < SAMPLES_TO_READ)
|
||||
waveBuf[1].nsamples = read / pFlac->channels;
|
||||
|
||||
ndspChnWaveBufAdd(CHANNEL, &waveBuf[1]);
|
||||
}
|
||||
|
||||
DSP_FlushDataCache(buffer1, SAMPLES_TO_READ * sizeof(s16));
|
||||
DSP_FlushDataCache(buffer2, SAMPLES_TO_READ * sizeof(s16));
|
||||
}
|
||||
|
||||
printf("\nEnd of file.");
|
||||
|
||||
out:
|
||||
printf("\nStopping Flac playback.\n");
|
||||
ndspChnWaveBufClear(CHANNEL);
|
||||
ndspExit();
|
||||
linearFree(buffer1);
|
||||
linearFree(buffer2);
|
||||
drflac_close(pFlac);
|
||||
return 0;
|
||||
decoder->init = &initFlac;
|
||||
decoder->rate = &rateFlac;
|
||||
decoder->channels = &channelFlac;
|
||||
decoder->buffSize = buffSize;
|
||||
decoder->decode = &decodeFlac;
|
||||
decoder->exit = &exitFlac;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise Flac decoder.
|
||||
*
|
||||
* \param file Location of flac file to play.
|
||||
* \return 0 on success, else failure.
|
||||
*/
|
||||
int initFlac(const char* file)
|
||||
{
|
||||
pFlac = drflac_open_file(file);
|
||||
|
||||
return pFlac == NULL ? -1 : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sampling rate of Flac file.
|
||||
*
|
||||
* \return Sampling rate.
|
||||
*/
|
||||
uint32_t rateFlac(void)
|
||||
{
|
||||
return pFlac->sampleRate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get number of channels of Flac file.
|
||||
*
|
||||
* \return Number of channels for opened file.
|
||||
*/
|
||||
uint8_t channelFlac(void)
|
||||
{
|
||||
return pFlac->channels;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode part of open Flac file.
|
||||
*
|
||||
* \param buffer Decoded output.
|
||||
* \return Samples read for each channel.
|
||||
*/
|
||||
uint64_t decodeFlac(void* buffer)
|
||||
{
|
||||
return drflac_read_s16(pFlac, buffSize, buffer) / pFlac->channels;
|
||||
}
|
||||
|
||||
/**
|
||||
* Free Flac decoder.
|
||||
*/
|
||||
void exitFlac(void)
|
||||
{
|
||||
drflac_close(pFlac);
|
||||
}
|
||||
|
||||
@@ -1 +1,41 @@
|
||||
int playFlac(const char* in);
|
||||
/**
|
||||
* Set decoder parameters for flac.
|
||||
*
|
||||
* \param decoder Structure to store parameters.
|
||||
*/
|
||||
void setFlac(struct decoder_fn* decoder);
|
||||
|
||||
/**
|
||||
* Initialise Flac decoder.
|
||||
*
|
||||
* \param file Location of flac file to play.
|
||||
* \return 0 on success, else failure.
|
||||
*/
|
||||
int initFlac(const char* file);
|
||||
|
||||
/**
|
||||
* Get sampling rate of Flac file.
|
||||
*
|
||||
* \return Sampling rate.
|
||||
*/
|
||||
uint32_t rateFlac(void);
|
||||
|
||||
/**
|
||||
* Get number of channels of Flac file.
|
||||
*
|
||||
* \return Number of channels for opened file.
|
||||
*/
|
||||
uint8_t channelFlac(void);
|
||||
|
||||
/**
|
||||
* Decode part of open Flac file.
|
||||
*
|
||||
* \param buffer Decoded output.
|
||||
* \return Samples read for each channel.
|
||||
*/
|
||||
uint64_t decodeFlac(void* buffer);
|
||||
|
||||
/**
|
||||
* Free Flac decoder.
|
||||
*/
|
||||
void exitFlac(void);
|
||||
|
||||
130
source/main.c
130
source/main.c
@@ -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;
|
||||
}
|
||||
|
||||
@@ -13,15 +13,6 @@
|
||||
/* Maximum number of lines that can be displayed */
|
||||
#define MAX_LIST 27
|
||||
|
||||
enum file_types {
|
||||
FILE_TYPE_ERROR = -1,
|
||||
FILE_TYPE_WAV,
|
||||
FILE_TYPE_FLAC,
|
||||
FILE_TYPE_OGG,
|
||||
FILE_TYPE_OPUS,
|
||||
FILE_TYPE_MP3
|
||||
};
|
||||
|
||||
/**
|
||||
* Get number of files in current working folder
|
||||
*
|
||||
@@ -39,11 +30,3 @@ int getNumberFiles(void);
|
||||
* \return Number of entries listed or negative on error.
|
||||
*/
|
||||
int listDir(int from, int max, int select);
|
||||
|
||||
/**
|
||||
* Obtains file type.
|
||||
*
|
||||
* \param file File location.
|
||||
* \return File type, else negative.
|
||||
*/
|
||||
int getFileType(const char *file);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
static OggOpusFile* opusFile;
|
||||
static const OpusHead* opusHead;
|
||||
static const int buffSize = 32 * 1024;
|
||||
static const int buffSize = 32 * 1024;
|
||||
|
||||
/**
|
||||
* Set decoder parameters for Opus.
|
||||
@@ -16,13 +16,12 @@ static const int buffSize = 32 * 1024;
|
||||
*/
|
||||
void setOpus(struct decoder_fn* decoder)
|
||||
{
|
||||
decoder->init = initOpus;
|
||||
decoder->rate = rateOpus;
|
||||
/* Opus decoder always returns stereo stream */
|
||||
decoder->channels = 2;
|
||||
decoder->init = &initOpus;
|
||||
decoder->rate = &rateOpus;
|
||||
decoder->channels = &channelOpus;
|
||||
decoder->buffSize = buffSize;
|
||||
decoder->decode = decodeOpus;
|
||||
decoder->exit = exitOpus;
|
||||
decoder->decode = &decodeOpus;
|
||||
decoder->exit = &exitOpus;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,6 +56,17 @@ uint32_t rateOpus(void)
|
||||
return opusHead->input_sample_rate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get number of channels of Opus file.
|
||||
*
|
||||
* \return Number of channels for opened file, so always be 2.
|
||||
*/
|
||||
uint8_t channelOpus(void)
|
||||
{
|
||||
/* Opus decoder always returns stereo stream */
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode part of open Opus file.
|
||||
*
|
||||
|
||||
@@ -6,6 +6,8 @@ int initOpus(const char* file);
|
||||
|
||||
uint32_t rateOpus(void);
|
||||
|
||||
uint8_t channelOpus(void);
|
||||
|
||||
uint64_t decodeOpus(void* buffer);
|
||||
|
||||
void exitOpus(void);
|
||||
|
||||
@@ -3,8 +3,11 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "all.h"
|
||||
#include "flac.h"
|
||||
#include "mp3.h"
|
||||
#include "opus.h"
|
||||
#include "playback.h"
|
||||
#include "wav.h"
|
||||
|
||||
int playFile(const char* file)
|
||||
{
|
||||
@@ -22,8 +25,30 @@ int playFile(const char* file)
|
||||
goto out;
|
||||
}
|
||||
|
||||
printf("Here: %d\n", __LINE__);
|
||||
setOpus(&decoder);
|
||||
switch(getFileType(file))
|
||||
{
|
||||
case FILE_TYPE_WAV:
|
||||
playWav(file);
|
||||
return 0;
|
||||
|
||||
case FILE_TYPE_FLAC:
|
||||
setFlac(&decoder);
|
||||
break;
|
||||
//playFlac(file);
|
||||
//return 0;
|
||||
|
||||
case FILE_TYPE_OPUS:
|
||||
setOpus(&decoder);
|
||||
break;
|
||||
|
||||
case FILE_TYPE_MP3:
|
||||
playMp3(file);
|
||||
return 0;
|
||||
|
||||
default:
|
||||
printf("Unsupported File type.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("Here: %d\n", __LINE__);
|
||||
buffer1 = linearAlloc(decoder.buffSize * sizeof(int16_t));
|
||||
@@ -36,7 +61,7 @@ int playFile(const char* file)
|
||||
printf("Here: %d\n", __LINE__);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("\nRate: %lu\tChan: %d\n", (*decoder.rate)(), decoder.channels);
|
||||
printf("\nRate: %lu\tChan: %d\n", (*decoder.rate)(), (*decoder.channels)());
|
||||
#endif
|
||||
|
||||
ndspChnReset(CHANNEL);
|
||||
@@ -44,16 +69,18 @@ int playFile(const char* file)
|
||||
ndspSetOutputMode(NDSP_OUTPUT_STEREO);
|
||||
ndspChnSetInterp(CHANNEL, NDSP_INTERP_POLYPHASE);
|
||||
ndspChnSetRate(CHANNEL, (*decoder.rate)());
|
||||
ndspChnSetFormat(CHANNEL, NDSP_FORMAT_STEREO_PCM16);
|
||||
ndspChnSetFormat(CHANNEL,
|
||||
(*decoder.channels)() == 2 ? NDSP_FORMAT_STEREO_PCM16 :
|
||||
NDSP_FORMAT_MONO_PCM16);
|
||||
printf("Here: %d\n", __LINE__);
|
||||
|
||||
memset(waveBuf, 0, sizeof(waveBuf));
|
||||
waveBuf[0].nsamples = (*decoder.decode)(&buffer1[0]) / decoder.channels;
|
||||
waveBuf[0].nsamples = (*decoder.decode)(&buffer1[0]) / (*decoder.channels)();
|
||||
waveBuf[0].data_vaddr = &buffer1[0];
|
||||
ndspChnWaveBufAdd(CHANNEL, &waveBuf[0]);
|
||||
printf("Here: %d\n", __LINE__);
|
||||
|
||||
waveBuf[1].nsamples = (*decoder.decode)(&buffer2[0]) / decoder.channels;
|
||||
waveBuf[1].nsamples = (*decoder.decode)(&buffer2[0]) / (*decoder.channels)();
|
||||
waveBuf[1].data_vaddr = &buffer2[0];
|
||||
ndspChnWaveBufAdd(CHANNEL, &waveBuf[1]);
|
||||
|
||||
@@ -103,7 +130,7 @@ int playFile(const char* file)
|
||||
continue;
|
||||
}
|
||||
else if(read < decoder.buffSize)
|
||||
waveBuf[0].nsamples = read / decoder.channels;
|
||||
waveBuf[0].nsamples = read / (*decoder.channels)();
|
||||
|
||||
ndspChnWaveBufAdd(CHANNEL, &waveBuf[0]);
|
||||
}
|
||||
@@ -118,7 +145,7 @@ int playFile(const char* file)
|
||||
continue;
|
||||
}
|
||||
else if(read < decoder.buffSize)
|
||||
waveBuf[1].nsamples = read / decoder.channels;
|
||||
waveBuf[1].nsamples = read / (*decoder.channels)();
|
||||
|
||||
ndspChnWaveBufAdd(CHANNEL, &waveBuf[1]);
|
||||
}
|
||||
@@ -136,3 +163,94 @@ out:
|
||||
linearFree(buffer2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
@@ -1 +1,18 @@
|
||||
enum file_types {
|
||||
FILE_TYPE_ERROR = -1,
|
||||
FILE_TYPE_WAV,
|
||||
FILE_TYPE_FLAC,
|
||||
FILE_TYPE_OGG,
|
||||
FILE_TYPE_OPUS,
|
||||
FILE_TYPE_MP3
|
||||
};
|
||||
|
||||
int playFile(const char* file);
|
||||
|
||||
/**
|
||||
* Obtains file type.
|
||||
*
|
||||
* \param file File location.
|
||||
* \return File type, else negative.
|
||||
*/
|
||||
int getFileType(const char *file);
|
||||
|
||||
Reference in New Issue
Block a user