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

[Bugfix][ALSA]Fixes a bug where snd_pcm_writei will hang the mix thread #364

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
27 changes: 13 additions & 14 deletions src/backend/alsa/soloud_alsa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,19 @@ namespace SoLoud
{
struct ALSAData
{
float *buffer;
short *sampleBuffer;
snd_pcm_t *alsaDeviceHandle;
Soloud *soloud;
int samples;
int channels;
bool audioProcessingDone;
float *buffer = NULL;
short *sampleBuffer = NULL;
snd_pcm_t *alsaDeviceHandle = NULL;
Soloud *soloud = NULL;
int samples = 0;
int channels = 0;
bool audioProcessingDone = false;
Thread::ThreadHandle threadHandle;
};


static void alsaThread(void *aParam)
{

ALSAData *data = static_cast<ALSAData*>(aParam);
while (!data->audioProcessingDone)
{
Expand All @@ -71,11 +70,12 @@ namespace SoLoud
data->sampleBuffer[i] = static_cast<short>(floor(data->buffer[i]
* static_cast<float>(0x7fff)));
}

snd_pcm_wait(data->alsaDeviceHandle, -1);
if (snd_pcm_writei(data->alsaDeviceHandle, data->sampleBuffer, data->samples) == -EPIPE)
snd_pcm_prepare(data->alsaDeviceHandle);

}

}

static void alsaCleanup(Soloud *aSoloud)
Expand Down Expand Up @@ -108,11 +108,10 @@ namespace SoLoud
result alsa_init(Soloud *aSoloud, unsigned int aFlags, unsigned int aSamplerate, unsigned int aBuffer, unsigned int aChannels)
{
ALSAData *data = new ALSAData;
memset(data, 0, sizeof(ALSAData));
aSoloud->mBackendData = data;
aSoloud->mBackendCleanupFunc = alsaCleanup;
data->samples = aBuffer;
data->channels = 2;
data->channels = aChannels;
data->soloud = aSoloud;

int rc;
Expand All @@ -131,7 +130,7 @@ namespace SoLoud

snd_pcm_hw_params_set_access(handle, params, SND_PCM_ACCESS_RW_INTERLEAVED);
snd_pcm_hw_params_set_format(handle, params, SND_PCM_FORMAT_S16_LE);
snd_pcm_hw_params_set_channels(handle, params, 2);
snd_pcm_hw_params_set_channels(handle, params, aChannels);
snd_pcm_hw_params_set_buffer_size(handle, params, aBuffer);

unsigned int val = aSamplerate;
Expand Down Expand Up @@ -165,4 +164,4 @@ namespace SoLoud
return 0;
}
};
#endif
#endif