DecoderGSM.hx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. //
  2. // WAV/AU Flash player with resampler
  3. //
  4. // Copyright (c) 2009, Anton Fedorov <datacompboy@call2ru.com>
  5. //
  6. /* This code is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 only, as
  8. * published by the Free Software Foundation.
  9. *
  10. * This code is distributed in the hope that it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  13. * version 2 for more details (a copy is included in the LICENSE file that
  14. * accompanied this code).
  15. */
  16. package fmt;
  17. import org.tritonus.lowlevel.gsm.GSMDecoder;
  18. class DecoderGSM extends fmt.Decoder {
  19. private var wavmode : Bool;
  20. private var decoder : GSMDecoder;
  21. private var temp : haxe.io.BytesData;
  22. public function new(bps : Int, ?bs : Int) {
  23. if (bps == 264 || (bps == 0 && bs==33)) { // Standarts mode, 264bit GSM -> 160 samples)
  24. wavmode = false;
  25. sampleSize = 33;
  26. sampleLength = 160;
  27. } else
  28. if (bps == 260 || (bps == 0 && bs==65)) { // WAV mode: 65 bytes per twin 32+33 packs
  29. wavmode = true;
  30. sampleSize = 65;
  31. temp = new haxe.io.BytesData();
  32. sampleLength = 320;
  33. } else
  34. throw "Unsupported BPS";
  35. decoder = new GSMDecoder();
  36. }
  37. public override function decode( InBuf : haxe.io.BytesData, InOff: Int, Chan: Int, OutBuf : Array<Float>, OutOff: Int) : Int {
  38. decoder.decode( InBuf, InOff, OutBuf, OutOff, wavmode );
  39. return wavmode ? 320 : 160;
  40. }
  41. }