<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>ALLEGRO_AUDIO_STREAM possible to add API to access the &#39;extra&#39; ponter?</title>
		<link>http://www.allegro.cc/forums/view/614984</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Tue, 20 Jan 2015 02:55:26 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yo Allegators!</p><p>As the thread title suggests, I was wondering why the &#39;extra&#39; userdata pointer in the <span class="source-code"><a href="http://www.allegro.cc/manual/ALLEGRO_AUDIO_STREAM"><span class="a">ALLEGRO_AUDIO_STREAM</span></a></span> structure does not have an API to be accessed/used.</p><p>I&#39;ve scoured through the current stream implementations and ALL and EACH of them use the extra pointer to pass a pointer to the file structure (being it WAV, OGG, IT, MOD, whatever), which comes in handy when usign the feeder thread.</p><p>I was looking into implementing a stream version for a WildMidi sample Loader, and of course I&#39;d like to take advantage of threading in Allegro to have an automatic feeding mechanism, but unless I explicitly ADD a wildmidi loader to Allegro itself, I can&#39;t access the &#39;extra&#39; pointer, thus I can&#39;t have the stream internally reference the filedata which would be useful to pass to a dedicated loader thread.</p><p>Premise: I do not want to add a wildmidi loader to Allegro due to:<br />        - Wildmidi being LGPL and thus not very welcome into allegro dependency.<br />        - being a softsynth, it depends on GUS compatible patches and an external cfg file...and as such not &#39;self contained&#39; enough for this task (IMO).</p><p>So I&#39;d like to do that &quot;externally&quot;, but I do WANT to be able to <span class="source-code"><a href="http://www.allegro.cc/manual/al_register_audio_stream_loader"><span class="a">al_register_audio_stream_loader</span></a></span> my loading functions (just like my <span class="source-code"><a href="http://www.allegro.cc/manual/load_sample"><span class="a">load_sample</span></a></span> functions)</p><p>This forces me on (as far as I can tell right now) <b>two</b> possible paths:</p><ul><li><p>explicitly pass around the wildmidi file data structure in my stream manager; <b>problem</b>: I drop the possibility to register my loader into Allegro interface (since it then has incompatible signature).</p><br /></li><li><p>create a <span class="source-code"><span class="k1">static</span></span> container which holds the information for all the open streams and can thus be accessed both from the loader and the feeder thread; <b>problem</b>: an unwanted layer of management and check for data races and so on....</p></li></ul><p>I was looking for some advice on which of these should be my choice...which can very well be &#39;neither of the two&#39; <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" /> </p><p>...and maybe (!) a dev word about adding an API like <span class="source-code">al_set<span class="k3">/</span>get_audio_stream_userdata<span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_AUDIO_STREAM"><span class="a">ALLEGRO_AUDIO_STREAM</span></a><span class="k3">*</span> stream, <span class="k1">void</span><span class="k3">*</span> extra<span class="k2">)</span></span> to the Allegro_Audio addon.</p><p>The latter seems to me that could be an easy addition and should cause no harm.</p><p>My very weakness here is that I do not know squat about proper threading and I&#39;m sure I might be missing something obvious.</p><p>Thanks for any feedback.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (pkrcel)</author>
		<pubDate>Sun, 11 Jan 2015 19:23:29 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That seems like a reasonable addition. Without thinking too much of it, it might be nice to also specify a destructor alongside this pointer?</p><p>There is another, sort of related, thing I just want to put out there. One weakness of the current audio addon is that it conflates two meanings of the word &#39;stream&#39;. The first, is streaming from a file: i.e. on-demand loading/generating audio. The second, is slowly feeding audio data to a mixer. The second is in principle supported, but the first is part of the internal API (every implementation of a file-backed audio stream has an implementation of reading from a file on demand). It&#39;d be nice to make it user-accessible.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Mon, 12 Jan 2015 00:29:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I didn&#39;t think about a destructor, which could come in handy after all when destroying the stream.</p><p>One question arises thou: internally the struct has a member <span class="source-code"><span class="k1">void</span> <span class="k3">*</span>extra</span>, which is currently used and I assumed that IF allocated (i.e. != NULL ) would have al_free called on it upon destruction.</p><p>Were I wrong assuming it?</p><p>Right now I&#39;ve added the two functions but I am merely adding the &#39;extra&#39; as a pointer to a WM_FILE_DATA struct that very much resembles WAVFILE, FLACFILE, etc...so a dtor is not strictly needed. I&#39;ll try to experiment a bit, if you like I can make a PR to have the code availble for review, though it&#39;s DEAD SIMPLE.</p><p>About your observation, I tend to agree that exposing the common interface for on-demand load could be useful, along with being able to register new handlers just like the loader....but I admit I haben&#39;t yet tooled around with the addon enough to have a well-informed opinion; gut feeling is that&#39;s a sensible proposal.</p><p>EDIT: I just realized that I can&#39;t access also the stream mutex with the API...damn...</p><p>How should I go then for a proper feeder thread?</p><h1>BUMP</h1><p>

</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/614984/1009179#target">SiegeLord</a> said:</div><div class="quote"><p> Without thinking too much of it, it might be nice to also specify a destructor alongside this pointer?</p></div></div><p>I&#39;ve dabbled a bit with the two functions, could you please explain me how should I handle the destructor passign along and such? </p><p>Is there something like <span class="source-code">_al_register_destructor</span> internal function? (I ask cause none is documented).</p><h1>BUMP 2</h1><p>

I&#39;ve succeeded into expanding the API with:</p><p><span class="source-code">al_get_audio_stream_userdata</span><br /><span class="source-code">al_set_audio_stream_userdata</span><br /><span class="source-code">al_get_audio_stream_mutex</span></p><p>and implemented a WildMidi loader which can be registered into Allegro interface and auto-feeds the stream.</p><p>It can be found <a href="https://github.com/pkrcel/test_al_wildmidi_loader">here</a> for peer-review, even thou I fear I&#39;ll be an embarrassment to myself <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /></p><p>Anyway I ran into some problems, that persist and that shed some light on what Siegelord wrote above (I didn&#39;t understand fully at the time, I guess).</p><p>The stream internal are quite elaborated and passing a <span class="source-code">userdata</span> pointer to manage the extras seems inefficient and incomplete.</p><p>For example, I correctly register my functions into Allegro interface through <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> and it starts the auto-feed thread, BUT I don&#39;t have means to signal the thread itself to stop if I call <span class="source-code"><a href="http://www.allegro.cc/manual/al_destroy_audio_stream"><span class="a">al_destroy_audio_stream</span></a></span></p><p>In the test executable it&#39;s not a problem but I <b>know</b> this is unacceptable, I will have to find a way to register an <span class="source-code"><span class="k3">*</span>extra</span> destructor that handles the signal for me (by the way, if anybody could suggest HOW, as I asked above, I&#39;d appreciate <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" />).</p><p>Seems a waste, since <span class="source-code"><a href="http://www.allegro.cc/manual/al_destroy_audio_stream"><span class="a">al_destroy_audio_stream</span></a></span> ALREADY does that for the internals.</p><p>I think that the stream API might benefit from a larger exposition of the stream&#39;s structure, at least for the feed thread and such.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (pkrcel)</author>
		<pubDate>Tue, 20 Jan 2015 02:55:26 +0000</pubDate>
	</item>
</rss>
