Skip to content

Instantly share code, notes, and snippets.

@Sciss
Created June 17, 2019 07:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sciss/4d48fb667d77a4d9c95c1097d93de208 to your computer and use it in GitHub Desktop.
Save Sciss/4d48fb667d77a4d9c95c1097d93de208 to your computer and use it in GitHub Desktop.
val sr = "sample-rate".attr(44100.0)
//val noiseLen = "noise-dur".attr(1.0).max(0.0) * sr
val numZero = "zero-crossings".attr(6).max(1)
val f1 = "f1".attr( 500.0)
val f2 = "f2".attr(1000.0)
//val roll = "roll".attr(0.0)
val tpe = "type".attr(1).clip(0, 4)
//val noise = WhiteNoise().take(noiseLen)
val noiseLen = 1
val noise = DC(1.0).take(1)
val f1N = f1 / sr
val f2N = f2 / sr
val fltLenH = (numZero / f1N).ceil.max(1)
val fltLen = fltLenH * 2 // - 1
val convLen = noiseLen + fltLen - 1
val fftLen = convLen.nextPowerOfTwo
val noiseF = Real1FFT(noise, noiseLen, fftLen - noiseLen, mode = 1)
val flt0: GE = If (tpe sig_== 0) Then {
// all-pass
ResizeWindow(DC(1.0).take(1), 1, start = -fltLenH, stop = fltLenH - 1)
} ElseIf (tpe sig_== 1) Then {
// low-pass
GenWindow(fltLen, shape = GenWindow.Sinc, param = f1N) * f1N
} ElseIf (tpe sig_== 2) Then {
// high-pass
GenWindow(fltLen, shape = GenWindow.Sinc, param = 0.5) * 0.5 -
GenWindow(fltLen, shape = GenWindow.Sinc, param = f1N) * f1N
} ElseIf (tpe sig_== 3) Then {
// band-pass
GenWindow(fltLen, shape = GenWindow.Sinc, param = f2N) * f2N -
GenWindow(fltLen, shape = GenWindow.Sinc, param = f1N) * f1N
} Else {
// band-stop
GenWindow(fltLen, shape = GenWindow.Sinc, param = 0.5) * 0.5 -
GenWindow(fltLen, shape = GenWindow.Sinc, param = f2N) * f2N +
GenWindow(fltLen, shape = GenWindow.Sinc, param = f1N) * f1N
}
val win = GenWindow(fltLen, shape = GenWindow.Kaiser, param = 6.0)
val flt = (flt0 * win).take(fltLen)
//Plot1D(flt, fltLen)
val fltF = Real1FFT(flt, fltLen, fftLen - fltLen, mode = 1)
val convF = noiseF.complex * fltF
val conv = Real1IFFT(convF, fftLen, mode = 1)
val sig = conv.take(convLen)
AudioFileOut("out", sig, sampleRate = sr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment