diff --git a/libkwave/Compression.cpp b/libkwave/Compression.cpp index f96bc43c..3bcdb169 100644 --- a/libkwave/Compression.cpp +++ b/libkwave/Compression.cpp @@ -1,389 +1,392 @@ /*************************************************************************** Compression.cpp - Wrapper for a compression ------------------- begin : Fri Jan 25 2013 copyright : (C) 2013 by Thomas Eschenbacher email : Thomas.Eschenbacher@gmx.de ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "config.h" #include #include #include #include "libkwave/Compression.h" /* static instance */ QMap Kwave::Compression::m_map; //*************************************************************************** Kwave::Compression::Compression() :m_type(Kwave::Compression::NONE) { fillMap(); } //*************************************************************************** Kwave::Compression::Compression(const Type value) :m_type(value) { fillMap(); } //*************************************************************************** QString Kwave::Compression::name() const { return (m_map.contains(m_type)) ? i18n(UTF8(m_map[m_type].m_name)) : QString(); } //*************************************************************************** QString Kwave::Compression::preferredMimeType() const { return (m_map.contains(m_type)) ? i18n(UTF8(m_map[m_type].m_mime_type)) : QString(); } //*************************************************************************** QList Kwave::Compression::sampleFormats() const { return (m_map.contains(m_type)) ? m_map[m_type].m_sample_formats : QList(); } //*************************************************************************** bool Kwave::Compression::hasABR() const { return (m_map.contains(m_type)) ? m_map[m_type].m_has_abr : false; } //*************************************************************************** bool Kwave::Compression::hasVBR() const { return (m_map.contains(m_type)) ? m_map[m_type].m_has_vbr : false; } //*************************************************************************** Kwave::Compression::Type Kwave::Compression::fromInt(int i) { + fillMap(); return (m_map.contains(static_cast(i))) ? static_cast(i) : Kwave::Compression::NONE; } //*************************************************************************** void Kwave::Compression::fillMap() { if (!m_map.isEmpty()) return; // bail out if already filled QList sfmt_none; QList sfmt_int; sfmt_int += Kwave::SampleFormat(Kwave::SampleFormat::Signed); sfmt_int += Kwave::SampleFormat(Kwave::SampleFormat::Unsigned); QList sfmt_all; sfmt_all += sfmt_int; sfmt_all += Kwave::SampleFormat(Kwave::SampleFormat::Float); sfmt_all += Kwave::SampleFormat(Kwave::SampleFormat::Double); /* no compression */ m_map.insert(Kwave::Compression::NONE, Kwave::Compression::Info( _(I18N_NOOP("No Compression")), QString(), sfmt_all, false, false)); /* types supported by OSS+ALSA record plugin and WAV codec */ m_map.insert(Kwave::Compression::G711_ULAW, Kwave::Compression::Info( _(I18N_NOOP("CCITT G.711 u-law")), QString(), sfmt_int, false, false)); m_map.insert(Kwave::Compression::G711_ALAW, Kwave::Compression::Info( _(I18N_NOOP("CCITT G.711 A-law")), QString(), sfmt_int, false, false)); m_map.insert(Kwave::Compression::MS_ADPCM, Kwave::Compression::Info( _(I18N_NOOP("MS ADPCM")), QString(), sfmt_int, false, false)); m_map.insert(Kwave::Compression::GSM, Kwave::Compression::Info( _(I18N_NOOP("GSM")), QString(), sfmt_int, false, false)); /* compression types from libaudiofile (for display only, not supported) */ m_map.insert(Kwave::Compression::G722, Kwave::Compression::Info( _(I18N_NOOP("G722")), QString(), sfmt_none, true, false)); m_map.insert(Kwave::Compression::APPLE_ACE2, Kwave::Compression::Info( _(I18N_NOOP("Apple ACE2")), QString(), sfmt_none, true, false)); m_map.insert(Kwave::Compression::APPLE_ACE8, Kwave::Compression::Info( _(I18N_NOOP("Apple ACE8")), QString(), sfmt_none, true, false)); m_map.insert(Kwave::Compression::APPLE_MAC3, Kwave::Compression::Info( _(I18N_NOOP("Apple MAC3")), QString(), sfmt_none, true, false)); m_map.insert(Kwave::Compression::APPLE_MAC6, Kwave::Compression::Info( _(I18N_NOOP("Apple MAC6")), QString(), sfmt_none, true, false)); m_map.insert(Kwave::Compression::G726, Kwave::Compression::Info( _(I18N_NOOP("G726")), QString(), sfmt_none, true, false)); m_map.insert(Kwave::Compression::DVI_AUDIO, Kwave::Compression::Info( _(I18N_NOOP("DVI Audio / IMA")), QString(), sfmt_none, true, false)); m_map.insert(Kwave::Compression::FS1016, Kwave::Compression::Info( _(I18N_NOOP("FS1016")), QString(), sfmt_none, true, false)); m_map.insert(Kwave::Compression::DV, Kwave::Compression::Info( _(I18N_NOOP("DV")), QString(), sfmt_none, true, false)); /* MPEG layer I/II/III */ #ifdef HAVE_MP3 m_map.insert(Kwave::Compression::MPEG_LAYER_I, Kwave::Compression::Info( _(I18N_NOOP("MPEG Layer I")), _("audio/x-mp3"), sfmt_none, true, false)); m_map.insert(Kwave::Compression::MPEG_LAYER_II, Kwave::Compression::Info( _(I18N_NOOP("MPEG Layer II")), _("audio/x-mp3"), sfmt_none, true, false)); m_map.insert(Kwave::Compression::MPEG_LAYER_III, Kwave::Compression::Info( _(I18N_NOOP("MPEG Layer III")), _("audio/x-mp3"), sfmt_none, true, false)); #endif /* HAVE_MP3 */ /* FLAC */ #ifdef HAVE_FLAC m_map.insert(Kwave::Compression::FLAC, Kwave::Compression::Info( _(I18N_NOOP("FLAC")), _("audio/x-flac"), sfmt_none, false, false)); #endif /* HAVE_FLAC */ /* Ogg Vorbis */ #ifdef HAVE_OGG_VORBIS m_map.insert(Kwave::Compression::OGG_VORBIS, Kwave::Compression::Info( _(I18N_NOOP("Ogg Vorbis")), _("audio/ogg"), sfmt_none, true, true)); #endif /* HAVE_OGG_VORBIS */ /* Ogg Opus */ #ifdef HAVE_OGG_OPUS m_map.insert(Kwave::Compression::OGG_OPUS, Kwave::Compression::Info( _(I18N_NOOP("Ogg Opus")), _("audio/opus"), sfmt_none, true, false)); #endif /* HAVE_OGG_OPUS */ } //*************************************************************************** int Kwave::Compression::toAudiofile(Kwave::Compression::Type compression) { int af_compression = AF_COMPRESSION_UNKNOWN; + fillMap(); switch (compression) { case Kwave::Compression::NONE: af_compression = AF_COMPRESSION_NONE; break; case Kwave::Compression::G722: af_compression = AF_COMPRESSION_G722; break; case Kwave::Compression::G711_ULAW: af_compression = AF_COMPRESSION_G711_ULAW; break; case Kwave::Compression::G711_ALAW: af_compression = AF_COMPRESSION_G711_ALAW; break; case Kwave::Compression::APPLE_ACE2: af_compression = AF_COMPRESSION_APPLE_ACE2; break; case Kwave::Compression::APPLE_ACE8: af_compression = AF_COMPRESSION_APPLE_ACE8; break; case Kwave::Compression::APPLE_MAC3: af_compression = AF_COMPRESSION_APPLE_MAC3; break; case Kwave::Compression::APPLE_MAC6: af_compression = AF_COMPRESSION_APPLE_MAC6; break; case Kwave::Compression::G726: af_compression = AF_COMPRESSION_G726; break; case Kwave::Compression::G728: af_compression = AF_COMPRESSION_G728; break; case Kwave::Compression::DVI_AUDIO: af_compression = AF_COMPRESSION_DVI_AUDIO; break; case Kwave::Compression::GSM: af_compression = AF_COMPRESSION_GSM; break; case Kwave::Compression::FS1016: af_compression = AF_COMPRESSION_FS1016; break; case Kwave::Compression::DV: af_compression = AF_COMPRESSION_DV; break; case Kwave::Compression::MS_ADPCM: af_compression = AF_COMPRESSION_MS_ADPCM; break; #ifdef HAVE_AF_COMPRESSION_FLAC case Kwave::Compression::FLAC: af_compression = AF_COMPRESSION_FLAC; break; #endif /* HAVE_AF_COMPRESSION_FLAC */ #ifdef HAVE_AF_COMPRESSION_ALAC case Kwave::Compression::ALAC: af_compression = AF_COMPRESSION_ALAC; break; #endif /* HAVE_AF_COMPRESSION_ALAC */ default: af_compression = AF_COMPRESSION_UNKNOWN; break; } return af_compression; } //*************************************************************************** Kwave::Compression::Type Kwave::Compression::fromAudiofile(int af_compression) { Kwave::Compression::Type compression_type; + fillMap(); switch (af_compression) { case AF_COMPRESSION_NONE : compression_type = Kwave::Compression::NONE; break; case AF_COMPRESSION_G722: compression_type = Kwave::Compression::G722; break; case AF_COMPRESSION_G711_ULAW: compression_type = Kwave::Compression::G711_ULAW; break; case AF_COMPRESSION_G711_ALAW: compression_type = Kwave::Compression::G711_ALAW; break; case AF_COMPRESSION_APPLE_ACE2: compression_type = Kwave::Compression::APPLE_ACE2; break; case AF_COMPRESSION_APPLE_ACE8: compression_type = Kwave::Compression::APPLE_ACE8; break; case AF_COMPRESSION_APPLE_MAC3: compression_type = Kwave::Compression::APPLE_MAC3; break; case AF_COMPRESSION_APPLE_MAC6: compression_type = Kwave::Compression::APPLE_MAC6; break; case AF_COMPRESSION_G726: compression_type = Kwave::Compression::G726; break; case AF_COMPRESSION_G728: compression_type = Kwave::Compression::G728; break; case AF_COMPRESSION_DVI_AUDIO: compression_type = Kwave::Compression::DVI_AUDIO; break; case AF_COMPRESSION_GSM: compression_type = Kwave::Compression::GSM; break; case AF_COMPRESSION_FS1016: compression_type = Kwave::Compression::FS1016; break; case AF_COMPRESSION_DV: compression_type = Kwave::Compression::DV; break; case AF_COMPRESSION_MS_ADPCM: compression_type = Kwave::Compression::MS_ADPCM; break; #ifdef HAVE_AF_COMPRESSION_FLAC case AF_COMPRESSION_FLAC: compression_type = Kwave::Compression::FLAC; break; #endif /* HAVE_AF_COMPRESSION_FLAC */ #ifdef HAVE_AF_COMPRESSION_ALAC case AF_COMPRESSION_ALAC: compression_type = Kwave::Compression::ALAC; break; #endif /* HAVE_AF_COMPRESSION_ALAC */ default: compression_type = Kwave::Compression::NONE; break; } return compression_type; } //*************************************************************************** //*************************************************************************** Kwave::Compression::Info::Info() :m_name(), m_mime_type(), m_sample_formats(), m_has_abr(false), m_has_vbr(false) { } //*************************************************************************** Kwave::Compression::Info::Info(const Kwave::Compression::Info &other) :m_name(other.m_name), m_mime_type(other.m_mime_type), m_sample_formats(other.m_sample_formats), m_has_abr(other.m_has_abr), m_has_vbr(other.m_has_vbr) { } //*************************************************************************** Kwave::Compression::Info::~Info() { } //*************************************************************************** Kwave::Compression::Info::Info( const QString &name, const QString &mime_type, const QList &sample_formats, bool has_abr, bool has_vbr ) :m_name(name), m_mime_type(mime_type), m_sample_formats(sample_formats), m_has_abr(has_abr), m_has_vbr(has_vbr) { } //*************************************************************************** //*************************************************************************** diff --git a/libkwave/Compression.h b/libkwave/Compression.h index f682d09f..15be4dff 100644 --- a/libkwave/Compression.h +++ b/libkwave/Compression.h @@ -1,204 +1,204 @@ /*************************************************************************** Compression.h - Wrapper for a compression ------------------- begin : Fri Jan 25 2013 copyright : (C) 2013 by Thomas Eschenbacher email : Thomas.Eschenbacher@gmx.de ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #ifndef COMPRESSION_H #define COMPRESSION_H #include "config.h" #include #include #include #include #include #include "libkwave/SampleFormat.h" namespace Kwave { class Q_DECL_EXPORT Compression { public: /** * supported compression types * @note for compatibility with older settings these values are * the same as defined in audiofile.h. */ typedef enum { INVALID = -1, NONE = 0, G722 = 501, G711_ULAW = 502, G711_ALAW = 503, APPLE_ACE2 = 504, APPLE_ACE8 = 505, APPLE_MAC3 = 506, APPLE_MAC6 = 507, G726 = 517, G728 = 518, DVI_AUDIO = 519, GSM = 520, FS1016 = 521, DV = 522, MS_ADPCM = 523, FLAC = 530, ALAC = 540, MPEG_LAYER_I = 600, MPEG_LAYER_II, MPEG_LAYER_III, OGG_VORBIS, OGG_OPUS } Type; /** * default constructor */ Compression(); /** * Constructor, from enum * @param value the enum of an already known compression type */ explicit Compression(const Type value); /** * Copy constructor * @param other another compression to copy from */ explicit Compression(const Kwave::Compression &other); /** destructor */ virtual ~Compression() {} /** assignment operator from sample_format_t */ inline void assign(Type t) { m_type = t; } /** * Returns the descriptive name of the compression, already localized * @return localized name */ QString name() const; /** * Returns the preferred mime type or an empty string */ QString preferredMimeType() const; /** * Returns a list of supported sample formats * @return list of sample formats, or empty list if none supported */ QList sampleFormats() const; /** * Returns whether average bitrate mode is supported * @return true if supported, false if not */ bool hasABR() const; /** * Returns whether variable bitrate mode is supported * @return true if supported, false if not */ bool hasVBR() const; /** conversion to int (e.g. for use in plugin parameters) */ inline int toInt() const { return static_cast(m_type); } /** conversion from int (e.g. for use in plugin parameters) */ static Kwave::Compression::Type fromInt(int i); /** conversion to a numeric value from libaudiofile */ static int toAudiofile(Kwave::Compression::Type compression); /** conversion from a numeric value from libaudiofile */ static Kwave::Compression::Type fromAudiofile(int af_compression); private: /** fills the map with known compression types (if empty) */ - void fillMap(); + static void fillMap(); private: /** internal storage of the compression type, see Type */ Type m_type; private: /** internal container class with meta data */ class Info { public: /** default constructor */ Info(); /** copy constructor */ Info(const Info &other); /** * Constructor * * @param name descriptive name of the compression, non-localized * @param mime_type preferred mime types (optional) * @param sample_formats list of supported sample formats * @param has_abr whether average bitrate mode is supported * @param has_vbr whether variable bitrate mode is supported */ Info(const QString &name, const QString &mime_type, const QList &sample_formats, bool has_abr, bool has_vbr ); /** destructor */ virtual ~Info(); public: /** non-localized descriptive name */ QString m_name; /** preferred mime type (optional) */ QString m_mime_type; /** list of supported sample formats */ QList m_sample_formats; /** true if ABR mode is supported */ bool m_has_abr; /** true if VBR mode is supported */ bool m_has_vbr; }; private: /** map with all known compression types */ static QMap m_map; }; } #endif /* COMPRESSION_H */ //*************************************************************************** //***************************************************************************