I am using libpd (Pure Data) on Android in order to make an application that can be used as a low budget hearing aid. My original design for the "audio engine" had 7 filters, and the volume from both headphones was the same. I changed the design to have 14 filters and now the right headphone has low volume.
Running the engine on my laptop produces the same volume on both ears. I tried running all the audio processing on it's own thread, but I am not sure if I did this correctly.
So to boil the question down.
Is my implementation of creating a new thread correct?
public class CircleOfFifths extends Activity {
private static final String TAG = "GuitarTuner";
private PdUiDispatcher dispatcher;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initGui();
new Thread(new Runnable() {
public void run(){
try {
initPd();
loadPatch();
} catch (IOException e) {
Log.e(TAG, e.toString());
finish();
} }
}).start();
}
private void initGui() {
setContentView(R.layout.main);
}
private void initPd() throws IOException {
// Configure the audio glue
// int sampleRate = AudioParameters.suggestSampleRate();
int sampleRate = AudioParameters.suggestSampleRate();
int inpch = AudioParameters.suggestInputChannels();
int outch = AudioParameters.suggestOutputChannels();
PdAudio.initAudio(sampleRate, inpch, outch, 4, true);
// Create and install the dispatcher dispatcher = new PdUiDispatcher();
// PdBase.setReceiver(dispatcher);
}
private void loadPatch() throws IOException {
File dir = getFilesDir();
IoUtils.extractZipResource(getResources().openRawResource(R.raw.patch),
dir, true);
File patchFile = new File(dir, "microphone.pd");
PdBase.openPatch(patchFile.getAbsolutePath());
PdAudio.startAudio(this);
}
@Override
protected void onResume() {
super.onResume();
PdAudio.startAudio(this);
}
@Override
protected void onPause() {
super.onPause();
PdAudio.stopAudio();
}
}
Using too much CPU shouldn't effect volume at all. It seems more likely one of your filters is causing a gain less than 1 on that channel.
Your thread looks fine to me. I'm not 100% sure that calling finish on a non-UI thread is legal, but if it isn't you can add a runOnUiThread there