1 | /********** |
2 | This library is free software; you can redistribute it and/or modify it under |
3 | the terms of the GNU Lesser General Public License as published by the |
4 | Free Software Foundation; either version 3 of the License, or (at your |
5 | option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.) |
6 | |
7 | This library is distributed in the hope that it will be useful, but WITHOUT |
8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for |
10 | more details. |
11 | |
12 | You should have received a copy of the GNU Lesser General Public License |
13 | along with this library; if not, write to the Free Software Foundation, Inc., |
14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
15 | **********/ |
16 | // "liveMedia" |
17 | // Copyright (c) 1996-2020 Live Networks, Inc. All rights reserved. |
18 | // Filters for converting between raw PCM audio and uLaw |
19 | // C++ header |
20 | |
21 | #ifndef _ULAW_AUDIO_FILTER_HH |
22 | #define _ULAW_AUDIO_FILTER_HH |
23 | |
24 | #ifndef _FRAMED_FILTER_HH |
25 | #include "FramedFilter.hh" |
26 | #endif |
27 | |
28 | ////////// 16-bit PCM (in various byte orderings) -> 8-bit u-Law ////////// |
29 | |
30 | class uLawFromPCMAudioSource: public FramedFilter { |
31 | public: |
32 | static uLawFromPCMAudioSource* |
33 | createNew(UsageEnvironment& env, FramedSource* inputSource, |
34 | int byteOrdering = 0); |
35 | // "byteOrdering" == 0 => host order (the default) |
36 | // "byteOrdering" == 1 => little-endian order |
37 | // "byteOrdering" == 2 => network (i.e., big-endian) order |
38 | |
39 | protected: |
40 | uLawFromPCMAudioSource(UsageEnvironment& env, FramedSource* inputSource, |
41 | int byteOrdering); |
42 | // called only by createNew() |
43 | virtual ~uLawFromPCMAudioSource(); |
44 | |
45 | private: |
46 | // Redefined virtual functions: |
47 | virtual void doGetNextFrame(); |
48 | |
49 | private: |
50 | static void afterGettingFrame(void* clientData, unsigned frameSize, |
51 | unsigned numTruncatedBytes, |
52 | struct timeval presentationTime, |
53 | unsigned durationInMicroseconds); |
54 | void afterGettingFrame1(unsigned frameSize, |
55 | unsigned numTruncatedBytes, |
56 | struct timeval presentationTime, |
57 | unsigned durationInMicroseconds); |
58 | |
59 | private: |
60 | int fByteOrdering; |
61 | unsigned char* fInputBuffer; |
62 | unsigned fInputBufferSize; |
63 | }; |
64 | |
65 | |
66 | ////////// u-Law -> 16-bit PCM (in host order) ////////// |
67 | |
68 | class PCMFromuLawAudioSource: public FramedFilter { |
69 | public: |
70 | static PCMFromuLawAudioSource* |
71 | createNew(UsageEnvironment& env, FramedSource* inputSource); |
72 | |
73 | protected: |
74 | PCMFromuLawAudioSource(UsageEnvironment& env, |
75 | FramedSource* inputSource); |
76 | // called only by createNew() |
77 | virtual ~PCMFromuLawAudioSource(); |
78 | |
79 | private: |
80 | // Redefined virtual functions: |
81 | virtual void doGetNextFrame(); |
82 | |
83 | private: |
84 | static void afterGettingFrame(void* clientData, unsigned frameSize, |
85 | unsigned numTruncatedBytes, |
86 | struct timeval presentationTime, |
87 | unsigned durationInMicroseconds); |
88 | void afterGettingFrame1(unsigned frameSize, |
89 | unsigned numTruncatedBytes, |
90 | struct timeval presentationTime, |
91 | unsigned durationInMicroseconds); |
92 | |
93 | private: |
94 | unsigned char* fInputBuffer; |
95 | unsigned fInputBufferSize; |
96 | }; |
97 | |
98 | |
99 | ////////// 16-bit values (in host order) -> 16-bit network order ////////// |
100 | |
101 | class NetworkFromHostOrder16: public FramedFilter { |
102 | public: |
103 | static NetworkFromHostOrder16* |
104 | createNew(UsageEnvironment& env, FramedSource* inputSource); |
105 | |
106 | protected: |
107 | NetworkFromHostOrder16(UsageEnvironment& env, FramedSource* inputSource); |
108 | // called only by createNew() |
109 | virtual ~NetworkFromHostOrder16(); |
110 | |
111 | private: |
112 | // Redefined virtual functions: |
113 | virtual void doGetNextFrame(); |
114 | |
115 | private: |
116 | static void afterGettingFrame(void* clientData, unsigned frameSize, |
117 | unsigned numTruncatedBytes, |
118 | struct timeval presentationTime, |
119 | unsigned durationInMicroseconds); |
120 | void afterGettingFrame1(unsigned frameSize, |
121 | unsigned numTruncatedBytes, |
122 | struct timeval presentationTime, |
123 | unsigned durationInMicroseconds); |
124 | }; |
125 | |
126 | |
127 | ////////// 16-bit values (in network order) -> 16-bit host order ////////// |
128 | |
129 | class HostFromNetworkOrder16: public FramedFilter { |
130 | public: |
131 | static HostFromNetworkOrder16* |
132 | createNew(UsageEnvironment& env, FramedSource* inputSource); |
133 | |
134 | protected: |
135 | HostFromNetworkOrder16(UsageEnvironment& env, FramedSource* inputSource); |
136 | // called only by createNew() |
137 | virtual ~HostFromNetworkOrder16(); |
138 | |
139 | private: |
140 | // Redefined virtual functions: |
141 | virtual void doGetNextFrame(); |
142 | |
143 | private: |
144 | static void afterGettingFrame(void* clientData, unsigned frameSize, |
145 | unsigned numTruncatedBytes, |
146 | struct timeval presentationTime, |
147 | unsigned durationInMicroseconds); |
148 | void afterGettingFrame1(unsigned frameSize, |
149 | unsigned numTruncatedBytes, |
150 | struct timeval presentationTime, |
151 | unsigned durationInMicroseconds); |
152 | }; |
153 | |
154 | |
155 | ////////// 16-bit values: little-endian <-> big-endian ////////// |
156 | |
157 | class EndianSwap16: public FramedFilter { |
158 | public: |
159 | static EndianSwap16* createNew(UsageEnvironment& env, FramedSource* inputSource); |
160 | |
161 | protected: |
162 | EndianSwap16(UsageEnvironment& env, FramedSource* inputSource); |
163 | // called only by createNew() |
164 | virtual ~EndianSwap16(); |
165 | |
166 | private: |
167 | // Redefined virtual functions: |
168 | virtual void doGetNextFrame(); |
169 | |
170 | private: |
171 | static void afterGettingFrame(void* clientData, unsigned frameSize, |
172 | unsigned numTruncatedBytes, |
173 | struct timeval presentationTime, |
174 | unsigned durationInMicroseconds); |
175 | void afterGettingFrame1(unsigned frameSize, |
176 | unsigned numTruncatedBytes, |
177 | struct timeval presentationTime, |
178 | unsigned durationInMicroseconds); |
179 | }; |
180 | |
181 | |
182 | ////////// 24-bit values: little-endian <-> big-endian ////////// |
183 | |
184 | class EndianSwap24: public FramedFilter { |
185 | public: |
186 | static EndianSwap24* createNew(UsageEnvironment& env, FramedSource* inputSource); |
187 | |
188 | protected: |
189 | EndianSwap24(UsageEnvironment& env, FramedSource* inputSource); |
190 | // called only by createNew() |
191 | virtual ~EndianSwap24(); |
192 | |
193 | private: |
194 | // Redefined virtual functions: |
195 | virtual void doGetNextFrame(); |
196 | |
197 | private: |
198 | static void afterGettingFrame(void* clientData, unsigned frameSize, |
199 | unsigned numTruncatedBytes, |
200 | struct timeval presentationTime, |
201 | unsigned durationInMicroseconds); |
202 | void afterGettingFrame1(unsigned frameSize, |
203 | unsigned numTruncatedBytes, |
204 | struct timeval presentationTime, |
205 | unsigned durationInMicroseconds); |
206 | }; |
207 | |
208 | #endif |
209 | |