2016-08-12 1 views
-1

Windows 7 데스크톱과 랩톱에서 Qt 5.5.1을 사용합니다.QAudioOutput을 통해 wav 파일을 재생하는 중에 윙윙 거리는 소리 만

나는 윙윙 거리는 소리 만들을 수 있습니다. 안내해주십시오. WAV 파일에

링크, 나는 시도 - https://www.dropbox.com/s/frfy43d8hznptgf/c.wav?dl=0

나는 또한 mp3 파일로이 작업을 시도했습니다. 내가 듣기로는 윙윙 거리는 소리가 들려요.

재현 할 예 :

#include <QCoreApplication> 
#include <QAudioOutput> 
#include <QFile> 
#include <QDebug> 

int main(int argc, char *argv[]) 
{ 
    QCoreApplication a(argc, argv); 

    QAudioOutput* audioOutpu; 

    QFile sourceFile; 
    sourceFile.setFileName("c.wav"); 
    bool p = sourceFile.open(QIODevice::ReadOnly); 
    if (p == false) 
     qDebug() << "no file"; 
    else 
     qDebug() << "yes file"; 


    QAudioDeviceInfo d1; 
    QList<QAudioDeviceInfo> l1 = d1.availableDevices(QAudio::AudioOutput); 

    qDebug() << "======================================================"; 
    qDebug() << l1.first().supportedCodecs(); 
    qDebug() << l1.first().supportedChannelCounts(); 
    qDebug() << l1.first().supportedSampleTypes(); 
    qDebug() << l1.first().supportedSampleRates(); 
    qDebug() << l1.first().supportedSampleSizes(); 

    QAudioFormat desiredFormat1; 
    desiredFormat1.setChannelCount(2); 
    desiredFormat1.setByteOrder(QAudioFormat::LittleEndian); 
    desiredFormat1.setCodec("audio/pcm"); 
    desiredFormat1.setSampleType(QAudioFormat::SignedInt); 
    desiredFormat1.setSampleRate(44100); 
    desiredFormat1.setSampleSize(16); 

    QAudioDeviceInfo info1(QAudioDeviceInfo::defaultOutputDevice()); 
    if (!info1.isFormatSupported(desiredFormat1)) 
    { 
      qWarning() << "Default format not supported, trying to use the nearest."; 
      desiredFormat1 = info1.preferredFormat(); 
    } 

    audioOutpu = new QAudioOutput(desiredFormat1); 
    audioOutpu->setVolume(1.0); 

    audioOutpu->start(&sourceFile); 
    qDebug() << "bbbbbbbbbb"; 
    QEventLoop loop; 
    QObject::connect(audioOutpu, SIGNAL(stateChanged(QAudio::State)), &loop, SLOT(quit())); 
    do { 
     loop.exec(); 
    } while(audioOutpu->state() == QAudio::ActiveState); 

    return a.exec(); 
} 

출력 :

enter image description here

+1

wav 파일에 대한 링크가 좋을 것입니다. –

+0

어떻게 그럴 수 있습니까? @ Jean-FrançoisFabre –

+0

나는 dropbox와 같은 외부 링크에 연결해야만한다고 인정한다. –

답변

4

귀하의 wav 파일이 여기 정말 WAVE format가 없습니다 파일과 연관된 MediaInfo 출력 :

Format         : MPEG Audio 
File size        : 4.67 MiB 
Duration         : 5mn 6s 
Overall bit rate mode     : Constant 
Overall bit rate       : 128 Kbps 
Track name        : Careless Whisper 
Performer        : Kenny G 
Genre         : Instrumental 

Audio 
Format         : MPEG Audio 
Format version       : Version 1 
Format profile       : Layer 3 
Mode          : Joint stereo 
Mode extension       : MS Stereo 
Duration         : 5mn 6s 
Bit rate mode       : Constant 
Bit rate         : 128 Kbps 
Channel(s)        : 2 channels 
Sampling rate       : 44.1 KHz 
Compression mode       : Lossy 
Stream size        : 4.67 MiB (100%) 

MPEG 오디오 압축 파일이므로 "audio/pcm" 코덱을 사용하여 재생할 수 없으며 오디오 파일을 PCM으로 압축 해제하여 코드에서 올바르게 재생할 수 있습니다. 여기 Mediainfo를 내 파일로 출력하는 것입니다 :

Format         : Wave 
File size        : 51.6 MiB 
Duration         : 5mn 6s 
Overall bit rate mode     : Constant 
Overall bit rate       : 1 411 Kbps 

Audio 
Format         : PCM 
Format settings, Endianness    : Little 
Format settings, Sign     : Signed 
Codec ID         : 1 
Duration         : 5mn 6s 
Bit rate mode       : Constant 
Bit rate         : 1 411.2 Kbps 
Channel(s)        : 2 channels 
Sampling rate       : 44.1 KHz 
Bit depth        : 16 bits 
Stream size        : 51.6 MiB (100%) 

당신이보고 here을 가지고 QMediaPlayer 사용을 고려, 압축 오디오 포맷을 재생해야합니다.

+0

감사합니다. 나는이 프로그램에서도 flac을 할 수 없었다. 그걸 좀 밝힐 수 있니? –

+0

[FLAC Audio] (https : //en.wikipedia.org/wiki/FLAC)은 오디오의 무손실 ** 압축 **을위한 또 다른 코덱이므로 압축되지 않은 PCM 오디오를 재생할 때 사용할 수있는 것을 사용하여 FLAC의 압축을 풀고 재생할 수 없습니다. 다시'QMediaPlayer' 사용을 고려하십시오. – Mike

+0

다시 감사드립니다. 나는 또한 usb 프레임 그래버에서 오디오를 수신하고 그것을 연주하고자합니다. 그게 뭘 제안하니? –

관련 문제