On Jan 4, 12:41 am, Serdel <adam.lichwierow...@gmail.com> wrote:
> How do you predict the size of the destination array? I mean I think
> you also copy the samples from audiostream into a smaller temp buffer
> and then into your dest. larger one - if you use an array for the
> dest. one how do you set size of that?

Hmmm.  It's been a very long time since I looked at this code.  I kick-
start it with something like this:

int minBufferBytes = AudioRecord.getMinBufferSize(sampleRate,
channelConfig, audioFormat);
mBufferBytes = /*Some value >= minBufferBytes*/;
mBufferFrames = mBufferBytes / (numChannels * sampleBytes);
mReceivedAudioBufferSrt = new short[mBufferFrames];
mRecordingEndPos = 0;

mAudioRecord = new AudioRecord(source, sampleRate, channelConfig,
audioFormat, numBufferBytes);
mAudioRecord.startRecording();
new Thread(new Runnable() {
        public void run() {
                processRecording();
        } // Runnable.run()
}).start(); // New Runnable inside New Thread

...where processRecording(), obviously now running on its own thread
parallel to the ongoing recording, does something like this:

while (mAudioRecord.getRecordingState() ==
AudioRecord.RECORDSTATE_RECORDING) {
        int numDataRead = mAudioRecord.read(mReceivedAudioBufferSrt, 0,
mBufferFrames);
        System.arraycopy(mReceivedAudioBufferSrt, 0,
mRecordingDesc.mRecordingSrt, mRecordingEndPos, mBufferFrames);
        mRecordingEndPos += mBufferFrames;
        if (mRecordingEndPos == mRecordingNumFrames)
                mRecordingEndPos = 0;
}

That's heavily pseudoized from my considerably more complicated
overall setup, but it's the basic idea.  I have to be very careful the
size of the data chunks I grab because I need to perform realtime
power-2 FFTs on them in my app.  Plus I have switches all over the
place to handle a variety of sampling rates, sample sizes (1 or 2
bytes), number of channels, etc.  The complexity grows very quickly
once you start worrying about all of that stuff.

Cheers!

-- 
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

Reply via email to