Closed zyf0330 closed 8 years ago
Ok, nice job!
I noticed that the comparison of bufferSizeInBytes and bufferSize was wrong and fixed that:
From if (bufferSizeInBytes > bufferSize)
to if (bufferSizeInBytes > bufferSize)
[Reference](https://developer.android.com/reference/android/media/AudioRecord.html#getMinBufferSize%28int, int, int%29)
@edimuj I don't understand mentioned above, where is the difference between from and to?
Sorry should be: From if (bufferSizeInBytes > bufferSize) to if (bufferSizeInBytes < bufferSize)
Are you sure? This is in constructor [AudioRecord](https://developer.android.com/reference/android/media/AudioRecord.html#AudioRecord%28int, int, int, int, int%29).bufferSizeInBytes
See getMinBufferSize(int, int, int) to determine the minimum required buffer size for the successful creation of an AudioRecord instance. Using values smaller than getMinBufferSize() will result in an initialization failure. So, maybe the buffersize to instance AudioRecord is different from that used to read from recorder into audioBuffer.
Yes, you're right of course. I have some other changes, including iOS native code that I going to push later and will fix this in that commit.
I just start to program with this plugin on iOS, and hope that you can fix what I meet. Thanks.
And yes, the bufferSize of the reader is different from the AudioRecord bufferSize. Today we are just using the same user parameter for both, but it would actually be good to for example have a larger AudioRecord buffer than the buffer used to read from it.
For example:
recorder = new AudioRecord(MediaRecorder.AudioSource.VOICE_RECOGNITION, sampleRateInHz, channelConfig, audioFormat, bufferSize * 10);
while keeping the reading buffer size the same:
numReadBytes = recorder.read(audioBuffer, 0, bufferSize);
What do you think?
Sure, I will commit the iOS fixes within the coming hours. I'm testing them on my devices right now.
I think it should be ok, at least it doesn't violate principle.
And I just think of one improvement of bufferSize. That's programmer may concern more about how often buffer data is given. In fact, this interval is (bufferSize / channels / sampleRate) s
.
I've pushed a change regarding the bufferSize. Now separate sizes are used for writing and reading.
I put my eye here.
@edimuj I know why, because I doesn't pull and merge from your main repository.