Home AudioKit - AKOperationGenerator with AKParameters - CPU Issue
Reply: 0

AudioKit - AKOperationGenerator with AKParameters - CPU Issue

user9810
1#
user9810 Published in September 21, 2018, 2:47 am

I need help with sending AKParameters to the AKOperationGenerator. My current solution use a lot of CPU. Is there a better way how to do it?

Here is my example code:

import AudioKit

class SynthVoice: AKNode {
    override init() {
        let synth = AKOperationGenerator { p in
            //(1) - 30% CPU
            let osc: AKOperation = AKOperation.squareWave(frequency: p[0], amplitude: p[1], pulseWidth: p[2])

            //(2) - 9% CPU
            //let osc: AKOperation = AKOperation.squareWave(frequency: 440, amplitude: 1, pulseWidth: 0.5)
            return osc
        }
        synth.parameters[0] = 880
        synth.parameters[1] = 1
        synth.parameters[2] = 0.5

        super.init()
        self.avAudioNode = synth.avAudioNode
        synth.start()
    }
}

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        let mixer: AKMixer = AKMixer([SynthVoice(), SynthVoice(), SynthVoice(), SynthVoice(), SynthVoice(), SynthVoice()])
        AudioKit.output = mixer
        AudioKit.start()
    }
}

I need 6 voice osc bank with envelope filter for each voice. I did not find any OSC-bank with envelope filter in AudioKit, so I started to write my own via AKOperationGenerator... But the CPU is too high. (About 100% in my project - 6 AKOperationGenerator with PWM square osc and envelope filter and a lot of AKParameters that can be changed via UI)

Thanks for any response.

share|improve this question
  • Any news here? I am interested in your solution. – headkit Mar 11 at 20:13
  • 1
    Sorry, I was a little busy, so I started rewriting my implementation yesterday. As Aurelius wrote, it can be done at kernel level. At the moment I had an easy moog low pass filter in PWMOscillator. I am still working on it, but if you want, I can upload my changes somewhere (here?) after it will be finished. – Jaroslav Coufalík Mar 21 at 7:37
  • 1
    This would be great, thank you. Maybe I then could get a deeper understanding and start some low level changes by myself as I want to make oscillators syncable (resettable on trigger). – headkit Mar 21 at 9:35
  • Here is link to the changed files (it is a work version): github.com/CoufalikJaroslav/AudioKitOscWithFilter Please see: AKPWMOscillatorBankDSPKernel.hpp and "void run" method. There you can update the logic of filter. (At the moment there is a simple algorithm for testing purpose.) – Jaroslav Coufalík Mar 21 at 14:24

1 Answer 1

active oldest votes
up vote 1 down vote
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.287728 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO