本文整理汇总了C++中QAudioFormat::setSampleType方法的典型用法代码示例。如果您正苦于以下问题:C++ QAudioFormat::setSampleType方法的具体用法?C++ QAudioFormat::setSampleType怎么用?C++ QAudioFormat::setSampleType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAudioFormat
的用法示例。
在下文中一共展示了QAudioFormat::setSampleType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setQuality
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;
}
示例2: switch
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;
}
}
示例3: audioFormat
QAudioFormat audioFormat( const int channels, const int sampleRate, AVSampleFormat sampleFormat )
{
QAudioFormat format;
format.setChannelCount( channels );
format.setCodec( "audio/pcm" );
switch (sampleFormat)
{
case AV_SAMPLE_FMT_U8: ///< unsigned 8 bits
format.setSampleSize(8);
format.setSampleType( QAudioFormat::UnSignedInt );
break;
case AV_SAMPLE_FMT_S16: ///< signed 16 bits
format.setSampleSize(16);
format.setSampleType( QAudioFormat::SignedInt );
break;
case AV_SAMPLE_FMT_S32: ///< signed 32 bits
format.setSampleSize(32);
format.setSampleType( QAudioFormat::SignedInt );
break;
case AV_SAMPLE_FMT_FLT: ///< float
format.setSampleSize(16);
format.setSampleType( QAudioFormat::Float );
break;
case AV_SAMPLE_FMT_DBL: ///< double
format.setSampleSize(32);
format.setSampleType( QAudioFormat::Float );
break;
case AV_SAMPLE_FMT_U8P: ///< unsigned 8 bits: planar
format.setSampleSize(8);
format.setSampleType( QAudioFormat::UnSignedInt );
break;
case AV_SAMPLE_FMT_S16P: ///< signed 16 bits: planar
format.setSampleSize(16);
format.setSampleType( QAudioFormat::SignedInt );
break;
case AV_SAMPLE_FMT_S32P: ///< signed 32 bits: planar
format.setSampleSize(32);
format.setSampleType( QAudioFormat::SignedInt );
break;
case AV_SAMPLE_FMT_FLTP: ///< float: planar
format.setSampleSize(16);
format.setSampleType( QAudioFormat::SignedInt );
break;
case AV_SAMPLE_FMT_DBLP: ///< double, planar
format.setSampleSize(32);
format.setSampleType( QAudioFormat::SignedInt );
break;
default:
qWarning() << "codec format: " << sampleFormat << AV_SAMPLE_FMT_NONE;
return QAudioFormat();
}
format.setSampleRate( sampleRate );
return format;
}
示例4: 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;
}
示例5: 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);
}
}
示例6: 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);
}
示例7: slotConnected
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);
}
示例8: 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);
}
示例9: 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);
}
示例10: 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);
}
示例11: 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);
}
}
示例12: 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);
}
示例13: nearestFormat
QAudioFormat QAudioDeviceInfo::nearestFormat(const QAudioFormat &settings) const
{
if (isFormatSupported(settings))
return settings;
QAudioFormat nearest = settings;
nearest.setCodec(QLatin1String("audio/pcm"));
if (nearest.sampleType() == QAudioFormat::Unknown) {
QAudioFormat preferred = preferredFormat();
nearest.setSampleType(preferred.sampleType());
}
QMap<int,int> testFrequencies;
QList<int> frequenciesAvailable = supportedFrequencies();
QMap<int,int> testSampleSizes;
QList<int> sampleSizesAvailable = supportedSampleSizes();
// Get sorted sampleSizes (equal to and ascending values only)
if (sampleSizesAvailable.contains(settings.sampleSize()))
testSampleSizes.insert(0,settings.sampleSize());
sampleSizesAvailable.removeAll(settings.sampleSize());
foreach (int size, sampleSizesAvailable) {
int larger = (size > settings.sampleSize()) ? size : settings.sampleSize();
int smaller = (size > settings.sampleSize()) ? settings.sampleSize() : size;
if (size >= settings.sampleSize()) {
int diff = larger - smaller;
testSampleSizes.insert(diff, size);
}
}
示例14: 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~";
}
示例15: 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();
}
}