mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-21 15:56:58 +02:00
Add an encoding API.
This API is called ma_encoder. Currently it only supports encoding to WAV files, which is done via dr_wav.
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
#include "../test_common/ma_test_common.c"
|
||||
|
||||
ma_result filtering_init_decoder_and_encoder(const char* pInputFilePath, const char* pOutputFilePath, ma_format format, ma_uint32 channels, ma_uint32 sampleRate, ma_decoder* pDecoder, drwav* pEncoder)
|
||||
ma_result filtering_init_decoder_and_encoder(const char* pInputFilePath, const char* pOutputFilePath, ma_format format, ma_uint32 channels, ma_uint32 sampleRate, ma_decoder* pDecoder, ma_encoder* pEncoder)
|
||||
{
|
||||
ma_result result;
|
||||
ma_decoder_config decoderConfig;
|
||||
drwav_data_format wavFormat;
|
||||
ma_encoder_config encoderConfig;
|
||||
|
||||
decoderConfig = ma_decoder_config_init(format, 0, 0);
|
||||
result = ma_decoder_init_file(pInputFilePath, &decoderConfig, pDecoder);
|
||||
@@ -12,10 +12,11 @@ ma_result filtering_init_decoder_and_encoder(const char* pInputFilePath, const c
|
||||
return result;
|
||||
}
|
||||
|
||||
wavFormat = drwav_data_format_from_minaudio_format(pDecoder->outputFormat, pDecoder->outputChannels, pDecoder->outputSampleRate);
|
||||
if (!drwav_init_file_write(pEncoder, pOutputFilePath, &wavFormat, NULL)) {
|
||||
encoderConfig = ma_encoder_config_init(ma_resource_format_wav, pDecoder->outputFormat, pDecoder->outputChannels, pDecoder->outputSampleRate);
|
||||
result = ma_encoder_init_file(pOutputFilePath, &encoderConfig, pEncoder);
|
||||
if (result != MA_SUCCESS) {
|
||||
ma_decoder_uninit(pDecoder);
|
||||
return MA_ERROR;
|
||||
return result;
|
||||
}
|
||||
|
||||
return MA_SUCCESS;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
ma_result bpf_init_decoder_and_encoder(const char* pInputFilePath, const char* pOutputFilePath, ma_format format, ma_decoder* pDecoder, drwav* pEncoder)
|
||||
ma_result bpf_init_decoder_and_encoder(const char* pInputFilePath, const char* pOutputFilePath, ma_format format, ma_decoder* pDecoder, ma_encoder* pEncoder)
|
||||
{
|
||||
return filtering_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, 0, 0, pDecoder, pEncoder);
|
||||
}
|
||||
@@ -8,13 +8,13 @@ ma_result test_bpf2__by_format(const char* pInputFilePath, const char* pOutputFi
|
||||
{
|
||||
ma_result result;
|
||||
ma_decoder decoder;
|
||||
drwav wav;
|
||||
ma_encoder encoder;
|
||||
ma_bpf2_config bpfConfig;
|
||||
ma_bpf2 bpf;
|
||||
|
||||
printf(" %s\n", pOutputFilePath);
|
||||
|
||||
result = bpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &wav);
|
||||
result = bpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &encoder);
|
||||
if (result != MA_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
@@ -23,7 +23,7 @@ ma_result test_bpf2__by_format(const char* pInputFilePath, const char* pOutputFi
|
||||
result = ma_bpf2_init(&bpfConfig, &bpf);
|
||||
if (result != MA_SUCCESS) {
|
||||
ma_decoder_uninit(&decoder);
|
||||
drwav_uninit(&wav);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -42,14 +42,14 @@ ma_result test_bpf2__by_format(const char* pInputFilePath, const char* pOutputFi
|
||||
ma_bpf2_process_pcm_frames(&bpf, tempOut, tempIn, framesJustRead);
|
||||
|
||||
/* Write to the WAV file. */
|
||||
drwav_write_pcm_frames(&wav, framesJustRead, tempOut);
|
||||
ma_encoder_write_pcm_frames(&encoder, tempOut, framesJustRead);
|
||||
|
||||
if (framesJustRead < framesToRead) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
drwav_uninit(&wav);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -68,13 +68,13 @@ ma_result test_bpf4__by_format(const char* pInputFilePath, const char* pOutputFi
|
||||
{
|
||||
ma_result result;
|
||||
ma_decoder decoder;
|
||||
drwav wav;
|
||||
ma_encoder encoder;
|
||||
ma_bpf_config bpfConfig;
|
||||
ma_bpf bpf;
|
||||
|
||||
printf(" %s\n", pOutputFilePath);
|
||||
|
||||
result = bpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &wav);
|
||||
result = bpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &encoder);
|
||||
if (result != MA_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
@@ -83,7 +83,7 @@ ma_result test_bpf4__by_format(const char* pInputFilePath, const char* pOutputFi
|
||||
result = ma_bpf_init(&bpfConfig, &bpf);
|
||||
if (result != MA_SUCCESS) {
|
||||
ma_decoder_uninit(&decoder);
|
||||
drwav_uninit(&wav);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -102,14 +102,14 @@ ma_result test_bpf4__by_format(const char* pInputFilePath, const char* pOutputFi
|
||||
ma_bpf_process_pcm_frames(&bpf, tempOut, tempIn, framesJustRead);
|
||||
|
||||
/* Write to the WAV file. */
|
||||
drwav_write_pcm_frames(&wav, framesJustRead, tempOut);
|
||||
ma_encoder_write_pcm_frames(&encoder, tempOut, framesJustRead);
|
||||
|
||||
if (framesJustRead < framesToRead) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
drwav_uninit(&wav);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ ma_result test_dithering__u8(const char* pInputFilePath)
|
||||
ma_result result;
|
||||
ma_decoder_config decoderConfig;
|
||||
ma_decoder decoder;
|
||||
drwav_data_format wavFormat;
|
||||
drwav wav;
|
||||
ma_encoder_config encoderConfig;
|
||||
ma_encoder encoder;
|
||||
|
||||
decoderConfig = ma_decoder_config_init(ma_format_f32, 0, 0);
|
||||
result = ma_decoder_init_file(pInputFilePath, &decoderConfig, &decoder);
|
||||
@@ -14,10 +14,11 @@ ma_result test_dithering__u8(const char* pInputFilePath)
|
||||
return result;
|
||||
}
|
||||
|
||||
wavFormat = drwav_data_format_from_minaudio_format(ma_format_u8, decoder.outputChannels, decoder.outputSampleRate);
|
||||
if (!drwav_init_file_write(&wav, pOutputFilePath, &wavFormat, NULL)) {
|
||||
encoderConfig = ma_encoder_config_init(ma_resource_format_wav, ma_format_u8, decoder.outputChannels, decoder.outputSampleRate);
|
||||
result = ma_encoder_init_file(pOutputFilePath, &encoderConfig, &encoder);
|
||||
if (result != MA_SUCCESS) {
|
||||
ma_decoder_uninit(&decoder);
|
||||
return MA_ERROR;
|
||||
return result;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
@@ -35,14 +36,14 @@ ma_result test_dithering__u8(const char* pInputFilePath)
|
||||
ma_convert_pcm_frames_format(tempOut, ma_format_u8, tempIn, decoder.outputFormat, framesJustRead, decoder.outputChannels, ma_dither_mode_triangle);
|
||||
|
||||
/* Write to the WAV file. */
|
||||
drwav_write_pcm_frames(&wav, framesJustRead, tempOut);
|
||||
ma_encoder_write_pcm_frames(&encoder, tempOut, framesJustRead);
|
||||
|
||||
if (framesJustRead < framesToRead) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
drwav_uninit(&wav);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
ma_result hpf_init_decoder_and_encoder(const char* pInputFilePath, const char* pOutputFilePath, ma_format format, ma_decoder* pDecoder, drwav* pEncoder)
|
||||
ma_result hpf_init_decoder_and_encoder(const char* pInputFilePath, const char* pOutputFilePath, ma_format format, ma_decoder* pDecoder, ma_encoder* pEncoder)
|
||||
{
|
||||
return filtering_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, 0, 0, pDecoder, pEncoder);
|
||||
}
|
||||
@@ -8,13 +8,13 @@ ma_result test_hpf1__by_format(const char* pInputFilePath, const char* pOutputFi
|
||||
{
|
||||
ma_result result;
|
||||
ma_decoder decoder;
|
||||
drwav wav;
|
||||
ma_encoder encoder;
|
||||
ma_hpf1_config hpfConfig;
|
||||
ma_hpf1 hpf;
|
||||
|
||||
printf(" %s\n", pOutputFilePath);
|
||||
|
||||
result = hpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &wav);
|
||||
result = hpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &encoder);
|
||||
if (result != MA_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
@@ -23,7 +23,7 @@ ma_result test_hpf1__by_format(const char* pInputFilePath, const char* pOutputFi
|
||||
result = ma_hpf1_init(&hpfConfig, &hpf);
|
||||
if (result != MA_SUCCESS) {
|
||||
ma_decoder_uninit(&decoder);
|
||||
drwav_uninit(&wav);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -42,14 +42,14 @@ ma_result test_hpf1__by_format(const char* pInputFilePath, const char* pOutputFi
|
||||
ma_hpf1_process_pcm_frames(&hpf, tempOut, tempIn, framesJustRead);
|
||||
|
||||
/* Write to the WAV file. */
|
||||
drwav_write_pcm_frames(&wav, framesJustRead, tempOut);
|
||||
ma_encoder_write_pcm_frames(&encoder, tempOut, framesJustRead);
|
||||
|
||||
if (framesJustRead < framesToRead) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
drwav_uninit(&wav);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -68,13 +68,13 @@ ma_result test_hpf2__by_format(const char* pInputFilePath, const char* pOutputFi
|
||||
{
|
||||
ma_result result;
|
||||
ma_decoder decoder;
|
||||
drwav wav;
|
||||
ma_encoder encoder;
|
||||
ma_hpf2_config hpfConfig;
|
||||
ma_hpf2 hpf;
|
||||
|
||||
printf(" %s\n", pOutputFilePath);
|
||||
|
||||
result = hpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &wav);
|
||||
result = hpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &encoder);
|
||||
if (result != MA_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
@@ -83,7 +83,7 @@ ma_result test_hpf2__by_format(const char* pInputFilePath, const char* pOutputFi
|
||||
result = ma_hpf2_init(&hpfConfig, &hpf);
|
||||
if (result != MA_SUCCESS) {
|
||||
ma_decoder_uninit(&decoder);
|
||||
drwav_uninit(&wav);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -102,14 +102,14 @@ ma_result test_hpf2__by_format(const char* pInputFilePath, const char* pOutputFi
|
||||
ma_hpf2_process_pcm_frames(&hpf, tempOut, tempIn, framesJustRead);
|
||||
|
||||
/* Write to the WAV file. */
|
||||
drwav_write_pcm_frames(&wav, framesJustRead, tempOut);
|
||||
ma_encoder_write_pcm_frames(&encoder, tempOut, framesJustRead);
|
||||
|
||||
if (framesJustRead < framesToRead) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
drwav_uninit(&wav);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -128,13 +128,13 @@ ma_result test_hpf3__by_format(const char* pInputFilePath, const char* pOutputFi
|
||||
{
|
||||
ma_result result;
|
||||
ma_decoder decoder;
|
||||
drwav wav;
|
||||
ma_encoder encoder;
|
||||
ma_hpf_config hpfConfig;
|
||||
ma_hpf hpf;
|
||||
|
||||
printf(" %s\n", pOutputFilePath);
|
||||
|
||||
result = hpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &wav);
|
||||
result = hpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &encoder);
|
||||
if (result != MA_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
@@ -143,7 +143,7 @@ ma_result test_hpf3__by_format(const char* pInputFilePath, const char* pOutputFi
|
||||
result = ma_hpf_init(&hpfConfig, &hpf);
|
||||
if (result != MA_SUCCESS) {
|
||||
ma_decoder_uninit(&decoder);
|
||||
drwav_uninit(&wav);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -162,14 +162,14 @@ ma_result test_hpf3__by_format(const char* pInputFilePath, const char* pOutputFi
|
||||
ma_hpf_process_pcm_frames(&hpf, tempOut, tempIn, framesJustRead);
|
||||
|
||||
/* Write to the WAV file. */
|
||||
drwav_write_pcm_frames(&wav, framesJustRead, tempOut);
|
||||
ma_encoder_write_pcm_frames(&encoder, tempOut, framesJustRead);
|
||||
|
||||
if (framesJustRead < framesToRead) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
drwav_uninit(&wav);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
ma_result lpf_init_decoder_and_encoder(const char* pInputFilePath, const char* pOutputFilePath, ma_format format, ma_decoder* pDecoder, drwav* pEncoder)
|
||||
ma_result lpf_init_decoder_and_encoder(const char* pInputFilePath, const char* pOutputFilePath, ma_format format, ma_decoder* pDecoder, ma_encoder* pEncoder)
|
||||
{
|
||||
return filtering_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, 0, 0, pDecoder, pEncoder);
|
||||
}
|
||||
@@ -8,13 +8,13 @@ ma_result test_lpf1__by_format(const char* pInputFilePath, const char* pOutputFi
|
||||
{
|
||||
ma_result result;
|
||||
ma_decoder decoder;
|
||||
drwav wav;
|
||||
ma_encoder encoder;
|
||||
ma_lpf1_config lpfConfig;
|
||||
ma_lpf1 lpf;
|
||||
|
||||
printf(" %s\n", pOutputFilePath);
|
||||
|
||||
result = lpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &wav);
|
||||
result = lpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &encoder);
|
||||
if (result != MA_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
@@ -23,7 +23,7 @@ ma_result test_lpf1__by_format(const char* pInputFilePath, const char* pOutputFi
|
||||
result = ma_lpf1_init(&lpfConfig, &lpf);
|
||||
if (result != MA_SUCCESS) {
|
||||
ma_decoder_uninit(&decoder);
|
||||
drwav_uninit(&wav);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -42,14 +42,14 @@ ma_result test_lpf1__by_format(const char* pInputFilePath, const char* pOutputFi
|
||||
ma_lpf1_process_pcm_frames(&lpf, tempOut, tempIn, framesJustRead);
|
||||
|
||||
/* Write to the WAV file. */
|
||||
drwav_write_pcm_frames(&wav, framesJustRead, tempOut);
|
||||
ma_encoder_write_pcm_frames(&encoder, tempOut, framesJustRead);
|
||||
|
||||
if (framesJustRead < framesToRead) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
drwav_uninit(&wav);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -68,13 +68,13 @@ ma_result test_lpf2__by_format(const char* pInputFilePath, const char* pOutputFi
|
||||
{
|
||||
ma_result result;
|
||||
ma_decoder decoder;
|
||||
drwav wav;
|
||||
ma_encoder encoder;
|
||||
ma_lpf2_config lpfConfig;
|
||||
ma_lpf2 lpf;
|
||||
|
||||
printf(" %s\n", pOutputFilePath);
|
||||
|
||||
result = lpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &wav);
|
||||
result = lpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &encoder);
|
||||
if (result != MA_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
@@ -83,7 +83,7 @@ ma_result test_lpf2__by_format(const char* pInputFilePath, const char* pOutputFi
|
||||
result = ma_lpf2_init(&lpfConfig, &lpf);
|
||||
if (result != MA_SUCCESS) {
|
||||
ma_decoder_uninit(&decoder);
|
||||
drwav_uninit(&wav);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -102,14 +102,14 @@ ma_result test_lpf2__by_format(const char* pInputFilePath, const char* pOutputFi
|
||||
ma_lpf2_process_pcm_frames(&lpf, tempOut, tempIn, framesJustRead);
|
||||
|
||||
/* Write to the WAV file. */
|
||||
drwav_write_pcm_frames(&wav, framesJustRead, tempOut);
|
||||
ma_encoder_write_pcm_frames(&encoder, tempOut, framesJustRead);
|
||||
|
||||
if (framesJustRead < framesToRead) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
drwav_uninit(&wav);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -129,13 +129,13 @@ ma_result test_lpf3__by_format(const char* pInputFilePath, const char* pOutputFi
|
||||
{
|
||||
ma_result result;
|
||||
ma_decoder decoder;
|
||||
drwav wav;
|
||||
ma_encoder encoder;
|
||||
ma_lpf_config lpfConfig;
|
||||
ma_lpf lpf;
|
||||
|
||||
printf(" %s\n", pOutputFilePath);
|
||||
|
||||
result = lpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &wav);
|
||||
result = lpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &encoder);
|
||||
if (result != MA_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
@@ -144,7 +144,7 @@ ma_result test_lpf3__by_format(const char* pInputFilePath, const char* pOutputFi
|
||||
result = ma_lpf_init(&lpfConfig, &lpf);
|
||||
if (result != MA_SUCCESS) {
|
||||
ma_decoder_uninit(&decoder);
|
||||
drwav_uninit(&wav);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -163,14 +163,14 @@ ma_result test_lpf3__by_format(const char* pInputFilePath, const char* pOutputFi
|
||||
ma_lpf_process_pcm_frames(&lpf, tempOut, tempIn, framesJustRead);
|
||||
|
||||
/* Write to the WAV file. */
|
||||
drwav_write_pcm_frames(&wav, framesJustRead, tempOut);
|
||||
ma_encoder_write_pcm_frames(&encoder, tempOut, framesJustRead);
|
||||
|
||||
if (framesJustRead < framesToRead) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
drwav_uninit(&wav);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user