void AudioOss::run() { surroundSampleFrame * temp = new surroundSampleFrame[mixer()->framesPerPeriod()]; int_sample_t * outbuf = new int_sample_t[mixer()->framesPerPeriod() * channels()]; while( true ) { const fpp_t frames = getNextBuffer( temp ); if( !frames ) { break; } int bytes = convertToS16( temp, frames, mixer()->masterGain(), outbuf, m_convertEndian ); if( write( m_audioFD, outbuf, bytes ) != bytes ) { break; } } delete[] temp; delete[] outbuf; }
void AudioSndio::run( void ) { surroundSampleFrame * temp = new surroundSampleFrame[mixer()->framesPerPeriod()]; int_sample_t * outbuf = new int_sample_t[mixer()->framesPerPeriod() * channels()]; while( TRUE ) { const fpp_t frames = getNextBuffer( temp ); if( !frames ) { break; } uint bytes = convertToS16( temp, frames, mixer()->masterGain(), outbuf, FALSE ); if( sio_write( m_hdl, outbuf, bytes ) != bytes ) { break; } } delete[] temp; delete[] outbuf; }
void AudioSdl::sdlAudioCallback( Uint8 * _buf, int _len ) { if( m_stopped ) { memset( _buf, 0, _len ); return; } while( _len ) { if( m_convertedBufPos == 0 ) { // frames depend on the sample rate const fpp_t frames = getNextBuffer( m_outBuf ); if( !frames ) { m_stopped = true; m_stopSemaphore.release(); memset( _buf, 0, _len ); return; } m_convertedBufSize = frames * channels() * sizeof( int_sample_t ); convertToS16( m_outBuf, frames, mixer()->masterGain(), (int_sample_t *)m_convertedBuf, m_convertEndian ); } const int min_len = qMin( _len, m_convertedBufSize - m_convertedBufPos ); memcpy( _buf, m_convertedBuf + m_convertedBufPos, min_len ); _buf += min_len; _len -= min_len; m_convertedBufPos += min_len; m_convertedBufPos %= m_convertedBufSize; } }
void AudioAlsa::run() { surroundSampleFrame * temp = new surroundSampleFrame[mixer()->framesPerPeriod()]; int_sample_t * outbuf = new int_sample_t[mixer()->framesPerPeriod() * channels()]; int_sample_t * pcmbuf = new int_sample_t[m_periodSize * channels()]; int outbuf_size = mixer()->framesPerPeriod() * channels(); int outbuf_pos = 0; int pcmbuf_size = m_periodSize * channels(); bool quit = false; while( quit == false ) { int_sample_t * ptr = pcmbuf; int len = pcmbuf_size; while( len ) { if( outbuf_pos == 0 ) { // frames depend on the sample rate const fpp_t frames = getNextBuffer( temp ); if( !frames ) { quit = true; memset( ptr, 0, len * sizeof( int_sample_t ) ); break; } outbuf_size = frames * channels(); convertToS16( temp, frames, mixer()->masterGain(), outbuf, m_convertEndian ); } int min_len = qMin( len, outbuf_size - outbuf_pos ); memcpy( ptr, outbuf + outbuf_pos, min_len * sizeof( int_sample_t ) ); ptr += min_len; len -= min_len; outbuf_pos += min_len; outbuf_pos %= outbuf_size; } f_cnt_t frames = m_periodSize; ptr = pcmbuf; while( frames ) { int err = snd_pcm_writei( m_handle, ptr, frames ); if( err == -EAGAIN ) { continue; } if( err < 0 ) { if( handleError( err ) < 0 ) { printf( "Write error: %s\n", snd_strerror( err ) ); } break; // skip this buffer } ptr += err * channels(); frames -= err; } } delete[] temp; delete[] outbuf; delete[] pcmbuf; }