summaryrefslogtreecommitdiffstats
path: root/src/audio_core/codec.h
blob: ef2ce01a8c9e111c835dd4ffe28b3ef3b41258d7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright 2018 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#pragma once

#include <array>
#include <vector>

#include "common/common_types.h"

namespace AudioCore::Codec {

enum class PcmFormat : u32 {
    Invalid = 0,
    Int8 = 1,
    Int16 = 2,
    Int24 = 3,
    Int32 = 4,
    PcmFloat = 5,
    Adpcm = 6,
};

/// See: Codec::DecodeADPCM
struct ADPCMState {
    // Two historical samples from previous processed buffer,
    // required for ADPCM decoding
    s16 yn1; ///< y[n-1]
    s16 yn2; ///< y[n-2]
};

using ADPCM_Coeff = std::array<s16, 16>;

/**
 * @param data Pointer to buffer that contains ADPCM data to decode
 * @param size Size of buffer in bytes
 * @param coeff ADPCM coefficients
 * @param state ADPCM state, this is updated with new state
 * @return Decoded stereo signed PCM16 data, sample_count in length
 */
std::vector<s16> DecodeADPCM(const u8* const data, std::size_t size, const ADPCM_Coeff& coeff,
                             ADPCMState& state);

}; // namespace AudioCore::Codec