obtainBuffer在AudioRecord - Android中超时

时间:2012-05-31 14:35:06

标签: android android-intent android-emulator android-widget android-audiorecord

我正在尝试从设备获取音频输入。在获取音频输入时,我尝试根据音频输入的强度将图标分配给标签。我使用以下代码:

public void run() {
        this.rec.startRecording();
        while (!this.done) {
            int nshorts = this.readBlock();
            if (nshorts <= 0)
                break;
        }
        //assignIcons();  
        this.rec.stop();
        this.rec.release();
    }

    int readBlock() {
        short[] buf = new short[this.block_size];

        int nshorts = this.rec.read(buf, 0, buf.length);
        if (nshorts > 0) {
            //Log.d(getClass().getName(), "Posting " + nshorts + " samples to queue");
            this.q.add(buf);
        }

        new Thread(new  Runnable() {
            public void run() {
                assignIcons(); 
            }
        }).start();
        return nshorts;
    }

    public void assignIcons(){
        //Add(Start)
        byte audioBuffer[]   = new  byte[this.minBufferSizeInBytes];//minBufferSizeInBytes = AudioRecord.getMinBufferSize( 8000,
                AudioFormat.CHANNEL_IN_MONO,AudioFormat.ENCODING_PCM_16BIT);
        float totalAbsValue = 0.0f;
        short sample = 0;
        int numberOfReadBytes = 0; 
        float tempFloatBuffer[] = new float[3];
        int tempIndex = 0;
        //Add(End)
      //Add(Start)
        numberOfReadBytes = this.rec.read( audioBuffer, 0, this.minBufferSizeInBytes );
        for( int i=0; i<numberOfReadBytes; i+=2 ) {
            sample = (short)( (audioBuffer[i]) | audioBuffer[i + 1] << 8 );
            if(sample!=0) {
                totalAbsValue += Math.abs( sample ) / (numberOfReadBytes/2);
            }
        }
        tempFloatBuffer[tempIndex%3] = totalAbsValue;
        temp = 0.0f;
        for( int i=0; i<3; ++i )
            temp += tempFloatBuffer[i];
        mCamBase = CameraBaseActivity.getInstance();
        mCamBase.handler.postDelayed(mCamBase.AnimateRunnable, 10);

        //Add(End)

    }

我遇到的问题是,我连续得到以下日志,但是我没有得到所需的输出。我确信我所显示的代码确实存在问题,但不确定导致所给出的日志连续输出的真正问题是什么。任何帮助解决这个问题都非常感谢。

    01-03 09:24:40.930: DEBUG/co.nyk.android.audio.RecognizerTask(19152): signalling START
01-03 09:24:40.930: DEBUG/co.nyk.android.audio.RecognizerTask(19152): signalled START
01-03 09:24:40.930: DEBUG/co.nyk.android.audio.RecognizerTask(19152): gotSTART
01-03 09:24:40.930: DEBUG/co.nyk.android.audio.RecognizerTask(19152): START
01-03 09:24:41.836: WARN/AudioRecord(19152): obtainBuffer timed out (is the CPU pegged?) user=00001000, server=00001000
01-03 09:24:42.086: WARN/AudioRecord(19152): obtainBuffer timed out (is the CPU pegged?) user=00001800, server=00001800
01-03 09:24:43.321: WARN/AudioRecord(19152): obtainBuffer timed out (is the CPU pegged?) user=00004000, server=00004000
01-03 09:24:43.571: WARN/AudioRecord(19152): obtainBuffer timed out (is the CPU pegged?) user=00004800, server=00004800
01-03 09:24:43.836: WARN/AudioRecord(19152): obtainBuffer timed out (is the CPU pegged?) user=00005000, server=00005000
01-03 09:24:44.094: WARN/AudioRecord(19152): obtainBuffer timed out (is the CPU pegged?) user=00005800, server=00005800
01-03 09:24:44.391: WARN/AudioRecord(19152): obtainBuffer timed out (is the CPU pegged?) user=00006000, server=00006000
01-03 09:24:44.649: WARN/AudioRecord(19152): obtainBuffer timed out (is the CPU pegged?) user=00006800, server=00006800
01-03 09:24:45.118: WARN/AudioRecord(19152): obtainBuffer timed out (is the CPU pegged?) user=00007800, server=00007800
01-03 09:24:45.368: WARN/AudioRecord(19152): obtainBuffer timed out (is the CPU pegged?) user=00008000, server=00008000

0 个答案:

没有答案