mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-25 06:47:19 +00:00
[client] audio: stop playback immediately if new playback is started
If a new playback is started while the previous playback is still flushing, we simply allow the stream to continue playing and effectively cancel the flush. In general this is not safe because there may not be enough data in the buffer to avoid underrunning. We could handle this better later by trying to insert the right number of silent samples into the buffer, but for now just completely stop the previous stream before starting the new one.
This commit is contained in:
parent
68b42e1c1a
commit
b34b253814
@ -176,20 +176,10 @@ void audio_playbackStart(int channels, int sampleRate, PSAudioFormat format,
|
||||
|
||||
LG_LOCK(audio.playback.lock);
|
||||
|
||||
static int lastChannels = 0;
|
||||
static int lastSampleRate = 0;
|
||||
|
||||
if (audio.playback.state != STREAM_STATE_STOP)
|
||||
{
|
||||
if (channels == lastChannels && sampleRate == lastSampleRate)
|
||||
{
|
||||
// if the stream was still draining and the format matches, return the
|
||||
// stream to the run state
|
||||
if (audio.playback.state == STREAM_STATE_DRAIN)
|
||||
audio.playback.state = STREAM_STATE_RUN;
|
||||
goto no_change;
|
||||
}
|
||||
|
||||
// Stop the current playback immediately. Even if the format is compatible,
|
||||
// we may not have enough data left in the buffers to avoid underrunning
|
||||
playbackStopNL();
|
||||
}
|
||||
|
||||
@ -197,9 +187,6 @@ void audio_playbackStart(int channels, int sampleRate, PSAudioFormat format,
|
||||
audio.playback.buffer = ringbuffer_new(bufferFrames,
|
||||
channels * sizeof(uint16_t));
|
||||
|
||||
lastChannels = channels;
|
||||
lastSampleRate = sampleRate;
|
||||
|
||||
audio.playback.sampleRate = sampleRate;
|
||||
audio.playback.stride = channels * sizeof(uint16_t);
|
||||
audio.playback.state = STREAM_STATE_SETUP;
|
||||
@ -223,7 +210,6 @@ void audio_playbackStart(int channels, int sampleRate, PSAudioFormat format,
|
||||
|
||||
audio.playback.state = STREAM_STATE_SETUP;
|
||||
|
||||
no_change:
|
||||
LG_UNLOCK(audio.playback.lock);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user