Support custom modules inclusion
Allow to choose which modules are compiled with raylib, if some modules are excluded from compilation, required functionality is not available but smaller builds are possible.
This commit is contained in:
parent
48d4806e53
commit
e637ad9d2a
9 changed files with 193 additions and 123 deletions
74
src/raudio.c
74
src/raudio.c
|
@ -12,6 +12,9 @@
|
|||
*
|
||||
* CONFIGURATION:
|
||||
*
|
||||
* #define SUPPORT_MODULE_RAUDIO
|
||||
* raudio module is included in the build
|
||||
*
|
||||
* #define RAUDIO_STANDALONE
|
||||
* Define to use the module as standalone library (independently of raylib).
|
||||
* Required types and functions are defined in the same module.
|
||||
|
@ -78,6 +81,8 @@
|
|||
#include "utils.h" // Required for: fopen() Android mapping
|
||||
#endif
|
||||
|
||||
#if defined(SUPPORT_MODULE_RAUDIO)
|
||||
|
||||
#if defined(_WIN32)
|
||||
// To avoid conflicting windows.h symbols with raylib, some flags are defined
|
||||
// WARNING: Those flags avoid inclusion of some Win32 headers that could be required
|
||||
|
@ -169,10 +174,9 @@ typedef struct tagBITMAPINFOHEADER {
|
|||
|
||||
#include <stdlib.h> // Required for: malloc(), free()
|
||||
#include <stdio.h> // Required for: FILE, fopen(), fclose(), fread()
|
||||
#include <string.h> // Required for: strcmp() [Used in IsFileExtension(), LoadWaveFromMemory(), LoadMusicStreamFromMemory()]
|
||||
|
||||
#if defined(RAUDIO_STANDALONE)
|
||||
#include <string.h> // Required for: strcmp() [Used in IsFileExtension()]
|
||||
|
||||
#ifndef TRACELOG
|
||||
#define TRACELOG(level, ...) (void)0
|
||||
#endif
|
||||
|
@ -374,8 +378,6 @@ static void MixAudioFrames(float *framesOut, const float *framesIn, ma_uint32 fr
|
|||
#if defined(RAUDIO_STANDALONE)
|
||||
static bool IsFileExtension(const char *fileName, const char *ext); // Check file extension
|
||||
static const char *GetFileExtension(const char *fileName); // Get pointer to extension for a filename string (includes the dot: .png)
|
||||
static bool TextIsEqual(const char *text1, const char *text2); // Check if two text string are equal
|
||||
static const char *TextToLower(const char *text); // Get lower case version of provided string
|
||||
|
||||
static unsigned char *LoadFileData(const char *fileName, unsigned int *bytesRead); // Load file data as byte array (read)
|
||||
static bool SaveFileData(const char *fileName, void *data, unsigned int bytesToWrite); // Save data to file from byte array (write)
|
||||
|
@ -711,16 +713,14 @@ Wave LoadWave(const char *fileName)
|
|||
}
|
||||
|
||||
// Load wave from memory buffer, fileType refers to extension: i.e. ".wav"
|
||||
// WARNING: File extension must be provided in lower-case
|
||||
Wave LoadWaveFromMemory(const char *fileType, const unsigned char *fileData, int dataSize)
|
||||
{
|
||||
Wave wave = { 0 };
|
||||
|
||||
char fileExtLower[16] = { 0 };
|
||||
strcpy(fileExtLower, TextToLower(fileType));
|
||||
|
||||
if (false) { }
|
||||
#if defined(SUPPORT_FILEFORMAT_WAV)
|
||||
else if (TextIsEqual(fileExtLower, ".wav"))
|
||||
else if (strcmp(fileType, ".wav") == 0)
|
||||
{
|
||||
drwav wav = { 0 };
|
||||
bool success = drwav_init_memory(&wav, fileData, dataSize, NULL);
|
||||
|
@ -742,7 +742,7 @@ Wave LoadWaveFromMemory(const char *fileType, const unsigned char *fileData, int
|
|||
}
|
||||
#endif
|
||||
#if defined(SUPPORT_FILEFORMAT_OGG)
|
||||
else if (TextIsEqual(fileExtLower, ".ogg"))
|
||||
else if (strcmp(fileType, ".ogg") == 0)
|
||||
{
|
||||
stb_vorbis *oggData = stb_vorbis_open_memory((unsigned char *)fileData, dataSize, NULL, NULL);
|
||||
|
||||
|
@ -764,7 +764,7 @@ Wave LoadWaveFromMemory(const char *fileType, const unsigned char *fileData, int
|
|||
}
|
||||
#endif
|
||||
#if defined(SUPPORT_FILEFORMAT_FLAC)
|
||||
else if (TextIsEqual(fileExtLower, ".flac"))
|
||||
else if (strcmp(fileType, ".flac") == 0)
|
||||
{
|
||||
unsigned long long int totalFrameCount = 0;
|
||||
|
||||
|
@ -777,7 +777,7 @@ Wave LoadWaveFromMemory(const char *fileType, const unsigned char *fileData, int
|
|||
}
|
||||
#endif
|
||||
#if defined(SUPPORT_FILEFORMAT_MP3)
|
||||
else if (TextIsEqual(fileExtLower, ".mp3"))
|
||||
else if (strcmp(fileType, ".mp3") == 0)
|
||||
{
|
||||
drmp3_config config = { 0 };
|
||||
unsigned long long int totalFrameCount = 0;
|
||||
|
@ -1377,18 +1377,16 @@ Music LoadMusicStream(const char *fileName)
|
|||
return music;
|
||||
}
|
||||
|
||||
// extension including period ".mod"
|
||||
// Load music stream from memory buffer, fileType refers to extension: i.e. ".wav"
|
||||
// WARNING: File extension must be provided in lower-case
|
||||
Music LoadMusicStreamFromMemory(const char *fileType, unsigned char *data, int dataSize)
|
||||
{
|
||||
Music music = { 0 };
|
||||
bool musicLoaded = false;
|
||||
|
||||
char fileExtLower[16] = { 0 };
|
||||
strcpy(fileExtLower, TextToLower(fileType));
|
||||
|
||||
if (false) { }
|
||||
#if defined(SUPPORT_FILEFORMAT_WAV)
|
||||
else if (TextIsEqual(fileExtLower, ".wav"))
|
||||
else if (strcmp(fileType, ".wav") == 0)
|
||||
{
|
||||
drwav *ctxWav = RL_CALLOC(1, sizeof(drwav));
|
||||
|
||||
|
@ -1410,7 +1408,7 @@ Music LoadMusicStreamFromMemory(const char *fileType, unsigned char *data, int d
|
|||
}
|
||||
#endif
|
||||
#if defined(SUPPORT_FILEFORMAT_FLAC)
|
||||
else if (TextIsEqual(fileExtLower, ".flac"))
|
||||
else if (strcmp(fileType, ".flac") == 0)
|
||||
{
|
||||
music.ctxType = MUSIC_AUDIO_FLAC;
|
||||
music.ctxData = drflac_open_memory((const void*)data, dataSize, NULL);
|
||||
|
@ -1427,7 +1425,7 @@ Music LoadMusicStreamFromMemory(const char *fileType, unsigned char *data, int d
|
|||
}
|
||||
#endif
|
||||
#if defined(SUPPORT_FILEFORMAT_MP3)
|
||||
else if (TextIsEqual(fileExtLower, ".mp3"))
|
||||
else if (strcmp(fileType, ".mp3") == 0)
|
||||
{
|
||||
drmp3 *ctxMp3 = RL_CALLOC(1, sizeof(drmp3));
|
||||
int success = drmp3_init_memory(ctxMp3, (const void*)data, dataSize, NULL);
|
||||
|
@ -1445,7 +1443,7 @@ Music LoadMusicStreamFromMemory(const char *fileType, unsigned char *data, int d
|
|||
}
|
||||
#endif
|
||||
#if defined(SUPPORT_FILEFORMAT_OGG)
|
||||
else if (TextIsEqual(fileExtLower, ".ogg"))
|
||||
else if (strcmp(fileType, ".ogg") == 0)
|
||||
{
|
||||
// Open ogg audio stream
|
||||
music.ctxType = MUSIC_AUDIO_OGG;
|
||||
|
@ -1467,7 +1465,7 @@ Music LoadMusicStreamFromMemory(const char *fileType, unsigned char *data, int d
|
|||
}
|
||||
#endif
|
||||
#if defined(SUPPORT_FILEFORMAT_XM)
|
||||
else if (TextIsEqual(fileExtLower, ".xm"))
|
||||
else if (strcmp(fileType, ".xm") == 0)
|
||||
{
|
||||
jar_xm_context_t *ctxXm = NULL;
|
||||
int result = jar_xm_create_context_safe(&ctxXm, (const char *)data, dataSize, AUDIO.System.device.sampleRate);
|
||||
|
@ -1494,7 +1492,7 @@ Music LoadMusicStreamFromMemory(const char *fileType, unsigned char *data, int d
|
|||
}
|
||||
#endif
|
||||
#if defined(SUPPORT_FILEFORMAT_MOD)
|
||||
else if (TextIsEqual(fileExtLower, ".mod"))
|
||||
else if (strcmp(fileType, ".mod") == 0)
|
||||
{
|
||||
jar_mod_context_t *ctxMod = (jar_mod_context_t *)RL_MALLOC(sizeof(jar_mod_context_t));
|
||||
int result = 0;
|
||||
|
@ -2261,38 +2259,6 @@ static const char *GetFileExtension(const char *fileName)
|
|||
return dot;
|
||||
}
|
||||
|
||||
// Check if two text string are equal
|
||||
// REQUIRES: strcmp()
|
||||
static bool TextIsEqual(const char *text1, const char *text2)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
if (strcmp(text1, text2) == 0) result = true;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Get lower case version of provided string
|
||||
// REQUIRES: tolower()
|
||||
static const char *TextToLower(const char *text)
|
||||
{
|
||||
#define MAX_TEXT_BUFFER_LENGTH 1024
|
||||
|
||||
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
||||
|
||||
for (int i = 0; i < MAX_TEXT_BUFFER_LENGTH; i++)
|
||||
{
|
||||
if (text[i] != '\0')
|
||||
{
|
||||
buffer[i] = (char)tolower(text[i]);
|
||||
//if ((text[i] >= 'A') && (text[i] <= 'Z')) buffer[i] = text[i] + 32;
|
||||
}
|
||||
else { buffer[i] = '\0'; break; }
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
// Load data from file into a buffer
|
||||
static unsigned char *LoadFileData(const char *fileName, unsigned int *bytesRead)
|
||||
{
|
||||
|
@ -2378,3 +2344,5 @@ static bool SaveFileText(const char *fileName, char *text)
|
|||
#endif
|
||||
|
||||
#undef AudioBuffer
|
||||
|
||||
#endif // SUPPORT_MODULE_RAUDIO
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue