I've observed that Android devices differ (sometimes radically!) in what audio rates and encodings they support, as well as the number of channels (mono/stereo). In my freeware app "SoundForm" (a signal generator) I have gone to some lengths to try to set the audio system up with a combination of parameter settings that the phone actually works with (my initial release of SoundForm always tried to use 44100/16/1 and worked fine on e.g. Droid, G1, and many others, but failed on several phones - it turned out that they only supported 44100/16/2 or different rates).
The code I use for discovering which audio settings work is as follows int rates[] = {8000,11025,22050,44100,48000}; int configs[] = {AudioFormat.CHANNEL_CONFIGURATION_MONO,AudioFormat.CHANNEL_CONFIGURATION_STEREO}; int encodings[] = {AudioFormat.ENCODING_PCM_8BIT,AudioFormat.ENCODING_PCM_16BIT}; int minBuffer,sampleRate,encoding,config; AudioRecord audio = null; for(int i=0;i<rates.length;i++) { for(int j=0;j<configs.length;j++) { for(int k=0;k<encodings.length;k++) { sampleRate = rates[i]; config = configs[j]; encoding = encodings[k]; try { minBuffer = AudioRecord.getMinBufferSize(sampleRate,config,encoding); if(minBuffer != AudioRecord.ERROR_BAD_VALUE && minBuffer != AudioRecord.ERROR) { boolean bGood = true; try { audio = new AudioRecord( MediaRecorder.AudioSource.MIC, sampleRate,config,encoding, minBuffer); int istate = audio.getState(); if(istate != AudioRecord.STATE_INITIALIZED) bGood = false; } catch (Exception e) { bGood = false; } if(bGood) .... (add settings combination to list of working settings) if(audio != null) audio.release(); audio = null; } } catch (Exception e) {System.err.println("Bad "+e);} } } } It's worth noting that, based on observations, even if getMinBufferSize() returns a positive result, the audio system on some devices can still fail on initialisation, hence the code to create a new AudioRecord object and check its state. (The minBufferSize for playback is more reliable in this regard.) The above set of checks is available as a standalone app in Market called "AudioCaps" - it simply shows a list of the working rates supported on the 'phone, for play and record. Now to my question :-) Users of the Samsung Galaxy S report that SoundForm doesn't work for them - and causes a force close :-( Does anyone here have a Galaxy S they would be kind enough to try SoundForm on, and let me have the logcat from when it fails? Also, any tips on aspects of setting up rates/encodings/channels in Android would be most welcome. Thanks! -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en