private void outputSamples ( ) { int samples ; while ( ( samples = vorbisDspState . synthesis_pcmout ( _pcmf , _index ) ) > 0 ) { float [ ] [ ] pcmf = _pcmf [ 0 ] ; bout = ( samples < convsize ? samples : convsize ) ; // convert doubles to 16 bit signed ints (host order) and // interleave for ( i = 0 ; i < vorbisInfo . channels ; i ++ ) { int pointer = i * 2 ; //int ptr=i; int mono = _index [ i ] ; for ( int j = 0 ; j < bout ; j ++ ) { double fVal = pcmf [ i ] [ mono + j ] * 32767. ; int val = ( int ) ( fVal ) ; if ( val > 32767 ) { val = 32767 ; } if ( val < - 32768 ) { val = - 32768 ; } if ( val < 0 ) { val = val | 0x8000 ; } convbuffer [ pointer ] = ( byte ) ( val ) ; convbuffer [ pointer + 1 ] = ( byte ) ( val >>> 8 ) ; pointer += 2 * ( vorbisInfo . channels ) ; } } LOG . log ( Level . FINE , "about to write: {0}" , 2 * vorbisInfo . channels * bout ) ; if ( getCircularBuffer ( ) . availableWrite ( ) < 2 * vorbisInfo . channels * bout ) { LOG . log ( Level . FINE , "Too much data in this data packet, better return, let the channel drain, and try again..." ) ; playState = playState_BufferFull ; return ; } getCircularBuffer ( ) . write ( convbuffer , 0 , 2 * vorbisInfo . channels * bout ) ; if ( bytes < bufferSize_ ) { LOG . log ( Level . FINE , "Finished with final buffer of music?" ) ; } if ( vorbisDspState . synthesis_read ( bout ) != 0 ) { LOG . log ( Level . FINE , "VorbisDspState.synthesis_read returned -1." ) ; } } // while(samples...) playState = playState_ReadData ; }
This routine was extracted so that when the output buffer fills up we can break out of the loop let the music channel drain then continue from where we were .