Пример #1
0
        public override bool initCapturer()
        {
            // get the minimum buffer size that can be used
            int minRecBufSize = AudioRecord.getMinBufferSize(m_captureSettings.SampleRate, NUM_CHANNELS_CAPTURING == 1 ? AudioFormat.CHANNEL_IN_MONO : AudioFormat.CHANNEL_IN_STEREO, AudioFormat.ENCODING_PCM_16BIT);

            // double size to be more safe
            int recBufSize = minRecBufSize * 2;

            // release the object
            if (m_audioRecord != null)
            {
                m_audioRecord.release();
                m_audioRecord = null;
            }

            try
            {
                m_audioRecord = new AudioRecord(AudioSource.VOICE_COMMUNICATION, m_captureSettings.SampleRate, NUM_CHANNELS_CAPTURING == 1 ? AudioFormat.CHANNEL_IN_MONO : AudioFormat.CHANNEL_IN_STEREO, AudioFormat.ENCODING_PCM_16BIT, recBufSize);
            }
            catch (Exception e)
            {
                Log.e(LOG_TAG, e.Message);
                return(false);
            }

            // check that the audioRecord is ready to be used
            if (m_audioRecord.State != AudioRecord.STATE_INITIALIZED)
            {
                Log.i(LOG_TAG, "Audio capture is not initialized " + m_captureSettings.SampleRate);

                return(false);
            }

            m_shutdownCaptureThread = false;
            (new Thread(m_captureThread)).Start();

            return(true);
        }