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