Bayonne 3 - API
 All Classes Namespaces Files Functions Variables Typedefs Macros
info.cpp
Go to the documentation of this file.
1 // Copyright (C) 2008-2011 David Sugar, Tycho Softworks.
2 //
3 // This file is part of GNU Bayonne.
4 //
5 // GNU Bayonne is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // GNU Bayonne is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with GNU Bayonne. If not, see <http://www.gnu.org/licenses/>.
17 
18 #include <config.h>
19 #include <ucommon/ucommon.h>
20 #include <ucommon/export.h>
21 #include <bayonne.h>
22 
23 using namespace BAYONNE_NAMESPACE;
24 using namespace UCOMMON_NAMESPACE;
25 
26 Audio::Info::Info()
27 {
28  clear();
29 }
30 
31 void Audio::Info::clear(void)
32 {
33  memset(this, 0, sizeof(Info));
34 }
35 
36 void Audio::Info::setRate(rate_t r)
37 {
38  rate = getRate(encoding, r);
39  set();
40 }
41 
42 void Audio::Info::setFraming(timeout_t timeout)
43 {
44  set();
45 
46  framing = getFraming(encoding);
47 
48  if(!timeout)
49  return;
50 
51  if(framing) {
52  timeout = (timeout / framing);
53  if(!timeout)
54  timeout = framing;
55  else
56  timeout = timeout * framing;
57  }
58 
59  switch(timeout) {
60  case 10:
61  case 15:
62  case 20:
63  case 30:
64  case 40:
65  break;
66  default:
67  timeout = 20;
68  }
69 
70  framing = timeout;
71  framecount = (rate * framing) / 1000l;
72  framesize = (unsigned)toBytes(encoding, framecount);
73 }
74 
75 void Audio::Info::set(void)
76 {
77  switch(encoding) {
78  case mp1Audio:
79  framecount = 384;
80  framesize = (12 * bitrate / rate) * 4 + headersize + padding;
81  return;
82  case mp2Audio:
83  case mp3Audio:
84  framecount = 1152;
85  framesize = (144 * bitrate / rate) + headersize + padding;
86  return;
87  default:
88  break;
89  }
90  if(!framesize)
91  framesize = getFrame(encoding);
92 
93  if(!framecount)
94  framecount = getCount(encoding);
95 
96  if(!rate)
97  rate = getRate(encoding);
98 
99  if(!bitrate && rate && framesize && framecount)
100  bitrate = ((long)framesize * 8l * rate) / (long)framecount;
101 }
102 
#define BAYONNE_NAMESPACE
Definition: bayonne.h:25
GNU Bayonne library namespace.