1 /* |
|
2 * Copyright (c) 2010 Ixonos Plc. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - Initial contribution |
|
11 * |
|
12 * Contributors: |
|
13 * Ixonos Plc |
|
14 * |
|
15 * Description: |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #ifndef __PROCTOOLS_H__ |
|
22 #define __PROCTOOLS_H__ |
|
23 |
|
24 #include <e32base.h> |
|
25 #include <f32file.h> |
|
26 #include "AudCommon.h" |
|
27 #include "ProcConstants.h" |
|
28 #include "Mp3API.h" |
|
29 |
|
30 class ProcTools |
|
31 { |
|
32 |
|
33 public: |
|
34 |
|
35 /** |
|
36 * Decimal number to binary number |
|
37 */ |
|
38 static TBool Dec2Bin(TUint8 aDec, TBuf8<8>& aBinary); |
|
39 /** |
|
40 * This version allocates memory (aBin), remember to release |
|
41 */ |
|
42 static TBool Dec2BinL(TUint32 aDec, HBufC8*& aBin); |
|
43 |
|
44 /** |
|
45 * Binary number to decimal number |
|
46 */ |
|
47 static TBool Bin2Dec(const TDesC8& aBin, TUint& aDec); |
|
48 |
|
49 /** |
|
50 * Decimal number in descriptor to unsigned integer |
|
51 */ |
|
52 static TBool Des2Dec(TDesC8& aDes, TUint& aDec); |
|
53 |
|
54 /** |
|
55 * Decimal number in descriptor to binary descriptor |
|
56 * allocates memory, the caller must release |
|
57 */ |
|
58 static TBool Des2BinL(const TDesC8& aDes, HBufC8*& aBin); |
|
59 |
|
60 /** |
|
61 * Gets milliseconds(TInt) from microseconds (TTimeIntervalMicroSeconds) |
|
62 * @param aMicroSeconds microseconds |
|
63 * |
|
64 * @return milliseconds |
|
65 */ |
|
66 |
|
67 static TInt MilliSeconds(TTimeIntervalMicroSeconds aMicroSeconds); |
|
68 |
|
69 /** |
|
70 * Gets microseconds (TTimeIntervalMicroSeconds) from milliseconds (TInt) |
|
71 * @param aMilliSeconds milliseconds |
|
72 * |
|
73 * @return microiseconds |
|
74 */ |
|
75 |
|
76 static TTimeIntervalMicroSeconds MicroSeconds(TInt aMilliSeconds); |
|
77 |
|
78 /** |
|
79 * casts TInt64 to TInt (overflow possible, the user is resonsible!!) |
|
80 * |
|
81 * @param aInt64 TInt64 |
|
82 * |
|
83 * @return Tint |
|
84 */ |
|
85 |
|
86 static TInt GetTInt(TInt64 aTInt64); |
|
87 |
|
88 |
|
89 /** |
|
90 * Retrieves a decimal number from a frame |
|
91 * |
|
92 * @param aFrame frame |
|
93 * @param aBitFirst index of the first bit of the needed balue |
|
94 * @param aLength number of bits in the needed value |
|
95 * |
|
96 * @return retrieved integer, if -1 then operation was unsuccessful |
|
97 */ |
|
98 static TInt GetValueFromFrame(const HBufC8* aFrame, TInt aBitFirst, TInt aLength); |
|
99 |
|
100 /** |
|
101 * Retrieves a decimal number from a frame, whose bits are shuffled |
|
102 * |
|
103 * @param aFrame frame |
|
104 * @param aBitRate bitrate |
|
105 * @param aBitPositions bit position in a deshuffled frame |
|
106 * @param aLength number of bits read |
|
107 * |
|
108 * @return retrieved integer |
|
109 * |
|
110 */ |
|
111 static TInt GetValueFromShuffledAWBFrameL(const HBufC8* aFrame, TInt aBitRate, TInt aBitPosition, TInt aLength); |
|
112 |
|
113 static TBool SetValueToShuffledAWBFrame(TUint8 aNewValue, HBufC8* aFrame, |
|
114 TInt aBitRate, TInt aBitPosition, TInt aLength); |
|
115 |
|
116 /** |
|
117 * Retrieves a decimal number from a frame, whose bits are shuffled |
|
118 * |
|
119 * @param aFrame frame |
|
120 * @param aBitPositions shuffling table |
|
121 * @param TInt aSize length of <code>aBitPositions</code> |
|
122 * |
|
123 * @return retrieved integer, if -1 then operation was unsuccessful |
|
124 * |
|
125 */ |
|
126 static TInt GetValueFromShuffledFrame(const HBufC8* aFrame, const TUint8 aBitPositions[], TInt aSize); |
|
127 |
|
128 |
|
129 /** |
|
130 * Writes a decimal number to a frame, whose bits are shuffled |
|
131 * |
|
132 * @param aFrame frame |
|
133 * @param aNewValue value to be written |
|
134 * @param aBitPositions bit indexes in order |
|
135 * @param TInt aSize length of <code>aBitPositions</code> |
|
136 * |
|
137 * @return ETrue if successful |
|
138 * |
|
139 */ |
|
140 static TBool SetValueToShuffledFrame(HBufC8* aFrame, TUint8 aNewValue, const TUint8 aBitPositions[], TInt aSize); |
|
141 |
|
142 /** |
|
143 * Appends integers to a file separated by linefeeds |
|
144 * Mostly for debugging purposes |
|
145 * |
|
146 * @param aArray array of integers to be written |
|
147 * @param aFilename file name, created if doesn't exist, append otherwise |
|
148 * |
|
149 * @return ETrue if successful |
|
150 */ |
|
151 static TBool WriteValuesToFileL(const RArray<TInt>& aArray, const TDesC& aFilename); |
|
152 |
|
153 /** |
|
154 * Finds a closest match in a gain table |
|
155 * used for scalar quantized gain tables |
|
156 * |
|
157 * @param aNewGain search key |
|
158 * @param aGainTable gain table |
|
159 * @param aTableSize gain table length |
|
160 * |
|
161 * @return index of the closest match |
|
162 */ |
|
163 static TUint8 FindNewIndexSQ(TInt aNewGain, const TInt aGainTable[], TInt aTableSize); |
|
164 |
|
165 /** |
|
166 * Finds a closest match in a gain table |
|
167 * used for vector quantized gain tables |
|
168 * pitch: Q14. FC gain Q12 |
|
169 * |
|
170 * @param aNewGain search key |
|
171 * @param aGainTable gain table |
|
172 * @param aTableSize gain table length |
|
173 * |
|
174 * @return index of the closest match |
|
175 */ |
|
176 static TUint8 FindNewIndexVQ(TInt aNewGain, TInt aOldPitch, const TInt aGainTable[], TInt aTableSize); |
|
177 |
|
178 /** |
|
179 * Finds a closest match in a gain table |
|
180 * used for vector quantized gain tables |
|
181 * pitch: Q14. FC gain Q11!! |
|
182 * |
|
183 * @param aNewGain search key |
|
184 * @param aGainTable gain table |
|
185 * @param aTableSize gain table length |
|
186 * |
|
187 * @return index of the closest match |
|
188 */ |
|
189 static TUint8 FindNewIndexVQ2(TInt aNewGain, TInt aOldPitch, const TInt aGainTable[], TInt aTableSize); |
|
190 |
|
191 |
|
192 /** |
|
193 * Finds a closest match in a gain table for 4.75 kBit/s |
|
194 * |
|
195 * @param aNewGain0 new gain of subframe 0 or 2 |
|
196 * @param aOldPitch0 new pitch of subframe 0 or 2 |
|
197 * @param aNewGain1 new gain of subframe 1 or 3 |
|
198 * @param aNewGain1 new pitch of subframe 1 or 3 |
|
199 * |
|
200 */ |
|
201 static TUint8 FindNewIndex475VQ(TInt aNewGain0, TInt aOldPitch0, TInt aNewGain1, TInt aOldPitch1); |
|
202 |
|
203 static TInt FindIndex(TInt aKey, const TInt aBitPositions[], TInt aTableLength); |
|
204 |
|
205 static TBool GenerateADTSHeaderL(TBuf8<7>& aHeader, TInt aFrameLength, TAudFileProperties aProperties); |
|
206 |
|
207 static TInt GetNextAMRFrameLength(const HBufC8* aFrame, TInt aPosNow); |
|
208 |
|
209 }; |
|
210 |
|
211 |
|
212 /* |
|
213 * |
|
214 * One processing event represents a section in the output clip |
|
215 * It includes the following information: |
|
216 * - when the section starts (iPosition) |
|
217 * - is the new section a result of a new clip (iCutIn == ETrue) |
|
218 * or a result of an ending clip (iCutIn == EFalse) |
|
219 * - what clips are supposed to be mixed from this processing event (iAllIndexes) |
|
220 * - what is the clip starting or ending that is causing this processing event (iChangedIndex) |
|
221 * |
|
222 * |
|
223 */ |
|
224 |
|
225 class CProcessingEvent : public CBase |
|
226 { |
|
227 |
|
228 public: |
|
229 |
|
230 |
|
231 static CProcessingEvent* NewL(); |
|
232 ~CProcessingEvent(); |
|
233 /* |
|
234 * Insert a new clip to this processing event |
|
235 */ |
|
236 void InsertIndex(TInt aIndex); |
|
237 |
|
238 /* |
|
239 * Gets the clip index in CAudSong based on the clip index in processing event |
|
240 */ |
|
241 TInt GetIndex(TInt aProcessingEventIndex); |
|
242 |
|
243 /* |
|
244 * Gets all clip indexes in this processing event |
|
245 */ |
|
246 TBool GetAllIndexes(RArray<TInt>& aAllIndexes); |
|
247 |
|
248 /* |
|
249 * Index count |
|
250 */ |
|
251 TInt IndexCount(); |
|
252 |
|
253 /* |
|
254 * Find processing event index based on clip index |
|
255 */ |
|
256 TInt FindIndex(TInt aClipIndex); |
|
257 |
|
258 /* |
|
259 * Remove processing event |
|
260 */ |
|
261 void RemoveIndex(TInt aProcessingEventIndex); |
|
262 |
|
263 public: |
|
264 |
|
265 //global position in milliseconds |
|
266 TInt32 iPosition; |
|
267 //true = cutIn, false = cutOut |
|
268 TBool iCutIn; |
|
269 |
|
270 // there can be only one different clip in iAllIndexes in consecutive |
|
271 // processing events: |
|
272 // iChangedClipIndex is that index |
|
273 TInt iChangedClipIndex; |
|
274 |
|
275 // compare starting times (used by a common ordering function) |
|
276 static TInt Compare(const CProcessingEvent& c1, const CProcessingEvent& c2); |
|
277 |
|
278 private: |
|
279 |
|
280 void ConstructL(); |
|
281 CProcessingEvent(); |
|
282 |
|
283 // indexes of all the clips that should be mixed |
|
284 // after this processing events |
|
285 RArray<TInt> iAllIndexes; // -1 = silence |
|
286 }; |
|
287 |
|
288 |
|
289 |
|
290 class AudioEngineUtilTools |
|
291 { |
|
292 public: |
|
293 |
|
294 /** |
|
295 * Displays messages on a box |
|
296 */ |
|
297 static void AudioEngineMessageBox(const TDesC& aMessage); |
|
298 |
|
299 }; |
|
300 |
|
301 #endif |
|