Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 131 lines (112 sloc) 3.575 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
#!/usr/bin/perl -w
use strict;
use SDL;
use SDL::Config;

my $audiodriver;

BEGIN {
use Config;
if ( !$Config{'useithreads'} ) {
print("1..0 # Skip: Perl not compiled with 'useithreads'\n");
exit(0);
}

use Test::More;
use lib 't/lib';
use SDL::TestTool;

$audiodriver = $ENV{SDL_AUDIODRIVER};
$ENV{SDL_AUDIODRIVER} = 'dummy' unless $ENV{SDL_RELEASE_TESTING};

if ( !SDL::TestTool->init(SDL_INIT_AUDIO) ) {
plan( skip_all => 'Failed to init sound' );
} elsif ( !SDL::Config->has('SDL_mixer') ) {
plan( skip_all => 'SDL_mixer support not compiled' );
}
}

use SDL::Mixer;
use SDL::Mixer::Channels;
use SDL::Mixer::Groups;
use SDL::Mixer::Samples;
my $can_open = SDL::Mixer::open_audio( 44100, SDL::Audio::AUDIO_S16SYS, 2, 4096 );

unless($can_open == 0)
{
plan( skip_all => 'Cannot open audio :'.SDL::get_error() );
}

is( $can_open ,
0, '[open_audio] ran'
);
is( SDL::Mixer::Channels::allocate_channels(8),
8, "[allocate_channels] 8 channels allocated"
);
is( SDL::Mixer::Groups::reserve_channels(4),
4, "[reserve_channels] 4 channels reserved"
);

my $delay = 100;
my $audio_test_file = 'test/data/silence.wav';

if ( $ENV{'SDL_RELEASE_TESTING'} ) {
SDL::Mixer::Channels::volume( -1, 10 );
is( SDL::Mixer::Channels::volume( -1, 20 ),
10, "[volume] set to 20, previously was 10"
);
$delay = 2000;
$audio_test_file = 'test/data/sample.wav';
} else {
SDL::Mixer::Channels::volume( -1, 10 );
is( SDL::Mixer::Channels::volume( -1, 1 ),
10, "[volume] set to 1, previously was 10"
);
}

my $sample_chunk = SDL::Mixer::Samples::load_WAV($audio_test_file);
my $playing_channel = SDL::Mixer::Channels::play_channel( -1, $sample_chunk, -1 );
is( $playing_channel > 3,
1, "[play_channel] plays on channel $playing_channel"
);
SDL::Mixer::Channels::halt_channel(-1);

is( SDL::Mixer::Groups::group_channel( 0, 0 ),
1, "[group_channel] channel 0 to group 0"
);
is( SDL::Mixer::Groups::group_channels( 1, 3, 1 ),
3, "[group_channels] channel 1-3 to group 1"
);
is( SDL::Mixer::Groups::group_channel( 3, -1 ),
1, "[group_channel] channel 0 ungrouped"
);
is( SDL::Mixer::Groups::group_channels( 3, 3, 2 ),
1, "[group_channels] channel 3-3 to group 2"
);
is( SDL::Mixer::Groups::group_count(0), 1, "[group_count] for group 0 is 1" );
is( SDL::Mixer::Groups::group_count(1), 2, "[group_count] for group 1 is 2" );
is( SDL::Mixer::Groups::group_count(2), 1, "[group_count] for group 2 is 1" );
is( SDL::Mixer::Groups::group_available(0),
0, "[group_available] first channel for group 0 is 0"
);
is( SDL::Mixer::Groups::group_available(1),
1, "[group_available] first channel for group 1 is 1"
);
is( SDL::Mixer::Groups::group_available(2),
3, "[group_available] first channel for group 2 is 3"
);
is( SDL::Mixer::Groups::group_oldest(1),
-1, "[group_oldest] group 1 does not play something"
);

SDL::Mixer::Channels::play_channel( 2, $sample_chunk, -1 );
SDL::delay( $delay / 4 );
SDL::Mixer::Channels::play_channel( 1, $sample_chunk, -1 );
SDL::delay(100);

is( SDL::Mixer::Groups::group_oldest(1),
2, "[group_oldest] channel 2 started first"
);
is( SDL::Mixer::Groups::group_newer(1),
1, "[group_newer] channel 1 started at last"
);

SDL::delay(100);
is( SDL::Mixer::Groups::fade_out_group( 1, $delay * 2 ),
2, "[fade_out_group] $delay ms for group 1"
);

SDL::delay($delay);
is( SDL::Mixer::Groups::halt_group(1), 0, "[halt_group] group 1 halted" );

SDL::Mixer::close_audio();
pass '[close_audio] ran';

if ($audiodriver) {
$ENV{SDL_AUDIODRIVER} = $audiodriver;
} else {
delete $ENV{SDL_AUDIODRIVER};
}

done_testing();
Something went wrong with that request. Please try again.