Home | History | Annotate | Download | only in interface
      1 /*
      2  *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
      3  *
      4  *  Use of this source code is governed by a BSD-style license
      5  *  that can be found in the LICENSE file in the root of the source
      6  *  tree. An additional intellectual property rights grant can be found
      7  *  in the file PATENTS.  All contributing project authors may
      8  *  be found in the AUTHORS file in the root of the source tree.
      9  */
     10 
     11 
     12 /*
     13  * A wrapper for resampling a numerous amount of sampling combinations.
     14  */
     15 
     16 #ifndef WEBRTC_RESAMPLER_RESAMPLER_H_
     17 #define WEBRTC_RESAMPLER_RESAMPLER_H_
     18 
     19 #include "typedefs.h"
     20 
     21 namespace webrtc
     22 {
     23 
     24 enum ResamplerType
     25 {
     26     // 4 MSB = Number of channels
     27     // 4 LSB = Synchronous or asynchronous
     28 
     29     kResamplerSynchronous = 0x10,
     30     kResamplerAsynchronous = 0x11,
     31     kResamplerSynchronousStereo = 0x20,
     32     kResamplerAsynchronousStereo = 0x21,
     33     kResamplerInvalid = 0xff
     34 };
     35 
     36 enum ResamplerMode
     37 {
     38     kResamplerMode1To1,
     39     kResamplerMode1To2,
     40     kResamplerMode1To3,
     41     kResamplerMode1To4,
     42     kResamplerMode1To6,
     43     kResamplerMode2To3,
     44     kResamplerMode2To11,
     45     kResamplerMode4To11,
     46     kResamplerMode8To11,
     47     kResamplerMode11To16,
     48     kResamplerMode11To32,
     49     kResamplerMode2To1,
     50     kResamplerMode3To1,
     51     kResamplerMode4To1,
     52     kResamplerMode6To1,
     53     kResamplerMode3To2,
     54     kResamplerMode11To2,
     55     kResamplerMode11To4,
     56     kResamplerMode11To8
     57 };
     58 
     59 class Resampler
     60 {
     61 
     62 public:
     63     Resampler();
     64     Resampler(int inFreq, int outFreq, ResamplerType type);
     65     ~Resampler();
     66 
     67     // Reset all states
     68     int Reset(int inFreq, int outFreq, ResamplerType type);
     69 
     70     // Reset all states if any parameter has changed
     71     int ResetIfNeeded(int inFreq, int outFreq, ResamplerType type);
     72 
     73     // Synchronous resampling, all output samples are written to samplesOut
     74     int Push(const WebRtc_Word16* samplesIn, int lengthIn, WebRtc_Word16* samplesOut,
     75              int maxLen, int &outLen);
     76 
     77     // Asynchronous resampling, input
     78     int Insert(WebRtc_Word16* samplesIn, int lengthIn);
     79 
     80     // Asynchronous resampling output, remaining samples are buffered
     81     int Pull(WebRtc_Word16* samplesOut, int desiredLen, int &outLen);
     82 
     83 private:
     84     // Generic pointers since we don't know what states we'll need
     85     void* state1_;
     86     void* state2_;
     87     void* state3_;
     88 
     89     // Storage if needed
     90     WebRtc_Word16* in_buffer_;
     91     WebRtc_Word16* out_buffer_;
     92     int in_buffer_size_;
     93     int out_buffer_size_;
     94     int in_buffer_size_max_;
     95     int out_buffer_size_max_;
     96 
     97     // State
     98     int my_in_frequency_khz_;
     99     int my_out_frequency_khz_;
    100     ResamplerMode my_mode_;
    101     ResamplerType my_type_;
    102 
    103     // Extra instance for stereo
    104     Resampler* slave_left_;
    105     Resampler* slave_right_;
    106 };
    107 
    108 } // namespace webrtc
    109 
    110 #endif // WEBRTC_RESAMPLER_RESAMPLER_H_
    111