Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix freeze when finishing export #2879

Merged
merged 1 commit into from
Jun 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/AudioAlsa.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#define ALSA_PCM_NEW_HW_PARAMS_API

#include <alsa/asoundlib.h>
#include <QThread>

#include "AudioDevice.h"

Expand Down
6 changes: 3 additions & 3 deletions include/AudioDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,15 @@
#ifndef AUDIO_DEVICE_H
#define AUDIO_DEVICE_H

#include <QtCore/QPair>
#include <QtCore/QMutex>
#include <QtCore/QThread>
#include <samplerate.h>

#include "lmms_basics.h"
#include "TabWidget.h"


class AudioPort;
class Mixer;
class QThread;


class AudioDevice
Expand Down Expand Up @@ -135,6 +133,8 @@ class AudioDevice

bool hqAudio() const;

static void stopProcessingThread( QThread * thread );


protected:
bool m_supportsCapture;
Expand Down
6 changes: 1 addition & 5 deletions include/AudioDummy.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,7 @@ class AudioDummy : public AudioDevice, public QThread

virtual void stopProcessing()
{
if( isRunning() )
{
wait( 1000 );
terminate();
}
stopProcessingThread( this );
}

virtual void run()
Expand Down
2 changes: 2 additions & 0 deletions include/AudioOss.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

#ifdef LMMS_HAVE_OSS

#include <QThread>

#include "AudioDevice.h"
#include "AudioDeviceSetupWidget.h"

Expand Down
1 change: 1 addition & 0 deletions include/AudioPulseAudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#ifdef LMMS_HAVE_PULSEAUDIO

#include <pulse/pulseaudio.h>
#include <QThread>

#include "AudioDevice.h"
#include "AudioDeviceSetupWidget.h"
Expand Down
1 change: 1 addition & 0 deletions include/AudioSndio.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#ifdef LMMS_HAVE_SNDIO

#include <QThread>
#include <sndio.h>

#include "AudioDevice.h"
Expand Down
5 changes: 5 additions & 0 deletions include/Mixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ class EXPORT Mixer : public QObject

virtual void run();

void write( surroundSampleFrame * buffer );

} ;


Expand All @@ -347,6 +349,7 @@ class EXPORT Mixer : public QObject

const surroundSampleFrame * renderNextBuffer();

void clearInternal();

void runChangesInModel();

Expand Down Expand Up @@ -403,6 +406,8 @@ class EXPORT Mixer : public QObject

bool m_metronomeActive;

bool m_clearSignal;

bool m_changesSignal;
bool m_waitForMixer;
unsigned int m_changes;
Expand Down
12 changes: 12 additions & 0 deletions include/fifo_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ class fifoBuffer
m_reader_sem.release();
}

bool tryWrite( T _element )
{
if( m_writer_sem.tryAcquire() )
{
m_buffer[m_writer_index++] = _element;
m_writer_index %= m_size;
m_reader_sem.release();
return true;
}
return false;
}

T read()
{
m_reader_sem.acquire();
Expand Down
41 changes: 35 additions & 6 deletions src/core/Mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Mixer::Mixer( bool renderOnly ) :
m_audioDevStartFailed( false ),
m_profiler(),
m_metronomeActive(false),
m_clearSignal( false ),
m_changesSignal( false ),
m_waitForMixer( true ),
m_changes( 0 ),
Expand Down Expand Up @@ -234,9 +235,9 @@ void Mixer::stopProcessing()
{
m_fifoWriter->finish();
m_fifoWriter->wait();
m_audioDev->stopProcessing();
delete m_fifoWriter;
m_fifoWriter = NULL;
m_audioDev->stopProcessing();
}
else
{
Expand Down Expand Up @@ -365,6 +366,12 @@ const surroundSampleFrame * Mixer::renderNextBuffer()
// clear new write buffer
m_inputBufferFrames[ m_inputBufferWrite ] = 0;

if( m_clearSignal )
{
m_clearSignal = false;
clearInternal();
}

// remove all play-handles that have to be deleted and delete
// them if they still exist...
// maybe this algorithm could be optimized...
Expand Down Expand Up @@ -469,12 +476,19 @@ const surroundSampleFrame * Mixer::renderNextBuffer()



void Mixer::clear()
{
m_clearSignal = true;
}




// removes all play-handles. this is necessary, when the song is stopped ->
// all remaining notes etc. would be played until their end
void Mixer::clear()
void Mixer::clearInternal()
{
// TODO: m_midiClient->noteOffAll();
requestChangeInModel();
for( PlayHandleList::Iterator it = m_playHandles.begin(); it != m_playHandles.end(); ++it )
{
// we must not delete instrument-play-handles as they exist
Expand All @@ -484,7 +498,6 @@ void Mixer::clear()
m_playHandlesToRemove.push_back( *it );
}
}
doneChangeInModel();
}


Expand Down Expand Up @@ -1053,10 +1066,26 @@ void Mixer::fifoWriter::run()
surroundSampleFrame * buffer = new surroundSampleFrame[frames];
const surroundSampleFrame * b = m_mixer->renderNextBuffer();
memcpy( buffer, b, frames * sizeof( surroundSampleFrame ) );
m_fifo->write( buffer );
write( buffer );
}

m_fifo->write( NULL );
write( NULL );
}




void Mixer::fifoWriter::write( surroundSampleFrame * buffer )
{
while( !m_fifo->tryWrite( buffer ) )
{
if( m_mixer->m_changesSignal )
{
m_mixer->runChangesInModel();
continue;
}
yieldCurrentThread();
}
}


Expand Down
6 changes: 1 addition & 5 deletions src/core/audio/AudioAlsa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,7 @@ void AudioAlsa::startProcessing()

void AudioAlsa::stopProcessing()
{
if( isRunning() )
{
wait( 1000 );
terminate();
}
stopProcessingThread( this );
}


Expand Down
16 changes: 16 additions & 0 deletions src/core/audio/AudioDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,22 @@ void AudioDevice::stopProcessing()



void AudioDevice::stopProcessingThread( QThread * thread )
{
if( !thread->wait( 30000 ) )
{
fprintf( stderr, "Terminating audio device thread\n" );
thread->terminate();
if( !thread->wait( 1000 ) )
{
fprintf( stderr, "Thread not terminated yet\n" );
}
}
}




void AudioDevice::applyQualitySettings()
{
src_delete( m_srcState );
Expand Down
6 changes: 1 addition & 5 deletions src/core/audio/AudioOss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,7 @@ void AudioOss::startProcessing()

void AudioOss::stopProcessing()
{
if( isRunning() )
{
wait( 1000 );
terminate();
}
stopProcessingThread( this );
}


Expand Down
6 changes: 1 addition & 5 deletions src/core/audio/AudioPulseAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,7 @@ void AudioPulseAudio::startProcessing()

void AudioPulseAudio::stopProcessing()
{
if( isRunning() )
{
wait( 1000 );
terminate();
}
stopProcessingThread( this );
}


Expand Down
6 changes: 1 addition & 5 deletions src/core/audio/AudioSndio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,7 @@ void AudioSndio::startProcessing( void )

void AudioSndio::stopProcessing( void )
{
if( isRunning() )
{
wait( 1000 );
terminate();
}
stopProcessingThread( this );
}


Expand Down