Просмотр исходного кода

SDL FreeAudio driver. Initial Import.

woollybah 10 лет назад
Родитель
Сommit
0e4bd1eb1d
2 измененных файлов с 179 добавлено и 0 удалено
  1. 93 0
      sdlfreeaudio.mod/glue.cpp
  2. 86 0
      sdlfreeaudio.mod/sdlfreeaudio.bmx

+ 93 - 0
sdlfreeaudio.mod/glue.cpp

@@ -0,0 +1,93 @@
+/*
+ Copyright (c) 2014 Bruce A Henderson
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+    1. The origin of this software must not be misrepresented; you must not
+    claim that you wrote the original software. If you use this software
+    in a product, an acknowledgment in the product documentation would be
+    appreciated but is not required.
+
+    2. Altered source versions must be plainly marked as such, and must not be
+    misrepresented as being the original software.
+
+    3. This notice may not be removed or altered from any source
+    distribution.
+*/
+
+#include "pub.mod/freeaudio.mod/freeaudio.h"
+
+#include "SDL.h"
+#include "SDL_audio.h"
+
+extern "C" {
+	audiodevice *OpenSDLAudioDevice();
+	void read_callback(void*  userdata, Uint8* stream, int len);
+}
+
+
+struct sdlaudio : audiodevice {
+	SDL_AudioDeviceID device;
+	SDL_AudioSpec have;
+
+	int reset() {
+
+		SDL_InitSubSystem(SDL_INIT_AUDIO);
+		
+		SDL_AudioSpec want;
+		
+		mix=new mixer(8192);
+		mix->freq=22050;
+		mix->channels=2;
+		
+		SDL_zero(want);
+		want.freq = 44100;
+		want.format = AUDIO_S16LSB;
+		want.channels = 2;
+		want.samples = 4096;
+		want.callback = read_callback;
+		want.userdata = this;
+		
+		device = SDL_OpenAudioDevice(NULL, 0, &want, &have, SDL_AUDIO_ALLOW_FORMAT_CHANGE);
+		if (device == 0) {
+			return 1;
+		}
+		
+		SDL_PauseAudioDevice(device, 0);
+		
+		return 0;
+	}
+	
+	
+	int close(){
+		int	res;
+
+		if (device > 0){
+			SDL_CloseAudioDevice(device);
+			device = 0;
+		}
+		return 0;
+	}
+
+	void read(Uint8* stream, int len){
+		mix->mix16((short*)stream,len/2);
+	}
+
+};
+
+
+void read_callback(void*  userdata, Uint8* stream, int len) {
+	sdlaudio	*audio;
+	audio=(sdlaudio*)userdata;
+	audio->read(stream, len);
+}
+
+audiodevice * OpenSDLAudioDevice() {
+	return new sdlaudio();
+}

+ 86 - 0
sdlfreeaudio.mod/sdlfreeaudio.bmx

@@ -0,0 +1,86 @@
+' Copyright (c) 2014 Bruce A Henderson
+'
+' This software is provided 'as-is', without any express or implied
+' warranty. In no event will the authors be held liable for any damages
+' arising from the use of this software.
+'
+' Permission is granted to anyone to use this software for any purpose,
+' including commercial applications, and to alter it and redistribute it
+' freely, subject to the following restrictions:
+'
+'    1. The origin of this software must not be misrepresented; you must not
+'    claim that you wrote the original software. If you use this software
+'    in a product, an acknowledgment in the product documentation would be
+'    appreciated but is not required.
+'
+'    2. Altered source versions must be plainly marked as such, and must not be
+'    misrepresented as being the original software.
+'
+'    3. This notice may not be removed or altered from any source
+'    distribution.
+'
+Strict
+
+Rem
+bbdoc: SDL FreeAudio Driver
+End Rem
+Module SDL.SDLFreeAudio
+
+Import SDL.SDL
+Import BRL.FreeAudioAudio
+
+?win32x86
+Import "../../sdl.mod/sdl.mod/include/win32x86/*.h"
+
+?win32x64
+Import "../../sdl.mod/sdl.mod/include/win32x64/*.h"
+
+?macos
+Import "../../sdl.mod/sdl.mod/include/macos/*.h"
+
+?linuxx86
+Import "../../sdl.mod/sdl.mod/include/linuxx86/*.h"
+
+?linuxx64
+Import "../../sdl.mod/sdl.mod/include/linuxx64/*.h"
+
+?raspberrypi
+Import "../../sdl.mod/sdl.mod/include/raspberrypi/*.h"
+
+?android
+Import "../../sdl.mod/sdl.mod/SDL/include/*.h"
+?
+
+?Not android
+Import "../../sdl.mod/sdl.mod/include/*.h"
+?
+
+Import "glue.cpp"
+
+
+Type TSDLFreeAudioDriver Extends TFreeAudioAudioDriver
+
+	Method Startup()
+		Local device:Byte Ptr = OpenSDLAudioDevice()
+		Local res:Int=-1
+		If device Then
+			res=fa_Reset(device)
+		End If
+		Return res <> -1
+	End Method
+
+	Function Create:TFreeAudioAudioDriver( name$,Mode )
+		Local t:TSDLFreeAudioDriver = New TSDLFreeAudioDriver
+		t._name=name
+		t._mode=Mode
+		Return t
+	End Function
+
+End Type
+
+Extern
+Function OpenSDLAudioDevice:Byte Ptr()
+End Extern
+
+TSDLFreeAudioDriver.Create "FreeAudio SDL", 8
+