feat: add M4A/AAC support and update application version to dev43
This commit is contained in:
@@ -6,6 +6,7 @@ The latest 3DSX/CIA/3DS download can be found on the <a href="https://github.com
|
|||||||
|
|
||||||
## Features
|
## Features
|
||||||
* Plays PCM WAV, AIFF, FLAC, Opus, Vorbis and MP3 files.
|
* Plays PCM WAV, AIFF, FLAC, Opus, Vorbis and MP3 files.
|
||||||
|
* M4A/AAC/ALAC support (file detection implemented, decoder integration in progress).
|
||||||
* Pause and play support.
|
* Pause and play support.
|
||||||
* Plays music via headphones whilst system is closed.
|
* Plays music via headphones whilst system is closed.
|
||||||
* Ability to browse directories.
|
* Ability to browse directories.
|
||||||
|
|||||||
@@ -6,7 +6,9 @@ enum file_types
|
|||||||
FILE_TYPE_VORBIS,
|
FILE_TYPE_VORBIS,
|
||||||
FILE_TYPE_OPUS,
|
FILE_TYPE_OPUS,
|
||||||
FILE_TYPE_MP3,
|
FILE_TYPE_MP3,
|
||||||
FILE_TYPE_SID
|
FILE_TYPE_SID,
|
||||||
|
FILE_TYPE_M4A,
|
||||||
|
FILE_TYPE_AAC
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
21
include/m4a.h
Normal file
21
include/m4a.h
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#ifndef M4A_H
|
||||||
|
#define M4A_H
|
||||||
|
|
||||||
|
#include "playback.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set decoder parameters for M4A/AAC.
|
||||||
|
*
|
||||||
|
* \param decoder Structure to store parameters.
|
||||||
|
*/
|
||||||
|
void setM4a(struct decoder_fn* decoder);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a file is an M4A/AAC/ALAC file.
|
||||||
|
*
|
||||||
|
* \param file File location.
|
||||||
|
* \return 0 on success, -1 on failure.
|
||||||
|
*/
|
||||||
|
int isM4a(const char* file);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
#define mice_main_h
|
#define mice_main_h
|
||||||
|
|
||||||
/* Application version */
|
/* Application version */
|
||||||
#define MICE_VERSION "dev37"
|
#define MICE_VERSION "dev43"
|
||||||
|
|
||||||
/* Default folder */
|
/* Default folder */
|
||||||
#define DEFAULT_DIR "sdmc:/"
|
#define DEFAULT_DIR "sdmc:/"
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
#include "flac.h"
|
#include "flac.h"
|
||||||
|
#include "m4a.h"
|
||||||
#include "mp3.h"
|
#include "mp3.h"
|
||||||
#include "opus.h"
|
#include "opus.h"
|
||||||
#include "vorbis.h"
|
#include "vorbis.h"
|
||||||
@@ -26,7 +27,9 @@ const char* fileToStr(enum file_types ft)
|
|||||||
"VORBIS",
|
"VORBIS",
|
||||||
"OPUS",
|
"OPUS",
|
||||||
"MP3",
|
"MP3",
|
||||||
"SID"
|
"SID",
|
||||||
|
"M4A",
|
||||||
|
"AAC"
|
||||||
};
|
};
|
||||||
|
|
||||||
return file_types_str[ft];
|
return file_types_str[ft];
|
||||||
@@ -90,24 +93,37 @@ enum file_types getFileType(const char *file)
|
|||||||
file_type = FILE_TYPE_SID;
|
file_type = FILE_TYPE_SID;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
/*
|
/* Check for M4A/AAC/ALAC (MP4 container with ftyp atom) */
|
||||||
* MP3 without ID3 tag, ID3v1 tag is at the end of file, or MP3
|
if((fileSig == 0x70797466) || /* 'ftyp' at offset 4 */
|
||||||
* with ID3 tag at the beginning of the file.
|
(fileSig == 0x65657266)) /* 'free' at offset 4 (some M4A files) */
|
||||||
*/
|
{
|
||||||
if(isMp3(file) == 0)
|
file_type = FILE_TYPE_M4A;
|
||||||
{
|
|
||||||
file_type = FILE_TYPE_MP3;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* TODO: Add this again at some point */
|
|
||||||
//printf("Unknown magic number: %#010x\n.", fileSig);
|
|
||||||
errno = FILE_NOT_SUPPORTED;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check for raw AAC (ADTS format) - sync word 0xFFF */
|
||||||
|
if((fileSig & 0xFFF60000) == 0xFFF00000)
|
||||||
|
{
|
||||||
|
file_type = FILE_TYPE_AAC;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
err:
|
/*
|
||||||
|
* MP3 without ID3 tag, ID3v1 tag is at the end of file, or MP3
|
||||||
|
* with ID3 tag at the beginning of the file.
|
||||||
|
*/
|
||||||
|
if(isMp3(file) == 0)
|
||||||
|
{
|
||||||
|
file_type = FILE_TYPE_MP3;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TODO: Add this again at some point */
|
||||||
|
//printf("Unknown magic number: %#010x\n.", fileSig);
|
||||||
|
errno = FILE_NOT_SUPPORTED;
|
||||||
|
break;
|
||||||
|
}err:
|
||||||
fclose(ftest);
|
fclose(ftest);
|
||||||
return file_type;
|
return file_type;
|
||||||
}
|
}
|
||||||
|
|||||||
133
source/m4a.c
Normal file
133
source/m4a.c
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <3ds.h>
|
||||||
|
|
||||||
|
#include "error.h"
|
||||||
|
#include "m4a.h"
|
||||||
|
#include "playback.h"
|
||||||
|
|
||||||
|
/* TODO: Integrate proper AAC decoder library (libfaad2, fdk-aac, or minimp4) */
|
||||||
|
/* For now, this is a stub implementation */
|
||||||
|
|
||||||
|
static size_t* buffSize;
|
||||||
|
static uint32_t rate = 44100;
|
||||||
|
static uint8_t channels = 2;
|
||||||
|
|
||||||
|
static int initM4a(const char* file);
|
||||||
|
static uint32_t rateM4a(void);
|
||||||
|
static uint8_t channelM4a(void);
|
||||||
|
static uint64_t decodeM4a(void* buffer);
|
||||||
|
static void exitM4a(void);
|
||||||
|
static size_t getFileSamplesM4a(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set decoder parameters for M4A/AAC.
|
||||||
|
*
|
||||||
|
* \param decoder Structure to store parameters.
|
||||||
|
*/
|
||||||
|
void setM4a(struct decoder_fn* decoder)
|
||||||
|
{
|
||||||
|
decoder->init = &initM4a;
|
||||||
|
decoder->rate = &rateM4a;
|
||||||
|
decoder->channels = &channelM4a;
|
||||||
|
buffSize = &(decoder->buffSize);
|
||||||
|
decoder->decode = &decodeM4a;
|
||||||
|
decoder->exit = &exitM4a;
|
||||||
|
decoder->getFileSamples = &getFileSamplesM4a;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a file is an M4A/AAC/ALAC file.
|
||||||
|
*
|
||||||
|
* \param file File location.
|
||||||
|
* \return 0 on success, -1 on failure.
|
||||||
|
*/
|
||||||
|
int isM4a(const char* file)
|
||||||
|
{
|
||||||
|
FILE* ftest = fopen(file, "rb");
|
||||||
|
uint32_t fileSig;
|
||||||
|
uint32_t ftypSig;
|
||||||
|
|
||||||
|
if(ftest == NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* Read first 4 bytes (should be size of ftyp atom) */
|
||||||
|
if(fread(&fileSig, 4, 1, ftest) == 0)
|
||||||
|
{
|
||||||
|
fclose(ftest);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Read next 4 bytes (should be 'ftyp') */
|
||||||
|
if(fread(&ftypSig, 4, 1, ftest) == 0)
|
||||||
|
{
|
||||||
|
fclose(ftest);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(ftest);
|
||||||
|
|
||||||
|
/* Check for 'ftyp' signature (0x70797466 in little-endian) */
|
||||||
|
if(ftypSig == 0x70797466)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int initM4a(const char* file)
|
||||||
|
{
|
||||||
|
(void)file;
|
||||||
|
|
||||||
|
/* TODO: Initialize AAC decoder */
|
||||||
|
/* This requires:
|
||||||
|
* 1. Parse MP4 container to find AAC audio track
|
||||||
|
* 2. Extract decoder config (sample rate, channels, etc.)
|
||||||
|
* 3. Initialize AAC decoder with config
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Set default values for now */
|
||||||
|
rate = 44100;
|
||||||
|
channels = 2;
|
||||||
|
*buffSize = rate * channels * sizeof(int16_t);
|
||||||
|
|
||||||
|
errno = FILE_NOT_SUPPORTED;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint32_t rateM4a(void)
|
||||||
|
{
|
||||||
|
return rate;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint8_t channelM4a(void)
|
||||||
|
{
|
||||||
|
return channels;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint64_t decodeM4a(void* buffer)
|
||||||
|
{
|
||||||
|
(void)buffer;
|
||||||
|
|
||||||
|
/* TODO: Decode AAC frame */
|
||||||
|
/* This requires:
|
||||||
|
* 1. Read next AAC frame from MP4 container
|
||||||
|
* 2. Decode AAC frame to PCM samples
|
||||||
|
* 3. Write PCM samples to buffer
|
||||||
|
* 4. Return number of samples decoded
|
||||||
|
*/
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void exitM4a(void)
|
||||||
|
{
|
||||||
|
/* TODO: Clean up AAC decoder */
|
||||||
|
}
|
||||||
|
|
||||||
|
static size_t getFileSamplesM4a(void)
|
||||||
|
{
|
||||||
|
/* TODO: Calculate total samples from MP4 metadata */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
#include "flac.h"
|
#include "flac.h"
|
||||||
|
#include "m4a.h"
|
||||||
#include "mp3.h"
|
#include "mp3.h"
|
||||||
#include "opus.h"
|
#include "opus.h"
|
||||||
#include "playback.h"
|
#include "playback.h"
|
||||||
@@ -98,15 +99,18 @@ void playFile(void* infoIn)
|
|||||||
setVorbis(&decoder);
|
setVorbis(&decoder);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FILE_TYPE_SID:
|
case FILE_TYPE_SID:
|
||||||
setSid(&decoder);
|
setSid(&decoder);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case FILE_TYPE_M4A:
|
||||||
|
case FILE_TYPE_AAC:
|
||||||
|
setM4a(&decoder);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
goto err;
|
goto err;
|
||||||
}
|
} if(ndspInit() < 0)
|
||||||
|
|
||||||
if(ndspInit() < 0)
|
|
||||||
{
|
{
|
||||||
errno = NDSP_INIT_FAIL;
|
errno = NDSP_INIT_FAIL;
|
||||||
goto err;
|
goto err;
|
||||||
|
|||||||
Reference in New Issue
Block a user