From 8088b01dd1f8d14d8110d2469e03b400e08c412c Mon Sep 17 00:00:00 2001 From: James Gray Date: Mon, 23 Feb 2015 22:51:02 -0600 Subject: [PATCH] console: fmod use `extern class` FFI --- lime/audio/AudioBuffer.hx | 3 ++ lime/audio/fmod/Channel.hx | 58 ++++++++--------------------------- lime/audio/fmod/Sound.hx | 62 ++++++++------------------------------ 3 files changed, 29 insertions(+), 94 deletions(-) diff --git a/lime/audio/AudioBuffer.hx b/lime/audio/AudioBuffer.hx index 0d448ee2d..543c1096c 100644 --- a/lime/audio/AudioBuffer.hx +++ b/lime/audio/AudioBuffer.hx @@ -61,6 +61,8 @@ class AudioBuffer { #if lime_console + trace ("not implemented"); +/* var sound:Sound = Sound.fromBytes (bytes); if (sound.valid) { @@ -74,6 +76,7 @@ class AudioBuffer { return audioBuffer; } +*/ #elseif (cpp || neko || nodejs) diff --git a/lime/audio/fmod/Channel.hx b/lime/audio/fmod/Channel.hx index 5a9a839e6..131c4a83e 100644 --- a/lime/audio/fmod/Channel.hx +++ b/lime/audio/fmod/Channel.hx @@ -2,66 +2,34 @@ package lime.audio.fmod; #if lime_console +import lime.ConsoleIncludePaths; import lime.system.System; import lime.utils.ByteArray; -abstract Channel(Int) { +@:include("ConsoleFmodAPI.h") +@:native("lime::hxapi::ConsoleFmodChannel") +extern class Channel { + // valid is true if this represents a valid handle to a channel. public var valid (get, never):Bool; - public static inline function fromHandle (handle:Int):Channel { - - #if lime_console - trace("not implemented"); - return cast (0, Channel); - #end - - } + // pause sets channel to a paused state. + public function pause ():Void; - public inline function pause ():Void { - - #if lime_console - lime_fmod_channel_pause (this); - #end - - } + // resume sets channel to an unpaused state. + public function resume ():Void; - public inline function resume ():Void { - - #if lime_console - lime_fmod_channel_resume (this); - #end - - } + // stop stops the channel from playing, making it available for another + // sound to use. + public function stop ():Void; - public inline function stop ():Void { - - #if lime_console - lime_fmod_channel_stop (this); - this = 0; - #end - - } - - - private inline function get_valid ():Bool { - - return this != 0; - - } - - - #if lime_console - private static var lime_fmod_channel_pause:Dynamic = System.load ("lime", "lime_fmod_channel_pause", 1); - private static var lime_fmod_channel_resume:Dynamic = System.load ("lime", "lime_fmod_channel_resume", 1); - private static var lime_fmod_channel_stop:Dynamic = System.load ("lime", "lime_fmod_channel_stop", 1); - #end + private function get_valid ():Bool; } diff --git a/lime/audio/fmod/Sound.hx b/lime/audio/fmod/Sound.hx index 2acbee38c..ff2dff4ba 100644 --- a/lime/audio/fmod/Sound.hx +++ b/lime/audio/fmod/Sound.hx @@ -2,70 +2,34 @@ package lime.audio.fmod; #if lime_console +import lime.ConsoleIncludePaths; import lime.system.System; import lime.utils.ByteArray; -abstract Sound(Int) { +@:include("ConsoleFmodAPI.h") +@:native("lime::hxapi::ConsoleFmodSound") +extern class Sound { + // valid returns true if this represents a valid handle to a sound. public var valid (get, never):Bool; - public static inline function fromBytes (bytes:ByteArray):Sound { - - // TODO(james4k): with FMOD_OPENMEMORY_POINT? We probably want to - // discourage this, or even not support it. Should avoid using haxe's - // heap when feasible. - - #if lime_console - trace("not implemented"); - return cast (0, Sound); - #end - - } + // fromFile creates a sound from the named file. + @:native("lime::ConsoleFmodSound::fromFile") + public static function fromFile (name:String):Sound; - public static inline function fromFile (name:String):Sound { - - #if lime_console - return lime_fmod_sound_create (name); - #end - - } + // play plays the sound and returns the channel it was assigned. + public function play ():Channel; - public inline function play ():Channel { - - #if lime_console - return lime_fmod_sound_play (this); - #end - - } + // release releases the sound. + public function release ():Void; - public inline function release ():Void { - - #if lime_console - lime_fmod_sound_release (this); - this = 0; - #end - - } - - - private inline function get_valid ():Bool { - - return this != 0; - - } - - - #if lime_console - private static var lime_fmod_sound_create:Dynamic = System.load ("lime", "lime_fmod_sound_create", 1); - private static var lime_fmod_sound_play:Dynamic = System.load ("lime", "lime_fmod_sound_play", 1); - private static var lime_fmod_sound_release:Dynamic = System.load ("lime", "lime_fmod_sound_release", 1); - #end + private function get_valid ():Bool; }