Home Superpowered SDK - real-time filter
Reply: 2

Superpowered SDK - real-time filter

Hanna Shahid
1#
Hanna Shahid Published in 2018-02-13 12:01:07Z

My Target is to make an app that captures audio from mic then pass it to band-pass filter and multiply it by some gain then output result in real-time to the speaker
so I had edited FrequencyDomain.cpp Example in the Superpowered SDK to match my purpose , I tried this code but i can't hear the output audio ,, what is missing in my Code ?

static SuperpoweredFrequencyDomain *frequencyDomain;
static float  *inputBufferFloat;

// This is called periodically by the media server.
static bool audioProcessing(void * __unused clientdata, short int 
*audioInputOutput, int numberOfSamples, int __unused samplerate) {
// Creating the filter.
SuperpoweredFilter *filter = new 
SuperpoweredFilter(SuperpoweredFilter_Resonant_Lowpass, samplerate);
filter->setResonantParameters(1000.0f, 0.1f);
filter->enable(true);
filter->process(stereoBuffer, stereoBuffer, numberOfSamples);
SuperpoweredShortIntToFloat(audioInputOutput, inputBufferFloat, (unsigned int)numberOfSamples); // Converting the 16-bit integer samples to 32-bit floating point.       
}
extern "C" JNIEXPORT void 
Java_com_superpowered_frequencydomain_MainActivity_FrequencyDomain(JNIEnv * 
__unused javaEnvironment, jobject __unused obj, jint samplerate, jint buffersize) {


inputBufferFloat = (float *)malloc(buffersize * sizeof(float) * 2 + 128);

SuperpoweredCPU::setSustainedPerformanceMode(true);
new SuperpoweredAndroidAudioIO(samplerate, buffersize, true, true, audioProcessing, NULL, -1, SL_ANDROID_STREAM_MEDIA, buffersize * 2); // Start audio input/output.
}
Gabor Szanto
2#
Gabor Szanto Reply to 2018-02-14 17:33:12Z

Don't create your filter in the audio processing callback. As you can see in the comment above it, it is called periodically by the media server (the operating system's audio stack).

Only filter->process() should be inside the audio processing callback.

You are not hearing audio output, because the rest of your code in the audio processing callback is nonsense.

The microphone input arrives in the "audioInputOutput" array. You need to convert it to floating point data first using SuperpoweredShortIntToFloat. Then you need to process that data with your filter. Finally, you convert the data back to short int using SuperpoweredFloatToShortInt. That is only 3 lines of code.

Hanna Shahid
3#
Hanna Shahid Reply to 2018-02-15 17:05:26Z

I managed to solve it by editing the frequencyDomain example like this

static bool audioProcessing(void *clientdata, short int *audioIO, int numberOfSamples, int __unused samplerate) {
SuperpoweredShortIntToFloat(audioIO, inputBufferFloat, (unsigned int)numberOfSamples);
return ((FrequencyDomain *)clientdata)->process(audioIO, (unsigned int)numberOfSamples);
 }
 FrequencyDomain::FrequencyDomain(unsigned int samplerate, unsigned int buffersize)  {

audioSystem = new SuperpoweredAndroidAudioIO(samplerate, buffersize, true, true, audioProcessing, this, -1, SL_ANDROID_STREAM_MEDIA, buffersize * 2);
}

bool FrequencyDomain::process(short int *output, unsigned int numberOfSamples) {

filterHighpass->enable(true);
filterHighpass->process(inputBufferFloat, outputBufferFloatHigh, numberOfSamples);
filter = new SuperpoweredFilter(SuperpoweredFilter_Resonant_Lowpass, numberOfSamples);
filter->setResonantParameters(200.0f, 0.1f);
filter->enable(true);
filter->process(inputBufferFloat, inputBufferFloat, numberOfSamples);

SuperpoweredFloatToShortInt(inputBufferFloat, output, numberOfSamples);

return true;
}
static FrequencyDomain *example = NULL;
extern "C" JNIEXPORT void Java_com_superpowered_frequencydomain_MainActivity_FrequencyDomain(JNIEnv * __unused javaEnvironment, jobject __unused obj, jint samplerate, jint buffersize) {

inputBufferFloat = (float *)malloc(buffersize * sizeof(float) * 2 + 128);

SuperpoweredCPU::setSustainedPerformanceMode(true);

example=new FrequencyDomain((unsigned int)samplerate, (unsigned int)buffersize);
}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.351607 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO