Add second order high shelf filter.

This commit is contained in:
David Reid
2020-02-23 21:21:02 +10:00
parent 5b385670f3
commit f305dc9890
3 changed files with 334 additions and 2 deletions
+6 -2
View File
@@ -29,6 +29,7 @@ ma_result filtering_init_decoder_and_encoder(const char* pInputFilePath, const 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)
{
@@ -39,7 +40,6 @@ int main(int argc, char** argv)
(void)argc;
(void)argv;
#if 0
result = ma_register_test("Dithering", test_entry__dithering);
if (result != MA_SUCCESS) {
hasError = MA_TRUE;
@@ -69,12 +69,16 @@ int main(int argc, char** argv)
if (result != MA_SUCCESS) {
hasError = MA_TRUE;
}
#endif
result = ma_register_test("Low Shelf Filtering", test_entry__loshelf);
if (result != MA_SUCCESS) {
hasError = MA_TRUE;
}
result = ma_register_test("High Shelf Filtering", test_entry__hishelf);
if (result != MA_SUCCESS) {
hasError = MA_TRUE;
}
for (iTest = 0; iTest < g_Tests.count; iTest += 1) {
@@ -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, &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_hishelf2_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_hishelf2__f32(const char* pInputFilePath)
{
return test_hishelf2__by_format(pInputFilePath, "output/hishelf2_f32.wav", ma_format_f32);
}
ma_result test_hishelf2__s16(const char* pInputFilePath)
{
return test_hishelf2__by_format(pInputFilePath, "output/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, "output/hishelf4_f32.wav", ma_format_f32);
}
ma_result test_hishelf4__s16(const char* pInputFilePath)
{
return test_hishelf4__by_format(pInputFilePath, "output/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;
}
}