Jpp  17.3.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
infoword.hh File Reference
#include <ostream>
#include <stdint.h>

Go to the source code of this file.

Functions

static unsigned int roundUpPow2 (unsigned int n, unsigned int multiple)
 
struct __attribute__ ((__packed__)) InfoWord
 
std::ostream & operator<< (std::ostream &stream, const InfoWord &iw)
 
bool is_infoword (const void *const data)
 

Function Documentation

static unsigned int roundUpPow2 ( unsigned int  n,
unsigned int  multiple 
)
inlinestatic
Author
cpellegrino

Definition at line 13 of file infoword.hh.

14 {
15  return (n + multiple - 1) & ~(multiple - 1);
16 }
const int n
Definition: JPolint.hh:697
struct __attribute__ ( (__packed__)  )

Definition at line 18 of file infoword.hh.

19 {
20  uint8_t head;
21  uint8_t SamplingRate;
22  uint32_t TimeInfo;
23 
24  unsigned int ChannelMask() const
25  {
26  const static uint8_t mask = 0x60;
27  return (mask & head) >> 5;
28  }
29 
30  unsigned int Amplitude() const
31  {
32  const static uint8_t mask = 0x18;
33  return (mask & head) >> 3;
34  }
35 
36  bool Mark() const
37  {
38  const static uint8_t mask = 0x80;
39  return mask & head;
40  }
41 
42  unsigned int amplitude() const
43  {
44  switch (Amplitude())
45  {
46  case 1: return 16;
47  case 2: return 24;
48  }
49  return 12;
50  }
51 
52  unsigned int timeInfo() const
53  {
54  return ntohl(TimeInfo);
55  }
56 
57  double samplingRate() const
58  {
59  const static double conv_factor = 1e6 / 128;
60  return SamplingRate * conv_factor;
61  }
62 
63  unsigned int audioWordSize() const
64  {
65  unsigned int sample_size_bit = amplitude();
66 
67  if (!ChannelMask()) // 0 ==> 2 channels, else only one
68  sample_size_bit <<= 1; // fast double the conteined value
69 
70  const unsigned int size_bit = sample_size_bit + 8;
71 
72  return roundUpPow2(size_bit, 16) >> 3; // return, in Bytes, the
73  // minimum multiple of 16
74  // bit greater then size_bit
75  }
76 
77 };
static unsigned int roundUpPow2(unsigned int n, unsigned int multiple)
Definition: infoword.hh:13
std::ostream& operator<< ( std::ostream &  stream,
const InfoWord &  iw 
)
inline

Definition at line 80 of file infoword.hh.

81 {
82  return stream
83  << "Is an InfoWord: " << iw.Mark() << '\n'
84  << "ChannelMask: " << iw.ChannelMask() << '\n'
85  << "Amplitude: " << iw.Amplitude() << '\n'
86  << "Amplitude (human): " << iw.amplitude() << " bit" << '\n'
87  << "Sampling rate: " << (uint32_t) iw.SamplingRate << '\n'
88  << "Sampling rate (human): " << iw.samplingRate() << " Hz" << '\n'
89  << "TimeInfo: " << iw.timeInfo();
90 }
bool is_infoword ( const void *const  data)
inline

Definition at line 93 of file infoword.hh.

94 {
95  const static unsigned char mask = 0x80;
96  const unsigned char* const p = static_cast<const unsigned char* const>(
97  data);
98 
99  return (*p & mask);
100 }