Decoder.hx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. // Generic sound-decoder interface.
  18. interface IDecoder {
  19. // Bytes size of one input chunk
  20. var sampleSize : Int;
  21. // Number of PCM samples in one input chunk
  22. var sampleLength : Int;
  23. // Seek decoder to required chunk
  24. // Returns initial seek position required for decoder to sync state
  25. public function seek ( chunk: Int ) : Int;
  26. // Decode one input chunk to PCM samples
  27. function decode( InBuf : haxe.io.BytesData, InOff: Int, Chan: Int, OutBuf : Array<Float>, OutOff: Int ) : Int;
  28. // Return output length based on count of input samples
  29. function decodeLength(chunks: Int) : Int;
  30. }
  31. class Decoder implements IDecoder {
  32. public var sampleSize : Int;
  33. public var sampleLength : Int;
  34. public function decode( InBuf : haxe.io.BytesData, InOff: Int, Chan: Int, OutBuf : Array<Float>, OutOff: Int ) : Int {
  35. throw("Please specify in subclass");
  36. return 0;
  37. }
  38. // Most of decoders have no problem with that
  39. public function seek ( chunk: Int ) : Int {
  40. return chunk;
  41. }
  42. // Common standard decoder
  43. public function decodeLength(chunks: Int) : Int {
  44. return chunks*sampleLength;
  45. }
  46. }