Creating custom waveform using AKTable

340 views
Skip to first unread message

MF

unread,
Jul 1, 2016, 12:15:55 PM7/1/16
to AudioKit Users Group

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

oscillator.play()


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

oscillator.play()


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



Aurelius Prochazka Ph.D.

unread,
Jul 1, 2016, 12:24:27 PM7/1/16
to AudioKit Users Group
AudioKit is getting this one right I believe.  You're learning about how interesting it is the way we hear frequencies.  Even though you're creating small bits of a higher frequency wave, you're still oscillating those at 440Hz.  If you know about Fourier series, think about how you would make your curve using them and you'll get an insight to what your ear will "hear".  You can get frequency overtones and frequency doubling easy enough, but not a pure 1.1 multiplication of a pure sound.  

By the, way two pi = tau!  We just passed tau day on 6/28. 


Aure

meifan...@googlemail.com

unread,
Jul 1, 2016, 1:33:08 PM7/1/16
to AudioKit Users Group
Thanks for the prompt reply! Aure :)

I see. I am actually trying to achieve additive (ish) synthesis using a wavetable. With the wavetable from Max/MSP for example, I need to feed the actual frequencies into the wavetable, ex. [440, 484] (See the screenshot)


And here is the drony sound that's generated from the wavetable:

Is there a way to achieve the same sound with AudioKit? The worst case I guess I'll need to use a few sine waves to do additive synthesis for real (I'll need about 15 partials for each voice, need to see if that's too heavy to run on a mobile device...)

Thanks!

Paul Batchelor

unread,
Jul 18, 2016, 7:23:18 PM7/18/16
to AudioKit Users Group
You'd have to do additive synthesis the "correct" way using a sine wave oscillator bank (multiple sine wave oscillators) since your wavetable you are trying to generate uses non-integer multiples of the fundamental.
Reply all
Reply to author
Forward
0 new messages