Add an example that plays a .WAV sound sample
[sdlgit/SDL_perl.git] / test / wave.pl
CommitLineData
71dfa2cb 1#!/usr/bin/env perl
2#
3# This example plays a .WAV sound sample
4#
5use strict;
6use warnings;
7use SDL;
8use SDL::Mixer;
9use SDL::Sound;
10
11SDL::Init(SDL_INIT_AUDIO);
12
13my $filename = shift || 'data/sample.wav';
14
15my $mixer = SDL::Mixer->new(
16 -frequency => 44100,
17);
18print "Using audio driver: ", SDL::AudioDriverName(), "\n";
19
20my $wave = SDL::Sound->new($filename);
21
22# we don't care what channel, and we only want to play it once
23my $channel = $mixer->play_channel( -1, $wave, 0 );
24
25# wait until it has finished playing
26while ( $mixer->playing($channel) ) {
27 SDL::Delay(10);
28}
29