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