videoeditorengine/audioeditorengine/resampler/inc/resampler_sinc_conv_one_to_two_int16.h
changeset 0 951a5db380a0
equal deleted inserted replaced
-1:000000000000 0:951a5db380a0
       
     1 #ifndef __RESAMPLER_SINC_CONV_ONE_TO_TWO_INT16_H__
       
     2 #define __RESAMPLER_SINC_CONV_ONE_TO_TWO_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   @brief Sampling rate conversion implementation for upsampling by two.
       
    29         
       
    30 */
       
    31 
       
    32 class RESAMPLER_SincConvOneToTwoInt16 : public RESAMPLER_RateConversionInputDrivenInt16, 
       
    33                                   public RESAMPLER_RateConversionOutputDrivenInt16
       
    34 {
       
    35     friend class RESAMPLER_RateConversionInputDrivenInt16;
       
    36     friend class RESAMPLER_RateConversionOutputDrivenInt16;
       
    37 
       
    38 public:
       
    39     
       
    40     /** @name Construction & Destruction */
       
    41     
       
    42     //@{
       
    43     
       
    44    /** Destructor
       
    45     */
       
    46     
       
    47     virtual ~RESAMPLER_SincConvOneToTwoInt16();
       
    48     
       
    49     //@}
       
    50     
       
    51     /** @name Query methods */
       
    52 
       
    53     //@{
       
    54 
       
    55     static bool RateSupported(float inRate, float outRate)
       
    56     { return (2*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 input driven converter
       
   129     needs to be able to handle in a single call to the processing functions.
       
   130 
       
   131     @param[in] maxInputBlockSize  Maximum input blocksize
       
   132     @return memory need in bytes
       
   133     */
       
   134     
       
   135     virtual size_t ScratchMemoryNeedInputDriven(int maxInputBlockSize) const;
       
   136 
       
   137     /** Set scratch buffer for the converter
       
   138 
       
   139     This method sets scratch buffer needed by the converter when the 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 SetScratchBufferInputDriven(char *buffer);
       
   147 
       
   148     /** Get the maximum number of input samples needed.
       
   149     
       
   150     This method returns the maximum number of input samples needed 
       
   151     for a given output sample count.
       
   152 
       
   153     @param[in] outSamples  Number of output samples
       
   154     @return Maximum number of input samples
       
   155     */
       
   156 
       
   157     virtual int MaxInputSampleCount(int outSamples) const;
       
   158     
       
   159     /** Get the amount of samples needed for input.
       
   160       
       
   161     This method returns the amount of samples needed for converter input
       
   162     given the number of output samples. This method must be called before
       
   163     each call to the processing methods. It is a serious error to have
       
   164     \a outSamples greater than the value set with ScratchMemoryNeedOutputDriven().
       
   165  
       
   166     @param[in] outSamples  Amount of samples the converter produces
       
   167     @return number of input samples needed
       
   168     */
       
   169 
       
   170     virtual int InSamplesNeeded(int outSamples);
       
   171 
       
   172     /** Run the sampling rate conversion for a block of samples
       
   173     
       
   174     This method runs the actual sampling rate conversion. The pointer arrays
       
   175     have to contain valid pointers for numChannels channel data buffers. The 
       
   176     output buffers must have space for MaxOutputSampleCount(inSamples) audio 
       
   177     samples.
       
   178       
       
   179     @param[out] outputBuffers  Pointer to output buffer array
       
   180     @param[in]  inputBuffers   Pointer to input buffer array
       
   181     @param[in]  inSamples      The number of input samples to process
       
   182     @return Number of output samples
       
   183     */
       
   184 
       
   185     virtual int ProcessFromInput(int16 *outputBuffers[], 
       
   186                                  int16 *inputBuffers[], 
       
   187                                  int inSamples);
       
   188 
       
   189     //@}
       
   190     
       
   191     /** @name Output-driven operation */
       
   192     
       
   193     //@{
       
   194     
       
   195     /** Enable one of the channels.
       
   196     
       
   197     This method is used to (re-)enable a rate conversion channel after it's
       
   198     been disabled. (All channels start in the enabled mode.) This is used to
       
   199     tell the algorithm that the channel must be properly processed, if the
       
   200     algorithm wants to take advantage of the optimization possibilities 
       
   201     provided by the DisableInputDriven() method.
       
   202 
       
   203     @note The channel index MUST be valid, i.e., it has to be smaller than
       
   204           @c numChannels given at initialization time.
       
   205 
       
   206     @param[in] channel  The index of the channel to be enabled.
       
   207     */
       
   208 
       
   209     virtual void EnableChannelOutputDriven(int channel)
       
   210     { EnableChannel(channel); }
       
   211 
       
   212     /** Disable one of the channels.
       
   213     
       
   214     This method can be used to tell the algorithm that the output from a
       
   215     specific channel will not be used in subsequent operations, and the 
       
   216     implementation may choose to optimize and leave the disabled channel
       
   217     unprocessed. However, the caller must always provide valid pointers for
       
   218     the actual processing methods for the case where it's difficult to 
       
   219     actually disable memory access for the specific channel in an 
       
   220     implementation.
       
   221 
       
   222     @note The channel index MUST be valid, i.e., it has to be smaller than
       
   223           @c numChannels given at initialization time.
       
   224 
       
   225     @param[in] channel  The index of the channel to be enabled.
       
   226     */
       
   227 
       
   228     virtual void DisableChannelOutputDriven(int channel)
       
   229     { DisableChannel(channel); }
       
   230 
       
   231     /** Query the scratch memory need of the converter.
       
   232     
       
   233     This method queries the amount of scratch memory the output driven converter
       
   234     needs to be able to handle in a single call to the processing functions.
       
   235 
       
   236     @param[in] maxOutputBlockSize  Maximum output blocksize
       
   237     @return memory need in bytes
       
   238     */
       
   239 
       
   240     virtual size_t ScratchMemoryNeedOutputDriven(int maxOutputBlockSize) const;
       
   241 
       
   242     /** Set scratch buffer for the converter
       
   243 
       
   244     This method sets scratch buffer needed by the converter when then converter is 
       
   245     used in output driven mode. The caller of this function is responsible of 
       
   246     allocating enough memory.
       
   247 
       
   248     @param[in] *buffer pointer to the allocated buffer
       
   249     */
       
   250 
       
   251     virtual void SetScratchBufferOutputDriven(char *buffer);
       
   252 
       
   253     /** Get the maximum number of output samples for a given input sample count
       
   254     
       
   255     This method returns the maximum number of output samples the converter
       
   256     can ever produce from a given number of input samples. The method assumes
       
   257     that the converter be used either input-driven or output-driven; the
       
   258     two modes should not be mixed.
       
   259       
       
   260     @param[in] inSamples  Number of input samples
       
   261     @return Maximum number of output samples
       
   262     */
       
   263 
       
   264     virtual int MaxOutputSampleCount(int inSamples) const;
       
   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_SincConvOneToTwoInt16(int channelCount);
       
   291 
       
   292     /** Disabled copy contructor 
       
   293      */
       
   294     RESAMPLER_SincConvOneToTwoInt16(const RESAMPLER_SincConvOneToTwoInt16 &);
       
   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     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     const int16  *m_filter;
       
   323     int           m_channelCount;
       
   324     int           m_blockSize;
       
   325     bool         *m_channelEnabled;
       
   326     
       
   327     int           m_state;
       
   328 };
       
   329 
       
   330 #endif  // __RESAMPLER_SINC_CONV_ONE_TO_TWO_INT16_H__