Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AudioRecord中的获取缓冲区超时-Android_Android_Android Intent_Android Emulator_Android Widget_Android Audiorecord - Fatal编程技术网

AudioRecord中的获取缓冲区超时-Android

AudioRecord中的获取缓冲区超时-Android,android,android-intent,android-emulator,android-widget,android-audiorecord,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; }

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

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