Commit f028e65e authored by David Reid's avatar David Reid

Update filtering tests.

parent d6f1d05d
#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 result;
ma_decoder_config decoderConfig;
drwav_data_format wavFormat;
decoderConfig = ma_decoder_config_init(format, 0, 0);
result = ma_decoder_init_file(pInputFilePath, &decoderConfig, pDecoder);
if (result != MA_SUCCESS) {
return result;
}
wavFormat = drwav_data_format_from_minaudio_format(pDecoder->outputFormat, pDecoder->outputChannels, pDecoder->outputSampleRate);
if (!drwav_init_file_write(pEncoder, pOutputFilePath, &wavFormat, NULL)) {
ma_decoder_uninit(pDecoder);
return MA_ERROR;
}
return MA_SUCCESS;
}
#include "ma_test_filtering_dithering.c"
#include "ma_test_filtering_lpf.c"
#include "ma_test_filtering_hpf.c"
......
ma_result test_lpf1__f32(const char* pInputFilePath)
ma_result lpf_init_decoder_and_encoder(const char* pInputFilePath, const char* pOutputFilePath, ma_format format, ma_decoder* pDecoder, drwav* pEncoder)
{
return filtering_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, 0, 0, pDecoder, pEncoder);
}
ma_result test_lpf1__by_format(const char* pInputFilePath, const char* pOutputFilePath, ma_format format)
{
const char* pOutputFilePath = "output/lpf1_f32.wav";
ma_result result;
ma_decoder_config decoderConfig;
ma_decoder decoder;
drwav_data_format wavFormat;
drwav wav;
ma_lpf1_config lpfConfig;
ma_lpf1 lpf;
decoderConfig = ma_decoder_config_init(ma_format_f32, 0, 0);
result = ma_decoder_init_file(pInputFilePath, &decoderConfig, &decoder);
printf(" %s\n", pOutputFilePath);
result = lpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &wav);
if (result != MA_SUCCESS) {
return result;
}
lpfConfig = ma_lpf_config_init(decoder.outputFormat, decoder.outputChannels, decoder.outputSampleRate, 2000);
lpfConfig = ma_lpf1_config_init(decoder.outputFormat, decoder.outputChannels, decoder.outputSampleRate, 2000);
result = ma_lpf1_init(&lpfConfig, &lpf);
if (result != MA_SUCCESS) {
ma_decoder_uninit(&decoder);
drwav_uninit(&wav);
return result;
}
wavFormat = drwav_data_format_from_minaudio_format(decoder.outputFormat, decoder.outputChannels, decoder.outputSampleRate);
if (!drwav_init_file_write(&wav, pOutputFilePath, &wavFormat, NULL)) {
ma_decoder_uninit(&decoder);
return MA_ERROR;
}
for (;;) {
ma_uint8 tempIn[4096];
ma_uint8 tempOut[4096];
......@@ -55,75 +53,28 @@ ma_result test_lpf1__f32(const char* pInputFilePath)
return MA_SUCCESS;
}
ma_result test_lpf1__s16(const char* pInputFilePath)
ma_result test_lpf1__f32(const char* pInputFilePath)
{
const char* pOutputFilePath = "output/lpf1_s16.wav";
ma_result result;
ma_decoder_config decoderConfig;
ma_decoder decoder;
drwav_data_format wavFormat;
drwav wav;
ma_lpf1_config lpfConfig;
ma_lpf1 lpf;
decoderConfig = ma_decoder_config_init(ma_format_s16, 0, 0);
result = ma_decoder_init_file(pInputFilePath, &decoderConfig, &decoder);
if (result != MA_SUCCESS) {
return result;
}
lpfConfig = ma_lpf_config_init(decoder.outputFormat, decoder.outputChannels, decoder.outputSampleRate, 2000);
result = ma_lpf1_init(&lpfConfig, &lpf);
if (result != MA_SUCCESS) {
ma_decoder_uninit(&decoder);
return result;
}
wavFormat = drwav_data_format_from_minaudio_format(decoder.outputFormat, decoder.outputChannels, decoder.outputSampleRate);
if (!drwav_init_file_write(&wav, pOutputFilePath, &wavFormat, NULL)) {
ma_decoder_uninit(&decoder);
return MA_ERROR;
}
for (;;) {
ma_uint8 tempIn[4096];
ma_uint8 tempOut[4096];
ma_uint64 tempCapIn = sizeof(tempIn) / ma_get_bytes_per_frame(decoder.outputFormat, decoder.outputChannels);
ma_uint64 tempCapOut = sizeof(tempOut) / ma_get_bytes_per_frame(decoder.outputFormat, decoder.outputChannels);
ma_uint64 framesToRead;
ma_uint64 framesJustRead;
framesToRead = ma_min(tempCapIn, tempCapOut);
framesJustRead = ma_decoder_read_pcm_frames(&decoder, tempIn, framesToRead);
/* Filter */
ma_lpf1_process_pcm_frames(&lpf, tempOut, tempIn, framesJustRead);
/* Write to the WAV file. */
drwav_write_pcm_frames(&wav, framesJustRead, tempOut);
if (framesJustRead < framesToRead) {
break;
}
}
return test_lpf1__by_format(pInputFilePath, "output/lpf1_f32.wav", ma_format_f32);
}
drwav_uninit(&wav);
return MA_SUCCESS;
ma_result test_lpf1__s16(const char* pInputFilePath)
{
return test_lpf1__by_format(pInputFilePath, "output/lpf1_s16.wav", ma_format_s16);
}
ma_result test_lpf2__f32(const char* pInputFilePath)
ma_result test_lpf2__by_format(const char* pInputFilePath, const char* pOutputFilePath, ma_format format)
{
const char* pOutputFilePath = "output/lpf2_f32.wav";
ma_result result;
ma_decoder_config decoderConfig;
ma_decoder decoder;
drwav_data_format wavFormat;
drwav wav;
ma_lpf_config lpfConfig;
ma_lpf lpf;
decoderConfig = ma_decoder_config_init(ma_format_f32, 0, 0);
result = ma_decoder_init_file(pInputFilePath, &decoderConfig, &decoder);
printf(" %s\n", pOutputFilePath);
result = lpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &wav);
if (result != MA_SUCCESS) {
return result;
}
......@@ -132,15 +83,10 @@ ma_result test_lpf2__f32(const char* pInputFilePath)
result = ma_lpf_init(&lpfConfig, &lpf);
if (result != MA_SUCCESS) {
ma_decoder_uninit(&decoder);
drwav_uninit(&wav);
return result;
}
wavFormat = drwav_data_format_from_minaudio_format(decoder.outputFormat, decoder.outputChannels, decoder.outputSampleRate);
if (!drwav_init_file_write(&wav, pOutputFilePath, &wavFormat, NULL)) {
ma_decoder_uninit(&decoder);
return MA_ERROR;
}
for (;;) {
ma_uint8 tempIn[4096];
ma_uint8 tempOut[4096];
......@@ -167,6 +113,17 @@ ma_result test_lpf2__f32(const char* pInputFilePath)
return MA_SUCCESS;
}
ma_result test_lpf2__f32(const char* pInputFilePath)
{
return test_lpf2__by_format(pInputFilePath, "output/lpf2_f32.wav", ma_format_f32);
}
ma_result test_lpf2__s16(const char* pInputFilePath)
{
return test_lpf2__by_format(pInputFilePath, "output/lpf2_s16.wav", ma_format_s16);
}
int test_entry__lpf(int argc, char** argv)
{
ma_result result;
......@@ -190,11 +147,18 @@ int test_entry__lpf(int argc, char** argv)
hasError = MA_TRUE;
}
result = test_lpf2__f32(pInputFilePath);
if (result != MA_SUCCESS) {
hasError = MA_TRUE;
}
result = test_lpf2__s16(pInputFilePath);
if (result != MA_SUCCESS) {
hasError = MA_TRUE;
}
if (hasError) {
return -1;
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment