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


C++ QAudioFormat::setChannelCount方法代码示例

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


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

示例1: checkChannelCount

/* channelCount() API property test. */
void tst_QAudioFormat::checkChannelCount()
{
    // channels is the old name for channelCount, so
    // they should always be equal
    QAudioFormat audioFormat;
    QVERIFY(audioFormat.channelCount() == -1);
    QVERIFY(audioFormat.channelCount() == -1);

    audioFormat.setChannelCount(123);
    QVERIFY(audioFormat.channelCount() == 123);
    QVERIFY(audioFormat.channelCount() == 123);

    audioFormat.setChannelCount(5);
    QVERIFY(audioFormat.channelCount() == 5);
    QVERIFY(audioFormat.channelCount() == 5);
}
开发者ID:MarianMMX,项目名称:MarianMMX,代码行数:17,代码来源:tst_qaudioformat.cpp

示例2: start

void Airplay :: start()
{
	// read the airplay pipe
	file.setFileName("/tmp/shairport-sync-pipe");
	file.open(QIODevice::ReadOnly);

	// set the audio format
	// https://github.com/mikebrady/shairport-sync/issues/126
	// Playing raw data 'stdin' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
	QAudioFormat format;
	format.setSampleRate(44100); // rate
	format.setChannelCount(2); // stereo
	format.setCodec("audio/pcm"); // raw
	format.setSampleSize(16); // 16 bit
	format.setByteOrder(QAudioFormat::LittleEndian);
	format.setSampleType(QAudioFormat::SignedInt);

	// check format is supported
	if (!deviceInfo.isFormatSupported(format))
		qWarning() << "Output format not supported";

	// connect signals
	audio = new QAudioOutput(deviceInfo, format, this);
	connect(audio, SIGNAL(stateChanged(QAudio::State)), this, SLOT(handleStateChange(QAudio::State)));

	// start playing
	audio->start(&file);
}
开发者ID:kevindoveton,项目名称:carpc,代码行数:28,代码来源:ClassAirplay.cpp

示例3: QObject

BeatController::BeatController(QAudioDeviceInfo inputDevice, uint16_t recordSize, uint32_t sampleRate, uint16_t m_bandCount, QObject *parent) : QObject(parent)
{
    m_RecordSize = recordSize;
    m_Buffer = new SoundBuffer(recordSize);
    m_Analyser = new BeatAnalyser(m_bandCount,sampleRate,recordSize);
    m_inputDevice = QAudioDeviceInfo(inputDevice);

    m_FFT = new FFT(recordSize);
    m_FFT->setSoundBuffer(m_Buffer);
    m_Analyser->setFFT(m_FFT);

    QAudioFormat audioFormat;
    audioFormat.setSampleRate(sampleRate);
    audioFormat.setChannelCount(1);
    audioFormat.setSampleSize(16);
    audioFormat.setSampleType(QAudioFormat::SignedInt);
    audioFormat.setByteOrder(QAudioFormat::LittleEndian);
    audioFormat.setCodec("audio/pcm");

    //QAudioDeviceInfo info(QAudioDeviceInfo::defaultInputDevice());

    if (!m_inputDevice.isFormatSupported(audioFormat)) {
        qWarning() << "Default format not supported - trying to use nearest";
        audioFormat = m_inputDevice.nearestFormat(audioFormat);
    }

    m_audioInput = new QAudioInput(m_inputDevice, audioFormat, this);
    m_ioDevice = m_audioInput->start();
    connect(m_ioDevice, SIGNAL(readyRead()), this, SLOT(readAudio()));

}
开发者ID:nzhome,项目名称:lightcontroller,代码行数:31,代码来源:beatcontroller.cpp

示例4: 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();
    // QTBUG-6548 StoppedState is not always emitted on error, force a cleanup
    // in case playback fails immediately.
    if (audio_output_ && audio_output_->state() == QAudio::StoppedState) {
        outputStateChanged();
    }
}
开发者ID:Nicholas1126,项目名称:wireshark-ex,代码行数:28,代码来源:rtp_audio_stream.cpp

示例5: test_2

int test_2()
{
    qyvlik::FFmpegStream* ffmpegStream = new qyvlik::FFmpegStream();

    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;
    }

    ffmpegStream->setFileName("E:/Test/1.mp3");

    QAudioOutput *audio;
    audio = new QAudioOutput(format);
    audio->start(ffmpegStream);

    qDebug() << "Play Finished~";

}
开发者ID:qyvlik,项目名称:AudioTestByFFmpeg,代码行数:29,代码来源:main.cpp

示例6: recordAudioSample

void AudioCore::recordAudioSample(int t = 500, bool writeToFile = false)
{
    latestSampleDuration = t;
    writeSampleToFile    = writeToFile;

    sampleAudioBuffer.open(QBuffer::ReadWrite);
    QAudioFormat format;

    // Настраиваем желаемый формат, например:
    format.setSampleRate(AudioCore::SampleRate);
    format.setSampleSize(8 * AudioCore::SampleSize);
    format.setChannelCount(1);
    format.setCodec("audio/pcm");
    format.setByteOrder(QAudioFormat::LittleEndian);
    format.setSampleType(QAudioFormat::UnSignedInt);

    // ВЫбрать устройство ввода 0:
    QAudioDeviceInfo info(QAudioDeviceInfo::availableDevices(QAudio::AudioInput).at(0));
    qDebug() << "Selected input device =" << info.deviceName();

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

    audio = new QAudioInput(format);

    // Очень важно, иначе будут шумы и все картинки ужасно некрасивые.
    audio->setVolume(AudioCore::AudioLevel);
    connect(audio, SIGNAL(stateChanged(QAudio::State)), this, SLOT(handleStateChanged(QAudio::State)));

    QTimer::singleShot(t, this, SLOT(stopRecording()));
    audio->start(&sampleAudioBuffer);
}
开发者ID:arinik2,项目名称:sunstar-mobile,代码行数:34,代码来源:audiocore.cpp

示例7: start

void AudioProcessorQt::start() {
	if (!input()) {
		return;
	}

	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_audioOutput->setCategory("game");
	}

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

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

示例8: processLocalAudio

void AudioReflector::processLocalAudio(unsigned int sampleTime, const QByteArray& samples, const QAudioFormat& format) {
    bool processLocalAudio = true; // Menu::getInstance()->isOptionChecked(MenuOption::AudioSpatialProcessingProcessLocalAudio)
    if (processLocalAudio) {
        const int NUM_CHANNELS_INPUT = 1;
        const int NUM_CHANNELS_OUTPUT = 2;
        const int EXPECTED_SAMPLE_RATE = 24000;
        if (format.channelCount() == NUM_CHANNELS_INPUT && format.sampleRate() == EXPECTED_SAMPLE_RATE) {
            QAudioFormat outputFormat = format;
            outputFormat.setChannelCount(NUM_CHANNELS_OUTPUT);
            QByteArray stereoInputData(samples.size() * NUM_CHANNELS_OUTPUT, 0);
            int numberOfSamples = (samples.size() / sizeof(int16_t));
            int16_t* monoSamples = (int16_t*)samples.data();
            int16_t* stereoSamples = (int16_t*)stereoInputData.data();
            
            for (int i = 0; i < numberOfSamples; i++) {
                stereoSamples[i* NUM_CHANNELS_OUTPUT] = monoSamples[i] * _localAudioAttenuationFactor;
                stereoSamples[(i * NUM_CHANNELS_OUTPUT) + 1] = monoSamples[i] * _localAudioAttenuationFactor;
            }
            _localAudioDelays.clear();
            _localEchoesSuppressed.clear();
            echoAudio(LOCAL_AUDIO, sampleTime, stereoInputData, outputFormat);
            _localEchoesCount = _localAudioDelays.size();
            _localEchoesSuppressedCount = _localEchoesSuppressed.size();
        }
    }
}
开发者ID:RyanDowne,项目名称:hifi,代码行数:26,代码来源:AudioReflector.cpp

示例9: startStreaming

void QSpotifyAudioThreadWorker::startStreaming(int channels, int sampleRate)
{
    qDebug() << "QSpotifyAudioThreadWorker::startStreaming";
    if (!m_audioOutput) {
        QAudioFormat af;
        af.setChannelCount(channels);
        af.setCodec("audio/pcm");
        af.setSampleRate(sampleRate);
        af.setSampleSize(16);
        af.setSampleType(QAudioFormat::SignedInt);

        QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
        if (!info.isFormatSupported(af)) {
            QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput);
            for (int i = 0; i < devices.size(); i++) {
                QAudioDeviceInfo dev = devices[i];
                qWarning() << dev.deviceName();
            }
            QCoreApplication::postEvent(QSpotifySession::instance(), new QEvent(QEvent::Type(StopEventType)));
            return;
        }

        m_audioOutput = new QAudioOutput(af);
        connect(m_audioOutput, SIGNAL(stateChanged(QAudio::State)), QSpotifySession::instance(), SLOT(audioStateChange(QAudio::State)));
        m_audioOutput->setBufferSize(BUF_SIZE);

        startAudioOutput();
    }
}
开发者ID:abranson,项目名称:libQtSpotify,代码行数:29,代码来源:qspotifyaudiothreadworker.cpp

示例10: StartRecord

int CRecordData::StartRecord(bool bIsSection)
{
    if(true == bIsSection)
    {

    }
    else
    {
        SetNumofRecDatSec(0);

        // 初始化一个buffer储存raw数据
        QBuffer* bufRecord = new QBuffer();
        bufRecord->open( QIODevice::WriteOnly | QIODevice::Truncate );

        SetRecDatSec(m_iNumOfRecDatSec, bufRecord);
        SetNumofRecDatSec(m_iNumOfRecDatSec+1);

        // 设置录音格式
        QAudioFormat format;
        format.setSampleRate(8000);
        format.setChannelCount(1);
        format.setSampleSize(8);
        format.setCodec("audio/pcm");
        format.setByteOrder(QAudioFormat::LittleEndian);
        format.setSampleType(QAudioFormat::UnSignedInt);

        // 设置录音设备
        audioInput = new QAudioInput(format, this);
        audioInput->start(bufRecord);
    }

}
开发者ID:yanwucanyue,项目名称:BrainUp,代码行数:32,代码来源:CRecordData.cpp

示例11: on_pushButton_clicked

void MainWindow::on_pushButton_clicked()
{
      QIODevice *QID;
      //QID->open( QIODevice::WriteOnly);
      QBuffer myQB;

     //QID(myQB);
    //cb(128000,64000);
     //dFile.setFileName("../RecordTest.raw");
     microphoneBuffer->open( QIODevice::ReadWrite);
     QAudioFormat format;
     // Set up the desired format, for example:
     format.setSampleRate(16000);
     format.setChannelCount(1);
     format.setSampleSize(16);
     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);
     }

     audio = new QAudioInput(format, this);
     connect(audio, SIGNAL(stateChanged(QAudio::State)), this, SLOT(handleStateChanged(QAudio::State)));

     //QTimer::singleShot(5000, this, SLOT(on_pushButton_2_clicked()));
     isRecording = true;
     audio->start(microphoneBuffer);
}
开发者ID:SpenserL,项目名称:WirelessAudio,代码行数:33,代码来源:mainwindow.cpp

示例12: QObject

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()));
}
开发者ID:alekseysidorov,项目名称:MeeTuner,代码行数:32,代码来源:frequencyanalyzer.cpp

示例13: connect

AudioDecoder::AudioDecoder(bool isPlayback, bool isDelete)
    : m_cout(stdout, QIODevice::WriteOnly)
{
    m_isPlayback = isPlayback;
    m_isDelete = isDelete;

    // Make sure the data we receive is in correct PCM format.
    // Our wav file writer only supports SignedInt sample type.
    QAudioFormat format;
    format.setChannelCount(2);
    format.setSampleSize(16);
    format.setSampleRate(48000);
    format.setCodec("audio/pcm");
    format.setSampleType(QAudioFormat::SignedInt);
    m_decoder.setAudioFormat(format);

    connect(&m_decoder, SIGNAL(bufferReady()), this, SLOT(bufferReady()));
    connect(&m_decoder, SIGNAL(error(QAudioDecoder::Error)), this, SLOT(error(QAudioDecoder::Error)));
    connect(&m_decoder, SIGNAL(stateChanged(QAudioDecoder::State)), this, SLOT(stateChanged(QAudioDecoder::State)));
    connect(&m_decoder, SIGNAL(finished()), this, SLOT(finished()));
    connect(&m_decoder, SIGNAL(positionChanged(qint64)), this, SLOT(updateProgress()));
    connect(&m_decoder, SIGNAL(durationChanged(qint64)), this, SLOT(updateProgress()));

    connect(&m_soundEffect, SIGNAL(statusChanged()), this, SLOT(playbackStatusChanged()));
    connect(&m_soundEffect, SIGNAL(playingChanged()), this, SLOT(playingChanged()));

    m_progress = -1.0;
}
开发者ID:MarianMMX,项目名称:MarianMMX,代码行数:28,代码来源:audiodecoder.cpp

示例14: slotAudioModeChanged

void xmppClient::slotAudioModeChanged(QIODevice::OpenMode mode)
{
    QXmppCall *call = qobject_cast<QXmppCall*>(sender());
    Q_ASSERT(call);
    QXmppRtpAudioChannel *channel = call->audioChannel();

    // prepare audio format
    QAudioFormat format;
    format.setSampleRate(channel->payloadType().clockrate());
    format.setChannelCount(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.sampleRate() * format.channelCount() * (format.sampleSize() / 8) * 160) / 1000;

    if (mode & QIODevice::ReadOnly) {
        // initialise audio output
        QAudioOutput *audioOutput = new QAudioOutput(format, this);
        audioOutput->setBufferSize(bufferSize);
        audioOutput->start(channel);
    }

    if (mode & QIODevice::WriteOnly) {
        // initialise audio input
        QAudioInput *audioInput = new QAudioInput(format, this);
        audioInput->setBufferSize(bufferSize);
        audioInput->start(channel);
    }
}
开发者ID:ninoles,项目名称:qxmpp,代码行数:33,代码来源:example_4_callHandling.cpp

示例15: InitializeAudio

void InitializeAudio()
{
    m_format.setSampleRate(SampleRate); //set frequency to 44100
    m_format.setChannelCount(1); //set channels to mono
    m_format.setSampleSize(16); //set sample sze to 16 bit
    m_format.setSampleType(QAudioFormat::SignedInt ); //Sample type as usigned integer sample UnSignedInt
    m_format.setByteOrder(QAudioFormat::LittleEndian); //Byte order
    m_format.setCodec("audio/pcm"); //set codec as simple audio/pcm

    QAudioDeviceInfo infoIn(QAudioDeviceInfo::defaultInputDevice());
    if (!infoIn.isFormatSupported(m_format))
    {
        //Default format not supported - trying to use nearest
        m_format = infoIn.nearestFormat(m_format);
    }

    QAudioDeviceInfo infoOut(QAudioDeviceInfo::defaultOutputDevice());

    if (!infoOut.isFormatSupported(m_format))
    {
       //Default format not supported - trying to use nearest
        m_format = infoOut.nearestFormat(m_format);
    }

    m_audioInput = new QAudioInput(m_Inputdevice, m_format);
    m_audioOutput = new QAudioOutput(m_Outputdevice, m_format);
}
开发者ID:narnru,项目名称:project-tuner,代码行数:27,代码来源:main.cpp


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