<li><a href="#CATEGORY">CATEGORY</a></li>
<li><a href="#DESCRIPTION">DESCRIPTION</a></li>
<li><a href="#METHODS">METHODS</a>
-<ul><li><a href="#open_audio">open_audio</a></li>
-<li><a href="#PauseAudio">PauseAudio </a></li>
+<ul><li><a href="#open">open</a>
+<ul><li><a href="#Synopsis">Synopsis</a></li>
+<li><a href="#Description">Description</a></li>
+</ul>
+</li>
+<li><a href="#pause">pause</a></li>
<li><a href="#GetAudioStatus">GetAudioStatus </a></li>
-<li><a href="#LoadWAV">LoadWAV </a></li>
-<li><a href="#FreeWAV">FreeWAV </a></li>
-<li><a href="#AudioCVT">AudioCVT </a></li>
-<li><a href="#BuildAudioCVT">BuildAudioCVT </a></li>
-<li><a href="#ConvertAudio">ConvertAudio </a></li>
+<li><a href="#load_WAV">load_WAV </a></li>
+<li><a href="#free_WAV">free_WAV </a></li>
+<li><a href="#convert">convert</a></li>
<li><a href="#MixAudio">MixAudio </a></li>
-<li><a href="#LockAudio">LockAudio</a></li>
-<li><a href="#UnlockAudio">UnlockAudio</a></li>
-<li><a href="#CloseAudio">CloseAudio </a>
+<li><a href="#lock">lock</a></li>
+<li><a href="#unlock">unlock</a></li>
+<li><a href="#close">close </a>
</li>
</ul>
</li>
<div id="METHODS_CONTENT">
</div>
-<h2 id="open_audio">open_audio</h2>
-<div id="open_audio_CONTENT">
+<h2 id="open">open</h2>
+<div id="open_CONTENT">
<p>Opens the audio device with the desired parameters.</p>
</div>
-<h2 id="PauseAudio">PauseAudio </h2>
-<div id="PauseAudio_CONTENT">
+<h3 id="Synopsis">Synopsis</h3>
+<div id="Synopsis_CONTENT">
+<pre> use SDL;
+ use SDL::Audio;
+
+ SDL::init(SDL_INIT_AUDIO);
+
+ my $desired = SDL::AudioSpec->new();
+
+ my $obtained;
+
+ SDL::open_audio($desired, $obtained);
+
+ # $obtained->... (A new SDL::AudioSpec now);
+
+</pre>
+
+</div>
+<h3 id="Description">Description</h3>
+<div id="Description_CONTENT">
+<p>This function opens the audio device with the desired parameters, and returns 0 if successful, placing the actual hardware parameters in the structure pointed to by obtained. If obtained is NULL, the audio data passed to the callback function will be guaranteed to be in the requested format, and will be automatically converted to the hardware audio format if necessary. This function returns -1 if it failed to open the audio device, or couldn't set up the audio thread.</p>
+<p>To open the audio device a desired SDL::AudioSpec must be created.</p>
+<pre> my $desired = SDL::AudioSpec->new();
+
+</pre>
+<p>You must then fill this structure with your desired audio specifications.</p>
+<dl>
+ <dt>The desired audio frequency in samples-per-second. </dt>
+ <dd>
+<pre> $desired->freq
+
+</pre>
+ </dd>
+ <dt>The desired audio format. See <cite>SDL::AudioSpec</cite></dt>
+ <dd>
+<pre> $desired->format
+
+</pre>
+ </dd>
+ <dt>The desired channels (1 for mono, 2 for stereo, 4 for surround, 6 for surround with center and lfe). </dt>
+ <dd>
+<pre> $desired->channels
+
+</pre>
+ </dd>
+ <dt>The desired size of the audio buffer in samples. This number should be a power of two, and may be adjusted by the audio driver to a value more suitable for the hardware. Good values seem to range between 512 and 8192 inclusive, depending on the application and CPU speed. Smaller values yield faster response time, but can lead to underflow if the application is doing heavy processing and cannot fill the audio buffer in time. A stereo sample consists of both right and left channels in LR ordering. Note that the number of samples is directly related to time by the following formula: ms = (samples*1000)/freq </dt>
+ <dd>
+<pre> $desired->samples
+
+</pre>
+ </dd>
+ <dt>This should be set to a function that will be called when the audio device is ready for more data. It is passed a pointer to the audio buffer, and the length in bytes of the audio buffer. This function usually runs in a separate thread, and so you should protect data structures that it accesses by calling SDL::Audio::lock and SDL::Audio::unlock in your code. </dt>
+ <dd>
+ <p>THIS IS NOT READY YET</p>
+<pre> $desired->callback
+
+ my $callback= sub{ my ($userdata, $stream, $len) = @_; };
+
+ $userdata is a reference stored in the userdata field of the SDL::AudioSpec.
+ $stream is a pointer to the audio buffer you want to fill with information and $len is the length of the audio buffer in bytes.
+
+ $desired->userdata
+
+ This pointer is passed as the first parameter to the callback function.
+
+</pre>
+ </dd>
+</dl>
+<p>SDL::Audio::open reads these fields from the desired SDL::AudioSpec structure passed to the function and attempts to find an audio configuration matching your desired. As mentioned above, if the obtained parameter is NULL then SDL with convert from your desired audio settings to the hardware settings as it plays.</p>
+<p>If obtained is NULL then the desired SDL::AudioSpec is your working specification, otherwise the obtained SDL::AudioSpec becomes the working specification and the desired specification can be deleted. The data in the working specification is used when building <cite>SDL::AudioCVT</cite>'s for converting loaded data to the hardware format.</p>
+<p>SDL::Audio::open calculates the size and silence fields for both the $desired and $obtained specifications. The size field stores the total size of the audio buffer in bytes, while the silence stores the value used to represent silence in the audio buffer</p>
+<p>The audio device starts out playing silence when it's opened, and should be enabled for playing by calling SDL::Audio::pause(0) when you are ready for your audio callback function to be called. Since the audio driver may modify the requested size of the audio buffer, you should allocate any local mixing buffers after you open the audio device. </p>
+
+</div>
+<h2 id="pause">pause</h2>
+<div id="pause_CONTENT">
<p>Pauses and unpauses the audio callback processing</p>
</div>
<p>Gets the current audio state</p>
</div>
-<h2 id="LoadWAV">LoadWAV </h2>
-<div id="LoadWAV_CONTENT">
+<h2 id="load_WAV">load_WAV </h2>
+<div id="load_WAV_CONTENT">
<p>Loads a WAVE file</p>
</div>
-<h2 id="FreeWAV">FreeWAV </h2>
-<div id="FreeWAV_CONTENT">
+<h2 id="free_WAV">free_WAV </h2>
+<div id="free_WAV_CONTENT">
<p>Frees previously opened WAV data</p>
</div>
-<h2 id="AudioCVT">AudioCVT </h2>
-<div id="AudioCVT_CONTENT">
-<p>Audio Conversion Structure</p>
+<h2 id="convert">convert</h2>
+<div id="convert_CONTENT">
+<pre> SDL::Audio->convert( cvt, data, len )
-</div>
-<h2 id="BuildAudioCVT">BuildAudioCVT </h2>
-<div id="BuildAudioCVT_CONTENT">
-<p>Initializes a SDL_AudioCVT - structure for conversion</p>
-
-</div>
-<h2 id="ConvertAudio">ConvertAudio </h2>
-<div id="ConvertAudio_CONTENT">
+</pre>
<p>Converts audio data to a desired audio format.</p>
+<p><code>convert_audio</code> takes as first parameter <code>cvt</code>, which was previously initialized. Initializing a <code>SDL::AudioCVT</code> is a two step process.
+First of all, the structure must be created via <code>SDL::AudioCVT-</code>build> along with source and destination format parameters. Secondly,
+the <code>data</code> and <code>len</code> fields must be setup. <code>data</code> should point to the audio data buffer beeing source and destination at
+once and <code>len</code> should be set to the buffer length in bytes. Remember, the length of the buffer pointed to by buf should be
+<code>len*len_mult</code> bytes in length.</p>
+<p>Once the <code>SDL::AudioCVT</code> structure is initialized, we can pass it to <code>convert_audio</code>, which will convert the audio data pointed to
+by <code>data</code>. If <code>convert_audio</code> fails <code>undef</code> is returned, otherwise the converted <code>SDL::AudioCVT</code> structure.</p>
+<p>If the conversion completed successfully then the converted audio data can be read from <code>cvt-</code>buf>. The amount of valid, converted,
+audio data in the buffer is equal to <code>cvt-</code>len*cvt->len_ratio>. </p>
+<p>Example:</p>
+<pre> use SDL;
+ use SDL::Audio;
+ use SDL::AudioSpec;
+ use SDL::AudioCVT;
+
+ SDL::init(SDL_INIT_AUDIO);
+
+ # Converting some WAV data to hardware format
+
+ my $desired = SDL::AudioSpec->new();
+ my $obtained = SDL::AudioSpec->new();
+
+ # Set desired format
+ $desired->freq(22050);
+ $desired->channels(1);
+ $desired->format(AUDIO_S16);
+ $desired->samples(8192);
+
+ # Open the audio device
+ if( SDL::Audio::open($desired, $obtained) < 0 )
+ {
+ printf( STDERR "Couldn't open audio: %s\n", SDL::get_error() );
+ exit(-1);
+ }
+
+ # Load the test.wav
+ my $wav_ref = SDL::Audio::load_wav('../../test/data/sample.wav', $obtained);
+
+ unless( $wav_ref )
+ {
+ warn("Could not open sample.wav: %s\n", SDL::get_error() );
+ SDL::Audio::close_audio();
+ SDL::quit;
+ exit(-1);
+ }
+
+ my ( $wav_spec, $wav_buf, $wav_len ) = @{$wav_ref};
+
+ # Build AudioCVT
+ my $wav_cvt = SDL::AudioCVT->build( $wav_spec->format, $wav_spec->channels, $wav_spec->freq,
+ $obtained->format, $obtained->channels, $obtained->freq);
+
+ # Check that the convert was built
+ if( $wav_cvt == -1 )
+ {
+ warn("Couldn't build converter!\n" );
+ SDL::Audio::close();
+ SDL::Audio::free_wav($wav_buf);
+ SDL::quit();
+ exit(-1);
+ }
+
+ # And now we're ready to convert
+ SDL::Audio::convert($wav_cvt, $wav_buf, $wav_len);
+
+
+
+
+ # We can freeto original WAV data now
+ SDL::Audio::free_wav($wav_buf);
+
+
+
+
+
+
+
+</pre>
+<p><strong>TODO</strong>: What to do with it? How to use callback? See http://www.libsdl.org/cgi/docwiki.cgi/SDL_ConvertAudio</p>
</div>
<h2 id="MixAudio">MixAudio </h2>
<p>Mixes audio data</p>
</div>
-<h2 id="LockAudio">LockAudio</h2>
-<div id="LockAudio_CONTENT">
+<h2 id="lock">lock</h2>
+<div id="lock_CONTENT">
<p>Locks out the callback function</p>
</div>
-<h2 id="UnlockAudio">UnlockAudio</h2>
-<div id="UnlockAudio_CONTENT">
+<h2 id="unlock">unlock</h2>
+<div id="unlock_CONTENT">
<p>Unlocks the callback function</p>
</div>
-<h2 id="CloseAudio">CloseAudio </h2>
-<div id="CloseAudio_CONTENT">
+<h2 id="close">close </h2>
+<div id="close_CONTENT">
<p>Shuts down audio processing and closes the audio device. </p>
</div>
<h3 id="TOP">Index</h3>
<ul><li><a href="#NAME">NAME</a></li>
-<li><a href="#CATEGORY">CATEGORY</a>
+<li><a href="#CATEGORY">CATEGORY</a></li>
+<li><a href="#SYNOPSIS">SYNOPSIS</a></li>
+<li><a href="#DESCRIPTION">DESCRIPTION</a></li>
+<li><a href="#METHODS">METHODS</a>
+<ul><li><a href="#new">new</a></li>
+<li><a href="#build">build</a></li>
+<li><a href="#needed">needed</a></li>
+<li><a href="#src_format">src_format</a></li>
+<li><a href="#dest_format">dest_format</a></li>
+<li><a href="#rate_incr">rate_incr</a></li>
+<li><a href="#len">len</a></li>
+<li><a href="#len_cvt">len_cvt</a></li>
+<li><a href="#len_mult">len_mult</a></li>
+<li><a href="#len_ratio">len_ratio</a></li>
+</ul>
+</li>
+<li><a href="#AUTHOR">AUTHOR</a>
</li>
</ul><hr />
<!-- INDEX END -->
<h1 id="NAME">NAME</h1><p><a href="#TOP" class="toplink">Top</a></p>
<div id="NAME_CONTENT">
-<p>SDL::AudioCVT -- Bindings to SDL structure SDL_AudioCVT</p>
+<p>SDL::AudioCVT -- Audio Conversion Structure</p>
</div>
<h1 id="CATEGORY">CATEGORY</h1><p><a href="#TOP" class="toplink">Top</a></p>
<div id="CATEGORY_CONTENT">
-<p>TODO, Core, Audio</p>
+<p>Core, Audio, Structure</p>
+
+</div>
+<h1 id="SYNOPSIS">SYNOPSIS</h1><p><a href="#TOP" class="toplink">Top</a></p>
+<div id="SYNOPSIS_CONTENT">
+
+</div>
+<h1 id="DESCRIPTION">DESCRIPTION</h1><p><a href="#TOP" class="toplink">Top</a></p>
+<div id="DESCRIPTION_CONTENT">
+<p>The <code>SDL::AudioCVT</code> is used to convert audio data between different formats. A <code>SDL::AudioCVT</code> structure is created with the
+<code>SDL::AudioCVT-</code>build> function, while the actual conversion is done by the <code>SDL::Audio::convert_audio</code> function. </p>
+
+</div>
+<h1 id="METHODS">METHODS</h1><p><a href="#TOP" class="toplink">Top</a></p>
+<div id="METHODS_CONTENT">
+
+</div>
+<h2 id="new">new</h2>
+<div id="new_CONTENT">
+<p>This constructor returns an empty <code>SDL::AudioCVT</code> structure.</p>
+
+</div>
+<h2 id="build">build</h2>
+<div id="build_CONTENT">
+<pre> $cvt = SDL::AudioCVT->build( $src_format, $src_channels, $src_rate
+ $dst_format, $dst_channels, $dst_rate );
+
+</pre>
+<p>Before an <code>SDL::AudioCVT</code> structure can be used to convert audio data it must be initialized with source and destination information.</p>
+<p><code>src_format</code> and <code>dst_format</code> are the source and destination format of the conversion. (For information on audio formats see
+<code>SDL::AudioSpec</code>). <code>src_channels</code> and <code>dst_channels</code> are the number of channels in the source and destination formats.
+Finally, <code>src_rate</code> and <code>dst_rate</code> are the frequency or samples-per-second of the source and destination formats. Once again,
+see <code>SDL::AudioSpec</code>.</p>
+<p>Currently (SDL-1.2.11) only rate conversions of 2x and (1/2)x with x > 0 are done, nearing the requested rate conversion. </p>
+<p>See <code>SDL::Audio::convert_audio</code>.</p>
+
+</div>
+<h2 id="needed">needed</h2>
+<div id="needed_CONTENT">
+<p>Set to one if the conversion is possible</p>
+
+</div>
+<h2 id="src_format">src_format</h2>
+<div id="src_format_CONTENT">
+<p>Audio format of the source</p>
+
+</div>
+<h2 id="dest_format">dest_format</h2>
+<div id="dest_format_CONTENT">
+<p>Audio format of the destination</p>
+
+</div>
+<h2 id="rate_incr">rate_incr</h2>
+<div id="rate_incr_CONTENT">
+<p>Rate conversion increment</p>
+
+</div>
+<h2 id="len">len</h2>
+<div id="len_CONTENT">
+<p>Length of the original audio buffer in bytes</p>
+
+</div>
+<h2 id="len_cvt">len_cvt</h2>
+<div id="len_cvt_CONTENT">
+<p>Length of converted audio buffer in bytes (calculated)</p>
+
+</div>
+<h2 id="len_mult">len_mult</h2>
+<div id="len_mult_CONTENT">
+<p><code>buf</code> must be <code>len*len_mult</code> bytes in size (calculated)</p>
+
+</div>
+<h2 id="len_ratio">len_ratio</h2>
+<div id="len_ratio_CONTENT">
+<p>Final audio size is <code>len*len_ratio</code></p>
+
+</div>
+<h1 id="AUTHOR">AUTHOR</h1><p><a href="#TOP" class="toplink">Top</a></p>
+<div id="AUTHOR_CONTENT">
+<p>Tobias Leich</p>
</div>
</div>
\ No newline at end of file