本文整理汇总了C++中QAudioFormat::setByteOrder方法的典型用法代码示例。如果您正苦于以下问题:C++ QAudioFormat::setByteOrder方法的具体用法?C++ QAudioFormat::setByteOrder怎么用?C++ QAudioFormat::setByteOrder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAudioFormat
的用法示例。
在下文中一共展示了QAudioFormat::setByteOrder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QMainWindow
Demo::Demo(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Demo)
{
ui->setupUi(this);
//create pointers
QJFastFIRFilter *fastfir;
QJSlowFIRFilter *slowfir;
//create fast fir LPF
fastfir = new QJFastFIRFilter(this);
fastfir->setKernel(QJFilterDesign::LowPassHanning(800,48000,1001));
//create slow fir LPF
slowfir = new QJSlowFIRFilter(this);
slowfir->setKernel(QJFilterDesign::LowPassHanning(800,48000,1001));
//make some data
QVector<kffsamp_t> buf;
buf.resize(48000*10);
//time slow fir
timer.start();
slowfir->Update(buf);
nMilliseconds = timer.elapsed();
ui->plainTextEdit->appendPlainText(((QString)"Slow FIR took %1 ms for %2 double samples with a kernel of 1001 samples").arg(nMilliseconds).arg(buf.size()));
//time fast fir
timer.start();
fastfir->Update(buf);
nMilliseconds = timer.elapsed();
ui->plainTextEdit->appendPlainText(((QString)"Fast FIR took %1 ms for %2 double samples with a kernel of 1001 samples").arg(nMilliseconds).arg(buf.size()));
//use the fast fir to LPF some random samples and output them to the sound card
ui->plainTextEdit->appendPlainText("Outputting 800Hz low pass filtered random samples to the soundcard using the fast fir");
QAudioFormat format;
format.setChannelCount(1);
format.setCodec("audio/pcm");
format.setSampleRate(48000);
format.setSampleSize(16);
format.setByteOrder(QAudioFormat::LittleEndian);
format.setSampleType(QAudioFormat::SignedInt);
generator = new Generator(format, this);
QAudioOutput *audiooutput = new QAudioOutput(format, this);
generator->start();
audiooutput->start(generator);
}
示例2: checkByteOrder
void tst_QAudioFormat::checkByteOrder()
{
QAudioFormat audioFormat;
audioFormat.setByteOrder(QAudioFormat::LittleEndian);
QVERIFY(audioFormat.byteOrder() == QAudioFormat::LittleEndian);
QTest::ignoreMessage(QtDebugMsg, "LittleEndian");
qDebug() << QAudioFormat::LittleEndian;
audioFormat.setByteOrder(QAudioFormat::BigEndian);
QVERIFY(audioFormat.byteOrder() == QAudioFormat::BigEndian);
QTest::ignoreMessage(QtDebugMsg, "BigEndian");
qDebug() << QAudioFormat::BigEndian;
}
示例3: 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);
}
示例4: QObject
BeatController::BeatController(QAudioDeviceInfo inputDevice, uint16_t recordSize, uint32_t sampleRate, uint16_t m_bandCount, QObject *parent) : QObject(parent)
{
m_RecordSize = recordSize;
m_Buffer = new SoundBuffer(recordSize);
m_Analyser = new BeatAnalyser(m_bandCount,sampleRate,recordSize);
m_inputDevice = QAudioDeviceInfo(inputDevice);
m_FFT = new FFT(recordSize);
m_FFT->setSoundBuffer(m_Buffer);
m_Analyser->setFFT(m_FFT);
QAudioFormat audioFormat;
audioFormat.setSampleRate(sampleRate);
audioFormat.setChannelCount(1);
audioFormat.setSampleSize(16);
audioFormat.setSampleType(QAudioFormat::SignedInt);
audioFormat.setByteOrder(QAudioFormat::LittleEndian);
audioFormat.setCodec("audio/pcm");
//QAudioDeviceInfo info(QAudioDeviceInfo::defaultInputDevice());
if (!m_inputDevice.isFormatSupported(audioFormat)) {
qWarning() << "Default format not supported - trying to use nearest";
audioFormat = m_inputDevice.nearestFormat(audioFormat);
}
m_audioInput = new QAudioInput(m_inputDevice, audioFormat, this);
m_ioDevice = m_audioInput->start();
connect(m_ioDevice, SIGNAL(readyRead()), this, SLOT(readAudio()));
}
示例5: 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);
}
示例6: 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);
}
示例7: 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~";
}
示例8: 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);
}
}
示例9: 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);
}
示例10: QObject
FrequencyAnalyzer::FrequencyAnalyzer(QObject *parent) :
QObject(parent),
d_ptr(new FrequencyAnalyzerPrivate(this))
{
Q_D(FrequencyAnalyzer);
QAudioDeviceInfo info = QAudioDeviceInfo::defaultInputDevice();
qDebug() << "device name: " << info.deviceName() << "\n"
<< "supported frequency:" << info.supportedFrequencies() << "\n"
<< "supported codecs" << info.supportedCodecs() << "\n"
<< "supported sample sizes" << info.supportedSampleSizes() << "\n"
<< "supported sample types" << info.supportedSampleTypes() << "\n";
QAudioFormat format = info.preferredFormat();
format.setCodec("audio/pcm");
format.setByteOrder(QAudioFormat::LittleEndian);
format.setSampleType(QAudioFormat::SignedInt);
format.setSampleSize(32);
//format.setFrequency(d->sampling = 11025);
//format.setFrequency(d->sampling = 22050);
format.setFrequency(d->sampling = info.supportedFrequencies().last());
format.setChannelCount(1);
if (!info.isFormatSupported(format)) {
qWarning("Format is unsupported");
return;
}
d->input = new QAudioInput(info, format, this);
connect(d->input, SIGNAL(stateChanged(QAudio::State)), SLOT(_q_onStateChanged()));
}
示例11: 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);
}
示例12: 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);
}
}
示例13: 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);
}
示例14: readWavHeader
QAudioFormat readWavHeader(QIODevice *device)
{
CombinedHeader header;
bool result = device->read(reinterpret_cast<char *>(&header),
sizeof(CombinedHeader)) == sizeof(CombinedHeader);
QAudioFormat format;
if (result) {
if ((memcmp(&header.riff.descriptor.id, "RIFF", 4) == 0
|| memcmp(&header.riff.descriptor.id, "RIFX", 4) == 0)
&& memcmp(&header.riff.type, "WAVE", 4) == 0
&& memcmp(&header.wave.descriptor.id, "fmt ", 4) == 0
&& (header.wave.audioFormat == 1 || header.wave.audioFormat == 0)) {
// Read off remaining header information
DATAHeader dataHeader;
if (qFromLittleEndian<quint32>(header.wave.descriptor.size) > sizeof(WAVEHeader)) {
// Extended data available
quint16 extraFormatBytes;
if (device->peek((char*)&extraFormatBytes, sizeof(quint16)) != sizeof(quint16))
return format;
const qint64 throwAwayBytes = sizeof(quint16) + qFromLittleEndian<quint16>(extraFormatBytes);
if (device->read(throwAwayBytes).size() != throwAwayBytes)
return format;
}
if (device->read((char*)&dataHeader, sizeof(DATAHeader)) != sizeof(DATAHeader))
return format;
// Establish format
if (memcmp(&header.riff.descriptor.id, "RIFF", 4) == 0)
format.setByteOrder(QAudioFormat::LittleEndian);
else
format.setByteOrder(QAudioFormat::BigEndian);
int bps = qFromLittleEndian<quint16>(header.wave.bitsPerSample);
format.setChannelCount(qFromLittleEndian<quint16>(header.wave.numChannels));
format.setCodec("audio/pcm");
format.setSampleRate(qFromLittleEndian<quint32>(header.wave.sampleRate));
format.setSampleSize(qFromLittleEndian<quint16>(header.wave.bitsPerSample));
format.setSampleType(bps == 8 ? QAudioFormat::UnSignedInt : QAudioFormat::SignedInt);
}
}
return format;
}
示例15: selectFormat
bool Engine::selectFormat()
{
bool foundSupportedFormat = false;
if (m_file || QAudioFormat() != m_format) {
QAudioFormat format = m_format;
if (m_file)
// Header is read from the WAV file; just need to check whether
// it is supported by the audio output device
format = m_file->fileFormat();
if (m_audioOutputDevice.isFormatSupported(format)) {
setFormat(format);
foundSupportedFormat = true;
}
} else {
QList<int> sampleRatesList;
if (!m_generateTone)
sampleRatesList += m_audioOutputDevice.supportedSampleRates();
sampleRatesList = sampleRatesList.toSet().toList(); // remove duplicates
qSort(sampleRatesList);
ENGINE_DEBUG << "Engine::initialize frequenciesList" << sampleRatesList;
QList<int> channelsList;
channelsList += m_audioOutputDevice.supportedChannelCounts();
channelsList = channelsList.toSet().toList();
qSort(channelsList);
ENGINE_DEBUG << "Engine::initialize channelsList" << channelsList;
QAudioFormat format;
format.setByteOrder(QAudioFormat::LittleEndian);
format.setCodec("audio/pcm");
format.setSampleSize(16);
format.setSampleType(QAudioFormat::SignedInt);
int sampleRate, channels;
foreach (sampleRate, sampleRatesList) {
if (foundSupportedFormat)
break;
format.setSampleRate(sampleRate);
foreach (channels, channelsList) {
format.setChannelCount(channels);
const bool outputSupport = m_audioOutputDevice.isFormatSupported(format);
ENGINE_DEBUG << "Engine::initialize checking " << format
<< "output" << outputSupport;
if (outputSupport)
{
foundSupportedFormat = true;
break;
}
}
}
if (!foundSupportedFormat)
format = QAudioFormat();
setFormat(format);
}