Permalink
Browse files

Finish support for IMA ADPCM: move chunks=>samples conversion into sn…

…dDecoder.

Bump to 1.8.0 version.
  • Loading branch information...
1 parent 61ffde6 commit 4866f811445f4162064bc7e59bdbbf3dcbd16be0 @datacompboy committed Aug 14, 2011
View
@@ -7,7 +7,7 @@ WavPlayer -- flash player for asterisk
Format | Codecs
=====================================================================
.au G711u, G711a, PCM format, any samplerate/channels
- .wav G711u, G711a, PCM, GSM 6.10 (MS) formats, any samplerate/channels
+ .wav G711u, G711a, PCM, GSM 6.10 (MS), IMA ADPCM formats, any samplerate/channels
.wav49 just alias of .wav, can content any of wav codecs
.gsm raw GSM 6.10
.sln raw PCM 16bit-signed 8kHz
View
@@ -303,7 +303,7 @@ class WavPlayerGui_Full extends WavPlayerGui {
// Main user interface: play / stop buttons & ExternalInterface
class WavPlayer {
- static var Version = "1.8.0beta1";
+ static var Version = "1.8.0";
static var player : Player;
static var state : String = PlayerEvent.STOPPED;
static var handlers : List<JsEventHandler>;
View
@@ -17,11 +17,26 @@
package fmt;
// Generic sound-decoder interface.
-interface Decoder {
+interface IDecoder {
// Bytes size of one input chunk
var sampleSize : Int;
// Number of PCM samples in one input chunk
var sampleLength : Int;
// Decode one input chunk to PCM samples
function decode( InBuf : haxe.io.BytesData, InOff: Int, Chan: Int, OutBuf : Array<Float>, OutOff: Int ) : Int;
+ // Return output length based on count of input samples
+ function decodeLength(chunks: Int) : Int;
+}
+
+class Decoder implements IDecoder {
+ public var sampleSize : Int;
+ public var sampleLength : Int;
+ public function decode( InBuf : haxe.io.BytesData, InOff: Int, Chan: Int, OutBuf : Array<Float>, OutOff: Int ) : Int {
+ throw("Please specify in subclass");
+ return 0;
+ }
+ // Common standard decoder
+ public function decodeLength(chunks: Int) : Int {
+ return chunks*sampleLength;
+ }
}
View
@@ -19,9 +19,7 @@
// and beautiful code from sox, licensed under GPL
package fmt;
-class DecoderG711a implements fmt.Decoder {
- public var sampleSize : Int;
- public var sampleLength : Int;
+class DecoderG711a extends fmt.Decoder {
public var inverted : Bool;
static var aLaw : Array<Float>;
static var Inv : Array<Int>;
@@ -32,7 +30,7 @@ class DecoderG711a implements fmt.Decoder {
inverted = inv;
generate();
}
- public function decode( InBuf : haxe.io.BytesData, InOff: Int, Chan: Int, OutBuf : Array<Float>, OutOff : Int) : Int {
+ public override function decode( InBuf : haxe.io.BytesData, InOff: Int, Chan: Int, OutBuf : Array<Float>, OutOff : Int) : Int {
if (inverted) {
OutBuf[OutOff] = aLaw[Inv[InBuf[InOff]]];
} else {
View
@@ -19,9 +19,7 @@
// and beautiful code from sox, licensed under GPL
package fmt;
-class DecoderG711u implements fmt.Decoder {
- public var sampleSize : Int;
- public var sampleLength : Int;
+class DecoderG711u extends fmt.Decoder {
public var inverted : Bool;
static var ulaw : Array<Float> = [ ];
static var Inv : Array<Int> = [ ];
@@ -32,7 +30,7 @@ class DecoderG711u implements fmt.Decoder {
inverted = inv;
generate();
}
- public function decode( InBuf : haxe.io.BytesData, InOff: Int, Chan: Int, OutBuf : Array<Float>, OutOff: Int) : Int {
+ public override function decode( InBuf : haxe.io.BytesData, InOff: Int, Chan: Int, OutBuf : Array<Float>, OutOff: Int) : Int {
if (inverted) {
OutBuf[OutOff] = ulaw[Inv[InBuf[InOff]]];
} else {
View
@@ -17,10 +17,7 @@
package fmt;
import org.tritonus.lowlevel.gsm.GSMDecoder;
-
-class DecoderGSM implements fmt.Decoder {
- public var sampleSize : Int;
- public var sampleLength : Int;
+class DecoderGSM extends fmt.Decoder {
private var wavmode : Bool;
private var decoder : GSMDecoder;
private var temp : haxe.io.BytesData;
@@ -39,7 +36,7 @@ class DecoderGSM implements fmt.Decoder {
throw "Unsupported BPS";
decoder = new GSMDecoder();
}
- public function decode( InBuf : haxe.io.BytesData, InOff: Int, Chan: Int, OutBuf : Array<Float>, OutOff: Int) : Int {
+ public override function decode( InBuf : haxe.io.BytesData, InOff: Int, Chan: Int, OutBuf : Array<Float>, OutOff: Int) : Int {
decoder.decode( InBuf, InOff, OutBuf, OutOff, wavmode );
return wavmode ? 320 : 160;
}
View
@@ -22,6 +22,7 @@ class IMAADPCM {
var step : Int;
var proceed : Int;
var resync : Int;
+ var spb : Int;
static var ima_index_table : Array<Int> = [
-1, -1, -1, -1, 2, 4, 6, 8,
@@ -42,6 +43,7 @@ class IMAADPCM {
public function new(samples: Int) {
proceed = 0;
resync = Std.int((samples+7)/8);
+ spb = samples;
}
function calc(nibble: Int): Float {
@@ -65,6 +67,13 @@ class IMAADPCM {
return predictor / 32767.0;
}
+ public function decodeLength(chunks: Int): Int {
+ var f = Math.floor(chunks / resync);
+ var r = chunks % resync;
+ if (r>0) r = r*8 - 7;
+ return f*spb+r;
+ }
+
public function decode( InBuf : haxe.io.BytesData, Off: Int, OutBuf: Array<Float>, OutOff: Int) : Int {
if ((proceed++) % resync == 0) {
// Read initial pack
@@ -83,9 +92,7 @@ class IMAADPCM {
}
}
}
-class DecoderIMAADPCM implements fmt.Decoder {
- public var sampleSize : Int;
- public var sampleLength : Int;
+class DecoderIMAADPCM extends fmt.Decoder {
var channels : Array<IMAADPCM>;
public function new(bps : Int, chans: Int, ?align: Int, ?samplesPerBlock: Int) {
@@ -106,7 +113,11 @@ class DecoderIMAADPCM implements fmt.Decoder {
}
}
- public function decode( InBuf : haxe.io.BytesData, Off: Int, Chan: Int, OutBuf: Array<Float>, OutOff: Int) : Int {
+ public override function decodeLength(chunks: Int): Int {
+ return channels[0].decodeLength(chunks);
+ }
+
+ public override function decode( InBuf : haxe.io.BytesData, Off: Int, Chan: Int, OutBuf: Array<Float>, OutOff: Int) : Int {
return channels[Chan].decode(InBuf, Off, OutBuf, OutOff);
}
}
View
@@ -16,9 +16,7 @@
package fmt;
// PCM sound decoder. Supports any bitlength
-class DecoderPCM implements fmt.Decoder {
- public var sampleSize : Int;
- public var sampleLength : Int;
+class DecoderPCM extends fmt.Decoder {
var divisor : Int;
var shift : Int;
public function new(bps : Int, ?bs : Int) {
@@ -28,7 +26,7 @@ class DecoderPCM implements fmt.Decoder {
shift = 1 << bps;
sampleLength = 1;
}
- public function decode( InBuf : haxe.io.BytesData, Off: Int, Chan: Int, OutBuf: Array<Float>, OutOff: Int) : Int {
+ public override function decode( InBuf : haxe.io.BytesData, Off: Int, Chan: Int, OutBuf: Array<Float>, OutOff: Int) : Int {
var Sample: Int = 0;
switch (sampleSize) {
case 1: Sample = InBuf[Off];
View
@@ -87,7 +87,7 @@ class File implements IFile {
public function getEtaLength(): Null<Float> {
if (rate==0 || chunkSize==0 || dataSize==0) return null;
if (dataLen == null && dataSize > 0)
- dataLen = Math.floor(dataSize/chunkSize)*sndDecoder.sampleLength/rate;
+ dataLen = sndDecoder.decodeLength(Math.floor(dataSize/chunkSize))/rate;
return dataLen;
}
@@ -96,7 +96,9 @@ class File implements IFile {
if (rate == 0 || chunkSize == 0 || sndDecoder==null)
return 0.0;
else
- return Math.floor((bufsize-dataOff)/chunkSize)*sndDecoder.sampleLength / rate;
+ return (bufsize-dataOff > dataLen)
+ ? getEtaLength()
+ : sndDecoder.decodeLength(Math.floor((bufsize-dataOff)/chunkSize)) / rate;
}
// Read file header
View
Binary file not shown.
View
Binary file not shown.

0 comments on commit 4866f81

Please sign in to comment.