AudioKit / SoundpipeAudioKit

C-based instruments and effects for AudioKit
MIT License
112 stars 41 forks source link

Can't ramp frequency in Equalizer Filter #6

Closed David4noy closed 3 years ago

David4noy commented 3 years ago

I'm trying to do an auto band filter with this code and I get an error.

If not - Should I start a new issue?

let synth = Synth() // my class
let filter = EqualizerFilter(osc)

var frequancy:Double = 500
var startFrequency: AUValue = 500
var endFrequency: AUValue = 3000
var frequancyRampDuration: Float = 3.0

filter.$centerFrequency.ramp(from: startFrequency, to: endFrequency, duration: frequancyRampDuration)
print(filter.centerFrequency)

It's not all the code and I do have engine. If I deleting this code all works good.. weird right?

This is the error :

libc++abi.dylib: terminating with uncaught exception of type NSException *** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: _engine != nil' terminating with uncaught exception of type NSException CoreSimulator 732.18.6 - Device: iPhone 11 (E5C0BBCA-35A4-4E4F-BFAC-33249EED9007) - Runtime: iOS 14.4 (18D46) - DeviceType: iPhone 11 (lldb)

aure commented 3 years ago

Well, I would need more context or, ideally, a test that shows this behavior. I mean, you're telling me you have an engine, but the error is telling me you don't. I tend to believe the computer. :) It doesn't look like EqualizerFilter has any tests, so it would be a good opportunity to make a PR to fix that as well.

David4noy commented 3 years ago

This is the "main" class for this issue:

class Synth{

    let synth:SynthType
    let fx:EffecetBuilder
    let engine = AudioEngine()
    let fader:Fader

    static let shared = Synth()

    private init() {
        synth = SynthType()
        synth.setSynth(type: .oscillator)

        fx = EffecetBuilder(synth.overtoneMix)
        fx.modulation.setModulation(.chorus)

        fader = Fader(fx.eq.dryWetMix)
        engine.output = fader

        fader.gain = 0.5

        do {
            try engine.start()
            print("engine started")
        } catch {
            print(error, "Field")
        }
    }
}

This is for the FX:

class EffecetBuilder {

    let envelope:AmplitudeEnvelope
    let autoBandFilter:AutoBandFilter
    let dist:TanhDistortion
    let modulation:Modulation
    let reverb:Reverbs
    let delay:Delays
    let eq:EQ

    var noteOnOff = false

    init(_ node:Node) {

        envelope = AmplitudeEnvelope(node, attackDuration: 0.12, decayDuration: 0.1, sustainLevel: 0.7, releaseDuration: 0.1)
        envelope.closeGate()

        dist = TanhDistortion(envelope)
        dist.bypass()

        autoBandFilter = AutoBandFilter(dist)

        modulation = Modulation(autoBandFilter.dryWetMix)
        modulation.bypass()

        reverb = Reverbs(modulation.flanger)
        reverb.bypass()

        delay = Delays(reverb.dryWetMix)
        delay.bypass()

        eq = EQ(delay.dryWetMix)
        eq.bypass()
        }

    }
David4noy commented 3 years ago

Debug area:

2021-08-01 23:25:52.852330+0300 FinaleProject5DSynth[37846:2179381] [midi] MIDI.swift:init():52:Initializing MIDI (MIDI.swift:init():52) 2021-08-01 23:25:53.466747+0300 FinaleProject5DSynth[37846:2179381] [avae] AVAEInternal.h:76 required condition is false: [AVAudioNodeImpl.h:256:AVAE_CheckNodeHasEngine: (_engine != nil)] 2021-08-01 23:25:53.524645+0300 FinaleProject5DSynth[37846:2179381] Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: _engine != nil' First throw call stack: ( 0 CoreFoundation 0x00007fff20421af6 exceptionPreprocess + 242 1 libobjc.A.dylib 0x00007fff20177e78 objc_exception_throw + 48 2 CoreFoundation 0x00007fff2042191f +[NSException raise:format:] + 0 3 AVFAudio 0x00007fff2f406821 _Z19AVAE_RaiseExceptionP8NSStringz + 156 4 AVFAudio 0x00007fff2f406a49 _ZNK15AVAudioNodeImpl23AVAE_CheckNodeHasEngineEv + 247 5 AVFAudio 0x00007fff2f4a2c75 _ZN19AVAudioNodeImplBase11CurrentTimeEv + 15 6 AVFAudio 0x00007fff2f49fd38 -[AVAudioNode lastRenderTime] + 60 7 FinaleProject5DSynth 0x00000001069d8ca7 $s8AudioKit13NodeParameterC0aB2EXE8automate6events9startTimeySaySo15AutomationEventVG_So07AVAudioI0CSgtF + 391 8 FinaleProject5DSynth 0x00000001069da092 $s8AudioKit13NodeParameterC0aB2EXE4ramp4from2to8durationySf_S2ftF + 194 9 FinaleProject5DSynth 0x000000010680b4af $s20FinaleProject5DSynth14AutoBandFilterCyAC8AudioKit4Node_pcfc + 1151 10 FinaleProject5DSynth 0x000000010680b027 $s20FinaleProject5DSynth14AutoBandFilterCyAC8AudioKit4Node_pcfC + 55 11 FinaleProject5DSynth 0x000000010681e995 $s20FinaleProject5DSynth14EffecetBuilderCyAC8AudioKit4Node_pcfc + 613 12 FinaleProject5DSynth 0x000000010681e727 $s20FinaleProject5DSynth14EffecetBuilderCyAC8AudioKit4Node_pcfC + 55 13 FinaleProject5DSynth 0x000000010682e3d6 $s20FinaleProject5DSynth5SynthCACyc33_0E85DB2A24D98DB712CF0AE5C77EAB20Llfc + 294 14 FinaleProject5DSynth 0x000000010682e231 $s20FinaleProject5DSynth5SynthCACyc33_0E85DB2A24D98DB712CF0AE5C77EAB20LlfC + 33 15 FinaleProject5DSynth 0x000000010682e1fc globalinit_33_0E85DB2A24D98DB712CF0AE5C77EAB20_func0 + 28 16 libdispatch.dylib 0x00000001073cc9c8 _dispatch_client_callout + 8 17 libdispatch.dylib 0x00000001073cdf33 _dispatch_once_callout + 66 18 libswiftCore.dylib 0x00007fff2ffa2e5a swift_once + 26 19 FinaleProject5DSynth 0x000000010682e274 $s20FinaleProject5DSynth5SynthC6sharedACvau + 52 20 FinaleProject5DSynth 0x000000010682925d $s20FinaleProject5DSynth18MainViewControllerC5coderACSgSo7NSCoderC_tcfc + 333 21 FinaleProject5DSynth 0x0000000106829523 $s20FinaleProject5DSynth18MainViewControllerC5coderACSgSo7NSCoderC_tcfcTo + 51 22 UIKitCore 0x00007fff24294d90 -[UIClassSwapper initWithCoder:] + 2308 23 UIFoundation 0x00007fff239ede71 UINibDecoderDecodeObjectForValue + 713 24 UIFoundation 0x00007fff239edb9b -[UINibDecoder decodeObjectForKey:] + 244 25 UIKitCore 0x00007fff24299184 -[UIRuntimeConnection initWithCoder:] + 125 26 UIFoundation 0x00007fff239ede71 UINibDecoderDecodeObjectForValue + 713 27 UIFoundation 0x00007fff239ee101 UINibDecoderDecodeObjectForValue + 1369 28 UIFoundation 0x00007fff239edb9b -[UINibDecoder decodeObjectForKey:] + 244 29 UIKitCore 0x00007fff24293edf -[NSCoder(UIIBDependencyInjectionInternal) _decodeObjectsWithSourceSegueTemplate:creator:sender:forKey:] + 450 30 UIKitCore 0x00007fff242969ee -[UINib instantiateWithOwner:options:] + 1122 31 UIKitCore 0x00007fff2481d512 -[UIStoryboard reallyInstantiateViewControllerWithIdentifier:creator:storyboardSegueTemplate:sender:] + 278 32 UIKitCore 0x00007fff2481d3be -[UIStoryboard _instantiateViewControllerWithIdentifier:creator:storyboardSegueTemplate:sender:] + 97 33 UIKitCore 0x00007fff2492513d -[UIWindowScene _loadWindowWithStoryboardIfNeeded:] + 95 34 UIKitCore 0x00007fff249250ae -[UIWindowScene _readySceneForConnection] + 145 35 UIKitCore 0x00007fff23aeb5e4 +[UIScene _sceneForFBSScene:create:withSession:connectionOptions:] + 1193 36 UIKitCore 0x00007fff24698602 -[UIApplication _connectUISceneFromFBSScene:transitionContext:] + 1114 37 UIKitCore 0x00007fff24698931 -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 289 38 UIKitCore 0x00007fff24183a1f -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 358 39 FrontBoardServices 0x00007fff25aa70ae -[FBSScene _callOutQueue_agent_didCreateWithTransitionContext:completion:] + 391 40 FrontBoardServices 0x00007fff25acfb41 94-[FBSWorkspaceScenesClient createWithSceneID:groupID:parameters:transitionContext:completion:]_block_invoke.176 + 102 41 FrontBoardServices 0x00007fff25ab4ad5 -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 209 42 FrontBoardServices 0x00007fff25acf80f 94-[FBSWorkspaceScenesClient createWithSceneID:groupID:parameters:transitionContext:completion:]_block_invoke + 352 43 libdispatch.dylib 0x00000001073cc9c8 _dispatch_client_callout + 8 44 libdispatch.dylib 0x00000001073cf910 _dispatch_block_invoke_direct + 295 45 FrontBoardServices 0x00007fff25af57a5 FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK + 30 46 FrontBoardServices 0x00007fff25af548b -[FBSSerialQueue _targetQueue_performNextIfPossible] + 433 47 FrontBoardServices 0x00007fff25af5950 -[FBSSerialQueue _performNextFromRunLoopSource] + 22 48 CoreFoundation 0x00007fff2039038a CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 49 CoreFoundation 0x00007fff20390282 CFRunLoopDoSource0 + 180 50 CoreFoundation 0x00007fff2038f7c6 CFRunLoopDoSources0 + 346 51 CoreFoundation 0x00007fff20389f2f __CFRunLoopRun + 878 52 CoreFoundation 0x00007fff203896d6 CFRunLoopRunSpecific + 567 53 GraphicsServices 0x00007fff2c257db3 GSEventRunModal + 139 54 UIKitCore 0x00007fff24696cf7 -[UIApplication _run] + 912 55 UIKitCore 0x00007fff2469bba8 UIApplicationMain + 101 56 libswiftUIKit.dylib 0x00007fff551885f2 $s5UIKit17UIApplicationMainys5Int32VAD_SpySpys4Int8VGGSgSSSgAJtF + 98 57 FinaleProject5DSynth 0x000000010680362a $sSo21UIApplicationDelegateP5UIKitE4mainyyFZ + 122 58 FinaleProject5DSynth 0x000000010680359e $s20FinaleProject5DSynth11AppDelegateC5$mainyyFZ + 46 59 FinaleProject5DSynth 0x0000000106803679 main + 41 60 libdyld.dylib 0x00007fff2025a3e9 start + 1 61 ??? 0x0000000000000001 0x0 + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException *** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: _engine != nil' terminating with uncaught exception of type NSException CoreSimulator 732.18.6 - Device: iPhone 11 (E5C0BBCA-35A4-4E4F-BFAC-33249EED9007) - Runtime: iOS 14.4 (18D46) - DeviceType: iPhone 11 (lldb)

David4noy commented 3 years ago

If I'm deleting all the "AutoBandFilter" class, references and so on, it works fine

David4noy commented 3 years ago

So the test shows it can ramp? do you know what I did wrong?

aure commented 3 years ago

At what line does it crash? Can you provide a smaple project that produces the error? If at all financially possible, I'd love for you to sponsor the project or me, especially if I'm debugging your code. :)

David4noy commented 3 years ago

This line:

filter.$centerFrequency.ramp(from: startFrequency, to: endFrequency, duration: frequancyRampDuration)

I'll try it in another project and send the results.

I can’t afford it now (Still student and looking for a job - this is my final project actually), but I do hope I'll in the future and I'll be glad to 🙂

David4noy commented 3 years ago

Apparently I didn't connect all the nodes to the engine..

If someone have the same problem and came to here: All the nodes must be connecting to the engine. Even if you don't want to hear them.