Microphone not working same on different devices

edited January 23 in Android Mode


I'm trying to get volume detection working on 3 different devices, on the first one, everything works as I want it to, on the second device, the initialisation doesn't work, but volume detection works, and on the third device nothing works. I think that it's weird, because on every device I use I've installed the same application, but it works so differently.

I've given this app needed permissions.

Basically, I want the application to "calibrate" whenever the app starts, which works on one device, on other two it get's stuck on 150. After that I want the application to detect the volume and whenever the volume is above the threshold, I want to do something. It works on two devices. I also unload the microphone after stopping the application.

Please tell me if I'm doing something, if it's not my fault, please tell me the workaround, I need to have this app working 'till Friday.

so I initialise my microphone with the following snippet

int freq =44100; int chan = AudioFormat.CHANNEL_IN_MONO; int enc = AudioFormat.ENCODING_PCM_16BIT; int src = MediaRecorder.AudioSource.MIC; buflen = AudioRecord.getMinBufferSize(freq, chan, enc); audioRecord = new AudioRecord(src, freq, chan, enc, buflen); if (audioRecord != null) { audioRecord.startRecording(); } buffer = new short[bufferSize];

and I calibrate/set the threshold using this snippet

void calibrate() { int bufferReadResult = audioRecord.read(buffer, 0, bufferSize); volume = 100; for (int i = 0; i < bufferReadResult; i++) { volume = Math.max(Math.abs(buffer[i]), volume); } treshold = volume+50; }

Microphone unload method

void stop() { audioRecord.stop(); audioRecord.release(); audioRecord = null; }

Thanks for taking your time and helping me out!


  • edited January 23

    Oh, I forgot to mention, but I'm waiting some time between microphone initialisation and it's "calibration" so that shouldn't be the problem.

Sign In or Register to comment.