I am trying to make my phone make simple "beep" noises.
I've followed the example here:
I can make beeps and vary the tone and length.
AudioTrack.getMinBufferSize()
suggests a min buffer size of 1280.
But using that value I wasn't getting all the beep (it was shorter than it should have been). These figures are all for a (requested) 1 second beep.
I varied the buffer size from 2 bytes to 16000 bytes.
Between 2 and 1280 bytes I got 940 milli seconds reasonably consistently.
From 1280 to 15998 bytes the beep got shorter.
The shortest was actually at about 12000, 250 milli seconds.
Then it increased again to 337 milli seconds at 15998. At 16000 there were no beeps at all.
So, I never got my full 1000 milli seconds, the longest was about 950.
The shortest was about 250 milli seconds.
Nothing else changed, just the buffer size.
Using Sonic Visualiser I can record the beeps and see the wave form on my PC. This is how I've been measuring beep duration.
Because of the amplitude ramp in and ramp out that I've been using, I can see clearly that the beeps start correctly with a ramp up from 0, and they are truncated at the end. I lose the end of the beeps.
Can anyone explain this and tell me how to get all my 1 second beep please?
Further information:
The same truncation happens for beep durations other than 1 second.
The microphone and PC are uncalibrated, but the results are repeatable.
The main bits of code are like this:
int minBufferSize = AudioTrack.getMinBufferSize(mSampleRate, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT);
mAudioTrack = new AudioTrack(AudioManager.STREAM_ALARM,
mSampleRate,
AudioFormat.CHANNEL_OUT_MONO,
AudioFormat.ENCODING_PCM_16BIT,
mBufferSize,
AudioTrack.MODE_STREAM);
Images from Sonic Analyser.
All these tests were done with a Galaxy S4 Running 5.0.1
How do I get the full 1 second beep please?
This single image may explain the problem better: shows: expected profile, profile for buffer=2, profile for buffer=12000
And here is a graph of buffer size vs beep length. Always the same beep data was generated, the only thing that changed was the buffer size:variation of "beep" length with buffer size