1#!/usr/bin/perl -w 2use strict; 3use warnings; 4use SDL; 5use SDL::Config; 6 7my $audiodriver; 8 9BEGIN { 10 use Config; 11 if ( !$Config{'useithreads'} ) { 12 print("1..0 # Skip: Perl not compiled with 'useithreads'\n"); 13 exit(0); 14 } 15 16 use Test::More; 17 use lib 't/lib'; 18 use SDL::TestTool; 19 20 $audiodriver = $ENV{SDL_AUDIODRIVER}; 21 $ENV{SDL_AUDIODRIVER} = 'dummy' unless $ENV{SDL_RELEASE_TESTING}; 22 23 if ( !SDL::TestTool->init(SDL_INIT_AUDIO) ) { 24 plan( skip_all => 'Failed to init sound' ); 25 } elsif ( !SDL::Config->has('SDL_mixer') ) { 26 plan( skip_all => 'SDL_mixer support not compiled' ); 27 } 28} 29 30use SDL::Mixer; 31use SDL::Mixer::Channels; 32use SDL::Mixer::Groups; 33use SDL::Mixer::Samples; 34my $can_open = SDL::Mixer::open_audio( 44100, SDL::Audio::AUDIO_S16SYS, 2, 4096 ); 35 36unless($can_open == 0) 37{ 38 plan( skip_all => 'Cannot open audio :'.SDL::get_error() ); 39} 40 41is( $can_open , 42 0, '[open_audio] ran' 43); 44is( SDL::Mixer::Channels::allocate_channels(8), 45 8, "[allocate_channels] 8 channels allocated" 46); 47is( SDL::Mixer::Groups::reserve_channels(4), 48 4, "[reserve_channels] 4 channels reserved" 49); 50 51my $delay = 100; 52my $audio_test_file = 'test/data/silence.wav'; 53 54if ( $ENV{'SDL_RELEASE_TESTING'} ) { 55 SDL::Mixer::Channels::volume( -1, 10 ); 56 is( SDL::Mixer::Channels::volume( -1, 20 ), 57 10, "[volume] set to 20, previously was 10" 58 ); 59 $delay = 2000; 60 $audio_test_file = 'test/data/sample.wav'; 61} else { 62 SDL::Mixer::Channels::volume( -1, 10 ); 63 is( SDL::Mixer::Channels::volume( -1, 1 ), 64 10, "[volume] set to 1, previously was 10" 65 ); 66} 67 68my $sample_chunk = SDL::Mixer::Samples::load_WAV($audio_test_file); 69my $playing_channel = SDL::Mixer::Channels::play_channel( -1, $sample_chunk, -1 ); 70is( $playing_channel > 3, 71 1, "[play_channel] plays on channel $playing_channel" 72); 73SDL::Mixer::Channels::halt_channel(-1); 74 75is( SDL::Mixer::Groups::group_channel( 0, 0 ), 76 1, "[group_channel] channel 0 to group 0" 77); 78is( SDL::Mixer::Groups::group_channels( 1, 3, 1 ), 79 3, "[group_channels] channel 1-3 to group 1" 80); 81is( SDL::Mixer::Groups::group_channel( 3, -1 ), 82 1, "[group_channel] channel 0 ungrouped" 83); 84is( SDL::Mixer::Groups::group_channels( 3, 3, 2 ), 85 1, "[group_channels] channel 3-3 to group 2" 86); 87is( SDL::Mixer::Groups::group_count(0), 1, "[group_count] for group 0 is 1" ); 88is( SDL::Mixer::Groups::group_count(1), 2, "[group_count] for group 1 is 2" ); 89is( SDL::Mixer::Groups::group_count(2), 1, "[group_count] for group 2 is 1" ); 90is( SDL::Mixer::Groups::group_available(0), 91 0, "[group_available] first channel for group 0 is 0" 92); 93is( SDL::Mixer::Groups::group_available(1), 94 1, "[group_available] first channel for group 1 is 1" 95); 96is( SDL::Mixer::Groups::group_available(2), 97 3, "[group_available] first channel for group 2 is 3" 98); 99is( SDL::Mixer::Groups::group_oldest(1), 100 -1, "[group_oldest] group 1 does not play something" 101); 102 103SDL::Mixer::Channels::play_channel( 2, $sample_chunk, -1 ); 104SDL::delay( $delay / 4 ); 105SDL::Mixer::Channels::play_channel( 1, $sample_chunk, -1 ); 106SDL::delay(100); 107 108is( SDL::Mixer::Groups::group_oldest(1), 109 2, "[group_oldest] channel 2 started first" 110); 111is( SDL::Mixer::Groups::group_newer(1), 112 1, "[group_newer] channel 1 started at last" 113); 114 115SDL::delay(100); 116is( SDL::Mixer::Groups::fade_out_group( 1, $delay * 2 ), 117 2, "[fade_out_group] $delay ms for group 1" 118); 119 120SDL::delay($delay); 121is( SDL::Mixer::Groups::halt_group(1), 0, "[halt_group] group 1 halted" ); 122 123SDL::Mixer::close_audio(); 124pass '[close_audio] ran'; 125 126if ($audiodriver) { 127 $ENV{SDL_AUDIODRIVER} = $audiodriver; 128} else { 129 delete $ENV{SDL_AUDIODRIVER}; 130} 131 132done_testing(); 133