PageRenderTime 53ms CodeModel.GetById 11ms app.highlight 39ms RepoModel.GetById 1ms app.codeStats 0ms

/t/core_audio.t

http://github.com/PerlGameDev/SDL
Perl | 141 lines | 118 code | 22 blank | 1 comment | 11 complexity | 1a6301036c59e9565796d45e0e3977b2 MD5 | raw file
  1#!/usr/bin/perl -w
  2BEGIN { # http://wiki.cpantesters.org/wiki/CPANAuthorNotes
  3	use Config;
  4	if ( !$Config{'useithreads'} ) {
  5		print("1..0 # Skip: Perl not compiled with 'useithreads'\n");
  6		exit(0);
  7	}
  8}
  9use strict;
 10use warnings;
 11use SDL;
 12use SDL::Audio;
 13use SDL::AudioSpec;
 14use Test::More;
 15use Devel::Peek;
 16
 17use lib 't/lib';
 18use SDL::TestTool;
 19
 20my $audiodriver = $ENV{SDL_AUDIODRIVER};
 21$ENV{SDL_AUDIODRIVER} = 'dummy' unless $ENV{SDL_RELEASE_TESTING};
 22
 23if ( !SDL::TestTool->init(SDL_INIT_AUDIO) ) {
 24	plan( skip_all => 'Failed to init sound' );
 25} else {
 26	plan( tests => 45 );
 27}
 28my @done = qw/
 29	audio_spec
 30	open
 31	pause
 32	close
 33	get_status
 34	lock
 35	unlock
 36	/;
 37
 38is( AUDIO_S16,      32784,  'AUDIO_S16 should be imported' );
 39is( AUDIO_S16(),    32784,  'AUDIO_S16() should also be available' );
 40is( AUDIO_S16MSB,   36880,  'AUDIO_S16MSB should be imported' );
 41is( AUDIO_S16MSB(), 36880,  'AUDIO_S16MSB() should also be available' );
 42is( AUDIO_S16LSB,   0x8010, 'AUDIO_S16MSB should be imported' );
 43is( AUDIO_S16LSB(), 0x8010, 'AUDIO_S16MSB() should also be available' );
 44is( AUDIO_S8,       32776,  'AUDIO_S8 should be imported' );
 45is( AUDIO_S8(),     32776,  'AUDIO_S8() should also be available' );
 46is( AUDIO_U16,      16,     'AUDIO_U16 should be imported' );
 47is( AUDIO_U16(),    16,     'AUDIO_U16() should also be available' );
 48is( AUDIO_U16MSB,   4112,   'AUDIO_U16MSB should be imported' );
 49is( AUDIO_U16MSB(), 4112,   'AUDIO_U16MSB() should also be available' );
 50is( AUDIO_U16LSB,   0x0010, 'AUDIO_U16MSB should be imported' );
 51is( AUDIO_U16LSB(), 0x0010, 'AUDIO_U16MSB() should also be available' );
 52is( AUDIO_U8,       8,      'AUDIO_U8 should be imported' );
 53is( AUDIO_U8(),     8,      'AUDIO_U8() should also be available' );
 54ok( ( SDL::Audio::AUDIO_U16SYS == AUDIO_U16LSB ) || ( SDL::Audio::AUDIO_U16SYS == AUDIO_U16MSB ),
 55	'AUDIO_U16SYS should be imported'
 56);
 57ok( ( SDL::Audio::AUDIO_U16SYS() == AUDIO_U16LSB() ) || ( SDL::Audio::AUDIO_U16SYS() == AUDIO_U16MSB() ),
 58	'AUDIO_U16SYS() should also be available'
 59);
 60
 61is( SDL_AUDIO_PAUSED,    2, 'SDL_AUDIO_PAUSED should be imported' );
 62is( SDL_AUDIO_PAUSED(),  2, 'SDL_AUDIO_PAUSED() should also be available' );
 63is( SDL_AUDIO_PLAYING,   1, 'SDL_AUDIO_PLAYING should be imported' );
 64is( SDL_AUDIO_PLAYING(), 1, 'SDL_AUDIO_PLAYING() should also be available' );
 65is( SDL_AUDIO_STOPPED,   0, 'SDL_AUDIO_STOPPED should be imported' );
 66is( SDL_AUDIO_STOPPED(), 0, 'SDL_AUDIO_STOPPED() should also be available' );
 67
 68my $driver = SDL::Audio::audio_driver_name();
 69pass "[audio_driver_name] using audio driver $driver";
 70
 71my $desired = SDL::AudioSpec->new;
 72$desired->freq(44100);
 73is( $desired->freq, 44100, '[audiospec] can set freq' );
 74$desired->format(SDL::Audio::AUDIO_S16SYS);
 75is( $desired->format, SDL::Audio::AUDIO_S16SYS, '[audiospec] can set format' );
 76$desired->channels(2);
 77is( $desired->channels, 2, '[audiospec] can set channels' );
 78$desired->samples(4096);
 79is( $desired->samples, 4096, '[audiospec] can set samples' );
 80$desired->callback('main::audio_callback');
 81
 82is( SDL::Audio::get_status, SDL_AUDIO_STOPPED, '[get_status stopped]' );
 83
 84my $obtained = SDL::AudioSpec->new;
 85is( SDL::Audio::open( $desired, $obtained ), 0, '[open returned success]' );
 86isa_ok( $obtained, 'SDL::AudioSpec', 'Created a new AudioSpec' );
 87
 88my $wav_ref = SDL::Audio::load_wav( 'test/data/sample.wav', $obtained );
 89isa_ok( $wav_ref, 'ARRAY', "Got and Array Out of load_wav. $wav_ref" );
 90my ( $wav_spec, $audio_buf, $audio_len ) = @{$wav_ref};
 91isa_ok( $wav_spec, 'SDL::AudioSpec', '[load_wav] got Audio::Spec back out ' );
 92is( $audio_len, 481712, '[load_wav] length is correct' );
 93SDL::Audio::free_wav($audio_buf);
 94
 95is( SDL::Audio::get_status, SDL_AUDIO_PAUSED, '[get_status paused]' );
 96
 97SDL::Audio::pause(0);
 98
 99is( SDL::Audio::get_status, SDL_AUDIO_PLAYING, '[get_status playing]' );
100
101SDL::Audio::lock();
102pass('Audio locked');
103SDL::Audio::unlock();
104pass('Audio unlocked');
105SDL::Audio::close();
106pass('Audio Closed');
107is( SDL::Audio::get_status, SDL_AUDIO_STOPPED, '[get_status stopped]' );
108
109my @left = qw/
110	audio_cvt
111	build_audio_cvt
112	convert_audio
113	mix_audio
114	/;
115
116my $why =
117	  '[Percentage Completion] '
118	. int( 100 * ( $#done + 1 ) / ( $#done + $#left + 2 ) )
119	. "\% implementation. "
120	. ( $#done + 1 ) . " / "
121	. ( $#done + $#left + 2 );
122
123TODO:
124{
125	local $TODO = $why;
126	fail "Not Implmented $_" foreach (@left)
127
128}
129print "$why\n";
130
131if ($audiodriver) {
132	$ENV{SDL_AUDIODRIVER} = $audiodriver;
133} else {
134	delete $ENV{SDL_AUDIODRIVER};
135}
136
137sleep(1);
138
139sub audio_callback {
140
141}