- Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathcore_audiospec.t
79 lines (61 loc) · 1.61 KB
/
core_audiospec.t
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
#!/usr/bin/perl -w
BEGIN { # http://wiki.cpantesters.org/wiki/CPANAuthorNotes
use Config;
if ( !$Config{'useithreads'} ) {
print("1..0 # Skip: Perl not compiled with 'useithreads'\n");
exit(0);
}
}
use strict;
use warnings;
use threads;
use threads::shared;
use SDL;
use SDL::Audio;
use SDL::AudioSpec;
use Test::More;
use Devel::Peek;
use Config;
use lib 't/lib';
use SDL::TestTool;
plan( skip_all=>"author tests not required for installation" )
unless ( $ENV{AUTOMATED_TESTING} or$ENV{SDL_RELEASE_TESTING} );
my$audiodriver = $ENV{SDL_AUDIODRIVER};
$ENV{SDL_AUDIODRIVER} = 'dummy'; # unless $ENV{SDL_RELEASE_TESTING};
plan( skip_all=>'Failed to init sound' )
unless SDL::TestTool->init(SDL_INIT_AUDIO);
my$obtained = SDL::AudioSpec->new;
my$p : shared = 0;
my$f : shared = 0;
my$desired = SDL::AudioSpec->new;
$desired->freq(44100);
$desired->format(AUDIO_S8);
$desired->channels(1);
$desired->samples(4096);
$desired->callback('main::callback');
subcallback {
my ( $int_size, $len, $streamref ) = @_;
my$chr = chr(0);
$chr = chr($p) if$p; #Windows is delaying the thread update for some reason
for ( my$i = 0; $i < $len; $i++ ) {
use bytes;
substr( $$streamref, $i, 1, $chr );
if ( $f && $p++ > 200 ) {
$f = 0;
} elsif ( !$f && $p-- < 0 ) {
$f = 1;
}
}
isnt $p, 0, '[callback] tested $p = ' . $p;
}
die'AudioMixer, Unable to open audio: ' . SDL::get_error()
if ( SDL::Audio::open( $desired, $obtained ) < 0 );
SDL::Audio::pause(0);
sleep(1);
SDL::Audio::close();
if ($audiodriver) {
$ENV{SDL_AUDIODRIVER} = $audiodriver;
} else {
delete$ENV{SDL_AUDIODRIVER};
}
done_testing();