kwave  18.07.70
Compression.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  Compression.cpp - Wrapper for a compression
3  -------------------
4  begin : Fri Jan 25 2013
5  copyright : (C) 2013 by Thomas Eschenbacher
6  email : Thomas.Eschenbacher@gmx.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "config.h"
19 
20 #include <new>
21 #include <stdlib.h>
22 
23 #include <audiofile.h>
24 
25 #include "libkwave/Compression.h"
26 
27 /* static instance */
28 QMap<int, Kwave::Compression::Info> Kwave::Compression::m_map;
29 
30 //***************************************************************************
32  :m_type(Kwave::Compression::NONE)
33 {
34  fillMap();
35 }
36 
37 //***************************************************************************
39  :m_type(value)
40 {
41  fillMap();
42 }
43 
44 //***************************************************************************
45 QString Kwave::Compression::name() const
46 {
47  return (m_map.contains(m_type)) ?
48  i18n(UTF8(m_map[m_type].m_name)) : QString();
49 }
50 
51 //***************************************************************************
53 {
54  return (m_map.contains(m_type)) ?
55  i18n(UTF8(m_map[m_type].m_mime_type)) : QString();
56 }
57 
58 //***************************************************************************
59 QList<Kwave::SampleFormat> Kwave::Compression::sampleFormats() const
60 {
61  return (m_map.contains(m_type)) ?
62  m_map[m_type].m_sample_formats : QList<Kwave::SampleFormat>();
63 }
64 
65 //***************************************************************************
67 {
68  return (m_map.contains(m_type)) ? m_map[m_type].m_has_abr : false;
69 }
70 
71 //***************************************************************************
73 {
74  return (m_map.contains(m_type)) ? m_map[m_type].m_has_vbr : false;
75 }
76 
77 //***************************************************************************
79 {
80  fillMap();
81  return (m_map.contains(static_cast<Kwave::Compression::Type>(i))) ?
82  static_cast<Kwave::Compression::Type>(i) : Kwave::Compression::NONE;
83 }
84 
85 //***************************************************************************
87 {
88  if (!m_map.isEmpty()) return; // bail out if already filled
89 
90  QList<Kwave::SampleFormat> sfmt_none;
91 
92  QList<Kwave::SampleFormat> sfmt_int;
95 
96  QList<Kwave::SampleFormat> sfmt_all;
97  sfmt_all += sfmt_int;
100 
101  /* no compression */
102 
104  _(I18N_NOOP("No Compression")),
105  QString(),
106  sfmt_all, false, false));
107 
108  /* types supported by OSS+ALSA record plugin and WAV codec */
109 
111  _(I18N_NOOP("CCITT G.711 u-law")),
112  QString(),
113  sfmt_int, false, false));
115  _(I18N_NOOP("CCITT G.711 A-law")),
116  QString(),
117  sfmt_int, false, false));
119  _(I18N_NOOP("MS ADPCM")),
120  QString(),
121  sfmt_int, false, false));
123  _(I18N_NOOP("GSM")),
124  QString(),
125  sfmt_int, false, false));
126 
127  /* compression types from libaudiofile (for display only, not supported) */
129  _(I18N_NOOP("G722")),
130  QString(),
131  sfmt_none, true, false));
133  _(I18N_NOOP("Apple ACE2")),
134  QString(),
135  sfmt_none, true, false));
137  _(I18N_NOOP("Apple ACE8")),
138  QString(),
139  sfmt_none, true, false));
141  _(I18N_NOOP("Apple MAC3")),
142  QString(),
143  sfmt_none, true, false));
145  _(I18N_NOOP("Apple MAC6")),
146  QString(),
147  sfmt_none, true, false));
149  _(I18N_NOOP("G726")),
150  QString(),
151  sfmt_none, true, false));
153  _(I18N_NOOP("DVI Audio / IMA")),
154  QString(),
155  sfmt_none, true, false));
157  _(I18N_NOOP("FS1016")),
158  QString(),
159  sfmt_none, true, false));
161  _(I18N_NOOP("DV")),
162  QString(),
163  sfmt_none, true, false));
164 
165  /* MPEG layer I/II/III */
166 #ifdef HAVE_MP3
168  _(I18N_NOOP("MPEG Layer I")),
169  _("audio/x-mp3"),
170  sfmt_none, true, false));
172  _(I18N_NOOP("MPEG Layer II")),
173  _("audio/x-mp3"),
174  sfmt_none, true, false));
176  _(I18N_NOOP("MPEG Layer III")),
177  _("audio/x-mp3"),
178  sfmt_none, true, false));
179 #endif /* HAVE_MP3 */
180 
181  /* FLAC */
182 #ifdef HAVE_FLAC
184  _(I18N_NOOP("FLAC")),
185  _("audio/x-flac"),
186  sfmt_none, false, false));
187 #endif /* HAVE_FLAC */
188 
189  /* Ogg Vorbis */
190 #ifdef HAVE_OGG_VORBIS
192  _(I18N_NOOP("Ogg Vorbis")),
193  _("audio/ogg"),
194  sfmt_none, true, true));
195 #endif /* HAVE_OGG_VORBIS */
196 
197  /* Ogg Opus */
198 #ifdef HAVE_OGG_OPUS
200  _(I18N_NOOP("Ogg Opus")),
201  _("audio/opus"),
202  sfmt_none, true, false));
203 #endif /* HAVE_OGG_OPUS */
204 
205 }
206 
207 //***************************************************************************
209 {
210  int af_compression = AF_COMPRESSION_UNKNOWN;
211 
212  fillMap();
213  switch (compression)
214  {
216  af_compression = AF_COMPRESSION_NONE;
217  break;
219  af_compression = AF_COMPRESSION_G722;
220  break;
222  af_compression = AF_COMPRESSION_G711_ULAW;
223  break;
225  af_compression = AF_COMPRESSION_G711_ALAW;
226  break;
228  af_compression = AF_COMPRESSION_APPLE_ACE2;
229  break;
231  af_compression = AF_COMPRESSION_APPLE_ACE8;
232  break;
234  af_compression = AF_COMPRESSION_APPLE_MAC3;
235  break;
237  af_compression = AF_COMPRESSION_APPLE_MAC6;
238  break;
240  af_compression = AF_COMPRESSION_G726;
241  break;
243  af_compression = AF_COMPRESSION_G728;
244  break;
246  af_compression = AF_COMPRESSION_DVI_AUDIO;
247  break;
249  af_compression = AF_COMPRESSION_GSM;
250  break;
252  af_compression = AF_COMPRESSION_FS1016;
253  break;
255  af_compression = AF_COMPRESSION_DV;
256  break;
258  af_compression = AF_COMPRESSION_MS_ADPCM;
259  break;
260 #ifdef HAVE_AF_COMPRESSION_FLAC
262  af_compression = AF_COMPRESSION_FLAC;
263  break;
264 #endif /* HAVE_AF_COMPRESSION_FLAC */
265 #ifdef HAVE_AF_COMPRESSION_ALAC
267  af_compression = AF_COMPRESSION_ALAC;
268  break;
269 #endif /* HAVE_AF_COMPRESSION_ALAC */
270  default:
271  af_compression = AF_COMPRESSION_UNKNOWN;
272  break;
273  }
274 
275  return af_compression;
276 }
277 
278 //***************************************************************************
280 {
281  Kwave::Compression::Type compression_type;
282 
283  fillMap();
284  switch (af_compression)
285  {
286  case AF_COMPRESSION_NONE :
287  compression_type = Kwave::Compression::NONE;
288  break;
289  case AF_COMPRESSION_G722:
290  compression_type = Kwave::Compression::G722;
291  break;
292  case AF_COMPRESSION_G711_ULAW:
293  compression_type = Kwave::Compression::G711_ULAW;
294  break;
295  case AF_COMPRESSION_G711_ALAW:
296  compression_type = Kwave::Compression::G711_ALAW;
297  break;
298  case AF_COMPRESSION_APPLE_ACE2:
299  compression_type = Kwave::Compression::APPLE_ACE2;
300  break;
301  case AF_COMPRESSION_APPLE_ACE8:
302  compression_type = Kwave::Compression::APPLE_ACE8;
303  break;
304  case AF_COMPRESSION_APPLE_MAC3:
305  compression_type = Kwave::Compression::APPLE_MAC3;
306  break;
307  case AF_COMPRESSION_APPLE_MAC6:
308  compression_type = Kwave::Compression::APPLE_MAC6;
309  break;
310  case AF_COMPRESSION_G726:
311  compression_type = Kwave::Compression::G726;
312  break;
313  case AF_COMPRESSION_G728:
314  compression_type = Kwave::Compression::G728;
315  break;
316  case AF_COMPRESSION_DVI_AUDIO:
317  compression_type = Kwave::Compression::DVI_AUDIO;
318  break;
319  case AF_COMPRESSION_GSM:
320  compression_type = Kwave::Compression::GSM;
321  break;
322  case AF_COMPRESSION_FS1016:
323  compression_type = Kwave::Compression::FS1016;
324  break;
325  case AF_COMPRESSION_DV:
326  compression_type = Kwave::Compression::DV;
327  break;
328  case AF_COMPRESSION_MS_ADPCM:
329  compression_type = Kwave::Compression::MS_ADPCM;
330  break;
331 #ifdef HAVE_AF_COMPRESSION_FLAC
332  case AF_COMPRESSION_FLAC:
333  compression_type = Kwave::Compression::FLAC;
334  break;
335 #endif /* HAVE_AF_COMPRESSION_FLAC */
336 #ifdef HAVE_AF_COMPRESSION_ALAC
337  case AF_COMPRESSION_ALAC:
338  compression_type = Kwave::Compression::ALAC;
339  break;
340 #endif /* HAVE_AF_COMPRESSION_ALAC */
341  default:
342  compression_type = Kwave::Compression::NONE;
343  break;
344  }
345 
346  return compression_type;
347 }
348 
349 //***************************************************************************
350 //***************************************************************************
352  :m_name(),
353  m_mime_type(),
354  m_sample_formats(),
355  m_has_abr(false),
356  m_has_vbr(false)
357 {
358 }
359 
360 //***************************************************************************
362  :m_name(other.m_name),
363  m_mime_type(other.m_mime_type),
365  m_has_abr(other.m_has_abr),
366  m_has_vbr(other.m_has_vbr)
367 {
368 }
369 
370 //***************************************************************************
372 {
373 }
374 
375 //***************************************************************************
377  const QString &name,
378  const QString &mime_type,
379  const QList<Kwave::SampleFormat> &sample_formats,
380  bool has_abr,
381  bool has_vbr
382 )
383  :m_name(name),
384  m_mime_type(mime_type),
385  m_sample_formats(sample_formats),
386  m_has_abr(has_abr),
387  m_has_vbr(has_vbr)
388 {
389 }
390 
391 //***************************************************************************
392 //***************************************************************************
static Kwave::Compression::Type fromAudiofile(int af_compression)
QString preferredMimeType() const
Definition: Compression.cpp:52
Definition: App.h:33
static void fillMap()
Definition: Compression.cpp:86
bool hasABR() const
Definition: Compression.cpp:66
static QMap< int, Kwave::Compression::Info > m_map
Definition: Compression.h:196
QString name() const
Definition: Compression.cpp:45
static Kwave::Compression::Type fromInt(int i)
Definition: Compression.cpp:78
QList< Kwave::SampleFormat > m_sample_formats
Definition: Compression.h:184
bool hasVBR() const
Definition: Compression.cpp:72
QList< Kwave::SampleFormat > sampleFormats() const
Definition: Compression.cpp:59
static int toAudiofile(Kwave::Compression::Type compression)
#define _(m)
Definition: memcpy.c:66
#define UTF8(qs)
Definition: String.h:48