edimuj / cordova-plugin-audioinput

This iOS/Android Cordova/PhoneGap plugin enables audio capture from the device microphone, by in near real-time forwarding audio to the web layer of your application. A typical usage scenario for this plugin would be to use the captured audio as source for a web audio node chain, where it then can be analyzed, manipulated and/or played.
https://github.com/edimuj/app-audioinput-demo
MIT License
161 stars 88 forks source link

see commit message #11

Closed zyf0330 closed 8 years ago

zyf0330 commented 8 years ago

@edimuj I know why, because I doesn't pull and merge from your main repository.

edimuj commented 8 years ago

Ok, nice job!

edimuj commented 8 years ago

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)

zyf0330 commented 8 years ago

@edimuj I don't understand mentioned above, where is the difference between from and to?

edimuj commented 8 years ago

Sorry should be: From if (bufferSizeInBytes > bufferSize) to if (bufferSizeInBytes < bufferSize)

zyf0330 commented 8 years ago

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.

edimuj commented 8 years ago

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.

zyf0330 commented 8 years ago

I just start to program with this plugin on iOS, and hope that you can fix what I meet. Thanks.

edimuj commented 8 years ago

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?

edimuj commented 8 years ago

Sure, I will commit the iOS fixes within the coming hours. I'm testing them on my devices right now.

zyf0330 commented 8 years ago

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.

edimuj commented 8 years ago

I've pushed a change regarding the bufferSize. Now separate sizes are used for writing and reading.

zyf0330 commented 8 years ago

I put my eye here.