<div dir="ltr"><div>Hi Gunter,</div><div>I've solved the sound glitch. Since it was hard to reproduce, it took me a while, but I eventually figured it out.</div><div><br></div><div>What I needed to do was fill the buffer with more data before handing it off to ao_play. It requires lots of bookkeeping, pointer arithmetic, and a sufficiently large buffer.</div><div><br></div><div>First, the bigger buffer. I just pulled this code from ogg123:</div><div><br></div><div>#define PRIMAGIC (2*2*2*2*3*3*3*5*7)</div><div>#define AUDIO_CHUNK_SIZE ((16384 + PRIMAGIC - 1)/ PRIMAGIC * PRIMAGIC)</div><div>char convbuffer[AUDIO_CHUNK_SIZE];</div><div>const int convsize = AUDIO_CHUNK_SIZE;</div><div><br></div><div>The loop is now more convoluted. Here's the old one, for reference:</div><div><br></div><div>long bytes_read = 0;</div><div>do {</div><div> bytes_read = decode_vorbisfile(&vf);</div><div> ao_play(device, pcmout, bytes_read);</div><div>} while (bytes_read > 0);</div><div><br></div><div>Here's the new loop, which now works:</div><div><br></div><div>long bytes_filled = 0;</div><div>long bytes_remaining = convsize;</div><div>while (1) {</div><div> while (bytes_remaining >= 4096) {</div><div> int current_section;</div><div> long bytes_read = ov_read(&vf, convbuffer + bytes_filled, bytes_remaining, 0, 2, 1, &current_section);</div><div> if (bytes_read == 0) break;</div><div> bytes_remaining -= bytes_read;</div><div> bytes_filled += bytes_read;</div><div> }</div><div> if (bytes_filled == 0) break;</div><div> ao_play(device, convbuffer, bytes_filled);</div><div> bytes_remaining = convsize;</div><div> bytes_filled = 0;</div><div>}</div><div><br></div><div>I'm not sure why, when the system is busy, the buffer needs more data before ao_play is called. All I can think of is that there might be some sort of race condition and ov_read is filling the buffer too slowly to keep up with ao_play.</div><div><br></div><div>Thanks,</div><div>Marshall</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jun 14, 2015 at 10:02 AM, Marshall Mason <span dir="ltr"><<a href="mailto:marshallmason2@gmail.com" target="_blank">marshallmason2@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Gunter,<div>I think this problem started happening when I upgraded from Debian Wheezy to Debian Jessie. If nothing looks amiss in my code, it probably is a sound driver problem. But since it works 100% of the time in ogg123, I feel I must have missed some corner case.</div><div><br></div><div>My audio driver is almost always active. I usually have my music player going in the background when I do my testing. The problem surfaces more reliably after watching a bunch of YouTube videos, but not consistently enough to use it as a test case.</div><div><br></div><div>I'll keep poking at it, and will give an update if I figure it out.</div><div><br></div><div>Thanks for your responses.</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>Marshall</div></font></span></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jun 14, 2015 at 12:51 AM, Gunter Königsmann <span dir="ltr"><<a href="mailto:gunter@peterpall.de" target="_blank">gunter@peterpall.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Dear Marshall,<div><br></div><div>I spent most of yesterday finding out that wxWidget's wxStringArray sometimes drops whitespace in a new entry depending on the character the last entry ended with - so I know what you mean. But your code looks clean and after listening to the bell for what felt too long I started using your program as a regular audio player.</div><div>I too assume the problem lies in the audio driver your soundcard is using and has to be triggered by using some exact timing. One potential way to test for this would be keeping the audio driver active between running instances of your program: You said the problem always turns up when starting the playback. Is it possible for you to constantly play back silent audio in the background while testing? Alsa can be configured to automatically mix all streams that are being played back simultaneously and the sound servers all support this feature, too.</div><div><br></div><div>Kind regards,</div><div><br></div><div> Gunter.</div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>