mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-23 16:54:03 +02:00
Update filtering tests.
This commit is contained in:
@@ -1,5 +1,26 @@
|
|||||||
#include "../test_common/ma_test_common.c"
|
#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_dithering.c"
|
||||||
#include "ma_test_filtering_lpf.c"
|
#include "ma_test_filtering_lpf.c"
|
||||||
#include "ma_test_filtering_hpf.c"
|
#include "ma_test_filtering_hpf.c"
|
||||||
|
|||||||
@@ -1,34 +1,32 @@
|
|||||||
|
|
||||||
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_result result;
|
||||||
ma_decoder_config decoderConfig;
|
|
||||||
ma_decoder decoder;
|
ma_decoder decoder;
|
||||||
drwav_data_format wavFormat;
|
|
||||||
drwav wav;
|
drwav wav;
|
||||||
ma_lpf1_config lpfConfig;
|
ma_lpf1_config lpfConfig;
|
||||||
ma_lpf1 lpf;
|
ma_lpf1 lpf;
|
||||||
|
|
||||||
decoderConfig = ma_decoder_config_init(ma_format_f32, 0, 0);
|
printf(" %s\n", pOutputFilePath);
|
||||||
result = ma_decoder_init_file(pInputFilePath, &decoderConfig, &decoder);
|
|
||||||
|
result = lpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &wav);
|
||||||
if (result != MA_SUCCESS) {
|
if (result != MA_SUCCESS) {
|
||||||
return result;
|
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);
|
result = ma_lpf1_init(&lpfConfig, &lpf);
|
||||||
if (result != MA_SUCCESS) {
|
if (result != MA_SUCCESS) {
|
||||||
ma_decoder_uninit(&decoder);
|
ma_decoder_uninit(&decoder);
|
||||||
|
drwav_uninit(&wav);
|
||||||
return result;
|
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 (;;) {
|
for (;;) {
|
||||||
ma_uint8 tempIn[4096];
|
ma_uint8 tempIn[4096];
|
||||||
ma_uint8 tempOut[4096];
|
ma_uint8 tempOut[4096];
|
||||||
@@ -55,75 +53,28 @@ ma_result test_lpf1__f32(const char* pInputFilePath)
|
|||||||
return MA_SUCCESS;
|
return MA_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ma_result test_lpf1__f32(const char* pInputFilePath)
|
||||||
|
{
|
||||||
|
return test_lpf1__by_format(pInputFilePath, "output/lpf1_f32.wav", ma_format_f32);
|
||||||
|
}
|
||||||
|
|
||||||
ma_result test_lpf1__s16(const char* pInputFilePath)
|
ma_result test_lpf1__s16(const char* pInputFilePath)
|
||||||
{
|
{
|
||||||
const char* pOutputFilePath = "output/lpf1_s16.wav";
|
return test_lpf1__by_format(pInputFilePath, "output/lpf1_s16.wav", ma_format_s16);
|
||||||
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);
|
ma_result test_lpf2__by_format(const char* pInputFilePath, const char* pOutputFilePath, ma_format format)
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
drwav_uninit(&wav);
|
|
||||||
return MA_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
ma_result test_lpf2__f32(const char* pInputFilePath)
|
|
||||||
{
|
{
|
||||||
const char* pOutputFilePath = "output/lpf2_f32.wav";
|
|
||||||
ma_result result;
|
ma_result result;
|
||||||
ma_decoder_config decoderConfig;
|
|
||||||
ma_decoder decoder;
|
ma_decoder decoder;
|
||||||
drwav_data_format wavFormat;
|
|
||||||
drwav wav;
|
drwav wav;
|
||||||
ma_lpf_config lpfConfig;
|
ma_lpf_config lpfConfig;
|
||||||
ma_lpf lpf;
|
ma_lpf lpf;
|
||||||
|
|
||||||
decoderConfig = ma_decoder_config_init(ma_format_f32, 0, 0);
|
printf(" %s\n", pOutputFilePath);
|
||||||
result = ma_decoder_init_file(pInputFilePath, &decoderConfig, &decoder);
|
|
||||||
|
result = lpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &wav);
|
||||||
if (result != MA_SUCCESS) {
|
if (result != MA_SUCCESS) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -132,15 +83,10 @@ ma_result test_lpf2__f32(const char* pInputFilePath)
|
|||||||
result = ma_lpf_init(&lpfConfig, &lpf);
|
result = ma_lpf_init(&lpfConfig, &lpf);
|
||||||
if (result != MA_SUCCESS) {
|
if (result != MA_SUCCESS) {
|
||||||
ma_decoder_uninit(&decoder);
|
ma_decoder_uninit(&decoder);
|
||||||
|
drwav_uninit(&wav);
|
||||||
return result;
|
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 (;;) {
|
for (;;) {
|
||||||
ma_uint8 tempIn[4096];
|
ma_uint8 tempIn[4096];
|
||||||
ma_uint8 tempOut[4096];
|
ma_uint8 tempOut[4096];
|
||||||
@@ -167,6 +113,17 @@ ma_result test_lpf2__f32(const char* pInputFilePath)
|
|||||||
return MA_SUCCESS;
|
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)
|
int test_entry__lpf(int argc, char** argv)
|
||||||
{
|
{
|
||||||
ma_result result;
|
ma_result result;
|
||||||
@@ -190,11 +147,18 @@ int test_entry__lpf(int argc, char** argv)
|
|||||||
hasError = MA_TRUE;
|
hasError = MA_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
result = test_lpf2__f32(pInputFilePath);
|
result = test_lpf2__f32(pInputFilePath);
|
||||||
if (result != MA_SUCCESS) {
|
if (result != MA_SUCCESS) {
|
||||||
hasError = MA_TRUE;
|
hasError = MA_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result = test_lpf2__s16(pInputFilePath);
|
||||||
|
if (result != MA_SUCCESS) {
|
||||||
|
hasError = MA_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (hasError) {
|
if (hasError) {
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user