diff options
Diffstat (limited to 'src/soundplayer.cc')
-rw-r--r-- | src/soundplayer.cc | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/soundplayer.cc b/src/soundplayer.cc index 6aea2bf..9802d1b 100644 --- a/src/soundplayer.cc +++ b/src/soundplayer.cc @@ -33,6 +33,7 @@ #define BUFSZ 512 SoundPlayer::SoundPlayer() + : sem_write(1) { start(); } @@ -63,7 +64,7 @@ void SoundPlayer::run() short s[BUFSZ]; while(running) { - sem.acquire(); + sem_read.acquire(); char *pcm; size_t size; @@ -74,11 +75,13 @@ void SoundPlayer::run() size = qi.size; } + sem_write.release(); + printf("."); fflush(stdout); ao_play(dev, pcm, size); - //free(pcm); + free(pcm); /* memset(s, 0, BUFSZ * sizeof(short)); @@ -113,11 +116,14 @@ void SoundPlayer::run() void SoundPlayer::playSamples(const char *pcm, size_t size) { - QMutexLocker lock(&mutex); + sem_write.acquire(); - qi.pcm = (char*)malloc(size); - memcpy(qi.pcm, pcm, size); - qi.size = size; + { + QMutexLocker lock(&mutex); + qi.pcm = (char*)malloc(size); + memcpy(qi.pcm, pcm, size); + qi.size = size; + } - sem.release(); + sem_read.release(); } |