Speex语音解码脚麻 [英] speex decoding going wrong

查看:207
本文介绍了Speex语音解码脚麻的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的Speex为en code一些音频数据并发送了UDP和德code那么它的另一面。
我跑了Speex的几个测试,并注意到,如果我去code的数据包后,我直接连接codeD吧,去codeD数据是没有办法接近原始数据。大多数在缓冲器的起始字节的0。
所以,当我去code通过UDP发送音频,我得到的是噪音。
这是怎么了编码音频:

I'm using speex to encode some audio data and send it over UDP, and decode it on the other side. I ran a few tests with speex, and noticed that if I decode a packet straight after I encoded it, the decoded data is in no way close to the original data. Most of the bytes at the start of the buffer are 0. So when I decode the audio sent over UDP, all I get is noise. This is how I am encoding the audio:

bool AudioEncoder::encode( float *raw, char *encoded_bits )
{
    for ( size_t i = 0; i < 256; i++ )
        this->_rfdata[i] = raw[i];
    speex_bits_reset(&this->_bits);
    speex_encode(this->_state, this->_rfdata, &this->_bits);
    int bytesWritten = speex_bits_write(&this->_bits, encoded_bits, 512);
    if (bytesWritten)
        return true;
    return false;
}

这是怎么了解码音频:

float *f = new float[256];
// recvbuf is the buffer I pass to my recv function on the socket
speex_bits_read_from(&this->_bits, recvbuf, 512);
speex_decode(this->state, &this->_bits, f);

我已经检查出文档,大多数我的code都来自从Speex语音网站的例子编码/解码样本。
我不知道我在这里失踪。

I've check out the docs, and most of my code comes from the example encoding/decoding sample from the speex website. I'm not sure what I'm missing here.

推荐答案

我找到了EN codeD数据是如此不同的原因。有它的作为圣保罗Scardine所述有损玉米pression的事实,也即Speex的仅与160帧的工作原理,所以从portaudio获取数据时的Speex,它需要由160帧的包。

I found the reason the encoded data was so different. There is the fact it's a lossy compression as Paulo Scardine said, and also that speex only works with 160 frames, so when getting data from portaudio to speex, it needs to be by "packets" of 160 frames.

这篇关于Speex语音解码脚麻的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆