Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Multichannel Audio Output using QAudioOutput
Forum Updated to NodeBB v4.3 + New Features

Multichannel Audio Output using QAudioOutput

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 2.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mccurrab
    wrote on 13 May 2012, 20:13 last edited by
    #1

    So some quick background, I am trying to make a surround sound environment in which the user has a lot of control over which sounds are played where. These sounds are coming exclusively from .aiff files (don't ask why) which means that I pretty much just have the raw samples (16 bit Big Endian Samples). I am trying to use my sound card (which has multiple outputs) to do this, however I'm having some issues. I tried to simply make a 441Hz wave to play out of each speaker, but I don't think I'm doing it right because all I'm getting is garbage sound.

    I know there are a few things I'm doing wrong, so could someone try to give me some advice?

    (this is a small test program i am writing to test it so that i don't have to go through all my other code [basically a proof of concept])

    @#include "mainwindow.h"

    mainWindow::mainWindow(QWidget *parent) :
    QMainWindow(parent)
    {
    this->resize(550,900);
    QWidget * central = new QWidget();
    this->setCentralWidget(central);
    out = new QLabel(central);
    out->resize(500,850);
    out->move(25,25);
    QString * outString = new QString();

    QList<QAudioDeviceInfo> avail = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput);
    for(int i=0; i< avail.length();i++)
    {
        QAudioDeviceInfo temp = avail.at(i);
        outString->append(temp.deviceName() + "\n");
        QList<int> count = temp.supportedChannelCounts();
        outString->append("channels:");
        for(int j=0; j<count.length();j++)
        {
            outString->append(QString::number(count.at(j))+" ");
        }
        outString->append("\n");
    
        QList<int> bits = temp.supportedSampleSizes();
        outString->append("bits:");
        for(int j=0; j<bits.length();j++)
        {
            outString->append(QString::number(bits.at(j))+" ");
        }
        outString->append("\n");
    
        QList<int> rates = temp.supportedSampleRates();
        outString->append("bitrates:");
        for(int j=0; j<rates.length();j++)
        {
            outString->append(QString::number(rates.at(j))+" ");
        }
        outString->append("\n");
    
        QList<QString> codecs = temp.supportedCodecs();
        outString->append("codecs:");
        for(int j=0; j<codecs.length();j++)
        {
            outString->append(codecs.at(j)+" ");
        }
        outString->append("\n");
    
        QList<QAudioFormat::SampleType> types = temp.supportedSampleTypes();
        outString->append("types:");
        for(int j=0; j<codecs.length();j++)
        {
            outString->append(QString::number(types.at(j))+" ");
        }
        outString->append("\n");
        outString->append("\n");
    }
    out->setText(*outString);
    
    QAudioOutput * toPlaywith;
    QAudioFormat format;
    
    format.setFrequency(44100);
    format.setChannelCount(4);
    format.setSampleSize(16);
    format.setCodec("audio/pcm");
    format.setByteOrder(QAudioFormat::LittleEndian);
    format.setSampleType(QAudioFormat::SignedInt);
    
    QAudioDeviceInfo info(avail.at(0));
     if (!info.isFormatSupported(format)) {
         qDebug()<<"raw audio format not supported by backend, cannot play audio.";
         return;
     }
    
     toPlaywith = new QAudioOutput(format, this);
    
     QBuffer * tempDev = new QBuffer();
     tempDev->open(QIODevice::ReadWrite);
     tempDev->seek(0);
     toPlaywith->start(tempDev);
     char* trans = new char[88200];
     for(int i=0;i<44100;i++)
     {
         uint16_t datapoint = cos((i*2*3.141592)/44100) * 0x7F;
         trans[2*i] = datapoint;
         trans[2*i+1] = datapoint/16;
         //trans[2] = datapoint;
         //trans[3] = datapoint/16;
         //trans[4] = datapoint;
         //trans[5] = datapoint/16;
         //trans[6] = datapoint;
         //trans[7] = datapoint/16;
     }
     int i=0;
     qint64 ActPos = tempDev->pos();
     tempDev->seek(tempDev->size());
     tempDev->write(trans,2);
     tempDev->seek(ActPos);
     while(i<20)
     {
    
         qint64 ActPos = tempDev->pos();
         tempDev->seek(tempDev->size());
         tempDev->write(trans,88200);
         tempDev->seek(ActPos);
         i++;
     }
    

    }
    @

    1 Reply Last reply
    0

    1/1

    13 May 2012, 20:13

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved