<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>[A5] Problem with streaming sound</title>
		<link>http://www.allegro.cc/forums/view/608877</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Tue, 29 Nov 2011 16:16:52 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;ve tried to load and stream the music in my game and the file is loaded but it never starts to play. I&#39;ve checked the &quot;ex_stream_seek example&quot; and I don&#39;t see any other functions being used that should relate to this issue.</p><p>As far as I&#39;ve read in the manual only the <span class="source-code"><a href="http://www.allegro.cc/manual/al_load_audio_stream"><span class="a">al_load_audio_stream</span></a></span> is needed to load and start streaming the file.</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/ALLEGRO_AUDIO_STREAM"><span class="a">ALLEGRO_AUDIO_STREAM</span></a> <span class="k3">*</span>music<span class="k2">;</span>
...
music <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_audio_stream"><span class="a">al_load_audio_stream</span></a><span class="k2">(</span>path, <span class="n">4</span>, <span class="n">2048</span><span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/al_set_audio_stream_playmode"><span class="a">al_set_audio_stream_playmode</span></a><span class="k2">(</span>music, ALLEGRO_PLAYMODE_LOOP<span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/al_set_audio_stream_playing"><span class="a">al_set_audio_stream_playing</span></a><span class="k2">(</span>music, <span class="k1">true</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

I&#39;ve tested to load the entire ogg file into memory with <span class="source-code"><a href="http://www.allegro.cc/manual/al_load_sample"><span class="a">al_load_sample</span></a></span> and play it with <span class="source-code"><a href="http://www.allegro.cc/manual/al_play_sample"><span class="a">al_play_sample</span></a></span> and that work as intended.</p><p>Another question, how big sound files are reasonable to load into memory and when is it time to start streaming? Currently the ogg files in my game are ranging from 1.5Mb to 4Mb. Stream or load whole file into memory?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (TeaRDoWN)</author>
		<pubDate>Mon, 21 Nov 2011 18:49:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608877/938053#target">TeaRDoWN</a> said:</div><div class="quote"><p> Currently the ogg files in my game are ranging from 1.5Mb to 4Mb. Stream or load whole file into memory?</p></div></div><p>You should definitely load them into memory. I think streaming is good for files &gt; 50 Mb.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AMCerasoli)</author>
		<pubDate>Mon, 21 Nov 2011 19:00:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Oh, hehe. Roger. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (TeaRDoWN)</author>
		<pubDate>Mon, 21 Nov 2011 19:02:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Loading a sample will uncompress the file. The source size is not directly relevant. It&#39;s the length of the audio and its quality that affects how much RAM is used. </p><p>I would always stream background music.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Mon, 21 Nov 2011 23:11:00 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Maybe this helps?
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/manual/5/al_load_audio_stream">The Manual</a> said:</div><div class="quote"><p>
The audio stream will start in the playing state. <b><i>It should be attached to a voice or mixer to generate any output.</i></b> See ALLEGRO_AUDIO_STREAM for more details.
</p></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Mon, 21 Nov 2011 23:39:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Edgar: Tried this, changed my music from ALLEGRO_SAMPLE to ALLEGRO_AUDIO_STREAM and after loading the stream I used:</p><div class="source-code snippet"><div class="inner"><pre>voice <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_voice"><span class="a">al_create_voice</span></a><span class="k2">(</span><span class="n">44100</span>, ALLEGRO_AUDIO_DEPTH_INT16, ALLEGRO_CHANNEL_CONF_2<span class="k2">)</span><span class="k2">;</span>
music <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_audio_stream"><span class="a">al_load_audio_stream</span></a><span class="k2">(</span><span class="s">"music.ogg"</span>, <span class="n">4</span>, <span class="n">2048</span><span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/al_attach_audio_stream_to_voice"><span class="a">al_attach_audio_stream_to_voice</span></a><span class="k2">(</span>music, voice<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

As far as I can see in the ex_stream_file example this is all you need to do...or?</p><p>EDIT: Noticed the text &quot;don&#39;t recommend attaching audio streams directly to voices&quot; and that helped:
</p><div class="source-code snippet"><div class="inner"><pre>mixer <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_mixer"><span class="a">al_create_mixer</span></a><span class="k2">(</span><span class="n">44100</span>, ALLEGRO_AUDIO_DEPTH_FLOAT32, ALLEGRO_CHANNEL_CONF_2<span class="k2">)</span><span class="k2">;</span>
voice <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_voice"><span class="a">al_create_voice</span></a><span class="k2">(</span><span class="n">44100</span>, ALLEGRO_AUDIO_DEPTH_INT16, ALLEGRO_CHANNEL_CONF_2<span class="k2">)</span><span class="k2">;</span>
music <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_audio_stream"><span class="a">al_load_audio_stream</span></a><span class="k2">(</span><span class="s">"music.ogg"</span>, <span class="n">4</span>, <span class="n">2048</span><span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/al_attach_audio_stream_to_mixer"><span class="a">al_attach_audio_stream_to_mixer</span></a><span class="k2">(</span>music, mixer<span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/al_attach_mixer_to_voice"><span class="a">al_attach_mixer_to_voice</span></a><span class="k2">(</span>mixer, voice<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

When I want to start to stream a new music file what do I need to do? Just run <span class="source-code"><a href="http://www.allegro.cc/manual/al_detach_audio_stream"><span class="a">al_detach_audio_stream</span></a></span> or?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (TeaRDoWN)</author>
		<pubDate>Fri, 25 Nov 2011 18:13:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608877/938462#target">TeaRDoWN</a> said:</div><div class="quote"><p>
When I want to start to stream a new music file what do I need to do? Just run al_detach_audio_stream or? 
</p></div></div><p>
Looks like it, and then attach your new audio stream to the same mixer. I haven&#39;t tried any of this stuff myself yet.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sat, 26 Nov 2011 04:26:59 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ok, I&#39;ll go with this for now and keep an eye out for memory leaks.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (TeaRDoWN)</author>
		<pubDate>Sat, 26 Nov 2011 13:06:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You need to destroy the stream at some point.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Sat, 26 Nov 2011 13:26:23 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Of course, when I start to stream a new file this is the first I do:</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">if</span> <span class="k2">(</span>music <span class="k3">!</span><span class="k3">=</span> NULL<span class="k2">)</span>
<span class="k2">{</span>
  <a href="http://www.allegro.cc/manual/al_detach_audio_stream"><span class="a">al_detach_audio_stream</span></a><span class="k2">(</span>music<span class="k2">)</span><span class="k2">;</span>
  <a href="http://www.allegro.cc/manual/al_destroy_audio_stream"><span class="a">al_destroy_audio_stream</span></a><span class="k2">(</span>music<span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (TeaRDoWN)</author>
		<pubDate>Tue, 29 Nov 2011 16:16:52 +0000</pubDate>
	</item>
</rss>
