Alexa Auto SDK  2.3.1
AudioFormat.h
1 /*
2  * Copyright 2017-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0/
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 #ifndef AACE_AUDIO_AUDIO_FORMAT_H
17 #define AACE_AUDIO_AUDIO_FORMAT_H
18 
19 #include <iostream>
20 #include <vector>
21 #include <string>
22 
25 namespace aace {
26 namespace audio {
27 
28 class AudioFormat {
29 public:
30  enum class Encoding { UNKNOWN, LPCM, MP3, OPUS };
31 
32  enum class SampleFormat { UNKNOWN, SIGNED, UNSIGNED, FLOAT };
33 
34  enum class Layout { UNKNOWN, NON_INTERLEAVED, INTERLEAVED };
35 
36  enum class Endianness { UNKNOWN, LITTLE, BIG };
37 
38  static AudioFormat UNKNOWN;
39 
40 private:
41  AudioFormat() = default;
42 
43 public:
44  AudioFormat(
45  Encoding encoding,
46  SampleFormat sampleFormat,
47  Layout layout,
48  Endianness endianness,
49  uint32_t sampleRate,
50  uint8_t sampleSize,
51  uint8_t channels);
52 
59  Encoding getEncoding();
60 
61  SampleFormat getSampleFormat();
62 
63  Layout getLayout();
64 
65  Endianness getEndianness();
66 
67  uint32_t getSampleRate();
68 
69  uint8_t getSampleSize();
70 
71  uint8_t getNumChannels();
72 
73 private:
74  Encoding m_encoding;
75  SampleFormat m_sampleFormat;
76  Layout m_layout;
77  Endianness m_endianness;
78  uint32_t m_sampleRate;
79  uint8_t m_sampleSize;
80  uint8_t m_channels;
81 };
82 
83 inline std::ostream& operator<<(std::ostream& stream, const AudioFormat::Encoding& encoding) {
84  switch (encoding) {
85  case AudioFormat::Encoding::UNKNOWN:
86  stream << "UNKNOWN";
87  break;
88  case AudioFormat::Encoding::LPCM:
89  stream << "LPCM";
90  break;
91  case AudioFormat::Encoding::MP3:
92  stream << "MP3";
93  break;
94  case AudioFormat::Encoding::OPUS:
95  stream << "OPUS";
96  break;
97  }
98  return stream;
99 }
100 
101 inline std::ostream& operator<<(std::ostream& stream, const AudioFormat::SampleFormat& sampleFormat) {
102  switch (sampleFormat) {
103  case AudioFormat::SampleFormat::UNKNOWN:
104  stream << "UNKNOWN";
105  break;
106  case AudioFormat::SampleFormat::SIGNED:
107  stream << "SIGNED";
108  break;
109  case AudioFormat::SampleFormat::UNSIGNED:
110  stream << "UNSIGNED";
111  break;
112  case AudioFormat::SampleFormat::FLOAT:
113  stream << "FLOAT";
114  break;
115  }
116  return stream;
117 }
118 
119 inline std::ostream& operator<<(std::ostream& stream, const AudioFormat::Layout& layout) {
120  switch (layout) {
121  case AudioFormat::Layout::UNKNOWN:
122  stream << "UNKNOWN";
123  break;
124  case AudioFormat::Layout::NON_INTERLEAVED:
125  stream << "NON_INTERLEAVED";
126  break;
127  case AudioFormat::Layout::INTERLEAVED:
128  stream << "INTERLEAVED";
129  break;
130  }
131  return stream;
132 }
133 
134 inline std::ostream& operator<<(std::ostream& stream, const AudioFormat::Endianness& endianness) {
135  switch (endianness) {
136  case AudioFormat::Endianness::UNKNOWN:
137  stream << "UNKNOWN";
138  break;
139  case AudioFormat::Endianness::LITTLE:
140  stream << "LITTLE";
141  break;
142  case AudioFormat::Endianness::BIG:
143  stream << "BIG";
144  break;
145  }
146  return stream;
147 }
148 
149 } // namespace audio
150 } // namespace aace
151 
152 #endif // AACE_AUDIO_AUDIO_FORMAT_H
Definition: AddressBook.h:26

Alexa Auto SDK 2.3.1 - Copyright 2017-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0