diff options
| author | Christoph Berg <christoph.berg@credativ.de> | 2022-08-23 10:23:16 +0200 |
|---|---|---|
| committer | Christoph Berg <christoph.berg@credativ.de> | 2022-08-23 10:23:16 +0200 |
| commit | 2d1068e60bce7ae1fff11623454900e8cee956b1 (patch) | |
| tree | acebe276e30466ef0ab91bc3da5e379bec0d7dc5 /Audio/AudioDevice.hpp | |
| parent | 43bebfbad6e7ba026bd3d55720c7d9e12a7ef8ef (diff) | |
New upstream version 2.6.0~rc3+repackupstream/2.6.0_rc3+repack
Diffstat (limited to 'Audio/AudioDevice.hpp')
| -rwxr-xr-x | Audio/AudioDevice.hpp | 196 |
1 files changed, 98 insertions, 98 deletions
diff --git a/Audio/AudioDevice.hpp b/Audio/AudioDevice.hpp index 2d47af89..df3e3f4c 100755 --- a/Audio/AudioDevice.hpp +++ b/Audio/AudioDevice.hpp @@ -1,98 +1,98 @@ -#ifndef AUDIODEVICE_HPP__ -#define AUDIODEVICE_HPP__ - -#include <QIODevice> - -class QDataStream; - -// -// abstract base class for audio devices -// -class AudioDevice : public QIODevice -{ -public: - enum Channel {Mono, Left, Right, Both}; // these are mapped to combobox index so don't change - - static char const * toString (Channel c) - { - return Mono == c ? "Mono" : Left == c ? "Left" : Right == c ? "Right" : "Both"; - } - - static Channel fromString (QString const& str) - { - QString s (str.toCaseFolded ().trimmed ().toLatin1 ()); - return "both" == s ? Both : "right" == s ? Right : "left" == s ? Left : Mono; - } - - bool initialize (OpenMode mode, Channel channel); - - bool isSequential () const override {return true;} - - size_t bytesPerFrame () const {return sizeof (qint16) * (Mono == m_channel ? 1 : 2);} - - Channel channel () const {return m_channel;} - -protected: - AudioDevice (QObject * parent = nullptr) - : QIODevice {parent} - { - } - - void store (char const * source, size_t numFrames, qint16 * dest) - { - qint16 const * begin (reinterpret_cast<qint16 const *> (source)); - for ( qint16 const * i = begin; i != begin + numFrames * (bytesPerFrame () / sizeof (qint16)); i += bytesPerFrame () / sizeof (qint16)) - { - switch (m_channel) - { - case Mono: - *dest++ = *i; - break; - - case Right: - *dest++ = *(i + 1); - break; - - case Both: // should be able to happen but if it - // does we'll take left - Q_ASSERT (Both == m_channel); - case Left: - *dest++ = *i; - break; - } - } - } - - qint16 * load (qint16 const sample, qint16 * dest) - { - switch (m_channel) - { - case Mono: - *dest++ = sample; - break; - - case Left: - *dest++ = sample; - *dest++ = 0; - break; - - case Right: - *dest++ = 0; - *dest++ = sample; - break; - - case Both: - *dest++ = sample; - *dest++ = sample; - break; - } - return dest; - } - -private: - Channel m_channel; -}; - -Q_DECLARE_METATYPE (AudioDevice::Channel); - -#endif +#ifndef AUDIODEVICE_HPP__
+#define AUDIODEVICE_HPP__
+
+#include <QIODevice>
+
+class QDataStream;
+
+//
+// abstract base class for audio devices
+//
+class AudioDevice : public QIODevice
+{
+public:
+ enum Channel {Mono, Left, Right, Both}; // these are mapped to combobox index so don't change
+
+ static char const * toString (Channel c)
+ {
+ return Mono == c ? "Mono" : Left == c ? "Left" : Right == c ? "Right" : "Both";
+ }
+
+ static Channel fromString (QString const& str)
+ {
+ QString s (str.toCaseFolded ().trimmed ().toLatin1 ());
+ return "both" == s ? Both : "right" == s ? Right : "left" == s ? Left : Mono;
+ }
+
+ bool initialize (OpenMode mode, Channel channel);
+
+ bool isSequential () const override {return true;}
+
+ size_t bytesPerFrame () const {return sizeof (qint16) * (Mono == m_channel ? 1 : 2);}
+
+ Channel channel () const {return m_channel;}
+
+protected:
+ AudioDevice (QObject * parent = nullptr)
+ : QIODevice {parent}
+ {
+ }
+
+ void store (char const * source, size_t numFrames, qint16 * dest)
+ {
+ qint16 const * begin (reinterpret_cast<qint16 const *> (source));
+ for ( qint16 const * i = begin; i != begin + numFrames * (bytesPerFrame () / sizeof (qint16)); i += bytesPerFrame () / sizeof (qint16))
+ {
+ switch (m_channel)
+ {
+ case Mono:
+ *dest++ = *i;
+ break;
+
+ case Right:
+ *dest++ = *(i + 1);
+ break;
+
+ case Both: // should be able to happen but if it
+ // does we'll take left
+ Q_ASSERT (Both == m_channel);
+ case Left:
+ *dest++ = *i;
+ break;
+ }
+ }
+ }
+
+ qint16 * load (qint16 const sample, qint16 * dest)
+ {
+ switch (m_channel)
+ {
+ case Mono:
+ *dest++ = sample;
+ break;
+
+ case Left:
+ *dest++ = sample;
+ *dest++ = 0;
+ break;
+
+ case Right:
+ *dest++ = 0;
+ *dest++ = sample;
+ break;
+
+ case Both:
+ *dest++ = sample;
+ *dest++ = sample;
+ break;
+ }
+ return dest;
+ }
+
+private:
+ Channel m_channel;
+};
+
+Q_DECLARE_METATYPE (AudioDevice::Channel);
+
+#endif
|
