2014-01-21 73 views
1

我嘗試在Qt 5.2.0中使用Speex Accoustic回聲消除,但只刪除了一部分回聲,它仍然保留。
這是我的測試(未優化內存管理)。它會記錄語音,刪除回聲並在400ms後播放,並帶有非常小的回聲消除功能。

任何想法,我的代碼是錯的?
Speex AEC只刪除回聲的一部分

//************ 
// declared in MainWindows.h 
QAudioInput* m_audioInput; 
QAudioOutput* m_audioOutput; 
QIODevice*  m_ioIn; 
QIODevice*  m_ioOut; 
QList<QByteArray> m_listBA; 
//************ 

void MainWindow::InitSpeex() 
{ 
    int loc_samplingRate=16000; 
    int loc_frameSize=320; 
    m_echo_state = speex_echo_state_init(loc_frameSize, 10*loc_frameSize); 
    speex_echo_ctl(m_echo_state, SPEEX_ECHO_SET_SAMPLING_RATE, &loc_samplingRate); 
    m_preprocess = speex_preprocess_state_init(loc_frameSize, loc_samplingRate); 
} 

void MainWindow::DestroySpeex() 
{ 
    speex_echo_state_destroy(m_echo_state); 
    speex_preprocess_state_destroy(m_preprocess); 
    m_echo_state = NULL; 
    m_preprocess = NULL; 
} 

void MainWindow::Start() 
{ 
    QAudioFormat format; 
    // Set up the desired format, for example: 
    format.setSampleRate(SAMPLING_RATE); 
    format.setChannelCount(1); 
    format.setSampleSize(16); 
    format.setCodec("audio/pcm"); 
    format.setByteOrder(QAudioFormat::LittleEndian); 
    format.setSampleType(QAudioFormat::UnSignedInt); 

    QAudioDeviceInfo loc_infoInput = QAudioDeviceInfo::defaultInputDevice(); 
    if (!loc_infoInput.isFormatSupported(format)) { 
     qWarning() << "Default format not supported, trying to use the nearest."; 
     format = loc_infoInput.nearestFormat(format); 
    } 

    m_audioInput = new QAudioInput(format, this); 


    QAudioDeviceInfo loc_infoOutput(QAudioDeviceInfo::defaultOutputDevice()); 
    if (!loc_infoOutput.isFormatSupported(format)) { 
    qWarning() << "Raw audio format not supported by backend, cannot play audio."; 
    return; 
    } 

    m_audioOutput = new QAudioOutput(format, this); 

    m_ioIn = m_audioInput->start(); 
    m_ioOut = m_audioOutput->start(); 

    connect(m_ioIn, SIGNAL(readyRead()), this, SLOT(on_data_input())); 
} 

void MainWindow::on_data_input() 
{ 
    // push data on the list 
    m_listBA.push_back(m_ioIn->readAll()); 


    // il list is about 400ms of sample 
    if(m_listBA.size() > 20) 
    { 
     // send oldest sample to speex and play it 
     speex_echo_playback(m_echo_state, (spx_int16_t*)m_listBA[1].constData()); 
     m_ioOut->write(m_listBA.takeFirst()); 

     // get most recent sample, remove echo and repush it on the list to be played later 
     speex_echo_capture(m_echo_state, (spx_int16_t*)m_listBA[m_listBA.size()-1].data(), m_AECBufferOut); 
     loc_vad = speex_preprocess_run(m_preprocess, m_AECBufferOut); 
     m_listBA.takeLast(); 
     m_listBA.push_back(QByteArray((const char*)m_AECBufferOut, sizeof(m_AECBufferOut))); 
    } 
} 

回答

0

我不知道你想與m_listBA做什麼。顯然這是一個FIFO,但你沒有使用[0]。

此外,爲什麼要將原始輸入添加到列表中,以便稍後刪除它?

最後,m_AECBufferOut可能是一個指針。在這種情況下,sizeof(m_AECBufferOut)可能是4或8.這不是你有多少字節的輸出。

基本上,讓你的設置工作沒有回聲消除,並驗證它只是增加了延遲。只有這樣你才能嘗試使回聲消除工作。如果第一部分正常工作,則不需要在此處發佈。

+0

這個測試可以正常工作,沒有迴音消除,語音被記錄並在400ms後播放,以模擬LIFO的網絡延遲。
沒有問題的內存或指針大小,問題是回聲部分刪除,我們仍然可以聽取它。 – Pierre