简体   繁体   English

如何使用 ADPCM 微芯片

[英]how use ADPCM microchips

I have some problems with adpcm in.wav (sound)files.我对 adpcm in.wav(声音)文件有一些问题。 at first of this question, I should say that I didn't read all things about ADPCM, just wanted to implement that fast and work on it... (just training code) I implemented it from MicroChip's pdf guid adpcm .(it's better to say copy/pasted and edited,created class)首先,我应该说我没有阅读有关 ADPCM 的所有内容,只是想快速实现并继续工作......(只是培训代码)我从MicroChip 的 pdf guid adpcm实现它。(更好说复制/粘贴和编辑,创建类)

Test code:测试代码:

    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, 126, 127, 127, 127, 126, 126, 125,
    124, 123, 121, 119, 117, 115, 112, 110, 107, 104, 101, 98,  94,  91,  87,
    83,  79,  75,  71,  67,  64,  60,  56,  52,  48,  44,  40,  36,  33,  29,
    26,  23,  20,  17,  15,  12,  10,  8,   6,   4,   3,   2,   1,   1,   0,
    0,   0,   1,   1,   2,   3,   4,   6,   8,   10,  12,  15,  17,  20,  23,
    26,  29,  33,  36,  40,  44,  48,  52,  56,  60,  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++;
  }
}

I'm sure that my class and encode/decode is right,just after decode I should do somethings to show correct numbers(but I donw know which casting is failed) .我确定我的 class 和编码/解码是正确的,就在解码后我应该做一些事情来显示正确的数字(但我不知道哪个转换失败)

why I'm sure?为什么我确定? because when I see my output in QDebug, every other sample(after decode) are correct (with few errors, in big datas errors will be smaller than now), but anothers are failed因为当我在 QDebug 中看到我的 output 时,其他所有样本(解码后)都是正确的(错误很少,在大数据中错误会比现在小),但其他样本都失败了

my output:我的 output:

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

data are 8bits in device设备中的数据为 8 位

Ok, I found my answer好的,我找到了答案

when you have error on any number, your error is in lower bits, so my predict was on two numbers that was anded to gether , then that number is in lower bits position have much errors!当你对任何数字有错误时,你的错误在低位,所以我的预测是在两个数字上,它们是与 gether 相乘的,那么这个数字在低位 position 有很多错误!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM