Permalink
Browse files

Implement SDL::AudioSpec

  • Loading branch information...
1 parent ba85b2c commit afb3d72780b218f483b5d5d0409f340de1585c82 @acme acme committed Nov 15, 2009
Showing with 139 additions and 19 deletions.
  1. +7 −0 Build.PL
  2. +9 −0 lib/SDL/AudioSpec.pm
  3. +87 −0 src/Core/objects/AudioSpec.xs
  4. +5 −1 src/SDL.xs
  5. +30 −17 t/core_audio.t
  6. +1 −1 typemap
View
@@ -105,6 +105,13 @@ my %subsystems =
},
libraries => [qw( SDL )],
},
+ AudioSpec => {
+ file => {
+ from => 'src/Core/objects/AudioSpec.xs',
+ to => 'lib/SDL/AudioSpec.xs',
+ },
+ libraries => [qw( SDL )],
+ },
MixChunk => {
file => {
from => 'src/Mixer/objects/MixChunk.xs',
View
@@ -0,0 +1,9 @@
+package SDL::AudioSpec;
+use strict;
+use warnings;
+require Exporter;
+require DynaLoader;
+our @ISA = qw(Exporter DynaLoader);
+bootstrap SDL::AudioSpec;
+
+1;
@@ -0,0 +1,87 @@
+#include "EXTERN.h"
+#include "perl.h"
+#include "XSUB.h"
+
+#ifndef aTHX_
+#define aTHX_
+#endif
+
+#include <SDL.h>
+#include <SDL_audio.h>
+
+MODULE = SDL::AudioSpec PACKAGE = SDL::AudioSpec PREFIX = audiospec_
+
+=for documentation
+
+SDL_AudioSpec -- Audio specification
+
+ /* The calculated values in this structure are calculated by SDL_OpenAudio() */
+ typedef struct SDL_AudioSpec {
+ int freq; /* DSP frequency -- samples per second */
+ Uint16 format; /* Audio data format */
+ Uint8 channels; /* Number of channels: 1 mono, 2 stereo */
+ Uint8 silence; /* Audio buffer silence value (calculated) */
+ Uint16 samples; /* Audio buffer size in samples (power of 2) */
+ Uint16 padding; /* Necessary for some compile environments */
+ Uint32 size; /* Audio buffer size in bytes (calculated) */
+ /* This function is called when the audio device needs more data.
+ 'stream' is a pointer to the audio data buffer
+ 'len' is the length of that buffer in bytes.
+ Once the callback returns, the buffer will no longer be valid.
+ Stereo samples are stored in a LRLRLR ordering.
+ */
+ void (SDLCALL *callback)(void *userdata, Uint8 *stream, int len);
+ void *userdata;
+ } SDL_AudioSpec;
+
+=cut
+
+SDL_AudioSpec *
+audiospec_new (CLASS)
+ char* CLASS
+ CODE:
+ RETVAL = malloc(sizeof(SDL_AudioSpec));
+ OUTPUT:
+ RETVAL
+
+int
+audiospec_freq ( audiospec, ... )
+ SDL_AudioSpec *audiospec
+ CODE:
+ if (items > 1 ) audiospec->freq = SvIV(ST(1));
+ RETVAL = audiospec->freq;
+ OUTPUT:
+ RETVAL
+
+Uint16
+audiospec_format ( audiospec, ... )
+ SDL_AudioSpec *audiospec
+ CODE:
+ if (items > 1 ) audiospec->format = SvIV(ST(1));
+ RETVAL = audiospec->format;
+ OUTPUT:
+ RETVAL
+
+Uint8
+audiospec_channels ( audiospec, ... )
+ SDL_AudioSpec *audiospec
+ CODE:
+ if (items > 1 ) audiospec->channels = SvIV(ST(1));
+ RETVAL = audiospec->channels;
+ OUTPUT:
+ RETVAL
+
+Uint16
+audiospec_samples ( audiospec, ... )
+ SDL_AudioSpec *audiospec
+ CODE:
+ if (items > 1 ) audiospec->samples = SvIV(ST(1));
+ RETVAL = audiospec->samples;
+ OUTPUT:
+ RETVAL
+
+void
+audiospec_DESTROY(self)
+ SDL_AudioSpec *self
+ CODE:
+ safefree( (char *)self );
View
@@ -752,6 +752,8 @@ ShowCursor ( toggle )
OUTPUT:
RETVAL
+=for comment
+
SDL_AudioSpec *
NewAudioSpec ( freq, format, channels, samples )
int freq
@@ -871,7 +873,9 @@ LoadWAV ( filename, spec )
error:
OUTPUT:
RETVAL
-
+
+=cut
+
#ifdef HAVE_SDL_MIXER
void
View
@@ -1,25 +1,38 @@
#!/usr/bin/perl -w
use strict;
use SDL;
+use SDL::AudioSpec;
use Test::More;
-my @done = qw//;
+my @done = qw/
+ audio_spec
+ /;
+
+my $desired = SDL::AudioSpec->new;
+$desired->freq(44100);
+is( $desired->freq, 44100, '[audiospec] can set freq' );
+$desired->format(SDL::Constants::AUDIO_S16);
+is( $desired->format, SDL::Constants::AUDIO_S16,
+ '[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' );
my @left = qw/
-audio_spec
-open_audio
-pause_audio
-get_audio_status
-load_wav
-free_wav
-audio_cvt
-build_audio_cvt
-convert_audio
-mix_audio
-lock_audio
-unlock_audio
-close_audio
-/;
+ open_audio
+ pause_audio
+ get_audio_status
+ load_wav
+ free_wav
+ audio_cvt
+ build_audio_cvt
+ convert_audio
+ mix_audio
+ lock_audio
+ unlock_audio
+ close_audio
+ /;
my $why
= '[Percentage Completion] '
@@ -31,8 +44,8 @@ my $why
TODO:
{
local $TODO = $why;
- fail "Not Implmented $_" foreach(@left)
-
+ fail "Not Implmented $_" foreach (@left)
+
}
diag $why;
View
@@ -45,7 +45,7 @@ SDL_VideoInfo * O_OBJECT
SDL_version * O_OBJECT
SDL_SysWMInfo * O_OBJECT
SDL_Cursor * T_PTR
-SDL_AudioSpec * T_PTR
+SDL_AudioSpec * O_OBJECT
SDL_AudioCVT * T_PTR
Mix_Fading T_UV
Mix_Chunk * O_OBJECT

0 comments on commit afb3d72

Please sign in to comment.