mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-23 16:54:03 +02:00
Add ma_lpf with support for configuring the number of poles.
This commit is contained in:
@@ -124,6 +124,67 @@ ma_result test_lpf2__s16(const char* pInputFilePath)
|
||||
}
|
||||
|
||||
|
||||
|
||||
ma_result test_lpf3__by_format(const char* pInputFilePath, const char* pOutputFilePath, ma_format format)
|
||||
{
|
||||
ma_result result;
|
||||
ma_decoder decoder;
|
||||
drwav wav;
|
||||
ma_lpf_config lpfConfig;
|
||||
ma_lpf lpf;
|
||||
|
||||
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, /*poles*/3);
|
||||
result = ma_lpf_init(&lpfConfig, &lpf);
|
||||
if (result != MA_SUCCESS) {
|
||||
ma_decoder_uninit(&decoder);
|
||||
drwav_uninit(&wav);
|
||||
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_lpf_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_lpf3__f32(const char* pInputFilePath)
|
||||
{
|
||||
return test_lpf3__by_format(pInputFilePath, "output/lpf3_f32.wav", ma_format_f32);
|
||||
}
|
||||
|
||||
ma_result test_lpf3__s16(const char* pInputFilePath)
|
||||
{
|
||||
return test_lpf3__by_format(pInputFilePath, "output/lpf3_s16.wav", ma_format_s16);
|
||||
}
|
||||
|
||||
|
||||
int test_entry__lpf(int argc, char** argv)
|
||||
{
|
||||
ma_result result;
|
||||
@@ -159,6 +220,17 @@ int test_entry__lpf(int argc, char** argv)
|
||||
}
|
||||
|
||||
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user