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). Then I'm trying to play it through QAudioOutput. One channel became louder, but still there is still sound in both channels. Playing file through mediaplayer gives same effect. 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);