• Stars
    star
    136
  • Rank 267,670 (Top 6 %)
  • Language
    C
  • License
    MIT License
  • Created over 6 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Simple and Efficient Audio Resampler Implementation in C

resampler

A Simple and Efficient Audio Resampler Implementation in C.

Example

uint64_t Resample_f32(const float *input, float *output, int inSampleRate, int outSampleRate, uint64_t inputSize,
                      uint32_t channels
) {
    if (input == NULL)
        return 0;
    uint64_t outputSize = (uint64_t) (inputSize * (double) outSampleRate / (double) inSampleRate);
    outputSize -= outputSize % channels;
    if (output == NULL)
        return outputSize;
    double stepDist = ((double) inSampleRate / (double) outSampleRate);
    const uint64_t fixedFraction = (1LL << 32);
    const double normFixed = (1.0 / (1LL << 32));
    uint64_t step = ((uint64_t) (stepDist * fixedFraction + 0.5));
    uint64_t curOffset = 0;
    for (uint32_t i = 0; i < outputSize; i += 1) {
        for (uint32_t c = 0; c < channels; c += 1) {
            *output++ = (float) (input[c] + (input[c + channels] - input[c]) * (
                    (double) (curOffset >> 32) + ((curOffset & (fixedFraction - 1)) * normFixed)
            )
            );
        }
        curOffset += step;
        input += (curOffset >> 32) * channels;
        curOffset &= (fixedFraction - 1);
    }
    return outputSize;
}


uint64_t Resample_s16(const int16_t *input, int16_t *output, int inSampleRate, int outSampleRate, uint64_t inputSize,
                      uint32_t channels
) {
    if (input == NULL)
        return 0;
    uint64_t outputSize = (uint64_t) (inputSize * (double) outSampleRate / (double) inSampleRate);
    outputSize -= outputSize % channels;
    if (output == NULL)
        return outputSize;
    double stepDist = ((double) inSampleRate / (double) outSampleRate);
    const uint64_t fixedFraction = (1LL << 32);
    const double normFixed = (1.0 / (1LL << 32));
    uint64_t step = ((uint64_t) (stepDist * fixedFraction + 0.5));
    uint64_t curOffset = 0;
    for (uint32_t i = 0; i < outputSize; i += 1) {
        for (uint32_t c = 0; c < channels; c += 1) {
            *output++ = (int16_t) (input[c] + (input[c + channels] - input[c]) * (
                    (double) (curOffset >> 32) + ((curOffset & (fixedFraction - 1)) * normFixed)
            )
            );
        }
        curOffset += step;
        input += (curOffset >> 32) * channels;
        curOffset &= (fixedFraction - 1);
    }
    return outputSize;
}

Donating

If you found this project useful, consider buying me a coffee

Buy Me A Coffee

More Repositories

1

WebRTC_NS

Noise Suppression Module Port From WebRTC
C
307
star
2

MTCNN

MTCNN face detection implementation base on NCNN
C
180
star
3

WebRTC_AECM

Acoustic Echo Canceller for Mobile Module Port From WebRTC
C
172
star
4

WebRTC_AGC

Automatic Gain Control Module Port From WebRTC
C
165
star
5

WebRTC_VAD

Voice Activity Detector Module Port From WebRTC
C
158
star
6

SimpleAudioDenoise

A Simple and Efficient Implementation Of Fast Fourier Transform For Audio Denoise
C
93
star
7

skin_smoothing

an efficient algorithm for skin smoothing implementation in c
C
91
star
8

CelebAHairMask-HQ

A large-scale face dataset for hair segmentation, hair recognition, and GANs for hair generation and editing.
74
star
9

pitchshift

Pitch Shifting Using The Fourier Transform Implementation In C
C
72
star
10

tinymp3

a tiny mp3 encoder && decoder example
C
61
star
11

Deblurring

Estimating an Image's Blur Kernel Using Natural Image Statistics, and Deblurring it: An Analysis of the Goldstein-Fattal Method
C
60
star
12

WebRTC_NS_CPP

Noise Suppression Module Port From WebRTC
C
60
star
13

FFmpeg_Lut3D

3D Lookup table filter Port From FFmpeg
C
53
star
14

FFTResampler

A Simple and Efficient Implementation Of Fast Fourier Transform For Audio Resampler
C
52
star
15

LocalColorCorrection

implmentation of γ€ŠLocal Color Correction using Non-Linear Masking》
C
47
star
16

shazam

a implementation of Shazam algorithm
C
46
star
17

AudioDenoise

c implementation of γ€ŠAudio Denoise by Time-Frequency Block Thresholding》
C
45
star
18

AudioFingerprinter

an efficient algorithm for acoustic fingerprinting implementation in c
C
38
star
19

ReplayGainAnalysis

ReplayGainAnalysis - analyzes input samples and give the recommended dB change
C
28
star
20

pffft

PFFFT: a pretty fast FFT with Bluestein's FFT Algorithm(Non Power of Two)
C
23
star
21

Transformer-TTS

A Tensorflow Implementation like "Neural Speech Synthesis with Transformer Network" Port From OpenSeq2Seq
Python
20
star
22

fftResample

a simple wave resampling by fft example.
C
19
star
23

OcrPreprocessing

OCR pre-processing algorithm implementation in C for remove color seal
C
17
star
24

WebRTC_CNG

Comfort Noise Generator Module Port From WebRTC
C
17
star
25

minSDTF

Stable Diffusion V1.5 Inference With PyTorch Weights And More Features Like Stable Diffusion Web UI In Keras 3.x
Python
16
star
26

mser

c implementation of Maximally Stable Extremal Regions (MSER) algorithm (modify from VLFeat)
C
15
star
27

stb_fft

stb_fft : A single-file library for computing the Fast Fourier Transform (FFT)
Objective-C
14
star
28

SINet

Unofficial Tensorflow 2 implementation of SINet: Extreme Lightweight Portrait Segmentation Networks with Spatial Squeeze Modules and Information Blocking Decoder
Python
14
star
29

cpuimagelib

An open source cpu-based image processing
C
14
star
30

EqualLoudness

Equal Loudness Filter
C
12
star
31

cpuFFT

A Simple and Efficient FFT Implementation in C
C
11
star
32

TinyText

Text Rendering Module Port From Tiny Differentiable Simulator For Win64
C
11
star
33

Tacotron-2

Tensorflow implementation of DeepMind's Tacotron-2 (without wavenet)
Python
11
star
34

FFmpeg_Loudness

Audio Loudness Normalization Filter Port From FFmpeg
C
11
star
35

DualAttentionGuidedDropout

Unofficial Tensorflow Implementation of Dual-attention Guided Dropblock Module https://arxiv.org/abs/2003.04719
Python
10
star
36

DCT_8X8

float data loss compression algorithm base DCT 8X8
C
9
star
37

deskew

Detect image skew angle and deskew image
C
9
star
38

bpm

tempo analysis (bpm detection) algorithms for dealing with beats per second detection
C
8
star
39

keras-optimizer

Collection of Optimizers for Keras and TensorFlow Keras
Python
8
star
40

minSDXLTF

Stable Diffusion XL Inference With PyTorch Weights And More Features Like Stable Diffusion Web UI In Keras 3.x
Python
7
star
41

BluesteinCrz

a simple Bluestein Chirp-Z transform implementation
C
7
star
42

AutomaticWhiteBalance

A Simple and Efficient Automatic White Balance Algorithm Implementation In C
C
7
star
43

libstft

A tiny C library for short-time Fourier transforms
C
7
star
44

BEEPS

Fast Bi-Exponential Edge-Preserving Blur Filter Implementation In C
C
7
star
45

noise_repellent

broadband noise reduction.
C
6
star
46

skin_detection

Skin Detection Algorithm Port From WebRTC
C
6
star
47

StockhamFFT

a simple Stockham FFT implementation
C
5
star
48

PhaseVocoder

A Phase Vocoder implementation in C
C
5
star
49

FreeU_TF

Unofficial Tensorflow 2 Implementation of FreeU: Free Lunch in Diffusion U-Net
Python
4
star
50

taesd-tf

Tiny AutoEncoder for Stable Diffusion in TensorFlow / Keras
Python
3
star
51

ParallelFor

a ParallelFor example
C++
3
star
52

NanoVG

NanoVG is small antialiased vector graphics rendering library for OpenGL. It has lean API modeled after HTML5 canvas API. It is aimed to be a practical and fun toolset for building scalable user interfaces and visualizations.
C
3
star
53

freetype

The FreeType Project: a free, high-quality and portable Font engine.
C
2
star
54

AngularGrad

The Unofficial Tensorflow 2 Implementations of AngularGrad Optimizers.
Python
2
star
55

cpuimage

2
star
56

World_Harvest

Fundamental Frequency Estimator Module Port From World.
C
2
star
57

SimAM

The Unofficial Tensorflow 2 Implemention Of Paper "SimAM: A Simple, Parameter-Free Attention Module for Convolutional Neural Networks".
Python
2
star
58

unisound_asr

unisound_asr δΊ‘ηŸ₯ε£° pythonη‰ˆζŽ₯口
Python
2
star
59

World_DIO

F0 Estimation Based On Distributed Inline-filter Operation Module Port From World.
C
2
star
60

GSAM

This is unofficial repository for Surrogate Gap Minimization Improves Sharpness-Aware Training in TensorFlow 2.
Python
2
star
61

EfficientFormer

Unofficial Tensorflow 2 implementation of EfficientFormer: Vision Transformers at MobileNet Speed <https://arxiv.org/abs/2206.01191>
Python
1
star
62

st_metadata_parser

a light-weight metadata parser for safetensors files
Python
1
star
63

MomentumSampler

Unofficial Tensorflow 2 implementation of Momentum Sampler. Soft Diffusion: Score Matching for General Corruptions<https://arxiv.org/abs/2209.05442>
Python
1
star
64

grid_patches

Tensorflow implementation of image grid patches transform
Python
1
star
65

PromptGenTF

A Simple and Efficient PromptGen Inference Implementation In TensorFlow 2
Python
1
star
66

MDecoderSD

MDecoder For Stable Diffusion On Super Fast Preview In TensorFlow 2
Python
1
star
67

GaussianUpsampling

The tensorflow 2 Implementations of Gaussian up-sampling
Python
1
star
68

FastBilateralFilter

A Fast Approximation of the Bilateral Filter using the Discrete Fourier Transform
C
1
star
69

HardMish

Tensorflow Implementation of Hard Mish - Memory Efficient and faster equivalent of Mish
Python
1
star