2

デバイスからオーディオ入力を取得しようとしています。オーディオ入力を取得している間、オーディオ入力の強度に基づいてラベルにアイコンを割り当てようとします。次のコードを使用します。

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
4

0 に答える 0