Update contrib.
1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #ifndef RATECONVERTIMPL_H
17 #define RATECONVERTIMPL_H
19 #include "mmf/utils/rateconvert.h"
22 Abstract class that all specific converters derive from.
24 NONSHARABLE_CLASS( CChannelAndSampleRateConverterCommon ) : public CChannelAndSampleRateConverter
27 virtual void SetRates(TInt aSrcRate,TInt aDstRate);
29 // from CChannelAndSampleRateConverter
31 TInt MaxConvertBufferSize(TInt aSrcBufferSize, TBool aRoundUpToPower);
34 CChannelAndSampleRateConverterCommon();
36 static TInt NextPowerUp(TInt aValue);
37 inline static TInt StereoToMono(TInt aSample);
38 inline static TInt MonoToStereo(TInt aSample);
40 inline static TInt LengthBytesTo16Bit(TInt aLength);
41 inline static TInt LengthBytesTo32Bit(TInt aLength);
42 inline static TInt Length16BitToBytes(TInt aLength);
43 inline static TInt Length32BitToBytes(TInt aLength);
46 /* functions for copying from mono to stereo and from stereo to mono */
48 inline TInt CChannelAndSampleRateConverterCommon::StereoToMono(TInt aSample)
50 TInt topChannel = aSample>>16; // will naturally keep sign
51 TInt bottomChannel = TInt16(aSample&0xffff); // need to sign extend
52 TInt monoSample = (topChannel + bottomChannel)/2; // add two channels and divide
56 inline TInt CChannelAndSampleRateConverterCommon::MonoToStereo(TInt aSample)
58 TInt32 stereoSample = (aSample<<16) | (aSample&0xffff);
60 TInt monoSample = StereoToMono(stereoSample);
61 ASSERT(monoSample==aSample);
63 return TInt(stereoSample);
66 // Convert various lengths by multipling or dividing by 2 or 4
68 inline TInt CChannelAndSampleRateConverterCommon::LengthBytesTo16Bit(TInt aLength)
70 return aLength/sizeof(TInt16);
73 inline TInt CChannelAndSampleRateConverterCommon::LengthBytesTo32Bit(TInt aLength)
75 return aLength/sizeof(TInt32);
78 inline TInt CChannelAndSampleRateConverterCommon::Length16BitToBytes(TInt aLength)
80 return aLength*sizeof(TInt16);
83 inline TInt CChannelAndSampleRateConverterCommon::Length32BitToBytes(TInt aLength)
85 return aLength*sizeof(TInt32);
89 Abstract class that all specific rate converters derive from - as opposed to channel converters
91 NONSHARABLE_CLASS( CChannelAndSampleRateConvert ) : public CChannelAndSampleRateConverterCommon
95 // from CChannelAndSampleRateConverterCommon
97 TInt MaxConvertBufferSize(TInt aSrcBufferSize, TBool aRoundUpToPower);
98 void SetRates(TInt aSrcRate,TInt aDstRate);
101 CChannelAndSampleRateConvert();
103 TInt SizeOfUpsampleBuffer(TInt aBufferLength);
106 The sample rate of the data in the source buffer
110 The sample rate of the data in the destination buffer
118 NONSHARABLE_CLASS( CStereoToMonoRateConverter ) : public CChannelAndSampleRateConvert
121 CStereoToMonoRateConverter();
124 // from CChannelAndSampleRateConvert
125 TInt Convert(const TDesC8& aSrcBuffer, TDes8& aDstBuffer);
126 TInt MaxConvertBufferSize(TInt aSrcBufferSize, TBool aRoundUpToPower);
129 NONSHARABLE_CLASS( CStereoToMonoConverter ) : public CChannelAndSampleRateConverterCommon
132 CStereoToMonoConverter();
135 // from CChannelAndSampleRateConverterCommon
136 TInt Convert(const TDesC8& aSrcBuffer, TDes8& aDstBuffer);
137 TInt MaxConvertBufferSize(TInt aSrcBufferSize, TBool aRoundUpToPower);
140 NONSHARABLE_CLASS( CStereoToStereoRateConverter ) : public CChannelAndSampleRateConvert
143 CStereoToStereoRateConverter();
146 // from CChannelAndSampleRateConvert
147 TInt Convert(const TDesC8& aSrcBuffer, TDes8& aDstBuffer);
150 NONSHARABLE_CLASS( CMonoToMonoRateConverter ) : public CChannelAndSampleRateConvert
153 CMonoToMonoRateConverter();
156 // from CChannelAndSampleRateConvert
157 TInt Convert(const TDesC8& aSrcBuffer, TDes8& aDstBuffer);
160 NONSHARABLE_CLASS( CMonoToStereoConverter ) : public CChannelAndSampleRateConverterCommon
163 CMonoToStereoConverter();
166 // from CChannelAndSampleRateConverterCommon
167 TInt Convert(const TDesC8& aSrcBuffer, TDes8& aDstBuffer);
168 TInt MaxConvertBufferSize(TInt aSrcBufferSize, TBool aRoundUpToPower);
171 NONSHARABLE_CLASS( CMonoToStereoRateConverter ) : public CChannelAndSampleRateConvert
174 CMonoToStereoRateConverter();
177 // from CChannelAndSampleRateConvert
178 TInt Convert(const TDesC8& aSrcBuffer, TDes8& aDstBuffer);
179 TInt MaxConvertBufferSize(TInt aSrcBufferSize, TBool aRoundUpToPower);