videoeditorengine/audioeditorengine/resampler/inc/resampler_sinc_conv_three_to_one_int16.h
branchRCL_3
changeset 3 e0b5df5c0969
parent 0 951a5db380a0
child 5 4c409de21d23
equal deleted inserted replaced
0:951a5db380a0 3:e0b5df5c0969
     1 #ifndef __RESAMPLER_SINC_CONV_THREE_TO_ONE_INT16_H__
       
     2 #define __RESAMPLER_SINC_CONV_THREE_TO_ONE_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 #include "resampler_rate_conversion_input_driven_int16.h"
       
    23 #include "resampler_rate_conversion_output_driven_int16.h"
       
    24 
       
    25 /** @ingroup rate_conversion
       
    26 
       
    27  Class for downsampling 16-bit audio in 3 to 1 ratio
       
    28 */
       
    29 
       
    30 class RESAMPLER_SincConvThreeToOneInt16 : public RESAMPLER_RateConversionInputDrivenInt16,
       
    31 								    public RESAMPLER_RateConversionOutputDrivenInt16
       
    32 {
       
    33     friend class RESAMPLER_RateConversionOutputDrivenInt16;
       
    34 	friend class RESAMPLER_RateConversionInputDrivenInt16;
       
    35 
       
    36 public:
       
    37     
       
    38     /** @name Destruction */
       
    39 
       
    40      //@{
       
    41 
       
    42     /** Destructor
       
    43       */
       
    44 
       
    45     virtual ~RESAMPLER_SincConvThreeToOneInt16();
       
    46 
       
    47     //@}
       
    48 
       
    49     /** @name Query methods */
       
    50 
       
    51     //@{
       
    52 
       
    53     static bool RateSupported(float inRate, float outRate)
       
    54     { return (inRate == 3*outRate ); }
       
    55 
       
    56     //@}
       
    57 
       
    58     /** @name Object lifetime methods */
       
    59 
       
    60     //@{
       
    61 
       
    62     /** Initializes the converter.
       
    63     
       
    64 	  This method initializes the sampling rate converter for output-driven
       
    65       operation. The initialization will be successful only if 
       
    66 	  inRate == 2*outRate.
       
    67       
       
    68       @return true if successful false otherwise
       
    69     */
       
    70 
       
    71     virtual bool InitOutputDriven();
       
    72 
       
    73     /** Initializes the converter.
       
    74     
       
    75     This method initializes the sampling rate converter for input-driven
       
    76     operation.
       
    77       
       
    78     @return true if successful false otherwise
       
    79     */
       
    80     
       
    81     virtual bool InitInputDriven();
       
    82 
       
    83     //@}
       
    84 
       
    85     /** @name Input-driven operation */
       
    86 
       
    87     //@{
       
    88 
       
    89 	/** Disable one of the channels.
       
    90     
       
    91     This method can be used to tell the algorithm that the output from a
       
    92     specific channel will not be used in subsequent operations, and the 
       
    93     implementation may choose to optimize and leave the disabled channel
       
    94     unprocessed. However, the caller must always provide valid pointers for
       
    95     the actual processing methods for the case where it's difficult to 
       
    96     actually disable memory access for the specific channel in an 
       
    97     implementation.
       
    98 
       
    99     @note The channel index MUST be valid, i.e., it has to be smaller than
       
   100           @c numChannels given at initialization time.
       
   101 
       
   102     @param[in] channel  The index of the channel to be enabled.
       
   103     */
       
   104 
       
   105     virtual void DisableChannelInputDriven(int channel)
       
   106     { DisableChannel(channel); }
       
   107 
       
   108     /** Enable one of the channels.
       
   109     
       
   110     This method is used to (re-)enable a rate conversion channel after it's
       
   111     been disabled. (All channels start in the enabled mode.) This is used to
       
   112     tell the algorithm that the channel must be properly processed, if the
       
   113     algorithm wants to take advantage of the optimization possibilities 
       
   114     provided by the DisableInputDriven() method.
       
   115 
       
   116     @note The channel index MUST be valid, i.e., it has to be smaller than
       
   117           @c numChannels given at initialization time.
       
   118 
       
   119     @param[in] channel  The index of the channel to be enabled.
       
   120     */
       
   121 
       
   122 	virtual void EnableChannelInputDriven(int channel)
       
   123     { EnableChannel(channel); }
       
   124 
       
   125     /** Query the scratch memory need of the converter.
       
   126     
       
   127     This method queries the amount of scratch memory the input driven converter
       
   128     needs to be able to handle in a single call to the processing functions.
       
   129 
       
   130     @param[in] maxInputBlockSize  Maximum input blocksize
       
   131     @return memory need in bytes
       
   132     */
       
   133 
       
   134     virtual size_t ScratchMemoryNeedInputDriven(int maxInputBlockSize) const;
       
   135 
       
   136     /** Set scratch buffer for the converter
       
   137 
       
   138     This method sets scratch buffer needed by the converter when then converter is 
       
   139     used in input driven mode. The caller of this function is responsible of 
       
   140     allocating enough memory.
       
   141 
       
   142     @param[in] *buffer pointer to the allocated buffer
       
   143     */
       
   144 
       
   145     virtual void SetScratchBufferInputDriven(char *buffer);
       
   146 
       
   147     /** Get the maximum number of input samples needed.
       
   148     
       
   149     This method returns the maximum number of input samples needed 
       
   150     for a given output sample count.
       
   151 
       
   152     @param[in] outSamples  Number of output samples
       
   153     @return Maximum number of input samples
       
   154     */
       
   155 
       
   156     virtual int MaxInputSampleCount(int outSamples) const;
       
   157     
       
   158     /** Get the amount of samples needed for input.
       
   159       
       
   160     This method returns the amount of samples needed for converter input
       
   161     given the number of output samples. This method must be called before
       
   162     each call to the processing methods. It is a serious error to have
       
   163     \a outSamples greater than the value set with ScratchMemoryNeedOutputDriven().
       
   164  
       
   165     @param[in] outSamples  Amount of samples the converter produces
       
   166     @return number of input samples needed
       
   167     */
       
   168 
       
   169     virtual int InSamplesNeeded(int outSamples);
       
   170 
       
   171     /** Run the sampling rate conversion for a block of samples
       
   172     
       
   173     This method runs the actual sampling rate conversion. The pointer arrays
       
   174     have to contain valid pointers for numChannels channel data buffers. The 
       
   175     output buffers must have space for MaxOutputSampleCount(inSamples) audio 
       
   176     samples.
       
   177       
       
   178     @param[out] outputBuffers  Pointer to output buffer array
       
   179     @param[in]  inputBuffers   Pointer to input buffer array
       
   180     @param[in]  inSamples      The number of input samples to process
       
   181     @return Number of output samples
       
   182     */
       
   183 
       
   184     virtual int ProcessFromInput(int16 *outputBuffers[], 
       
   185                                  int16 *inputBuffers[], 
       
   186                                  int inSamples);
       
   187 
       
   188     //@}
       
   189     
       
   190     /** @name Output-driven operation */
       
   191     
       
   192     //@{
       
   193 
       
   194     /** Enable one of the channels.
       
   195     
       
   196     This method is used to (re-)enable a rate conversion channel after it's
       
   197     been disabled. (All channels start in the enabled mode.) This is used to
       
   198     tell the algorithm that the channel must be properly processed, if the
       
   199     algorithm wants to take advantage of the optimization possibilities 
       
   200     provided by the DisableInputDriven() method.
       
   201 
       
   202     @note The channel index MUST be valid, i.e., it has to be smaller than
       
   203           @c numChannels given at initialization time.
       
   204 
       
   205     @param[in] channel  The index of the channel to be enabled.
       
   206     */
       
   207 
       
   208 	virtual void EnableChannelOutputDriven(int channel)
       
   209     { EnableChannel(channel); }
       
   210 
       
   211     /** Disable one of the channels.
       
   212     
       
   213     This method can be used to tell the algorithm that the output from a
       
   214     specific channel will not be used in subsequent operations, and the 
       
   215     implementation may choose to optimize and leave the disabled channel
       
   216     unprocessed. However, the caller must always provide valid pointers for
       
   217     the actual processing methods for the case where it's difficult to 
       
   218     actually disable memory access for the specific channel in an 
       
   219     implementation.
       
   220 
       
   221     @note The channel index MUST be valid, i.e., it has to be smaller than
       
   222           @c numChannels given at initialization time.
       
   223 
       
   224     @param[in] channel  The index of the channel to be enabled.
       
   225     */
       
   226 
       
   227     virtual void DisableChannelOutputDriven(int channel)
       
   228     { DisableChannel(channel); }	
       
   229 
       
   230 	/** Query the scratch memory need of the converter.
       
   231     
       
   232     This method queries the amount of scratch memory the output driven converter
       
   233     needs to be able to handle in a single call to the processing functions.
       
   234 
       
   235     @param[in] maxOutputBlockSize  Maximum output blocksize
       
   236     @return memory need in bytes
       
   237     */
       
   238 
       
   239     virtual size_t ScratchMemoryNeedOutputDriven(int maxOutputBlockSize) const;
       
   240 
       
   241     /** Set scratch buffer for the converter
       
   242 
       
   243     This method sets scratch buffer needed by the converter when then converter is 
       
   244     used in output driven mode. The caller of this function is responsible of 
       
   245     allocating enough memory.
       
   246 
       
   247     @param[in] *buffer pointer to the allocated buffer
       
   248     */
       
   249 
       
   250     virtual void SetScratchBufferOutputDriven(char *buffer);
       
   251 
       
   252     /** Get the maximum number of output samples for a given input sample count
       
   253     
       
   254     This method returns the maximum number of output samples the converter
       
   255     can ever produce from a given number of input samples. The method assumes
       
   256     that the converter be used either input-driven or output-driven; the
       
   257     two modes should not be mixed.
       
   258       
       
   259     @param[in] inSamples  Number of input samples
       
   260     @return Maximum number of output samples
       
   261     */
       
   262 
       
   263     virtual int MaxOutputSampleCount(int inSamples) const;
       
   264 
       
   265     /** Run the sampling rate conversion for a block of samples
       
   266 
       
   267     This method does the sampling rate conversion. The pointer arrays
       
   268     have to contain valid pointers for numChannels channel data buffers.
       
   269     The input buffers MUST contain the amount of samples returned by
       
   270     a previous call to InSamplesNeeded. Output buffers must have space
       
   271     for \a outSamples audio samples.
       
   272  
       
   273     @param[out] outputBuffers  Pointer to output buffer array
       
   274     @param[in]  inputBuffers   Pointer to input buffer array
       
   275     @param[in]  outSamples     The number of samples the converter produces
       
   276     @return Number of output samples
       
   277     */
       
   278 
       
   279     virtual int ProcessToOutput(int16 *outputBuffers[], 
       
   280                                 int16 *inputBuffers[], 
       
   281                                 int outSamples);
       
   282 
       
   283     //@}
       
   284 
       
   285 private:
       
   286 
       
   287      /** Constructor
       
   288       */
       
   289 
       
   290     RESAMPLER_SincConvThreeToOneInt16(int channelCount);
       
   291 
       
   292     /** Disabled copy contructor 
       
   293     */
       
   294 	RESAMPLER_SincConvThreeToOneInt16(const RESAMPLER_SincConvThreeToOneInt16 &);
       
   295 
       
   296     /** Initializes the converter.
       
   297     
       
   298       This method initializes the sampling rate converter. The 
       
   299       initialization will be successful only if 2*inRate == outRate.
       
   300       
       
   301       @return true if successful false otherwise
       
   302     */
       
   303     
       
   304     bool Init();
       
   305 
       
   306 	/** Deallocate all the allocated memory 
       
   307 
       
   308     This methods deallocates all memory previously allocated by 
       
   309     InitOutputDriven(). Can be used both for recovering from a memory 
       
   310     allocation error and in destructor.
       
   311     */
       
   312     void DeInit();
       
   313 
       
   314     /** Enable one of the channels */
       
   315     void EnableChannel(int channel);
       
   316 
       
   317     /** Disable one of the channels */
       
   318     void DisableChannel(int channel);
       
   319 
       
   320     int16       **m_memBuffers;
       
   321     int16        *m_scratchBuffer;
       
   322     int           m_channelCount;
       
   323 	int           m_blockSize;
       
   324     bool         *m_channelEnabled;
       
   325 
       
   326     int           m_state;
       
   327 
       
   328     int           m_coeffCount;
       
   329     const int16  *m_filterMatrix;
       
   330 };
       
   331 
       
   332 #endif  // __RESAMPLER_SINC_CONV_THREE_TO_ONE_INT16_H__