void S60AudioEncoderControl::setAudioSettings(const QAudioEncoderSettings &settings)
{
    QAudioFormat fmt = m_session->format();
    if (settings.encodingMode() == QtMultimediaKit::ConstantQualityEncoding) {
        fmt.setCodec(settings.codec());
        setQuality(settings.quality(), fmt);
        if (settings.sampleRate() > 0) {
            fmt.setFrequency(settings.sampleRate());
        }
        if (settings.channelCount() > 0)
            fmt.setChannels(settings.channelCount());
    }else {
        if (settings.sampleRate() == 8000) {
            fmt.setSampleType(QAudioFormat::UnSignedInt);
            fmt.setSampleSize(8);
        } else {
            fmt.setSampleType(QAudioFormat::SignedInt);
            fmt.setSampleSize(16);
        }
        fmt.setCodec(settings.codec());
        fmt.setFrequency(settings.sampleRate());
        fmt.setChannels(settings.channelCount());
    }
    m_session->setFormat(fmt);
    m_settings = settings;
}
void S60AudioEncoderControl::setQuality(QtMultimediaKit::EncodingQuality value, QAudioFormat &fmt)
{
    switch (value) {
    case QtMultimediaKit::VeryLowQuality:
    case QtMultimediaKit::LowQuality:
        // low, 8000Hz mono U8
        fmt.setSampleType(QAudioFormat::UnSignedInt);
        fmt.setSampleSize(8);
        fmt.setFrequency(8000);
        fmt.setChannels(1);
        break;
    case QtMultimediaKit::NormalQuality:
        // medium, 22050Hz mono S16
        fmt.setSampleType(QAudioFormat::SignedInt);
        fmt.setSampleSize(16);
        fmt.setFrequency(22050);
        fmt.setChannels(1);
        break;
    case QtMultimediaKit::HighQuality:
    case QtMultimediaKit::VeryHighQuality:
        // high, 44100Hz mono S16
        fmt.setSampleType(QAudioFormat::SignedInt);
        fmt.setSampleSize(16);
        fmt.setFrequency(44100);
        fmt.setChannels(2);
        break;
    default:
        break;
    }
}
Ejemplo n.º 3
0
FrequencyAnalyzer::FrequencyAnalyzer(QObject *parent) :
    QObject(parent),
    d_ptr(new FrequencyAnalyzerPrivate(this))
{
    Q_D(FrequencyAnalyzer);

    QAudioDeviceInfo info = QAudioDeviceInfo::defaultInputDevice();

    qDebug() << "device name: " << info.deviceName() << "\n"
             << "supported frequency:" << info.supportedFrequencies() << "\n"
             << "supported codecs" << info.supportedCodecs() << "\n"
             << "supported sample sizes" << info.supportedSampleSizes() << "\n"
             << "supported sample types" << info.supportedSampleTypes() << "\n";

    QAudioFormat format = info.preferredFormat();
    format.setCodec("audio/pcm");
    format.setByteOrder(QAudioFormat::LittleEndian);
    format.setSampleType(QAudioFormat::SignedInt);
    format.setSampleSize(32);
    //format.setFrequency(d->sampling = 11025);
    //format.setFrequency(d->sampling = 22050);
    format.setFrequency(d->sampling = info.supportedFrequencies().last());
    format.setChannelCount(1);

    if (!info.isFormatSupported(format)) {
        qWarning("Format is unsupported");
        return;
    }

    d->input = new QAudioInput(info, format, this);
    connect(d->input, SIGNAL(stateChanged(QAudio::State)), SLOT(_q_onStateChanged()));
}
Ejemplo n.º 4
0
void xmppClient::slotConnected()
{
    QXmppCall *call = qobject_cast<QXmppCall*>(sender());
    Q_ASSERT(call);

    qDebug() << "Call connected";
    QXmppRtpChannel *channel = call->audioChannel();

    // prepare audio format
    QAudioFormat format;
    format.setFrequency(channel->payloadType().clockrate());
    format.setChannels(channel->payloadType().channels());
    format.setSampleSize(16);
    format.setCodec("audio/pcm");
    format.setByteOrder(QAudioFormat::LittleEndian);
    format.setSampleType(QAudioFormat::SignedInt);

    // the size in bytes of the audio buffers to/from sound devices
    // 160 ms seems to be the minimum to work consistently on Linux/Mac/Windows
    const int bufferSize = (format.frequency() * format.channels() * (format.sampleSize() / 8) * 160) / 1000;

    // initialise audio output
    QAudioOutput *audioOutput = new QAudioOutput(format, this);
    audioOutput->setBufferSize(bufferSize);
    audioOutput->start(channel);

    // initialise audio input
    QAudioInput *audioInput = new QAudioInput(format, this);
    audioInput->setBufferSize(bufferSize);
    audioInput->start(channel);
}
Ejemplo n.º 5
0
QAudioFormat QAudioDeviceInfoInternal::preferredFormat() const
{
    QAudioFormat format;
    switch (m_mode) {
    case QAudio::AudioOutput:
        format.setFrequency(44100);
        format.setChannels(2);
        format.setSampleSize(16);
        format.setByteOrder(QAudioFormat::LittleEndian);
        format.setSampleType(QAudioFormat::SignedInt);
        format.setCodec(QLatin1String("audio/pcm"));
        break;

    case QAudio::AudioInput:
        format.setFrequency(8000);
        format.setChannels(1);
        format.setSampleSize(16);
        format.setByteOrder(QAudioFormat::LittleEndian);
        format.setSampleType(QAudioFormat::SignedInt);
        format.setCodec(QLatin1String("audio/pcm"));
        break;

    default:
        Q_ASSERT_X(false, Q_FUNC_INFO, "Invalid mode");
    }

    if (!isFormatSupported(format)) {
        format = QAudioFormat();
        format.setCodec(QLatin1String("audio/pcm"));
        if (m_capabilities.contains(format.codec())) {
            const Capabilities &codecCaps = m_capabilities[format.codec()];
            if (codecCaps.m_frequencies.size())
                format.setFrequency(codecCaps.m_frequencies[0]);
            if (codecCaps.m_channels.size())
                format.setChannels(codecCaps.m_channels[0]);
            if (codecCaps.m_sampleSizes.size())
                format.setSampleSize(codecCaps.m_sampleSizes[0]);
            if (codecCaps.m_byteOrders.size())
                format.setByteOrder(codecCaps.m_byteOrders[0]);
            if (codecCaps.m_sampleTypes.size())
                format.setSampleType(codecCaps.m_sampleTypes[0]);
        }
    }

    return format;
}
Ejemplo n.º 6
0
QAudioFormat QAudioDeviceInfoInternal::preferredFormat() const
{
    QAudioFormat nearest;
    if(mode == QAudio::AudioOutput) {
        nearest.setFrequency(44100);
        nearest.setChannels(2);
        nearest.setByteOrder(QAudioFormat::LittleEndian);
        nearest.setSampleType(QAudioFormat::SignedInt);
        nearest.setSampleSize(16);
        nearest.setCodec(QLatin1String("audio/pcm"));
    } else {
        nearest.setFrequency(11025);
        nearest.setChannels(1);
        nearest.setSampleType(QAudioFormat::SignedInt);
        nearest.setSampleSize(8);
        nearest.setCodec(QLatin1String("audio/pcm"));
    }
    return nearest;
}
Ejemplo n.º 7
0
 explicit DeviceAudioOutput(int sampleRate) :
     AudioOutput(sampleRate) {
     format.setChannels(2);
     format.setFrequency(sampleRate);
     format.setSampleSize(16);
     format.setCodec("audio/pcm");
     format.setSampleType(QAudioFormat::SignedInt);
     out = new QAudioOutput(format);
     device = 0;
     memset(buffer, 0, sizeof(char) * kUnitBufferLength);
 }
Ejemplo n.º 8
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow), m_timer(), m_totalNeededTime(0,0), m_spentTime(0,0), m_belowAlarmTime(false), m_belowEndTime(false),
    m_dbusInterface(0), m_alarmTime(60), m_useLED(true), m_useSounds(true)
{
    ui->setupUi(this);

    m_topics.push_back(new AgendaTopic("topic #1", QTime(0,5)));
    m_topics.push_back(new AgendaTopic("topic #2", QTime(0,15)));

    calculateTotalTimes();

    m_currentTopic = 1;

    mainWindowSetup();
    setupMenus();

    connect(ui->next, SIGNAL(clicked()), this, SLOT(switchToNextTopic()));
    connect(ui->previous, SIGNAL(clicked()), this, SLOT(switchToPreviousTopic()));
    connect(ui->start, SIGNAL(clicked()), this, SLOT(startOrStop()));

    connect(ui->plus15, SIGNAL(clicked()), this, SLOT(add15m()));
    connect(ui->plus5, SIGNAL(clicked()), this, SLOT(add5m()));
    connect(ui->plus1, SIGNAL(clicked()), this, SLOT(add1m()));

    connect(ui->minus15, SIGNAL(clicked()), this, SLOT(minus15m()));
    connect(ui->minus5, SIGNAL(clicked()), this, SLOT(minus5m()));
    connect(ui->minus1, SIGNAL(clicked()), this, SLOT(minus1m()));

    connect(&m_timer, SIGNAL(timeout()), this, SLOT(timeElapsed()));

#ifdef IS_MAEMO
    m_dbusInterface = new QDBusInterface(MCE_SERVICE, MCE_REQUEST_PATH, MCE_REQUEST_IF, QDBusConnection::systemBus(), this);
    QDBusMessage reply = m_dbusInterface->call(MCE_ENABLE_LED);
    if (reply.type() == QDBusMessage::ErrorMessage)
        qDebug() << reply.errorMessage();
#endif

    // set up the output audio

    QAudioFormat format;
    // Set up the format, eg.
    format.setFrequency(44100);
    format.setChannels(1);
    format.setSampleSize(16);
    format.setCodec("audio/pcm");
    format.setByteOrder(QAudioFormat::LittleEndian);
    format.setSampleType(QAudioFormat::SignedInt);

    QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());

    m_audioOut = new QAudioOutput(format);
    // connect(m_audioOut,SIGNAL(stateChanged(QAudio::State)),SLOT(finishedPlaying(QAudio::State)));
}
Ejemplo n.º 9
0
QAudioOutput *
MainWindow::createAudioOutput()
{
   QAudioFormat settings;

    settings.setFrequency(44100);
    settings.setChannels(1);
    settings.setSampleSize(16);
    settings.setCodec("audio/pcm");
    settings.setByteOrder(QAudioFormat::LittleEndian);
    settings.setSampleType(QAudioFormat::SignedInt);

    m_audioOutput = new QAudioOutput(settings);
    return m_audioOutput;
}
Ejemplo n.º 10
0
void S60AudioEncoderControl::setEncodingOption(
        const QString &codec, const QString &name, const QVariant &value)
{
    TRACE("S60AudioEncoderControl::setEncodingOption" << qtThisPtr()
          << "codec" << codec << "name" << name << "value" << value);
    if (codec == "PCM") {
        QAudioFormat fmt = m_session->format();
        if(qstrcmp(name.toLocal8Bit().constData(), "quality") == 0)
            setQuality((QtMultimediaKit::EncodingQuality)value.toInt(), fmt);
        else if(qstrcmp(name.toLocal8Bit().constData(), "channels") == 0)
            fmt.setChannels(value.toInt());
        else if(qstrcmp(name.toLocal8Bit().constData(), "samplerate") == 0)
            fmt.setFrequency(value.toInt());
        m_session->setFormat(fmt);
    }
}
void S60AudioEncoderControl::setEncodingOption(
        const QString &codec, const QString &name, const QVariant &value)
{
    if (codec == "PCM") {        
        QAudioFormat fmt = m_session->format();

        if(qstrcmp(name.toLocal8Bit().constData(), "quality") == 0) {
            setQuality((QtMultimediaKit::EncodingQuality)value.toInt(), fmt);
        } else if(qstrcmp(name.toLocal8Bit().constData(), "channels") == 0) {
            fmt.setChannels(value.toInt());
        } else if(qstrcmp(name.toLocal8Bit().constData(), "samplerate") == 0) {
            fmt.setFrequency(value.toInt());
        }
        m_session->setFormat(fmt);
    }
}
S60AudioEncoderControl::S60AudioEncoderControl(QObject *session, QObject *parent)
    :QAudioEncoderControl(parent), m_quality(QtMultimediaKit::NormalQuality)
{   
    m_session = qobject_cast<S60AudioCaptureSession*>(session);
    QAudioFormat fmt = m_session->format();
    // medium, 22050Hz mono S16
    fmt.setSampleType(QAudioFormat::SignedInt);
    if (fmt.codec().compare("PCM", Qt::CaseInsensitive) == 0) {
        fmt.setSampleSize(16);
        fmt.setFrequency(22050);
    }
    fmt.setChannels(1);
    m_session->setFormat(fmt);
    m_settings.setChannelCount(fmt.channels());
    m_settings.setCodec(fmt.codec());
    m_settings.setSampleRate(fmt.sampleRate());
}
Ejemplo n.º 13
0
void StreamOutputWidget::startButtonClicked()
{
    qDebug("void StreamOutputWidget::startButtonClicked()");

    //Get available output devices...
    QList<QAudioDeviceInfo>	myList = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput);

    if (m_audioOutput)
    {
        delete m_audioOutput;
        m_audioOutput = NULL;
    }
    for (int i =0; i < myList.size(); i++)
    {
        if (myList[i].deviceName() == m_ui.m_comboDeviceSelection->currentText())
        {
            //QAudioFormat
            QAudioFormat format;

            //Set up the format
            format.setFrequency(48000);
            format.setChannels(1);
            format.setSampleSize(16);
            format.setCodec("audio/pcm");
            format.setByteOrder(QAudioFormat::LittleEndian);
            format.setSampleType(QAudioFormat::SignedInt);
            m_audioOutput = new QAudioOutput(myList[i],format,this);
	    //m_audioOutput = new QAudioOutput(QAudioDeviceInfo::defaultOutputDevice(),format,this);

            //We have 10ms frames, this should be enough
            m_audioOutput->setNotifyInterval(5);

        }
    }

    if (m_audioOutput)
    {
        connect(m_audioOutput,SIGNAL(stateChanged(QAudio::State)),this,SLOT(audioStateChanged(QAudio::State)));
        connect(m_audioOutput,SIGNAL(notify()),this,SLOT(notify()));
        m_audioOutput->setBufferSize(1000000);
        m_IODevice = m_audioOutput->start();
        m_ui.m_controlTextEdit->append("Starting stream... \n");
        m_ui.m_startButton->setEnabled(false);
        m_ui.m_stopButton->setEnabled(true);
    }
}
Ejemplo n.º 14
0
bool AudioHelper::AudioInputIsOK()
{
    QAudioFormat format;
    format.setFrequency(22050);
    format.setChannels(1);
    format.setSampleSize(16);
    format.setCodec("audio/pcm");
    format.setByteOrder(QAudioFormat::LittleEndian);
    format.setSampleType(QAudioFormat::UnSignedInt);

    QAudioDeviceInfo info(QAudioDeviceInfo::defaultInputDevice());
    if (!info.isFormatSupported(format)) {
        AudioHelperDebug("no default input device");
        return false;
    }
    return true;
}
Ejemplo n.º 15
0
// Conversion
QAudioFormat toQAudioFormat(AudioStreamBasicDescription const& sf)
{
    QAudioFormat    audioFormat;

    audioFormat.setFrequency(sf.mSampleRate);
    audioFormat.setChannels(sf.mChannelsPerFrame);
    audioFormat.setSampleSize(sf.mBitsPerChannel);
    audioFormat.setCodec(QString::fromLatin1("audio/pcm"));
    audioFormat.setByteOrder((sf.mFormatFlags & kAudioFormatFlagIsBigEndian) != 0 ? QAudioFormat::BigEndian : QAudioFormat::LittleEndian);
    QAudioFormat::SampleType type = QAudioFormat::UnSignedInt;
    if ((sf.mFormatFlags & kAudioFormatFlagIsSignedInteger) != 0)
        type = QAudioFormat::SignedInt;
    else if ((sf.mFormatFlags & kAudioFormatFlagIsFloat) != 0)
        type = QAudioFormat::Float;
    audioFormat.setSampleType(type);

    return audioFormat;
}
Ejemplo n.º 16
0
int InitAudio(){
    QAudioFormat format;
    format.setFrequency(22050);
    format.setChannels(1);
    format.setSampleSize(16);
    format.setCodec("audio/pcm");
    format.setByteOrder(QAudioFormat::LittleEndian);
    format.setSampleType(QAudioFormat::SignedInt);

    QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());

    emuWindow->audioOut = new QAudioOutput(info, format, emuWindow);
    if(emuWindow->audioOut){
        emuWindow->setDevice();
        return 1;
    }else{
        return 0;
    }
}
Ejemplo n.º 17
0
WLAudio::WLAudio():
    m_adLib(false), m_soundBlaster(false), m_soundPositioned(0),
    m_numReadySamples(0), m_curAlSound(0), m_curAlSoundPtr(0), m_curAlLengthLeft(0),
    m_soundTimeCounter(5), m_originalSampleRate(7042), m_sqMaxTracks(10),
    m_alChar(0x20), m_alScale(0x40), m_alAttack(0x60), m_alSus(0x80), m_alWave(0xe0),
    m_alFreqL(0xa0), m_alFreqH(0xb0), m_alFeedCon(0xc0), m_alEffects(0xbd),
    m_nextSoundPos(false)
{
    QAudioFormat format;

#if QT_VERSION >= 0x050000
    format.setSampleRate(param_samplerate);
    format.setChannelCount(2);
#else
    format.setFrequency(param_samplerate);
    format.setChannels(2);
#endif
    format.setByteOrder(QAudioFormat::LittleEndian);
    format.setCodec("audio/pcm");
    format.setSampleSize(16);
    format.setSampleType(QAudioFormat::SignedInt);
    m_soundServer = new GameSoundServer(format);

    m_samplesPerMusicTick = param_samplerate / 700;

    if(YM3812Init(1,3579545,param_samplerate)) {
        printf("Unable to create virtual OPL!!\n");
    }
    for(int i = 1;i < 0xf6;i++)
        YM3812Write(0,i,0);

    YM3812Write(0, 1, 0x20); // Set WSE=1
    m_adLib = true;
    m_soundBlaster = true;
    m_alTimeCount = 0;
    setSoundMode(sdm_Off);
    setMusicMode(smm_Off);
    setupDigi();
}
Ejemplo n.º 18
0
/*!
  Constructor.
*/
AudioOut::AudioOut(AudioSource *source, QObject *parent /* = 0 */)
    : QThread(parent),
      m_audioOutput(0),
      m_outTarget(0),
      m_source(source),
      m_sendBuffer(0),
      m_sendBufferSize(0),
      m_samplesMixed(0),
      m_threadState(NotRunning),
      m_usingThread(false)
{
    QAudioFormat format;
    format.setFrequency(AUDIO_FREQUENCY);
    format.setChannels(GEDefaultChannelCount);
    format.setSampleSize(AUDIO_SAMPLE_BITS);
    format.setCodec(GEDefaultAudioCodec);
    format.setByteOrder(GEByteOrder);
    format.setSampleType(GESampleType);

    QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());

    if (!info.isFormatSupported(format))
        format = info.nearestFormat(format);

    m_audioOutput = new QAudioOutput(info, format);
    m_audioOutput->setBufferSize(4096 * 8);
    m_sendBufferSize = 4096 * 8;
    m_outTarget = m_audioOutput->start();

    DEBUG_INFO("Buffer size: " << m_audioOutput->bufferSize());
    m_sendBuffer = new AUDIO_SAMPLE_TYPE[m_sendBufferSize];

#ifndef Q_OS_SYMBIAN
    m_usingThread = true;
    start();
#endif

}
Ejemplo n.º 19
0
/*!
  Constructor.
*/
PushAudioOut::PushAudioOut(AudioSource *source, QObject *parent /* = 0 */)
    : QThread(parent),
      m_audioOutput(0),
      m_outTarget(0),
      m_sendBuffer(0),
      m_sendBufferSize(0),
      m_samplesMixed(0),
      m_threadState(NotRunning),
      m_source(source)
{
    DEBUG_INFO(this);

    QAudioFormat format;
    format.setFrequency(AUDIO_FREQUENCY);
    format.setChannels(AUDIO_CHANNELS);
    format.setSampleSize(AUDIO_SAMPLE_BITS);
    format.setCodec(GEDefaultAudioCodec);
    switch (GEByteOrder) {
    case BigEndian:
        format.setByteOrder(QAudioFormat::BigEndian);
        break;
    case LittleEndian:
        format.setByteOrder(QAudioFormat::LittleEndian);
        break;
    default:
        DEBUG_INFO("INVALID BYTE ORDER");
    }
    switch (GESampleType) {
    case Unknown:
        format.setSampleType(QAudioFormat::Unknown);
        break;
    case SignedInt:
        format.setSampleType(QAudioFormat::SignedInt);
        break;
    case UnSignedInt:
        format.setSampleType(QAudioFormat::UnSignedInt);
        break;
    case Float:
        format.setSampleType(QAudioFormat::Float);
        break;
    default:
        DEBUG_INFO("INVALID SAMPLE TYPE");
    }
    QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());

    if (!info.isFormatSupported(format))
        format = info.nearestFormat(format);

    m_audioOutput = new QAudioOutput(info, format);

#if defined(Q_WS_MAEMO_5) || defined(MEEGO_EDITION_HARMATTAN)
    m_sendBufferSize = 4096 * 4;
#else
    m_audioOutput->setBufferSize(4096 * 4);
#endif

#if defined(Q_WS_MAEMO_5) || defined(MEEGO_EDITION_HARMATTAN)
    m_audioOutput->setBufferSize(4096 * 16);
    m_sendBufferSize = 4096 * 8;
#else
    m_audioOutput->setBufferSize(4096 * 4);
    m_sendBufferSize = 4096 * 2;
#endif

    DEBUG_INFO("Buffer size: " << m_audioOutput->bufferSize());
    m_sendBuffer = new AUDIO_SAMPLE_TYPE[m_sendBufferSize];

    m_needsTick = false;
#if defined(QTGAMEENABLER_USE_VOLUME_HACK) && defined(Q_OS_SYMBIAN)
    DEBUG_INFO("WARNING: Using the volume hack!");

    // This really ugly hack is used as the last resort. This allows us to
    // adjust the application volume in Symbian. The CMMFDevSound object lies
    // deep inside the QAudioOutput in Symbian implementation and it has the
    // needed functions. So, we dig the required object accessing it directly
    // from memory.
    unsigned int *pointer_to_abstract_audio =
            (unsigned int*)((unsigned char*)m_audioOutput + 8);

    unsigned int *dev_sound_wrapper =
            (unsigned int*)(*pointer_to_abstract_audio) + 13;

    unsigned int *temp = ((unsigned int*)(*dev_sound_wrapper) + 6);

    CMMFDevSound *devSound = (CMMFDevSound*)(*temp);
    devSound->SetVolume(devSound->MaxVolume() * 6 / 10);
#endif

}
Ejemplo n.º 20
0
void tst_QAudioFormat::checkFrequency()
{
    QAudioFormat audioFormat;
    audioFormat.setFrequency(44100);
    QVERIFY(audioFormat.frequency() == 44100);
}
Ejemplo n.º 21
0
bool Engine::selectFormat()
{
    bool foundSupportedFormat = false;

    if (m_file || QAudioFormat() != m_format) {
        QAudioFormat format = m_format;
        if (m_file)
            // Header is read from the WAV file; just need to check whether
            // it is supported by the audio output device
            format = m_file->fileFormat();
        if (m_audioOutputDevice.isFormatSupported(format)) {
            setFormat(format);
            foundSupportedFormat = true;
        }
    } else {

        QList<int> frequenciesList;
    #ifdef Q_OS_WIN
        // The Windows audio backend does not correctly report format support
        // (see QTBUG-9100).  Furthermore, although the audio subsystem captures
        // at 11025Hz, the resulting audio is corrupted.
        frequenciesList += 8000;
    #endif

        if (!m_generateTone)
            frequenciesList += m_audioInputDevice.supportedFrequencies();

        frequenciesList += m_audioOutputDevice.supportedFrequencies();
        frequenciesList = frequenciesList.toSet().toList(); // remove duplicates
        qSort(frequenciesList);
        ENGINE_DEBUG << "Engine::initialize frequenciesList" << frequenciesList;

        QList<int> channelsList;
        channelsList += m_audioInputDevice.supportedChannels();
        channelsList += m_audioOutputDevice.supportedChannels();
        channelsList = channelsList.toSet().toList();
        qSort(channelsList);
        ENGINE_DEBUG << "Engine::initialize channelsList" << channelsList;

        QAudioFormat format;
        format.setByteOrder(QAudioFormat::LittleEndian);
        format.setCodec("audio/pcm");
        format.setSampleSize(16);
        format.setSampleType(QAudioFormat::SignedInt);
        int frequency, channels;
        foreach (frequency, frequenciesList) {
            if (foundSupportedFormat)
                break;
            format.setFrequency(frequency);
            foreach (channels, channelsList) {
                format.setChannels(channels);
                const bool inputSupport = m_generateTone ||
                                          m_audioInputDevice.isFormatSupported(format);
                const bool outputSupport = m_audioOutputDevice.isFormatSupported(format);
                ENGINE_DEBUG << "Engine::initialize checking " << format
                             << "input" << inputSupport
                             << "output" << outputSupport;
                if (inputSupport && outputSupport) {
                    foundSupportedFormat = true;
                    break;
                }
            }
        }

        if (!foundSupportedFormat)
            format = QAudioFormat();

        setFormat(format);
    }
Ejemplo n.º 22
0
QAudioFormat sampleSpecToAudioFormat(pa_sample_spec spec)
{
    QAudioFormat format;
    format.setFrequency(spec.rate);
    format.setChannelCount(spec.channels);
    format.setCodec("audio/pcm");

    switch (spec.format) {
        case PA_SAMPLE_U8:
            format.setByteOrder(QAudioFormat::LittleEndian);
            format.setSampleType(QAudioFormat::UnSignedInt);
            format.setSampleSize(8);
        break;
        case PA_SAMPLE_ALAW:
        // TODO:
        break;
        case PA_SAMPLE_ULAW:
        // TODO:
        break;
        case PA_SAMPLE_S16LE:
            format.setByteOrder(QAudioFormat::LittleEndian);
            format.setSampleType(QAudioFormat::SignedInt);
            format.setSampleSize(16);
        break;
        case PA_SAMPLE_S16BE:
            format.setByteOrder(QAudioFormat::BigEndian);
            format.setSampleType(QAudioFormat::SignedInt);
            format.setSampleSize(16);
        break;
        case PA_SAMPLE_FLOAT32LE:
            format.setByteOrder(QAudioFormat::LittleEndian);
            format.setSampleType(QAudioFormat::Float);
            format.setSampleSize(32);
        break;
        case PA_SAMPLE_FLOAT32BE:
            format.setByteOrder(QAudioFormat::BigEndian);
            format.setSampleType(QAudioFormat::Float);
            format.setSampleSize(32);
        break;
        case PA_SAMPLE_S32LE:
            format.setByteOrder(QAudioFormat::LittleEndian);
            format.setSampleType(QAudioFormat::SignedInt);
            format.setSampleSize(32);
        break;
        case PA_SAMPLE_S32BE:
            format.setByteOrder(QAudioFormat::BigEndian);
            format.setSampleType(QAudioFormat::SignedInt);
            format.setSampleSize(32);
        break;
        case PA_SAMPLE_S24LE:
            format.setByteOrder(QAudioFormat::LittleEndian);
            format.setSampleType(QAudioFormat::SignedInt);
            format.setSampleSize(24);
        break;
        case PA_SAMPLE_S24BE:
            format.setByteOrder(QAudioFormat::BigEndian);
            format.setSampleType(QAudioFormat::SignedInt);
            format.setSampleSize(24);
        break;
        case PA_SAMPLE_S24_32LE:
            format.setByteOrder(QAudioFormat::LittleEndian);
            format.setSampleType(QAudioFormat::SignedInt);
            format.setSampleSize(24);
        break;
        case PA_SAMPLE_S24_32BE:
            format.setByteOrder(QAudioFormat::BigEndian);
            format.setSampleType(QAudioFormat::SignedInt);
            format.setSampleSize(24);
        break;
        case PA_SAMPLE_MAX:
        case PA_SAMPLE_INVALID:
        default:
            format.setByteOrder(QAudioFormat::LittleEndian);
            format.setSampleType(QAudioFormat::Unknown);
            format.setSampleSize(0);
    }

    return format;
}
Ejemplo n.º 23
0
bool OutputQtMultimedia::initialize(quint32 freq, ChannelMap map, Qmmp::AudioFormat format)
{
    QAudioFormat qformat;
    qformat.setCodec("audio/pcm");
    qformat.setFrequency(freq);
    qformat.setByteOrder(QAudioFormat::LittleEndian);
    qformat.setChannels(map.size());
    qformat.setSampleType(QAudioFormat::SignedInt);

    //Size of sample representation in input data. For 24-bit is 4, high byte is ignored.
    qint64 bytes_per_sample = 0;

    switch (format)
    {
    case Qmmp::PCM_S8:
        qformat.setSampleSize(8);
        bytes_per_sample = 1;
        break;
    case Qmmp::PCM_S16LE:
        qformat.setSampleSize(16);
        bytes_per_sample = 2;
        break;
    case Qmmp::PCM_S24LE:
        qformat.setSampleSize(24);
        bytes_per_sample = 4;
        break;
    case Qmmp::PCM_S32LE:
        qformat.setSampleSize(32);
        bytes_per_sample = 4;
        break;
    default:
        break;
    }

    if (!qformat.isValid())
        return false;

    m_bytes_per_second = bytes_per_sample * freq * qformat.channels();

    const QSettings settings(Qmmp::configFile(), QSettings::IniFormat);
    const QString saved_device_name = settings.value("QTMULTIMEDIA/device").toString();

    QAudioDeviceInfo device_info;
    if (!saved_device_name.isEmpty())
    {
        const QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput);
        foreach (const QAudioDeviceInfo &info, devices)
        {
            if (info.deviceName()==saved_device_name)
            {
                if (info.isFormatSupported(qformat))
                {
                    device_info = info;
                    break;
                }
                else
                    qDebug() << "OutputQtMultimedia: Output device: " << saved_device_name << " is not supported";
            }
        }
    }

    if (device_info.isNull())
    {
        device_info = QAudioDeviceInfo::defaultOutputDevice();
        if (!device_info.isFormatSupported(qformat))
            return false;
    }

    qDebug() << "OutputQtMultimedia: Using output device: " << device_info.deviceName();

    m_output.reset(new QAudioOutput(device_info, qformat));
    m_buffer = m_output->start();

    configure(freq, map, format);
    return true;
}
Ejemplo n.º 24
0
PullAudioOut::PullAudioOut(AudioSource *source, QObject *parent)
    : QIODevice(parent),
      m_source(source)
{
    DEBUG_INFO(this);

    QAudioFormat format;
    format.setFrequency(AUDIO_FREQUENCY);
    format.setChannels(AUDIO_CHANNELS);
    format.setSampleSize(AUDIO_SAMPLE_BITS);
    format.setCodec(GEDefaultAudioCodec);
    switch (GEByteOrder) {
    case BigEndian:
        format.setByteOrder(QAudioFormat::BigEndian);
        break;
    case LittleEndian:
        format.setByteOrder(QAudioFormat::LittleEndian);
        break;
    default:
        DEBUG_INFO("INVALID BYTE ORDER");
    }
    switch (GESampleType) {
    case Unknown:
        format.setSampleType(QAudioFormat::Unknown);
        break;
    case SignedInt:
        format.setSampleType(QAudioFormat::SignedInt);
        break;
    case UnSignedInt:
        format.setSampleType(QAudioFormat::UnSignedInt);
        break;
    case Float:
        format.setSampleType(QAudioFormat::Float);
        break;
    default:
        DEBUG_INFO("INVALID SAMPLE TYPE");
    }

    QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());

    if (!info.isFormatSupported(format))
        format = info.nearestFormat(format);

    m_sendBufferSize = 4096;
    m_audioOutput = new QAudioOutput(info, format);

#if defined(QTGAMEENABLER_USE_VOLUME_HACK) && defined(Q_OS_SYMBIAN)
    DEBUG_INFO("WARNING: Using the volume hack!");

    // This really ugly hack is used as the last resort. This allows us to
    // adjust the application volume in Symbian. The CMMFDevSound object lies
    // deep inside the QAudioOutput in Symbian implementation and it has the
    // needed functions. So, we get the needed object accessing it directly
    // from memory.
    unsigned int *pointer_to_abstract_audio =
            (unsigned int*)((unsigned char*)m_audioOutput + 8);

    unsigned int *dev_sound_wrapper =
            (unsigned int*)(*pointer_to_abstract_audio) + 13;

    unsigned int *temp = ((unsigned int*)(*dev_sound_wrapper) + 6);

    CMMFDevSound *devSound = (CMMFDevSound*)(*temp);
    devSound->SetVolume(devSound->MaxVolume() * 6 / 10);
#endif

    open(QIODevice::ReadOnly | QIODevice::Unbuffered);
    connect(m_audioOutput, SIGNAL(stateChanged(QAudio::State)),
        SLOT(audioStateChanged(QAudio::State)));
}