1
0

avi_alaw_decoder.cpp 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #include "avi_alaw_decoder.h"
  2. static int16_t ALawDecompressTable[256] =
  3. {
  4. -5504, -5248, -6016, -5760, -4480, -4224, -4992, -4736,
  5. -7552, -7296, -8064, -7808, -6528, -6272, -7040, -6784,
  6. -2752, -2624, -3008, -2880, -2240, -2112, -2496, -2368,
  7. -3776, -3648, -4032, -3904, -3264, -3136, -3520, -3392,
  8. -22016,-20992,-24064,-23040,-17920,-16896,-19968,-18944,
  9. -30208,-29184,-32256,-31232,-26112,-25088,-28160,-27136,
  10. -11008,-10496,-12032,-11520,-8960, -8448, -9984, -9472,
  11. -15104,-14592,-16128,-15616,-13056,-12544,-14080,-13568,
  12. -344, -328, -376, -360, -280, -264, -312, -296,
  13. -472, -456, -504, -488, -408, -392, -440, -424,
  14. -88, -72, -120, -104, -24, -8, -56, -40,
  15. -216, -200, -248, -232, -152, -136, -184, -168,
  16. -1376, -1312, -1504, -1440, -1120, -1056, -1248, -1184,
  17. -1888, -1824, -2016, -1952, -1632, -1568, -1760, -1696,
  18. -688, -656, -752, -720, -560, -528, -624, -592,
  19. -944, -912, -1008, -976, -816, -784, -880, -848,
  20. 5504, 5248, 6016, 5760, 4480, 4224, 4992, 4736,
  21. 7552, 7296, 8064, 7808, 6528, 6272, 7040, 6784,
  22. 2752, 2624, 3008, 2880, 2240, 2112, 2496, 2368,
  23. 3776, 3648, 4032, 3904, 3264, 3136, 3520, 3392,
  24. 22016, 20992, 24064, 23040, 17920, 16896, 19968, 18944,
  25. 30208, 29184, 32256, 31232, 26112, 25088, 28160, 27136,
  26. 11008, 10496, 12032, 11520, 8960, 8448, 9984, 9472,
  27. 15104, 14592, 16128, 15616, 13056, 12544, 14080, 13568,
  28. 344, 328, 376, 360, 280, 264, 312, 296,
  29. 472, 456, 504, 488, 408, 392, 440, 424,
  30. 88, 72, 120, 104, 24, 8, 56, 40,
  31. 216, 200, 248, 232, 152, 136, 184, 168,
  32. 1376, 1312, 1504, 1440, 1120, 1056, 1248, 1184,
  33. 1888, 1824, 2016, 1952, 1632, 1568, 1760, 1696,
  34. 688, 656, 752, 720, 560, 528, 624, 592,
  35. 944, 912, 1008, 976, 816, 784, 880, 848
  36. };
  37. AVIALawDecoder::AVIALawDecoder(const nsavi::audio_format *waveformat) : waveformat(waveformat)
  38. {
  39. }
  40. int AVIALawDecoder::OutputFrameSize(size_t *frame_size)
  41. {
  42. *frame_size = waveformat->block_align; // TODO
  43. return AVI_SUCCESS;
  44. }
  45. int AVIALawDecoder::GetOutputProperties(unsigned int *sampleRate, unsigned int *channels, unsigned int *bitsPerSample, bool *isFloat)
  46. {
  47. if (waveformat)
  48. {
  49. *sampleRate = waveformat->sample_rate;
  50. *channels = waveformat->channels;
  51. *bitsPerSample = 16;
  52. *isFloat = false; // TODO
  53. return AVI_SUCCESS;
  54. }
  55. else
  56. {
  57. return AVI_FAILURE;
  58. }
  59. }
  60. int AVIALawDecoder::DecodeChunk(uint16_t type, void **inputBuffer, size_t *inputBufferBytes, void *outputBuffer, size_t *outputBufferBytes)
  61. {
  62. size_t num_samples = min(*inputBufferBytes, *outputBufferBytes / 2);
  63. const uint8_t *in = (const uint8_t *)*inputBuffer;
  64. int16_t *out = (int16_t *)outputBuffer;
  65. for (size_t i=0;i!=num_samples;i++)
  66. {
  67. out[i] = ALawDecompressTable[in[i]];
  68. }
  69. *outputBufferBytes = num_samples * 2;
  70. *inputBufferBytes -= num_samples;
  71. *inputBuffer = (uint8_t *)inputBuffer + num_samples;
  72. return AVI_SUCCESS;
  73. }
  74. void AVIALawDecoder::Close()
  75. {
  76. delete this;
  77. }
  78. #define CBCLASS AVIALawDecoder
  79. START_DISPATCH;
  80. CB(OUTPUT_FRAME_SIZE, OutputFrameSize)
  81. CB(GET_OUTPUT_PROPERTIES, GetOutputProperties)
  82. CB(DECODE_CHUNK, DecodeChunk)
  83. VCB(CLOSE, Close)
  84. END_DISPATCH;
  85. #undef CBCLASS