Explorar el Código

added emulator F32 support (prevent double resampling)

Nicolas Cannasse hace 8 años
padre
commit
52c4d029f8
Se han modificado 3 ficheros con 35 adiciones y 6 borrados
  1. 25 5
      hxd/snd/ALEmulator.hx
  2. 1 0
      hxd/snd/Data.hx
  3. 9 1
      hxd/snd/Driver.hx

+ 25 - 5
hxd/snd/ALEmulator.hx

@@ -18,6 +18,7 @@ private class ALChannel extends NativeChannel {
 		super(samples);
 	}
 
+	@:noDebug
 	override function onSample( out : haxe.io.Float32Array ) {
 		var pos = 0;
 		var count = out.length >> 1;
@@ -386,12 +387,11 @@ class ALEmulator {
 	public static function isBuffer(buffer : Buffer) : Bool {
 		return buffer != null;
 	}
+
+	@:noDebug
 	public static function bufferData(buffer : Buffer, format : Int, data : Bytes, size : Int, freq : Int) {
 		if( freq != NATIVE_FREQ )
 			throw "Unsupported frequency value: " + freq +" should be " + NATIVE_FREQ;
-		inline function sext8(v:Int) {
-			return (v & 0x80) == 0 ? v : v | 0xFFFFFF00;
-		}
 		inline function sext16(v:Int) {
 			return (v & 0x8000) == 0 ? v : v | 0xFFFF0000;
 		}
@@ -399,14 +399,14 @@ class ALEmulator {
 		case FORMAT_MONO8:
 			buffer.data = new haxe.ds.Vector(size*2);
 			for( i in 0...size ) {
-				var v = sext8(data.get(i)) / 0x80;
+				var v = data.get(i) / 0xFF;
 				buffer.data[i << 1] = v;
 				buffer.data[(i<<1) | 1] = v;
 			}
 		case FORMAT_STEREO8:
 			buffer.data = new haxe.ds.Vector(size);
 			for( i in 0...size ) {
-				var v = sext8(data.get(i)) / 0x80;
+				var v = data.get(i) / 0xFF;
 				buffer.data[i] = v;
 			}
 		case FORMAT_MONO16:
@@ -422,6 +422,20 @@ class ALEmulator {
 				var v = sext16(data.getUInt16(i << 1)) / 0x8000;
 				buffer.data[i] = v;
 			}
+		case FORMAT_MONOF32:
+			buffer.data = new haxe.ds.Vector(size >> 1);
+			for( i in 0...size >> 1 ) {
+				var f = data.getFloat(i << 2);
+				buffer.data[i << 1] = f;
+				buffer.data[(i<<1) | 1] = f;
+			}
+		case FORMAT_STEREOF32:
+			buffer.data = new haxe.ds.Vector(size >> 2);
+			#if flash
+			flash.Memory.select(data.getData());
+			#end
+			for( i in 0...size>>2 )
+				buffer.data[i] = #if flash flash.Memory.getFloat #else data.getFloat #end(i<<2);
 		default:
 			throw "Format not supported 0x" + StringTools.hex(format);
 		}
@@ -492,6 +506,12 @@ class ALEmulator {
 		throw "TODO";
 	}
 
+
+	// --- our own float32 extension
+
+	public static inline var FORMAT_MONOF32				= 0x1110;
+	public static inline var FORMAT_STEREOF32			= 0x1111;
+
 	// ------------------------------------------------------------------------
 	// Constants
 	// ------------------------------------------------------------------------

+ 1 - 0
hxd/snd/Data.hx

@@ -31,6 +31,7 @@ class Data {
 		decodeBuffer(out, outPos, sampleStart, sampleCount);
 	}
 
+	@:noDebug
 	public function resample( rate : Int, format : SampleFormat, channels : Int ) : Data {
 		if( sampleFormat == format && samplingRate == rate && this.channels == channels )
 			return this;

+ 9 - 1
hxd/snd/Driver.hx

@@ -444,9 +444,17 @@ class Driver {
 		case UI8:
 			alFormat = targetChannels == 1 ? AL.FORMAT_MONO8 : AL.FORMAT_STEREO8;
 			UI8;
-		case I16, F32:
+		case I16:
 			alFormat = targetChannels == 1 ? AL.FORMAT_MONO16 : AL.FORMAT_STEREO16;
 			I16;
+		case F32:
+			#if hl
+			alFormat = targetChannels == 1 ? AL.FORMAT_MONO16 : AL.FORMAT_STEREO16;
+			I16;
+			#else
+			alFormat = targetChannels == 1 ? AL.FORMAT_MONOF32 : AL.FORMAT_STEREOF32;
+			F32;
+			#end
 		}
 		if( targetChannels != dat.channels || targetFormat != dat.sampleFormat || targetRate != dat.samplingRate )
 			dat = dat.resample(targetRate, targetFormat, targetChannels);