本文整理汇总了C++中QAudioFormat::sampleType方法的典型用法代码示例。如果您正苦于以下问题:C++ QAudioFormat::sampleType方法的具体用法?C++ QAudioFormat::sampleType怎么用?C++ QAudioFormat::sampleType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAudioFormat
的用法示例。
在下文中一共展示了QAudioFormat::sampleType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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);
}
}
示例3: 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;
}
示例4: 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;
}
}
示例5: 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.channelCount());
switch (format.channelCount()) {
case 1:
formatChannels = "mono";
break;
case 2:
formatChannels = "stereo";
break;
}
result = QString("%1 Hz %2 bit %3 %4 %5")
.arg(format.sampleRate())
.arg(format.sampleSize())
.arg(formatType)
.arg(formatEndian)
.arg(formatChannels);
} else {
result = format.codec();
}
}
return result;
}
示例6: 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
}
示例7: QMemoryAudioBufferProvider
QMemoryAudioBufferProvider(const void *data, int frameCount, const QAudioFormat &format, qint64 startTime)
: mStartTime(startTime)
, mFrameCount(frameCount)
, mFormat(format)
{
int numBytes = format.bytesForFrames(frameCount);
if (numBytes > 0) {
mBuffer = malloc(numBytes);
if (!mBuffer) {
// OOM, if that's likely
mStartTime = -1;
mFrameCount = 0;
mFormat = QAudioFormat();
} else {
// Allocated, see if we have data to copy
if (data) {
memcpy(mBuffer, data, numBytes);
} else {
// We have to fill with the zero value..
switch (format.sampleType()) {
case QAudioFormat::SignedInt:
// Signed int means 0x80, 0x8000 is zero
// XXX this is not right for > 8 bits(0x8080 vs 0x8000)
memset(mBuffer, 0x80, numBytes);
break;
default:
memset(mBuffer, 0x0, numBytes);
}
}
}
} else
mBuffer = 0;
}
示例8: open
bool WaveFileWriter::open(const QString& fileName, const QAudioFormat& format)
{
if (file.isOpen())
return false; // file already open
if (format.codec() != "audio/pcm" || format.sampleType() != QAudioFormat::SignedInt)
return false; // data format is not supported
if (fileName == "stdout")
{
if (!file.open(stdout, QIODevice::WriteOnly))
return false;
}
else
{
file.setFileName(fileName);
if (!file.open(QIODevice::WriteOnly))
return false; // unable to open file for writing
}
if (!writeHeader(format))
return false;
m_format = format;
return true;
}
示例9: 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;
}
}
示例10: 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;
}
示例11: isPCMS16LE
bool isPCMS16LE(const QAudioFormat &format)
{
return isPCM(format) &&
format.sampleType() == QAudioFormat::SignedInt &&
format.sampleSize() == 16 &&
format.byteOrder() == QAudioFormat::LittleEndian;
}
示例12: nearestFormat
/*!
Returns the closest QAudioFormat to the supplied \a settings that the system supports.
These settings are provided by the platform/audio plugin being used.
They are also dependent on the \l {QAudio}::Mode being used.
*/
QAudioFormat QAudioDeviceInfo::nearestFormat(const QAudioFormat &settings) const
{
if (isFormatSupported(settings))
return settings;
QAudioFormat nearest = settings;
QList<QString> testCodecs = supportedCodecs();
QList<int> testChannels = supportedChannelCounts();
QList<QAudioFormat::Endian> testByteOrders = supportedByteOrders();
QList<QAudioFormat::SampleType> testSampleTypes;
QList<QAudioFormat::SampleType> sampleTypesAvailable = supportedSampleTypes();
QMap<int,int> testSampleRates;
QList<int> sampleRatesAvailable = supportedSampleRates();
QMap<int,int> testSampleSizes;
QList<int> sampleSizesAvailable = supportedSampleSizes();
// Get sorted lists for checking
if (testCodecs.contains(settings.codec())) {
testCodecs.removeAll(settings.codec());
testCodecs.insert(0, settings.codec());
}
testChannels.removeAll(settings.channelCount());
testChannels.insert(0, settings.channelCount());
testByteOrders.removeAll(settings.byteOrder());
testByteOrders.insert(0, settings.byteOrder());
if (sampleTypesAvailable.contains(settings.sampleType()))
testSampleTypes.append(settings.sampleType());
if (sampleTypesAvailable.contains(QAudioFormat::SignedInt))
testSampleTypes.append(QAudioFormat::SignedInt);
if (sampleTypesAvailable.contains(QAudioFormat::UnSignedInt))
testSampleTypes.append(QAudioFormat::UnSignedInt);
if (sampleTypesAvailable.contains(QAudioFormat::Float))
testSampleTypes.append(QAudioFormat::Float);
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;
bool isMultiple = ( 0 == (larger % smaller));
int diff = larger - smaller;
testSampleSizes.insert((isMultiple ? diff : diff+100000), size);
}
示例13: qMultiplySamples
void qMultiplySamples(qreal factor, const QAudioFormat &format, const void* src, void* dest, int len)
{
int samplesCount = len / (format.sampleSize()/8);
switch ( format.sampleSize() ) {
case 8:
if (format.sampleType() == QAudioFormat::SignedInt)
QAudioHelperInternal::adjustSamples<qint8>(factor,src,dest,samplesCount);
else if (format.sampleType() == QAudioFormat::UnSignedInt)
QAudioHelperInternal::adjustUnsignedSamples<quint8>(factor,src,dest,samplesCount);
break;
case 16:
if (format.sampleType() == QAudioFormat::SignedInt)
QAudioHelperInternal::adjustSamples<qint16>(factor,src,dest,samplesCount);
else if (format.sampleType() == QAudioFormat::UnSignedInt)
QAudioHelperInternal::adjustUnsignedSamples<quint16>(factor,src,dest,samplesCount);
break;
default:
if (format.sampleType() == QAudioFormat::SignedInt)
QAudioHelperInternal::adjustSamples<qint32>(factor,src,dest,samplesCount);
else if (format.sampleType() == QAudioFormat::UnSignedInt)
QAudioHelperInternal::adjustUnsignedSamples<quint32>(factor,src,dest,samplesCount);
else if (format.sampleType() == QAudioFormat::Float)
QAudioHelperInternal::adjustSamples<float>(factor,src,dest,samplesCount);
}
}
示例14: generateData
void Generator::generateData(const QAudioFormat& format, unsigned char* ptr, qint64 length)
{
const int channelBytes = format.sampleSize() / 8;
if (length <= 0)
return;
QMutexLocker lock(m_mutex);
QVector<qreal> channels;
channels.resize(2);
// LOG_INFO() << "generating Sounds" << QDateTime::currentDateTime() << length;
initializeSounds();
while (length) {
generateTone(channels[0], channels[1], m_sampleIndex);
//const qreal x = soundFunc(2 * M_PI * frequency * qreal(sampleIndex ) / 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 + channels[i]) / 2 * 255);
*reinterpret_cast<quint8*>(ptr) = value;
} else if (format.sampleSize() == 8 && format.sampleType() == QAudioFormat::SignedInt) {
const qint8 value = static_cast<qint8>(channels[i] * 127);
*reinterpret_cast<quint8*>(ptr) = value;
} else if (format.sampleSize() == 16 && format.sampleType() == QAudioFormat::UnSignedInt) {
quint16 value = static_cast<quint16>((1.0 + channels[i]) / 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>(channels[i] * 32767);
if (format.byteOrder() == QAudioFormat::LittleEndian)
qToLittleEndian<qint16>(value, ptr);
else
qToBigEndian<qint16>(value, ptr);
}
ptr += channelBytes;
length -= channelBytes;
}
++m_sampleIndex;
}
}
示例15: play
void TSoundOutputDeviceImp::play(const TSoundTrackP &st, TINT32 s0, TINT32 s1,
bool loop, bool scrubbing) {
if (!doSetStreamFormat(st->getFormat())) return;
MyData *myData = new MyData();
myData->imp = shared_from_this();
myData->totalPacketCount = s1 - s0;
myData->fileByteCount = (s1 - s0) * st->getSampleSize();
myData->entireFileBuffer = new char[myData->fileByteCount];
memcpy(myData->entireFileBuffer, st->getRawData() + s0 * st->getSampleSize(),
myData->fileByteCount);
m_isPlaying = true;
myData->isLooping = loop;
QAudioFormat format;
QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
format.setSampleSize(st->getBitPerSample());
format.setCodec("audio/pcm");
format.setChannelCount(st->getChannelCount());
format.setByteOrder(QAudioFormat::LittleEndian);
format.setSampleType(st->getFormat().m_signedSample
? QAudioFormat::SignedInt
: QAudioFormat::UnSignedInt);
format.setSampleRate(st->getSampleRate());
QList<QAudioFormat::Endian> sbos = info.supportedByteOrders();
QList<int> sccs = info.supportedChannelCounts();
QList<int> ssrs = info.supportedSampleRates();
QList<QAudioFormat::SampleType> sstypes = info.supportedSampleTypes();
QList<int> ssss = info.supportedSampleSizes();
QStringList supCodes = info.supportedCodecs();
if (!info.isFormatSupported((format))) {
format = info.nearestFormat(format);
int newChannels = format.channelCount();
int newBitsPerSample = format.sampleSize();
int newSampleRate = format.sampleRate();
QAudioFormat::SampleType newSampleType = format.sampleType();
QAudioFormat::Endian newBo = format.byteOrder();
}
int test = st->getSampleCount() / st->getSampleRate();
QByteArray *data =
new QByteArray(myData->entireFileBuffer, myData->fileByteCount);
QBuffer *newBuffer = new QBuffer;
newBuffer->setBuffer(data);
newBuffer->open(QIODevice::ReadOnly);
newBuffer->seek(0);
if (m_audioOutput == NULL) {
m_audioOutput = new QAudioOutput(format, NULL);
}
m_audioOutput->start(newBuffer);
m_audioOutput->setVolume(m_volume);
}