如何解决如何使用 ADPCM 微芯片
我对 .wav(声音)文件中的 adpcm 有一些问题。 首先这个问题,我应该说我没有阅读所有关于 ADPCM 的东西,只是想快速实现并努力......(只是训练代码) 我从 MicroChip's pdf guid adpcm 实现它。(最好说复制/粘贴和编辑,创建类)
测试代码:
const std::vector<int8_t> data = {
64,67,71,75,79,83,87,91,94,98,101,104,107,110,112,115,117,119,121,123,124,125,126,127,64,60,56,52,48,44,40,36,33,29,26,23,20,17,15,12,10,8,6,4,3,2,1,64};
void function() {
std::vector<uint8_t> en;
std::vector<uint8_t> de;
{ // encode
wave::ADPCM adpcm;
// 32768
for (size_t i{0}; i < data.size() - 3; i += 4) {
int16_t first{static_cast<int16_t>(
~((static_cast<uint16_t>(data[i]) & 0xff) |
((static_cast<uint16_t>(data[i + 1]) << 8) & 0xff00)) +
1)};
int16_t second{static_cast<int16_t>(
~((static_cast<uint16_t>(data[i + 2]) & 0xff) |
((static_cast<uint16_t>(data[i + 3]) << 8) & 0xff00)) +
1)};
en.push_back(static_cast<uint8_t>((adpcm.ADPcmencoder(first) & 0x0f) |
(adpcm.ADPcmencoder(second) << 4)));
}
}
{ // decode
wave::ADPCM adpcm;
for (auto val : en) {
int16_t result = ~adpcm.ADPCMDecoder(val & 0xf) + 1;
int8_t temp0 = ((result)&0xff);
int8_t temp1 = ((result)&0xff00) >> 8;
de.push_back(temp0);
de.push_back(temp1);
result = ~adpcm.ADPCMDecoder(val >> 4) + 1;
temp0 = ((result)&0xff);
temp1 = (result & 0xff00) >> 8;
de.push_back(temp0);
de.push_back(temp1);
}
}
int i{0};
for (auto val : de) {
qDebug() << "real:" << data[i] << "decoded: " << val;
i++;
}
}
我确定我的类和编码/解码是正确的,在解码后我应该做一些事情来显示正确的数字(但我不知道哪个转换失败了)。
为什么我确定?因为当我在 QDebug 中看到我的输出时,所有其他样本(解码后)都是正确的(错误很少,在大数据中错误会比现在小),但其他样本失败
我的输出:
real: 26 decoded: 6
real: 29 decoded: 32
real: 33 decoded: 5
real: 36 decoded: 48
real: 40 decoded: 6
real: 44 decoded: 32
real: 48 decoded: 5
real: 52 decoded: 48
real: 56 decoded: 4
real: 60 decoded: 64
设备中的数据为 8 位
解决方法
好的,我找到了答案
当您在任何数字上出错时,您的错误都在低位! 所以我的预测是在两个数字上并在一起,然后那个数字在较低位的位置有很多错误!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。