I’m encountering an intermittent issue while using the Superpowered library to process audio in my Android app. I’m implementing an 8-band equalizer for both the left and right channels, along with other effects like reverb. However, sometimes when I activate the equalizer, the audio simply stops playing (it becomes muted).
Here’s a summary of what’s happening:
The audio player works fine without the equalizer. When I enable the equalizer (on both left and right channels), sometimes the audio works perfectly, but other times it goes completely silent. The equalizer is properly set up, and the initial gains for the bands are set to 0dB during initialization. Audio processing is done inside the audioProcessing function, where I apply the equalizer and other effects.
Here’s a snippet of the audio processing code:
static SuperpoweredAndroidAudioIO *audioIO;
static Superpowered::AdvancedAudioPlayer *player;
static SuperpoweredNBandEQ *leftEQ;
static SuperpoweredNBandEQ *rightEQ;
static Superpowered::Waveform *waveform;
static Superpowered::Reverb *reverb;
static const int numberOfBands = 8;
static bool isProcessStereo = false;
static bool audioProcessing (
void * __unused clientdata,
short int *audio,
int numberOfFrames,
int samplerate
) {
player->outputSamplerate = (unsigned int)samplerate;
float playerOutput[numberOfFrames * 2]; // Buffer intercalado de áudio estéreo
if (player->processStereo(playerOutput, false, (unsigned int)numberOfFrames)) {
reverb->samplerate = samplerate;
reverb->process(playerOutput, playerOutput, numberOfFrames);
float leftChannel[numberOfFrames];
float rightChannel[numberOfFrames];
for (int i = 0; i < numberOfFrames; i++) {
leftChannel[i] = playerOutput[i * 2]; // Canal esquerdo
rightChannel[i] = playerOutput[i * 2 + 1]; // Canal direito
}
// Processar os canais com o equalizador
leftEQ->process(leftChannel, leftChannel, (unsigned int)numberOfFrames);
rightEQ->process(rightChannel, rightChannel, (unsigned int)numberOfFrames);
// Recombinar os canais processados
for (int i = 0; i < numberOfFrames; i++) {
playerOutput[i * 2] = leftChannel[i];
playerOutput[i * 2 + 1] = rightChannel[i];
}
waveform->process(playerOutput, numberOfFrames, -1);
Superpowered::FloatToShortIntInterleave(leftChannel, rightChannel, audio, (unsigned int)numberOfFrames);
isProcessStereo = true;
} else {
isProcessStereo = false;
}
return isProcessStereo;
}
extern "C"
JNIEXPORT void JNICALL
Java_com_expert_mixer_core_superpowered_SuperpoweredPlayerManager_NativeInit(JNIEnv *env, jobject thiz, jint samplerate,
jint buffersize, jstring tempPath) {
Superpowered::Initialize("ExampleLicenseKey-WillExpire-OnNextUpdate");
const char *str = env->GetStringUTFChars(tempPath, nullptr);
Superpowered::AdvancedAudioPlayer::setTempFolder(str);
env->ReleaseStringUTFChars(tempPath, str);
player = new Superpowered::AdvancedAudioPlayer((unsigned int)samplerate, 0);
waveform = new Superpowered::Waveform(
48000,
0
);
float frequencies[numberOfBands] = {60.0f, 170.0f, 310.0f, 600.0f, 1000.0f, 3000.0f, 6000.0f, 12000.0f};
leftEQ = new SuperpoweredNBandEQ((unsigned int)48000, frequencies);
rightEQ = new SuperpoweredNBandEQ((unsigned int)48000, frequencies);
reverb = new Superpowered::Reverb(48000, 48000);
for (int i = 0; i < numberOfBands; i++) {
leftEQ->setGainDb(i, 0.0f);
rightEQ->setGainDb(i, 0.0f);
}
audioIO = new SuperpoweredAndroidAudioIO (
samplerate, // device native sampling rate
buffersize, // device native buffer size
false, // enableInput
true, // enableOutput
audioProcessing, // process callback function
nullptr, // clientData
-1, // inputStreamType (-1 = default)
SL_ANDROID_STREAM_MEDIA // outputStreamType (-1 = default)
);
}
extern "C"
JNIEXPORT void JNICALL
Java_com_expert_mixer_core_superpowered_SuperpoweredPlayerManager_ToggleEqualizer(JNIEnv *env, jobject thiz, jboolean value) {
leftEQ->enabled = value;
rightEQ->enabled = value;
}
I’ve already tried the following:
Resetting the equalizer gains every time Superpowered is initialized. Ensuring the equalizer is properly enabled before processing audio. Has anyone encountered this issue or has suggestions on where I might be going wrong?