Streaming PCM time stretching and pitch shifting in pure MoonBit.
| 参数 | 范围 | 效果 |
|---|---|---|
| tempo | 0.5..2.0,默认 1 | 改变速度和时长,保持目标音高 |
| pitch_semitones | -12..12,默认 0 | 按半音移调,保持时长 |
| rate | 0.5..2.0,默认 1 | 同时改变速度和音高,类似改变唱片转速 |
moon add Ridge-Lab/moonstretch@0.1.1import {
"Ridge-Lab/moonstretch",
"moonbitlang/core/math",
}fn main {
let input = Array::makei(16000, i =>
0.3 * @math.sin(2.0 * @math.PI * 440.0 * i.to_double() / 16000.0))
let output = @moonstretch.process(
input, 16000, 1, tempo=0.75, pitch_semitones=3.0,
) catch {
error => abort((error : Error).to_string())
}
println("\{output.length()} output frames")
}git clone https://github.com/Ridge-Lab/moonstretch
cd moonstretch
moon update
moon check --target all --deny-warn
moon test --target all --deny-warn
moon run --target wasm-gc examples/basicmoon build --target js --release
node scripts/moonstretch.mjs input.wav slower.wav --tempo 0.75
node scripts/moonstretch.mjs input.wav transposed.wav --pitch 3
node scripts/moonstretch.mjs input.wav combined.wav --tempo 1.25 --pitch -2 --rate 1npm run web:build
npm run web:servemoon fmt --check
moon check --target all --deny-warn
moon test --target all --deny-warn
moon build --target all --release --deny-warn
moon info
moon build --target js --release
python scripts/audio_quality.py --output work/quality.json -- node scripts/quality_driver.mjs
node scripts/verify_wav.mjs
node scripts/benchmark.mjs work/benchmark.jsonfn Stream::new(sample_rate : Int, channels : Int, tempo? : Double, pitch_semitones? : Double, rate? : Double) -> Stream raise AudioErrorfn process(samples : Array[Double], sample_rate : Int, channels : Int, tempo? : Double, pitch_semitones? : Double, rate? : Double) -> Array[Double] raise AudioErrorInstall
Download zipStreaming PCM time stretching and pitch shifting in pure MoonBit.