6 PCM resampling with SoXR🔗ℹ
This module provides a small Racket wrapper around libsoxr. It is meant
for interleaved PCM buffers such as stereo L R L R ... data. It supports
sample-rate conversion and the PCM datatypes that SoXR can process directly:
's16, 's32, 'float32 and 'float64. Packed
24-bit PCM is supported by the wrapper by expanding 's24 input to
's32 before calling SoXR and packing 's32 output back to
's24 afterwards.
SoXR does not perform general channel-layout conversion in this wrapper. Use it
for unchanged channel counts, for example mono-to-mono or stereo-to-stereo.
(resampler-available?) → boolean?
|
Returns #t when libsoxr was loaded.
(resampler-version) → string?
|
Returns the version string reported by libsoxr.
| (make-resampler | | input-rate | | | | | | | | output-rate | | | | | | | | channels | | | | | | | [ | #:input-format input-format | | | | | | | | #:output-format output-format | | | | | | | | #:quality quality | | | | | | | | #:phase phase | | | | | | | | #:steep-filter? steep-filter? | | | | | | | | #:scale scale | | | | | | | | #:no-dither? no-dither? | | | | | | | | #:num-threads num-threads]) | | → | | resampler? |
|
| input-rate : exact-positive-integer? |
| output-rate : exact-positive-integer? |
| channels : exact-positive-integer? |
| input-format : symbol? = 's32 |
| output-format : symbol? = 's32 |
| quality : symbol? = 'hq |
| phase : symbol? = 'linear |
| steep-filter? : boolean? = #f |
| scale : real? = 1.0 |
| no-dither? : boolean? = #f |
| num-threads : exact-positive-integer? = 1 |
Creates a streaming resampler. The supported PCM formats are 's16,
's24, 's32, 'float32 and 'float64.
The quality value selects a SoXR resampling recipe. Useful values are
'qq, 'lq, 'mq, 'hq, 'vhq,
'16-bit, '20-bit, '24-bit, '28-bit and
'32-bit. The '24-bit quality recipe is a filter precision
setting; it is not the same thing as 24-bit PCM output. Use
#:output-format 's24 for packed 24-bit output.
(resampler-convert r buffer [size])
|
| | → | | | bytes? | | exact-nonnegative-integer? |
|
|
| r : resampler? |
| buffer : bytes? |
| size : exact-nonnegative-integer? = (bytes-length buffer) |
Feeds interleaved PCM bytes to the resampler and returns converted PCM bytes and
the number of output frames. A frame contains one sample for each channel.
| (resampler-drain r) | | → | | | bytes? | | exact-nonnegative-integer? |
|
|
| r : resampler? |
Flushes delayed output after the last input block and returns converted bytes and
frames.
(resampler-clear! r) → boolean?
|
| r : resampler? |
Clears the resampler state so the same instance can be reused for a fresh signal
with the same configuration.
(resampler-close! r) → boolean?
|
| r : resampler? |
Releases the native SoXR resampler. Calling this more than once is harmless.
| (resample-bytes | | buffer | | | | | input-rate | | | | | output-rate | | | | | channels | | | | [ | #:size size | | | | | #:input-format input-format | | | | | #:output-format output-format | | | | | #:quality quality | | | | | #:phase phase | | | | | #:steep-filter? steep-filter? | | | | | #:scale scale | | | | | #:no-dither? no-dither? | | | | | #:num-threads num-threads]) | |
|
| | → | | | bytes? | | exact-nonnegative-integer? |
|
|
| buffer : bytes? |
| input-rate : exact-positive-integer? |
| output-rate : exact-positive-integer? |
| channels : exact-positive-integer? |
| size : exact-nonnegative-integer? = (bytes-length buffer) |
| input-format : symbol? = 's32 |
| output-format : symbol? = 's32 |
| quality : symbol? = 'hq |
| phase : symbol? = 'linear |
| steep-filter? : boolean? = #f |
| scale : real? = 1.0 |
| no-dither? : boolean? = #f |
| num-threads : exact-positive-integer? = 1 |
Convenience function for one buffer. It creates a resampler, processes the
input, drains delayed samples and closes the native state.
(pcm-format? v) → boolean?
|
| v : any/c |
Returns whether v is one of the supported PCM format symbols.
(pcm-format-sample-bytes fmt) → exact-positive-integer?
|
| fmt : symbol? |
Returns the packed sample size in bytes for fmt. For 's24
this is 3, even though the wrapper internally expands to 32-bit samples
for SoXR.