mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-21 15:56:58 +02:00
Use a simplified naming scheme for tests.
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
#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, ma_encoder* pEncoder)
|
||||
{
|
||||
ma_result result;
|
||||
ma_decoder_config decoderConfig;
|
||||
ma_encoder_config encoderConfig;
|
||||
|
||||
decoderConfig = ma_decoder_config_init(format, channels, sampleRate);
|
||||
result = ma_decoder_init_file(pInputFilePath, &decoderConfig, pDecoder);
|
||||
if (result != MA_SUCCESS) {
|
||||
printf("Failed to open \"%s\" for decoding. %s\n", pInputFilePath, ma_result_description(result));
|
||||
return result;
|
||||
}
|
||||
|
||||
encoderConfig = ma_encoder_config_init(ma_encoding_format_wav, pDecoder->outputFormat, pDecoder->outputChannels, pDecoder->outputSampleRate);
|
||||
result = ma_encoder_init_file(pOutputFilePath, &encoderConfig, pEncoder);
|
||||
if (result != MA_SUCCESS) {
|
||||
printf("Failed to open \"%s\" for encoding. %s\n", pOutputFilePath, ma_result_description(result));
|
||||
ma_decoder_uninit(pDecoder);
|
||||
return result;
|
||||
}
|
||||
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
#include "ma_test_filtering_dithering.c"
|
||||
#include "ma_test_filtering_lpf.c"
|
||||
#include "ma_test_filtering_hpf.c"
|
||||
#include "ma_test_filtering_bpf.c"
|
||||
#include "ma_test_filtering_notch.c"
|
||||
#include "ma_test_filtering_peak.c"
|
||||
#include "ma_test_filtering_loshelf.c"
|
||||
#include "ma_test_filtering_hishelf.c"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
ma_register_test("Dithering", test_entry__dithering);
|
||||
ma_register_test("Low-Pass Filtering", test_entry__lpf);
|
||||
ma_register_test("High-Pass Filtering", test_entry__hpf);
|
||||
ma_register_test("Band-Pass Filtering", test_entry__bpf);
|
||||
ma_register_test("Notching Filtering", test_entry__notch);
|
||||
ma_register_test("Peaking EQ Filtering", test_entry__peak);
|
||||
ma_register_test("Low Shelf Filtering", test_entry__loshelf);
|
||||
ma_register_test("High Shelf Filtering", test_entry__hishelf);
|
||||
|
||||
return ma_run_tests(argc, argv);
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
ma_result test_bpf2__by_format(const char* pInputFilePath, const char* pOutputFilePath, ma_format format)
|
||||
{
|
||||
ma_result result;
|
||||
ma_decoder decoder;
|
||||
ma_encoder encoder;
|
||||
ma_bpf2_config bpfConfig;
|
||||
ma_bpf2 bpf;
|
||||
|
||||
printf(" %s\n", pOutputFilePath);
|
||||
|
||||
result = bpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &encoder);
|
||||
if (result != MA_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
|
||||
bpfConfig = ma_bpf2_config_init(decoder.outputFormat, decoder.outputChannels, decoder.outputSampleRate, 2000, 0);
|
||||
result = ma_bpf2_init(&bpfConfig, NULL, &bpf);
|
||||
if (result != MA_SUCCESS) {
|
||||
ma_decoder_uninit(&decoder);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return result;
|
||||
}
|
||||
|
||||
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);
|
||||
ma_decoder_read_pcm_frames(&decoder, tempIn, framesToRead, &framesJustRead);
|
||||
|
||||
/* Filter */
|
||||
ma_bpf2_process_pcm_frames(&bpf, tempOut, tempIn, framesJustRead);
|
||||
|
||||
/* Write to the WAV file. */
|
||||
ma_encoder_write_pcm_frames(&encoder, tempOut, framesJustRead, NULL);
|
||||
|
||||
if (framesJustRead < framesToRead) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ma_decoder_uninit(&decoder);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
ma_result test_bpf2__f32(const char* pInputFilePath)
|
||||
{
|
||||
return test_bpf2__by_format(pInputFilePath, TEST_OUTPUT_DIR"/bpf2_f32.wav", ma_format_f32);
|
||||
}
|
||||
|
||||
ma_result test_bpf2__s16(const char* pInputFilePath)
|
||||
{
|
||||
return test_bpf2__by_format(pInputFilePath, TEST_OUTPUT_DIR"/bpf2_s16.wav", ma_format_s16);
|
||||
}
|
||||
|
||||
|
||||
ma_result test_bpf4__by_format(const char* pInputFilePath, const char* pOutputFilePath, ma_format format)
|
||||
{
|
||||
ma_result result;
|
||||
ma_decoder decoder;
|
||||
ma_encoder encoder;
|
||||
ma_bpf_config bpfConfig;
|
||||
ma_bpf bpf;
|
||||
|
||||
printf(" %s\n", pOutputFilePath);
|
||||
|
||||
result = bpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &encoder);
|
||||
if (result != MA_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
|
||||
bpfConfig = ma_bpf_config_init(decoder.outputFormat, decoder.outputChannels, decoder.outputSampleRate, 2000, 4);
|
||||
result = ma_bpf_init(&bpfConfig, NULL, &bpf);
|
||||
if (result != MA_SUCCESS) {
|
||||
ma_decoder_uninit(&decoder);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return result;
|
||||
}
|
||||
|
||||
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);
|
||||
ma_decoder_read_pcm_frames(&decoder, tempIn, framesToRead, &framesJustRead);
|
||||
|
||||
/* Filter */
|
||||
ma_bpf_process_pcm_frames(&bpf, tempOut, tempIn, framesJustRead);
|
||||
|
||||
/* Write to the WAV file. */
|
||||
ma_encoder_write_pcm_frames(&encoder, tempOut, framesJustRead, NULL);
|
||||
|
||||
if (framesJustRead < framesToRead) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ma_decoder_uninit(&decoder);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
ma_result test_bpf4__f32(const char* pInputFilePath)
|
||||
{
|
||||
return test_bpf4__by_format(pInputFilePath, TEST_OUTPUT_DIR"/bpf4_f32.wav", ma_format_f32);
|
||||
}
|
||||
|
||||
ma_result test_bpf4__s16(const char* pInputFilePath)
|
||||
{
|
||||
return test_bpf4__by_format(pInputFilePath, TEST_OUTPUT_DIR"/bpf4_s16.wav", ma_format_s16);
|
||||
}
|
||||
|
||||
|
||||
int test_entry__bpf(int argc, char** argv)
|
||||
{
|
||||
ma_result result;
|
||||
ma_bool32 hasError = MA_FALSE;
|
||||
const char* pInputFilePath;
|
||||
|
||||
if (argc < 2) {
|
||||
printf("No input file.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
pInputFilePath = argv[1];
|
||||
|
||||
|
||||
result = test_bpf2__f32(pInputFilePath);
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
result = test_bpf2__s16(pInputFilePath);
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
|
||||
result = test_bpf4__f32(pInputFilePath);
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
result = test_bpf4__s16(pInputFilePath);
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
|
||||
if (hasError) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
|
||||
ma_result test_dithering__u8(const char* pInputFilePath)
|
||||
{
|
||||
const char* pOutputFilePath = TEST_OUTPUT_DIR"/dithering_u8.wav";
|
||||
ma_result result;
|
||||
ma_decoder_config decoderConfig;
|
||||
ma_decoder decoder;
|
||||
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);
|
||||
if (result != MA_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
|
||||
encoderConfig = ma_encoder_config_init(ma_encoding_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 result;
|
||||
}
|
||||
|
||||
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(ma_format_u8, decoder.outputChannels);
|
||||
ma_uint64 framesToRead;
|
||||
ma_uint64 framesJustRead;
|
||||
|
||||
framesToRead = ma_min(tempCapIn, tempCapOut);
|
||||
ma_decoder_read_pcm_frames(&decoder, tempIn, framesToRead, &framesJustRead);
|
||||
|
||||
/* Convert, with dithering. */
|
||||
ma_convert_pcm_frames_format(tempOut, ma_format_u8, tempIn, decoder.outputFormat, framesJustRead, decoder.outputChannels, ma_dither_mode_triangle);
|
||||
|
||||
/* Write to the WAV file. */
|
||||
ma_encoder_write_pcm_frames(&encoder, tempOut, framesJustRead, NULL);
|
||||
|
||||
if (framesJustRead < framesToRead) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ma_decoder_uninit(&decoder);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
int test_entry__dithering(int argc, char** argv)
|
||||
{
|
||||
ma_result result;
|
||||
ma_bool32 hasError = MA_FALSE;
|
||||
const char* pInputFilePath;
|
||||
|
||||
if (argc < 2) {
|
||||
printf("No input file.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
pInputFilePath = argv[1];
|
||||
|
||||
result = test_dithering__u8(pInputFilePath);
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
if (hasError) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
ma_result hishelf_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);
|
||||
}
|
||||
|
||||
|
||||
ma_result test_hishelf2__by_format(const char* pInputFilePath, const char* pOutputFilePath, ma_format format)
|
||||
{
|
||||
ma_result result;
|
||||
ma_decoder decoder;
|
||||
ma_encoder encoder;
|
||||
ma_hishelf2_config hishelfConfig;
|
||||
ma_hishelf2 hishelf;
|
||||
|
||||
printf(" %s\n", pOutputFilePath);
|
||||
|
||||
result = hishelf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &encoder);
|
||||
if (result != MA_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
|
||||
hishelfConfig = ma_hishelf2_config_init(decoder.outputFormat, decoder.outputChannels, decoder.outputSampleRate, 18, 1, 16000);
|
||||
result = ma_hishelf2_init(&hishelfConfig, NULL, &hishelf);
|
||||
if (result != MA_SUCCESS) {
|
||||
ma_decoder_uninit(&decoder);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return result;
|
||||
}
|
||||
|
||||
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);
|
||||
ma_decoder_read_pcm_frames(&decoder, tempIn, framesToRead, &framesJustRead);
|
||||
|
||||
/* Filter */
|
||||
ma_hishelf2_process_pcm_frames(&hishelf, tempOut, tempIn, framesJustRead);
|
||||
|
||||
/* Write to the WAV file. */
|
||||
ma_encoder_write_pcm_frames(&encoder, tempOut, framesJustRead, NULL);
|
||||
|
||||
if (framesJustRead < framesToRead) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ma_decoder_uninit(&decoder);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
ma_result test_hishelf2__f32(const char* pInputFilePath)
|
||||
{
|
||||
return test_hishelf2__by_format(pInputFilePath, TEST_OUTPUT_DIR"/hishelf2_f32.wav", ma_format_f32);
|
||||
}
|
||||
|
||||
ma_result test_hishelf2__s16(const char* pInputFilePath)
|
||||
{
|
||||
return test_hishelf2__by_format(pInputFilePath, TEST_OUTPUT_DIR"/hishelf2_s16.wav", ma_format_s16);
|
||||
}
|
||||
|
||||
#if 0
|
||||
ma_result test_hishelf4__by_format(const char* pInputFilePath, const char* pOutputFilePath, ma_format format)
|
||||
{
|
||||
ma_result result;
|
||||
ma_decoder decoder;
|
||||
ma_encoder encoder;
|
||||
ma_hishelf_config hishelfConfig;
|
||||
ma_hishelf hishelf;
|
||||
|
||||
printf(" %s\n", pOutputFilePath);
|
||||
|
||||
result = hishelf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &encoder);
|
||||
if (result != MA_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
|
||||
hishelfConfig = ma_hishelf_config_init(decoder.outputFormat, decoder.outputChannels, decoder.outputSampleRate, 2000, 4);
|
||||
result = ma_hishelf_init(&hishelfConfig, &hishelf);
|
||||
if (result != MA_SUCCESS) {
|
||||
ma_decoder_uninit(&decoder);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return result;
|
||||
}
|
||||
|
||||
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_hishelf_process_pcm_frames(&hishelf, tempOut, tempIn, framesJustRead);
|
||||
|
||||
/* Write to the WAV file. */
|
||||
ma_encoder_write_pcm_frames(&encoder, tempOut, framesJustRead);
|
||||
|
||||
if (framesJustRead < framesToRead) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ma_decoder_uninit(&decoder);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
ma_result test_hishelf4__f32(const char* pInputFilePath)
|
||||
{
|
||||
return test_hishelf4__by_format(pInputFilePath, TEST_OUTPUT_DIR"/hishelf4_f32.wav", ma_format_f32);
|
||||
}
|
||||
|
||||
ma_result test_hishelf4__s16(const char* pInputFilePath)
|
||||
{
|
||||
return test_hishelf4__by_format(pInputFilePath, TEST_OUTPUT_DIR"/hishelf4_s16.wav", ma_format_s16);
|
||||
}
|
||||
#endif
|
||||
|
||||
int test_entry__hishelf(int argc, char** argv)
|
||||
{
|
||||
ma_result result;
|
||||
ma_bool32 hasError = MA_FALSE;
|
||||
const char* pInputFilePath;
|
||||
|
||||
if (argc < 2) {
|
||||
printf("No input file.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
pInputFilePath = argv[1];
|
||||
|
||||
|
||||
result = test_hishelf2__f32(pInputFilePath);
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
result = test_hishelf2__s16(pInputFilePath);
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
#if 0
|
||||
result = test_hishelf4__f32(pInputFilePath);
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
result = test_hishelf4__s16(pInputFilePath);
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (hasError) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,242 @@
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
ma_result test_hpf1__by_format(const char* pInputFilePath, const char* pOutputFilePath, ma_format format)
|
||||
{
|
||||
ma_result result;
|
||||
ma_decoder decoder;
|
||||
ma_encoder encoder;
|
||||
ma_hpf1_config hpfConfig;
|
||||
ma_hpf1 hpf;
|
||||
|
||||
printf(" %s\n", pOutputFilePath);
|
||||
|
||||
result = hpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &encoder);
|
||||
if (result != MA_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
|
||||
hpfConfig = ma_hpf1_config_init(decoder.outputFormat, decoder.outputChannels, decoder.outputSampleRate, 2000);
|
||||
result = ma_hpf1_init(&hpfConfig, NULL, &hpf);
|
||||
if (result != MA_SUCCESS) {
|
||||
ma_decoder_uninit(&decoder);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return result;
|
||||
}
|
||||
|
||||
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);
|
||||
ma_decoder_read_pcm_frames(&decoder, tempIn, framesToRead, &framesJustRead);
|
||||
|
||||
/* Filter */
|
||||
ma_hpf1_process_pcm_frames(&hpf, tempOut, tempIn, framesJustRead);
|
||||
|
||||
/* Write to the WAV file. */
|
||||
ma_encoder_write_pcm_frames(&encoder, tempOut, framesJustRead, NULL);
|
||||
|
||||
if (framesJustRead < framesToRead) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ma_decoder_uninit(&decoder);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
ma_result test_hpf1__f32(const char* pInputFilePath)
|
||||
{
|
||||
return test_hpf1__by_format(pInputFilePath, TEST_OUTPUT_DIR"/hpf1_f32.wav", ma_format_f32);
|
||||
}
|
||||
|
||||
ma_result test_hpf1__s16(const char* pInputFilePath)
|
||||
{
|
||||
return test_hpf1__by_format(pInputFilePath, TEST_OUTPUT_DIR"/hpf1_s16.wav", ma_format_s16);
|
||||
}
|
||||
|
||||
|
||||
ma_result test_hpf2__by_format(const char* pInputFilePath, const char* pOutputFilePath, ma_format format)
|
||||
{
|
||||
ma_result result;
|
||||
ma_decoder decoder;
|
||||
ma_encoder encoder;
|
||||
ma_hpf2_config hpfConfig;
|
||||
ma_hpf2 hpf;
|
||||
|
||||
printf(" %s\n", pOutputFilePath);
|
||||
|
||||
result = hpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &encoder);
|
||||
if (result != MA_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
|
||||
hpfConfig = ma_hpf2_config_init(decoder.outputFormat, decoder.outputChannels, decoder.outputSampleRate, 2000, 0);
|
||||
result = ma_hpf2_init(&hpfConfig, NULL, &hpf);
|
||||
if (result != MA_SUCCESS) {
|
||||
ma_decoder_uninit(&decoder);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return result;
|
||||
}
|
||||
|
||||
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);
|
||||
ma_decoder_read_pcm_frames(&decoder, tempIn, framesToRead, &framesJustRead);
|
||||
|
||||
/* Filter */
|
||||
ma_hpf2_process_pcm_frames(&hpf, tempOut, tempIn, framesJustRead);
|
||||
|
||||
/* Write to the WAV file. */
|
||||
ma_encoder_write_pcm_frames(&encoder, tempOut, framesJustRead, NULL);
|
||||
|
||||
if (framesJustRead < framesToRead) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ma_decoder_uninit(&decoder);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
ma_result test_hpf2__f32(const char* pInputFilePath)
|
||||
{
|
||||
return test_hpf2__by_format(pInputFilePath, TEST_OUTPUT_DIR"/hpf2_f32.wav", ma_format_f32);
|
||||
}
|
||||
|
||||
ma_result test_hpf2__s16(const char* pInputFilePath)
|
||||
{
|
||||
return test_hpf2__by_format(pInputFilePath, TEST_OUTPUT_DIR"/hpf2_s16.wav", ma_format_s16);
|
||||
}
|
||||
|
||||
|
||||
ma_result test_hpf3__by_format(const char* pInputFilePath, const char* pOutputFilePath, ma_format format)
|
||||
{
|
||||
ma_result result;
|
||||
ma_decoder decoder;
|
||||
ma_encoder encoder;
|
||||
ma_hpf_config hpfConfig;
|
||||
ma_hpf hpf;
|
||||
|
||||
printf(" %s\n", pOutputFilePath);
|
||||
|
||||
result = hpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &encoder);
|
||||
if (result != MA_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
|
||||
hpfConfig = ma_hpf_config_init(decoder.outputFormat, decoder.outputChannels, decoder.outputSampleRate, 2000, 3);
|
||||
result = ma_hpf_init(&hpfConfig, NULL, &hpf);
|
||||
if (result != MA_SUCCESS) {
|
||||
ma_decoder_uninit(&decoder);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return result;
|
||||
}
|
||||
|
||||
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);
|
||||
ma_decoder_read_pcm_frames(&decoder, tempIn, framesToRead, &framesJustRead);
|
||||
|
||||
/* Filter */
|
||||
ma_hpf_process_pcm_frames(&hpf, tempOut, tempIn, framesJustRead);
|
||||
|
||||
/* Write to the WAV file. */
|
||||
ma_encoder_write_pcm_frames(&encoder, tempOut, framesJustRead, NULL);
|
||||
|
||||
if (framesJustRead < framesToRead) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ma_decoder_uninit(&decoder);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
ma_result test_hpf3__f32(const char* pInputFilePath)
|
||||
{
|
||||
return test_hpf3__by_format(pInputFilePath, TEST_OUTPUT_DIR"/hpf3_f32.wav", ma_format_f32);
|
||||
}
|
||||
|
||||
ma_result test_hpf3__s16(const char* pInputFilePath)
|
||||
{
|
||||
return test_hpf3__by_format(pInputFilePath, TEST_OUTPUT_DIR"/hpf3_s16.wav", ma_format_s16);
|
||||
}
|
||||
|
||||
|
||||
int test_entry__hpf(int argc, char** argv)
|
||||
{
|
||||
ma_result result;
|
||||
ma_bool32 hasError = MA_FALSE;
|
||||
const char* pInputFilePath;
|
||||
|
||||
if (argc < 2) {
|
||||
printf("No input file.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
pInputFilePath = argv[1];
|
||||
|
||||
|
||||
result = test_hpf1__f32(pInputFilePath);
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
result = test_hpf1__s16(pInputFilePath);
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
|
||||
result = test_hpf2__f32(pInputFilePath);
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
result = test_hpf2__s16(pInputFilePath);
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
|
||||
result = test_hpf3__f32(pInputFilePath);
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
result = test_hpf3__s16(pInputFilePath);
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
|
||||
if (hasError) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
ma_result loshelf_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);
|
||||
}
|
||||
|
||||
|
||||
ma_result test_loshelf2__by_format(const char* pInputFilePath, const char* pOutputFilePath, ma_format format)
|
||||
{
|
||||
ma_result result;
|
||||
ma_decoder decoder;
|
||||
ma_encoder encoder;
|
||||
ma_loshelf2_config loshelfConfig;
|
||||
ma_loshelf2 loshelf;
|
||||
|
||||
printf(" %s\n", pOutputFilePath);
|
||||
|
||||
result = loshelf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &encoder);
|
||||
if (result != MA_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
|
||||
loshelfConfig = ma_loshelf2_config_init(decoder.outputFormat, decoder.outputChannels, decoder.outputSampleRate, 6, 1, 200);
|
||||
result = ma_loshelf2_init(&loshelfConfig, NULL, &loshelf);
|
||||
if (result != MA_SUCCESS) {
|
||||
ma_decoder_uninit(&decoder);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return result;
|
||||
}
|
||||
|
||||
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);
|
||||
ma_decoder_read_pcm_frames(&decoder, tempIn, framesToRead, &framesJustRead);
|
||||
|
||||
/* Filter */
|
||||
ma_loshelf2_process_pcm_frames(&loshelf, tempOut, tempIn, framesJustRead);
|
||||
|
||||
/* Write to the WAV file. */
|
||||
ma_encoder_write_pcm_frames(&encoder, tempOut, framesJustRead, NULL);
|
||||
|
||||
if (framesJustRead < framesToRead) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ma_decoder_uninit(&decoder);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
ma_result test_loshelf2__f32(const char* pInputFilePath)
|
||||
{
|
||||
return test_loshelf2__by_format(pInputFilePath, TEST_OUTPUT_DIR"/loshelf2_f32.wav", ma_format_f32);
|
||||
}
|
||||
|
||||
ma_result test_loshelf2__s16(const char* pInputFilePath)
|
||||
{
|
||||
return test_loshelf2__by_format(pInputFilePath, TEST_OUTPUT_DIR"/loshelf2_s16.wav", ma_format_s16);
|
||||
}
|
||||
|
||||
#if 0
|
||||
ma_result test_loshelf4__by_format(const char* pInputFilePath, const char* pOutputFilePath, ma_format format)
|
||||
{
|
||||
ma_result result;
|
||||
ma_decoder decoder;
|
||||
ma_encoder encoder;
|
||||
ma_loshelf_config loshelfConfig;
|
||||
ma_loshelf loshelf;
|
||||
|
||||
printf(" %s\n", pOutputFilePath);
|
||||
|
||||
result = loshelf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &encoder);
|
||||
if (result != MA_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
|
||||
loshelfConfig = ma_loshelf_config_init(decoder.outputFormat, decoder.outputChannels, decoder.outputSampleRate, 2000, 4);
|
||||
result = ma_loshelf_init(&loshelfConfig, &loshelf);
|
||||
if (result != MA_SUCCESS) {
|
||||
ma_decoder_uninit(&decoder);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return result;
|
||||
}
|
||||
|
||||
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_loshelf_process_pcm_frames(&loshelf, tempOut, tempIn, framesJustRead);
|
||||
|
||||
/* Write to the WAV file. */
|
||||
ma_encoder_write_pcm_frames(&encoder, tempOut, framesJustRead);
|
||||
|
||||
if (framesJustRead < framesToRead) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ma_decoder_uninit(&decoder);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
ma_result test_loshelf4__f32(const char* pInputFilePath)
|
||||
{
|
||||
return test_loshelf4__by_format(pInputFilePath, TEST_OUTPUT_DIR"/loshelf4_f32.wav", ma_format_f32);
|
||||
}
|
||||
|
||||
ma_result test_loshelf4__s16(const char* pInputFilePath)
|
||||
{
|
||||
return test_loshelf4__by_format(pInputFilePath, TEST_OUTPUT_DIR"/loshelf4_s16.wav", ma_format_s16);
|
||||
}
|
||||
#endif
|
||||
|
||||
int test_entry__loshelf(int argc, char** argv)
|
||||
{
|
||||
ma_result result;
|
||||
ma_bool32 hasError = MA_FALSE;
|
||||
const char* pInputFilePath;
|
||||
|
||||
if (argc < 2) {
|
||||
printf("No input file.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
pInputFilePath = argv[1];
|
||||
|
||||
|
||||
result = test_loshelf2__f32(pInputFilePath);
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
result = test_loshelf2__s16(pInputFilePath);
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
#if 0
|
||||
result = test_loshelf4__f32(pInputFilePath);
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
result = test_loshelf4__s16(pInputFilePath);
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (hasError) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,242 @@
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
ma_result test_lpf1__by_format(const char* pInputFilePath, const char* pOutputFilePath, ma_format format)
|
||||
{
|
||||
ma_result result;
|
||||
ma_decoder decoder;
|
||||
ma_encoder encoder;
|
||||
ma_lpf1_config lpfConfig;
|
||||
ma_lpf1 lpf;
|
||||
|
||||
printf(" %s\n", pOutputFilePath);
|
||||
|
||||
result = lpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &encoder);
|
||||
if (result != MA_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
|
||||
lpfConfig = ma_lpf1_config_init(decoder.outputFormat, decoder.outputChannels, decoder.outputSampleRate, 2000);
|
||||
result = ma_lpf1_init(&lpfConfig, NULL, &lpf);
|
||||
if (result != MA_SUCCESS) {
|
||||
ma_decoder_uninit(&decoder);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return result;
|
||||
}
|
||||
|
||||
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);
|
||||
ma_decoder_read_pcm_frames(&decoder, tempIn, framesToRead, &framesJustRead);
|
||||
|
||||
/* Filter */
|
||||
ma_lpf1_process_pcm_frames(&lpf, tempOut, tempIn, framesJustRead);
|
||||
|
||||
/* Write to the WAV file. */
|
||||
ma_encoder_write_pcm_frames(&encoder, tempOut, framesJustRead, NULL);
|
||||
|
||||
if (framesJustRead < framesToRead) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ma_decoder_uninit(&decoder);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
ma_result test_lpf1__f32(const char* pInputFilePath)
|
||||
{
|
||||
return test_lpf1__by_format(pInputFilePath, TEST_OUTPUT_DIR"/lpf1_f32.wav", ma_format_f32);
|
||||
}
|
||||
|
||||
ma_result test_lpf1__s16(const char* pInputFilePath)
|
||||
{
|
||||
return test_lpf1__by_format(pInputFilePath, TEST_OUTPUT_DIR"/lpf1_s16.wav", ma_format_s16);
|
||||
}
|
||||
|
||||
|
||||
ma_result test_lpf2__by_format(const char* pInputFilePath, const char* pOutputFilePath, ma_format format)
|
||||
{
|
||||
ma_result result;
|
||||
ma_decoder decoder;
|
||||
ma_encoder encoder;
|
||||
ma_lpf2_config lpfConfig;
|
||||
ma_lpf2 lpf;
|
||||
|
||||
printf(" %s\n", pOutputFilePath);
|
||||
|
||||
result = lpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &encoder);
|
||||
if (result != MA_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
|
||||
lpfConfig = ma_lpf2_config_init(decoder.outputFormat, decoder.outputChannels, decoder.outputSampleRate, 2000, 0);
|
||||
result = ma_lpf2_init(&lpfConfig, NULL, &lpf);
|
||||
if (result != MA_SUCCESS) {
|
||||
ma_decoder_uninit(&decoder);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return result;
|
||||
}
|
||||
|
||||
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);
|
||||
ma_decoder_read_pcm_frames(&decoder, tempIn, framesToRead, &framesJustRead);
|
||||
|
||||
/* Filter */
|
||||
ma_lpf2_process_pcm_frames(&lpf, tempOut, tempIn, framesJustRead);
|
||||
|
||||
/* Write to the WAV file. */
|
||||
ma_encoder_write_pcm_frames(&encoder, tempOut, framesJustRead, NULL);
|
||||
|
||||
if (framesJustRead < framesToRead) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ma_decoder_uninit(&decoder);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
ma_result test_lpf2__f32(const char* pInputFilePath)
|
||||
{
|
||||
return test_lpf2__by_format(pInputFilePath, TEST_OUTPUT_DIR"/lpf2_f32.wav", ma_format_f32);
|
||||
}
|
||||
|
||||
ma_result test_lpf2__s16(const char* pInputFilePath)
|
||||
{
|
||||
return test_lpf2__by_format(pInputFilePath, TEST_OUTPUT_DIR"/lpf2_s16.wav", ma_format_s16);
|
||||
}
|
||||
|
||||
|
||||
|
||||
ma_result test_lpf3__by_format(const char* pInputFilePath, const char* pOutputFilePath, ma_format format)
|
||||
{
|
||||
ma_result result;
|
||||
ma_decoder decoder;
|
||||
ma_encoder encoder;
|
||||
ma_lpf_config lpfConfig;
|
||||
ma_lpf lpf;
|
||||
|
||||
printf(" %s\n", pOutputFilePath);
|
||||
|
||||
result = lpf_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &encoder);
|
||||
if (result != MA_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
|
||||
lpfConfig = ma_lpf_config_init(decoder.outputFormat, decoder.outputChannels, decoder.outputSampleRate, 2000, /*poles*/3);
|
||||
result = ma_lpf_init(&lpfConfig, NULL, &lpf);
|
||||
if (result != MA_SUCCESS) {
|
||||
ma_decoder_uninit(&decoder);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return result;
|
||||
}
|
||||
|
||||
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);
|
||||
ma_decoder_read_pcm_frames(&decoder, tempIn, framesToRead, &framesJustRead);
|
||||
|
||||
/* Filter */
|
||||
ma_lpf_process_pcm_frames(&lpf, tempOut, tempIn, framesJustRead);
|
||||
|
||||
/* Write to the WAV file. */
|
||||
ma_encoder_write_pcm_frames(&encoder, tempOut, framesJustRead, NULL);
|
||||
|
||||
if (framesJustRead < framesToRead) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ma_decoder_uninit(&decoder);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
ma_result test_lpf3__f32(const char* pInputFilePath)
|
||||
{
|
||||
return test_lpf3__by_format(pInputFilePath, TEST_OUTPUT_DIR"/lpf3_f32.wav", ma_format_f32);
|
||||
}
|
||||
|
||||
ma_result test_lpf3__s16(const char* pInputFilePath)
|
||||
{
|
||||
return test_lpf3__by_format(pInputFilePath, TEST_OUTPUT_DIR"/lpf3_s16.wav", ma_format_s16);
|
||||
}
|
||||
|
||||
|
||||
int test_entry__lpf(int argc, char** argv)
|
||||
{
|
||||
ma_result result;
|
||||
ma_bool32 hasError = MA_FALSE;
|
||||
const char* pInputFilePath;
|
||||
|
||||
if (argc < 2) {
|
||||
printf("No input file.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
pInputFilePath = argv[1];
|
||||
|
||||
result = test_lpf1__f32(pInputFilePath);
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
result = test_lpf1__s16(pInputFilePath);
|
||||
if (result != MA_SUCCESS) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
result = test_lpf3__f32(pInputFilePath);
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
result = test_lpf3__s16(pInputFilePath);
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
|
||||
if (hasError) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
ma_result notch_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);
|
||||
}
|
||||
|
||||
|
||||
ma_result test_notch2__by_format(const char* pInputFilePath, const char* pOutputFilePath, ma_format format)
|
||||
{
|
||||
ma_result result;
|
||||
ma_decoder decoder;
|
||||
ma_encoder encoder;
|
||||
ma_notch2_config notchConfig;
|
||||
ma_notch2 notch;
|
||||
|
||||
printf(" %s\n", pOutputFilePath);
|
||||
|
||||
result = notch_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &encoder);
|
||||
if (result != MA_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
|
||||
notchConfig = ma_notch2_config_init(decoder.outputFormat, decoder.outputChannels, decoder.outputSampleRate, 1, 60);
|
||||
result = ma_notch2_init(¬chConfig, NULL, ¬ch);
|
||||
if (result != MA_SUCCESS) {
|
||||
ma_decoder_uninit(&decoder);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return result;
|
||||
}
|
||||
|
||||
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);
|
||||
ma_decoder_read_pcm_frames(&decoder, tempIn, framesToRead, &framesJustRead);
|
||||
|
||||
/* Filter */
|
||||
ma_notch2_process_pcm_frames(¬ch, tempOut, tempIn, framesJustRead);
|
||||
|
||||
/* Write to the WAV file. */
|
||||
ma_encoder_write_pcm_frames(&encoder, tempOut, framesJustRead, NULL);
|
||||
|
||||
if (framesJustRead < framesToRead) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ma_decoder_uninit(&decoder);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
ma_result test_notch2__f32(const char* pInputFilePath)
|
||||
{
|
||||
return test_notch2__by_format(pInputFilePath, TEST_OUTPUT_DIR"/notch2_f32.wav", ma_format_f32);
|
||||
}
|
||||
|
||||
ma_result test_notch2__s16(const char* pInputFilePath)
|
||||
{
|
||||
return test_notch2__by_format(pInputFilePath, TEST_OUTPUT_DIR"/notch2_s16.wav", ma_format_s16);
|
||||
}
|
||||
|
||||
#if 0
|
||||
ma_result test_notch4__by_format(const char* pInputFilePath, const char* pOutputFilePath, ma_format format)
|
||||
{
|
||||
ma_result result;
|
||||
ma_decoder decoder;
|
||||
ma_encoder encoder;
|
||||
ma_notch_config notchConfig;
|
||||
ma_notch notch;
|
||||
|
||||
printf(" %s\n", pOutputFilePath);
|
||||
|
||||
result = notch_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &encoder);
|
||||
if (result != MA_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
|
||||
notchConfig = ma_notch_config_init(decoder.outputFormat, decoder.outputChannels, decoder.outputSampleRate, 2000, 4);
|
||||
result = ma_notch_init(¬chConfig, ¬ch);
|
||||
if (result != MA_SUCCESS) {
|
||||
ma_decoder_uninit(&decoder);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return result;
|
||||
}
|
||||
|
||||
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_notch_process_pcm_frames(¬ch, tempOut, tempIn, framesJustRead);
|
||||
|
||||
/* Write to the WAV file. */
|
||||
ma_encoder_write_pcm_frames(&encoder, tempOut, framesJustRead);
|
||||
|
||||
if (framesJustRead < framesToRead) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ma_decoder_uninit(&decoder);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
ma_result test_notch4__f32(const char* pInputFilePath)
|
||||
{
|
||||
return test_notch4__by_format(pInputFilePath, TEST_OUTPUT_DIR"/notch4_f32.wav", ma_format_f32);
|
||||
}
|
||||
|
||||
ma_result test_notch4__s16(const char* pInputFilePath)
|
||||
{
|
||||
return test_notch4__by_format(pInputFilePath, TEST_OUTPUT_DIR"/notch4_s16.wav", ma_format_s16);
|
||||
}
|
||||
#endif
|
||||
|
||||
int test_entry__notch(int argc, char** argv)
|
||||
{
|
||||
ma_result result;
|
||||
ma_bool32 hasError = MA_FALSE;
|
||||
const char* pInputFilePath;
|
||||
|
||||
if (argc < 2) {
|
||||
printf("No input file.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
pInputFilePath = argv[1];
|
||||
|
||||
|
||||
result = test_notch2__f32(pInputFilePath);
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
result = test_notch2__s16(pInputFilePath);
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
#if 0
|
||||
result = test_notch4__f32(pInputFilePath);
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
result = test_notch4__s16(pInputFilePath);
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (hasError) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
ma_result peak_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);
|
||||
}
|
||||
|
||||
|
||||
ma_result test_peak2__by_format(const char* pInputFilePath, const char* pOutputFilePath, ma_format format)
|
||||
{
|
||||
ma_result result;
|
||||
ma_decoder decoder;
|
||||
ma_encoder encoder;
|
||||
ma_peak2_config peakConfig;
|
||||
ma_peak2 peak;
|
||||
|
||||
printf(" %s\n", pOutputFilePath);
|
||||
|
||||
result = peak_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &encoder);
|
||||
if (result != MA_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
|
||||
peakConfig = ma_peak2_config_init(decoder.outputFormat, decoder.outputChannels, decoder.outputSampleRate, 24, 0, 16000);
|
||||
result = ma_peak2_init(&peakConfig, NULL, &peak);
|
||||
if (result != MA_SUCCESS) {
|
||||
ma_decoder_uninit(&decoder);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return result;
|
||||
}
|
||||
|
||||
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);
|
||||
ma_decoder_read_pcm_frames(&decoder, tempIn, framesToRead, &framesJustRead);
|
||||
|
||||
/* Filter */
|
||||
ma_peak2_process_pcm_frames(&peak, tempOut, tempIn, framesJustRead);
|
||||
|
||||
/* Write to the WAV file. */
|
||||
ma_encoder_write_pcm_frames(&encoder, tempOut, framesJustRead, NULL);
|
||||
|
||||
if (framesJustRead < framesToRead) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ma_decoder_uninit(&decoder);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
ma_result test_peak2__f32(const char* pInputFilePath)
|
||||
{
|
||||
return test_peak2__by_format(pInputFilePath, TEST_OUTPUT_DIR"/peak2_f32.wav", ma_format_f32);
|
||||
}
|
||||
|
||||
ma_result test_peak2__s16(const char* pInputFilePath)
|
||||
{
|
||||
return test_peak2__by_format(pInputFilePath, TEST_OUTPUT_DIR"/peak2_s16.wav", ma_format_s16);
|
||||
}
|
||||
|
||||
#if 0
|
||||
ma_result test_peak4__by_format(const char* pInputFilePath, const char* pOutputFilePath, ma_format format)
|
||||
{
|
||||
ma_result result;
|
||||
ma_decoder decoder;
|
||||
ma_encoder encoder;
|
||||
ma_peak_config peakConfig;
|
||||
ma_peak peak;
|
||||
|
||||
printf(" %s\n", pOutputFilePath);
|
||||
|
||||
result = peak_init_decoder_and_encoder(pInputFilePath, pOutputFilePath, format, &decoder, &encoder);
|
||||
if (result != MA_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
|
||||
peakConfig = ma_peak_config_init(decoder.outputFormat, decoder.outputChannels, decoder.outputSampleRate, 2000, 4);
|
||||
result = ma_peak_init(&peakConfig, &peak);
|
||||
if (result != MA_SUCCESS) {
|
||||
ma_decoder_uninit(&decoder);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return result;
|
||||
}
|
||||
|
||||
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_peak_process_pcm_frames(&peak, tempOut, tempIn, framesJustRead);
|
||||
|
||||
/* Write to the WAV file. */
|
||||
ma_encoder_write_pcm_frames(&encoder, tempOut, framesJustRead);
|
||||
|
||||
if (framesJustRead < framesToRead) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ma_decoder_uninit(&decoder);
|
||||
ma_encoder_uninit(&encoder);
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
ma_result test_peak4__f32(const char* pInputFilePath)
|
||||
{
|
||||
return test_peak4__by_format(pInputFilePath, TEST_OUTPUT_DIR"/peak4_f32.wav", ma_format_f32);
|
||||
}
|
||||
|
||||
ma_result test_peak4__s16(const char* pInputFilePath)
|
||||
{
|
||||
return test_peak4__by_format(pInputFilePath, TEST_OUTPUT_DIR"/peak4_s16.wav", ma_format_s16);
|
||||
}
|
||||
#endif
|
||||
|
||||
int test_entry__peak(int argc, char** argv)
|
||||
{
|
||||
ma_result result;
|
||||
ma_bool32 hasError = MA_FALSE;
|
||||
const char* pInputFilePath;
|
||||
|
||||
if (argc < 2) {
|
||||
printf("No input file.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
pInputFilePath = argv[1];
|
||||
|
||||
|
||||
result = test_peak2__f32(pInputFilePath);
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
result = test_peak2__s16(pInputFilePath);
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
#if 0
|
||||
result = test_peak4__f32(pInputFilePath);
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
result = test_peak4__s16(pInputFilePath);
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (hasError) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user