kwave  18.07.70
StandardBitrates.cpp
Go to the documentation of this file.
1 /*************************************************************************
2  StandardBitrates.h - well known bitrates from ogg/vorbis + MP3
3  -------------------
4  begin : Tue Jun 17 2003
5  copyright : (C) 2003 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"
20 #include <limits.h>
21 
24 
25 //***************************************************************************
27  :QList<int>()
28 {
29  // use well-known bitrates from MP3
30  append( 8000);
31  append( 16000);
32  append( 24000);
33  append( 32000);
34  append( 40000);
35  append( 56000);
36  append( 64000);
37  append( 80000);
38  append( 96000);
39  append(112000);
40  append(128000);
41  append(144000);
42  append(160000);
43  append(176000);
44  append(192000);
45  append(224000);
46  append(256000);
47  append(288000);
48  append(320000);
49  append(352000);
50  append(384000);
51  append(416000);
52  append(448000);
53 }
54 
55 //***************************************************************************
57 {
58 }
59 
60 //***************************************************************************
62 {
63  return g_bitrates;
64 }
65 
66 //***************************************************************************
68 {
69  int best = rate;
70  int min_delta = INT_MAX;
71 
72  foreach (int value, *this) {
73  int delta = (value > rate) ? (value-rate) : (rate-value);
74  if (!delta) return rate; // complete match, easy case
75 
76  if (delta < min_delta) {
77  // found a better alternative
78  min_delta = delta;
79  best = value;
80  }
81  }
82 
83  return best;
84 }
85 
86 //***************************************************************************
87 //***************************************************************************
static Kwave::StandardBitrates g_bitrates
virtual int nearest(int rate) const
static const StandardBitrates & instance()