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

This change FIX Issue #2638 (Crash after rendering when using soundio). #5681

Merged
merged 3 commits into from
Oct 30, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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/AudioSoundIo.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class AudioSoundIo : public AudioDevice
fpp_t m_outBufFrameIndex;

bool m_stopped;
bool m_started;

int m_disconnectErr;
void onBackendDisconnect(int err);
Expand Down
33 changes: 28 additions & 5 deletions src/core/audio/AudioSoundIo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ AudioSoundIo::AudioSoundIo( bool & outSuccessful, Mixer * _mixer ) :
m_outBufFrameIndex = 0;
m_outBufFramesTotal = 0;
m_stopped = true;
m_started = false;

m_soundio = soundio_create();
if (!m_soundio)
Expand Down Expand Up @@ -196,6 +197,12 @@ void AudioSoundIo::onBackendDisconnect(int err)
AudioSoundIo::~AudioSoundIo()
{
stopProcessing();

if (m_outstream)
{
soundio_outstream_destroy(m_outstream);
}

if (m_soundio)
{
soundio_destroy(m_soundio);
Expand All @@ -205,18 +212,34 @@ AudioSoundIo::~AudioSoundIo()

void AudioSoundIo::startProcessing()
{
int err;

m_outBufFrameIndex = 0;
m_outBufFramesTotal = 0;
m_outBufSize = mixer()->framesPerPeriod();

m_outBuf = new surroundSampleFrame[m_outBufSize];

if (! m_started)
PhysSong marked this conversation as resolved.
Show resolved Hide resolved
{
if ((err = soundio_outstream_start(m_outstream)))
{
fprintf(stderr,
"AudioSoundIo::startProcessing() :: soundio unable to start stream: %s\n",
soundio_strerror(err));
} else {
m_started = true;
}
}

m_stopped = false;
int err;
if ((err = soundio_outstream_start(m_outstream)))

if ((err = soundio_outstream_pause(m_outstream, false)))
{
m_stopped = true;
fprintf(stderr, "soundio unable to start stream: %s\n", soundio_strerror(err));
fprintf(stderr,
"AudioSoundIo::startProcessing() :: resuming result: %s\n",
soundio_strerror(err));
}
}

Expand All @@ -225,8 +248,8 @@ void AudioSoundIo::stopProcessing()
m_stopped = true;
if (m_outstream)
{
soundio_outstream_destroy(m_outstream);
m_outstream = NULL;
fprintf(stderr, "AudioSoundIo::stopProcessing() :: pausing result: %s\n",
soundio_strerror(soundio_outstream_pause(m_outstream, true)));
}

if (m_outBuf)
Expand Down