2015-09-10 10 views
5

私の目的は、生のフォーマット(サンプルのみ)、8kHz、16bit(リトルエンディアン)、1chのサウンドを録音したいのです。次に、それらのサンプルをウィンドウに転送し、QAudioOutputで再生したいと思います。 QAudioInputで音声を録音するプログラムと、いくつかのサンプルが含まれているファイルを提供するプログラムの2つのプログラムがあり、QAudioOutputで再生します。以下はQAudioInputとQAudioOutputを作成するための私のソースコードです。QAudioInputでlinuxに録音してWindowsで再生する

//Initialize audio 
void AudioBuffer::initializeAudio() 
{ 
    m_format.setFrequency(8000); //set frequency to 8000 
    m_format.setChannels(1); //set channels to mono 
    m_format.setSampleSize(16); //set sample sze to 16 bit 
    m_format.setSampleType(QAudioFormat::UnSignedInt); //Sample type as usigned integer sample 
    m_format.setByteOrder(QAudioFormat::LittleEndian); //Byte order 
    m_format.setCodec("audio/pcm"); //set codec as simple audio/pcm 

    QAudioDeviceInfo infoIn(QAudioDeviceInfo::defaultInputDevice()); 
    if (!infoIn.isFormatSupported(m_format)) 
    { 
     //Default format not supported - trying to use nearest 
     m_format = infoIn.nearestFormat(m_format); 
    } 

    QAudioDeviceInfo infoOut(QAudioDeviceInfo::defaultOutputDevice()); 

    if (!infoOut.isFormatSupported(m_format)) 
    { 
    //Default format not supported - trying to use nearest 
    m_format = infoOut.nearestFormat(m_format); 
    } 
    createAudioInput(); 
    createAudioOutput(); 
} 

void AudioBuffer::createAudioOutput() 
{ 
    m_audioOutput = new QAudioOutput(m_Outputdevice, m_format, this); 
} 

void AudioBuffer::createAudioInput() 
{ 
    if (m_input != 0) { 
    disconnect(m_input, 0, this, 0); 
    m_input = 0; 
    } 

    m_audioInput = new QAudioInput(m_Inputdevice, m_format, this); 

} 

これらのプログラムは、WindowsとLinuxでは別々に動作します。しかし、私はLinuxに音声を録音してWindowsで再生すると、騒音が大きくなります。

WindowsとLinuxでキャプチャされたサンプルが異なることがわかります。最初の画像はLinuxでキャプチャされたサウンドに関連し、2番目の画像はウィンドウで使用されます。 captured sound in Linux

のWindowsでキャプチャサウンド:Linuxでのサウンドキャプチャ

もう少し captured sound in Windows

の詳細については、WindowsとLinuxでの沈黙が異なることです。私は両方のプラットフォームでリトルエンディアンを設定していましたが、バイトのスワップを含む多くのことを試しました。

今、私はalsaの設定について疑問があります。設定がありませんか?

QAudioInputを使用せずに音声を直接録音する方が良いと思いますか?

+0

どちらの場合でも 'isFormatSupported'がtrueであることを確認できますか? – UmNyobe

+0

入力と出力の両方が真です! – Ari

+0

'nearestFormat'コードを計算し、代わりに' abort() 'を置いた両方の行を削除し、linuxに新しいファイルを記録し、ファイルをウィンドウに移動して再試行してください。変更が適用され、freshmeat_linux/Linux]のマシンから転送された新しくキャプチャされたファイルを再生している両方で新鮮なビルドを使用することを確認してください。 –

答えて

3

音声はUnSignedIntですが、サンプル値は負の値と正の値の両方を持ちます。キャプチャに問題があるようです。 QAudioFormat::UnSignedIntQAudioFormat::SignedIntに変更してください。

関連する問題