removed buffer allocator, automatable object dependencies, deadlocks

git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@477 0778d3d1-df1d-0410-868b-ea421aaaa00d
This commit is contained in:
Javier Serrano Polo
2007-04-24 05:36:58 +00:00
parent 40137f4453
commit 416d208cc3
77 changed files with 1010 additions and 1105 deletions

View File

@@ -48,7 +48,6 @@
#ifdef ALSA_SUPPORT
#include "endian_handling.h"
#include "buffer_allocator.h"
#include "config_mgr.h"
#include "lcd_spinbox.h"
#include "gui_templates.h"
@@ -214,13 +213,11 @@ void audioALSA::stopProcessing( void )
void audioALSA::run( void )
{
surroundSampleFrame * temp =
bufferAllocator::alloc<surroundSampleFrame>(
getMixer()->framesPerAudioBuffer() );
int_sample_t * outbuf = bufferAllocator::alloc<int_sample_t>(
getMixer()->framesPerAudioBuffer() *
channels() );
int_sample_t * pcmbuf = bufferAllocator::alloc<int_sample_t>(
m_periodSize * channels() );
new surroundSampleFrame[getMixer()->framesPerAudioBuffer()];
int_sample_t * outbuf =
new int_sample_t[getMixer()->framesPerAudioBuffer() *
channels()];
int_sample_t * pcmbuf = new int_sample_t[m_periodSize * channels()];
int outbuf_size = getMixer()->framesPerAudioBuffer() * channels();
int outbuf_pos = 0;
@@ -286,9 +283,9 @@ void audioALSA::run( void )
}
}
bufferAllocator::free( temp );
bufferAllocator::free( outbuf );
bufferAllocator::free( pcmbuf );
delete[] temp;
delete[] outbuf;
delete[] pcmbuf;
}

View File

@@ -33,7 +33,6 @@
#include "audio_device.h"
#include "buffer_allocator.h"
#include "debug.h"
@@ -43,8 +42,7 @@ audioDevice::audioDevice( const sample_rate_t _sample_rate,
m_sampleRate( _sample_rate ),
m_channels( _channels ),
m_mixer( _mixer ),
m_buffer( bufferAllocator::alloc<surroundSampleFrame>(
getMixer()->framesPerAudioBuffer() ) )
m_buffer( new surroundSampleFrame[getMixer()->framesPerAudioBuffer()] )
{
#ifdef HAVE_SAMPLERATE_H
int error;
@@ -70,7 +68,7 @@ audioDevice::~audioDevice()
#ifdef HAVE_SAMPLERATE_H
src_delete( m_srcState );
#endif
bufferAllocator::free( m_buffer );
delete[] m_buffer;
#ifdef QT3
if( m_devMutex.locked() )
{
@@ -85,15 +83,17 @@ audioDevice::~audioDevice()
bool audioDevice::processNextBuffer( void )
void audioDevice::processNextBuffer( void )
{
const fpab_t frames = getNextBuffer( m_buffer );
if( !frames )
if( frames )
{
return( FALSE );
writeBuffer( m_buffer, frames, getMixer()->masterGain() );
}
else
{
m_in_process = FALSE;
}
writeBuffer( m_buffer, frames, getMixer()->masterGain() );
return( TRUE );
}
@@ -136,7 +136,10 @@ fpab_t audioDevice::getNextBuffer( surroundSampleFrame * _ab )
void audioDevice::stopProcessing( void )
{
while( processNextBuffer() );
while( m_in_process )
{
processNextBuffer();
}
}

View File

@@ -41,7 +41,6 @@
#include "audio_file_device.h"
#include "export_project_dialog.h"
#include "buffer_allocator.h"
audioFileDevice::audioFileDevice( const sample_rate_t _sample_rate,

View File

@@ -29,7 +29,6 @@
#include "audio_file_wave.h"
#include "endian_handling.h"
#include "buffer_allocator.h"
#include <cstring>
@@ -96,13 +95,12 @@ void FASTCALL audioFileWave::writeBuffer( const surroundSampleFrame * _ab,
const fpab_t _frames,
const float _master_gain )
{
int_sample_t * outbuf = bufferAllocator::alloc<int_sample_t>(
_frames * channels() );
int_sample_t * outbuf = new int_sample_t[_frames * channels()];
Uint32 bytes = convertToS16( _ab, _frames, _master_gain, outbuf,
!isLittleEndian() );
writeData( outbuf, bytes );
bufferAllocator::free( outbuf );
delete[] outbuf;
m_bytesWritten += bytes;
}

View File

@@ -51,7 +51,6 @@
#include "debug.h"
#include "templates.h"
#include "gui_templates.h"
#include "buffer_allocator.h"
#include "config_mgr.h"
#include "lcd_spinbox.h"
#include "audio_port.h"
@@ -69,8 +68,7 @@ audioJACK::audioJACK( const sample_rate_t _sample_rate, bool & _success_ful,
m_active( FALSE ),
// m_processCallbackMutex(),
m_stop_semaphore( 1 ),
m_outBuf( bufferAllocator::alloc<surroundSampleFrame>(
getMixer()->framesPerAudioBuffer() ) ),
m_outBuf( new surroundSampleFrame[getMixer()->framesPerAudioBuffer()] ),
m_framesDoneInCurBuf( 0 ),
m_framesToDoInCurBuf( 0 )
{
@@ -202,7 +200,7 @@ audioJACK::~audioJACK()
jack_client_close( m_client );
}
bufferAllocator::free( m_outBuf );
delete[] m_outBuf;
}

View File

@@ -47,7 +47,6 @@
#endif
#include "buffer_allocator.h"
#include "endian_handling.h"
#include "lcd_spinbox.h"
#include "gui_templates.h"
@@ -317,11 +316,10 @@ void audioOSS::stopProcessing( void )
void audioOSS::run( void )
{
surroundSampleFrame * temp =
bufferAllocator::alloc<surroundSampleFrame>(
getMixer()->framesPerAudioBuffer() );
int_sample_t * outbuf = bufferAllocator::alloc<int_sample_t>(
getMixer()->framesPerAudioBuffer() *
channels() );
new surroundSampleFrame[getMixer()->framesPerAudioBuffer()];
int_sample_t * outbuf =
new int_sample_t[getMixer()->framesPerAudioBuffer() *
channels()];
while( TRUE )
{
@@ -337,8 +335,8 @@ void audioOSS::run( void )
write( m_audioFD, outbuf, bytes );
}
bufferAllocator::free( temp );
bufferAllocator::free( outbuf );
delete[] temp;
delete[] outbuf;
}

View File

@@ -30,15 +30,14 @@
#include "audio_port.h"
#include "audio_device.h"
#include "buffer_allocator.h"
#include "engine.h"
audioPort::audioPort( const QString & _name ) :
m_bufferUsage( NONE ),
m_firstBuffer( bufferAllocator::alloc<surroundSampleFrame>(
engine::getMixer()->framesPerAudioBuffer() ) ),
m_secondBuffer( bufferAllocator::alloc<surroundSampleFrame>(
engine::getMixer()->framesPerAudioBuffer() ) ),
m_firstBuffer( new surroundSampleFrame[
engine::getMixer()->framesPerAudioBuffer()] ),
m_secondBuffer( new surroundSampleFrame[
engine::getMixer()->framesPerAudioBuffer()] ),
m_extOutputEnabled( FALSE ),
m_nextFxChannel( -1 ),
m_name( "unnamed port" )
@@ -63,8 +62,8 @@ audioPort::~audioPort()
{
engine::getMixer()->audioDev()->unregisterPort( this );
}
bufferAllocator::free( m_firstBuffer );
bufferAllocator::free( m_secondBuffer );
delete[] m_firstBuffer;
delete[] m_secondBuffer;
}

View File

@@ -30,7 +30,6 @@
#include "audio_sample_recorder.h"
#include "sample_buffer.h"
#include "buffer_allocator.h"
#include "debug.h"
@@ -52,7 +51,7 @@ audioSampleRecorder::~audioSampleRecorder()
{
while( !m_buffers.empty() )
{
bufferAllocator::free( m_buffers.front().first );
delete[] m_buffers.front().first;
m_buffers.erase( m_buffers.begin() );
}
}
@@ -78,9 +77,9 @@ void audioSampleRecorder::createSampleBuffer( sampleBuffer * * _sample_buf )
{
const f_cnt_t frames = framesRecorded();
// create buffer to store all recorded buffers in
sampleFrame * data = bufferAllocator::alloc<sampleFrame>( frames );
sampleFrame * data = new sampleFrame[frames];
// make sure buffer is cleaned up properly at the end...
bufferAllocator::autoCleaner<sampleFrame> ac( data );
sampleFrame * data_ptr = data;
#ifdef LMMS_DEBUG
assert( data != NULL );
@@ -89,12 +88,14 @@ void audioSampleRecorder::createSampleBuffer( sampleBuffer * * _sample_buf )
for( bufferList::const_iterator it = m_buffers.begin();
it != m_buffers.end(); ++it )
{
memcpy( data, ( *it ).first, ( *it ).second *
memcpy( data_ptr, ( *it ).first, ( *it ).second *
sizeof( sampleFrame ) );
data += ( *it ).second;
data_ptr += ( *it ).second;
}
// create according sample-buffer out of big buffer
*_sample_buf = new sampleBuffer( ac.ptr(), frames );
*_sample_buf = new sampleBuffer( data, frames );
( *_sample_buf )->setSampleRate( sampleRate() );
delete[] data;
}
@@ -103,7 +104,7 @@ void audioSampleRecorder::createSampleBuffer( sampleBuffer * * _sample_buf )
void audioSampleRecorder::writeBuffer( const surroundSampleFrame * _ab,
const fpab_t _frames, const float )
{
sampleFrame * buf = bufferAllocator::alloc<sampleFrame>( _frames );
sampleFrame * buf = new sampleFrame[_frames];
for( fpab_t frame = 0; frame < _frames; ++frame )
{
for( ch_cnt_t chnl = 0; chnl < DEFAULT_CHANNELS; ++chnl )

View File

@@ -43,7 +43,6 @@
#endif
#include "buffer_allocator.h"
#include "debug.h"
#include "config_mgr.h"
#include "gui_templates.h"
@@ -55,8 +54,7 @@
audioSDL::audioSDL( const sample_rate_t _sample_rate, bool & _success_ful,
mixer * _mixer ) :
audioDevice( _sample_rate, DEFAULT_CHANNELS, _mixer ),
m_outBuf( bufferAllocator::alloc<surroundSampleFrame>(
getMixer()->framesPerAudioBuffer() ) ),
m_outBuf( new surroundSampleFrame[getMixer()->framesPerAudioBuffer()] ),
m_convertedBuf_pos( 0 ),
m_convertEndian( FALSE ),
m_stop_semaphore( 1 )
@@ -65,8 +63,7 @@ audioSDL::audioSDL( const sample_rate_t _sample_rate, bool & _success_ful,
m_convertedBuf_size = getMixer()->framesPerAudioBuffer() * channels()
* sizeof( int_sample_t );
m_convertedBuf = (Uint8 *)bufferAllocator::allocBytes(
m_convertedBuf_size );
m_convertedBuf = new Uint8[m_convertedBuf_size];
/* // if device is set, we set AUDIODEV-environment-variable, so that
// SDL can evaluate and use it
@@ -130,8 +127,8 @@ audioSDL::~audioSDL()
#endif
SDL_CloseAudio();
SDL_Quit();
bufferAllocator::free( m_convertedBuf );
bufferAllocator::free( m_outBuf );
delete[] m_convertedBuf;
delete[] m_outBuf;
}

View File

@@ -65,6 +65,7 @@
#include "song_editor.h"
#include "main_window.h"
#include "embed.h"
#include "engine.h"
#include "pixmap_button.h"
#include "templates.h"
#include "gui_templates.h"

View File

@@ -46,6 +46,7 @@
#include "bb_editor.h"
#include "song_editor.h"
#include "embed.h"
#include "engine.h"
#include "tool_button.h"
#include "track_container.h"
#include "bb_track.h"

View File

@@ -49,6 +49,7 @@
#include "envelope_and_lfo_widget.h"
#include "song_editor.h"
#include "embed.h"
#include "engine.h"
#include "knob.h"
#include "pixmap_button.h"
#include "oscillator.h"

View File

@@ -253,7 +253,7 @@ void envelopeTabWidget::processAudioBuffer( sampleFrame * _ab,
const fpab_t _frames,
notePlayHandle * _n )
{
f_cnt_t total_frames = _n->totalFramesPlayed();
const f_cnt_t total_frames = _n->totalFramesPlayed();
f_cnt_t release_begin = total_frames - _n->releaseFramesDone() +
_n->framesBeforeRelease();
@@ -263,67 +263,49 @@ void envelopeTabWidget::processAudioBuffer( sampleFrame * _ab,
}
// because of optimizations, there's special code for several cases:
// - volume-, cut- and res-lfo/envelope active
// - volume- and cut-lfo/envelope active
// - volume- and res-lfo/envelope active
// - cut- and res-lfo/envelope active
// - cut-lfo/envelope active
// - res-lfo/envelope active
// - volume-lfo/envelope active
// - no lfo/envelope active but filter is used
// now there's a lot of similar code but I didn't found a way to
// generalize it yet... may be later we could do that
// by using preprocessor and macro-expansion... (like in oscillator.cpp)
// only use filter, if it is really needed
if( _n->m_filter == NULL )
{
_n->m_filter = new basicFilters<>(
engine::getMixer()->sampleRate() );
}
m_envLFOWidgets[VOLUME]->lock();
m_envLFOWidgets[CUT]->lock();
m_envLFOWidgets[RES]->lock();
float * vol_buf = NULL;
float * cut_buf = NULL;
float * res_buf = NULL;
if( m_envLFOWidgets[VOLUME]->used() )
{
vol_buf = new float[_frames];
m_envLFOWidgets[VOLUME]->fillLevel( vol_buf, total_frames,
release_begin, _frames );
}
if( m_envLFOWidgets[CUT]->used() )
{
cut_buf = new float[_frames];
m_envLFOWidgets[CUT]->fillLevel( cut_buf, total_frames,
release_begin, _frames );
}
if( m_envLFOWidgets[RES]->used() )
{
res_buf = new float[_frames];
m_envLFOWidgets[RES]->fillLevel( res_buf, total_frames,
release_begin, _frames );
}
if( m_filterGroupBox->isActive() )
{
int old_filter_cut = 0;
int old_filter_res = 0;
basicFilters<>::filterTypes filter =
basicFilters<>::getFilterType(
m_filterComboBox->value() );
if( _n->m_filter == NULL )
{
_n->m_filter = new basicFilters<>(
engine::getMixer()->sampleRate() );
}
_n->m_filter->setType( basicFilters<>::getFilterType(
m_filterComboBox->value() ) );
if( m_envLFOWidgets[VOLUME]->used() &&
m_envLFOWidgets[CUT]->used() &&
float * cut_buf = NULL;
float * res_buf = NULL;
m_envLFOWidgets[CUT]->lock();
m_envLFOWidgets[RES]->lock();
if( m_envLFOWidgets[CUT]->used() )
{
cut_buf = new float[_frames];
m_envLFOWidgets[CUT]->fillLevel( cut_buf, total_frames,
release_begin, _frames );
}
if( m_envLFOWidgets[RES]->used() )
{
res_buf = new float[_frames];
m_envLFOWidgets[RES]->fillLevel( res_buf, total_frames,
release_begin, _frames );
}
if( m_envLFOWidgets[CUT]->used() &&
m_envLFOWidgets[RES]->used() )
{
for( fpab_t frame = 0; frame < _frames;
++frame, ++total_frames )
for( fpab_t frame = 0; frame < _frames; ++frame )
{
float new_cut_val = envelopeAndLFOWidget::expKnobVal( cut_buf[frame] ) * CUT_FREQ_MULTIPLIER +
m_filterCutKnob->value();
@@ -334,76 +316,27 @@ void envelopeTabWidget::processAudioBuffer( sampleFrame * _ab,
if( static_cast<int>( new_cut_val ) != old_filter_cut ||
static_cast<int>( new_res_val*RES_PRECISION ) != old_filter_res )
{
_n->m_filter->calcFilterCoeffs( filter, new_cut_val, new_res_val );
_n->m_filter->calcFilterCoeffs( new_cut_val, new_res_val );
old_filter_cut = static_cast<int>( new_cut_val );
old_filter_res = static_cast<int>( new_res_val*RES_PRECISION );
}
float vol_level = vol_buf[frame];
vol_level = vol_level*vol_level;
for( ch_cnt_t chnl = 0; chnl < DEFAULT_CHANNELS; ++chnl )
{
_ab[frame][chnl] = vol_level * _n->m_filter->update( _ab[frame][chnl], chnl );
_ab[frame][chnl] = _n->m_filter->update( _ab[frame][chnl], chnl );
}
}
}
else if( m_envLFOWidgets[VOLUME]->used() && m_envLFOWidgets[CUT]->used() )
{
for( fpab_t frame = 0; frame < _frames; ++frame, ++total_frames )
{
float new_cut_val = envelopeAndLFOWidget::expKnobVal( cut_buf[frame] ) * CUT_FREQ_MULTIPLIER +
m_filterCutKnob->value();
if( static_cast<int>( new_cut_val ) != old_filter_cut )
{
_n->m_filter->calcFilterCoeffs( filter, new_cut_val, m_filterResKnob->value() );
old_filter_cut = static_cast<int>( new_cut_val );
}
float vol_level = vol_buf[frame];
vol_level = vol_level*vol_level;
for( ch_cnt_t chnl = 0; chnl < DEFAULT_CHANNELS; ++chnl )
{
_ab[frame][chnl] = vol_level * _n->m_filter->update( _ab[frame][chnl], chnl );
}
}
}
else if( m_envLFOWidgets[VOLUME]->used() && m_envLFOWidgets[RES]->used() )
{
for( fpab_t frame = 0; frame < _frames; ++frame, ++total_frames )
{
float new_res_val = m_filterResKnob->value() + RES_MULTIPLIER *
res_buf[frame];
if( static_cast<int>( new_res_val*RES_PRECISION ) != old_filter_res )
{
_n->m_filter->calcFilterCoeffs( filter, m_filterCutKnob->value(), new_res_val );
old_filter_res = static_cast<int>( new_res_val*RES_PRECISION );
}
float vol_level = vol_buf[frame];
vol_level = vol_level*vol_level;
for( ch_cnt_t chnl = 0; chnl < DEFAULT_CHANNELS; ++chnl )
{
_ab[frame][chnl] = vol_level * _n->m_filter->update( _ab[frame][chnl], chnl );
}
}
}
else if( m_envLFOWidgets[CUT]->used() )
{
for( fpab_t frame = 0; frame < _frames; ++frame, ++total_frames )
for( fpab_t frame = 0; frame < _frames; ++frame )
{
float new_cut_val = envelopeAndLFOWidget::expKnobVal( cut_buf[frame] ) * CUT_FREQ_MULTIPLIER +
m_filterCutKnob->value();
if( static_cast<int>( new_cut_val ) != old_filter_cut )
{
_n->m_filter->calcFilterCoeffs( filter, new_cut_val, m_filterResKnob->value() );
_n->m_filter->calcFilterCoeffs( new_cut_val, m_filterResKnob->value() );
old_filter_cut = static_cast<int>( new_cut_val );
}
@@ -415,14 +348,14 @@ void envelopeTabWidget::processAudioBuffer( sampleFrame * _ab,
}
else if( m_envLFOWidgets[RES]->used() )
{
for( fpab_t frame = 0; frame < _frames; ++frame, ++total_frames )
for( fpab_t frame = 0; frame < _frames; ++frame )
{
float new_res_val = m_filterResKnob->value() + RES_MULTIPLIER *
res_buf[frame];
if( static_cast<int>( new_res_val*RES_PRECISION ) != old_filter_res )
{
_n->m_filter->calcFilterCoeffs( filter, m_filterCutKnob->value(), new_res_val );
_n->m_filter->calcFilterCoeffs( m_filterCutKnob->value(), new_res_val );
old_filter_res = static_cast<int>( new_res_val*RES_PRECISION );
}
@@ -432,26 +365,11 @@ void envelopeTabWidget::processAudioBuffer( sampleFrame * _ab,
}
}
}
else if( m_envLFOWidgets[VOLUME]->used() )
{
_n->m_filter->calcFilterCoeffs( filter, m_filterCutKnob->value(), m_filterResKnob->value() );
for( fpab_t frame = 0; frame < _frames; ++frame, ++total_frames )
{
float vol_level = vol_buf[frame];
vol_level = vol_level*vol_level;
for( ch_cnt_t chnl = 0; chnl < DEFAULT_CHANNELS; ++chnl )
{
_ab[frame][chnl] = vol_level * _n->m_filter->update( _ab[frame][chnl], chnl );
}
}
}
else
{
_n->m_filter->calcFilterCoeffs( filter, m_filterCutKnob->value(), m_filterResKnob->value() );
_n->m_filter->calcFilterCoeffs( m_filterCutKnob->value(), m_filterResKnob->value() );
for( fpab_t frame = 0; frame < _frames; ++frame, ++total_frames )
for( fpab_t frame = 0; frame < _frames; ++frame )
{
for( ch_cnt_t chnl = 0; chnl < DEFAULT_CHANNELS; ++chnl )
{
@@ -459,24 +377,39 @@ void envelopeTabWidget::processAudioBuffer( sampleFrame * _ab,
}
}
}
m_envLFOWidgets[RES]->unlock();
m_envLFOWidgets[CUT]->unlock();
delete[] cut_buf;
delete[] res_buf;
}
else if( m_envLFOWidgets[VOLUME]->used() /*&& m_envLFOWidgets[PANNING]->used() == FALSE*/ )
m_envLFOWidgets[VOLUME]->lock();
if( m_envLFOWidgets[VOLUME]->used() )
{
// only use volume-envelope...
for( fpab_t frame = 0; frame < _frames; ++frame, ++total_frames )
float * vol_buf = new float[_frames];
m_envLFOWidgets[VOLUME]->fillLevel( vol_buf, total_frames,
release_begin, _frames );
for( fpab_t frame = 0; frame < _frames; ++frame )
{
float vol_level = vol_buf[frame];
vol_level = vol_level*vol_level;
for( ch_cnt_t chnl = 0; chnl < DEFAULT_CHANNELS; ++chnl )
vol_level = vol_level * vol_level;
for( ch_cnt_t chnl = 0; chnl < DEFAULT_CHANNELS;
++chnl )
{
_ab[frame][chnl] = vol_level * _ab[frame][chnl];
}
}
delete[] vol_buf;
}
m_envLFOWidgets[VOLUME]->unlock();
/* else if( m_envLFOWidgets[VOLUME]->used() == FALSE && m_envLFOWidgets[PANNING]->used() )
{
// only use panning-envelope...
for( fpab_t frame = 0; frame < _frames; ++frame, ++total_frames )
for( fpab_t frame = 0; frame < _frames; ++frame )
{
float vol_level = pan_buf[frame];
vol_level = vol_level*vol_level;
@@ -486,14 +419,6 @@ void envelopeTabWidget::processAudioBuffer( sampleFrame * _ab,
}
}
}*/
delete[] vol_buf;
delete[] cut_buf;
delete[] res_buf;
m_envLFOWidgets[RES]->unlock();
m_envLFOWidgets[CUT]->unlock();
m_envLFOWidgets[VOLUME]->unlock();
}

View File

@@ -55,6 +55,7 @@
#include "combobox.h"
#include "led_checkbox.h"
#include "embed.h"
#include "engine.h"
#include "audio_file_wave.h"
#include "audio_file_ogg.h"
@@ -383,7 +384,8 @@ void exportProjectDialog::exportBtnClicked( void )
songEditor::PLAY_SONG );
while( engine::getSongEditor()->exportDone() == FALSE &&
engine::getSongEditor()->exporting() == TRUE )
engine::getSongEditor()->exporting() == TRUE
&& !m_deleteFile )
{
dev->processNextBuffer();
int pval = pp * 100 /
@@ -401,13 +403,7 @@ void exportProjectDialog::exportBtnClicked( void )
qApp->processEvents();
}
// if m_deleteFile == TRUE, user aborted export and finalization-
// routines were already called, so we only need to call them if
// export went through without any problems
if( m_deleteFile == FALSE )
{
finishProjectExport();
}
finishProjectExport();
}
@@ -432,8 +428,6 @@ void exportProjectDialog::cancelBtnClicked( void )
void exportProjectDialog::abortProjectExport( void )
{
m_deleteFile = TRUE;
finishProjectExport();
}

View File

@@ -75,7 +75,6 @@
#include "config_mgr.h"
#include "mixer.h"
#include "project_notes.h"
#include "buffer_allocator.h"
#include "setup_dialog.h"
#include "audio_dummy.h"
#include "tool.h"

View File

@@ -32,7 +32,6 @@
#include "song_editor.h"
#include "templates.h"
#include "envelope_and_lfo_widget.h"
#include "buffer_allocator.h"
#include "debug.h"
#include "engine.h"
#include "config_mgr.h"
@@ -109,8 +108,7 @@ mixer::mixer( void ) :
for( Uint8 i = 0; i < 3; i++ )
{
m_readBuf = bufferAllocator::alloc<surroundSampleFrame>(
m_framesPerAudioBuffer );
m_readBuf = new surroundSampleFrame[m_framesPerAudioBuffer];
clearAudioBuffer( m_readBuf, m_framesPerAudioBuffer );
m_bufferPool.push_back( m_readBuf );
@@ -135,7 +133,7 @@ mixer::~mixer()
for( Uint8 i = 0; i < 3; i++ )
{
bufferAllocator::free( m_bufferPool[i] );
delete[] m_bufferPool[i];
}
}
@@ -165,11 +163,12 @@ void mixer::startProcessing( void )
void mixer::stopProcessing( void )
{
m_fifo_writer->finish();
m_audioDev->stopProcessing();
m_fifo_writer->wait( 1000 );
m_fifo_writer->terminate();
delete m_fifo_writer;
m_audioDev->stopProcessing();
}

View File

@@ -39,8 +39,8 @@
#include <math.h>
#include "debug.h"
#include "note.h"
#include "automatable_object_templates.h"
#include "knob.h"
#include "templates.h"

View File

@@ -27,6 +27,7 @@
#include "note_play_handle.h"
#include "automatable_object_templates.h"
#include "instrument_track.h"
#include "envelope_tab_widget.h"
#include "midi.h"

View File

@@ -62,6 +62,7 @@
#include "piano_roll.h"
#include "automatable_object_templates.h"
#include "song_editor.h"
#include "main_window.h"
#include "pattern.h"

View File

@@ -48,6 +48,7 @@
#include "piano_widget.h"
#include "automatable_object_templates.h"
#include "instrument_track.h"
#include "midi.h"
#include "templates.h"

View File

@@ -31,7 +31,6 @@
#include "pattern.h"
#include "sample_buffer.h"
#include "sample_track.h"
#include "buffer_allocator.h"
#include "audio_port.h"
@@ -132,8 +131,7 @@ void samplePlayHandle::play( const fpab_t _frame_base, bool )
if( !( m_track && m_track->muted() )
&& !( m_bbTrack && m_bbTrack->muted() ) )
{
sampleFrame * buf = bufferAllocator::alloc<sampleFrame>(
frames );
sampleFrame * buf = new sampleFrame[frames];
volumeVector v = { { m_volume, m_volume
#ifndef DISABLE_SURROUND
, m_volume, m_volume
@@ -143,7 +141,7 @@ void samplePlayHandle::play( const fpab_t _frame_base, bool )
engine::getMixer()->bufferToPort( buf, frames, _frame_base, v,
m_audioPort );
bufferAllocator::free( buf );
delete[] buf;
}
m_frame += frames;

View File

@@ -61,6 +61,7 @@
#include "project_journal.h"
#include "config_mgr.h"
#include "embed.h"
#include "engine.h"
#include "debug.h"
#include "tooltip.h"
#include "led_checkbox.h"

View File

@@ -69,6 +69,7 @@
#include "song_editor.h"
#include "automatable_object_templates.h"
#include "automatable_slider.h"
#include "bb_editor.h"
#include "rename_dialog.h"

View File

@@ -52,6 +52,7 @@
#include <math.h>
#include "surround_area.h"
#include "automatable_object_templates.h"
#include "embed.h"
#include "templates.h"
#include "tooltip.h"

View File

@@ -50,6 +50,7 @@
#include "track.h"
#include "automation_pattern.h"
#include "track_container.h"
#include "automation_track.h"
#include "instrument_track.h"

View File

@@ -1,230 +0,0 @@
#ifndef SINGLE_SOURCE_COMPILE
/*
* buffer_allocator.cpp - namespace bufferAllocator providing routines for own
* optimized memory-management for audio-buffers
*
* Copyright (c) 2005-2006 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/
#include "qt3support.h"
#ifdef QT4
#include <QtCore/QList>
#include <QtCore/QMutex>
#else
#include <qpair.h>
#include <qvaluelist.h>
#include <qmutex.h>
#define qSort qHeapSort
#endif
#include <math.h>
#include <cstring>
#include "buffer_allocator.h"
#include "templates.h"
#include "mixer.h"
#include "debug.h"
struct bufDesc
{
bool free;
char * origPtr;
void * buf;
Uint32 bytes;
Uint32 timesUsed;
} ;
inline bool operator<( const bufDesc & _bd1, const bufDesc & _bd2 )
{
return( _bd1.timesUsed < _bd2.timesUsed );
}
#ifndef QT3
inline bool operator==( const bufDesc & _bd1, const bufDesc & _bd2 )
{
return( memcmp( &_bd1, &_bd2, sizeof( bufDesc ) ) == 0 );
}
#else
inline bool operator!=( const bufDesc & _bd1, const bufDesc & _bd2 )
{
return( memcmp( &_bd1, &_bd2, sizeof( bufDesc ) ) != 0 );
}
#endif
static vlist<bufDesc> s_buffers;
typedef vlist<bufDesc>::iterator bufIt;
static int s_freeBufs = 0;
static bool s_autoCleanupDisabled = FALSE;
static QMutex s_buffersMutex;
const int BUFFER_ALIGN = 16;
const int BUFFER_ALIGN_MASK = BUFFER_ALIGN - 1;
void bufferAllocator::cleanUp( Uint16 _level )
{
// first insert all unused bufs into an array
vlist<bufDesc> bufsToRemove;
for( bufIt it = s_buffers.begin(); it != s_buffers.end(); ++it )
{
if( ( *it ).free )
{
bufsToRemove.push_back( *it );
}
}
// sort array by usage of each buffer
// ( operator<(...) compares bufDesc::timesUsed )
qSort( bufsToRemove );
const Sint16 todo = tMin<Sint16>( s_buffers.size() - _level,
bufsToRemove.size() );
// now cleanup the first n elements of sorted array
for( Sint16 i = 0; i < todo; ++i )
{
delete[] bufsToRemove[i].origPtr;
s_buffers.erase( qFind( s_buffers.begin(), s_buffers.end(),
bufsToRemove[i] ) );
--s_freeBufs;
}
#ifdef LMMS_DEBUG
//printf( "cleaned up %d buffers\n", todo );
#endif
}
void bufferAllocator::free( void * _buf )
{
s_buffersMutex.lock();
// look for buffer
for( bufIt it = s_buffers.begin(); it != s_buffers.end(); ++it )
{
if( !( *it ).free && ( *it ).buf == _buf )
{
++( *it ).timesUsed;
( *it ).free = TRUE;
++s_freeBufs;
break;
}
}
// do clean-up if neccessary
static const csize CLEANUP_LEVEL = static_cast<csize>( 768 / ( logf(
/*mixer::inst()->framesPerAudioBuffer()*/
128 ) /
logf( 2 ) ) );
static int count = 0;
// only cleanup every 10th time, because otherwise there's a lot of
// overhead e.g. when freeing a lot of single buffers
if( s_autoCleanupDisabled == FALSE &&
s_buffers.size() > CLEANUP_LEVEL && ++count > 10 )
{
cleanUp( CLEANUP_LEVEL );
count = 0;
}
s_buffersMutex.unlock();
}
void * bufferAllocator::allocBytes( Uint32 _bytes )
{
QMutexLocker ml( &s_buffersMutex );
// there's a low probability that we find a matching buffer, if there're
// less than 2 bufs available, so do not search - this speeds up
// processes like pattern-freezing because this way we do not have to
// search for a free buffer in an array, containing several
// 10.000 buffers
if( (csize) s_freeBufs > s_buffers.size() / 10 )
{
bufIt free_buf = s_buffers.end();
// look whether there's a buffer matching to the one wanted and
// find out the most used one (higher chances for being in CPU-
// cache)
for( bufIt it = s_buffers.begin(); it != s_buffers.end(); ++it )
{
if( ( *it ).free && ( *it ).bytes == _bytes )
{
if( free_buf == s_buffers.end() ||
( *it ).timesUsed >
( *free_buf ).timesUsed )
{
free_buf = it;
}
}
}
if( free_buf != s_buffers.end() )
{
--s_freeBufs;
( *free_buf ).free = FALSE;
return( ( *free_buf ).buf );
}
}
// got nothing so far, so we'll alloc a new (aligned) buf
bufDesc d = { FALSE, new char[_bytes + BUFFER_ALIGN], NULL, _bytes, 0 };
d.buf = (void *)( (size_t) d.origPtr + ( BUFFER_ALIGN -
( (size_t) d.origPtr &
BUFFER_ALIGN_MASK ) ) );
s_buffers.push_back( d );
return( d.buf );
}
void bufferAllocator::disableAutoCleanup( bool _disabled )
{
s_autoCleanupDisabled = _disabled;
}
#endif

View File

@@ -4,7 +4,6 @@
#include "src/core/effect_tab_widget.cpp"
#include "src/core/midi_tab_widget.cpp"
#include "src/lib/string_pair_drag.cpp"
#include "src/lib/buffer_allocator.cpp"
#include "src/lib/journalling_object.cpp"
#include "src/lib/project_journal.cpp"
#include "src/lib/embed.cpp"

View File

@@ -69,6 +69,7 @@
#include "arp_and_chords_tab_widget.h"
#include "instrument.h"
#include "audio_port.h"
#include "automation_pattern.h"
#include "midi_client.h"
#include "midi_port.h"
#include "midi_tab_widget.h"

View File

@@ -68,7 +68,6 @@
#include "tooltip.h"
#include "bb_editor.h"
#include "string_pair_drag.h"
#include "buffer_allocator.h"
#include "main_window.h"
@@ -1317,8 +1316,6 @@ patternFreezeThread::~patternFreezeThread()
void patternFreezeThread::run( void )
{
bufferAllocator::disableAutoCleanup( TRUE );
// create and install audio-sample-recorder
bool b;
// we cannot create local copy, because at a later stage
@@ -1368,8 +1365,6 @@ void patternFreezeThread::run( void )
m_pattern->m_frozenPatternMutex.unlock();
}
bufferAllocator::disableAutoCleanup( FALSE );
// restore original audio-device
engine::getMixer()->restoreAudioDevice();

View File

@@ -49,9 +49,11 @@
#include "sample_track.h"
#include "song_editor.h"
#include "embed.h"
#include "engine.h"
#include "templates.h"
#include "tooltip.h"
#include "audio_port.h"
#include "automation_pattern.h"
#include "sample_play_handle.h"
#include "string_pair_drag.h"
#include "knob.h"

View File

@@ -45,6 +45,7 @@
#endif
#include "automatable_object_templates.h"
#include "embed.h"
@@ -296,7 +297,7 @@ void automatableButtonGroup::setValue( const int _value )
#ifdef QT3
#undef findIndex
#undef indexOf
#endif

View File

@@ -42,6 +42,7 @@
#endif
#include "automatable_object_templates.h"
#include "embed.h"

View File

@@ -26,6 +26,7 @@
#include "combobox.h"
#include "automatable_object_templates.h"
#include "templates.h"
#include "embed.h"
#include "gui_templates.h"

View File

@@ -29,6 +29,7 @@
#include "effect_label.h"
#include "sample_track.h"
#include "embed.h"
#include "engine.h"
#include "gui_templates.h"
#include "rename_dialog.h"
#include "main_window.h"

View File

@@ -66,6 +66,7 @@
#include <math.h>
#include "knob.h"
#include "automatable_object_templates.h"
/*#include "midi_client.h"*/
#include "embed.h"
#include "spc_bg_hndl_widget.h"

View File

@@ -46,6 +46,7 @@
#include "lcd_spinbox.h"
#include "automatable_object_templates.h"
#include "embed.h"
#include "gui_templates.h"
#include "templates.h"

View File

@@ -42,6 +42,7 @@
#include "led_checkbox.h"
#include "automatable_object_templates.h"
#include "embed.h"
#include "gui_templates.h"
#include "spc_bg_hndl_widget.h"

View File

@@ -41,6 +41,7 @@
#include "pixmap_button.h"
#include "automatable_object_templates.h"
#include "embed.h"

View File

@@ -59,6 +59,7 @@
#include "tooltip.h"
#include "effect_control_dialog.h"
#include "embed.h"
#include "engine.h"
#include "gui_templates.h"
#include "main_window.h"

View File

@@ -47,6 +47,7 @@
#include "tempo_sync_knob.h"
#include "automatable_object_templates.h"
#include "song_editor.h"
#include "embed.h"
#include "main_window.h"
@@ -76,7 +77,10 @@ tempoSyncKnob::tempoSyncKnob( int _knob_num, QWidget * _parent,
tempoSyncKnob::~tempoSyncKnob()
{
m_custom->deleteLater();
if( m_custom )
{
m_custom->deleteLater();
}
}

View File

@@ -46,7 +46,6 @@
#include "visualization_widget.h"
#include "embed.h"
#include "engine.h"
#include "buffer_allocator.h"
#include "templates.h"
#include "tooltip.h"
@@ -68,7 +67,7 @@ visualizationWidget::visualizationWidget( const QPixmap & _bg, QWidget * _p,
const fpab_t frames = engine::getMixer()->framesPerAudioBuffer();
m_buffer = bufferAllocator::alloc<surroundSampleFrame>( frames );
m_buffer = new surroundSampleFrame[frames];
engine::getMixer()->clearAudioBuffer( m_buffer, frames );
@@ -94,6 +93,7 @@ visualizationWidget::visualizationWidget( const QPixmap & _bg, QWidget * _p,
visualizationWidget::~visualizationWidget()
{
delete[] m_buffer;
}

View File

@@ -28,8 +28,10 @@
#include <math.h>
#include "volume_knob.h"
#include "automatable_object_templates.h"
#include "main_window.h"
#include "config_mgr.h"
#include "engine.h"
#include "text_float.h"
#include "string_pair_drag.h"