<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, May 17, 2016 at 12:25 AM, David Griffith <span dir="ltr"><<a href="mailto:dave@661.org" target="_blank">dave@661.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">On Mon, 16 May 2016, Andrea Del Signore wrote:<br>
<br>
</span><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">
> I've been knocking my head against a wall for more than a year trying to<br>
> figure out how to correctly mix two streams of audio while using<br>
> libsndfile for input and libao for output.  My main requirement is that<br>
> I cannot assume anything about the output drivers -- that is, I cannot<br>
> depend on the output driver (ALSA, OSS, Sun, etc) being able to do the<br>
> mixing for me.  Many of my target platforms lack any sort of mixing<br>
> services.  I need to do this myself.  I tried starting a mixer/player<br>
> thread that would work in a producer/consumer relationship with one or<br>
> two audio file decoder threads.  I can play one sound at a time just<br>
> fine. When I try to do both, I get distortion followed by a segfault.<br>
<br></span><span class="">
Hi,<br>
<br>
not sure if I understood correctly: do you just want to mix N files?<br>
<br>
Like you I'm learning libsndfile and libao so this is my attempt to mix some audio files:<br>
<br>
<a href="http://pastebin.com/dm7z8b3Z" rel="noreferrer" target="_blank">http://pastebin.com/dm7z8b3Z</a><br>
<br>
HTH,<br>
Andrea<br>
<br>
P.S.<br>
Can someone explain line 88 (I already read the sndfile FAQ)?<br>
</span></blockquote>
<br>
I'm not simply trying to mix two files.  My main project is a game engine in which two sounds are allowed at any one time.  For instance, there can be constant background music punctuated by sound effects.  I can't get these to mix correctly.<br>
<br></blockquote><div><br></div><div>Hi,</div><div><br></div><div>in that case you can just skip the right number of frames before starting playing sounds.</div><div><br></div><div>I modified my code to take the start time for each file and schedule the play time with frame accuracy.</div><div><br></div><div><a href="http://pastebin.com/0PMyfPvK">http://pastebin.com/0PMyfPvK</a></div><div><br></div><div>If you want your timing to be sample accurate the algorithm is a bit more complex.</div><div><br></div><div>Ciao,</div><div>Andrea</div><div><br></div><div><br></div></div></div></div>