From 43d119d21e6bce10fe8860f83011c89f222b0efc Mon Sep 17 00:00:00 2001 From: Javier Serrano Polo Date: Wed, 15 Nov 2006 21:06:12 +0000 Subject: [PATCH] fixed OSS and SDL git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@428 0778d3d1-df1d-0410-868b-ea421aaaa00d --- ChangeLog | 13 ++++++++++++ configure.in | 4 ++-- include/audio_alsa.h | 2 +- include/audio_sdl.h | 4 ++++ src/audio/audio_alsa.cpp | 10 ++++++--- src/audio/audio_device.cpp | 32 ++++++++++++++-------------- src/audio/audio_file_wave.cpp | 2 +- src/audio/audio_sdl.cpp | 39 ++++++++++++++++++++++++++++++----- 8 files changed, 78 insertions(+), 28 deletions(-) diff --git a/ChangeLog b/ChangeLog index e8298c005..f3abfbdec 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2006-11-15 Javier Serrano Polo + + * include/audio_alsa.h: + * src/audio/audio_alsa.cpp: + * src/audio/audio_device.cpp: + * src/audio/audio_file_wave.cpp: + convert-endian-based conversion instead of little-endian-based, + fixes OSS and SDL + + * include/audio_sdl.h: + * src/audio/audio_sdl.cpp: + fill the whole audio buffer + 2006-11-11 Javier Serrano Polo * src/core/piano_roll.cpp: diff --git a/configure.in b/configure.in index 2aacfd2f1..554f19c9c 100644 --- a/configure.in +++ b/configure.in @@ -2,8 +2,8 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.50) -AC_INIT(lmms, 0.2.1-svn20061111, lmms-devel/at/lists/dot/sf/dot/net) -AM_INIT_AUTOMAKE(lmms, 0.2.1-svn20061111) +AC_INIT(lmms, 0.2.1-svn20061115, lmms-devel/at/lists/dot/sf/dot/net) +AM_INIT_AUTOMAKE(lmms, 0.2.1-svn20061115) AM_CONFIG_HEADER(config.h) diff --git a/include/audio_alsa.h b/include/audio_alsa.h index fe3468010..f4b125a67 100644 --- a/include/audio_alsa.h +++ b/include/audio_alsa.h @@ -99,7 +99,7 @@ private: snd_pcm_hw_params_t * m_hwParams; snd_pcm_sw_params_t * m_swParams; - bool m_littleEndian; + bool m_convertEndian; volatile bool m_quit; } ; diff --git a/include/audio_sdl.h b/include/audio_sdl.h index b707a589c..a59366c82 100644 --- a/include/audio_sdl.h +++ b/include/audio_sdl.h @@ -80,10 +80,14 @@ private: virtual void stopProcessing( void ); static void sdlAudioCallback( void * _udata, Uint8 * _buf, int _len ); + void sdlAudioCallback( Uint8 * _buf, int _len ); SDL_AudioSpec m_audioHandle; surroundSampleFrame * m_outBuf; + Uint8 * m_convertedBuf; + int m_convertedBuf_pos; + int m_convertedBuf_size; bool m_convertEndian; diff --git a/src/audio/audio_alsa.cpp b/src/audio/audio_alsa.cpp index 66898f357..801c62df0 100644 --- a/src/audio/audio_alsa.cpp +++ b/src/audio/audio_alsa.cpp @@ -65,7 +65,7 @@ audioALSA::audioALSA( const sample_rate_t _sample_rate, bool & _success_ful, m_handle( NULL ), m_hwParams( NULL ), m_swParams( NULL ), - m_littleEndian( isLittleEndian() ), + m_convertEndian( FALSE ), m_quit( FALSE ) { _success_ful = FALSE; @@ -228,7 +228,7 @@ void audioALSA::run( void ) const f_cnt_t frames = getNextBuffer( temp ); convertToS16( temp, frames, getMixer()->masterGain(), outbuf, - m_littleEndian ); + m_convertEndian ); f_cnt_t frame = 0; int_sample_t * ptr = outbuf; @@ -298,7 +298,11 @@ int audioALSA::setHWParams( const sample_rate_t _sample_rate, "playback: %s\n", snd_strerror( err ) ); return( err ); } - m_littleEndian = FALSE; + m_convertEndian = isLittleEndian(); + } + else + { + m_convertEndian = !isLittleEndian(); } // set the count of channels diff --git a/src/audio/audio_device.cpp b/src/audio/audio_device.cpp index 8d320d223..4a2b3ef19 100644 --- a/src/audio/audio_device.cpp +++ b/src/audio/audio_device.cpp @@ -297,23 +297,9 @@ Uint32 FASTCALL audioDevice::convertToS16( const surroundSampleFrame * _ab, const fpab_t _frames, const float _master_gain, int_sample_t * _output_buffer, - const bool _little_endian ) + const bool _convert_endian ) { - if( _little_endian ) - { - for( fpab_t frame = 0; frame < _frames; ++frame ) - { - for( ch_cnt_t chnl = 0; chnl < channels(); ++chnl ) - { - ( _output_buffer + frame * channels() )[chnl] = - static_cast( - mixer::clip( _ab[frame][chnl] * - _master_gain ) * - OUTPUT_SAMPLE_MULTIPLIER ); - } - } - } - else + if( _convert_endian ) { Uint16 temp; for( fpab_t frame = 0; frame < _frames; ++frame ) @@ -331,6 +317,20 @@ Uint32 FASTCALL audioDevice::convertToS16( const surroundSampleFrame * _ab, } } } + else + { + for( fpab_t frame = 0; frame < _frames; ++frame ) + { + for( ch_cnt_t chnl = 0; chnl < channels(); ++chnl ) + { + ( _output_buffer + frame * channels() )[chnl] = + static_cast( + mixer::clip( _ab[frame][chnl] * + _master_gain ) * + OUTPUT_SAMPLE_MULTIPLIER ); + } + } + } return( _frames * channels() * BYTES_PER_INT_SAMPLE ); } diff --git a/src/audio/audio_file_wave.cpp b/src/audio/audio_file_wave.cpp index 529fcdca3..6abf746d9 100644 --- a/src/audio/audio_file_wave.cpp +++ b/src/audio/audio_file_wave.cpp @@ -99,7 +99,7 @@ void FASTCALL audioFileWave::writeBuffer( const surroundSampleFrame * _ab, int_sample_t * outbuf = bufferAllocator::alloc( _frames * channels() ); Uint32 bytes = convertToS16( _ab, _frames, _master_gain, outbuf, - TRUE ); + !isLittleEndian() ); writeData( outbuf, bytes ); bufferAllocator::free( outbuf ); diff --git a/src/audio/audio_sdl.cpp b/src/audio/audio_sdl.cpp index 13894fea2..0b0291a95 100644 --- a/src/audio/audio_sdl.cpp +++ b/src/audio/audio_sdl.cpp @@ -47,6 +47,7 @@ #include "debug.h" #include "config_mgr.h" #include "gui_templates.h" +#include "templates.h" @@ -55,10 +56,16 @@ audioSDL::audioSDL( const sample_rate_t _sample_rate, bool & _success_ful, audioDevice( _sample_rate, DEFAULT_CHANNELS, _mixer ), m_outBuf( bufferAllocator::alloc( getMixer()->framesPerAudioBuffer() ) ), + m_convertedBuf_pos( 0 ), m_convertEndian( FALSE ) { _success_ful = FALSE; + m_convertedBuf_size = getMixer()->framesPerAudioBuffer() * channels() + * sizeof( int_sample_t ); + m_convertedBuf = (Uint8 *)bufferAllocator::allocBytes( + m_convertedBuf_size ); + /* // if device is set, we set AUDIODEV-environment-variable, so that // SDL can evaluate and use it QString dev = configManager::inst()->value( "audiosdl", "device" ); @@ -110,6 +117,7 @@ audioSDL::~audioSDL() stopProcessing(); SDL_CloseAudio(); SDL_Quit(); + bufferAllocator::free( m_convertedBuf ); bufferAllocator::free( m_outBuf ); } @@ -145,12 +153,33 @@ void audioSDL::sdlAudioCallback( void * _udata, Uint8 * _buf, int _len ) assert( _this != NULL ); #endif - const fpab_t frames = _this->getNextBuffer( _this->m_outBuf ); + _this->sdlAudioCallback( _buf, _len ); +} - _this->convertToS16( _this->m_outBuf, frames, - _this->getMixer()->masterGain(), - (int_sample_t *)( _buf ), - _this->m_convertEndian ); + + + +void audioSDL::sdlAudioCallback( Uint8 * _buf, int _len ) +{ + while( _len ) + { + if( m_convertedBuf_pos == 0 ) + { + const fpab_t frames = getNextBuffer( m_outBuf ); + + convertToS16( m_outBuf, frames, + getMixer()->masterGain(), + (int_sample_t *)m_convertedBuf, + m_convertEndian ); + } + int min_len = tMin( _len, m_convertedBuf_size + - m_convertedBuf_pos ); + memcpy( _buf, m_convertedBuf + m_convertedBuf_pos, min_len ); + _buf += min_len; + _len -= min_len; + m_convertedBuf_pos += min_len; + m_convertedBuf_pos %= m_convertedBuf_size; + } }