tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

resample_48khz.c (5919B)


      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 * This file contains resampling functions between 48 kHz and nb/wb.
     13 * The description header can be found in signal_processing_library.h
     14 *
     15 */
     16 
     17 #include <string.h>
     18 
     19 #include "common_audio/signal_processing/include/signal_processing_library.h"
     20 #include "common_audio/signal_processing/resample_by_2_internal.h"
     21 
     22 ////////////////////////////
     23 ///// 48 kHz -> 16 kHz /////
     24 ////////////////////////////
     25 
     26 // 48 -> 16 resampler
     27 void WebRtcSpl_Resample48khzTo16khz(const int16_t* in,
     28                                    int16_t* out,
     29                                    WebRtcSpl_State48khzTo16khz* state,
     30                                    int32_t* tmpmem) {
     31  ///// 48 --> 48(LP) /////
     32  // int16_t  in[480]
     33  // int32_t out[480]
     34  /////
     35  WebRtcSpl_LPBy2ShortToInt(in, 480, tmpmem + 16, state->S_48_48);
     36 
     37  ///// 48 --> 32 /////
     38  // int32_t  in[480]
     39  // int32_t out[320]
     40  /////
     41  // copy state to and from input array
     42  memcpy(tmpmem + 8, state->S_48_32, 8 * sizeof(int32_t));
     43  memcpy(state->S_48_32, tmpmem + 488, 8 * sizeof(int32_t));
     44  WebRtcSpl_Resample48khzTo32khz(tmpmem + 8, tmpmem, 160);
     45 
     46  ///// 32 --> 16 /////
     47  // int32_t  in[320]
     48  // int16_t out[160]
     49  /////
     50  WebRtcSpl_DownBy2IntToShort(tmpmem, 320, out, state->S_32_16);
     51 }
     52 
     53 // initialize state of 48 -> 16 resampler
     54 void WebRtcSpl_ResetResample48khzTo16khz(WebRtcSpl_State48khzTo16khz* state) {
     55  memset(state->S_48_48, 0, 16 * sizeof(int32_t));
     56  memset(state->S_48_32, 0, 8 * sizeof(int32_t));
     57  memset(state->S_32_16, 0, 8 * sizeof(int32_t));
     58 }
     59 
     60 ////////////////////////////
     61 ///// 16 kHz -> 48 kHz /////
     62 ////////////////////////////
     63 
     64 // 16 -> 48 resampler
     65 void WebRtcSpl_Resample16khzTo48khz(const int16_t* in,
     66                                    int16_t* out,
     67                                    WebRtcSpl_State16khzTo48khz* state,
     68                                    int32_t* tmpmem) {
     69  ///// 16 --> 32 /////
     70  // int16_t  in[160]
     71  // int32_t out[320]
     72  /////
     73  WebRtcSpl_UpBy2ShortToInt(in, 160, tmpmem + 16, state->S_16_32);
     74 
     75  ///// 32 --> 24 /////
     76  // int32_t  in[320]
     77  // int32_t out[240]
     78  // copy state to and from input array
     79  /////
     80  memcpy(tmpmem + 8, state->S_32_24, 8 * sizeof(int32_t));
     81  memcpy(state->S_32_24, tmpmem + 328, 8 * sizeof(int32_t));
     82  WebRtcSpl_Resample32khzTo24khz(tmpmem + 8, tmpmem, 80);
     83 
     84  ///// 24 --> 48 /////
     85  // int32_t  in[240]
     86  // int16_t out[480]
     87  /////
     88  WebRtcSpl_UpBy2IntToShort(tmpmem, 240, out, state->S_24_48);
     89 }
     90 
     91 // initialize state of 16 -> 48 resampler
     92 void WebRtcSpl_ResetResample16khzTo48khz(WebRtcSpl_State16khzTo48khz* state) {
     93  memset(state->S_16_32, 0, 8 * sizeof(int32_t));
     94  memset(state->S_32_24, 0, 8 * sizeof(int32_t));
     95  memset(state->S_24_48, 0, 8 * sizeof(int32_t));
     96 }
     97 
     98 ////////////////////////////
     99 ///// 48 kHz ->  8 kHz /////
    100 ////////////////////////////
    101 
    102 // 48 -> 8 resampler
    103 void WebRtcSpl_Resample48khzTo8khz(const int16_t* in,
    104                                   int16_t* out,
    105                                   WebRtcSpl_State48khzTo8khz* state,
    106                                   int32_t* tmpmem) {
    107  ///// 48 --> 24 /////
    108  // int16_t  in[480]
    109  // int32_t out[240]
    110  /////
    111  WebRtcSpl_DownBy2ShortToInt(in, 480, tmpmem + 256, state->S_48_24);
    112 
    113  ///// 24 --> 24(LP) /////
    114  // int32_t  in[240]
    115  // int32_t out[240]
    116  /////
    117  WebRtcSpl_LPBy2IntToInt(tmpmem + 256, 240, tmpmem + 16, state->S_24_24);
    118 
    119  ///// 24 --> 16 /////
    120  // int32_t  in[240]
    121  // int32_t out[160]
    122  /////
    123  // copy state to and from input array
    124  memcpy(tmpmem + 8, state->S_24_16, 8 * sizeof(int32_t));
    125  memcpy(state->S_24_16, tmpmem + 248, 8 * sizeof(int32_t));
    126  WebRtcSpl_Resample48khzTo32khz(tmpmem + 8, tmpmem, 80);
    127 
    128  ///// 16 --> 8 /////
    129  // int32_t  in[160]
    130  // int16_t out[80]
    131  /////
    132  WebRtcSpl_DownBy2IntToShort(tmpmem, 160, out, state->S_16_8);
    133 }
    134 
    135 // initialize state of 48 -> 8 resampler
    136 void WebRtcSpl_ResetResample48khzTo8khz(WebRtcSpl_State48khzTo8khz* state) {
    137  memset(state->S_48_24, 0, 8 * sizeof(int32_t));
    138  memset(state->S_24_24, 0, 16 * sizeof(int32_t));
    139  memset(state->S_24_16, 0, 8 * sizeof(int32_t));
    140  memset(state->S_16_8, 0, 8 * sizeof(int32_t));
    141 }
    142 
    143 ////////////////////////////
    144 /////  8 kHz -> 48 kHz /////
    145 ////////////////////////////
    146 
    147 // 8 -> 48 resampler
    148 void WebRtcSpl_Resample8khzTo48khz(const int16_t* in,
    149                                   int16_t* out,
    150                                   WebRtcSpl_State8khzTo48khz* state,
    151                                   int32_t* tmpmem) {
    152  ///// 8 --> 16 /////
    153  // int16_t  in[80]
    154  // int32_t out[160]
    155  /////
    156  WebRtcSpl_UpBy2ShortToInt(in, 80, tmpmem + 264, state->S_8_16);
    157 
    158  ///// 16 --> 12 /////
    159  // int32_t  in[160]
    160  // int32_t out[120]
    161  /////
    162  // copy state to and from input array
    163  memcpy(tmpmem + 256, state->S_16_12, 8 * sizeof(int32_t));
    164  memcpy(state->S_16_12, tmpmem + 416, 8 * sizeof(int32_t));
    165  WebRtcSpl_Resample32khzTo24khz(tmpmem + 256, tmpmem + 240, 40);
    166 
    167  ///// 12 --> 24 /////
    168  // int32_t  in[120]
    169  // int16_t out[240]
    170  /////
    171  WebRtcSpl_UpBy2IntToInt(tmpmem + 240, 120, tmpmem, state->S_12_24);
    172 
    173  ///// 24 --> 48 /////
    174  // int32_t  in[240]
    175  // int16_t out[480]
    176  /////
    177  WebRtcSpl_UpBy2IntToShort(tmpmem, 240, out, state->S_24_48);
    178 }
    179 
    180 // initialize state of 8 -> 48 resampler
    181 void WebRtcSpl_ResetResample8khzTo48khz(WebRtcSpl_State8khzTo48khz* state) {
    182  memset(state->S_8_16, 0, 8 * sizeof(int32_t));
    183  memset(state->S_16_12, 0, 8 * sizeof(int32_t));
    184  memset(state->S_12_24, 0, 8 * sizeof(int32_t));
    185  memset(state->S_24_48, 0, 8 * sizeof(int32_t));
    186 }