本文整理汇总了C++中QAudioFormat类的典型用法代码示例。如果您正苦于以下问题:C++ QAudioFormat类的具体用法?C++ QAudioFormat怎么用?C++ QAudioFormat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QAudioFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: stop
void CAudioOutputTest::start(const QString &filePath, const QAudioDeviceInfo &audioDeviceInfo)
{
stop();
if(m_PCMIODevice)
{
m_PCMIODevice->deleteLater();
m_PCMIODevice = NULL;
}
m_PCMIODevice = new CPCMIODevice(filePath,this);
connect(m_PCMIODevice,SIGNAL(readChannelFinished()),this,SLOT(onStateChanged()));
QAudioFormat format;
format.setSampleRate(44100);
format.setChannelCount(2);
format.setSampleSize(16);
format.setCodec("audio/pcm");
format.setByteOrder(QAudioFormat::LittleEndian);
format.setSampleType(QAudioFormat::SignedInt);
QAudioDeviceInfo info(audioDeviceInfo);
if (!info.isFormatSupported(format)) {
// qWarning() << "Default format not supported - trying to use nearest";
format = info.nearestFormat(format);
}
if(m_audioOutput)
{
delete m_audioOutput;
m_audioOutput = 0;
}
m_audioOutput = new QAudioOutput(audioDeviceInfo, format, this);
connect(m_audioOutput,SIGNAL(stateChanged(QAudio::State)),this,SLOT(onStateChanged()));
if(m_PCMIODevice)
{
m_PCMIODevice->start();
}
m_audioOutput->start(m_PCMIODevice);
}
示例2: QtSoundInit
static int QtSoundInit()
{
qDebug() << __func__;
nQtAudioFps = nAppVirtualFps;
nAudSegLen = (nAudSampleRate[0] * 100 + (nQtAudioFps / 2)) / nQtAudioFps;
// seglen * 2 channels * 2 bytes per sample (16bits)
nAudAllocSegLen = nAudSegLen * 4;
// seg * nsegs * 2 channels
if (qSoundBuffer != nullptr)
delete qSoundBuffer;
qSoundBuffer = new QAudioInterfaceBuffer();
qSoundBuffer->setBufferSize(nAudAllocSegLen * nAudSegCount);
nAudNextSound = new short[nAudAllocSegLen / sizeof(short)];
QtSoundSetCallback(nullptr);
QtSoundGetNextSoundFiller(0);
//qSoundBuffer->writeData((const char *) nAudNextSound, nAudAllocSegLen);
//qSoundBuffer->writeData((const char *) nAudNextSound, nAudAllocSegLen);
pBurnSoundOut = nAudNextSound;
nBurnSoundRate = nAudSampleRate[0];
nBurnSoundLen = nAudAllocSegLen;
qAudio = QAudioInterface::get();
qAudio->setBuffer(qSoundBuffer);
QAudioFormat format;
format.setChannelCount(2);
format.setSampleRate(nAudSampleRate[0]);
format.setSampleType(QAudioFormat::SignedInt);
format.setByteOrder(QAudioFormat::LittleEndian);
format.setSampleSize(16);
qAudio->setFormat(format);
// we need to invoke this method on sound's thread, so we can't call this
// method from our object
QMetaObject::invokeMethod(qAudio, "init", Qt::QueuedConnection);
bAudOkay = 1;
return 0;
}
示例3: run
void MainAudio::run()
{
QAudioFormat fmt;
fmt.setSampleRate(AUDIO_FREQ);
fmt.setCodec("audio/pcm");
fmt.setChannelCount(AUDIO_CHANNELS);
fmt.setSampleSize(AUDIO_SAMPLESIZE);
fmt.setByteOrder(QAudioFormat::LittleEndian);
fmt.setSampleType(QAudioFormat::SignedInt);
mixlen = sizeof(short)*AUDIO_BUFFERS*AUDIO_CHANNELS*AUDIO_SAMPLES;
mixbuf = (char*)malloc(mixlen);
output = new QAudioOutput(fmt);
output->setBufferSize(mixlen);
feed = output->start();
if (feed != NULL) {
// buffering has already done in the internal mixed buffer
// use a small interval to copy mixed audio stream from
// internal buffer to audio output buffer as soon as possible
// use 1 instead of 0 to prevent CPU exhausting
timer = startTimer(1);
}
}
示例4: QThread
/*!
Constructor.
*/
AudioOut::AudioOut(AudioSource *source, QObject *parent /* = 0 */)
: QThread(parent),
m_audioOutput(0),
m_outTarget(0),
m_source(source),
m_sendBuffer(0),
m_sendBufferSize(0),
m_samplesMixed(0),
m_threadState(NotRunning),
m_usingThread(false)
{
QAudioFormat format;
format.setFrequency(AUDIO_FREQUENCY);
format.setChannels(GEDefaultChannelCount);
format.setSampleSize(AUDIO_SAMPLE_BITS);
format.setCodec(GEDefaultAudioCodec);
format.setByteOrder(GEByteOrder);
format.setSampleType(GESampleType);
QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
if (!info.isFormatSupported(format))
format = info.nearestFormat(format);
m_audioOutput = new QAudioOutput(info, format);
m_audioOutput->setBufferSize(4096 * 8);
m_sendBufferSize = 4096 * 8;
m_outTarget = m_audioOutput->start();
DEBUG_INFO("Buffer size: " << m_audioOutput->bufferSize());
m_sendBuffer = new AUDIO_SAMPLE_TYPE[m_sendBufferSize];
#ifndef Q_OS_SYMBIAN
m_usingThread = true;
start();
#endif
}
示例5: AudioDevice
void AudioProcessorQt::start() {
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_device->setInput(input());
m_device->setFormat(m_audioOutput->format());
m_audioOutput->setBufferSize(input()->audioBuffers * 4);
m_audioOutput->start(m_device);
}
示例6: addHeader
void AudioFileWav::addHeader(const QAudioFormat& audioFormat) {
QDataStream stream(&_file);
stream.setByteOrder(QDataStream::LittleEndian);
// RIFF
stream.writeRawData("RIFF", 4);
stream << quint32(0);
stream.writeRawData("WAVE", 4);
// Format description PCM = 16
stream.writeRawData("fmt ", 4);
stream << quint32(16);
stream << quint16(1);
stream << quint16(audioFormat.channelCount());
stream << quint32(audioFormat.sampleRate());
stream << quint32(audioFormat.sampleRate() * audioFormat.channelCount() * audioFormat.sampleSize() / 8); // bytes per second
stream << quint16(audioFormat.channelCount() * audioFormat.sampleSize() / 8); // block align
stream << quint16(audioFormat.sampleSize()); // bits Per Sample
// Init data chunck
stream.writeRawData("data", 4);
stream << quint32(0);
}
示例7: startListening
void Engine::startListening()
{
QAudioFormat format;
// Set up the desired format, for example:
format.setSampleRate(8000);
format.setChannelCount(1);
format.setSampleSize(8);
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);
}
QAudioInput *audio = new QAudioInput(format, this);
QBuffer buffer;
audio->start(&buffer);
}
示例8: QMainWindow
MainWindow::MainWindow(vector<TimeOption> timeOptions_, QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
timer(this),
finishedSource(":/sounds/alarm.raw"),
timeOptions(timeOptions_)
{
ui->setupUi(this);
for (vector<TimeOption>::iterator it = timeOptions.begin(); it!= timeOptions.end(); ++ it) {
TimeOption o = *it;
ui->timeSelection->addItem(QString::fromStdString(o.name));
}
finishedSource.open(QIODevice::ReadOnly);
QAudioFormat format;
format.setSampleRate(44100);
format.setChannelCount(1);
format.setSampleSize(16);
format.setCodec("audio/pcm");
format.setByteOrder(QAudioFormat::LittleEndian);
format.setSampleType(QAudioFormat::SignedInt);
QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
if (!info.isFormatSupported(format)) {
qWarning() << "Raw audio format not supported by backend, cannot play audio.";
finishedSound = NULL;
} else {
finishedSound = new QAudioOutput(format, this);
//finishedSound->start(&finishedSource);
}
connect(ui->startTimer, SIGNAL(clicked()), this, SLOT(startCountDown()));
connect(&timer, SIGNAL(timeout()), this, SLOT(timerTick()));
connect(ui->fullscreen, SIGNAL(clicked()), this, SLOT(fullScreenClicked()));
}
示例9: qSin
void NotificationSound::playSound()
{
//QSound::play(":/sound/notification_sound.wav");
//return;
qreal frequency = ((sFrequency <= 0)?2000:sFrequency);
qreal mseconds = ((sDuration <= 0)?1000:sDuration);
quint8 volume = ((sVolume <= 0)?1:sVolume);
qreal sampleRate = 2.0 * M_PI / (192000./frequency);
QByteArray bytebuf;
bytebuf.resize(mseconds * 192);
for (int i=0; i < bytebuf.size(); i++) {
bytebuf[i] = (quint8)(qreal(255) * qSin(qreal(i) * sampleRate));
}
QDataStream stream(&bytebuf, QIODevice::ReadWrite);
QAudioFormat format;
format.setSampleRate(192000);
format.setChannelCount(1);
format.setSampleSize(8);
format.setCodec("audio/pcm");
format.setByteOrder(QAudioFormat::LittleEndian);
format.setSampleType(QAudioFormat::UnSignedInt);
QAudioOutput * audio = new QAudioOutput(format, this);
audio->setVolume(1.0 * (qreal(volume + 1)/4));
audio->setBufferSize(bytebuf.size());
audio->start(stream.device());
QEventLoop loop;
QTimer::singleShot(mseconds*2, &loop, SLOT(quit()));
loop.exec();
}
示例10: test_1
int test_1(QObject* a)
{
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;
}
char filename[1024];
printf("input file name :");
scanf("%s",filename);
fflush(stdin);
fflush(stdout);
printf("start audio \n");
QAudioOutput *audio;
audio = new QAudioOutput(format, a);
QIODevice *out = audio->start();
#if 0
qDebug()<< out->isSequential() << " swquential"; // 不是顺序设备,是随机设备
#endif
decodeAndPlay(filename,out);
}
示例11: QCustomDialog
DlgEditMusic::DlgEditMusic(cMusicObject *TheMusicObject,cApplicationConfig *ApplicationConfig,QWidget *parent):
QCustomDialog(ApplicationConfig,parent), ui(new Ui::DlgEditMusic) {
ui->setupUi(this);
OkBt =ui->OKBT;
CancelBt =ui->CancelBt;
HelpBt =ui->HelpBt;
HelpFile ="0124";
MusicObject =TheMusicObject;
StopMaj =false;
InSliderMoveEvent =false;
IsInit =false;
PlayerPlayMode =false;
PlayerPauseMode =false;
IsSliderProcess =false;
ActualPosition =-1;
ResetPositionWanted =false;
AudioBuf =(u_int8_t *)malloc(AUDIOBUFSIZE);
AudioBufSize =0;
MixedMusic.SetFPS(double(1000)/ApplicationConfig->PreviewFPS,2,ApplicationConfig->PreviewSamplingRate,AV_SAMPLE_FMT_S16);
Music.SetFPS(MixedMusic.WantedDuration,MixedMusic.Channels,MixedMusic.SamplingRate,MixedMusic.SampleFormat);
// Set up the format
QAudioFormat format;
format.setCodec("audio/pcm");
format.setSampleRate(MixedMusic.SamplingRate); // Usually this is specified through an UI option
format.setChannelCount(MixedMusic.Channels);
format.setSampleSize(16);
format.setByteOrder(QAudioFormat::LittleEndian);
format.setSampleType(QAudioFormat::SignedInt);
// Create audio output stream, set up signals
audio_outputStream = new QAudioOutput(format,this);
}
示例12: GetStreamAudioFormat
QAudioFormat AudioTransmitter::GetStreamAudioFormat(void)
{
QAudioFormat format;
QAudioDeviceInfo info1 = QAudioDeviceInfo::defaultInputDevice();
format.setSampleRate(44100);
//format.setChannels(1);
format.setSampleSize(24);
format.setCodec("audio/pcm");
format.setByteOrder(QAudioFormat::LittleEndian);
format.setSampleType(QAudioFormat::UnSignedInt);
QAudioDeviceInfo info = QAudioDeviceInfo::defaultInputDevice();
if (!info.isFormatSupported(format))
format = info.nearestFormat(format);
QStringList list=info1.supportedCodecs();
foreach (const QString &str, list) {
qDebug()<<"codec: "<<str;
}
return format;
}
示例13: 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();
}
示例14: QThread
/*!
Constructor.
*/
PushAudioOut::PushAudioOut(AudioSource *source, QObject *parent /* = 0 */)
: QThread(parent),
m_audioOutput(0),
m_outTarget(0),
m_sendBuffer(0),
m_sendBufferSize(0),
m_samplesMixed(0),
m_threadState(NotRunning),
m_source(source)
{
DEBUG_INFO(this);
QAudioFormat format;
format.setFrequency(AUDIO_FREQUENCY);
format.setChannels(AUDIO_CHANNELS);
format.setSampleSize(AUDIO_SAMPLE_BITS);
format.setCodec(GEDefaultAudioCodec);
switch (GEByteOrder) {
case BigEndian:
format.setByteOrder(QAudioFormat::BigEndian);
break;
case LittleEndian:
format.setByteOrder(QAudioFormat::LittleEndian);
break;
default:
DEBUG_INFO("INVALID BYTE ORDER");
}
switch (GESampleType) {
case Unknown:
format.setSampleType(QAudioFormat::Unknown);
break;
case SignedInt:
format.setSampleType(QAudioFormat::SignedInt);
break;
case UnSignedInt:
format.setSampleType(QAudioFormat::UnSignedInt);
break;
case Float:
format.setSampleType(QAudioFormat::Float);
break;
default:
DEBUG_INFO("INVALID SAMPLE TYPE");
}
QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
if (!info.isFormatSupported(format))
format = info.nearestFormat(format);
m_audioOutput = new QAudioOutput(info, format);
#if defined(Q_WS_MAEMO_5) || defined(MEEGO_EDITION_HARMATTAN)
m_sendBufferSize = 4096 * 4;
#else
m_audioOutput->setBufferSize(4096 * 4);
#endif
#if defined(Q_WS_MAEMO_5) || defined(MEEGO_EDITION_HARMATTAN)
m_audioOutput->setBufferSize(4096 * 16);
m_sendBufferSize = 4096 * 8;
#else
m_audioOutput->setBufferSize(4096 * 4);
m_sendBufferSize = 4096 * 2;
#endif
DEBUG_INFO("Buffer size: " << m_audioOutput->bufferSize());
m_sendBuffer = new AUDIO_SAMPLE_TYPE[m_sendBufferSize];
m_needsTick = false;
#if defined(QTGAMEENABLER_USE_VOLUME_HACK) && defined(Q_OS_SYMBIAN)
DEBUG_INFO("WARNING: Using the volume hack!");
// This really ugly hack is used as the last resort. This allows us to
// adjust the application volume in Symbian. The CMMFDevSound object lies
// deep inside the QAudioOutput in Symbian implementation and it has the
// needed functions. So, we dig the required object accessing it directly
// from memory.
unsigned int *pointer_to_abstract_audio =
(unsigned int*)((unsigned char*)m_audioOutput + 8);
unsigned int *dev_sound_wrapper =
(unsigned int*)(*pointer_to_abstract_audio) + 13;
unsigned int *temp = ((unsigned int*)(*dev_sound_wrapper) + 6);
CMMFDevSound *devSound = (CMMFDevSound*)(*temp);
devSound->SetVolume(devSound->MaxVolume() * 6 / 10);
#endif
}
示例15: Q_ASSERT
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;
}
}