simple_src
A simple sample rate conversion lib for audio.
Usage
Usually use sinc Converter, it is flexible and high-quality. The linear Converter is not recommended unless performance is really important and quality is not cared.
sinc
With new method:
use ;
let samples = vec!;
let manager = new.unwrap;
let mut converter = manager.converter;
for s in converter.process
Or use builder:
use ;
let samples = vec!;
let manager = builder
.ratio
.attenuation
.quantify
.pass_width
.build
.unwrap;
let mut converter = manager.converter;
for s in converter.process
For multi-channel example see two_channels.rs.
linear
use ;
let samples = vec!;
let manager = new.unwrap;
let mut converter = manager.converter;
for s in converter.process
Sinc parameters
Recommended initialization parameters for sinc converter:
attenuation | quantify | |
---|---|---|
8bit fast | 48 | 8 |
8bit medium | 60 | 16 |
8bit better | 72 | 32 |
16bit lower | 84 | 64 |
16bit fast | 96 | 128 |
16bit medium | 108 | 256 |
16bit better | 120 | 512 |
24bit lower | 132 | 1024 |
24bit fast | 144 | 2048 |
24bit medium | 156 | 4096 |
24bit better | 168 | 8192 |
The relationship between attenuation and quantify is about Q = 2 ^ (A / 12 - 1), A = 12 + 12 * log2(Q).
Due to the amount of calculation and the size of LUT, A = 144 or 156 for 24bit audio is usually fine, and for 16bit, A = 120 is enough.
Plots
Use plots.py to show the results of conversion. It needs numpy, scipy and matplotlib.
Here is an example showing the results of a downsampling 96kHz:
$ cargo test -r --test testwav -- --ignored --exact --show-output generate
$ cargo test -r --test sinc -- --ignored --exact --show-output ta120_2_96k_down
$ python
>>> import plots
>>> import os
>>> os.chdir('output')
>>> plots.spectrum('beep_96k_44k_s_a120_2.wav')
>>> plots.spectrogram('sweep_96k_44k_s_a120_2.wav')
>>> plots.impulse('impulse_96k_44k_s_a120_2.wav')
>>> plots.impulse('impulse_96k_44k_s_a120_2.wav', True)
See code in tests for more details.
References
- Smith, J.O. Digital Audio Resampling Home Page https://ccrma.stanford.edu/~jos/resample/.
- Alan V. Oppenheim, Ronald W. Schafer. Discrete-Time Signal Processing, Third Edition.