summaryrefslogtreecommitdiffstats
path: root/examples/multimedia
diff options
context:
space:
mode:
Diffstat (limited to 'examples/multimedia')
-rw-r--r--examples/multimedia/README34
-rw-r--r--examples/multimedia/audio/audio.pro10
-rw-r--r--examples/multimedia/audio/audiodevices/audiodevices.cpp272
-rw-r--r--examples/multimedia/audio/audiodevices/audiodevices.h79
-rw-r--r--examples/multimedia/audio/audiodevices/audiodevices.pro12
-rw-r--r--examples/multimedia/audio/audiodevices/audiodevicesbase.ui255
-rw-r--r--examples/multimedia/audio/audiodevices/main.cpp55
-rw-r--r--examples/multimedia/audio/audioinput/audioinput.cpp376
-rw-r--r--examples/multimedia/audio/audioinput/audioinput.h144
-rw-r--r--examples/multimedia/audio/audioinput/audioinput.pro12
-rw-r--r--examples/multimedia/audio/audioinput/main.cpp55
-rw-r--r--examples/multimedia/audio/audiooutput/audiooutput.cpp280
-rw-r--r--examples/multimedia/audio/audiooutput/audiooutput.h112
-rw-r--r--examples/multimedia/audio/audiooutput/audiooutput.pro11
-rw-r--r--examples/multimedia/audio/audiooutput/main.cpp56
-rw-r--r--examples/multimedia/multimedia.pro8
16 files changed, 1771 insertions, 0 deletions
diff --git a/examples/multimedia/README b/examples/multimedia/README
new file mode 100644
index 0000000..aa78e36
--- /dev/null
+++ b/examples/multimedia/README
@@ -0,0 +1,34 @@
+
+The example launcher provided with Qt can be used to explore each of the
+examples in this directory.
+
+Documentation for these examples can be found via the Tutorial and Examples
+link in the main Qt documentation.
+
+
+Finding the Qt Examples and Demos launcher
+==========================================
+
+On Windows:
+
+The launcher can be accessed via the Windows Start menu. Select the menu
+entry entitled "Qt Examples and Demos" entry in the submenu containing
+the Qt tools.
+
+On Mac OS X:
+
+For the binary distribution, the qtdemo executable is installed in the
+/Developer/Applications/Qt directory. For the source distribution, it is
+installed alongside the other Qt tools on the path specified when Qt is
+configured.
+
+On Unix/Linux:
+
+The qtdemo executable is installed alongside the other Qt tools on the path
+specified when Qt is configured.
+
+On all platforms:
+
+The source code for the launcher can be found in the demos/qtdemo directory
+in the Qt package. This example is built at the same time as the Qt libraries,
+tools, examples, and demonstrations.
diff --git a/examples/multimedia/audio/audio.pro b/examples/multimedia/audio/audio.pro
new file mode 100644
index 0000000..c64bb34
--- /dev/null
+++ b/examples/multimedia/audio/audio.pro
@@ -0,0 +1,10 @@
+TEMPLATE = subdirs
+SUBDIRS = audioinput \
+ audiooutput \
+ audiodevices
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/multimedia/audio
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS audio.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/multimedia/audio
+INSTALLS += target sources
diff --git a/examples/multimedia/audio/audiodevices/audiodevices.cpp b/examples/multimedia/audio/audiodevices/audiodevices.cpp
new file mode 100644
index 0000000..2a3af98
--- /dev/null
+++ b/examples/multimedia/audio/audiodevices/audiodevices.cpp
@@ -0,0 +1,272 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://www.qtsoftware.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <QDebug>
+#include <QAudioDeviceInfo>
+
+#include "audiodevices.h"
+
+AudioDevicesBase::AudioDevicesBase( QMainWindow *parent, Qt::WFlags f )
+{
+ Q_UNUSED(parent)
+ Q_UNUSED(f)
+ setupUi( this );
+}
+
+AudioDevicesBase::~AudioDevicesBase() {}
+
+
+AudioTest::AudioTest( QMainWindow *parent, Qt::WFlags f )
+ : AudioDevicesBase( parent, f )
+{
+ mode = QAudio::AudioOutput;
+ modeBox->addItem("Input");
+ modeBox->addItem("Output");
+
+ connect(testButton,SIGNAL(clicked()),SLOT(test()));
+ connect(modeBox,SIGNAL(activated(int)),SLOT(modeChanged(int)));
+ connect(deviceBox,SIGNAL(activated(int)),SLOT(deviceChanged(int)));
+ connect(frequencyBox,SIGNAL(activated(int)),SLOT(freqChanged(int)));
+ connect(channelsBox,SIGNAL(activated(int)),SLOT(channelChanged(int)));
+ connect(codecsBox,SIGNAL(activated(int)),SLOT(codecChanged(int)));
+ connect(sampleSizesBox,SIGNAL(activated(int)),SLOT(sampleSizeChanged(int)));
+ connect(sampleTypesBox,SIGNAL(activated(int)),SLOT(sampleTypeChanged(int)));
+ connect(endianBox,SIGNAL(activated(int)),SLOT(endianChanged(int)));
+
+ device = 0;
+
+ modeBox->setCurrentIndex(0);
+ modeChanged(0);
+ deviceBox->setCurrentIndex(0);
+ deviceChanged(0);
+}
+
+AudioTest::~AudioTest()
+{
+}
+
+void AudioTest::test()
+{
+ // tries to set all the settings picked.
+
+ if(device) {
+ if(device->isFormatSupported(settings)) {
+ logOutput->append("Success");
+ nearestFreq->setText("");
+ nearestChannel->setText("");
+ nearestCodec->setText("");
+ nearestSampleSize->setText("");
+ nearestSampleType->setText("");
+ nearestEndian->setText("");
+ } else {
+ QAudioFormat nearest = device->nearestFormat(settings);
+ logOutput->append(tr("Failed"));
+ nearestFreq->setText(QString("%1").arg(nearest.frequency()));
+ nearestChannel->setText(QString("%1").arg(nearest.channels()));
+ nearestCodec->setText(nearest.codec());
+ nearestSampleSize->setText(QString("%1").arg(nearest.sampleSize()));
+
+ switch(nearest.sampleType()) {
+ case QAudioFormat::SignedInt:
+ nearestSampleType->setText("SignedInt");
+ break;
+ case QAudioFormat::UnSignedInt:
+ nearestSampleType->setText("UnSignedInt");
+ break;
+ case QAudioFormat::Float:
+ nearestSampleType->setText("Float");
+ break;
+ case QAudioFormat::Unknown:
+ nearestSampleType->setText("Unknown");
+ }
+ switch(nearest.byteOrder()) {
+ case QAudioFormat::LittleEndian:
+ nearestEndian->setText("LittleEndian");
+ break;
+ case QAudioFormat::BigEndian:
+ nearestEndian->setText("BigEndian");
+ }
+ }
+ }
+ else
+ logOutput->append("No Device");
+}
+
+void AudioTest::modeChanged(int idx)
+{
+ // mode has changed
+ if(idx == 0)
+ mode=QAudio::AudioInput;
+ else
+ mode=QAudio::AudioOutput;
+
+ deviceBox->clear();
+ QList<QAudioDeviceId> devices = QAudioDeviceInfo::deviceList(mode);
+ for(int i = 0; i < devices.size(); ++i) {
+ deviceBox->addItem(QAudioDeviceInfo(devices.at(i)).deviceName(), qVariantFromValue(devices.at(i)));
+ }
+}
+
+void AudioTest::deviceChanged(int idx)
+{
+ delete device;
+ device = 0;
+
+ if (deviceBox->count() == 0)
+ return;
+
+ // device has changed
+ deviceHandle = deviceBox->itemData(idx).value<QAudioDeviceId>();
+ device = new QAudioDeviceInfo(deviceHandle, this);
+
+ frequencyBox->clear();
+ QList<int> freqz = device->supportedFrequencies();
+ for(int i = 0; i < freqz.size(); ++i)
+ frequencyBox->addItem(QString("%1").arg(freqz.at(i)));
+ if(freqz.size())
+ settings.setFrequency(freqz.at(0));
+
+ channelsBox->clear();
+ QList<int> chz = device->supportedChannels();
+ for(int i = 0; i < chz.size(); ++i)
+ channelsBox->addItem(QString("%1").arg(chz.at(i)));
+ if(chz.size())
+ settings.setChannels(chz.at(0));
+
+ codecsBox->clear();
+ QStringList codecz = device->supportedCodecs();
+ for(int i = 0; i < codecz.size(); ++i)
+ codecsBox->addItem(QString("%1").arg(codecz.at(i)));
+ if(codecz.size())
+ settings.setCodec(codecz.at(0));
+ // Add false to create failed condition!
+ codecsBox->addItem("audio/mpeg");
+
+ sampleSizesBox->clear();
+ QList<int> sampleSizez = device->supportedSampleSizes();
+ for(int i = 0; i < sampleSizez.size(); ++i)
+ sampleSizesBox->addItem(QString("%1").arg(sampleSizez.at(i)));
+ if(sampleSizez.size())
+ settings.setSampleSize(sampleSizez.at(0));
+
+ sampleTypesBox->clear();
+ QList<QAudioFormat::SampleType> sampleTypez = device->supportedSampleTypes();
+ for(int i = 0; i < sampleTypez.size(); ++i) {
+ switch(sampleTypez.at(i)) {
+ case QAudioFormat::SignedInt:
+ sampleTypesBox->addItem("SignedInt");
+ break;
+ case QAudioFormat::UnSignedInt:
+ sampleTypesBox->addItem("UnSignedInt");
+ break;
+ case QAudioFormat::Float:
+ sampleTypesBox->addItem("Float");
+ break;
+ case QAudioFormat::Unknown:
+ sampleTypesBox->addItem("Unknown");
+ }
+ if(sampleTypez.size())
+ settings.setSampleType(sampleTypez.at(0));
+ }
+
+ endianBox->clear();
+ QList<QAudioFormat::Endian> endianz = device->supportedByteOrders();
+ for(int i = 0; i < endianz.size(); ++i) {
+ switch(endianz.at(i)) {
+ case QAudioFormat::LittleEndian:
+ endianBox->addItem("Little Endian");
+ break;
+ case QAudioFormat::BigEndian:
+ endianBox->addItem("Big Endian");
+ break;
+ }
+ }
+ if(endianz.size())
+ settings.setByteOrder(endianz.at(0));
+}
+
+void AudioTest::freqChanged(int idx)
+{
+ // freq has changed
+ settings.setFrequency(frequencyBox->itemText(idx).toInt());
+}
+
+void AudioTest::channelChanged(int idx)
+{
+ settings.setChannels(channelsBox->itemText(idx).toInt());
+}
+
+void AudioTest::codecChanged(int idx)
+{
+ settings.setCodec(codecsBox->itemText(idx));
+}
+
+void AudioTest::sampleSizeChanged(int idx)
+{
+ settings.setSampleSize(sampleSizesBox->itemText(idx).toInt());
+}
+
+void AudioTest::sampleTypeChanged(int idx)
+{
+ switch(sampleTypesBox->itemText(idx).toInt()) {
+ case QAudioFormat::SignedInt:
+ settings.setSampleType(QAudioFormat::SignedInt);
+ break;
+ case QAudioFormat::UnSignedInt:
+ settings.setSampleType(QAudioFormat::UnSignedInt);
+ break;
+ case QAudioFormat::Float:
+ settings.setSampleType(QAudioFormat::Float);
+ }
+}
+
+void AudioTest::endianChanged(int idx)
+{
+ switch(endianBox->itemText(idx).toInt()) {
+ case QAudioFormat::LittleEndian:
+ settings.setByteOrder(QAudioFormat::LittleEndian);
+ break;
+ case QAudioFormat::BigEndian:
+ settings.setByteOrder(QAudioFormat::BigEndian);
+ }
+}
+
diff --git a/examples/multimedia/audio/audiodevices/audiodevices.h b/examples/multimedia/audio/audiodevices/audiodevices.h
new file mode 100644
index 0000000..34a531b
--- /dev/null
+++ b/examples/multimedia/audio/audiodevices/audiodevices.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://www.qtsoftware.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <QObject>
+#include <QMainWindow>
+#include <QAudioDeviceInfo>
+
+#include "ui_audiodevicesbase.h"
+
+class AudioDevicesBase : public QMainWindow, public Ui::AudioDevicesBase
+{
+public:
+ AudioDevicesBase( QMainWindow *parent = 0, Qt::WFlags f = 0 );
+ virtual ~AudioDevicesBase();
+};
+
+class AudioTest : public AudioDevicesBase
+{
+ Q_OBJECT
+public:
+ AudioTest( QMainWindow *parent = 0, Qt::WFlags f = 0 );
+ virtual ~AudioTest();
+
+ QAudioDeviceId deviceHandle;
+ QAudioDeviceInfo* device;
+ QAudioFormat settings;
+ QAudio::Mode mode;
+
+private slots:
+ void modeChanged(int idx);
+ void deviceChanged(int idx);
+ void freqChanged(int idx);
+ void channelChanged(int idx);
+ void codecChanged(int idx);
+ void sampleSizeChanged(int idx);
+ void sampleTypeChanged(int idx);
+ void endianChanged(int idx);
+ void test();
+};
+
diff --git a/examples/multimedia/audio/audiodevices/audiodevices.pro b/examples/multimedia/audio/audiodevices/audiodevices.pro
new file mode 100644
index 0000000..adc4890
--- /dev/null
+++ b/examples/multimedia/audio/audiodevices/audiodevices.pro
@@ -0,0 +1,12 @@
+HEADERS = audiodevices.h
+SOURCES = audiodevices.cpp \
+ main.cpp
+FORMS += audiodevicesbase.ui
+
+QT += multimedia
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/multimedia/audio/audiodevices
+sources.files = $$SOURCES *.h $$RESOURCES $$FORMS audiodevices.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/multimedia/audio/audiodevices
+INSTALLS += target sources
diff --git a/examples/multimedia/audio/audiodevices/audiodevicesbase.ui b/examples/multimedia/audio/audiodevices/audiodevicesbase.ui
new file mode 100644
index 0000000..674f201
--- /dev/null
+++ b/examples/multimedia/audio/audiodevices/audiodevicesbase.ui
@@ -0,0 +1,255 @@
+<ui version="4.0" >
+ <class>AudioDevicesBase</class>
+ <widget class="QMainWindow" name="AudioDevicesBase" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>504</width>
+ <height>702</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>AudioDevicesBase</string>
+ </property>
+ <widget class="QWidget" name="centralwidget" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>28</y>
+ <width>504</width>
+ <height>653</height>
+ </rect>
+ </property>
+ <widget class="QWidget" name="layoutWidget" >
+ <property name="geometry" >
+ <rect>
+ <x>40</x>
+ <y>21</y>
+ <width>321</width>
+ <height>506</height>
+ </rect>
+ </property>
+ <layout class="QGridLayout" name="gridLayout" >
+ <item row="0" column="0" >
+ <widget class="QLabel" name="deviceLabel" >
+ <property name="sizePolicy" >
+ <sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
+ <horstretch>1</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text" >
+ <string>Device</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1" >
+ <widget class="QLabel" name="modeLabel" >
+ <property name="text" >
+ <string>Mode</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0" >
+ <widget class="QComboBox" name="deviceBox" />
+ </item>
+ <item row="1" column="1" >
+ <widget class="QComboBox" name="modeBox" />
+ </item>
+ <item row="2" column="0" >
+ <widget class="QLabel" name="actualLabel" >
+ <property name="frameShape" >
+ <enum>QFrame::Panel</enum>
+ </property>
+ <property name="frameShadow" >
+ <enum>QFrame::Raised</enum>
+ </property>
+ <property name="text" >
+ <string>Actual Settings</string>
+ </property>
+ <property name="alignment" >
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1" >
+ <widget class="QLabel" name="nearestLabel" >
+ <property name="frameShape" >
+ <enum>QFrame::Panel</enum>
+ </property>
+ <property name="frameShadow" >
+ <enum>QFrame::Raised</enum>
+ </property>
+ <property name="text" >
+ <string>Nearest Settings</string>
+ </property>
+ <property name="alignment" >
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="0" >
+ <widget class="QLabel" name="actualFreqLabel" >
+ <property name="text" >
+ <string>Frequency</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1" >
+ <widget class="QLabel" name="nearestFreqLabel" >
+ <property name="text" >
+ <string>Frequency</string>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="0" >
+ <widget class="QComboBox" name="frequencyBox" />
+ </item>
+ <item row="4" column="1" >
+ <widget class="QLineEdit" name="nearestFreq" />
+ </item>
+ <item row="5" column="0" >
+ <widget class="QLabel" name="actualChannelsLabel" >
+ <property name="text" >
+ <string>Channels</string>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="1" >
+ <widget class="QLabel" name="nearestChannelLabel" >
+ <property name="text" >
+ <string>Channel</string>
+ </property>
+ </widget>
+ </item>
+ <item row="6" column="0" >
+ <widget class="QComboBox" name="channelsBox" />
+ </item>
+ <item row="6" column="1" >
+ <widget class="QLineEdit" name="nearestChannel" />
+ </item>
+ <item row="7" column="0" >
+ <widget class="QLabel" name="actualCodecLabel" >
+ <property name="text" >
+ <string>Codecs</string>
+ </property>
+ </widget>
+ </item>
+ <item row="7" column="1" >
+ <widget class="QLabel" name="nearestCodecLabel" >
+ <property name="text" >
+ <string>Codec</string>
+ </property>
+ </widget>
+ </item>
+ <item row="8" column="0" >
+ <widget class="QComboBox" name="codecsBox" />
+ </item>
+ <item row="8" column="1" >
+ <widget class="QLineEdit" name="nearestCodec" />
+ </item>
+ <item row="9" column="0" >
+ <widget class="QLabel" name="actualSampleSizeLabel" >
+ <property name="text" >
+ <string>SampleSize</string>
+ </property>
+ </widget>
+ </item>
+ <item row="9" column="1" >
+ <widget class="QLabel" name="nearestSampleSizeLabel" >
+ <property name="text" >
+ <string>SampleSize</string>
+ </property>
+ </widget>
+ </item>
+ <item row="10" column="0" >
+ <widget class="QComboBox" name="sampleSizesBox" />
+ </item>
+ <item row="10" column="1" >
+ <widget class="QLineEdit" name="nearestSampleSize" />
+ </item>
+ <item row="11" column="0" >
+ <widget class="QLabel" name="actualSampleTypeLabel" >
+ <property name="text" >
+ <string>SampleType</string>
+ </property>
+ </widget>
+ </item>
+ <item row="11" column="1" >
+ <widget class="QLabel" name="nearestSampleTypeLabel" >
+ <property name="text" >
+ <string>SampleType</string>
+ </property>
+ </widget>
+ </item>
+ <item row="12" column="0" >
+ <widget class="QComboBox" name="sampleTypesBox" />
+ </item>
+ <item row="12" column="1" >
+ <widget class="QLineEdit" name="nearestSampleType" />
+ </item>
+ <item row="13" column="0" >
+ <widget class="QLabel" name="actualEndianLabel" >
+ <property name="text" >
+ <string>Endianess</string>
+ </property>
+ </widget>
+ </item>
+ <item row="13" column="1" >
+ <widget class="QLabel" name="nearestEndianLabel" >
+ <property name="text" >
+ <string>Endianess</string>
+ </property>
+ </widget>
+ </item>
+ <item row="14" column="0" >
+ <widget class="QComboBox" name="endianBox" />
+ </item>
+ <item row="14" column="1" >
+ <widget class="QLineEdit" name="nearestEndian" />
+ </item>
+ <item row="15" column="0" colspan="2" >
+ <widget class="QTextEdit" name="logOutput" >
+ <property name="minimumSize" >
+ <size>
+ <width>0</width>
+ <height>40</height>
+ </size>
+ </property>
+ </widget>
+ </item>
+ <item row="16" column="0" colspan="2" >
+ <widget class="QPushButton" name="testButton" >
+ <property name="text" >
+ <string>Test</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ <widget class="QMenuBar" name="menubar" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>504</width>
+ <height>28</height>
+ </rect>
+ </property>
+ </widget>
+ <widget class="QStatusBar" name="statusbar" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>681</y>
+ <width>504</width>
+ <height>21</height>
+ </rect>
+ </property>
+ </widget>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/examples/multimedia/audio/audiodevices/main.cpp b/examples/multimedia/audio/audiodevices/main.cpp
new file mode 100644
index 0000000..12e413e
--- /dev/null
+++ b/examples/multimedia/audio/audiodevices/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://www.qtsoftware.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "audiodevices.h"
+
+int main(int argv, char **args)
+{
+ QApplication app(argv, args);
+ app.setApplicationName("Audio Device Test");
+
+ AudioTest audio;
+ audio.show();
+
+ return app.exec();
+}
diff --git a/examples/multimedia/audio/audioinput/audioinput.cpp b/examples/multimedia/audio/audioinput/audioinput.cpp
new file mode 100644
index 0000000..ae7d84c
--- /dev/null
+++ b/examples/multimedia/audio/audioinput/audioinput.cpp
@@ -0,0 +1,376 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://www.qtsoftware.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <stdlib.h>
+#include <math.h>
+
+#include <QDebug>
+#include <QPainter>
+#include <QVBoxLayout>
+
+#include <QAudioDeviceInfo>
+#include <QAudioInput>
+#include "audioinput.h"
+
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
+
+Spectrum::Spectrum(QObject* parent, QAudioInput* device, float* out)
+ :QIODevice( parent )
+{
+ input = device;
+ output = out;
+
+ unsigned int i;
+
+ // Allocate sample buffer and initialize sin and cos lookup tables
+ fftState = (fft_state *) malloc (sizeof(fft_state));
+
+ for(i = 0; i < BUFFER_SIZE; i++) {
+ bitReverse[i] = reverseBits(i);
+ }
+ for(i = 0; i < BUFFER_SIZE / 2; i++) {
+ float j = 2 * M_PI * i / BUFFER_SIZE;
+ costable[i] = cos(j);
+ sintable[i] = sin(j);
+ }
+}
+
+Spectrum::~Spectrum()
+{
+}
+
+void Spectrum::start()
+{
+ open(QIODevice::WriteOnly);
+}
+
+void Spectrum::stop()
+{
+ close();
+}
+
+qint64 Spectrum::readData(char *data, qint64 maxlen)
+{
+ Q_UNUSED(data)
+ Q_UNUSED(maxlen)
+
+ return 0;
+}
+
+qint64 Spectrum::writeData(const char *data, qint64 len)
+{
+ performFFT((sound_sample*)data);
+ emit update();
+
+ return len;
+}
+
+int Spectrum::reverseBits(unsigned int initial) {
+ // BIT-REVERSE-COPY(a,A)
+
+ unsigned int reversed = 0, loop;
+ for(loop = 0; loop < BUFFER_SIZE_LOG; loop++) {
+ reversed <<= 1;
+ reversed += (initial & 1);
+ initial >>= 1;
+ }
+ return reversed;
+}
+
+void Spectrum::performFFT(const sound_sample *input) {
+ /* Convert to reverse bit order for FFT */
+ prepFFT(input, fftState->real, fftState->imag);
+
+ /* Calculate FFT */
+ calcFFT(fftState->real, fftState->imag);
+
+ /* Convert FFT to intensities */
+ outputFFT(fftState->real, fftState->imag);
+}
+
+void Spectrum::prepFFT(const sound_sample *input, float * re, float * im) {
+ unsigned int i;
+ float *realptr = re;
+ float *imagptr = im;
+
+ /* Get input, in reverse bit order */
+ for(i = 0; i < BUFFER_SIZE; i++) {
+ *realptr++ = input[bitReverse[i]];
+ *imagptr++ = 0;
+ }
+}
+
+void Spectrum::calcFFT(float * re, float * im) {
+ unsigned int i, j, k;
+ unsigned int exchanges;
+ float fact_real, fact_imag;
+ float tmp_real, tmp_imag;
+ unsigned int factfact;
+
+ /* Set up some variables to reduce calculation in the loops */
+ exchanges = 1;
+ factfact = BUFFER_SIZE / 2;
+
+ /* divide and conquer method */
+ for(i = BUFFER_SIZE_LOG; i != 0; i--) {
+ for(j = 0; j != exchanges; j++) {
+ fact_real = costable[j * factfact];
+ fact_imag = sintable[j * factfact];
+ for(k = j; k < BUFFER_SIZE; k += exchanges << 1) {
+ int k1 = k + exchanges;
+ tmp_real = fact_real * re[k1] - fact_imag * im[k1];
+ tmp_imag = fact_real * im[k1] + fact_imag * re[k1];
+ re[k1] = re[k] - tmp_real;
+ im[k1] = im[k] - tmp_imag;
+ re[k] += tmp_real;
+ im[k] += tmp_imag;
+ }
+ }
+ exchanges <<= 1;
+ factfact >>= 1;
+ }
+}
+
+void Spectrum::outputFFT(const float * re, const float * im) {
+ const float *realptr = re;
+ const float *imagptr = im;
+ float *outputptr = output;
+
+ float *endptr = output + BUFFER_SIZE / 2;
+
+ /* Convert FFT to intensities */
+
+ while(outputptr <= endptr) {
+ *outputptr = (*realptr * *realptr) + (*imagptr * *imagptr);
+ outputptr++; realptr++; imagptr++;
+ }
+ *output /= 4;
+ *endptr /= 4;
+}
+
+
+RenderArea::RenderArea(QWidget *parent)
+ : QWidget(parent)
+{
+ setBackgroundRole(QPalette::Base);
+ setAutoFillBackground(true);
+
+ samples = 0;
+ sampleSize = 0;
+ setMinimumHeight(30);
+ setMinimumWidth(200);
+}
+
+void RenderArea::paintEvent(QPaintEvent * /* event */)
+{
+ QPainter painter(this);
+
+ if(sampleSize == 0)
+ return;
+
+ painter.setPen(Qt::red);
+ int max = 0;
+ for(int i=0;i<sampleSize;i++) {
+ int m = (int)(sqrt(samples[i])/32768);
+ if(m > max)
+ max = m;
+ }
+ 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().right()-20-max;
+ 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.setPen(Qt::black);
+ painter.drawRect(QRect(painter.viewport().left()+10, painter.viewport().top()+10,
+ painter.viewport().right()-20, painter.viewport().bottom()-20));
+}
+
+void RenderArea::spectrum(float* output, int size)
+{
+ samples = output;
+ sampleSize = size;
+ repaint();
+}
+
+
+InputTest::InputTest()
+{
+ QWidget *window = new QWidget;
+ QVBoxLayout* layout = new QVBoxLayout;
+
+ canvas = new RenderArea;
+ layout->addWidget(canvas);
+
+ deviceBox = new QComboBox(this);
+ QList<QAudioDeviceId> devices = QAudioDeviceInfo::deviceList(QAudio::AudioInput);
+ for(int i = 0; i < devices.size(); ++i) {
+ deviceBox->addItem(QAudioDeviceInfo(devices.at(i)).deviceName(), qVariantFromValue(devices.at(i)));
+ }
+ 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()));
+ layout->addWidget(button);
+
+ button2 = new QPushButton(this);
+ button2->setText(tr("Click To Suspend"));
+ connect(button2,SIGNAL(clicked()),SLOT(toggleSuspend()));
+ layout->addWidget(button2);
+
+ window->setLayout(layout);
+ setCentralWidget(window);
+ window->show();
+
+ buffer = new char[BUFFER_SIZE*10];
+ output = new float[1024];
+
+ pullMode = true;
+
+ format.setFrequency(8000);
+ format.setChannels(1);
+ format.setSampleSize(8);
+ format.setSampleType(QAudioFormat::UnSignedInt);
+ format.setByteOrder(QAudioFormat::LittleEndian);
+ format.setCodec("audio/pcm");
+
+ audioInput = new QAudioInput(format,this);
+ connect(audioInput,SIGNAL(notify()),SLOT(status()));
+ connect(audioInput,SIGNAL(stateChanged(QAudio::State)),SLOT(state(QAudio::State)));
+ spec = new Spectrum(this,audioInput,output);
+ connect(spec,SIGNAL(update()),SLOT(refreshDisplay()));
+ spec->start();
+ audioInput->start(spec);
+}
+
+InputTest::~InputTest() {}
+
+void InputTest::status()
+{
+ qWarning()<<"bytesReady = "<<audioInput->bytesReady()<<" bytes, clock = "<<audioInput->clock()<<"ms, totalTime = "<<audioInput->totalTime()/1000<<"ms";
+}
+
+void InputTest::readMore()
+{
+ if(!audioInput)
+ return;
+ qint64 len = audioInput->bytesReady();
+ if(len > BUFFER_SIZE*10)
+ len = BUFFER_SIZE*10;
+ qint64 l = input->read(buffer,len);
+ if(l > 0) {
+ spec->write(buffer,l);
+ }
+}
+
+void InputTest::toggleMode()
+{
+ // Change bewteen pull and push modes
+ audioInput->stop();
+
+ if(pullMode) {
+ button->setText(tr("Click for Push Mode"));
+ input = audioInput->start(0);
+ connect(input,SIGNAL(readyRead()),SLOT(readMore()));
+ pullMode = false;
+ } else {
+ button->setText(tr("Click for Pull Mode"));
+ pullMode = true;
+ audioInput->start(spec);
+ }
+}
+
+void InputTest::toggleSuspend()
+{
+ // toggle suspend/resume
+ if(audioInput->state() == QAudio::SuspendState) {
+ qWarning()<<"status: Suspended, resume()";
+ audioInput->resume();
+ button2->setText("Click To Suspend");
+ } else if (audioInput->state() == QAudio::ActiveState) {
+ qWarning()<<"status: Active, suspend()";
+ audioInput->suspend();
+ button2->setText("Click To Resume");
+ } else if (audioInput->state() == QAudio::StopState) {
+ qWarning()<<"status: Stopped, resume()";
+ audioInput->resume();
+ button2->setText("Click To Suspend");
+ } else if (audioInput->state() == QAudio::IdleState) {
+ qWarning()<<"status: IdleState";
+ }
+}
+
+void InputTest::state(QAudio::State state)
+{
+ qWarning()<<" state="<<state;
+}
+
+void InputTest::refreshDisplay()
+{
+ canvas->spectrum(output,256);
+ canvas->repaint();
+}
+
+void InputTest::deviceChanged(int idx)
+{
+ spec->stop();
+ audioInput->stop();
+ audioInput->disconnect(this);
+ delete audioInput;
+
+ device = deviceBox->itemData(idx).value<QAudioDeviceId>();
+ audioInput = new QAudioInput(device, format, this);
+ connect(audioInput,SIGNAL(notify()),SLOT(status()));
+ connect(audioInput,SIGNAL(stateChanged(QAudio::State)),SLOT(state(QAudio::State)));
+ spec->start();
+ audioInput->start(spec);
+}
diff --git a/examples/multimedia/audio/audioinput/audioinput.h b/examples/multimedia/audio/audioinput/audioinput.h
new file mode 100644
index 0000000..3a6b356
--- /dev/null
+++ b/examples/multimedia/audio/audioinput/audioinput.h
@@ -0,0 +1,144 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://www.qtsoftware.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QPixmap>
+#include <QWidget>
+#include <QObject>
+#include <QMainWindow>
+#include <QPushButton>
+#include <QComboBox>
+
+#include <qaudioinput.h>
+
+#define BUFFER_SIZE_LOG 9
+#define BUFFER_SIZE (1 << BUFFER_SIZE_LOG)
+
+struct _struct_fft_state {
+ float real[BUFFER_SIZE];
+ float imag[BUFFER_SIZE];
+};
+typedef _struct_fft_state fft_state;
+typedef short int sound_sample;
+
+class Spectrum : public QIODevice
+{
+ Q_OBJECT
+public:
+ Spectrum(QObject* parent, QAudioInput* device, float* out);
+ ~Spectrum();
+
+ void start();
+ void stop();
+
+ qint64 readData(char *data, qint64 maxlen);
+ qint64 writeData(const char *data, qint64 len);
+
+ QAudioInput* input;
+ float* output;
+ fft_state* fftState;
+
+ unsigned int bitReverse[BUFFER_SIZE];
+ float sintable[BUFFER_SIZE / 2];
+ float costable[BUFFER_SIZE / 2];
+
+ void prepFFT (const sound_sample *input, float *re, float *im);
+ void calcFFT (float *re, float *im);
+ void outputFFT (const float *re, const float *im);
+ int reverseBits (unsigned int initial);
+ void performFFT (const sound_sample *input);
+
+signals:
+ void update();
+};
+
+
+class RenderArea : public QWidget
+{
+ Q_OBJECT
+
+public:
+ RenderArea(QWidget *parent = 0);
+
+ void spectrum(float* output, int size);
+
+protected:
+ void paintEvent(QPaintEvent *event);
+
+private:
+ QPixmap pixmap;
+
+ float* samples;
+ int sampleSize;
+};
+
+class InputTest : public QMainWindow
+{
+ Q_OBJECT
+public:
+ InputTest();
+ ~InputTest();
+
+ QAudioDeviceId device;
+ QAudioFormat format;
+ QAudioInput* audioInput;
+ Spectrum* spec;
+ QIODevice* input;
+ RenderArea* canvas;
+
+ bool pullMode;
+
+ QPushButton* button;
+ QPushButton* button2;
+ QComboBox* deviceBox;
+
+ char* buffer;
+ float* output;
+
+private slots:
+ void refreshDisplay();
+ void status();
+ void readMore();
+ void toggleMode();
+ void toggleSuspend();
+ void state(QAudio::State s);
+ void deviceChanged(int idx);
+};
+
diff --git a/examples/multimedia/audio/audioinput/audioinput.pro b/examples/multimedia/audio/audioinput/audioinput.pro
new file mode 100644
index 0000000..d930750
--- /dev/null
+++ b/examples/multimedia/audio/audioinput/audioinput.pro
@@ -0,0 +1,12 @@
+HEADERS = audioinput.h
+SOURCES = audioinput.cpp \
+ main.cpp
+
+QT += multimedia
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/multimedia/audio/audioinput
+sources.files = $$SOURCES *.h $$RESOURCES $$FORMS audioinput.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/multimedia/audio/audioinput
+INSTALLS += target sources
+
diff --git a/examples/multimedia/audio/audioinput/main.cpp b/examples/multimedia/audio/audioinput/main.cpp
new file mode 100644
index 0000000..64a9b04
--- /dev/null
+++ b/examples/multimedia/audio/audioinput/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://www.qtsoftware.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "audioinput.h"
+
+int main(int argv, char **args)
+{
+ QApplication app(argv, args);
+ app.setApplicationName("Audio Input Test");
+
+ InputTest input;
+ input.show();
+
+ return app.exec();
+}
diff --git a/examples/multimedia/audio/audiooutput/audiooutput.cpp b/examples/multimedia/audio/audiooutput/audiooutput.cpp
new file mode 100644
index 0000000..be26f19
--- /dev/null
+++ b/examples/multimedia/audio/audiooutput/audiooutput.cpp
@@ -0,0 +1,280 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://www.qtsoftware.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QDebug>
+#include <QVBoxLayout>
+
+#include <QAudioOutput>
+#include <QAudioDeviceInfo>
+#include "audiooutput.h"
+
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
+
+Generator::Generator(QObject *parent)
+ :QIODevice( parent )
+{
+ finished = false;
+ buffer = new char[SECONDS*44100*4+1000];
+ t=buffer;
+ len=fillData(t+4,450,SECONDS); /* left channel, 450Hz sine */
+ len+=fillData(t+6,452,SECONDS); /* right channel, 452Hz sine */
+ putLong(t,len);
+ putLong(buffer+4,len+8+16+8);
+ pos = 0;
+ total = len+8+16+8;
+}
+
+Generator::~Generator()
+{
+ delete [] buffer;
+}
+
+void Generator::start()
+{
+ open(QIODevice::ReadOnly);
+}
+
+void Generator::stop()
+{
+ close();
+}
+
+int Generator::putShort(char *t, unsigned int value)
+{
+ *(unsigned char *)(t++)=value&255;
+ *(unsigned char *)(t)=(value/256)&255;
+ return 2;
+}
+
+int Generator::putLong(char *t, unsigned int value)
+{
+ *(unsigned char *)(t++)=value&255;
+ *(unsigned char *)(t++)=(value/256)&255;
+ *(unsigned char *)(t++)=(value/(256*256))&255;
+ *(unsigned char *)(t)=(value/(256*256*256))&255;
+ return 4;
+}
+
+int Generator::fillData(char *start, int frequency, int seconds)
+{
+ int i, len=0;
+ int value;
+ for(i=0; i<seconds*44100; i++) {
+ value=(int)(32767.0*sin(2.0*M_PI*((double)(i))*(double)(frequency)/44100.0));
+ putShort(start, value);
+ start += 4;
+ len+=2;
+ }
+ return len;
+}
+
+qint64 Generator::readData(char *data, qint64 maxlen)
+{
+ int len = maxlen;
+ if(len > 16384)
+ len = 16384;
+
+ if(len < (SECONDS*44100*4+1000)-pos) {
+ // Normal
+ memcpy(data,t+pos,len);
+ pos+=len;
+ return len;
+ } else {
+ // Whats left and reset to start
+ qint64 left = (SECONDS*44100*4+1000)-pos;
+ memcpy(data,t+pos,left);
+ pos=0;
+ return left;
+ }
+}
+
+qint64 Generator::writeData(const char *data, qint64 len)
+{
+ Q_UNUSED(data);
+ Q_UNUSED(len);
+
+ return 0;
+}
+
+AudioTest::AudioTest()
+{
+ QWidget *window = new QWidget;
+ QVBoxLayout* layout = new QVBoxLayout;
+
+ deviceBox = new QComboBox(this);
+ QList<QAudioDeviceId> devices = QAudioDeviceInfo::deviceList(QAudio::AudioOutput);
+ for(int i = 0; i < devices.size(); ++i) {
+ deviceBox->addItem(QAudioDeviceInfo(devices.at(i)).deviceName(), qVariantFromValue(devices.at(i)));
+ }
+ 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(toggle()));
+ layout->addWidget(button);
+
+ button2 = new QPushButton(this);
+ button2->setText(tr("Click To Suspend"));
+ connect(button2,SIGNAL(clicked()),SLOT(togglePlay()));
+ layout->addWidget(button2);
+
+ window->setLayout(layout);
+ setCentralWidget(window);
+ window->show();
+
+ buffer = new char[BUFFER_SIZE];
+
+ gen = new Generator(this);
+
+ pullMode = true;
+
+ timer = new QTimer(this);
+ connect(timer,SIGNAL(timeout()),SLOT(writeMore()));
+
+ gen->start();
+
+ settings.setFrequency(44100);
+ settings.setChannels(2);
+ settings.setSampleSize(16);
+ settings.setCodec("audio/pcm");
+ settings.setByteOrder(QAudioFormat::LittleEndian);
+ settings.setSampleType(QAudioFormat::SignedInt);
+ audioOutput = new QAudioOutput(settings,this);
+ connect(audioOutput,SIGNAL(notify()),SLOT(status()));
+ connect(audioOutput,SIGNAL(stateChanged(QAudio::State)),SLOT(state(QAudio::State)));
+
+ audioOutput->start(gen);
+}
+
+AudioTest::~AudioTest()
+{
+ delete [] buffer;
+}
+
+void AudioTest::deviceChanged(int idx)
+{
+ timer->stop();
+ gen->stop();
+ audioOutput->stop();
+ audioOutput->disconnect(this);
+ delete audioOutput;
+
+ device = deviceBox->itemData(idx).value<QAudioDeviceId>();
+ audioOutput = new QAudioOutput(device,settings,this);
+ connect(audioOutput,SIGNAL(notify()),SLOT(status()));
+ connect(audioOutput,SIGNAL(stateChanged(QAudio::State)),SLOT(state(QAudio::State)));
+ gen->start();
+ audioOutput->start(gen);
+}
+
+void AudioTest::status()
+{
+ qWarning()<<"byteFree = "<<audioOutput->bytesFree()<<" bytes, clock = "<<audioOutput->clock()<<"ms, totalTime = "<<audioOutput->totalTime()/1000<<"ms";
+}
+
+void AudioTest::writeMore()
+{
+ if(!audioOutput)
+ return;
+
+ if(audioOutput->state() == QAudio::StopState)
+ return;
+
+ int l;
+ int out;
+
+ int chunks = audioOutput->bytesFree()/audioOutput->periodSize();
+ while(chunks) {
+ l = gen->read(buffer,audioOutput->periodSize());
+ if(l > 0)
+ out = output->write(buffer,l);
+ if(l != audioOutput->periodSize())
+ break;
+ chunks--;
+ }
+}
+
+void AudioTest::toggle()
+{
+ // Change between pull and push modes
+
+ timer->stop();
+ audioOutput->stop();
+
+ if (pullMode) {
+ button->setText("Click for Pull Mode");
+ output = audioOutput->start(0);
+ pullMode = false;
+ timer->start(20);
+ } else {
+ button->setText("Click for Push Mode");
+ pullMode = true;
+ audioOutput->start(gen);
+ }
+}
+
+void AudioTest::togglePlay()
+{
+ // toggle suspend/resume
+ if(audioOutput->state() == QAudio::SuspendState) {
+ qWarning()<<"status: Suspended, resume()";
+ audioOutput->resume();
+ button2->setText("Click To Suspend");
+ } else if (audioOutput->state() == QAudio::ActiveState) {
+ qWarning()<<"status: Active, suspend()";
+ audioOutput->suspend();
+ button2->setText("Click To Resume");
+ } else if (audioOutput->state() == QAudio::StopState) {
+ qWarning()<<"status: Stopped, resume()";
+ audioOutput->resume();
+ button2->setText("Click To Suspend");
+ } else if (audioOutput->state() == QAudio::IdleState) {
+ qWarning()<<"status: IdleState";
+ }
+}
+
+void AudioTest::state(QAudio::State state)
+{
+ qWarning()<<" state="<<state;
+}
diff --git a/examples/multimedia/audio/audiooutput/audiooutput.h b/examples/multimedia/audio/audiooutput/audiooutput.h
new file mode 100644
index 0000000..1e21b48
--- /dev/null
+++ b/examples/multimedia/audio/audiooutput/audiooutput.h
@@ -0,0 +1,112 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://www.qtsoftware.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <math.h>
+
+#define BUFFER_SIZE 32768
+#define SECONDS 3
+
+#include <QObject>
+#include <QMainWindow>
+#include <QIODevice>
+#include <QTimer>
+#include <QPushButton>
+#include <QComboBox>
+
+#include <QAudioOutput>
+
+class Generator : public QIODevice
+{
+ Q_OBJECT
+public:
+ Generator(QObject *parent);
+ ~Generator();
+
+ void start();
+ void stop();
+
+ char *t;
+ int len;
+ int pos;
+ int total;
+ char *buffer;
+ bool finished;
+ int chunk_size;
+
+ qint64 readData(char *data, qint64 maxlen);
+ qint64 writeData(const char *data, qint64 len);
+
+private:
+ int putShort(char *t, unsigned int value);
+ int putLong(char *t, unsigned int value);
+ int fillData(char *start, int frequency, int seconds);
+};
+
+class AudioTest : public QMainWindow
+{
+ Q_OBJECT
+public:
+ AudioTest();
+ ~AudioTest();
+
+ QAudioDeviceId device;
+ Generator* gen;
+ QAudioOutput* audioOutput;
+ QIODevice* output;
+ QTimer* timer;
+ QAudioFormat settings;
+
+ bool pullMode;
+ char* buffer;
+
+ QPushButton* button;
+ QPushButton* button2;
+ QComboBox* deviceBox;
+
+private slots:
+ void status();
+ void writeMore();
+ void toggle();
+ void togglePlay();
+ void state(QAudio::State s);
+ void deviceChanged(int idx);
+};
+
diff --git a/examples/multimedia/audio/audiooutput/audiooutput.pro b/examples/multimedia/audio/audiooutput/audiooutput.pro
new file mode 100644
index 0000000..08f43ce
--- /dev/null
+++ b/examples/multimedia/audio/audiooutput/audiooutput.pro
@@ -0,0 +1,11 @@
+HEADERS = audiooutput.h
+SOURCES = audiooutput.cpp \
+ main.cpp
+
+QT += multimedia
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/multimedia/audio/audiooutput
+sources.files = $$SOURCES *.h $$RESOURCES $$FORMS audiooutput.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/multimedia/audio/audiooutput
+INSTALLS += target sources
diff --git a/examples/multimedia/audio/audiooutput/main.cpp b/examples/multimedia/audio/audiooutput/main.cpp
new file mode 100644
index 0000000..fc319bd
--- /dev/null
+++ b/examples/multimedia/audio/audiooutput/main.cpp
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://www.qtsoftware.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <QtGui>
+
+#include "audiooutput.h"
+
+int main(int argv, char **args)
+{
+ QApplication app(argv, args);
+ app.setApplicationName("Audio Output Test");
+
+ AudioTest audio;
+ audio.show();
+
+ return app.exec();
+}
diff --git a/examples/multimedia/multimedia.pro b/examples/multimedia/multimedia.pro
new file mode 100644
index 0000000..ac78b15
--- /dev/null
+++ b/examples/multimedia/multimedia.pro
@@ -0,0 +1,8 @@
+TEMPLATE = subdirs
+SUBDIRS = audio
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/multimedia
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS multimedia.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/multimedia
+INSTALLS += target sources