Preliminary support for MP3 fileformat -WIP-
This commit is contained in:
parent
2aae62cea2
commit
88c2337225
41
src/audio.c
41
src/audio.c
@ -73,8 +73,6 @@
|
|||||||
*
|
*
|
||||||
**********************************************************************************************/
|
**********************************************************************************************/
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#if !defined(USE_OPENAL_BACKEND)
|
#if !defined(USE_OPENAL_BACKEND)
|
||||||
#define USE_MINI_AL 1 // Set to 1 to use mini_al; 0 to use OpenAL.
|
#define USE_MINI_AL 1 // Set to 1 to use mini_al; 0 to use OpenAL.
|
||||||
#endif
|
#endif
|
||||||
@ -83,7 +81,8 @@
|
|||||||
#include "audio.h"
|
#include "audio.h"
|
||||||
#include <stdarg.h> // Required for: va_list, va_start(), vfprintf(), va_end()
|
#include <stdarg.h> // Required for: va_list, va_start(), vfprintf(), va_end()
|
||||||
#else
|
#else
|
||||||
#include "raylib.h"
|
#include "config.h" // Defines module configuration flags
|
||||||
|
#include "raylib.h" // Declares module functions
|
||||||
#include "utils.h" // Required for: fopen() Android mapping
|
#include "utils.h" // Required for: fopen() Android mapping
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -164,6 +163,7 @@
|
|||||||
typedef enum {
|
typedef enum {
|
||||||
MUSIC_AUDIO_OGG = 0,
|
MUSIC_AUDIO_OGG = 0,
|
||||||
MUSIC_AUDIO_FLAC,
|
MUSIC_AUDIO_FLAC,
|
||||||
|
MUSIC_AUDIO_MP3,
|
||||||
MUSIC_MODULE_XM,
|
MUSIC_MODULE_XM,
|
||||||
MUSIC_MODULE_MOD
|
MUSIC_MODULE_MOD
|
||||||
} MusicContextType;
|
} MusicContextType;
|
||||||
@ -177,6 +177,9 @@ typedef struct MusicData {
|
|||||||
#if defined(SUPPORT_FILEFORMAT_FLAC)
|
#if defined(SUPPORT_FILEFORMAT_FLAC)
|
||||||
drflac *ctxFlac; // FLAC audio context
|
drflac *ctxFlac; // FLAC audio context
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_MP3)
|
||||||
|
drmp3 ctxMp3; // MP3 audio context
|
||||||
|
#endif
|
||||||
#if defined(SUPPORT_FILEFORMAT_XM)
|
#if defined(SUPPORT_FILEFORMAT_XM)
|
||||||
jar_xm_context_t *ctxXm; // XM chiptune context
|
jar_xm_context_t *ctxXm; // XM chiptune context
|
||||||
#endif
|
#endif
|
||||||
@ -1368,6 +1371,27 @@ Music LoadMusicStream(const char *fileName)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_MP3)
|
||||||
|
else if (IsFileExtension(fileName, ".mp3"))
|
||||||
|
{
|
||||||
|
drmp3_init_file(&music->ctxMp3, fileName, NULL)
|
||||||
|
|
||||||
|
if (music->ctxMp3 == NULL) TraceLog(LOG_WARNING, "[%s] MP3 audio file could not be opened", fileName);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
music->stream = InitAudioStream(music->ctxMp3.sampleRate, 16, music->ctxMp3.channels);
|
||||||
|
//music->totalSamples = (unsigned int)music->ctxMp3.totalSampleCount/music->ctxMp3.channels; //TODO!
|
||||||
|
music->samplesLeft = music->totalSamples;
|
||||||
|
music->ctxType = MUSIC_AUDIO_MP3;
|
||||||
|
music->loopCount = -1; // Infinite loop by default
|
||||||
|
|
||||||
|
TraceLog(LOG_DEBUG, "[%s] MP3 total samples: %i", fileName, music->totalSamples);
|
||||||
|
TraceLog(LOG_DEBUG, "[%s] MP3 sample rate: %i", fileName, music->ctxMp3.sampleRate);
|
||||||
|
//TraceLog(LOG_DEBUG, "[%s] MP3 bits per sample: %i", fileName, music->ctxMp3.bitsPerSample);
|
||||||
|
TraceLog(LOG_DEBUG, "[%s] MP3 channels: %i", fileName, music->ctxMp3.channels);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#if defined(SUPPORT_FILEFORMAT_XM)
|
#if defined(SUPPORT_FILEFORMAT_XM)
|
||||||
else if (IsFileExtension(fileName, ".xm"))
|
else if (IsFileExtension(fileName, ".xm"))
|
||||||
{
|
{
|
||||||
@ -1423,6 +1447,9 @@ void UnloadMusicStream(Music music)
|
|||||||
#if defined(SUPPORT_FILEFORMAT_FLAC)
|
#if defined(SUPPORT_FILEFORMAT_FLAC)
|
||||||
else if (music->ctxType == MUSIC_AUDIO_FLAC) drflac_free(music->ctxFlac);
|
else if (music->ctxType == MUSIC_AUDIO_FLAC) drflac_free(music->ctxFlac);
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_MP3)
|
||||||
|
else if (music->ctxType == MUSIC_AUDIO_MP3) drmp3_uninit(&music->ctxMp3);
|
||||||
|
#endif
|
||||||
#if defined(SUPPORT_FILEFORMAT_XM)
|
#if defined(SUPPORT_FILEFORMAT_XM)
|
||||||
else if (music->ctxType == MUSIC_MODULE_XM) jar_xm_free_context(music->ctxXm);
|
else if (music->ctxType == MUSIC_MODULE_XM) jar_xm_free_context(music->ctxXm);
|
||||||
#endif
|
#endif
|
||||||
@ -1564,6 +1591,14 @@ void UpdateMusicStream(Music music)
|
|||||||
|
|
||||||
} break;
|
} break;
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_MP3)
|
||||||
|
case MUSIC_AUDIO_MP3:
|
||||||
|
{
|
||||||
|
// NOTE: Returns the number of samples to process
|
||||||
|
unsigned int numSamplesMp3 = (unsigned int)drmp3_read_f32(music->ctxMp3, samplesCount*music->stream.channels, (short *)pcm);
|
||||||
|
|
||||||
|
} break;
|
||||||
|
#endif
|
||||||
#if defined(SUPPORT_FILEFORMAT_XM)
|
#if defined(SUPPORT_FILEFORMAT_XM)
|
||||||
case MUSIC_MODULE_XM: jar_xm_generate_samples_16bit(music->ctxXm, pcm, samplesCount); break;
|
case MUSIC_MODULE_XM: jar_xm_generate_samples_16bit(music->ctxXm, pcm, samplesCount); break;
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user