<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>SAMPLE_INSTANCE vs a beginner (me)</title>
		<link>http://www.allegro.cc/forums/view/614455</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Fri, 18 Jul 2014 11:49:44 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hello!<br />I&#39;m new to this forum and quite new to programming as well. This far, I&#39;ve written two very simple games using Allegro 5 but I still don&#39;t feel particurarly sure that I always know what&#39;s going on. <br />I&#39;ve never had this problem before, maybe it&#39;s caused by using a wrong name somewhere, maybe it&#39;s an effect of me having not enough C++ knowledge. Whatever.<br />If you could help me, I&#39;d be very greatful! </p><p>So, what is my problem? I&#39;m following this tutorial: <a href="http://fixbyproximity.com/oop-game-development/">http://fixbyproximity.com/oop-game-development/</a><br />Here&#39;s my problem:<br />My SAMPLE_INSTANCE does not want to play at all. I tried al_set_sample_instance_playing(songInstance, true) as well as al_play_sample_instance(songInstance). At first, I put it in my changeState function, but I&#39;ve also tried to put it in various places in main just to see, where the problem is.<br />I&#39;ve told the program to write out if the sample_instance is playing and it always told me: 0, (not playing). The changeState function itself most certainly works, because I&#39;ve told the game to write out the current state and it changed how I wanted it to.</p><p>So, what the hell is wrong with my instance? I don&#39;t know.</p><p>Here are parts of my code that include anything connected with the instance.</p><p>This is global: </p><p><span class="source-code"><a href="http://www.allegro.cc/manual/ALLEGRO_SAMPLE_INSTANCE"><span class="a">ALLEGRO_SAMPLE_INSTANCE</span></a> <span class="k3">*</span>songInstance<span class="k2">;</span></span></p><p>This is in main: </p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span><a href="http://www.allegro.cc/manual/ALLEGRO_SAMPLE"><span class="a">ALLEGRO_SAMPLE</span></a> <span class="k3">*</span>mainLoop <span class="k3">=</span> NULL<span class="k2">;</span>
<span class="number">  2</span><span class="c">//...</span>
<span class="number">  3</span><a href="http://www.allegro.cc/manual/al_install_keyboard"><span class="a">al_install_keyboard</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  4</span><a href="http://www.allegro.cc/manual/al_init_image_addon"><span class="a">al_init_image_addon</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  5</span><a href="http://www.allegro.cc/manual/al_init_font_addon"><span class="a">al_init_font_addon</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  6</span><a href="http://www.allegro.cc/manual/al_init_ttf_addon"><span class="a">al_init_ttf_addon</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  7</span><a href="http://www.allegro.cc/manual/al_init_primitives_addon"><span class="a">al_init_primitives_addon</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  8</span><a href="http://www.allegro.cc/manual/al_install_audio"><span class="a">al_install_audio</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  9</span><a href="http://www.allegro.cc/manual/al_init_acodec_addon"><span class="a">al_init_acodec_addon</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 10</span><span class="c">//...</span>
<span class="number"> 11</span><span class="c">//...</span>
<span class="number"> 12</span><a href="http://www.allegro.cc/manual/al_reserve_samples"><span class="a">al_reserve_samples</span></a><span class="k2">(</span><span class="n">25</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 13</span>mainLoop <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_sample"><span class="a">al_load_sample</span></a><span class="k2">(</span><span class="s">"MainLoop.wav"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 14</span>songInstance <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_sample_instance"><span class="a">al_create_sample_instance</span></a><span class="k2">(</span>mainLoop<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 15</span><a href="http://www.allegro.cc/manual/al_set_sample_instance_playmode"><span class="a">al_set_sample_instance_playmode</span></a><span class="k2">(</span>songInstance, ALLEGRO_PLAYMODE_LOOP<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 16</span><a href="http://www.allegro.cc/manual/al_attach_sample_instance_to_mixer"><span class="a">al_attach_sample_instance_to_mixer</span></a><span class="k2">(</span>songInstance, <a href="http://www.allegro.cc/manual/al_get_default_mixer"><span class="a">al_get_default_mixer</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 17</span>
<span class="number"> 18</span>ChangeState<span class="k2">(</span>state, TITLE<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 19</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_739.html" target="_blank">srand</a><span class="k2">(</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_821.html" target="_blank">time</a><span class="k2">(</span>NULL<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 20</span>
<span class="number"> 21</span><span class="c">//...</span>
<span class="number"> 22</span><a href="http://www.allegro.cc/manual/al_destroy_sample_instance"><span class="a">al_destroy_sample_instance</span></a><span class="k2">(</span>songInstance<span class="k2">)</span><span class="k2">;</span>
</div></div><p>

And this is the changeState function, called right now only once, just before while(!done) loop.</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span><span class="k1">void</span> ChangeState<span class="k2">(</span><span class="k1">int</span> <span class="k3">&amp;</span>state, <span class="k1">int</span> newState<span class="k2">)</span>
<span class="number">  2</span><span class="k2">{</span>
<span class="number">  3</span>  <span class="k1">if</span> <span class="k2">(</span>state <span class="k3">=</span><span class="k3">=</span> TITLE<span class="k2">)</span>
<span class="number">  4</span>  <span class="k2">{</span>
<span class="number">  5</span>
<span class="number">  6</span>  <span class="k2">}</span>
<span class="number">  7</span>  <span class="k1">else</span> <span class="k1">if</span> <span class="k2">(</span>state <span class="k3">=</span><span class="k3">=</span> PLAYING<span class="k2">)</span>
<span class="number">  8</span>  <span class="k2">{</span>
<span class="number">  9</span>    <span class="k1">for</span> <span class="k2">(</span>iter <span class="k3">=</span> objects.begin<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> iter <span class="k3">!</span><span class="k3">=</span> objects.end<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> <span class="k3">+</span><span class="k3">+</span>iter<span class="k2">)</span>
<span class="number"> 10</span>    <span class="k2">{</span>
<span class="number"> 11</span>      <span class="k1">if</span> <span class="k2">(</span><span class="k2">(</span><span class="k3">*</span>iter<span class="k2">)</span><span class="k3">-</span><span class="k3">&gt;</span>GetID<span class="k2">(</span><span class="k2">)</span> <span class="k3">!</span><span class="k3">=</span> PLAYER <span class="k3">&amp;</span><span class="k3">&amp;</span> <span class="k2">(</span><span class="k3">*</span>iter<span class="k2">)</span><span class="k3">-</span><span class="k3">&gt;</span>GetID<span class="k2">(</span><span class="k2">)</span> <span class="k3">!</span><span class="k3">=</span> MISC<span class="k2">)</span>
<span class="number"> 12</span>        <span class="k2">(</span><span class="k3">*</span>iter<span class="k2">)</span><span class="k3">-</span><span class="k3">&gt;</span>SetAlive<span class="k2">(</span><span class="k1">false</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 13</span>    <span class="k2">}</span>
<span class="number"> 14</span>    <a href="http://www.allegro.cc/manual/al_stop_sample_instance"><span class="a">al_stop_sample_instance</span></a><span class="k2">(</span>songInstance<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 15</span>  <span class="k2">}</span>
<span class="number"> 16</span>  <span class="k1">else</span> <span class="k1">if</span> <span class="k2">(</span>state <span class="k3">=</span><span class="k3">=</span> LOST<span class="k2">)</span>
<span class="number"> 17</span>  <span class="k2">{</span>
<span class="number"> 18</span>
<span class="number"> 19</span>  <span class="k2">}</span>
<span class="number"> 20</span>
<span class="number"> 21</span>  <span class="k1">if</span> <span class="k2">(</span>newState <span class="k3">=</span><span class="k3">=</span> TITLE<span class="k2">)</span>
<span class="number"> 22</span>  <span class="k2">{</span>
<span class="number"> 23</span>    <a href="http://www.allegro.cc/manual/al_play_sample_instance"><span class="a">al_play_sample_instance</span></a><span class="k2">(</span>songInstance<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 24</span>  <span class="k2">}</span>
<span class="number"> 25</span>  <span class="k1">else</span> <span class="k1">if</span> <span class="k2">(</span>newState <span class="k3">=</span><span class="k3">=</span> PLAYING<span class="k2">)</span>
<span class="number"> 26</span>  <span class="k2">{</span>
<span class="number"> 27</span>
<span class="number"> 28</span>  <span class="k2">}</span>
<span class="number"> 29</span>  <span class="k1">else</span> <span class="k1">if</span> <span class="k2">(</span>newState <span class="k3">=</span><span class="k3">=</span> LOST<span class="k2">)</span>
<span class="number"> 30</span>  <span class="k2">{</span>
<span class="number"> 31</span>
<span class="number"> 32</span>  <span class="k2">}</span>
<span class="number"> 33</span>
<span class="number"> 34</span>  state <span class="k3">=</span> newState<span class="k2">;</span>
<span class="number"> 35</span><span class="k2">}</span>
</div></div><p>

Cheers <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>---<br />EDIT:<br />Ok guys, so I have a very surprising solution to my problem. I honestly have no idea why it worked, but here&#39;s what I did:</p><p>checked if another .wav sound would play<br />&quot;oh, it works with this one. Strange&quot;<br />checked if I misspelled the file name or something but not. It was also .wav<br />I opened it in Audacity and exported it again as a .wav (not having changed anything)<br />I replaced my old .wav file with the new one from Audacity<br />It started working.</p><p>I&#39;m dumbfounded. But also glad it worked.<br />Thank you for all the advise you&#39;ve given me. <br />Cheers!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (mir0slaw)</author>
		<pubDate>Mon, 14 Jul 2014 23:30:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Does ex_mixer_chain work for you?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Tue, 15 Jul 2014 03:07:29 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m sorry, but I don&#39;t think I understand what I should do. Do you mean trying to run this file: <a href="http://sourceforge.net/p/alleg/allegro/ci/5.1/tree/examples/ex_mixer_chain.c#l20">http://sourceforge.net/p/alleg/allegro/ci/5.1/tree/examples/ex_mixer_chain.c#l20</a> ?<br />Well, I tried, but my compiler doesn&#39;t know what common.c is and I also found this on the net: <a href="http://opensource.apple.com/source/pam_modules/pam_modules-126.1/common/Common.c">http://opensource.apple.com/source/pam_modules/pam_modules-126.1/common/Common.c</a> and copied it into the project, but compiler doesn&#39;t know what all those included files are:<br />&lt;code start=&quot;1&#39;&gt;#include &lt;CoreFoundation/CoreFoundation.h&gt;<br />#include &lt;DirectoryService/DirectoryService.h&gt;<br />#include &lt;OpenDirectory/OpenDirectory.h&gt;<br />#include &lt;OpenDirectory/OpenDirectoryPriv.h&gt;<br />#include &lt;ServerInformation/ServerInformation.h&gt;&lt;/code&gt;</p><p>Also, I&#39;ve already made programs in Allegro which had working sample instances, but I don&#39;t see any differences in code between them and this one. This is strange.</p><p>Please, remember that I&#39;m new to programming, so try to explain things more carefully.<br />Thank you!<br />Cheers
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (mir0slaw)</author>
		<pubDate>Tue, 15 Jul 2014 09:55:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If you have the allegro source you can compile the examples from there.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Tue, 15 Jul 2014 11:25:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Give him the link too.</p><p><a href="http://cdn.allegro.cc/file/library/allegro/5.0.8/allegro-5.0.8-extra.zip">Sources and windows binaries</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Tue, 15 Jul 2014 11:28:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, I have Allegro 5.0.10 so I used an example from  5.0.10 zip file. I tried to build and run the file &quot;ex_mixer_chain.c&quot; but it gave me a few errors. Here&#39;s a screen shot:<br /><a href="http://postimg.org/image/xu3xpofr1/full/">http://postimg.org/image/xu3xpofr1/full/</a><br />Did I do something wrong?<br />Cheers
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (mir0slaw)</author>
		<pubDate>Tue, 15 Jul 2014 11:40:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The file &quot;common.c&quot; defines open_log() and the others, so somehow you&#39;re not including it.  Is it in the same directory/folder as ex_mixer_chain.c?</p><p>For the error &quot;char followed by bool is illegal&quot;, I&#39;d just delete the word &#39;char&#39; and see if that works.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Tue, 15 Jul 2014 11:46:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That makes me think that you&#39;re using msvc? That bool char error comes from bool being new to C99, which allegro will partially emulate. But the example you&#39;re compiling may be picking up the in configured allegro source instead of a properly installed copy.</p><p>Try just grabbing the pre compiled examples that were linked.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Tue, 15 Jul 2014 13:01:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>But if I open that .exe file that this kind man linked, I get an error &quot;Couldn&#39;t find allegro-5.0.8-monolith-md.dll on your computer&quot;.</p><p>And on allegro web page I can only see download links for 5.0.10 version. What should I do?</p><p>And by the way, what is this .exe supposed to do?</p><p>Cheers
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (mir0slaw)</author>
		<pubDate>Tue, 15 Jul 2014 15:20:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The dll should be in another download on that page.</p><p>If the example doesn&#39;t work, then its a system or allegro problem, rather than your code.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Tue, 15 Jul 2014 15:33:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ok guys, so I have a very surprising solution to my problem. I honestly have no idea why it worked, but here&#39;s what I did:</p><p>checked if another .wav sound would play<br />&quot;oh, it works with this one. Strange&quot;<br />checked if I misspelled the file name or something but not. It was also .wav<br />I opened it in Audacity and exported it again as a .wav (not having changed anything)<br />I replaced my old .wav file with the new one from Audacity<br />It started working.</p><p>I&#39;m dumbfounded. But also glad it worked.<br />Thank you for all the advise you&#39;ve given me. <br />Cheers!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (mir0slaw)</author>
		<pubDate>Thu, 17 Jul 2014 01:01:25 +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/614455/1003079#target">mir0slaw</a> said:</div><div class="quote"><p> checked if I misspelled the file name or something but not. It was also .wav</p></div></div><p>I think there are some special compression formats that weren&#39;t programmed into Allegro.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Thu, 17 Jul 2014 01:07:00 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Sounds like the real issue is that you aren&#39;t checking the return values of the functions you are using. I&#39;d wager al_load_sample returned NULL for your &quot;bad&quot; .wav and you didn&#39;t even notice.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Slartibartfast)</author>
		<pubDate>Thu, 17 Jul 2014 19:36:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I forgot I could do that, that&#39;s valuable advice. Thanks
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (mir0slaw)</author>
		<pubDate>Fri, 18 Jul 2014 11:49:44 +0000</pubDate>
	</item>
</rss>
