|
1 #ifndef __RESAMPLER_RATE_CONVERSION_OUTPUT_DRIVEN_INT16_H__ |
|
2 #define __RESAMPLER_RATE_CONVERSION_OUTPUT_DRIVEN_INT16_H__ |
|
3 /* |
|
4 * Copyright (c) 2010 Ixonos Plc. |
|
5 * All rights reserved. |
|
6 * This component and the accompanying materials are made available |
|
7 * under the terms of the "Eclipse Public License v1.0" |
|
8 * which accompanies this distribution, and is available |
|
9 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
10 * |
|
11 * Initial Contributors: |
|
12 * Nokia Corporation - Initial contribution |
|
13 * |
|
14 * Contributors: |
|
15 * Ixonos Plc |
|
16 * |
|
17 * Description: |
|
18 * |
|
19 */ |
|
20 |
|
21 |
|
22 /** @ingroup rate_conversion |
|
23 |
|
24 Base class for output-driven sampling rate conversion. |
|
25 |
|
26 */ |
|
27 |
|
28 #include "resampler_data_types.h" |
|
29 #include "resampler_rate_conversion_quality.h" |
|
30 |
|
31 |
|
32 class RESAMPLER_RateConversionOutputDrivenInt16 |
|
33 { |
|
34 public: |
|
35 |
|
36 /** @name Construction & Destruction */ |
|
37 |
|
38 //@{ |
|
39 |
|
40 /** This method checks if the desired conversion is available. |
|
41 |
|
42 @param[in] inRate Input sampling rate |
|
43 @param[in] outRate Output sampling rate |
|
44 @param[in] channelCount Number of audio channels |
|
45 */ |
|
46 static bool RateSupported(float inRate, |
|
47 float outRate, |
|
48 int channelCount); |
|
49 |
|
50 /** This method creates a sampling rate converter for input-driven |
|
51 operation. |
|
52 |
|
53 @param[in] inRate Input sampling rate |
|
54 @param[in] outRate Output sampling rate |
|
55 @param[in] channelCount Number of audio channels |
|
56 */ |
|
57 |
|
58 static RESAMPLER_RateConversionOutputDrivenInt16 * New(float inRate, |
|
59 float outRate, |
|
60 int channelCount); |
|
61 |
|
62 /** Constructor |
|
63 */ |
|
64 |
|
65 RESAMPLER_RateConversionOutputDrivenInt16() { ; } |
|
66 |
|
67 /** Destructor |
|
68 */ |
|
69 |
|
70 virtual ~RESAMPLER_RateConversionOutputDrivenInt16() { ; } |
|
71 |
|
72 //@} |
|
73 |
|
74 /** @name Object lifetime methods */ |
|
75 |
|
76 //@{ |
|
77 |
|
78 /** Initializes the converter. |
|
79 |
|
80 This method initializes the sampling rate converter for output-driven |
|
81 operation. Calling this method twice for the same converter instance |
|
82 is considered a programming error, and behaviour in that case is |
|
83 undefined. |
|
84 |
|
85 @return true if successful false otherwise |
|
86 */ |
|
87 |
|
88 virtual bool InitOutputDriven() = 0; |
|
89 |
|
90 //@} |
|
91 |
|
92 /** @name Operation */ |
|
93 |
|
94 //@{ |
|
95 |
|
96 /** Set the quality mode for the subsequent operations */ |
|
97 |
|
98 virtual bool SetQualityOutputDriven(int mode); |
|
99 |
|
100 /** Enable one of the channels. |
|
101 |
|
102 This method is used to (re-)enable a rate conversion channel after it's |
|
103 been disabled. (All channels start in the enabled mode.) This is used to |
|
104 tell the algorithm that the channel must be properly processed, if the |
|
105 algorithm wants to take advantage of the optimization possibilities |
|
106 provided by the DisableInputDriven() method. |
|
107 |
|
108 @note The channel index MUST be valid, i.e., it has to be smaller than |
|
109 @c numChannels given at initialization time. |
|
110 |
|
111 @param[in] channel The index of the channel to be enabled. |
|
112 */ |
|
113 |
|
114 virtual void EnableChannelOutputDriven(int channel); |
|
115 |
|
116 /** Disable one of the channels. |
|
117 |
|
118 This method can be used to tell the algorithm that the output from a |
|
119 specific channel will not be used in subsequent operations, and the |
|
120 implementation may choose to optimize and leave the disabled channel |
|
121 unprocessed. However, the caller must always provide valid pointers for |
|
122 the actual processing methods for the case where it's difficult to |
|
123 actually disable memory access for the specific channel in an |
|
124 implementation. |
|
125 |
|
126 @note The channel index MUST be valid, i.e., it has to be smaller than |
|
127 @c numChannels given at initialization time. |
|
128 |
|
129 @param[in] channel The index of the channel to be enabled. |
|
130 */ |
|
131 |
|
132 virtual void DisableChannelOutputDriven(int channel); |
|
133 |
|
134 /** Query the scratch memory need of the converter. |
|
135 |
|
136 This method queries the amount of scratch memory the converter needs to be |
|
137 able to handle in a single call to the processing functions. |
|
138 |
|
139 @param[in] maxOutputBlockSize Maximum output blocksize |
|
140 @return memory need in bytes |
|
141 */ |
|
142 |
|
143 virtual size_t ScratchMemoryNeedOutputDriven(int maxOutputBlockSize) const = 0; |
|
144 |
|
145 /** Set scratch buffer for the converter |
|
146 |
|
147 This method sets scratch buffer needed by the converter. The caller of this |
|
148 function is responsible of allocating enough memory. |
|
149 |
|
150 @param[in] *buffer pointer to the allocated buffer |
|
151 */ |
|
152 |
|
153 virtual void SetScratchBufferOutputDriven(char *buffer) = 0; |
|
154 |
|
155 |
|
156 /** Get the maximum number of input samples needed. |
|
157 |
|
158 This method returns the maximum number of input samples needed |
|
159 for a given output sample count. |
|
160 |
|
161 @param[in] outSamples Number of output samples |
|
162 @return Maximum number of input samples |
|
163 */ |
|
164 |
|
165 virtual int MaxInputSampleCount(int outSamples) const = 0; |
|
166 |
|
167 /** Get the amount of samples needed for input. |
|
168 |
|
169 This method returns the amount of samples needed for converter input |
|
170 given the number of output samples. This method must be called before |
|
171 each call to the processing methods. It is a serious error to have |
|
172 \a outSamples greater than the value set with ScratchMemoryNeedOutputDriven(). |
|
173 |
|
174 @param[in] outSamples Amount of samples the converter produces |
|
175 @return number of input samples needed |
|
176 */ |
|
177 |
|
178 virtual int InSamplesNeeded(int outSamples) = 0; |
|
179 |
|
180 /** Run the sampling rate conversion for a block of samples |
|
181 |
|
182 This method does the sampling rate conversion. The pointer arrays |
|
183 have to contain valid pointers for numChannels channel data buffers. |
|
184 The input buffers MUST contain the amount of samples returned by |
|
185 a previous call to InSamplesNeeded. Output buffers must have space |
|
186 for \a outSamples audio samples. |
|
187 |
|
188 @param[out] outputBuffers Pointer to output buffer array |
|
189 @param[in] inputBuffers Pointer to input buffer array |
|
190 @param[in] outSamples The number of samples the converter produces |
|
191 @return Number of output samples |
|
192 */ |
|
193 |
|
194 virtual int ProcessToOutput(int16 *outputBuffers[], |
|
195 int16 *inputBuffers[], |
|
196 int outSamples) = 0; |
|
197 |
|
198 //@} |
|
199 |
|
200 }; |
|
201 |
|
202 #endif // __RESAMPLER_RATE_CONVERSION_OUTPUT_DRIVEN_INT16_H__ |