ios – AudioKit: Programmatically make a choice waveform for oscillator


I created an oscillator with AudioKit resp. SoundpipeAudioKit and I’d like to let the user change the waveform at runtime. I’m just showing the relevant parts:

let osc = DynamicOscillator(amplitude: 0) 
[...]
osc.setWaveform(Table(.sine))

The selected waveform comes from a GroupBox that contains several waveforms in an HStack. I bet this is not relevant, I’m just reading the selected waveform into a string, like this:

.onTapGesture {
    waveForm = waveForms[index]
}

Somehow AudioKit is using an enum for the waveforms. How to take the string value to assign as an enum?

This does not work:

osc.setWaveform(Table(waveForm))

It returns

No exact matches in call to initator

That’s the definition of “Table”:

public class Table: MutableCollection {
    [...]
}

And this are the Enums:

/// Supported default table types
public enum TableType {
    /// Standard sine waveform
    case sine
    [....]
}

Leave a Reply

Your email address will not be published. Required fields are marked *