本文整理汇总了C++中QAudioFormat::sampleRate方法的典型用法代码示例。如果您正苦于以下问题:C++ QAudioFormat::sampleRate方法的具体用法?C++ QAudioFormat::sampleRate怎么用?C++ QAudioFormat::sampleRate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAudioFormat
的用法示例。
在下文中一共展示了QAudioFormat::sampleRate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: writeHeader
bool WaveFileWriter::writeHeader(const QAudioFormat &format)
{
// check if format is supported
if (format.byteOrder() == QAudioFormat::BigEndian || format.sampleType() != QAudioFormat::SignedInt)
return false;
CombinedHeader header;
memset(&header, 0, HeaderLength);
#ifndef Q_LITTLE_ENDIAN
// only implemented for LITTLE ENDIAN
return false;
#else
// RIFF header
memcpy(header.riff.descriptor.id, "RIFF", 4);
header.riff.descriptor.size = 0; // this will be updated with correct duration:
// m_dataLength + HeaderLength - 8
// WAVE header
memcpy(header.riff.type, "WAVE", 4);
memcpy(header.wave.descriptor.id, "fmt ", 4);
header.wave.descriptor.size = quint32(16);
header.wave.audioFormat = quint16(1);
header.wave.numChannels = quint16(format.channelCount());
header.wave.sampleRate = quint32(format.sampleRate());
header.wave.byteRate = quint32(format.sampleRate() * format.channelCount() * format.sampleSize() / 8);
header.wave.blockAlign = quint16(format.channelCount() * format.sampleSize() / 8);
header.wave.bitsPerSample = quint16(format.sampleSize());
// DATA header
memcpy(header.data.descriptor.id,"data", 4);
header.data.descriptor.size = 0; // this will be updated with correct data length: m_dataLength
return (file.write(reinterpret_cast<const char *>(&header), HeaderLength) == HeaderLength);
#endif
}
示例2: generateData
void Generator::generateData(const QAudioFormat &format, qint64 durationUs, int sampleRate)
{
const int channelBytes = format.sampleSize() / 8;
qint64 length = (format.sampleRate() * format.channelCount() * (format.sampleSize() / 8))
* durationUs / 1000000;
m_buffer.resize(length);
unsigned char *ptr = reinterpret_cast<unsigned char *>(m_buffer.data());
int sampleIndex = 0;
PHDBG() << "Type :" << format.sampleType() << " Size : " << format.sampleSize() << " Channel Count : " << format.channelCount();
while (length) {
const qreal x = qSin(2 * M_PI * sampleRate * qreal(sampleIndex % format.sampleRate()) / format.sampleRate());
for (int i = 0; i < format.channelCount(); ++i) {
qint16 value = static_cast<qint16>(x * 32767);
qToLittleEndian<qint16>(value, ptr);
ptr += channelBytes;
length -= channelBytes;
}
++sampleIndex;
}
}
示例3: generateData
void Generator::generateData(const QAudioFormat &format, qint64 durationUs, int sampleRate)
{
const int channelBytes = format.sampleSize() / 8;//разрядность
const int sampleBytes = format.channelCount() * channelBytes;//количество байт умнож на кол-во каналов
qint64 length = (format.sampleRate() * format.channelCount() * (format.sampleSize() / 8))
* durationUs / 1000000;
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 * sampleRate * qreal(sampleIndex % format.sampleRate()) / format.sampleRate());
for (int i=0; i<format.channelCount(); ++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;
}
}
示例4: setFormat
void AudioDevice::setFormat(const QAudioFormat& format) {
if (!m_context || !mCoreThreadIsActive(m_context)) {
LOG(QT, INFO) << tr("Can't set format of context-less audio device");
return;
}
double fauxClock = GBAAudioCalculateRatio(1, m_context->impl->sync.fpsTarget, 1);
mCoreSyncLockAudio(&m_context->impl->sync);
blip_set_rates(m_context->core->getAudioChannel(m_context->core, 0),
m_context->core->frequency(m_context->core), format.sampleRate() * fauxClock);
blip_set_rates(m_context->core->getAudioChannel(m_context->core, 1),
m_context->core->frequency(m_context->core), format.sampleRate() * fauxClock);
mCoreSyncUnlockAudio(&m_context->impl->sync);
}
示例5: qDebug
bool Lockin2::start(const QAudioDeviceInfo &audioDevice, const QAudioFormat &format)
{
if (_audioInput != 0) {
qDebug() << __FUNCTION__ << ": lockin is already running, please stop is before start";
return false;
}
if (!format.isValid()) {
qDebug() << __FUNCTION__ << ": format not valid";
return false;
}
if (!isFormatSupported(format)) {
qDebug() << __FUNCTION__ << ": format not supported for lockin2";
return false;
}
if (audioDevice.isFormatSupported(format)) {
_audioInput = new QAudioInput(audioDevice, format, this);
_audioInput->setNotifyInterval(_outputPeriod * 1000.0);
connect(_audioInput, SIGNAL(notify()), this, SLOT(interpretInput()));
connect(_audioInput, SIGNAL(stateChanged(QAudio::State)), this, SLOT(audioStateChanged(QAudio::State)));
// pour être au millieu avec le temps
_timeValue = -(_integrationTime / 2.0);
// nombre d'échantillons pour le temps d'integration
_sampleIntegration = format.sampleRate() * _integrationTime;
// nombre d'échantillons pour un affichage de vumeter
_sampleVumeter = _vumeterTime * format.sampleRate();
// nettoyage des variables
_fifo->readAll(); // vide le fifo
_dataXY.clear(); // vide <x,y>
_format = format;
_audioInput->start(_fifo);
} else {
qDebug() << __FUNCTION__ << ": format not supported, can't start";
return false;
}
return true;
}
示例6: if
ViAudioFormat::ViAudioFormat(const QAudioFormat &other)
{
if(other.sampleType() == QAudioFormat::SignedInt)
{
setSampleType(ViAudioFormat::SignedInt);
}
else if(other.sampleType() == QAudioFormat::UnSignedInt)
{
setSampleType(ViAudioFormat::UnSignedInt);
}
else if(other.sampleType() == QAudioFormat::Float)
{
setSampleType(ViAudioFormat::Float);
}
else
{
setSampleSize(ViAudioFormat::Unknown);
}
if(other.byteOrder() == QAudioFormat::BigEndian)
{
setByteOrder(ViAudioFormat::BigEndian);
}
else
{
setByteOrder(ViAudioFormat::LittleEndian);
}
mQuality = ViAudioFormat::Average;
mSampleSize = other.sampleSize();
mSampleRate = other.sampleRate();
mChannelCount = other.channelCount();
mCodec = NULL;
}
示例7: 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();
}
}
}
示例8: toAudioStreamBasicDescription
AudioStreamBasicDescription toAudioStreamBasicDescription(QAudioFormat const& audioFormat)
{
AudioStreamBasicDescription sf;
sf.mFormatFlags = kAudioFormatFlagIsPacked;
sf.mSampleRate = audioFormat.sampleRate();
sf.mFramesPerPacket = 1;
sf.mChannelsPerFrame = audioFormat.channelCount();
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;
}
示例9: audioFormatToSampleSpec
pa_sample_spec audioFormatToSampleSpec(const QAudioFormat &format)
{
pa_sample_spec spec;
spec.rate = format.sampleRate();
spec.channels = format.channelCount();
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;
}
示例10: setFormat
void AudioDevice::setFormat(const QAudioFormat& format) {
if (!m_context || !GBAThreadIsActive(m_context)) {
return;
}
#if RESAMPLE_LIBRARY == RESAMPLE_NN
GBAThreadInterrupt(m_context);
m_ratio = GBAAudioCalculateRatio(m_context->gba->audio.sampleRate, m_context->fpsTarget, format.sampleRate());
GBAThreadContinue(m_context);
#elif RESAMPLE_LIBRARY == RESAMPLE_BLIP_BUF
double fauxClock = GBAAudioCalculateRatio(1, m_context->fpsTarget, 1);
GBASyncLockAudio(&m_context->sync);
blip_set_rates(m_context->gba->audio.left, GBA_ARM7TDMI_FREQUENCY, format.sampleRate() * fauxClock);
blip_set_rates(m_context->gba->audio.right, GBA_ARM7TDMI_FREQUENCY, format.sampleRate() * fauxClock);
GBASyncUnlockAudio(&m_context->sync);
#endif
}
示例11: 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);
}
}
示例12: audioLength
qint64 audioLength(const QAudioFormat &format, qint64 microSeconds)
{
qint64 result = (format.sampleRate() * format.channelCount() * (format.sampleSize() / 8))
* microSeconds / 1000000;
result -= result % (format.channelCount() * format.sampleSize());
return result;
}
示例13: QIODevice
Generator::Generator(QAudioFormat format, QObject *parent) : QIODevice(parent)
{
//create fast FIR LPF
fastfir = new QJFastFIRFilter(this);
fastfir->setKernel(QJFilterDesign::LowPassHanning(800,format.sampleRate(),2111));
}
示例14: file
void tst_QWaveDecoder::file()
{
QFETCH(QString, file);
QFETCH(tst_QWaveDecoder::Corruption, corruption);
QFETCH(int, channels);
QFETCH(int, samplesize);
QFETCH(int, samplerate);
QFETCH(QAudioFormat::Endian, byteorder);
QFile stream;
stream.setFileName(file);
stream.open(QIODevice::ReadOnly);
QVERIFY(stream.isOpen());
QWaveDecoder waveDecoder(&stream);
QSignalSpy validFormatSpy(&waveDecoder, SIGNAL(formatKnown()));
QSignalSpy parsingErrorSpy(&waveDecoder, SIGNAL(parsingError()));
if (corruption == NotAWav) {
QSKIP("Not all failures detected correctly yet");
QTRY_COMPARE(parsingErrorSpy.count(), 1);
QCOMPARE(validFormatSpy.count(), 0);
} else if (corruption == NoSampleData) {
QTRY_COMPARE(validFormatSpy.count(), 1);
QCOMPARE(parsingErrorSpy.count(), 0);
QVERIFY(waveDecoder.audioFormat().isValid());
QVERIFY(waveDecoder.size() == 0);
QVERIFY(waveDecoder.duration() == 0);
} else if (corruption == FormatDescriptor) {
QTRY_COMPARE(parsingErrorSpy.count(), 1);
QCOMPARE(validFormatSpy.count(), 0);
} else if (corruption == FormatString) {
QTRY_COMPARE(parsingErrorSpy.count(), 1);
QCOMPARE(validFormatSpy.count(), 0);
QVERIFY(!waveDecoder.audioFormat().isValid());
} else if (corruption == DataDescriptor) {
QTRY_COMPARE(parsingErrorSpy.count(), 1);
QCOMPARE(validFormatSpy.count(), 0);
QVERIFY(waveDecoder.size() == 0);
} else if (corruption == None) {
QTRY_COMPARE(validFormatSpy.count(), 1);
QCOMPARE(parsingErrorSpy.count(), 0);
QVERIFY(waveDecoder.audioFormat().isValid());
QVERIFY(waveDecoder.size() > 0);
QVERIFY(waveDecoder.duration() == 250);
QAudioFormat format = waveDecoder.audioFormat();
QVERIFY(format.isValid());
QVERIFY(format.channelCount() == channels);
QVERIFY(format.sampleSize() == samplesize);
QVERIFY(format.sampleRate() == samplerate);
if (format.sampleSize() != 8) {
QVERIFY(format.byteOrder() == byteorder);
}
}
stream.close();
}
示例15: audioLength
// Returns position in bytes, given position in microSeconds.
qint64 audioLength(const QAudioFormat &format, qint64 microSeconds)
{
// format.sampleRate() is in Hz, format.sampleSize() in bits
qint64 result = (format.sampleRate() * format.channelCount() * (format.sampleSize() / 8))
* microSeconds / 1000000;
// Round off to start of the channel 0.
result -= result % (format.channelCount() * format.sampleSize());
return result;
}