codec.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2016 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <array>
  6. #include <vector>
  7. #include "common/common_types.h"
  8. namespace Codec {
  9. /// A variable length buffer of signed PCM16 stereo samples.
  10. using StereoBuffer16 = std::vector<std::array<s16, 2>>;
  11. /// See: Codec::DecodeADPCM
  12. struct ADPCMState {
  13. // Two historical samples from previous processed buffer,
  14. // required for ADPCM decoding
  15. s16 yn1; ///< y[n-1]
  16. s16 yn2; ///< y[n-2]
  17. };
  18. /**
  19. * @param data Pointer to buffer that contains ADPCM data to decode
  20. * @param sample_count Length of buffer in terms of number of samples
  21. * @param adpcm_coeff ADPCM coefficients
  22. * @param state ADPCM state, this is updated with new state
  23. * @return Decoded stereo signed PCM16 data, sample_count in length
  24. */
  25. StereoBuffer16 DecodeADPCM(const u8* const data, const size_t sample_count, const std::array<s16, 16>& adpcm_coeff, ADPCMState& state);
  26. /**
  27. * @param num_channels Number of channels
  28. * @param data Pointer to buffer that contains PCM8 data to decode
  29. * @param sample_count Length of buffer in terms of number of samples
  30. * @return Decoded stereo signed PCM16 data, sample_count in length
  31. */
  32. StereoBuffer16 DecodePCM8(const unsigned num_channels, const u8* const data, const size_t sample_count);
  33. /**
  34. * @param num_channels Number of channels
  35. * @param data Pointer to buffer that contains PCM16 data to decode
  36. * @param sample_count Length of buffer in terms of number of samples
  37. * @return Decoded stereo signed PCM16 data, sample_count in length
  38. */
  39. StereoBuffer16 DecodePCM16(const unsigned num_channels, const u8* const data, const size_t sample_count);
  40. };