Audio decoder now takes a "sequence" offset to feed to the WMAPro decoder.
This commit is contained in:
parent
0050b3df83
commit
4675a1e17a
|
@ -22,7 +22,7 @@ extern "C" {
|
||||||
namespace xe {
|
namespace xe {
|
||||||
namespace apu {
|
namespace apu {
|
||||||
|
|
||||||
AudioDecoder::AudioDecoder() : offset_(0), codec_(nullptr), context_(nullptr),
|
AudioDecoder::AudioDecoder() : codec_(nullptr), context_(nullptr),
|
||||||
decoded_frame_(nullptr), packet_(nullptr) {}
|
decoded_frame_(nullptr), packet_(nullptr) {}
|
||||||
|
|
||||||
AudioDecoder::~AudioDecoder() {
|
AudioDecoder::~AudioDecoder() {
|
||||||
|
@ -100,7 +100,7 @@ int AudioDecoder::Initialize(int bits) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int AudioDecoder::PreparePacket(uint8_t* input, size_t size,
|
int AudioDecoder::PreparePacket(uint8_t* input, size_t seq_offset, size_t size,
|
||||||
int sample_rate, int channels) {
|
int sample_rate, int channels) {
|
||||||
if (size != XMAContextData::kBytesPerBlock) {
|
if (size != XMAContextData::kBytesPerBlock) {
|
||||||
// Invalid packet size!
|
// Invalid packet size!
|
||||||
|
@ -115,9 +115,8 @@ int AudioDecoder::PreparePacket(uint8_t* input, size_t size,
|
||||||
std::memcpy(packet_data_, input, size);
|
std::memcpy(packet_data_, input, size);
|
||||||
|
|
||||||
// Modify the packet header so it's WMAPro compatible
|
// Modify the packet header so it's WMAPro compatible
|
||||||
*((int *)packet_data_) = (((offset_ & 0x7800) | 0x400) >> 7) |
|
*((int *)packet_data_) = (((seq_offset & 0x7800) | 0x400) >> 7) |
|
||||||
(*((int*)packet_data_) & 0xFFFEFF08);
|
(*((int*)packet_data_) & 0xFFFEFF08);
|
||||||
offset_ += XMAContextData::kBytesPerBlock; // Sequence number
|
|
||||||
|
|
||||||
packet_->data = packet_data_;
|
packet_->data = packet_data_;
|
||||||
packet_->size = XMAContextData::kBytesPerBlock;
|
packet_->size = XMAContextData::kBytesPerBlock;
|
||||||
|
@ -201,10 +200,10 @@ int AudioDecoder::DecodePacket(uint8_t* output, size_t output_offset, size_t out
|
||||||
for (int i = 0; i < decoded_frame_->nb_samples; i++) {
|
for (int i = 0; i < decoded_frame_->nb_samples; i++) {
|
||||||
// Raw sample should be within [-1, 1]
|
// Raw sample should be within [-1, 1]
|
||||||
float fRawSample = sample_array[i];
|
float fRawSample = sample_array[i];
|
||||||
float fScaledSample = fRawSample * (1 << (bits_ - 1));
|
float fScaledSample = fRawSample * ((1 << bits_) - 1);
|
||||||
|
|
||||||
// Clamp the sample in range
|
// Clamp the sample in range
|
||||||
int64_t range = (1 << (bits_ - 1));
|
int64_t range = (1 << bits_) * 2;
|
||||||
if (fScaledSample > (range - 1)) {
|
if (fScaledSample > (range - 1)) {
|
||||||
fScaledSample = (float)range;
|
fScaledSample = (float)range;
|
||||||
} else if (fScaledSample < (-range + 1)) {
|
} else if (fScaledSample < (-range + 1)) {
|
||||||
|
|
|
@ -38,7 +38,8 @@ class AudioDecoder {
|
||||||
|
|
||||||
int Initialize(int bits);
|
int Initialize(int bits);
|
||||||
|
|
||||||
int PreparePacket(uint8_t* input, size_t size, int sample_rate, int channels);
|
int PreparePacket(uint8_t* input, size_t seq_offset, size_t size,
|
||||||
|
int sample_rate, int channels);
|
||||||
void DiscardPacket();
|
void DiscardPacket();
|
||||||
|
|
||||||
int DecodePacket(uint8_t* output, size_t offset, size_t size);
|
int DecodePacket(uint8_t* output, size_t offset, size_t size);
|
||||||
|
@ -54,7 +55,6 @@ class AudioDecoder {
|
||||||
size_t current_frame_pos_;
|
size_t current_frame_pos_;
|
||||||
uint8_t* current_frame_;
|
uint8_t* current_frame_;
|
||||||
uint32_t frame_samples_size_;
|
uint32_t frame_samples_size_;
|
||||||
int offset_;
|
|
||||||
|
|
||||||
uint8_t packet_data_[XMAContextData::kBytesPerBlock];
|
uint8_t packet_data_[XMAContextData::kBytesPerBlock];
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue