3 <h3 id="TOP">Index</h3>
5 <ul><li><a href="#NAME">NAME</a></li>
6 <li><a href="#CATEGORY">CATEGORY</a></li>
7 <li><a href="#DESCRIPTION">DESCRIPTION</a></li>
8 <li><a href="#METHODS">METHODS</a>
9 <ul><li><a href="#open_audio">open_audio</a></li>
10 <li><a href="#PauseAudio">PauseAudio </a></li>
11 <li><a href="#GetAudioStatus">GetAudioStatus </a></li>
12 <li><a href="#LoadWAV">LoadWAV </a></li>
13 <li><a href="#FreeWAV">FreeWAV </a></li>
14 <li><a href="#convert_audio">convert_audio</a></li>
15 <li><a href="#MixAudio">MixAudio </a></li>
16 <li><a href="#LockAudio">LockAudio</a></li>
17 <li><a href="#UnlockAudio">UnlockAudio</a></li>
18 <li><a href="#CloseAudio">CloseAudio </a>
25 <h1 id="NAME">NAME</h1><p><a href="#TOP" class="toplink">Top</a></p>
26 <div id="NAME_CONTENT">
27 <p>SDL::Audio -- SDL Bindings for Audio</p>
30 <h1 id="CATEGORY">CATEGORY</h1><p><a href="#TOP" class="toplink">Top</a></p>
31 <div id="CATEGORY_CONTENT">
32 <p>TODO, Core, Audio</p>
35 <h1 id="DESCRIPTION">DESCRIPTION</h1><p><a href="#TOP" class="toplink">Top</a></p>
36 <div id="DESCRIPTION_CONTENT">
43 <h1 id="METHODS">METHODS</h1><p><a href="#TOP" class="toplink">Top</a></p>
44 <div id="METHODS_CONTENT">
47 <h2 id="open_audio">open_audio</h2>
48 <div id="open_audio_CONTENT">
49 <p>Opens the audio device with the desired parameters.</p>
52 <h2 id="PauseAudio">PauseAudio </h2>
53 <div id="PauseAudio_CONTENT">
54 <p>Pauses and unpauses the audio callback processing</p>
57 <h2 id="GetAudioStatus">GetAudioStatus </h2>
58 <div id="GetAudioStatus_CONTENT">
59 <p>Gets the current audio state</p>
62 <h2 id="LoadWAV">LoadWAV </h2>
63 <div id="LoadWAV_CONTENT">
64 <p>Loads a WAVE file</p>
67 <h2 id="FreeWAV">FreeWAV </h2>
68 <div id="FreeWAV_CONTENT">
69 <p>Frees previously opened WAV data</p>
72 <h2 id="convert_audio">convert_audio</h2>
73 <div id="convert_audio_CONTENT">
74 <pre> SDL::Audio->convert_audio( cvt, data, len )
77 <p>Converts audio data to a desired audio format.</p>
78 <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.
79 First of all, the structure must be created via <code>SDL::AudioCVT-</code>build> along with source and destination format parameters. Secondly,
80 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
81 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
82 <code>len*len_mult</code> bytes in length.</p>
83 <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
84 by <code>data</code>. If <code>convert_audio</code> fails <code>undef</code> is returned, otherwise the converted <code>SDL::AudioCVT</code> structure.</p>
85 <p>If the conversion completed successfully then the converted audio data can be read from <code>cvt-</code>buf>. The amount of valid, converted,
86 audio data in the buffer is equal to <code>cvt-</code>len*cvt->len_ratio>. </p>
93 # Converting some WAV data to hardware format
95 my $desired = SDL::AudioSpec->new();
96 my $obtained = SDL::AudioSpec->new();
99 $desired->freq(22050);
100 $desired->channels(1);
101 $desired->format(AUDIO_S16);
102 $desired->samples(8192);
104 # Open the audio device
105 if( SDL::Audio::open_audio($desired, $obtained) < 0 )
107 printf( STDERR "Couldn't open audio: %s\n", SDL::get_error() );
112 my $wav_ref = SDL::Audio::load_wav('C:/SDL_perl/test/data/sample.wav', $obtained);
116 printf( STDERR "Could not open sample.wav: %s\n", SDL::get_error() );
117 SDL::Audio::close_audio();
121 my ( $wav_spec, $wav_buf, $wav_len ) = @{$wav_ref};
124 my $wav_cvt = SDL::AudioCVT->build( $wav_spec->format, $wav_spec->channels, $wav_spec->freq,
125 $obtained->format, $obtained->channels, $obtained->freq);
127 # Check that the convert was built
130 printf( STDERR "Couldn't build converter!\n" );
131 SDL::Audio::close_audio();
132 SDL::Audio::free_wav($wav_buf);
135 # And now we're ready to convert
136 SDL::Audio::convert_audio($wav_cvt, $wav_buf, $wav_len);
138 # We can delete to original WAV data now
139 SDL::Audio::free_wav($wav_buf);
142 <p><strong>TODO</strong>: What to do with it? How to use callback? See http://www.libsdl.org/cgi/docwiki.cgi/SDL_ConvertAudio</p>
145 <h2 id="MixAudio">MixAudio </h2>
146 <div id="MixAudio_CONTENT">
147 <p>Mixes audio data</p>
150 <h2 id="LockAudio">LockAudio</h2>
151 <div id="LockAudio_CONTENT">
152 <p>Locks out the callback function</p>
155 <h2 id="UnlockAudio">UnlockAudio</h2>
156 <div id="UnlockAudio_CONTENT">
157 <p>Unlocks the callback function</p>
160 <h2 id="CloseAudio">CloseAudio </h2>
161 <div id="CloseAudio_CONTENT">
162 <p>Shuts down audio processing and closes the audio device. </p>