1 /* This file is part of the KDE project
2 Copyright (C) 2005-2006 Matthias Kretz <kretz@kde.org>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
19 #ifndef Phonon_AUDIODATAOUTPUT_H
20 #define Phonon_AUDIODATAOUTPUT_H
22 #include <kdelibs_export.h>
23 #include "abstractaudiooutput.h"
24 #include "phonondefs.h"
26 #ifndef DOXYGEN_SHOULD_SKIP_THIS
27 template<typename T
> class QVector
;
28 template<typename Key
, typename T
> class QMap
;
33 class AudioDataOutputPrivate
;
36 * \short This class gives you the audio data (for visualizations).
38 * This class implements a special AbstractAudioOutput that gives your
39 * application the audio data. Don't expect realtime performance. But
40 * the latencies should be low enough to use the audio data for
41 * visualizations. You can also use the audio data for further processing
42 * (e.g. encoding and saving to a file).
44 * The class supports different data formats. One of the most common formats
45 * is to read vectors of integers (which will only use 16 Bit), but you can
46 * also request floats which some backends use internally.
48 * \author Matthias Kretz <kretz@kde.org>
50 class PHONONCORE_EXPORT AudioDataOutput
: public AbstractAudioOutput
53 K_DECLARE_PRIVATE( AudioDataOutput
)
54 Q_ENUMS( Channel Format
)
55 Q_PROPERTY( Format format READ format WRITE setFormat
)
56 Q_PROPERTY( int dataSize READ dataSize WRITE setDataSize
)
57 PHONON_HEIR( AudioDataOutput
)
60 * Specifies the channel the audio data belongs to.
73 * Used for telling the object whether you want 16 bit Integers or
81 * Requests 16 bit signed integers.
83 * \see dataReady( const QVector<qint16>& )
87 * Requests 32 bit floating point: signed, zero centered, and
88 * normalized to the unit value (-1.0 to 1.0).
90 * \see dataReady( const QVector<float>& )
96 * Returns the currently used format.
100 Format
format() const;
103 * Returns the currently used number of samples passed through
108 int dataSize() const;
111 * Returns the sample rate in Hz. Common sample rates are 44100 Hz
112 * and 48000 Hz. AudioDataOutput will not do any sample rate
113 * conversion for you. If you need to convert the sample rate you
114 * might want to take a look at libsamplerate. For visualizations it
115 * is often enough to do simple interpolation or even drop/duplicate
118 * \return The sample rate as reported by the backend. If the
119 * backend is unavailable -1 is returned.
121 int sampleRate() const;
125 * Requests the dataformat you'd like to receive. Only one of the
126 * signals of this class will be emitted when new data is ready.
128 * The default format is IntegerFormat.
132 void setFormat( Format format
);
135 * Sets the number of samples to be passed in one signal emission.
137 * Defaults to 512 samples per emitted signal.
139 * \param size the number of samples
141 void setDataSize( int size
);
145 * Emitted whenever another dataSize number of samples are ready and
146 * format is set to IntegerFormat.
148 * If format is set to FloatFormat the signal is not emitted at all.
150 * \param data A mapping of Channel to a vector holding the audio data.
152 void dataReady( const QMap
<Phonon::AudioDataOutput::Channel
, QVector
<qint16
> >& data
);
155 * Emitted whenever another dataSize number of samples are ready and
156 * format is set to FloatFormat.
158 * If format is set to IntegerFormat the signal is not emitted at all.
160 * \param data A mapping of Channel to a vector holding the audio data.
162 void dataReady( const QMap
<Phonon::AudioDataOutput::Channel
, QVector
<float> >& data
);
165 * This signal is emitted before the last dataReady signal of a
168 * If, for example, the playback of a media file has finished and the
169 * last audio data of that file is going to be passed with the next
170 * dataReady signal, and only the 28 first samples of the data
171 * vector are from that media file endOfMedia will be emitted right
172 * before dataReady with \p remainingSamples = 28.
174 * \param remainingSamples The number of samples in the next
175 * dataReady vector that belong to the media that was playing to
178 void endOfMedia( int remainingSamples
);
182 // vim: sw=4 ts=4 tw=80
183 #endif // Phonon_AUDIODATAOUTPUT_H