summaryrefslogtreecommitdiffstats
path: root/src/multimedia/audio
diff options
context:
space:
mode:
Diffstat (limited to 'src/multimedia/audio')
-rw-r--r--src/multimedia/audio/qaudiodeviceinfo.cpp4
-rw-r--r--src/multimedia/audio/qaudioinput.cpp45
-rw-r--r--src/multimedia/audio/qaudiooutput.cpp45
3 files changed, 12 insertions, 82 deletions
diff --git a/src/multimedia/audio/qaudiodeviceinfo.cpp b/src/multimedia/audio/qaudiodeviceinfo.cpp
index 603c388..c46fa7f 100644
--- a/src/multimedia/audio/qaudiodeviceinfo.cpp
+++ b/src/multimedia/audio/qaudiodeviceinfo.cpp
@@ -114,9 +114,9 @@ public:
supported format that is as close as possible to the format with
nearestFormat(). For instance:
- \snippet doc/src/snippets/audio/main.cpp 1
+ \snippet doc/src/snippets/audio/main.cpp 6
\dots 8
- \snippet doc/src/snippets/audio/main.cpp 2
+ \snippet doc/src/snippets/audio/main.cpp 7
A QAudioDeviceInfo is used by Qt to construct
classes that communicate with the device--such as
diff --git a/src/multimedia/audio/qaudioinput.cpp b/src/multimedia/audio/qaudioinput.cpp
index e209dd1..d22f66d 100644
--- a/src/multimedia/audio/qaudioinput.cpp
+++ b/src/multimedia/audio/qaudioinput.cpp
@@ -76,37 +76,9 @@ QT_BEGIN_NAMESPACE
with a QIODevice opened for writing. For instance, to record to a
file, you can:
- \code
- QFile outputFile; // class member.
- QAudioInput* audio; // class member.
- \endcode
-
- \code
- {
- outputFile.setFileName("/tmp/test.raw");
- outputFile.open( QIODevice::WriteOnly | QIODevice::Truncate );
-
- QAudioFormat format;
- // set up the format you want, eg.
- format.setFrequency(8000);
- format.setChannels(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 try to use nearest";
- format = info.nearestFormat(format);
- }
-
- audio = new QAudioInput(format, this);
- QTimer::singleShot(3000, this, SLOT(stopRecording()));
- audio->start(&outputFile);
- // Records audio for 3000ms
- }
- \endcode
+ \snippet doc/src/snippets/audio/main.cpp 3
+ \dots 4
+ \snippet doc/src/snippets/audio/main.cpp 0
This will start recording if the format specified is supported by
the input device (you can check this with
@@ -114,14 +86,7 @@ QT_BEGIN_NAMESPACE
snags, use the error() function to check what went wrong. We stop
recording in the \c stopRecording() slot.
- \code
- void stopRecording()
- {
- audio->stop();
- outputFile->close();
- delete audio;
- }
- \endcode
+ \snippet doc/src/snippets/audio/main.cpp 1
At any point in time, QAudioInput will be in one of four states:
active, suspended, stopped, or idle. These states are specified by
@@ -143,7 +108,7 @@ QT_BEGIN_NAMESPACE
an error is encountered. Connect to the stateChanged() signal to
handle the error:
- \snippet doc/src/snippets/audio/main.cpp 0
+ \snippet doc/src/snippets/audio/main.cpp 2
\sa QAudioOutput, QAudioDeviceInfo
diff --git a/src/multimedia/audio/qaudiooutput.cpp b/src/multimedia/audio/qaudiooutput.cpp
index 1abdc58..5420574 100644
--- a/src/multimedia/audio/qaudiooutput.cpp
+++ b/src/multimedia/audio/qaudiooutput.cpp
@@ -72,35 +72,9 @@ QT_BEGIN_NAMESPACE
needs from the io device. So playing back an audio file is as
simple as:
- \code
- QFile inputFile; // class member.
- QAudioOutput* audio; // class member.
- \endcode
-
- \code
- inputFile.setFileName("/tmp/test.raw");
- inputFile.open(QIODevice::ReadOnly);
-
- QAudioFormat format;
- // Set up the format, eg.
- format.setFrequency(8000);
- format.setChannels(1);
- format.setSampleSize(8);
- format.setCodec("audio/pcm");
- format.setByteOrder(QAudioFormat::LittleEndian);
- format.setSampleType(QAudioFormat::UnSignedInt);
-
- QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
- if (!info.isFormatSupported(format)) {
- qWarning()<<"raw audio format not supported by backend, cannot play audio.";
- return;
- }
-
- audio = new QAudioOutput(format, this);
- connect(audio,SIGNAL(stateChanged(QAudio::State)),SLOT(finishedPlaying(QAudio::State)));
- audio->start(&inputFile);
-
- \endcode
+ \snippet doc/src/snippets/audio/main.cpp 9
+ \dots 4
+ \snippet doc/src/snippets/audio/main.cpp 4
The file will start playing assuming that the audio system and
output device support it. If you run out of luck, check what's
@@ -108,16 +82,7 @@ QT_BEGIN_NAMESPACE
After the file has finished playing, we need to stop the device:
- \code
- void finishedPlaying(QAudio::State state)
- {
- if(state == QAudio::IdleState) {
- audio->stop();
- inputFile.close();
- delete audio;
- }
- }
- \endcode
+ \snippet doc/src/snippets/audio/main.cpp 5
At any given time, the QAudioOutput will be in one of four states:
active, suspended, stopped, or idle. These states are described
@@ -145,7 +110,7 @@ QT_BEGIN_NAMESPACE
You can check for errors by connecting to the stateChanged()
signal:
- \snippet doc/src/snippets/audio/main.cpp 3
+ \snippet doc/src/snippets/audio/main.cpp 8
\sa QAudioInput, QAudioDeviceInfo
*/