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