diff options
Diffstat (limited to 'examples/multimedia')
-rw-r--r-- | examples/multimedia/audiodevices/audiodevices.cpp | 24 | ||||
-rw-r--r-- | examples/multimedia/audioinput/audioinput.cpp | 79 | ||||
-rw-r--r-- | examples/multimedia/audioinput/audioinput.h | 35 | ||||
-rw-r--r-- | examples/multimedia/audiooutput/audiooutput.cpp | 30 |
4 files changed, 86 insertions, 82 deletions
diff --git a/examples/multimedia/audiodevices/audiodevices.cpp b/examples/multimedia/audiodevices/audiodevices.cpp index a193f3d..6373d57 100644 --- a/examples/multimedia/audiodevices/audiodevices.cpp +++ b/examples/multimedia/audiodevices/audiodevices.cpp @@ -96,8 +96,8 @@ void AudioTest::test() } else { QAudioFormat nearest = deviceInfo.nearestFormat(settings); logOutput->append(tr("Failed")); - nearestFreq->setText(QString("%1").arg(nearest.frequency())); - nearestChannel->setText(QString("%1").arg(nearest.channels())); + nearestFreq->setText(QString("%1").arg(nearest.sampleRate())); + nearestChannel->setText(QString("%1").arg(nearest.channelCount())); nearestCodec->setText(nearest.codec()); nearestSampleSize->setText(QString("%1").arg(nearest.sampleSize())); @@ -149,18 +149,18 @@ void AudioTest::deviceChanged(int idx) deviceInfo = deviceBox->itemData(idx).value<QAudioDeviceInfo>(); frequencyBox->clear(); - QList<int> freqz = deviceInfo.supportedFrequencies(); - for (int i = 0; i < freqz.size(); ++i) + QList<int> freqz = deviceInfo.supportedSampleRates(); + for(int i = 0; i < freqz.size(); ++i) frequencyBox->addItem(QString("%1").arg(freqz.at(i))); - if (freqz.size()) - settings.setFrequency(freqz.at(0)); + if(freqz.size()) + settings.setSampleRate(freqz.at(0)); channelsBox->clear(); - QList<int> chz = deviceInfo.supportedChannels(); - for (int i = 0; i < chz.size(); ++i) + QList<int> chz = deviceInfo.supportedChannelCounts(); + for(int i = 0; i < chz.size(); ++i) channelsBox->addItem(QString("%1").arg(chz.at(i))); - if (chz.size()) - settings.setChannels(chz.at(0)); + if(chz.size()) + settings.setChannelCount(chz.at(0)); codecsBox->clear(); QStringList codecz = deviceInfo.supportedCodecs(); @@ -217,12 +217,12 @@ void AudioTest::deviceChanged(int idx) void AudioTest::freqChanged(int idx) { // freq has changed - settings.setFrequency(frequencyBox->itemText(idx).toInt()); + settings.setSampleRate(frequencyBox->itemText(idx).toInt()); } void AudioTest::channelChanged(int idx) { - settings.setChannels(channelsBox->itemText(idx).toInt()); + settings.setChannelCount(channelsBox->itemText(idx).toInt()); } void AudioTest::codecChanged(int idx) diff --git a/examples/multimedia/audioinput/audioinput.cpp b/examples/multimedia/audioinput/audioinput.cpp index eed1bbc..86650da 100644 --- a/examples/multimedia/audioinput/audioinput.cpp +++ b/examples/multimedia/audioinput/audioinput.cpp @@ -52,8 +52,8 @@ #define BUFFER_SIZE 4096 -AudioInfo::AudioInfo(QObject* parent, QAudioInput* device) - :QIODevice( parent ) +AudioInfo::AudioInfo(QObject *parent, QAudioInput *device) + :QIODevice(parent) { input = device; @@ -90,21 +90,24 @@ qint64 AudioInfo::writeData(const char *data, qint64 len) m_maxValue = 0; - qint16* s = (qint16*)data; + qint16 *s = (qint16*)data; // sample format is S16LE, only! - for(int i=0;i<samples;i++) { + for (int i = 0; i < samples; ++i) { qint16 sample = *s; s++; - if(abs(sample) > m_maxValue) m_maxValue = abs(sample); + if (abs(sample) > m_maxValue) m_maxValue = abs(sample); } // check for clipping - if(m_maxValue>=(maxAmp-1)) clipping = true; + if (m_maxValue >= (maxAmp - 1)) + clipping = true; float value = ((float)m_maxValue/(float)maxAmp); - if(clipping) m_maxValue = 100; - else m_maxValue = (int)(value*100); + if (clipping) + m_maxValue = 100; + else + m_maxValue = (int)(value*100); emit update(); @@ -132,25 +135,25 @@ void RenderArea::paintEvent(QPaintEvent * /* event */) QPainter painter(this); painter.setPen(Qt::black); - painter.drawRect(QRect(painter.viewport().left()+10, painter.viewport().top()+10, - painter.viewport().right()-20, painter.viewport().bottom()-20)); - - if(level == 0) + painter.drawRect(QRect(painter.viewport().left()+10, + painter.viewport().top()+10, + painter.viewport().right()-20, + painter.viewport().bottom()-20)); + if (level == 0) return; painter.setPen(Qt::red); int pos = ((painter.viewport().right()-20)-(painter.viewport().left()+11))*level/100; - int x1,y1,x2,y2; - for(int i=0;i<10;i++) { - x1 = painter.viewport().left()+11; - y1 = painter.viewport().top()+10+i; - x2 = painter.viewport().left()+20+pos; - y2 = painter.viewport().top()+10+i; - if(x2 < painter.viewport().left()+10) + for (int i = 0; i < 10; ++i) { + int x1 = painter.viewport().left()+11; + int y1 = painter.viewport().top()+10+i; + int x2 = painter.viewport().left()+20+pos; + int y2 = painter.viewport().top()+10+i; + if (x2 < painter.viewport().left()+10) x2 = painter.viewport().left()+10; - painter.drawLine(QPoint(x1,y1),QPoint(x2,y2)); + painter.drawLine(QPoint(x1, y1),QPoint(x2, y2)); } } @@ -171,20 +174,20 @@ InputTest::InputTest() deviceBox = new QComboBox(this); QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::availableDevices(QAudio::AudioInput); - for(int i = 0; i < devices.size(); ++i) { + for(int i = 0; i < devices.size(); ++i) deviceBox->addItem(devices.at(i).deviceName(), qVariantFromValue(devices.at(i))); - } - connect(deviceBox,SIGNAL(activated(int)),SLOT(deviceChanged(int))); + + connect(deviceBox, SIGNAL(activated(int)), SLOT(deviceChanged(int))); layout->addWidget(deviceBox); button = new QPushButton(this); button->setText(tr("Click for Push Mode")); - connect(button,SIGNAL(clicked()),SLOT(toggleMode())); + connect(button, SIGNAL(clicked()), SLOT(toggleMode())); layout->addWidget(button); button2 = new QPushButton(this); button2->setText(tr("Click To Suspend")); - connect(button2,SIGNAL(clicked()),SLOT(toggleSuspend())); + connect(button2, SIGNAL(clicked()), SLOT(toggleSuspend())); layout->addWidget(button2); window->setLayout(layout); @@ -195,8 +198,8 @@ InputTest::InputTest() pullMode = true; - format.setFrequency(8000); - format.setChannels(1); + format.setSampleRate(8000); + format.setChannelCount(1); format.setSampleSize(16); format.setSampleType(QAudioFormat::SignedInt); format.setByteOrder(QAudioFormat::LittleEndian); @@ -214,10 +217,10 @@ InputTest::InputTest() } audioInput = new QAudioInput(format,this); - connect(audioInput,SIGNAL(notify()),SLOT(status())); - connect(audioInput,SIGNAL(stateChanged(QAudio::State)),SLOT(state(QAudio::State))); + connect(audioInput, SIGNAL(notify()), SLOT(status())); + connect(audioInput, SIGNAL(stateChanged(QAudio::State)), SLOT(state(QAudio::State))); audioinfo = new AudioInfo(this,audioInput); - connect(audioinfo,SIGNAL(update()),SLOT(refreshDisplay())); + connect(audioinfo, SIGNAL(update()), SLOT(refreshDisplay())); audioinfo->start(); audioInput->start(audioinfo); } @@ -250,7 +253,7 @@ void InputTest::toggleMode() if (pullMode) { button->setText(tr("Click for Pull Mode")); input = audioInput->start(); - connect(input,SIGNAL(readyRead()),SLOT(readMore())); + connect(input, SIGNAL(readyRead()), SLOT(readMore())); pullMode = false; } else { button->setText(tr("Click for Push Mode")); @@ -263,25 +266,25 @@ void InputTest::toggleSuspend() { // toggle suspend/resume if(audioInput->state() == QAudio::SuspendedState) { - qWarning()<<"status: Suspended, resume()"; + qWarning() << "status: Suspended, resume()"; audioInput->resume(); button2->setText("Click To Suspend"); } else if (audioInput->state() == QAudio::ActiveState) { - qWarning()<<"status: Active, suspend()"; + qWarning() << "status: Active, suspend()"; audioInput->suspend(); button2->setText("Click To Resume"); } else if (audioInput->state() == QAudio::StoppedState) { - qWarning()<<"status: Stopped, resume()"; + qWarning() << "status: Stopped, resume()"; audioInput->resume(); button2->setText("Click To Suspend"); } else if (audioInput->state() == QAudio::IdleState) { - qWarning()<<"status: IdleState"; + qWarning() << "status: IdleState"; } } void InputTest::state(QAudio::State state) { - qWarning()<<" state="<<state; + qWarning() << " state=" << state; } void InputTest::refreshDisplay() @@ -299,8 +302,8 @@ void InputTest::deviceChanged(int idx) device = deviceBox->itemData(idx).value<QAudioDeviceInfo>(); audioInput = new QAudioInput(device, format, this); - connect(audioInput,SIGNAL(notify()),SLOT(status())); - connect(audioInput,SIGNAL(stateChanged(QAudio::State)),SLOT(state(QAudio::State))); + connect(audioInput, SIGNAL(notify()), SLOT(status())); + connect(audioInput, SIGNAL(stateChanged(QAudio::State)), SLOT(state(QAudio::State))); audioinfo->start(); audioInput->start(audioinfo); } diff --git a/examples/multimedia/audioinput/audioinput.h b/examples/multimedia/audioinput/audioinput.h index c4a8d0d..abe2be1 100644 --- a/examples/multimedia/audioinput/audioinput.h +++ b/examples/multimedia/audioinput/audioinput.h @@ -52,7 +52,7 @@ class AudioInfo : public QIODevice { Q_OBJECT public: - AudioInfo(QObject* parent, QAudioInput* device); + AudioInfo(QObject *parent, QAudioInput *device); ~AudioInfo(); void start(); @@ -63,7 +63,7 @@ public: qint64 readData(char *data, qint64 maxlen); qint64 writeData(const char *data, qint64 len); - QAudioInput* input; + QAudioInput *input; private: int m_maxValue; @@ -97,21 +97,6 @@ public: InputTest(); ~InputTest(); - QAudioDeviceInfo device; - QAudioFormat format; - QAudioInput* audioInput; - AudioInfo* audioinfo; - QIODevice* input; - RenderArea* canvas; - - bool pullMode; - - QPushButton* button; - QPushButton* button2; - QComboBox* deviceBox; - - char* buffer; - private slots: void refreshDisplay(); void status(); @@ -120,5 +105,21 @@ private slots: void toggleSuspend(); void state(QAudio::State s); void deviceChanged(int idx); + +private: + AudioInfo *audioinfo; + QAudioDeviceInfo device; + QAudioFormat format; + QAudioInput *audioInput; + QIODevice *input; + RenderArea *canvas; + + bool pullMode; + + QPushButton *button; + QPushButton *button2; + QComboBox *deviceBox; + + char *buffer; }; diff --git a/examples/multimedia/audiooutput/audiooutput.cpp b/examples/multimedia/audiooutput/audiooutput.cpp index a04b14a..58dbbaf 100644 --- a/examples/multimedia/audiooutput/audiooutput.cpp +++ b/examples/multimedia/audiooutput/audiooutput.cpp @@ -103,10 +103,10 @@ int Generator::fillData(char *start, int frequency, int seconds) qint64 Generator::readData(char *data, qint64 maxlen) { int len = maxlen; - if(len > 16384) + if (len > 16384) len = 16384; - if(len < (SECONDS*SYSTEM_FREQ*2)-pos) { + if (len < (SECONDS*SYSTEM_FREQ*2)-pos) { // Normal memcpy(data,t+pos,len); pos+=len; @@ -164,8 +164,8 @@ AudioTest::AudioTest() gen->start(); - settings.setFrequency(SYSTEM_FREQ); - settings.setChannels(1); + settings.setSampleRate(SYSTEM_FREQ); + settings.setChannelCount(1); settings.setSampleSize(16); settings.setCodec("audio/pcm"); settings.setByteOrder(QAudioFormat::LittleEndian); @@ -212,15 +212,15 @@ void AudioTest::deviceChanged(int idx) void AudioTest::status() { - qWarning()<<"byteFree = "<<audioOutput->bytesFree()<<" bytes, elapsedUSecs = "<<audioOutput->elapsedUSecs()<<", processedUSecs = "<<audioOutput->processedUSecs(); + qWarning() << "byteFree = " << audioOutput->bytesFree() << " bytes, elapsedUSecs = " << audioOutput->elapsedUSecs() << ", processedUSecs = " << audioOutput->processedUSecs(); } void AudioTest::writeMore() { - if(!audioOutput) + if (!audioOutput) return; - if(audioOutput->state() == QAudio::StoppedState) + if (audioOutput->state() == QAudio::StoppedState) return; int l; @@ -229,9 +229,9 @@ void AudioTest::writeMore() int chunks = audioOutput->bytesFree()/audioOutput->periodSize(); while(chunks) { l = gen->read(buffer,audioOutput->periodSize()); - if(l > 0) + if (l > 0) out = output->write(buffer,l); - if(l != audioOutput->periodSize()) + if (l != audioOutput->periodSize()) break; chunks--; } @@ -259,24 +259,24 @@ void AudioTest::toggle() void AudioTest::togglePlay() { // toggle suspend/resume - if(audioOutput->state() == QAudio::SuspendedState) { - qWarning()<<"status: Suspended, resume()"; + if (audioOutput->state() == QAudio::SuspendedState) { + qWarning() << "status: Suspended, resume()"; audioOutput->resume(); button2->setText("Click To Suspend"); } else if (audioOutput->state() == QAudio::ActiveState) { - qWarning()<<"status: Active, suspend()"; + qWarning() << "status: Active, suspend()"; audioOutput->suspend(); button2->setText("Click To Resume"); } else if (audioOutput->state() == QAudio::StoppedState) { - qWarning()<<"status: Stopped, resume()"; + qWarning() << "status: Stopped, resume()"; audioOutput->resume(); button2->setText("Click To Suspend"); } else if (audioOutput->state() == QAudio::IdleState) { - qWarning()<<"status: IdleState"; + qWarning() << "status: IdleState"; } } void AudioTest::state(QAudio::State state) { - qWarning()<<" state="<<state; + qWarning() << " state=" << state; } |