Browse files

Added the audio sample ... however it is not working with latest SDL.…

… ...
  • Loading branch information...
1 parent bad295c commit 6e4fbd81536e33e1d9630a0e310c3cb7891b9f0e @kthakore kthakore committed Nov 19, 2010
Showing with 57 additions and 0 deletions.
  1. +57 −0 code_listings/audio.pl
  2. BIN data/sample.wav
View
57 code_listings/audio.pl
@@ -0,0 +1,57 @@
+#!/usr/bin/perl -w
+use strict;
+use SDL;
+use SDL::Audio;
+use SDL::AudioSpec;
+
+use threads;
+use threads::shared;
+
+SDL::init(SDL_INIT_AUDIO);
+
+
+my $desired = SDL::AudioSpec->new;
+
+$desired->freq(44100);
+$desired->format(SDL::Audio::AUDIO_S16SYS);
+$desired->channels(2);
+$desired->samples(4096);
+$desired->callback('main::audio_callback');
+
+
+my $done :shared = 0;
+
+sub audio_callback {
+$done = 1;
+warn 'Set Done:'.$done;
+#SDL::Audio::pause(2);
+}
+
+my $obtained = SDL::AudioSpec->new;
+unless( SDL::Audio::open( $desired, $obtained ) == 0 )
+{
+ die "Problem opening audio:".SDL::get_error();
+}
+my $wav_ref = SDL::Audio::load_wav( 'data/sample.wav', $obtained );
+
+unless ( $wav_ref )
+{
+
+ die "Problem loading wav data:".SDL::get_error();
+
+}
+my ( $wav_spec, $audio_buf, $audio_len ) = @{$wav_ref};
+
+
+SDL::Audio::pause(0);
+
+while( $done != 1 && SDL::Audio::get_status() == SDL_AUDIO_PLAYING )
+{
+ warn $done;
+
+ SDL::delay(100);
+
+}
+SDL::Audio::free_wav($audio_buf);
+SDL::Audio::close();
+
View
BIN data/sample.wav
Binary file not shown.

0 comments on commit 6e4fbd8

Please sign in to comment.