sl@0
|
1 |
// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#ifndef RATECONVERTIMPL_H
|
sl@0
|
17 |
#define RATECONVERTIMPL_H
|
sl@0
|
18 |
|
sl@0
|
19 |
#include "mmf/utils/rateconvert.h"
|
sl@0
|
20 |
|
sl@0
|
21 |
/**
|
sl@0
|
22 |
Abstract class that all specific converters derive from.
|
sl@0
|
23 |
*/
|
sl@0
|
24 |
NONSHARABLE_CLASS( CChannelAndSampleRateConverterCommon ) : public CChannelAndSampleRateConverter
|
sl@0
|
25 |
{
|
sl@0
|
26 |
public:
|
sl@0
|
27 |
virtual void SetRates(TInt aSrcRate,TInt aDstRate);
|
sl@0
|
28 |
|
sl@0
|
29 |
// from CChannelAndSampleRateConverter
|
sl@0
|
30 |
void Reset();
|
sl@0
|
31 |
TInt MaxConvertBufferSize(TInt aSrcBufferSize, TBool aRoundUpToPower);
|
sl@0
|
32 |
|
sl@0
|
33 |
protected:
|
sl@0
|
34 |
CChannelAndSampleRateConverterCommon();
|
sl@0
|
35 |
|
sl@0
|
36 |
static TInt NextPowerUp(TInt aValue);
|
sl@0
|
37 |
inline static TInt StereoToMono(TInt aSample);
|
sl@0
|
38 |
inline static TInt MonoToStereo(TInt aSample);
|
sl@0
|
39 |
|
sl@0
|
40 |
inline static TInt LengthBytesTo16Bit(TInt aLength);
|
sl@0
|
41 |
inline static TInt LengthBytesTo32Bit(TInt aLength);
|
sl@0
|
42 |
inline static TInt Length16BitToBytes(TInt aLength);
|
sl@0
|
43 |
inline static TInt Length32BitToBytes(TInt aLength);
|
sl@0
|
44 |
};
|
sl@0
|
45 |
|
sl@0
|
46 |
/* functions for copying from mono to stereo and from stereo to mono */
|
sl@0
|
47 |
|
sl@0
|
48 |
inline TInt CChannelAndSampleRateConverterCommon::StereoToMono(TInt aSample)
|
sl@0
|
49 |
{
|
sl@0
|
50 |
TInt topChannel = aSample>>16; // will naturally keep sign
|
sl@0
|
51 |
TInt bottomChannel = TInt16(aSample&0xffff); // need to sign extend
|
sl@0
|
52 |
TInt monoSample = (topChannel + bottomChannel)/2; // add two channels and divide
|
sl@0
|
53 |
return monoSample;
|
sl@0
|
54 |
}
|
sl@0
|
55 |
|
sl@0
|
56 |
inline TInt CChannelAndSampleRateConverterCommon::MonoToStereo(TInt aSample)
|
sl@0
|
57 |
{
|
sl@0
|
58 |
TInt32 stereoSample = (aSample<<16) | (aSample&0xffff);
|
sl@0
|
59 |
#ifdef _DEBUG
|
sl@0
|
60 |
TInt monoSample = StereoToMono(stereoSample);
|
sl@0
|
61 |
ASSERT(monoSample==aSample);
|
sl@0
|
62 |
#endif
|
sl@0
|
63 |
return TInt(stereoSample);
|
sl@0
|
64 |
}
|
sl@0
|
65 |
|
sl@0
|
66 |
// Convert various lengths by multipling or dividing by 2 or 4
|
sl@0
|
67 |
|
sl@0
|
68 |
inline TInt CChannelAndSampleRateConverterCommon::LengthBytesTo16Bit(TInt aLength)
|
sl@0
|
69 |
{
|
sl@0
|
70 |
return aLength/sizeof(TInt16);
|
sl@0
|
71 |
}
|
sl@0
|
72 |
|
sl@0
|
73 |
inline TInt CChannelAndSampleRateConverterCommon::LengthBytesTo32Bit(TInt aLength)
|
sl@0
|
74 |
{
|
sl@0
|
75 |
return aLength/sizeof(TInt32);
|
sl@0
|
76 |
}
|
sl@0
|
77 |
|
sl@0
|
78 |
inline TInt CChannelAndSampleRateConverterCommon::Length16BitToBytes(TInt aLength)
|
sl@0
|
79 |
{
|
sl@0
|
80 |
return aLength*sizeof(TInt16);
|
sl@0
|
81 |
}
|
sl@0
|
82 |
|
sl@0
|
83 |
inline TInt CChannelAndSampleRateConverterCommon::Length32BitToBytes(TInt aLength)
|
sl@0
|
84 |
{
|
sl@0
|
85 |
return aLength*sizeof(TInt32);
|
sl@0
|
86 |
}
|
sl@0
|
87 |
|
sl@0
|
88 |
/**
|
sl@0
|
89 |
Abstract class that all specific rate converters derive from - as opposed to channel converters
|
sl@0
|
90 |
*/
|
sl@0
|
91 |
NONSHARABLE_CLASS( CChannelAndSampleRateConvert ) : public CChannelAndSampleRateConverterCommon
|
sl@0
|
92 |
{
|
sl@0
|
93 |
public:
|
sl@0
|
94 |
|
sl@0
|
95 |
// from CChannelAndSampleRateConverterCommon
|
sl@0
|
96 |
void Reset();
|
sl@0
|
97 |
TInt MaxConvertBufferSize(TInt aSrcBufferSize, TBool aRoundUpToPower);
|
sl@0
|
98 |
void SetRates(TInt aSrcRate,TInt aDstRate);
|
sl@0
|
99 |
|
sl@0
|
100 |
protected:
|
sl@0
|
101 |
CChannelAndSampleRateConvert();
|
sl@0
|
102 |
|
sl@0
|
103 |
TInt SizeOfUpsampleBuffer(TInt aBufferLength);
|
sl@0
|
104 |
protected:
|
sl@0
|
105 |
/*
|
sl@0
|
106 |
The sample rate of the data in the source buffer
|
sl@0
|
107 |
*/
|
sl@0
|
108 |
TInt iFromRate;
|
sl@0
|
109 |
/*
|
sl@0
|
110 |
The sample rate of the data in the destination buffer
|
sl@0
|
111 |
*/
|
sl@0
|
112 |
TInt iToRate;
|
sl@0
|
113 |
|
sl@0
|
114 |
TInt iFraction;
|
sl@0
|
115 |
TInt iIndex;
|
sl@0
|
116 |
};
|
sl@0
|
117 |
|
sl@0
|
118 |
NONSHARABLE_CLASS( CStereoToMonoRateConverter ) : public CChannelAndSampleRateConvert
|
sl@0
|
119 |
{
|
sl@0
|
120 |
public:
|
sl@0
|
121 |
CStereoToMonoRateConverter();
|
sl@0
|
122 |
|
sl@0
|
123 |
protected:
|
sl@0
|
124 |
// from CChannelAndSampleRateConvert
|
sl@0
|
125 |
TInt Convert(const TDesC8& aSrcBuffer, TDes8& aDstBuffer);
|
sl@0
|
126 |
TInt MaxConvertBufferSize(TInt aSrcBufferSize, TBool aRoundUpToPower);
|
sl@0
|
127 |
};
|
sl@0
|
128 |
|
sl@0
|
129 |
NONSHARABLE_CLASS( CStereoToMonoConverter ) : public CChannelAndSampleRateConverterCommon
|
sl@0
|
130 |
{
|
sl@0
|
131 |
public:
|
sl@0
|
132 |
CStereoToMonoConverter();
|
sl@0
|
133 |
|
sl@0
|
134 |
protected:
|
sl@0
|
135 |
// from CChannelAndSampleRateConverterCommon
|
sl@0
|
136 |
TInt Convert(const TDesC8& aSrcBuffer, TDes8& aDstBuffer);
|
sl@0
|
137 |
TInt MaxConvertBufferSize(TInt aSrcBufferSize, TBool aRoundUpToPower);
|
sl@0
|
138 |
};
|
sl@0
|
139 |
|
sl@0
|
140 |
NONSHARABLE_CLASS( CStereoToStereoRateConverter ) : public CChannelAndSampleRateConvert
|
sl@0
|
141 |
{
|
sl@0
|
142 |
public:
|
sl@0
|
143 |
CStereoToStereoRateConverter();
|
sl@0
|
144 |
|
sl@0
|
145 |
protected:
|
sl@0
|
146 |
// from CChannelAndSampleRateConvert
|
sl@0
|
147 |
TInt Convert(const TDesC8& aSrcBuffer, TDes8& aDstBuffer);
|
sl@0
|
148 |
};
|
sl@0
|
149 |
|
sl@0
|
150 |
NONSHARABLE_CLASS( CMonoToMonoRateConverter ) : public CChannelAndSampleRateConvert
|
sl@0
|
151 |
{
|
sl@0
|
152 |
public:
|
sl@0
|
153 |
CMonoToMonoRateConverter();
|
sl@0
|
154 |
|
sl@0
|
155 |
protected:
|
sl@0
|
156 |
// from CChannelAndSampleRateConvert
|
sl@0
|
157 |
TInt Convert(const TDesC8& aSrcBuffer, TDes8& aDstBuffer);
|
sl@0
|
158 |
};
|
sl@0
|
159 |
|
sl@0
|
160 |
NONSHARABLE_CLASS( CMonoToStereoConverter ) : public CChannelAndSampleRateConverterCommon
|
sl@0
|
161 |
{
|
sl@0
|
162 |
public:
|
sl@0
|
163 |
CMonoToStereoConverter();
|
sl@0
|
164 |
|
sl@0
|
165 |
protected:
|
sl@0
|
166 |
// from CChannelAndSampleRateConverterCommon
|
sl@0
|
167 |
TInt Convert(const TDesC8& aSrcBuffer, TDes8& aDstBuffer);
|
sl@0
|
168 |
TInt MaxConvertBufferSize(TInt aSrcBufferSize, TBool aRoundUpToPower);
|
sl@0
|
169 |
};
|
sl@0
|
170 |
|
sl@0
|
171 |
NONSHARABLE_CLASS( CMonoToStereoRateConverter ) : public CChannelAndSampleRateConvert
|
sl@0
|
172 |
{
|
sl@0
|
173 |
public:
|
sl@0
|
174 |
CMonoToStereoRateConverter();
|
sl@0
|
175 |
|
sl@0
|
176 |
protected:
|
sl@0
|
177 |
// from CChannelAndSampleRateConvert
|
sl@0
|
178 |
TInt Convert(const TDesC8& aSrcBuffer, TDes8& aDstBuffer);
|
sl@0
|
179 |
TInt MaxConvertBufferSize(TInt aSrcBufferSize, TBool aRoundUpToPower);
|
sl@0
|
180 |
};
|
sl@0
|
181 |
|
sl@0
|
182 |
#endif
|
sl@0
|
183 |
|