WaveBeans / wavebeans

Audio Processing. On scale.
https://wavebeans.io
Apache License 2.0
24 stars 0 forks source link

Window functions support. #7

Closed asubb closed 4 years ago

asubb commented 4 years ago

Support of different window functions for WaveBeans.

Suggested API

// fixed window to FFT
stream.window(401)
      .hamming()
      .fft(512)

// sliding window to FFT
stream.window(401)
      .sliding(101)
      .hamming()
      .fft(512)

Technically that means multiplying two different windowed streams, however second window stream should be generated based on the window size.


// function implementation here based on current value `i` 
// out of overall values `n`
fun windowImpl(i: Int, n: Int): Sample { /* ... */ }

val window = stream.window(401)
val windowFn = FunctionSampleStream(fn = { i - > windowImpl(i, 401)} ).window(401)
val windowedStream = window * windowFn
val fft = windowedStream.fft(512)

// add new stream to be able to generate stream out of functions.
class FunctionSampleStream(
  fn: (Int) -> Sample
) : BeanStream<Sample, FunctionSampleStream> {
  /* ... */
}

Need to come up with some nice short API.

So objectives of this issue:

  1. Introduce new type of stream that is generated based on function value
  2. sine() and sineSweep() functions possible can be migrated on this new approach.
  3. Using that new approach introduce window functions: