2020-07-07 16:35:34 +02:00
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/)
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
|
|
|
|
namespace skyline::audio {
|
|
|
|
/**
|
2020-09-28 12:05:17 +02:00
|
|
|
* @brief The AdpcmDecoder class handles decoding single channel ADPCM (Adaptive Differential Pulse-Code Modulation) data
|
2020-07-07 16:35:34 +02:00
|
|
|
*/
|
|
|
|
class AdpcmDecoder {
|
|
|
|
private:
|
|
|
|
union FrameHeader {
|
2020-08-21 15:28:47 +02:00
|
|
|
u8 raw;
|
|
|
|
|
2020-07-07 16:35:34 +02:00
|
|
|
struct {
|
|
|
|
u8 scale : 4; //!< The scale factor for this frame
|
2020-08-21 15:28:47 +02:00
|
|
|
u8 coefficientIndex : 3;
|
2020-11-08 20:54:15 +01:00
|
|
|
u8 _pad_ : 1;
|
2020-07-07 16:35:34 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
static_assert(sizeof(FrameHeader) == 0x1);
|
|
|
|
|
2020-09-28 12:05:17 +02:00
|
|
|
std::array<i32, 2> history{}; //!< The previous samples for decoding the ADPCM stream
|
|
|
|
std::vector<std::array<i16, 2>> coefficients; //!< The coefficients for decoding the ADPCM stream
|
2020-07-07 16:35:34 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
AdpcmDecoder(const std::vector<std::array<i16, 2>> &coefficients);
|
|
|
|
|
|
|
|
/**
|
2020-09-28 12:05:17 +02:00
|
|
|
* @brief Decodes a buffer of ADPCM data into I16 PCM
|
2020-07-07 16:35:34 +02:00
|
|
|
*/
|
2020-09-25 02:05:12 +02:00
|
|
|
std::vector<i16> Decode(span<u8> adpcmData);
|
2020-07-07 16:35:34 +02:00
|
|
|
};
|
|
|
|
}
|