本文整理汇总了C++中QAudioFormat::frequency方法的典型用法代码示例。如果您正苦于以下问题:C++ QAudioFormat::frequency方法的具体用法?C++ QAudioFormat::frequency怎么用?C++ QAudioFormat::frequency使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAudioFormat
的用法示例。
在下文中一共展示了QAudioFormat::frequency方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
示例2: audioLength
qint64 audioLength(const QAudioFormat &format, qint64 microSeconds)
{
qint64 result = (format.frequency() * format.channels() * (format.sampleSize() / 8))
* microSeconds / 1000000;
result -= result % (format.channelCount() * format.sampleSize());
return result;
}
示例3: audioFormatToSampleSpec
pa_sample_spec audioFormatToSampleSpec(const QAudioFormat &format)
{
pa_sample_spec spec;
spec.rate = format.frequency();
spec.channels = format.channels();
if (format.sampleSize() == 8) {
spec.format = PA_SAMPLE_U8;
} else if (format.sampleSize() == 16) {
switch (format.byteOrder()) {
case QAudioFormat::BigEndian: spec.format = PA_SAMPLE_S16BE; break;
case QAudioFormat::LittleEndian: spec.format = PA_SAMPLE_S16LE; break;
}
} else if (format.sampleSize() == 24) {
switch (format.byteOrder()) {
case QAudioFormat::BigEndian: spec.format = PA_SAMPLE_S24BE; break;
case QAudioFormat::LittleEndian: spec.format = PA_SAMPLE_S24LE; break;
}
} else if (format.sampleSize() == 32) {
switch (format.byteOrder()) {
case QAudioFormat::BigEndian:
format.sampleType() == QAudioFormat::Float ? spec.format = PA_SAMPLE_FLOAT32BE : spec.format = PA_SAMPLE_S32BE;
break;
case QAudioFormat::LittleEndian:
format.sampleType() == QAudioFormat::Float ? spec.format = PA_SAMPLE_FLOAT32LE : spec.format = PA_SAMPLE_S32LE;
break;
}
} else {
spec.format = PA_SAMPLE_INVALID;
}
return spec;
}
示例4: toAudioStreamBasicDescription
AudioStreamBasicDescription toAudioStreamBasicDescription(QAudioFormat const& audioFormat)
{
AudioStreamBasicDescription sf;
sf.mFormatFlags = kAudioFormatFlagIsPacked;
sf.mSampleRate = audioFormat.frequency();
sf.mFramesPerPacket = 1;
sf.mChannelsPerFrame = audioFormat.channels();
sf.mBitsPerChannel = audioFormat.sampleSize();
sf.mBytesPerFrame = sf.mChannelsPerFrame * (sf.mBitsPerChannel / 8);
sf.mBytesPerPacket = sf.mFramesPerPacket * sf.mBytesPerFrame;
sf.mFormatID = kAudioFormatLinearPCM;
switch (audioFormat.sampleType()) {
case QAudioFormat::SignedInt: sf.mFormatFlags |= kAudioFormatFlagIsSignedInteger; break;
case QAudioFormat::UnSignedInt: /* default */ break;
case QAudioFormat::Float: sf.mFormatFlags |= kAudioFormatFlagIsFloat; break;
case QAudioFormat::Unknown: default: break;
}
if (audioFormat.byteOrder() == QAudioFormat::BigEndian)
sf.mFormatFlags |= kAudioFormatFlagIsBigEndian;
return sf;
}
示例5: calculate
void SpectrumAnalyser::calculate(const QByteArray &buffer,
const QAudioFormat &format, bool isSample,char phoneme)
{
// QThread::currentThread is marked 'for internal use only', but
// we're only using it for debug output here, so it's probably OK :)
SPECTRUMANALYSER_DEBUG << "SpectrumAnalyser::calculate"
<< QThread::currentThread()
<< "state" << m_state;
if (isReady()) {
Q_ASSERT(isPCMS16LE(format));
const int bytesPerSample = format.sampleSize() * format.channels() / 8;
#ifdef DUMP_SPECTRUMANALYSER
m_count++;
const QString pcmFileName = m_outputDir.filePath(QString("spectrum_%1.pcm").arg(m_count, 4, 10, QChar('0')));
QFile pcmFile(pcmFileName);
pcmFile.open(QIODevice::WriteOnly);
const int bufferLength = m_numSamples * bytesPerSample;
pcmFile.write(buffer, bufferLength);
m_textStream << "TimeDomain " << m_count << "\n";
const qint16* input = reinterpret_cast<const qint16*>(buffer);
for (int i=0; i<m_numSamples; ++i) {
m_textStream << i << "\t" << *input << "\n";
input += format.channels();
}
#endif
m_state = Busy;
// Invoke SpectrumAnalyserThread::calculateSpectrum using QMetaObject. If
// m_thread is in a different thread from the current thread, the
// calculation will be done in the child thread.
// Once the calculation is finished, a calculationChanged signal will be
// emitted by m_thread.
const bool b = QMetaObject::invokeMethod(m_thread, "calculateSpectrum",
Qt::AutoConnection,
Q_ARG(QByteArray, buffer),
Q_ARG(int, format.frequency()),
Q_ARG(int, bytesPerSample),
Q_ARG(bool,isSample),
Q_ARG(char,phoneme));
Q_ASSERT(b);
Q_UNUSED(b) // suppress warnings in release builds
#ifdef DUMP_SPECTRUMANALYSER
m_textStream << "FrequencySpectrum " << m_count << "\n";
FrequencySpectrum::const_iterator x = m_spectrum.begin();
for (int i=0; i<m_numSamples; ++i, ++x)
m_textStream << i << "\t"
<< x->frequency << "\t"
<< x->amplitude<< "\t"
<< x->phase << "\n";
#endif
}
}
示例6: generateData
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;
}
}
示例7: 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).
bool failed = false;
// For now, just accept only audio/pcm codec
if(!format.codec().startsWith(QLatin1String("audio/pcm")))
failed = true;
if(!failed && !(format.channels() == 1 || format.channels() == 2))
failed = true;
if(!failed) {
if(!(format.frequency() == 8000 || format.frequency() == 11025 || format.frequency() == 22050 ||
format.frequency() == 44100 || format.frequency() == 48000 || format.frequency() == 96000))
failed = true;
}
if(!failed && !(format.sampleSize() == 8 || format.sampleSize() == 16))
failed = true;
if(!failed) {
// settings work
return true;
}
return false;
}
示例8: formatToString
QString formatToString(const QAudioFormat &format)
{
QString result;
if (QAudioFormat() != format) {
if (format.codec() == "audio/pcm") {
Q_ASSERT(format.sampleType() == QAudioFormat::SignedInt);
const QString formatEndian = (format.byteOrder() == QAudioFormat::LittleEndian)
? QString("LE") : QString("BE");
QString formatType;
switch(format.sampleType()) {
case QAudioFormat::SignedInt:
formatType = "signed";
break;
case QAudioFormat::UnSignedInt:
formatType = "unsigned";
break;
case QAudioFormat::Float:
formatType = "float";
break;
case QAudioFormat::Unknown:
formatType = "unknown";
break;
}
QString formatChannels = QString("%1 channels").arg(format.channels());
switch (format.channels()) {
case 1:
formatChannels = "mono";
break;
case 2:
formatChannels = "stereo";
break;
}
result = QString("%1 Hz %2 bit %3 %4 %5")
.arg(format.frequency())
.arg(format.sampleSize())
.arg(formatType)
.arg(formatEndian)
.arg(formatChannels);
} else {
result = format.codec();
}
}
return result;
}
示例9: isFormatSupported
bool QAudioDeviceInfoInternal::isFormatSupported(
const QAudioFormat &format) const
{
getSupportedFormats();
bool supported = false;
if (m_capabilities.contains(format.codec())) {
const Capabilities &codecCaps = m_capabilities[format.codec()];
supported = codecCaps.m_frequencies.contains(format.frequency())
&& codecCaps.m_channels.contains(format.channels())
&& codecCaps.m_sampleSizes.contains(format.sampleSize())
&& codecCaps.m_byteOrders.contains(format.byteOrder())
&& codecCaps.m_sampleTypes.contains(format.sampleType());
}
return supported;
}
示例10:
QT_BEGIN_NAMESPACE
// Debugging
QDebug operator<<(QDebug dbg, const QAudioFormat& audioFormat)
{
dbg.nospace() << "QAudioFormat(" <<
audioFormat.frequency() << "," <<
audioFormat.channels() << "," <<
audioFormat.sampleSize()<< "," <<
audioFormat.codec() << "," <<
audioFormat.byteOrder() << "," <<
audioFormat.sampleType() << ")";
return dbg.space();
}
示例11: test
void AudioTest::test()
{
// tries to set all the settings picked.
logOutput->clear();
logOutput->append("NOTE: an invalid codec audio/test exists for testing, to get a fail condition.");
if (!deviceInfo.isNull()) {
if (deviceInfo.isFormatSupported(settings)) {
logOutput->append(tr("Success"));
nearestFreq->setText("");
nearestChannel->setText("");
nearestCodec->setText("");
nearestSampleSize->setText("");
nearestSampleType->setText("");
nearestEndian->setText("");
} else {
QAudioFormat nearest = deviceInfo.nearestFormat(settings);
logOutput->append(tr("Failed"));
nearestFreq->setText(QString("%1").arg(nearest.frequency()));
nearestChannel->setText(QString("%1").arg(nearest.channels()));
nearestCodec->setText(nearest.codec());
nearestSampleSize->setText(QString("%1").arg(nearest.sampleSize()));
switch(nearest.sampleType()) {
case QAudioFormat::SignedInt:
nearestSampleType->setText("SignedInt");
break;
case QAudioFormat::UnSignedInt:
nearestSampleType->setText("UnSignedInt");
break;
case QAudioFormat::Float:
nearestSampleType->setText("Float");
break;
case QAudioFormat::Unknown:
nearestSampleType->setText("Unknown");
}
switch(nearest.byteOrder()) {
case QAudioFormat::LittleEndian:
nearestEndian->setText("LittleEndian");
break;
case QAudioFormat::BigEndian:
nearestEndian->setText("BigEndian");
}
}
}
else
logOutput->append(tr("No Device"));
}
示例12: audioLength
qint64 audioLength(const QAudioFormat &format, qint64 microSeconds)
{
return (format.frequency() * format.channels() * (format.sampleSize() / 8))
* microSeconds / 1000000;
}
示例13: audioDuration
qint64 audioDuration(const QAudioFormat &format, qint64 bytes)
{
return (bytes * 1000000) /
(format.frequency() * format.channels() * (format.sampleSize() / 8));
}
示例14: 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( ¶ms );
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)
//.........这里部分代码省略.........
示例15: nyquistFrequency
qreal nyquistFrequency(const QAudioFormat &format)
{
return format.frequency() / 2;
}