<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Creating new samples using std::vector</title>
		<link>http://www.allegro.cc/forums/view/615679</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Mon, 24 Aug 2015 18:51:51 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi! I would like to create empty sounds using std::vector, but I don&#39;t know what to type in &quot;al_create_sample&quot; function in order to create an empty sound.</p><p>For example, when I create empty bitmaps with std::vector I do it like that:</p><p>std::vector &lt; ALLEGRO_BITMAP* &gt; empty_bitmap;</p><p>[...]</p><p>empty_bitmap.push_back(al_create_bitmap(0,0));</p><p>In documentation, al_create_sample function looks like that: al_create_sample(void *buf, unsigned int samples,<br />   unsigned int freq, ALLEGRO_AUDIO_DEPTH depth,<br />   ALLEGRO_CHANNEL_CONF chan_conf, bool free_buf)</p><p>what do I have to type in this function in order to create an empty sound? Please help.</p><p>And sorry for my english <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bronxz)</author>
		<pubDate>Sun, 23 Aug 2015 18:17:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I don&#39;t know, but why not just set the pointer to NULL instead?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Sun, 23 Aug 2015 18:33:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I have some ideas to solve it. </p><p>1st. Create an empty sample, as you would do normal. Then you keep pushing this example into the vector. Sadly you can end up with having a vector filled with samples pointing all at the same memory :-)</p><p>2nd, somewhat more complicated solution. Find the header for the sample definition. There look at the copy constructor of sample. You will need the same information as the copy constructor, since you make a copy. </p><p>3rd solution. You create a proforma class with sample included. There you define you&#39;re on copy constructor. When doing this, surely new objects will be created. </p><p>Once I had this problems with bitmaps in vectors...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (#00JMP00)</author>
		<pubDate>Sun, 23 Aug 2015 20:30:40 +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/615679/1016118#target">torhu</a> said:</div><div class="quote"><p> I don&#39;t know, but why not just set the pointer to NULL instead? 
</p></div></div><p>This sounds most sensible to me - just make sure you don&#39;t pass a null pointer to <span class="source-code"><a href="http://www.allegro.cc/manual/al_play_sample"><span class="a">al_play_sample</span></a></span></p><p>If you absolutely have to have a non-NULL, but empty, sample, I think this will work:
</p><div class="source-code snippet"><div class="inner"><pre>  <span class="k1">void</span><span class="k3">*</span> dummy <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_malloc"><span class="a">al_malloc</span></a><span class="k2">(</span><span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
  <a href="http://www.allegro.cc/manual/ALLEGRO_SAMPLE"><span class="a">ALLEGRO_SAMPLE</span></a><span class="k3">*</span> samp <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_sample"><span class="a">al_create_sample</span></a><span class="k2">(</span>dummy,
                          <span class="n">0</span>,
                          <span class="n">44100</span>,
                          ALLEGRO_AUDIO_DEPTH_INT16,
                          ALLEGRO_CHANNEL_CONF_1,
                          <span class="k1">true</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
so for you, you could call it as 
</p><div class="source-code snippet"><div class="inner"><pre>std::vector<span class="k3">&lt;</span><a href="http://www.allegro.cc/manual/ALLEGRO_SAMPLE"><span class="a">ALLEGRO_SAMPLE</span></a><span class="k3">*</span><span class="k3">&gt;</span> samples<span class="k2">;</span>
<span class="k2">[</span> ... <span class="k2">]</span>
samples.push_back<span class="k2">(</span><a href="http://www.allegro.cc/manual/al_create_sample"><span class="a">al_create_sample</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_malloc"><span class="a">al_malloc</span></a><span class="k2">(</span><span class="n">0</span><span class="k2">)</span>, <span class="n">0</span>, <span class="n">44100</span>, ALLEGRO_AUDIO_DEPTH_INT16, ALLEGRO_CHANNEL_CONF_1, <span class="k1">true</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Hull)</author>
		<pubDate>Sun, 23 Aug 2015 23:23:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Than you all for help <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>Problem solved.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bronxz)</author>
		<pubDate>Mon, 24 Aug 2015 18:51:51 +0000</pubDate>
	</item>
</rss>
