我正在嘗試在Android平臺上構建某種聲音計。 (我正在使用HTC Wildfire)爲此目標使用AudioRecord
類,但是從「讀取」返回的 值似乎不合理。AudioRecord讀取返回奇怪的值
這是我創建的AudioRecord對象:
int minBufferSize =
AudioRecord.getMinBufferSize(sampleRateInHz,
android.media.AudioFormat.CHANNEL_IN_MONO,
android.media.AudioFormat.ENCODING_PCM_16BIT);
audioRecored = new AudioRecord(MediaRecorder.AudioSource.MIC,
44100,
android.media.AudioFormat.CHANNEL_IN_MONO,
android.media.AudioFormat.ENCODING_PCM_16BIT,
minBufferSize);
這是我嘗試從中讀取數據:
short[] audioData = new short[bufferSize];
int offset =0;
int shortRead = 0;
int sampleToReadPerGet = 1000;//some value in order to avoid momentaraly nosies.
//start tapping into the microphone
audioRecored.startRecording();
//start reading from the microphone to an internal buffer - chuck by chunk
while (offset < sampleToReadPerGet)
{
shortRead = audioRecored.read(audioData, offset ,sampleToReadPerGet - offset);
offset += shortRead;
}
//stop tapping into the microphone
audioRecored.stop();
//average the buffer
int averageSoundLevel = 0;
for (int i = 0 ; i < sampleToReadPerGet ; i++)
{
averageSoundLevel += audioData[i];
}
averageSoundLevel /= sampleToReadPerGet;
那些是什麼價值觀?他們是分貝嗎?
編輯: 值從-200到3000. shortRead的值是sampleToReadPerGet(1000)。
你得到什麼樣的價值觀?當然你只是回來了16位PCM樣本。 – Brad
調用讀取後'shortRead'的值是多少? –
爲問題添加了值。 – talel