Java.lang.IllegalStateException: Cannot get AudioTrack pointer for write ()

I am getting the following error: java.lang.IllegalStateException: Cannot get AudioTrack pointer for write () and I am trying to do this:

// Get the minimum buffer size required for the successful creation of an AudioRecord object.
    bufferSizeInBytes = AudioRecord.getMinBufferSize(
      hz,
      AudioFormat.CHANNEL_IN_MONO,
      AudioFormat.ENCODING_PCM_16BIT
    );

    bufferSizeInShorts = (bufferSizeInBytes /2);

    // Initialize Audio Recorder. 
    arec = new AudioRecord( 
      MediaRecorder.AudioSource.VOICE_RECOGNITION, 
      hz, 
      AudioFormat.CHANNEL_IN_MONO,
      AudioFormat.ENCODING_PCM_16BIT, 
      bufferSizeInBytes 
    );

    if (AcousticEchoCanceler.isAvailable()) {
            AcousticEchoCanceler echoCanceller = AcousticEchoCanceler.create(arec.getAudioSessionId());
            if (echoCanceller != null) {
        //        echoCanceller.setEnableStatusListener(this);
                echoCanceller.setEnabled(true);
            }
        } else { Log.e("configAudio", "Echo Canceler not available");}

    if (NoiseSuppressor.isAvailable()) {
            NoiseSuppressor noiseSuppressor = NoiseSuppressor.create(arec.getAudioSessionId());
            if (noiseSuppressor != null) {
            //    noiseSuppressor.setEnableStatusListener(this);
                noiseSuppressor.setEnabled(true);
            }
        } else { Log.e("configAudio", "Noise Suppressor not available");
          aManager.setParameters("noise_suppression=auto");
        }

    //Initialize AudioTrack               
        atrack = new AudioTrack(AudioManager.STREAM_MUSIC,
                        hz,
                        AudioFormat.CHANNEL_OUT_MONO,
                        AudioFormat.ENCODING_PCM_16BIT,
                        bufferSizeInBytes,
                        AudioTrack.MODE_STREAM);

        atrack.setPlaybackRate(pbhz);

    // Start Recording & Playing 
        audioBuffer = new short[bufferSizeInShorts]; 
        arec.startRecording(); 
        atrack.play();
        onRec = true;

     try{   
        new Thread(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub\
                while (onRec) {
                          shortsRead = arec.read(audioBuffer, 0, bufferSizeInShorts);
                      }
            }
        }).start();

        new Thread(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub\
                while (onRec) { 
                   atrack.write(audioBuffer, 0, audioBuffer.length);
                 } 
                }

        }).start();

      

Any hint what might be causing this error?

+3
android byte short audiotrack audiorecord


source to share


No one has answered this question yet

Check out similar questions:

five
NanoHTTPD. InputStream cache for writing and continuing streaming
4
Loadmanager onLoadFinished is not called
4
Failed to get AudioTrack pointer for write ()
1
Copy pdf file from asset to SD card
0
Refreshing TextView on long running Thread
0
Acceleromter service does not work on Android TV Box
0
Trying to run my first Andengine app on a device
0
View.SurfaceView, why is its member, mSurfaceHolder, returning null from getSurface ()?
0
Is the delay hidden and the ActionBar displayed?
-1
Mysql database connection with fragments



All Articles
Loading...
X
Show
Funny
Dev
Pics