72#if defined(RAUDIO_STANDALONE)
78 #if !defined(EXTERNAL_CONFIG_FLAGS)
84#if defined(SUPPORT_MODULE_RAUDIO)
94#define NOVIRTUALKEYCODES
130#define NODEFERWINDOWPOS
134typedef struct tagMSG *LPMSG;
139typedef struct tagBITMAPINFOHEADER {
147 LONG biXPelsPerMeter;
148 LONG biYPelsPerMeter;
150 DWORD biClrImportant;
151} BITMAPINFOHEADER, *PBITMAPINFOHEADER;
158#if defined(_MSC_VER) || defined(__TINYC__)
163#define MA_MALLOC RL_MALLOC
164#define MA_FREE RL_FREE
170#define MINIAUDIO_IMPLEMENTATION
179#if defined(RAUDIO_STANDALONE)
181 #define TRACELOG(level, ...) (void)0
186 #define RL_MALLOC(sz) malloc(sz)
189 #define RL_CALLOC(n,sz) calloc(n,sz)
192 #define RL_REALLOC(ptr,sz) realloc(ptr,sz)
195 #define RL_FREE(ptr) free(ptr)
199#if defined(SUPPORT_FILEFORMAT_OGG)
202 #define STB_VORBIS_IMPLEMENTATION
206#if defined(SUPPORT_FILEFORMAT_XM)
207 #define JARXM_MALLOC RL_MALLOC
208 #define JARXM_FREE RL_FREE
210 #define JAR_XM_IMPLEMENTATION
214#if defined(SUPPORT_FILEFORMAT_MOD)
215 #define JARMOD_MALLOC RL_MALLOC
216 #define JARMOD_FREE RL_FREE
218 #define JAR_MOD_IMPLEMENTATION
222#if defined(SUPPORT_FILEFORMAT_WAV)
223 #define DRWAV_MALLOC RL_MALLOC
224 #define DRWAV_REALLOC RL_REALLOC
225 #define DRWAV_FREE RL_FREE
227 #define DR_WAV_IMPLEMENTATION
231#if defined(SUPPORT_FILEFORMAT_MP3)
232 #define DRMP3_MALLOC RL_MALLOC
233 #define DRMP3_REALLOC RL_REALLOC
234 #define DRMP3_FREE RL_FREE
236 #define DR_MP3_IMPLEMENTATION
240#if defined(SUPPORT_FILEFORMAT_FLAC)
241 #define DRFLAC_MALLOC RL_MALLOC
242 #define DRFLAC_REALLOC RL_REALLOC
243 #define DRFLAC_FREE RL_FREE
245 #define DR_FLAC_IMPLEMENTATION
246 #define DR_FLAC_NO_WIN32_IO
257#ifndef AUDIO_DEVICE_FORMAT
258 #define AUDIO_DEVICE_FORMAT ma_format_f32
260#ifndef AUDIO_DEVICE_CHANNELS
261 #define AUDIO_DEVICE_CHANNELS 2
263#ifndef AUDIO_DEVICE_SAMPLE_RATE
264 #define AUDIO_DEVICE_SAMPLE_RATE 0
267#ifndef MAX_AUDIO_BUFFER_POOL_CHANNELS
268 #define MAX_AUDIO_BUFFER_POOL_CHANNELS 16
270#ifndef DEFAULT_AUDIO_BUFFER_SIZE
271 #define DEFAULT_AUDIO_BUFFER_SIZE 4096
292#if defined(RAUDIO_STANDALONE)
349#define AudioBuffer rAudioBuffer
386static void OnLog(
void *pUserData,
ma_uint32 level,
const char *pMessage);
387static void OnSendAudioDataToDevice(
ma_device *pDevice,
void *pFramesOut,
const void *pFramesInput,
ma_uint32 frameCount);
388static void MixAudioFrames(
float *framesOut,
const float *framesIn,
ma_uint32 frameCount,
AudioBuffer *buffer);
390#if defined(RAUDIO_STANDALONE)
394static unsigned char *
LoadFileData(
const char *fileName,
unsigned int *bytesRead);
395static bool SaveFileData(
const char *fileName,
void *data,
unsigned int bytesToWrite);
396static bool SaveFileText(
const char *fileName,
char *text);
520 else TRACELOG(
LOG_WARNING,
"AUDIO: Device could not be closed, not currently initialized");
544 if (audioBuffer ==
NULL)
566 audioBuffer->volume = 1.0f;
567 audioBuffer->pitch = 1.0f;
568 audioBuffer->pan = 0.5f;
570 audioBuffer->callback =
NULL;
571 audioBuffer->processor =
NULL;
573 audioBuffer->playing =
false;
574 audioBuffer->paused =
false;
575 audioBuffer->looping =
false;
577 audioBuffer->usage = usage;
578 audioBuffer->frameCursorPos = 0;
579 audioBuffer->sizeInFrames = sizeInFrames;
583 audioBuffer->isSubBufferProcessed[0] =
true;
584 audioBuffer->isSubBufferProcessed[1] =
true;
609 if (buffer !=
NULL) result = (buffer->playing && !buffer->paused);
621 buffer->playing =
true;
622 buffer->paused =
false;
623 buffer->frameCursorPos = 0;
634 buffer->playing =
false;
635 buffer->paused =
false;
636 buffer->frameCursorPos = 0;
637 buffer->framesProcessed = 0;
638 buffer->isSubBufferProcessed[0] =
true;
639 buffer->isSubBufferProcessed[1] =
true;
647 if (buffer !=
NULL) buffer->paused =
true;
653 if (buffer !=
NULL) buffer->paused =
false;
659 if (buffer !=
NULL) buffer->volume = volume;
665 if ((buffer !=
NULL) && (pitch > 0.0f))
671 ma_uint32 outputSampleRate = (
ma_uint32)((
float)buffer->converter.sampleRateOut/pitch);
674 buffer->pitch = pitch;
681 if (pan < 0.0f) pan = 0.0f;
682 else if (pan > 1.0f) pan = 1.0f;
684 if (buffer !=
NULL) buffer->pan = pan;
710 else buffer->prev->next = buffer->next;
713 else buffer->next->prev = buffer->prev;
731 unsigned int fileSize = 0;
732 unsigned char *fileData =
LoadFileData(fileName, &fileSize);
749#if defined(SUPPORT_FILEFORMAT_WAV)
750 else if (strcmp(fileType,
".wav") == 0)
771#if defined(SUPPORT_FILEFORMAT_OGG)
772 else if (strcmp(fileType,
".ogg") == 0)
793#if defined(SUPPORT_FILEFORMAT_FLAC)
794 else if (strcmp(fileType,
".flac") == 0)
796 unsigned long long int totalFrameCount = 0;
806#if defined(SUPPORT_FILEFORMAT_MP3)
807 else if (strcmp(fileType,
".mp3") == 0)
810 unsigned long long int totalFrameCount = 0;
867 if (frameCount == 0)
TRACELOG(
LOG_WARNING,
"SOUND: Failed to get frame count for format conversion");
870 if (audioBuffer ==
NULL)
918 bool success =
false;
921#if defined(SUPPORT_FILEFORMAT_WAV)
933 void *fileData =
NULL;
934 size_t fileDataSize = 0;
951 if (success)
TRACELOG(
LOG_INFO,
"FILEIO: [%s] Wave data exported successfully", fileName);
960 bool success =
false;
962#ifndef TEXT_BYTES_PER_LINE
963 #define TEXT_BYTES_PER_LINE 20
970 char *txtData = (
char *)
RL_CALLOC(waveDataSize*6 + 2000,
sizeof(
char));
973 byteCount += sprintf(txtData + byteCount,
"\n//////////////////////////////////////////////////////////////////////////////////\n");
974 byteCount += sprintf(txtData + byteCount,
"// //\n");
975 byteCount += sprintf(txtData + byteCount,
"// WaveAsCode exporter v1.1 - Wave data exported as an array of bytes //\n");
976 byteCount += sprintf(txtData + byteCount,
"// //\n");
977 byteCount += sprintf(txtData + byteCount,
"// more info and bugs-report: github.com/raysan5/raylib //\n");
978 byteCount += sprintf(txtData + byteCount,
"// feedback and support: ray[at]raylib.com //\n");
979 byteCount += sprintf(txtData + byteCount,
"// //\n");
980 byteCount += sprintf(txtData + byteCount,
"// Copyright (c) 2018-2022 Ramon Santamaria (@raysan5) //\n");
981 byteCount += sprintf(txtData + byteCount,
"// //\n");
982 byteCount += sprintf(txtData + byteCount,
"//////////////////////////////////////////////////////////////////////////////////\n\n");
984 char fileNameLower[256] = { 0 };
985 char fileNameUpper[256] = { 0 };
986 for (
int i = 0; fileName[i] !=
'.'; i++) { fileNameLower[i] = fileName[i]; }
987 for (
int i = 0; fileNameLower[i] !=
'\0'; i++)
if (fileNameLower[i] >=
'a' && fileNameLower[i] <=
'z') { fileNameUpper[i] = fileNameLower[i] - 32; }
989 byteCount += sprintf(txtData + byteCount,
"// Wave data information\n");
990 byteCount += sprintf(txtData + byteCount,
"#define %s_FRAME_COUNT %u\n", fileNameUpper, wave.
frameCount);
991 byteCount += sprintf(txtData + byteCount,
"#define %s_SAMPLE_RATE %u\n", fileNameUpper, wave.
sampleRate);
992 byteCount += sprintf(txtData + byteCount,
"#define %s_SAMPLE_SIZE %u\n", fileNameUpper, wave.
sampleSize);
993 byteCount += sprintf(txtData + byteCount,
"#define %s_CHANNELS %u\n\n", fileNameUpper, wave.
channels);
1000 byteCount += sprintf(txtData + byteCount,
"static float %sData[%i] = {\n", fileNameLower, waveDataSize/4);
1001 for (
int i = 1; i < waveDataSize/4; i++) byteCount += sprintf(txtData + byteCount, ((i%
TEXT_BYTES_PER_LINE == 0)?
"%.4ff,\n " :
"%.4ff, "), ((
float *)wave.
data)[i - 1]);
1002 byteCount += sprintf(txtData + byteCount,
"%.4ff };\n", ((
float *)wave.
data)[waveDataSize/4 - 1]);
1006 byteCount += sprintf(txtData + byteCount,
"static unsigned char %sData[%i] = { ", fileNameLower, waveDataSize);
1007 for (
int i = 1; i < waveDataSize; i++) byteCount += sprintf(txtData + byteCount, ((i%
TEXT_BYTES_PER_LINE == 0)?
"0x%x,\n " :
"0x%x, "), ((
unsigned char *)wave.
data)[i - 1]);
1008 byteCount += sprintf(txtData + byteCount,
"0x%x };\n", ((
unsigned char *)wave.
data)[waveDataSize - 1]);
1016 if (success != 0)
TRACELOG(
LOG_INFO,
"FILEIO: [%s] Wave as code exported successfully", fileName);
1032 unsigned int oldAge = 0;
1059 TRACELOG(
LOG_WARNING,
"SOUND: Buffer pool could not determine oldest buffer not playing sound");
1161 if (frameCount == 0)
1167 void *data =
RL_MALLOC(frameCount*channels*(sampleSize/8));
1170 if (frameCount == 0)
1187 Wave newWave = { 0 };
1209 if ((initSample >= 0) && (initSample < finalSample) &&
1210 (finalSample > 0) && ((
unsigned int)finalSample < (wave->
frameCount*wave->
channels)))
1212 int sampleCount = finalSample - initSample;
1235 if (wave.
sampleSize == 8) samples[i] = (float)(((
unsigned char *)wave.
data)[i] - 127)/256.0f;
1236 else if (wave.
sampleSize == 16) samples[i] = (float)(((
short *)wave.
data)[i])/32767.0f;
1237 else if (wave.
sampleSize == 32) samples[i] = ((
float *)wave.
data)[i];
1256 Music music = { 0 };
1257 bool musicLoaded =
false;
1260#if defined(SUPPORT_FILEFORMAT_WAV)
1281#if defined(SUPPORT_FILEFORMAT_OGG)
1302#if defined(SUPPORT_FILEFORMAT_FLAC)
1319#if defined(SUPPORT_FILEFORMAT_MP3)
1337#if defined(SUPPORT_FILEFORMAT_XM)
1350 unsigned int bits = 32;
1358 jar_xm_reset(ctxXm);
1363#if defined(SUPPORT_FILEFORMAT_MOD)
1388 #if defined(SUPPORT_FILEFORMAT_WAV)
1391 #if defined(SUPPORT_FILEFORMAT_OGG)
1394 #if defined(SUPPORT_FILEFORMAT_FLAC)
1397 #if defined(SUPPORT_FILEFORMAT_MP3)
1400 #if defined(SUPPORT_FILEFORMAT_XM)
1403 #if defined(SUPPORT_FILEFORMAT_MOD)
1413 TRACELOG(
LOG_INFO,
"FILEIO: [%s] Music file loaded successfully", fileName);
1427 Music music = { 0 };
1428 bool musicLoaded =
false;
1431#if defined(SUPPORT_FILEFORMAT_WAV)
1432 else if (strcmp(fileType,
".wav") == 0)
1453#if defined(SUPPORT_FILEFORMAT_FLAC)
1454 else if (strcmp(fileType,
".flac") == 0)
1470#if defined(SUPPORT_FILEFORMAT_MP3)
1471 else if (strcmp(fileType,
".mp3") == 0)
1488#if defined(SUPPORT_FILEFORMAT_OGG)
1489 else if (strcmp(fileType,
".ogg") == 0)
1510#if defined(SUPPORT_FILEFORMAT_XM)
1511 else if (strcmp(fileType,
".xm") == 0)
1520 unsigned int bits = 32;
1530 jar_xm_reset(ctxXm);
1537#if defined(SUPPORT_FILEFORMAT_MOD)
1538 else if (strcmp(fileType,
".mod") == 0)
1546 unsigned char *newData = (
unsigned char *)
RL_MALLOC(dataSize);
1547 int it = dataSize/
sizeof(
unsigned char);
1548 for (
int i = 0; i < it; i++) newData[i] = data[i];
1551 if (dataSize && dataSize < 32*1024*1024)
1555 if (jar_mod_load(ctxMod, (
void *)ctxMod->
modfile, dataSize)) result = dataSize;
1578 #if defined(SUPPORT_FILEFORMAT_WAV)
1581 #if defined(SUPPORT_FILEFORMAT_FLAC)
1584 #if defined(SUPPORT_FILEFORMAT_MP3)
1587 #if defined(SUPPORT_FILEFORMAT_OGG)
1590 #if defined(SUPPORT_FILEFORMAT_XM)
1593 #if defined(SUPPORT_FILEFORMAT_MOD)
1621#if defined(SUPPORT_FILEFORMAT_WAV)
1624#if defined(SUPPORT_FILEFORMAT_OGG)
1627#if defined(SUPPORT_FILEFORMAT_FLAC)
1630#if defined(SUPPORT_FILEFORMAT_MP3)
1633#if defined(SUPPORT_FILEFORMAT_XM)
1636#if defined(SUPPORT_FILEFORMAT_MOD)
1676#if defined(SUPPORT_FILEFORMAT_WAV)
1679#if defined(SUPPORT_FILEFORMAT_OGG)
1682#if defined(SUPPORT_FILEFORMAT_FLAC)
1685#if defined(SUPPORT_FILEFORMAT_MP3)
1688#if defined(SUPPORT_FILEFORMAT_XM)
1691#if defined(SUPPORT_FILEFORMAT_MOD)
1704 unsigned int positionInFrames = (
unsigned int)(position*music.
stream.
sampleRate);
1708#if defined(SUPPORT_FILEFORMAT_WAV)
1711#if defined(SUPPORT_FILEFORMAT_OGG)
1714#if defined(SUPPORT_FILEFORMAT_FLAC)
1717#if defined(SUPPORT_FILEFORMAT_MP3)
1731 bool streamEnding =
false;
1737 int frameCountToStream = 0;
1745 if (framesLeft >= subBufferSizeInFrames) frameCountToStream = subBufferSizeInFrames;
1746 else frameCountToStream = framesLeft;
1750 #if defined(SUPPORT_FILEFORMAT_WAV)
1759 #if defined(SUPPORT_FILEFORMAT_OGG)
1767 #if defined(SUPPORT_FILEFORMAT_FLAC)
1775 #if defined(SUPPORT_FILEFORMAT_MP3)
1782 #if defined(SUPPORT_FILEFORMAT_XM)
1792 #if defined(SUPPORT_FILEFORMAT_MOD)
1804 framesLeft -= frameCountToStream;
1806 if (framesLeft <= 0)
1808 streamEnding =
true;
1857 float totalSeconds = 0.0f;
1861 return totalSeconds;
1867 float secondsPlayed = 0.0f;
1870 #if defined(SUPPORT_FILEFORMAT_XM)
1887 return secondsPlayed;
1907 if (subBufferSize < periodSize) subBufferSize = periodSize;
1917 else TRACELOG(
LOG_WARNING,
"STREAM: Failed to load audio buffer, stream could not be created");
1945 subBufferToUpdate = 0;
1962 if (subBufferSizeInFrames >= (
ma_uint32)frameCount)
1964 ma_uint32 framesToWrite = subBufferSizeInFrames;
1969 memcpy(subBuffer, data, bytesToWrite);
1972 ma_uint32 leftoverFrameCount = subBufferSizeInFrames - framesToWrite;
1974 if (leftoverFrameCount > 0) memset(subBuffer + bytesToWrite, 0, leftoverFrameCount*stream.
channels*(stream.
sampleSize/8));
2064 while (last && last->
next)
2070 processor->
prev = last;
2071 last->
next = processor;
2089 if (processor->
process == process)
2092 if (prev) prev->
next = next;
2093 if (next) next->
prev = prev;
2109static void OnLog(
void *pUserData,
ma_uint32 level,
const char *pMessage)
2118 if (audioBuffer->callback)
2120 audioBuffer->callback(framesOut, frameCount);
2121 audioBuffer->framesProcessed += frameCount;
2126 ma_uint32 subBufferSizeInFrames = (audioBuffer->sizeInFrames > 1)? audioBuffer->sizeInFrames/2 : audioBuffer->sizeInFrames;
2127 ma_uint32 currentSubBufferIndex = audioBuffer->frameCursorPos/subBufferSizeInFrames;
2129 if (currentSubBufferIndex > 1)
return 0;
2133 bool isSubBufferProcessed[2] = { 0 };
2134 isSubBufferProcessed[0] = audioBuffer->isSubBufferProcessed[0];
2135 isSubBufferProcessed[1] = audioBuffer->isSubBufferProcessed[1];
2137 ma_uint32 frameSizeInBytes = ma_get_bytes_per_frame(audioBuffer->converter.formatIn, audioBuffer->converter.channelsIn);
2149 if (framesRead >= frameCount)
break;
2153 if (isSubBufferProcessed[currentSubBufferIndex])
break;
2156 ma_uint32 totalFramesRemaining = (frameCount - framesRead);
2157 if (totalFramesRemaining == 0)
break;
2159 ma_uint32 framesRemainingInOutputBuffer;
2162 framesRemainingInOutputBuffer = audioBuffer->sizeInFrames - audioBuffer->frameCursorPos;
2166 ma_uint32 firstFrameIndexOfThisSubBuffer = subBufferSizeInFrames*currentSubBufferIndex;
2167 framesRemainingInOutputBuffer = subBufferSizeInFrames - (audioBuffer->frameCursorPos - firstFrameIndexOfThisSubBuffer);
2170 ma_uint32 framesToRead = totalFramesRemaining;
2171 if (framesToRead > framesRemainingInOutputBuffer) framesToRead = framesRemainingInOutputBuffer;
2173 memcpy((
unsigned char *)framesOut + (framesRead*frameSizeInBytes), audioBuffer->data + (audioBuffer->frameCursorPos*frameSizeInBytes), framesToRead*frameSizeInBytes);
2174 audioBuffer->frameCursorPos = (audioBuffer->frameCursorPos + framesToRead)%audioBuffer->sizeInFrames;
2175 framesRead += framesToRead;
2178 if (framesToRead == framesRemainingInOutputBuffer)
2180 audioBuffer->isSubBufferProcessed[currentSubBufferIndex] =
true;
2181 isSubBufferProcessed[currentSubBufferIndex] =
true;
2183 currentSubBufferIndex = (currentSubBufferIndex + 1)%2;
2186 if (!audioBuffer->looping)
2195 ma_uint32 totalFramesRemaining = (frameCount - framesRead);
2196 if (totalFramesRemaining > 0)
2198 memset((
unsigned char *)framesOut + (framesRead*frameSizeInBytes), 0, totalFramesRemaining*frameSizeInBytes);
2216 ma_uint8 inputBuffer[4096] = { 0 };
2217 ma_uint32 inputBufferFrameCap =
sizeof(inputBuffer)/ma_get_bytes_per_frame(audioBuffer->converter.formatIn, audioBuffer->converter.channelsIn);
2219 ma_uint32 totalOutputFramesProcessed = 0;
2220 while (totalOutputFramesProcessed < frameCount)
2222 ma_uint64 outputFramesToProcessThisIteration = frameCount - totalOutputFramesProcessed;
2223 ma_uint64 inputFramesToProcessThisIteration = 0;
2226 if (inputFramesToProcessThisIteration > inputBufferFrameCap)
2228 inputFramesToProcessThisIteration = inputBufferFrameCap;
2231 float *runningFramesOut = framesOut + (totalOutputFramesProcessed*audioBuffer->converter.channelsOut);
2234 ma_uint64 inputFramesProcessedThisIteration = ReadAudioBufferFramesInInternalFormat(audioBuffer, inputBuffer, (
ma_uint32)inputFramesToProcessThisIteration);
2235 ma_uint64 outputFramesProcessedThisIteration = outputFramesToProcessThisIteration;
2238 totalOutputFramesProcessed += (
ma_uint32)outputFramesProcessedThisIteration;
2240 if (inputFramesProcessedThisIteration < inputFramesToProcessThisIteration)
2246 if (inputFramesProcessedThisIteration == 0 && outputFramesProcessedThisIteration == 0)
2252 return totalOutputFramesProcessed;
2259static void OnSendAudioDataToDevice(
ma_device *pDevice,
void *pFramesOut,
const void *pFramesInput,
ma_uint32 frameCount)
2273 if (!audioBuffer->playing || audioBuffer->paused)
continue;
2279 if (framesRead >= frameCount)
break;
2282 ma_uint32 framesToRead = (frameCount - framesRead);
2284 while (framesToRead > 0)
2286 float tempBuffer[1024] = { 0 };
2288 ma_uint32 framesToReadRightNow = framesToRead;
2294 ma_uint32 framesJustRead = ReadAudioBufferFramesInMixingFormat(audioBuffer, tempBuffer, framesToReadRightNow);
2295 if (framesJustRead > 0)
2298 float *framesIn = tempBuffer;
2304 processor->
process(framesIn, framesJustRead);
2305 processor = processor->
next;
2308 MixAudioFrames(framesOut, framesIn, framesJustRead, audioBuffer);
2310 framesToRead -= framesJustRead;
2311 framesRead += framesJustRead;
2314 if (!audioBuffer->playing)
2316 framesRead = frameCount;
2321 if (framesJustRead < framesToReadRightNow)
2323 if (!audioBuffer->looping)
2332 audioBuffer->frameCursorPos = 0;
2340 if (framesToRead > 0)
break;
2350static void MixAudioFrames(
float *framesOut,
const float *framesIn,
ma_uint32 frameCount,
AudioBuffer *buffer)
2352 const float localVolume = buffer->volume;
2357 const float left = buffer->pan;
2358 const float right = 1.0f - left;
2361 const float levels[2] = { localVolume*0.5f*left*(3.0f - left*left), localVolume*0.5f*right*(3.0f - right*right) };
2363 float *frameOut = framesOut;
2364 const float *frameIn = framesIn;
2366 for (
ma_uint32 frame = 0; frame < frameCount; frame++)
2368 frameOut[0] += (frameIn[0]*levels[0]);
2369 frameOut[1] += (frameIn[1]*levels[1]);
2377 for (
ma_uint32 frame = 0; frame < frameCount; frame++)
2379 for (
ma_uint32 c = 0; c < channels; c++)
2381 float *frameOut = framesOut + (frame*channels);
2382 const float *frameIn = framesIn + (frame*channels);
2385 frameOut[c] += (frameIn[c]*localVolume);
2392#if defined(RAUDIO_STANDALONE)
2396 bool result =
false;
2397 const char *fileExt;
2399 if ((fileExt = strrchr(fileName,
'.')) !=
NULL)
2401 if (strcmp(fileExt, ext) == 0) result =
true;
2410 const char *dot = strrchr(fileName,
'.');
2412 if (!dot || dot == fileName)
return NULL;
2418static unsigned char *
LoadFileData(
const char *fileName,
unsigned int *bytesRead)
2420 unsigned char *data =
NULL;
2423 if (fileName !=
NULL)
2425 FILE *file = fopen(fileName,
"rb");
2431 fseek(file, 0, SEEK_END);
2432 int size = ftell(file);
2433 fseek(file, 0, SEEK_SET);
2437 data = (
unsigned char *)
RL_MALLOC(size*
sizeof(
unsigned char));
2440 unsigned int count = (
unsigned int)fread(data,
sizeof(
unsigned char), size, file);
2444 else TRACELOG(
LOG_INFO,
"FILEIO: [%s] File loaded successfully", fileName);
2458static bool SaveFileData(
const char *fileName,
void *data,
unsigned int bytesToWrite)
2460 if (fileName !=
NULL)
2462 FILE *file = fopen(fileName,
"wb");
2466 unsigned int count = (
unsigned int)fwrite(data,
sizeof(
unsigned char), bytesToWrite, file);
2469 else if (count != bytesToWrite)
TRACELOG(
LOG_WARNING,
"FILEIO: [%s] File partially written", fileName);
2480static bool SaveFileText(
const char *fileName,
char *text)
2482 if (fileName !=
NULL)
2484 FILE *file = fopen(fileName,
"wt");
2488 int count = fprintf(file,
"%s", text);
2490 if (count == 0)
TRACELOG(
LOG_WARNING,
"FILEIO: [%s] Failed to write text file", fileName);
2491 else TRACELOG(
LOG_INFO,
"FILEIO: [%s] Text file saved successfully", fileName);
#define AUDIO_DEVICE_CHANNELS
#define AUDIO_DEVICE_SAMPLE_RATE
#define AUDIO_DEVICE_FORMAT
#define MAX_AUDIO_BUFFER_POOL_CHANNELS
DRFLAC_API drflac_bool32 drflac_seek_to_pcm_frame(drflac *pFlac, drflac_uint64 pcmFrameIndex)
DRFLAC_API drflac_uint64 drflac_read_pcm_frames_s16(drflac *pFlac, drflac_uint64 framesToRead, drflac_int16 *pBufferOut)
DRFLAC_API void drflac_free(void *p, const drflac_allocation_callbacks *pAllocationCallbacks)
DRFLAC_API drflac_int16 * drflac_open_memory_and_read_pcm_frames_s16(const void *data, size_t dataSize, unsigned int *channels, unsigned int *sampleRate, drflac_uint64 *totalPCMFrameCount, const drflac_allocation_callbacks *pAllocationCallbacks)
DRFLAC_API drflac * drflac_open_memory(const void *pData, size_t dataSize, const drflac_allocation_callbacks *pAllocationCallbacks)
DRFLAC_API drflac * drflac_open_file(const char *pFileName, const drflac_allocation_callbacks *pAllocationCallbacks)
DRMP3_API drmp3_uint64 drmp3_read_pcm_frames_f32(drmp3 *pMP3, drmp3_uint64 framesToRead, float *pBufferOut)
DRMP3_API drmp3_bool32 drmp3_init_file(drmp3 *pMP3, const char *pFilePath, const drmp3_allocation_callbacks *pAllocationCallbacks)
DRMP3_API void drmp3_uninit(drmp3 *pMP3)
DRMP3_API float * drmp3_open_memory_and_read_pcm_frames_f32(const void *pData, size_t dataSize, drmp3_config *pConfig, drmp3_uint64 *pTotalFrameCount, const drmp3_allocation_callbacks *pAllocationCallbacks)
DRMP3_API drmp3_bool32 drmp3_init_memory(drmp3 *pMP3, const void *pData, size_t dataSize, const drmp3_allocation_callbacks *pAllocationCallbacks)
DRMP3_API drmp3_uint64 drmp3_get_pcm_frame_count(drmp3 *pMP3)
DRMP3_API drmp3_bool32 drmp3_seek_to_pcm_frame(drmp3 *pMP3, drmp3_uint64 frameIndex)
DRWAV_API void drwav_free(void *p, const drwav_allocation_callbacks *pAllocationCallbacks)
DRWAV_API drwav_uint64 drwav_read_pcm_frames_f32(drwav *pWav, drwav_uint64 framesToRead, float *pBufferOut)
DRWAV_API drwav_bool32 drwav_init_memory_write(drwav *pWav, void **ppData, size_t *pDataSize, const drwav_data_format *pFormat, const drwav_allocation_callbacks *pAllocationCallbacks)
DRWAV_API drwav_bool32 drwav_init_memory(drwav *pWav, const void *data, size_t dataSize, const drwav_allocation_callbacks *pAllocationCallbacks)
#define DR_WAVE_FORMAT_PCM
DRWAV_API drwav_bool32 drwav_init_file(drwav *pWav, const char *filename, const drwav_allocation_callbacks *pAllocationCallbacks)
DRWAV_API drwav_bool32 drwav_seek_to_pcm_frame(drwav *pWav, drwav_uint64 targetFrameIndex)
DRWAV_API drwav_uint64 drwav_read_pcm_frames_s16(drwav *pWav, drwav_uint64 framesToRead, drwav_int16 *pBufferOut)
DRWAV_API drwav_result drwav_uninit(drwav *pWav)
DRWAV_API drwav_uint64 drwav_write_pcm_frames(drwav *pWav, drwav_uint64 framesToWrite, const void *pData)
#define DR_WAVE_FORMAT_IEEE_FLOAT
void jar_mod_unload(jar_mod_context_t *modctx)
mulong jar_mod_max_samples(jar_mod_context_t *modctx)
void jar_mod_fillbuffer(jar_mod_context_t *modctx, short *outbuffer, unsigned long nbsample, jar_mod_tracker_buffer_state *trkbuf)
mulong jar_mod_load_file(jar_mod_context_t *modctx, const char *filename)
void jar_mod_seek_start(jar_mod_context_t *ctx)
bool jar_mod_init(jar_mod_context_t *modctx)
void jar_xm_set_max_loop_count(jar_xm_context_t *ctx, uint8_t loopcnt)
void jar_xm_free_context(jar_xm_context_t *ctx)
void jar_xm_get_position(jar_xm_context_t *ctx, uint8_t *pattern_index, uint8_t *pattern, uint8_t *row, uint64_t *samples)
void jar_xm_generate_samples(jar_xm_context_t *ctx, float *output, size_t numsamples)
void jar_xm_generate_samples_16bit(jar_xm_context_t *ctx, short *output, size_t numsamples)
int jar_xm_create_context_safe(jar_xm_context_t **ctx, const char *moddata, size_t moddata_length, uint32_t rate)
void jar_xm_generate_samples_8bit(jar_xm_context_t *ctx, char *output, size_t numsamples)
uint64_t jar_xm_get_remaining_samples(jar_xm_context_t *ctx)
struct jar_xm_context_s jar_xm_context_t
int jar_xm_create_context_from_file(jar_xm_context_t **ctx, uint32_t rate, const char *filename)
MA_API ma_uint32 ma_get_bytes_per_sample(ma_format format)
MA_API void ma_device_uninit(ma_device *pDevice)
MA_API ma_result ma_data_converter_set_rate(ma_data_converter *pConverter, ma_uint32 sampleRateIn, ma_uint32 sampleRateOut)
MA_API void ma_mutex_unlock(ma_mutex *pMutex)
MA_API ma_uint64 ma_convert_frames(void *pOut, ma_uint64 frameCountOut, ma_format formatOut, ma_uint32 channelsOut, ma_uint32 sampleRateOut, const void *pIn, ma_uint64 frameCountIn, ma_format formatIn, ma_uint32 channelsIn, ma_uint32 sampleRateIn)
Conversion Helpers.
MA_API ma_data_converter_config ma_data_converter_config_init(ma_format formatIn, ma_format formatOut, ma_uint32 channelsIn, ma_uint32 channelsOut, ma_uint32 sampleRateIn, ma_uint32 sampleRateOut)
MA_API ma_result ma_context_uninit(ma_context *pContext)
MA_API const char * ma_get_backend_name(ma_backend backend)
MA_API ma_context_config ma_context_config_init(void)
MA_API void ma_data_converter_uninit(ma_data_converter *pConverter, const ma_allocation_callbacks *pAllocationCallbacks)
unsigned long long ma_uint64
MA_API void ma_mutex_uninit(ma_mutex *pMutex)
@ ma_device_type_playback
MA_API ma_result ma_data_converter_init(const ma_data_converter_config *pConfig, const ma_allocation_callbacks *pAllocationCallbacks, ma_data_converter *pConverter)
MA_API ma_result ma_context_init(const ma_backend backends[], ma_uint32 backendCount, const ma_context_config *pConfig, ma_context *pContext)
MA_API ma_result ma_mutex_init(ma_mutex *pMutex)
MA_API ma_result ma_data_converter_process_pcm_frames(ma_data_converter *pConverter, const void *pFramesIn, ma_uint64 *pFrameCountIn, void *pFramesOut, ma_uint64 *pFrameCountOut)
MA_API void ma_mutex_lock(ma_mutex *pMutex)
MA_API ma_result ma_data_converter_get_required_input_frame_count(const ma_data_converter *pConverter, ma_uint64 outputFrameCount, ma_uint64 *pInputFrameCount)
MA_API ma_device_config ma_device_config_init(ma_device_type deviceType)
MA_API ma_result ma_device_init(ma_context *pContext, const ma_device_config *pConfig, ma_device *pDevice)
MA_API ma_log_callback ma_log_callback_init(ma_log_callback_proc onLog, void *pUserData)
MA_API ma_result ma_device_start(ma_device *pDevice)
ma_pthread_mutex_t ma_mutex
MA_API ma_result ma_device_set_master_volume(ma_device *pDevice, float volume)
MA_API const char * ma_get_format_name(ma_format format)
void SetAudioStreamVolume(AudioStream stream, float volume)
bool IsAudioStreamPlaying(AudioStream stream)
void WaveFormat(Wave *wave, int sampleRate, int sampleSize, int channels)
void SetSoundPitch(Sound sound, float pitch)
void SetAudioBufferPitch(AudioBuffer *buffer, float pitch)
void UpdateMusicStream(Music music)
void PauseAudioBuffer(AudioBuffer *buffer)
void StopAudioStream(AudioStream stream)
void InitAudioDevice(void)
void AttachAudioStreamProcessor(AudioStream stream, AudioCallback process)
bool IsAudioBufferPlaying(AudioBuffer *buffer)
void WaveCrop(Wave *wave, int initSample, int finalSample)
void StopMusicStream(Music music)
void StopSoundMulti(void)
Wave LoadWave(const char *fileName)
int GetSoundsPlaying(void)
void ResumeAudioStream(AudioStream stream)
void SetAudioStreamBufferSizeDefault(int size)
void ResumeAudioBuffer(AudioBuffer *buffer)
void UnloadAudioBuffer(AudioBuffer *buffer)
void SetMusicPan(Music music, float pan)
void SetSoundPan(Sound sound, float pan)
void PlayAudioStream(AudioStream stream)
void PlayMusicStream(Music music)
void SetSoundVolume(Sound sound, float volume)
void ResumeMusicStream(Music music)
float GetMusicTimeLength(Music music)
void SetMasterVolume(float volume)
bool IsSoundPlaying(Sound sound)
void StopSound(Sound sound)
void UnloadWaveSamples(float *samples)
void ResumeSound(Sound sound)
void StopAudioBuffer(AudioBuffer *buffer)
void UnloadSound(Sound sound)
void UnloadAudioStream(AudioStream stream)
bool IsMusicStreamPlaying(Music music)
void SeekMusicStream(Music music, float position)
void SetAudioBufferVolume(AudioBuffer *buffer, float volume)
void SetAudioBufferPan(AudioBuffer *buffer, float pan)
void SetAudioStreamCallback(AudioStream stream, AudioCallback callback)
void SetAudioStreamPitch(AudioStream stream, float pitch)
void UnloadMusicStream(Music music)
void DetachAudioStreamProcessor(AudioStream stream, AudioCallback process)
void TrackAudioBuffer(AudioBuffer *buffer)
@ AUDIO_BUFFER_USAGE_STATIC
@ AUDIO_BUFFER_USAGE_STREAM
Sound LoadSound(const char *fileName)
bool IsAudioStreamProcessed(AudioStream stream)
void SetMusicVolume(Music music, float volume)
void PlayAudioBuffer(AudioBuffer *buffer)
#define TEXT_BYTES_PER_LINE
void UnloadWave(Wave wave)
void SetMusicPitch(Music music, float pitch)
Sound LoadSoundFromWave(Wave wave)
void UpdateSound(Sound sound, const void *data, int sampleCount)
void PlaySound(Sound sound)
bool ExportWaveAsCode(Wave wave, const char *fileName)
void CloseAudioDevice(void)
Wave LoadWaveFromMemory(const char *fileType, const unsigned char *fileData, int dataSize)
Music LoadMusicStream(const char *fileName)
AudioStream LoadAudioStream(unsigned int sampleRate, unsigned int sampleSize, unsigned int channels)
Music LoadMusicStreamFromMemory(const char *fileType, const unsigned char *data, int dataSize)
void PauseMusicStream(Music music)
void PauseAudioStream(AudioStream stream)
bool IsAudioDeviceReady(void)
void PauseSound(Sound sound)
void UntrackAudioBuffer(AudioBuffer *buffer)
float GetMusicTimePlayed(Music music)
AudioBuffer * LoadAudioBuffer(ma_format format, ma_uint32 channels, ma_uint32 sampleRate, ma_uint32 sizeInFrames, int usage)
void PlaySoundMulti(Sound sound)
bool ExportWave(Wave wave, const char *fileName)
void UpdateAudioStream(AudioStream stream, const void *data, int frameCount)
void SetAudioStreamPan(AudioStream stream, float pan)
float * LoadWaveSamples(Wave wave)
#define RL_MALLOC(sz)
raudio v1.0 - A simple and easy-to-use audio library based on miniaudio
#define TRACELOG(level,...)
RLAPI bool SaveFileData(const char *fileName, void *data, unsigned int bytesToWrite)
RLAPI unsigned char * LoadFileData(const char *fileName, unsigned int *bytesRead)
void(* AudioCallback)(void *bufferData, unsigned int frames)
RLAPI bool SaveFileText(const char *fileName, char *text)
RLAPI const char * GetFileExtension(const char *fileName)
RLAPI bool IsFileExtension(const char *fileName, const char *ext)
STBVDEF stb_vorbis * stb_vorbis_open_memory(const unsigned char *data, int len, int *error, const stb_vorbis_alloc *alloc_buffer)
STBVDEF void stb_vorbis_close(stb_vorbis *f)
STBVDEF int stb_vorbis_seek_frame(stb_vorbis *f, unsigned int sample_number)
STBVDEF int stb_vorbis_get_samples_short_interleaved(stb_vorbis *f, int channels, short *buffer, int num_shorts)
struct stb_vorbis stb_vorbis
STBVDEF unsigned int stb_vorbis_stream_length_in_samples(stb_vorbis *f)
STBVDEF int stb_vorbis_seek_start(stb_vorbis *f)
STBVDEF stb_vorbis_info stb_vorbis_get_info(stb_vorbis *f)
STBVDEF stb_vorbis * stb_vorbis_open_filename(const char *filename, int *error, const stb_vorbis_alloc *alloc_buffer)
unsigned __int64 uint64_t
struct AudioData::@136 Buffer
struct AudioData::@137 MultiChannel
unsigned int channels[MAX_AUDIO_BUFFER_POOL_CHANNELS]
AudioBuffer * pool[MAX_AUDIO_BUFFER_POOL_CHANNELS]
struct AudioData::@135 System
drflac_uint8 bitsPerSample
drflac_uint64 totalPCMFrameCount
drwav_uint16 bitsPerSample
drwav_uint64 totalPCMFrameCount
ma_bool32 allowDynamicSampleRate
ma_device_data_proc dataCallback
const ma_device_id * pDeviceID
struct ma_device_config::@83 capture
struct ma_device_config::@82 playback
ma_uint32 internalSampleRate
ma_uint32 internalPeriods
ma_uint32 internalPeriodSizeInFrames
struct ma_device::@105 playback
ma_uint32 internalChannels
rAudioProcessor * processor
bool isSubBufferProcessed[2]
unsigned int frameCursorPos
unsigned int sizeInFrames
unsigned int framesProcessed
ma_data_converter converter