synchronizer
synchronizer

Reputation: 2075

Are Continuous Frequency Changes for Synthesized Sound in Audiokit Possible?

I'm interested in developing a simple test application on ios (using Swift) in which moving the mouse cursor from left to right controls the frequency of the sound being played, according to a floating point position on a continuous grid. I'd be looking for something like this: https://www.szynalski.com/tone-generator/

I've created a basic visualization of the exponential frequency curve to help myself get started:

one octave frequency graph, darker colors represent the whole tones

The sound has to be generated at runtime and play continuously, and frequency changes should also be continuous/instantaneous (as with a pitch-bend). AudioKit seemed like a greatAPI to help me get something done quickly, but looking into it more, it looks like a lot of the well-documented convenience features apply only to pre-made audio. For example, the webpage says that the pitch-bend example is only for player sounds, not generated sound.

Looking through the tutorials, I don't see that my use case is covered -- maybe in the complex audio synth. There is also the question of how I will make frequency changes and audio be in a prioritized thread, as this is the main point of the application. I remember reading that using a UI event loop won't work.

To show that I've made an effort to find the solution, I'd like to link a few pages I've found:

This is an example of MIDI note output, but it isn't continuous: https://audiokit.io/playgrounds/Synthesis/Oscillator%20Bank/

One of the only frequency questions I've found on stackoverflow works with pitch detection with the microphone, which isn't really related: AudioKit (iOS) - Add observer for frequency / amplitude change

This talks about continuous oscillation, but doesn't describe how to change a frequency dynamically or generate a sound How to change frequency of AKMorphingOscillatorBank countinuously in Audiokit?

I think this is the closest thing I've found (generating sound, using run-time parameters to adjust the frequency): AudioKit: change sound based upon gyro data / swing phone around?

If the last page has the solution, then what do I do with AKOperationGenerator? I'd love to see a full example.

The question in short: how do I create a simple example in AudioKit (or do I need CoreAudio and AudioUnits?) in which a floating point coordinate updated continuously at runtime can be used to change the frequency of a generated sound continuously and instantaneously? How do I create such a sound (I imagine that I'd like to synthesize not only a sine wave, but also something that sounds more like a real instrument or FM synth), turn it on/off, and control it the way I need?

I'm a beginner with AudioKit, but I have the development environment all set-up. May I have a little help getting this off-the ground?

Upvotes: 2

Views: 398

Answers (2)

wall-e
wall-e

Reputation: 71

It's a slightly other usecase, but I used the ramp method to create a sliding note. Maybe you could try a function, which always ramps the frequency depending on the position of the mouse.

func playSlidingNote(freq1: Float, freq2: Float) {
        
    audioEngine.output = osc
    do {
        try audioEngine.start()
    }
    catch {
        print("could not start audioengine")
    }

    osc.setWaveform(Table(.sine))
    osc.$frequency.ramp(to: freq1, duration: 0)
    osc.amplitude = 0
    osc.start()
    // start of the tone
    osc.$amplitude.ramp(to: 1, duration: 0.01)
    osc.$frequency.ramp(to: freq2, duration: Float(noteLength))
    DispatchQueue.main.asyncAfter(deadline: .now() + noteLength) {
        // end of the tone
        osc.$amplitude.ramp(to: 0, duration: 0.01)
        DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
        osc.stop()
        }
    }
}

Upvotes: 0

sridhar_rajagopal
sridhar_rajagopal

Reputation: 180

AKOscillatorBank does have a pitchBend option, and it is continuous. I've used it myself.

In fact, the Oscillator Bank example in the Synthesis Playground has a pitch bend slider, and when you have the piano key on, you can slide it up and down for continuous pitch change.

I know this thread is a little old, but hope it helps!

Upvotes: 0

Related Questions