Hi,
I am trying to create a few custom wavetables using AKTable and feed them to AKMorphingOscillator. My goal is to create weird tones using inharmonic partials (ie. their frequencies are not integer multiples of the fundamental frequency - 1.01, 1.05, 2.03, etc, while on the contrary, sawtooth is composed of harmonic partials - 1, 2, 3, 4, 5... etc.)
I created a function which takes a list of arbitrary partials, and returns a wavetable composed of those partials. Here is the code:
let TableSize = 4096
let TWOPI : Float = 6.28318530718
func createWavetable(partials: [Float]) -> AKTable {
var custom = AKTable(.Sine, size: TableSize)
custom.values = [Float](count: TableSize, repeatedValue: 0.0)
for harmony in partials {
let amplitude : Float = 1.0 / Float(harmony)
for j in 0..<custom.values.count {
custom.values[j] += amplitude * sin(TWOPI * Float(harmony) * (Float(j)/Float(TableSize)))
}
}
return custom
}
var tab = createWavetable([1]) // create a wavetable with only the fundamental frequency
var oscillator = AKMorphingOscillator(waveformArray:[tab])
oscillator.frequency = 440
In this above case the oscillator plays a nice sine wave of frequency 440.
-------
If the wavetable is fed with a non-integer partial:
var tab = createWavetable([1.1])
oscillator.frequency = 440
I expected to get a pure sine wave of frequency 484 Hz (the fundamental frequency 440 * 1.1), but the resulting tone sounds like 440 Hz with some high frequency overtones (or rather noise). Am I using the oscillator wrong? Or AKMorphingOscillator isn't built for this use case? Is there any other approach I should use instead? Any suggestions would be very appreciated!
Cheers, MF