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