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


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

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


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

示例1: QVariant

QVariant S60AudioEncoderControl::encodingOption(const QString &codec, const QString &name) const
{
    if (codec == "PCM") {
        QAudioFormat fmt = m_session->format();
        
        if(qstrcmp(name.toLocal8Bit().constData(), "quality") == 0) {
            return QVariant(quality());
        }        
        else if(qstrcmp(name.toLocal8Bit().constData(), "channels") == 0) {
            return QVariant(fmt.channels());
        }                
        else if(qstrcmp(name.toLocal8Bit().constData(), "samplerate") == 0) {
            return QVariant(fmt.frequency());
        }       
    }
    return QVariant();
}
开发者ID:bavanisp,项目名称:qtmobility-1.1.0,代码行数:17,代码来源:s60audioencodercontrol.cpp

示例2: initialize

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;
}
开发者ID:Greedysky,项目名称:qmmp,代码行数:76,代码来源:outputqtmultimedia.cpp

示例3: testSettings

bool QAudioDeviceInfoInternal::testSettings(const QAudioFormat& format) const
{
    // Set nearest to closest settings that do work.
    // See if what is in settings will work (return value).
    int err = 0;
    snd_pcm_t* handle;
    snd_pcm_hw_params_t *params;
    QString dev = device;

    // open()
    if(!dev.contains(QLatin1String("default"))) {
        int idx = snd_card_get_index(dev.toLocal8Bit().constData());
        dev = QString(QLatin1String("hw:%1,0")).arg(idx);
    }
    if(mode == QAudio::AudioOutput) {
        err=snd_pcm_open( &handle,dev.toLocal8Bit().constData(),SND_PCM_STREAM_PLAYBACK,0);
    } else {
        err=snd_pcm_open( &handle,dev.toLocal8Bit().constData(),SND_PCM_STREAM_CAPTURE,0);
    }
    if(err < 0) {
        handle = 0;
        return false;
    }

    bool testChannel = false;
    bool testCodec = false;
    bool testFreq = false;
    bool testType = false;
    bool testSize = false;

    int  dir = 0;

    snd_pcm_nonblock( handle, 0 );
    snd_pcm_hw_params_alloca( &params );
    snd_pcm_hw_params_any( handle, params );

    // set the values!
    snd_pcm_hw_params_set_channels(handle,params,format.channels());
    snd_pcm_hw_params_set_rate(handle,params,format.frequency(),dir);
    switch(format.sampleSize()) {
        case 8:
            if(format.sampleType() == QAudioFormat::SignedInt)
                snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S8);
            else if(format.sampleType() == QAudioFormat::UnSignedInt)
                snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U8);
            break;
        case 16:
            if(format.sampleType() == QAudioFormat::SignedInt) {
                if(format.byteOrder() == QAudioFormat::LittleEndian)
                    snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S16_LE);
                else if(format.byteOrder() == QAudioFormat::BigEndian)
                    snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S16_BE);
            } else if(format.sampleType() == QAudioFormat::UnSignedInt) {
                if(format.byteOrder() == QAudioFormat::LittleEndian)
                    snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U16_LE);
                else if(format.byteOrder() == QAudioFormat::BigEndian)
                    snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U16_BE);
            }
            break;
        case 32:
            if(format.sampleType() == QAudioFormat::SignedInt) {
                if(format.byteOrder() == QAudioFormat::LittleEndian)
                    snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S32_LE);
                else if(format.byteOrder() == QAudioFormat::BigEndian)
                    snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S32_BE);
            } else if(format.sampleType() == QAudioFormat::UnSignedInt) {
                if(format.byteOrder() == QAudioFormat::LittleEndian)
                    snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U32_LE);
                else if(format.byteOrder() == QAudioFormat::BigEndian)
                    snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U32_BE);
            }
    }

    // For now, just accept only audio/pcm codec
    if(!format.codec().startsWith(QLatin1String("audio/pcm"))) {
        err=-1;
    } else
        testCodec = true;

    if(err>=0 && format.channels() != -1) {
        err = snd_pcm_hw_params_test_channels(handle,params,format.channels());
        if(err>=0)
            err = snd_pcm_hw_params_set_channels(handle,params,format.channels());
        if(err>=0)
            testChannel = true;
    }

    if(err>=0 && format.frequency() != -1) {
        err = snd_pcm_hw_params_test_rate(handle,params,format.frequency(),0);
        if(err>=0)
            err = snd_pcm_hw_params_set_rate(handle,params,format.frequency(),dir);
        if(err>=0)
            testFreq = true;
    }

    if((err>=0 && format.sampleSize() != -1) &&
            (format.sampleType() != QAudioFormat::Unknown)) {
        switch(format.sampleSize()) {
            case 8:
                if(format.sampleType() == QAudioFormat::SignedInt)
//.........这里部分代码省略.........
开发者ID:dtbinh,项目名称:dviz,代码行数:101,代码来源:qaudiodeviceinfo_alsa_p.cpp

示例4: audioDuration

qint64 audioDuration(const QAudioFormat &format, qint64 bytes)
{
    return (bytes * 1000000) /
        (format.frequency() * format.channels() * (format.sampleSize() / 8));
}
开发者ID:hongyunnchen,项目名称:qt-fft-realtime-spectrum,代码行数:5,代码来源:utils.cpp

示例5: PlayFile


//.........这里部分代码省略.........
	{
		// single-file compression
		// -> just decrunch to buffer
	
		//m_pArchiveHandler->openArchive(filename);
		//m_pArchiveHandler->openArchive(pView, nSize);
		
		//m_pFileBuffer = m_pArchiveHandler->decrunchToBuffer(pView, nSize);
	}
	else
	{
		// module file without compression, just use as-is.
		//
		// use buffer as interface to accessing memory-mapped file:
		// OS will generate pagefaults as needed
		//
		m_pFileBuffer = new CReadBuffer(pView, nSize);
	}

	// format-specific handling,
	// fileformat, playback-to-buffer etc.
    m_pModPlayer = GetPlayer(m_pFileBuffer);
    if (m_pModPlayer == nullptr)
    {
        emit error("Failed to create player");
        return;
    }
    
    if (m_pModPlayer->ParseFileInfo() == false)
    {
        emit error("File could not be handled");
        return;
    }
	
	// get decoding context: 
	// player should keep position/status information,
	// we want it to control position (if possible..)
	//
	// TODO: determine how we are able to output
	// (e.g. 256 tracker channels -> 2 channels in stereo,
	// 8/16-bit width?)
	// and check that device supports what is possible..
	//
	m_pCtx = m_pModPlayer->PrepareDecoder();
    
    // TODO: get info on what is suitable format for playing..
    // (what is supported by player/format/module..)
    //QAudioFormat format = pModPlayer->GetOutputFormat();
	// placeholder.. set output format
	// these will need changing later:
	// due to module-format support
	// and device-support we may need something or other..
    QAudioFormat format;
	format.setByteOrder(QAudioFormat::LittleEndian);
	format.setCodec("audio/pcm");
	format.setSampleRate(m_pCtx->sampleRate());
	format.setChannels(m_pCtx->channelCount());
	format.setSampleSize(m_pCtx->sampleSize());
	format.setSampleType(QAudioFormat::SignedInt);

	QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
    if (info.isNull() == true)
    {
        emit error("Failed to get default audio output");
		return;
    }
	if (info.isFormatSupported(format) == false)
	{
		emit error("Output format not supported");
		return;
	}

	// expect 2-channels and 8-bit samples at 44.1kHz,
    // get proper values later, expecting 1s buffer to be enough for now..
	//
    size_t nBuffer = (format.sampleRate() * format.channels() * (format.sampleSize()/8));
    m_pDecodeBuffer->PrepareBuffer(nBuffer, false);

	// get device for output
	m_pAudioOut = new QAudioOutput(format, this);
	connect(m_pAudioOut, SIGNAL(stateChanged(QAudio::State)), this, SLOT(onAudioState(QAudio::State)));
	connect(m_pAudioOut, SIGNAL(notify()), this, SLOT(onPlayNotify()));

	if (m_pAudioOut->bufferSize() < nBuffer)
	{
		m_pAudioOut->setBufferSize(nBuffer);
	}
    m_pAudioOut->setNotifyInterval(250); // 250ms

	// push-mode (we decode to buffer and push to device),
	// we might need different thread for no-gaps playback..
	m_pDevOut = m_pAudioOut->start();

	if (initialOutput() == false)
	{
		// failed, cleanup
		stopPlay(); // status message
		emit error("Failed on audiodevice write(): " + filename);
	}
}	
开发者ID:ipr,项目名称:qModPlay,代码行数:101,代码来源:PlaybackHandler.cpp

示例6: audioLength

qint64 audioLength(const QAudioFormat &format, qint64 microSeconds)
{
   return (format.frequency() * format.channels() * (format.sampleSize() / 8))
       * microSeconds / 1000000;
}
开发者ID:daborton,项目名称:RTVT,代码行数:5,代码来源:utils.cpp

示例7: checkChannels

void tst_QAudioFormat::checkChannels()
{
    QAudioFormat    audioFormat;
    audioFormat.setChannels(2);
    QVERIFY(audioFormat.channels() == 2);
}
开发者ID:KDE,项目名称:android-qt,代码行数:6,代码来源:tst_qaudioformat.cpp


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