From 025cc48dfb2f0a2bbf9a628c98a57b2e4fc21b3a Mon Sep 17 00:00:00 2001 From: CawawaC Date: Tue, 19 Dec 2017 14:43:10 +0100 Subject: [PATCH] Filter setup --- lime/_backend/native/NativeCFFI.hx | 4 ++ lime/media/openal/AL.hx | 48 ++++++++++++++++ lime/media/openal/ALFilter.hx | 19 +++++++ project/src/media/openal/OpenALBindings.cpp | 63 +++++++++++++++++++-- 4 files changed, 129 insertions(+), 5 deletions(-) create mode 100644 lime/media/openal/ALFilter.hx diff --git a/lime/_backend/native/NativeCFFI.hx b/lime/_backend/native/NativeCFFI.hx index 9c18a2ab4..38019a6ad 100644 --- a/lime/_backend/native/NativeCFFI.hx +++ b/lime/_backend/native/NativeCFFI.hx @@ -279,6 +279,10 @@ class NativeCFFI { @:cffi private static function lime_alc_process_context (context:CFFIPointer):Void; @:cffi private static function lime_alc_resume_device (device:CFFIPointer):Void; @:cffi private static function lime_alc_suspend_context (context:CFFIPointer):Void; + + @:cffi private static function lime_al_gen_filter():CFFIPointer; + @:cffi private static function lime_al_filteri(filter:CFFIPointer, param:Int, value:Dynamic):Void; + @:cffi private static function lime_al_filterf(filter:CFFIPointer, param:Int, value:Float32):Void; #end #if (lime_cffi && !macro && lime_cairo) diff --git a/lime/media/openal/AL.hx b/lime/media/openal/AL.hx index c34319e0f..f655da77d 100644 --- a/lime/media/openal/AL.hx +++ b/lime/media/openal/AL.hx @@ -79,6 +79,32 @@ class AL { public static inline var EXPONENT_DISTANCE:Int = 0xD005; public static inline var EXPONENT_DISTANCE_CLAMPED:Int = 0xD006; + public static inline var DIRECT_FILTER:Int = 0x20005; + + /* Lowpass filter parameters */ + public static inline var LOWPASS_GAIN:Int = 0x0001; + public static inline var LOWPASS_GAINHF:Int = 0x0002; + + /* Highpass filter parameters */ + public static inline var HIGHPASS_GAIN:Int = 0x0001; + public static inline var HIGHPASS_GAINLF:Int = 0x0002; + + /* Bandpass filter parameters */ + public static inline var BANDPASS_GAIN:Int = 0x0001; + public static inline var BANDPASS_GAINLF:Int = 0x0002; + public static inline var BANDPASS_GAINHF:Int = 0x0003; + + /* Filter type */ + public static inline var FILTER_FIRST_PARAMETER:Int = 0x0000; + public static inline var FILTER_LAST_PARAMETER:Int = 0x8000; + public static inline var FILTER_TYPE:Int = 0x8001; + + /* Filter types, used with the AL_FILTER_TYPE property */ + public static inline var FILTER_NULL:Int = 0x0000; + public static inline var FILTER_LOWPASS:Int = 0x0001; + public static inline var FILTER_HIGHPASS:Int = 0x0002; + public static inline var FILTER_BANDPASS:Int = 0x0003; + public static function bufferData (buffer:ALBuffer, format:Int, data:ArrayBufferView, size:Int, freq:Int):Void { @@ -164,6 +190,15 @@ class AL { } + public static function createFilter():ALFilter { + #if (lime_cffi && lime_openal && !macro) + return NativeCFFI.lime_al_gen_filter (); + #else + return null; + #end + + } + public static function deleteBuffer (buffer:ALBuffer):Void { @@ -786,6 +821,19 @@ class AL { } + public static function filteri(filter:ALFilter, param:Int, value:Dynamic):Void { + #if (lime_cffi && lime_openal && !macro) + NativeCFFI.lime_al_filteri (filter, param, value); + #end + } + + public static function filterf (filter:ALFilter, param:Int, value:Float):Void { + + #if (lime_cffi && lime_openal && !macro) + NativeCFFI.lime_al_filterf (filter, param, value); + #end + + } public static function sourceiv (source:ALSource, param:Int, values:Array):Void { diff --git a/lime/media/openal/ALFilter.hx b/lime/media/openal/ALFilter.hx new file mode 100644 index 000000000..947bbb936 --- /dev/null +++ b/lime/media/openal/ALFilter.hx @@ -0,0 +1,19 @@ +package lime.media.openal; + + +import lime.system.CFFIPointer; + +@:allow(lime.media.openal.AL) + + +abstract ALFilter(CFFIPointer) from CFFIPointer to CFFIPointer { + + + private inline function new (handle:CFFIPointer) { + + this = handle; + + } + + +} \ No newline at end of file diff --git a/project/src/media/openal/OpenALBindings.cpp b/project/src/media/openal/OpenALBindings.cpp index 1cfbbd58d..9270eb4ee 100644 --- a/project/src/media/openal/OpenALBindings.cpp +++ b/project/src/media/openal/OpenALBindings.cpp @@ -24,7 +24,7 @@ namespace lime { void lime_al_delete_buffer (value buffer); void lime_al_delete_source (value source); - + void lime_al_delete_filter (value filter); void gc_al_buffer (value buffer) { @@ -38,6 +38,10 @@ namespace lime { lime_al_delete_source (source); } + + void gc_al_filter(value filter) { + lime_al_delete_filter(filter); + } void gc_alc_object (value object) { @@ -193,6 +197,19 @@ namespace lime { } } + + + void lime_al_delete_filter(value filter) { + + if (!val_is_null(filter)) { + + ALuint data = (ALuint)(uintptr_t)val_data(filter); + alDeleteFilters(1, &data); + val_gc(filter, 0); + + } + + } void lime_al_delete_source (value source) { @@ -230,6 +247,8 @@ namespace lime { } } + + void lime_al_disable (int capability) { @@ -265,6 +284,26 @@ namespace lime { alEnable (capability); } + + + void lime_al_filteri(value filter, int param, value val) { + + ALuint id = (ALuint)(uintptr_t)val_data(filter); + ALuint data; + + data = val_int(val); + + alFilteri(id, param, data); + + } + + + void lime_al_filterf(value filter, int param, float value) { + + ALuint id = (ALuint)(uintptr_t)val_data(filter); + alFilterf(id, param, value); + + } value lime_al_gen_buffer () { @@ -302,6 +341,15 @@ namespace lime { return result; } + + + value lime_al_gen_filter() { + + ALuint filter; + alGenFilters((ALuint)1, &filter); + return CFFIPointer((void*)(uintptr_t)filter, gc_al_filter); + + } value lime_al_gen_source () { @@ -1079,7 +1127,7 @@ namespace lime { ALuint id = (ALuint)(uintptr_t)val_data (source); ALuint data; - if (param == AL_BUFFER) { + if (param == AL_BUFFER || param == AL_DIRECT_FILTER) { data = (ALuint)(uintptr_t)val_data (val); @@ -1092,7 +1140,7 @@ namespace lime { alSourcei (id, param, data); } - + void lime_al_sourceiv (value source, int param, value values) { @@ -1307,6 +1355,8 @@ namespace lime { alcSuspendContext (alcContext); } + + DEFINE_PRIME5v (lime_al_buffer_data); @@ -1318,15 +1368,19 @@ namespace lime { DEFINE_PRIME3v (lime_al_bufferiv); DEFINE_PRIME1v (lime_al_delete_buffer); DEFINE_PRIME2v (lime_al_delete_buffers); + DEFINE_PRIME1v(lime_al_delete_filter); DEFINE_PRIME1v (lime_al_delete_source); DEFINE_PRIME2v (lime_al_delete_sources); DEFINE_PRIME1v (lime_al_disable); DEFINE_PRIME1v (lime_al_distance_model); DEFINE_PRIME1v (lime_al_doppler_factor); DEFINE_PRIME1v (lime_al_doppler_velocity); - DEFINE_PRIME1v (lime_al_enable); + DEFINE_PRIME1v (lime_al_enable); + DEFINE_PRIME3v (lime_al_filteri); + DEFINE_PRIME3v (lime_al_filterf); DEFINE_PRIME0 (lime_al_gen_buffer); DEFINE_PRIME1 (lime_al_gen_buffers); + DEFINE_PRIME0 (lime_al_gen_filter); DEFINE_PRIME0 (lime_al_gen_source); DEFINE_PRIME1 (lime_al_gen_sources); DEFINE_PRIME1 (lime_al_get_boolean); @@ -1401,7 +1455,6 @@ namespace lime { DEFINE_PRIME1v (lime_alc_resume_device); DEFINE_PRIME1v (lime_alc_suspend_context); - }