PageRenderTime 16ms CodeModel.GetById 10ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 1ms

/src/Core/Audio.xs

http://github.com/PerlGameDev/SDL
Unknown | 111 lines | 93 code | 18 blank | 0 comment | 0 complexity | 9c0cc9c20f6c08704f940e578a1531ec MD5 | raw file
  1#include "EXTERN.h"
  2#include "perl.h"
  3#include "XSUB.h"
  4#include "ppport.h"
  5#include "helper.h"
  6
  7#ifndef aTHX_
  8#define aTHX_
  9#endif
 10
 11#include <SDL.h>
 12
 13MODULE = SDL::Audio     PACKAGE = SDL::Audio    PREFIX = audio_
 14
 15int
 16audio_open ( desired, obtained )
 17	SDL_AudioSpec *desired
 18	SDL_AudioSpec *obtained
 19	CODE:
 20		RETVAL = SDL_OpenAudio(desired, obtained);
 21	OUTPUT:
 22		RETVAL
 23
 24void
 25audio_pause ( pause_on )
 26	int pause_on
 27	CODE:
 28		SDL_PauseAudio(pause_on);
 29
 30Uint32
 31audio_get_status ()
 32	CODE:
 33		RETVAL = SDL_GetAudioStatus ();
 34	OUTPUT:
 35		RETVAL
 36
 37void
 38audio_lock ()
 39	CODE:
 40		SDL_LockAudio();
 41
 42void
 43audio_unlock ()
 44	CODE:
 45		SDL_UnlockAudio();
 46
 47AV *
 48audio_load_wav ( filename, spec )
 49	char *filename
 50	SDL_AudioSpec *spec
 51	CODE:
 52		SDL_AudioSpec *temp = safemalloc(sizeof(SDL_AudioSpec));
 53		Uint8 *buf;
 54		Uint32 len;
 55
 56		memcpy( temp, spec, sizeof(SDL_AudioSpec) );
 57		temp = SDL_LoadWAV(filename,temp,&buf,&len);
 58		if ( temp == NULL ) 
 59		{
 60			croak("Error in SDL_LoadWAV: %s", SDL_GetError()); 
 61		}
 62		else
 63		{
 64			RETVAL = (AV*)sv_2mortal((SV*)newAV());
 65			av_push(RETVAL, obj2bag( sizeof(SDL_AudioSpec *), (void *)temp, "SDL::AudioSpec" ));
 66			av_push(RETVAL, newSViv(PTR2IV(buf)));
 67			av_push(RETVAL, newSViv(len));
 68		}
 69	OUTPUT:
 70		RETVAL
 71
 72void
 73audio_free_wav ( audio_buf )
 74	Uint8 *audio_buf
 75	CODE:
 76		SDL_FreeWAV(audio_buf);
 77
 78int
 79audio_convert( cvt, data, len )
 80	SDL_AudioCVT *cvt
 81	Uint8 *data
 82	int len
 83	CODE:
 84		cvt->buf = (Uint8 *)safemalloc(len * cvt->len_mult);
 85		cvt->len = len;
 86		memcpy(cvt->buf, data, cvt->len);
 87		RETVAL = SDL_ConvertAudio(cvt);
 88		
 89		
 90	OUTPUT:
 91		RETVAL
 92
 93SV *
 94audio_audio_driver_name ( ... )
 95	CODE:
 96		char buffer[1024];
 97		if ( SDL_AudioDriverName(buffer, 1024) != NULL ) 
 98		{ 
 99			RETVAL =  newSVpv(buffer, 0);
100		} 
101		else 
102			 XSRETURN_UNDEF;  	
103	OUTPUT:
104		RETVAL
105
106
107void
108audio_close ()
109	CODE:
110		SDL_CloseAudio();
111