简体   繁体   English

在单通道中播放单声道WAV文件

[英]Playing mono wav-file in single channel

I have problem with playing sound through only one channel. 我只能通过一个声道播放声音有问题。 Currently I've read data from mono wav file, through libsndfile, and written it as stereo wav file alternating data with zeroes (so One channel must be pure silence). 目前,我已通过libsndfile从mono wav文件中读取数据,并将其写为立体声wav文件,数据交替为零(因此,一个通道必须是纯静默)。 Then I'm trying to play it through QAudioOutput. 然后,我尝试通过QAudioOutput播放它。 One channel became louder, but still there is still sound in both channels. 一个声道变大了,但是两个声道仍然有声音。 Playing file through mediaplayer gives same effect. 通过mediaplayer播放文件具有相同的效果。 Am I doing something wrong? 难道我做错了什么?

    SNDFILE *sf;
    SF_INFO info;
    int num_channels;
    int num, num_items;
    int f,sr,c;

    /* Open the WAV file. */
    info.format = 0;
    sf = sf_open("file.wav",SFM_READ,&info);
    f = info.frames;
    sr = info.samplerate;
    c = info.channels;
    num_items = f*c;
    QVector<int> buf;
    buf.resize(num_items);
    num = sf_read_int(sf,buf.data(),num_items);


    QVector<int> out;
    for(uint j = 0; j < buf.size(); j++)
    {
        out.push_back(buf[j]);
        out.push_back(0);
    }
    sf_close(sf);

    SF_INFO out_info = info;
    out_info.channels = 2;
    sf = sf_open("file2.wav",SFM_WRITE,&out_info);
    sf_write_int(sf,out.data(),num_items*2);
    sf_close(sf);

    QFile sourceFile;
    QAudioOutput* audio;
    sourceFile.setFileName("file2.wav");
    sourceFile.open(QIODevice::ReadOnly);

    QAudioFormat format;
    // Set up the format, eg.
    format.setSampleRate(out_info.samplerate);
    format.setChannelCount(out_info.channels);
    format.setSampleSize(8);
    format.setCodec("audio/pcm");
    format.setByteOrder(QAudioFormat::LittleEndian);
    format.setSampleType(QAudioFormat::UnSignedInt);

    QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
    audio = new QAudioOutput(format, 0);
    audio->start(&sourceFile);

Problem was in audio driver. 问题出在音频驱动程序中。 Creative CMSS 3D leads to sound leaking. Creative CMSS 3D导致声音泄漏。 So such wav file seems to be easier way to play sound in one channel. 因此,这样的wav文件似乎是一种在一个通道中播放声音的简便方法。

UPD: changed that method to BASS library, which allows to set output channel flag. UPD:将该方法更改为BASS库,该库允许设置输出通道标志。 Still it won't work if there is any 3d-simulating driver settings. 如果有任何3D模拟驱动程序设置,它仍然无法正常工作。

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

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