[raudio]: Replace DrWAV with miniaudio WAV encoder
Miniaudio includes DrWAV, and their encoder is just a wrapper. Now we don't have 2 copies of it.
This commit is contained in:
parent
d00f52e419
commit
4918d435e9
31
examples/audio/audio_wave_export.c
Normal file
31
examples/audio/audio_wave_export.c
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [audio] example - sound loading
|
||||||
|
*
|
||||||
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
|
*
|
||||||
|
* Example originally created with raylib 5.5
|
||||||
|
* Example contributed by Torphedo (@torphedo)
|
||||||
|
*
|
||||||
|
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
||||||
|
* BSD-like license that allows static linking with closed source software
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Torphedo (@torphedo)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
#include "raylib.h"
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Program main entry point
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
Wave wave = LoadWave("resources/country.mp3");
|
||||||
|
if (wave.data) {
|
||||||
|
ExportWave(wave, "country.wav");
|
||||||
|
UnloadWave(wave);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
9003
src/external/dr_wav.h
vendored
9003
src/external/dr_wav.h
vendored
File diff suppressed because it is too large
Load Diff
38
src/raudio.c
38
src/raudio.c
|
|
@ -31,7 +31,6 @@
|
||||||
* DEPENDENCIES:
|
* DEPENDENCIES:
|
||||||
* miniaudio.h - Audio device management lib (https://github.com/mackron/miniaudio)
|
* miniaudio.h - Audio device management lib (https://github.com/mackron/miniaudio)
|
||||||
* stb_vorbis.h - Ogg audio files loading (http://www.nothings.org/stb_vorbis/)
|
* stb_vorbis.h - Ogg audio files loading (http://www.nothings.org/stb_vorbis/)
|
||||||
* dr_wav.h - WAV audio files loading (http://github.com/mackron/dr_libs)
|
|
||||||
* jar_xm.h - XM module file loading
|
* jar_xm.h - XM module file loading
|
||||||
* jar_mod.h - MOD audio file loading
|
* jar_mod.h - MOD audio file loading
|
||||||
*
|
*
|
||||||
|
|
@ -166,14 +165,7 @@ typedef struct tagBITMAPINFOHEADER {
|
||||||
#define MA_NO_WAV
|
#define MA_NO_WAV
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SUPPORT_FILEFORMAT_WAV)
|
#if !defined(SUPPORT_FILEFORMAT_WAV)
|
||||||
#define DRWAV_MALLOC RL_MALLOC
|
|
||||||
#define DRWAV_REALLOC RL_REALLOC
|
|
||||||
#define DRWAV_FREE RL_FREE
|
|
||||||
|
|
||||||
#define DR_WAV_IMPLEMENTATION
|
|
||||||
#include "external/dr_wav.h" // WAV saving functions
|
|
||||||
#else
|
|
||||||
#define MA_NO_WAV
|
#define MA_NO_WAV
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -1029,24 +1021,16 @@ bool ExportWave(Wave wave, const char *fileName)
|
||||||
#if defined(SUPPORT_FILEFORMAT_WAV)
|
#if defined(SUPPORT_FILEFORMAT_WAV)
|
||||||
else if (IsFileExtension(fileName, ".wav"))
|
else if (IsFileExtension(fileName, ".wav"))
|
||||||
{
|
{
|
||||||
drwav wav = { 0 };
|
ma_format format = (wave.sampleSize == 32)? ma_format_f32 : ma_format_s16;
|
||||||
drwav_data_format format = { 0 };
|
ma_encoder_config cfg = ma_encoder_config_init(ma_encoding_format_wav, format, wave.channels, wave.sampleRate);
|
||||||
format.container = drwav_container_riff;
|
ma_encoder encoder;
|
||||||
if (wave.sampleSize == 32) format.format = DR_WAVE_FORMAT_IEEE_FLOAT;
|
ma_result res = ma_encoder_init_file(fileName, &cfg, &encoder);
|
||||||
else format.format = DR_WAVE_FORMAT_PCM;
|
if (res == MA_SUCCESS) {
|
||||||
format.channels = wave.channels;
|
ma_uint64 framesWritten = 0;
|
||||||
format.sampleRate = wave.sampleRate;
|
ma_encoder_write_pcm_frames(&encoder, wave.data, wave.frameCount, &framesWritten);
|
||||||
format.bitsPerSample = wave.sampleSize;
|
ma_encoder_uninit(&encoder);
|
||||||
|
success = (framesWritten == wave.frameCount);
|
||||||
void *fileData = NULL;
|
}
|
||||||
size_t fileDataSize = 0;
|
|
||||||
success = drwav_init_memory_write(&wav, &fileData, &fileDataSize, &format, NULL);
|
|
||||||
if (success) success = (int)drwav_write_pcm_frames(&wav, wave.frameCount, wave.data);
|
|
||||||
drwav_result result = drwav_uninit(&wav);
|
|
||||||
|
|
||||||
if (result == DRWAV_SUCCESS) success = SaveFileData(fileName, (unsigned char *)fileData, (unsigned int)fileDataSize);
|
|
||||||
|
|
||||||
drwav_free(fileData, NULL);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if defined(SUPPORT_FILEFORMAT_QOA)
|
#if defined(SUPPORT_FILEFORMAT_QOA)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user