File: core_audio.t

package info (click to toggle)
libsdl-perl 2.548-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,972 kB
  • sloc: perl: 13,985; ansic: 583; makefile: 35
file content (141 lines) | stat: -rw-r--r-- 4,502 bytes parent folder | download | duplicates (5)
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
132
133
134
135
136
137
138
139
140
141
#!/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 SDL;
use SDL::Audio;
use SDL::AudioSpec;
use Test::More;
use Devel::Peek;

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

my $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' );
} else {
	plan( tests => 45 );
}
my @done = qw/
	audio_spec
	open
	pause
	close
	get_status
	lock
	unlock
	/;

is( AUDIO_S16,      32784,  'AUDIO_S16 should be imported' );
is( AUDIO_S16(),    32784,  'AUDIO_S16() should also be available' );
is( AUDIO_S16MSB,   36880,  'AUDIO_S16MSB should be imported' );
is( AUDIO_S16MSB(), 36880,  'AUDIO_S16MSB() should also be available' );
is( AUDIO_S16LSB,   0x8010, 'AUDIO_S16MSB should be imported' );
is( AUDIO_S16LSB(), 0x8010, 'AUDIO_S16MSB() should also be available' );
is( AUDIO_S8,       32776,  'AUDIO_S8 should be imported' );
is( AUDIO_S8(),     32776,  'AUDIO_S8() should also be available' );
is( AUDIO_U16,      16,     'AUDIO_U16 should be imported' );
is( AUDIO_U16(),    16,     'AUDIO_U16() should also be available' );
is( AUDIO_U16MSB,   4112,   'AUDIO_U16MSB should be imported' );
is( AUDIO_U16MSB(), 4112,   'AUDIO_U16MSB() should also be available' );
is( AUDIO_U16LSB,   0x0010, 'AUDIO_U16MSB should be imported' );
is( AUDIO_U16LSB(), 0x0010, 'AUDIO_U16MSB() should also be available' );
is( AUDIO_U8,       8,      'AUDIO_U8 should be imported' );
is( AUDIO_U8(),     8,      'AUDIO_U8() should also be available' );
ok( ( SDL::Audio::AUDIO_U16SYS == AUDIO_U16LSB ) || ( SDL::Audio::AUDIO_U16SYS == AUDIO_U16MSB ),
	'AUDIO_U16SYS should be imported'
);
ok( ( SDL::Audio::AUDIO_U16SYS() == AUDIO_U16LSB() ) || ( SDL::Audio::AUDIO_U16SYS() == AUDIO_U16MSB() ),
	'AUDIO_U16SYS() should also be available'
);

is( SDL_AUDIO_PAUSED,    2, 'SDL_AUDIO_PAUSED should be imported' );
is( SDL_AUDIO_PAUSED(),  2, 'SDL_AUDIO_PAUSED() should also be available' );
is( SDL_AUDIO_PLAYING,   1, 'SDL_AUDIO_PLAYING should be imported' );
is( SDL_AUDIO_PLAYING(), 1, 'SDL_AUDIO_PLAYING() should also be available' );
is( SDL_AUDIO_STOPPED,   0, 'SDL_AUDIO_STOPPED should be imported' );
is( SDL_AUDIO_STOPPED(), 0, 'SDL_AUDIO_STOPPED() should also be available' );

my $driver = SDL::Audio::audio_driver_name();
pass "[audio_driver_name] using audio driver $driver";

my $desired = SDL::AudioSpec->new;
$desired->freq(44100);
is( $desired->freq, 44100, '[audiospec] can set freq' );
$desired->format(SDL::Audio::AUDIO_S16SYS);
is( $desired->format, SDL::Audio::AUDIO_S16SYS, '[audiospec] can set format' );
$desired->channels(2);
is( $desired->channels, 2, '[audiospec] can set channels' );
$desired->samples(4096);
is( $desired->samples, 4096, '[audiospec] can set samples' );
$desired->callback('main::audio_callback');

is( SDL::Audio::get_status, SDL_AUDIO_STOPPED, '[get_status stopped]' );

my $obtained = SDL::AudioSpec->new;
is( SDL::Audio::open( $desired, $obtained ), 0, '[open returned success]' );
isa_ok( $obtained, 'SDL::AudioSpec', 'Created a new AudioSpec' );

my $wav_ref = SDL::Audio::load_wav( 'test/data/sample.wav', $obtained );
isa_ok( $wav_ref, 'ARRAY', "Got and Array Out of load_wav. $wav_ref" );
my ( $wav_spec, $audio_buf, $audio_len ) = @{$wav_ref};
isa_ok( $wav_spec, 'SDL::AudioSpec', '[load_wav] got Audio::Spec back out ' );
is( $audio_len, 481712, '[load_wav] length is correct' );
SDL::Audio::free_wav($audio_buf);

is( SDL::Audio::get_status, SDL_AUDIO_PAUSED, '[get_status paused]' );

SDL::Audio::pause(0);

is( SDL::Audio::get_status, SDL_AUDIO_PLAYING, '[get_status playing]' );

SDL::Audio::lock();
pass('Audio locked');
SDL::Audio::unlock();
pass('Audio unlocked');
SDL::Audio::close();
pass('Audio Closed');
is( SDL::Audio::get_status, SDL_AUDIO_STOPPED, '[get_status stopped]' );

my @left = qw/
	audio_cvt
	build_audio_cvt
	convert_audio
	mix_audio
	/;

my $why =
	  '[Percentage Completion] '
	. int( 100 * ( $#done + 1 ) / ( $#done + $#left + 2 ) )
	. "\% implementation. "
	. ( $#done + 1 ) . " / "
	. ( $#done + $#left + 2 );

TODO:
{
	local $TODO = $why;
	fail "Not Implmented $_" foreach (@left)

}
print "$why\n";

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

sleep(1);

sub audio_callback {

}