Пример #1
0
void GuitarTuner::initAudioOutput()
 {
     m_format_output.setSampleRate(DataFrequencyHzOutput);
     m_format_output.setCodec("audio/pcm");
     m_format_output.setSampleSize(16);
     m_format_output.setChannelCount(1);
     m_format_output.setByteOrder(QAudioFormat::LittleEndian);
     m_format_output.setSampleType(QAudioFormat::SignedInt);

     QAudioDeviceInfo outputDeviceInfo(
                 QAudioDeviceInfo::defaultOutputDevice());
     if (!outputDeviceInfo.isFormatSupported(m_format_output)) {
         m_format_output = outputDeviceInfo.nearestFormat(m_format_output);
     }

     m_audioOutput = new QAudioOutput(outputDeviceInfo,
                                      m_format_output, this);
     m_voicegenerator = new VoiceGenerator(m_format_output,
                                           getFrequency(),
                                           getVolume(),
                                           this);

     connect(m_audioOutput, SIGNAL(stateChanged(QAudio::State)),
             SLOT(outputStateChanged(QAudio::State)));
 }
Пример #2
0
/**
  * Inits audio output.
  */
void GuitarTuner::initAudioOutput()
{
    // Set up the output format.
    m_format_output.setFrequency(DataFrequencyHzOutput);
    m_format_output.setCodec("audio/pcm");
    m_format_output.setSampleSize(16);
    m_format_output.setChannels(1);
    m_format_output.setByteOrder(QAudioFormat::LittleEndian);
    m_format_output.setSampleType(QAudioFormat::SignedInt);

    // Obtain a default output device, and if the format is not
    // supported, find the nearest format available.
    QAudioDeviceInfo outputDeviceInfo(
                QAudioDeviceInfo::defaultOutputDevice());
    if (!outputDeviceInfo.isFormatSupported(m_format_output)) {
        m_format_output = outputDeviceInfo.nearestFormat(m_format_output);
    }

    // Create new QAudioOutput and VoiceGenerator instances, and store
    // them in m_audioOutput and m_voicegenerator, respectively.
    m_audioOutput = new QAudioOutput(outputDeviceInfo,
                                     m_format_output, this);
    m_voicegenerator = new VoiceGenerator(m_format_output,
                                          qmlObject->property("frequency").toReal(),
                                          qmlObject->property("volume").toReal(),
                                          this);

    // Connect m_audioOutput stateChanged signal to outputStateChanged.
    connect(m_audioOutput, SIGNAL(stateChanged(QAudio::State)),
            SLOT(outputStateChanged(QAudio::State)));
}