当前位置: 首页>>代码示例>>C++>>正文


C++ QAudioFormat类代码示例

本文整理汇总了C++中QAudioFormat的典型用法代码示例。如果您正苦于以下问题:C++ QAudioFormat类的具体用法?C++ QAudioFormat怎么用?C++ QAudioFormat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了QAudioFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: stop

void CAudioOutputTest::start(const QString &filePath, const QAudioDeviceInfo &audioDeviceInfo)
{
    stop();

    if(m_PCMIODevice)
    {
        m_PCMIODevice->deleteLater();
        m_PCMIODevice = NULL;
    }
    m_PCMIODevice = new CPCMIODevice(filePath,this);
    connect(m_PCMIODevice,SIGNAL(readChannelFinished()),this,SLOT(onStateChanged()));

    QAudioFormat format;
    format.setSampleRate(44100);
    format.setChannelCount(2);
    format.setSampleSize(16);
    format.setCodec("audio/pcm");
    format.setByteOrder(QAudioFormat::LittleEndian);
    format.setSampleType(QAudioFormat::SignedInt);

    QAudioDeviceInfo info(audioDeviceInfo);
    if (!info.isFormatSupported(format)) {
//        qWarning() << "Default format not supported - trying to use nearest";
        format = info.nearestFormat(format);
    }

    if(m_audioOutput)
    {
        delete m_audioOutput;
        m_audioOutput = 0;
    }
    m_audioOutput = new QAudioOutput(audioDeviceInfo, format, this);
    connect(m_audioOutput,SIGNAL(stateChanged(QAudio::State)),this,SLOT(onStateChanged()));

    if(m_PCMIODevice)
    {
        m_PCMIODevice->start();
    }
    m_audioOutput->start(m_PCMIODevice);
}
开发者ID:weinkym,项目名称:src_miao,代码行数:40,代码来源:caudiooutputtest.cpp

示例2: QtSoundInit

static int QtSoundInit()
{
    qDebug() << __func__;
    nQtAudioFps = nAppVirtualFps;
    nAudSegLen = (nAudSampleRate[0] * 100 + (nQtAudioFps / 2)) / nQtAudioFps;

    // seglen * 2 channels * 2 bytes per sample (16bits)
    nAudAllocSegLen = nAudSegLen * 4;

    // seg * nsegs * 2 channels
    if (qSoundBuffer != nullptr)
        delete qSoundBuffer;

    qSoundBuffer = new QAudioInterfaceBuffer();
    qSoundBuffer->setBufferSize(nAudAllocSegLen * nAudSegCount);
    nAudNextSound = new short[nAudAllocSegLen / sizeof(short)];

    QtSoundSetCallback(nullptr);
    QtSoundGetNextSoundFiller(0);

    //qSoundBuffer->writeData((const char *) nAudNextSound, nAudAllocSegLen);
    //qSoundBuffer->writeData((const char *) nAudNextSound, nAudAllocSegLen);

    pBurnSoundOut = nAudNextSound;
    nBurnSoundRate = nAudSampleRate[0];
    nBurnSoundLen = nAudAllocSegLen;

    qAudio = QAudioInterface::get();
    qAudio->setBuffer(qSoundBuffer);
    QAudioFormat format;
    format.setChannelCount(2);
    format.setSampleRate(nAudSampleRate[0]);
    format.setSampleType(QAudioFormat::SignedInt);
    format.setByteOrder(QAudioFormat::LittleEndian);
    format.setSampleSize(16);
    qAudio->setFormat(format);

    // we need to invoke this method on sound's thread, so we can't call this
    // method from our object
    QMetaObject::invokeMethod(qAudio, "init", Qt::QueuedConnection);

    bAudOkay = 1;
    return 0;
}
开发者ID:Cpasjuste,项目名称:libarcade,代码行数:44,代码来源:qaudiointerface.cpp

示例3: run

void MainAudio::run()
{
    QAudioFormat fmt;
    fmt.setSampleRate(AUDIO_FREQ);
    fmt.setCodec("audio/pcm");
    fmt.setChannelCount(AUDIO_CHANNELS);
    fmt.setSampleSize(AUDIO_SAMPLESIZE);
    fmt.setByteOrder(QAudioFormat::LittleEndian);
    fmt.setSampleType(QAudioFormat::SignedInt);
    mixlen = sizeof(short)*AUDIO_BUFFERS*AUDIO_CHANNELS*AUDIO_SAMPLES;
    mixbuf = (char*)malloc(mixlen);
    output = new QAudioOutput(fmt);
    output->setBufferSize(mixlen);
    feed = output->start();
    if (feed != NULL) {
        // buffering has already done in the internal mixed buffer
        // use a small interval to copy mixed audio stream from
        // internal buffer to audio output buffer as soon as possible
        // use 1 instead of 0 to prevent CPU exhausting
        timer = startTimer(1);
    }
}
开发者ID:RisingFog,项目名称:ppsspp,代码行数:22,代码来源:QtMain.cpp

示例4: QThread

/*!
  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

}
开发者ID:ltomuta,项目名称:quickhit,代码行数:41,代码来源:GEAudioOut.cpp

示例5: AudioDevice

void AudioProcessorQt::start() {
	if (!m_device) {
		m_device = new AudioDevice(this);
	}

	if (!m_audioOutput) {
		QAudioFormat format;
		format.setSampleRate(44100);
		format.setChannelCount(2);
		format.setSampleSize(16);
		format.setCodec("audio/pcm");
		format.setByteOrder(QAudioFormat::LittleEndian);
		format.setSampleType(QAudioFormat::SignedInt);

		m_audioOutput = new QAudioOutput(format, this);
	}

	m_device->setInput(input());
	m_device->setFormat(m_audioOutput->format());
	m_audioOutput->setBufferSize(input()->audioBuffers * 4);

	m_audioOutput->start(m_device);
}
开发者ID:MoochMcGee,项目名称:mgba,代码行数:23,代码来源:AudioProcessorQt.cpp

示例6: addHeader

void AudioFileWav::addHeader(const QAudioFormat& audioFormat) {
    QDataStream stream(&_file);

    stream.setByteOrder(QDataStream::LittleEndian);

    // RIFF
    stream.writeRawData("RIFF", 4);
    stream << quint32(0);
    stream.writeRawData("WAVE", 4);

    // Format description PCM = 16
    stream.writeRawData("fmt ", 4);
    stream << quint32(16);
    stream << quint16(1);
    stream << quint16(audioFormat.channelCount());
    stream << quint32(audioFormat.sampleRate());
    stream << quint32(audioFormat.sampleRate() * audioFormat.channelCount() * audioFormat.sampleSize() / 8); // bytes per second
    stream << quint16(audioFormat.channelCount() * audioFormat.sampleSize() / 8); // block align
    stream << quint16(audioFormat.sampleSize()); // bits Per Sample
    // Init data chunck
    stream.writeRawData("data", 4);
    stream << quint32(0);
}
开发者ID:AndrewMeadows,项目名称:hifi,代码行数:23,代码来源:AudioFileWav.cpp

示例7: startListening

void Engine::startListening()
{
    QAudioFormat format;
    // Set up the desired format, for example:
    format.setSampleRate(8000);
    format.setChannelCount(1);
    format.setSampleSize(8);
    format.setCodec("audio/pcm");
    format.setByteOrder(QAudioFormat::LittleEndian);
    format.setSampleType(QAudioFormat::UnSignedInt);

    QAudioDeviceInfo info = QAudioDeviceInfo::defaultInputDevice();
    if (!info.isFormatSupported(format)) {
        qWarning() << "Default format not supported, trying to use the nearest.";
        format = info.nearestFormat(format);
    }

    QAudioInput *audio = new QAudioInput(format, this);

    QBuffer buffer;

    audio->start(&buffer);
}
开发者ID:jimtendo,项目名称:darcoi,代码行数:23,代码来源:engine.cpp

示例8: QMainWindow

MainWindow::MainWindow(vector<TimeOption> timeOptions_, QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow),
    timer(this),
    finishedSource(":/sounds/alarm.raw"),
    timeOptions(timeOptions_)
{

    ui->setupUi(this);

    for (vector<TimeOption>::iterator it = timeOptions.begin(); it!= timeOptions.end(); ++ it) {
        TimeOption o = *it;
        ui->timeSelection->addItem(QString::fromStdString(o.name));
    }

    finishedSource.open(QIODevice::ReadOnly);
    QAudioFormat format;
    format.setSampleRate(44100);
    format.setChannelCount(1);
    format.setSampleSize(16);
    format.setCodec("audio/pcm");
    format.setByteOrder(QAudioFormat::LittleEndian);
    format.setSampleType(QAudioFormat::SignedInt);

    QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
    if (!info.isFormatSupported(format)) {
        qWarning() << "Raw audio format not supported by backend, cannot play audio.";
        finishedSound = NULL;
    } else {
        finishedSound = new QAudioOutput(format, this);
        //finishedSound->start(&finishedSource);
    }

    connect(ui->startTimer, SIGNAL(clicked()), this, SLOT(startCountDown()));
    connect(&timer, SIGNAL(timeout()), this, SLOT(timerTick()));
    connect(ui->fullscreen, SIGNAL(clicked()), this, SLOT(fullScreenClicked()));
}
开发者ID:cajun-rat,项目名称:countdowntimer,代码行数:37,代码来源:mainwindow.cpp

示例9: qSin

void NotificationSound::playSound()
{
    //QSound::play(":/sound/notification_sound.wav");
    //return;
    qreal frequency = ((sFrequency <= 0)?2000:sFrequency);
    qreal mseconds = ((sDuration <= 0)?1000:sDuration);
    quint8 volume = ((sVolume <= 0)?1:sVolume);
    qreal sampleRate = 2.0 * M_PI / (192000./frequency);

    QByteArray bytebuf;
    bytebuf.resize(mseconds * 192);

    for (int i=0; i < bytebuf.size(); i++) {
        bytebuf[i] = (quint8)(qreal(255) * qSin(qreal(i) * sampleRate));
    }


    QDataStream stream(&bytebuf, QIODevice::ReadWrite);

    QAudioFormat format;
    format.setSampleRate(192000);
    format.setChannelCount(1);
    format.setSampleSize(8);
    format.setCodec("audio/pcm");
    format.setByteOrder(QAudioFormat::LittleEndian);
    format.setSampleType(QAudioFormat::UnSignedInt);

    QAudioOutput * audio = new QAudioOutput(format, this);
    audio->setVolume(1.0 * (qreal(volume + 1)/4));
    audio->setBufferSize(bytebuf.size());
    audio->start(stream.device());

    QEventLoop loop;
    QTimer::singleShot(mseconds*2, &loop, SLOT(quit()));
    loop.exec();
}
开发者ID:nhinze,项目名称:rhodes,代码行数:36,代码来源:notificationsound.cpp

示例10: test_1

int test_1(QObject* a)
{
    QAudioFormat format;
    // Set up the format, eg.

    format.setSampleRate(44100);
    format.setChannelCount(2);
    format.setCodec("audio/pcm");
    format.setSampleType(QAudioFormat::SignedInt);
    format.setSampleSize(16);
    format.setByteOrder(QAudioFormat::LittleEndian);

    QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
    if (!info.isFormatSupported(format)) {
        qDebug() << "Raw audio format not supported by backend, cannot play audio.";
        return -1;
    }

    char filename[1024];
    printf("input file name :");
    scanf("%s",filename);
    fflush(stdin);
    fflush(stdout);

    printf("start audio \n");
    QAudioOutput *audio;
    audio = new QAudioOutput(format, a);

    QIODevice *out = audio->start();

#if 0
    qDebug()<< out->isSequential() << " swquential"; // 不是顺序设备,是随机设备
#endif

    decodeAndPlay(filename,out);
}
开发者ID:qyvlik,项目名称:AudioTestByFFmpeg,代码行数:36,代码来源:main.cpp

示例11: QCustomDialog

DlgEditMusic::DlgEditMusic(cMusicObject *TheMusicObject,cApplicationConfig *ApplicationConfig,QWidget *parent):
    QCustomDialog(ApplicationConfig,parent), ui(new Ui::DlgEditMusic) {
    ui->setupUi(this);

    OkBt                =ui->OKBT;
    CancelBt            =ui->CancelBt;
    HelpBt              =ui->HelpBt;
    HelpFile            ="0124";
    MusicObject         =TheMusicObject;
    StopMaj             =false;
    InSliderMoveEvent   =false;
    IsInit              =false;
    PlayerPlayMode      =false;
    PlayerPauseMode     =false;
    IsSliderProcess     =false;
    ActualPosition      =-1;
    ResetPositionWanted =false;

    AudioBuf            =(u_int8_t *)malloc(AUDIOBUFSIZE);
    AudioBufSize        =0;

    MixedMusic.SetFPS(double(1000)/ApplicationConfig->PreviewFPS,2,ApplicationConfig->PreviewSamplingRate,AV_SAMPLE_FMT_S16);
    Music.SetFPS(MixedMusic.WantedDuration,MixedMusic.Channels,MixedMusic.SamplingRate,MixedMusic.SampleFormat);

    // Set up the format
    QAudioFormat format;
    format.setCodec("audio/pcm");
    format.setSampleRate(MixedMusic.SamplingRate); // Usually this is specified through an UI option
    format.setChannelCount(MixedMusic.Channels);
    format.setSampleSize(16);
    format.setByteOrder(QAudioFormat::LittleEndian);
    format.setSampleType(QAudioFormat::SignedInt);

    // Create audio output stream, set up signals
    audio_outputStream = new QAudioOutput(format,this);
}
开发者ID:JonasCz,项目名称:ffdiaporama-1604-builds,代码行数:36,代码来源:DlgEditMusic.cpp

示例12: GetStreamAudioFormat

QAudioFormat AudioTransmitter::GetStreamAudioFormat(void)
{
   QAudioFormat format;
   QAudioDeviceInfo info1 = QAudioDeviceInfo::defaultInputDevice();
   format.setSampleRate(44100);
   //format.setChannels(1);
   format.setSampleSize(24);
   format.setCodec("audio/pcm");
   format.setByteOrder(QAudioFormat::LittleEndian);
   format.setSampleType(QAudioFormat::UnSignedInt);

   QAudioDeviceInfo info = QAudioDeviceInfo::defaultInputDevice();
   if (!info.isFormatSupported(format))
       format = info.nearestFormat(format);
   QStringList list=info1.supportedCodecs();
   foreach (const QString &str, list) {
       qDebug()<<"codec: "<<str;
   }

   return format;
}
开发者ID:lvip,项目名称:TwaddleMSG-desctop-,代码行数:21,代码来源:voip.cpp

示例13: startPlaying

void RtpAudioStream::startPlaying()
{
    if (audio_output_) return;

    QAudioFormat format;
    format.setSampleRate(audio_out_rate_);
    format.setSampleSize(sample_bytes_ * 8); // bits
    format.setSampleType(QAudioFormat::SignedInt);
    format.setChannelCount(1);
    format.setCodec("audio/pcm");

    // RTP_STREAM_DEBUG("playing %s %d samples @ %u Hz",
    //                 tempfile_->fileName().toUtf8().constData(),
    //                 (int) tempfile_->size(), audio_out_rate_);

    audio_output_ = new QAudioOutput(format, this);
    audio_output_->setNotifyInterval(65); // ~15 fps
    connect(audio_output_, SIGNAL(stateChanged(QAudio::State)), this, SLOT(outputStateChanged()));
    connect(audio_output_, SIGNAL(notify()), this, SLOT(outputNotify()));
    tempfile_->seek(0);
    audio_output_->start(tempfile_);
    emit startedPlaying();
}
开发者ID:joewan,项目名称:wireshark,代码行数:23,代码来源:rtp_audio_stream.cpp

示例14: QThread

/*!
  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

}
开发者ID:wannaphongcom,项目名称:epong,代码行数:92,代码来源:pushaudioout.cpp

示例15: Q_ASSERT

 void Generator::generateData(const QAudioFormat &format, qint64 durationUs, int frequency)
 {
     const int channelBytes = format.sampleSize() / 8;
     const int sampleBytes = format.channels() * channelBytes;

     qint64 length = (format.frequency() * format.channels() * (format.sampleSize() / 8))
                         * durationUs / 100000;

     Q_ASSERT(length % sampleBytes == 0);
     Q_UNUSED(sampleBytes) // suppress warning in release builds

     m_buffer.resize(length);
     unsigned char *ptr = reinterpret_cast<unsigned char *>(m_buffer.data());
     int sampleIndex = 0;

     while (length) {
         const qreal x = qSin(2 * M_PI * frequency * qreal(sampleIndex % format.frequency()) / format.frequency());
         for (int i=0; i<format.channels(); ++i) {
             if (format.sampleSize() == 8 && format.sampleType() == QAudioFormat::UnSignedInt) {
                 const quint8 value = static_cast<quint8>((1.0 + x) / 2 * 255);
                 *reinterpret_cast<quint8*>(ptr) = value;
             } else if (format.sampleSize() == 8 && format.sampleType() == QAudioFormat::SignedInt) {
                 const qint8 value = static_cast<qint8>(x * 127);
                 *reinterpret_cast<quint8*>(ptr) = value;
             } else if (format.sampleSize() == 16 && format.sampleType() == QAudioFormat::UnSignedInt) {
                 quint16 value = static_cast<quint16>((1.0 + x) / 2 * 65535);
                 if (format.byteOrder() == QAudioFormat::LittleEndian)
                     qToLittleEndian<quint16>(value, ptr);
                 else
                     qToBigEndian<quint16>(value, ptr);
             } else if (format.sampleSize() == 16 && format.sampleType() == QAudioFormat::SignedInt) {
                 qint16 value = static_cast<qint16>(x * 32767);
                 if (format.byteOrder() == QAudioFormat::LittleEndian)
                     qToLittleEndian<qint16>(value, ptr);
                 else
                     qToBigEndian<qint16>(value, ptr);
             }

             ptr += channelBytes;
             length -= channelBytes;
         }
         ++sampleIndex;
     }
 }
开发者ID:stephaneAG,项目名称:Qt_tests_Mac,代码行数:44,代码来源:audiooutput.cpp


注:本文中的QAudioFormat类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。