AKAmplitudeEnvelope unexpected behaviour
It seems like I can't init my custom AKNode properly, I've also tried to put all the code inside viewDidLoad (and not using classes) but the behaviour is identical.
Here's my class:
class customNode:AKNode,AKToggleable
var isStarted: Bool
let sine = AKTable(.sine)
var toneGenerator: AKOscillator
var adsr: AKAmplitudeEnvelope
override init()
isStarted = false
toneGenerator = AKOscillator(waveform: sine)
toneGenerator.frequency = 440
toneGenerator.amplitude = 0.5
adsr = AKAmplitudeEnvelope(toneGenerator)
super.init(avAudioNode: adsr.outputNode)
self.setup()
func setup()
toneGenerator.detuningOffset = 0
toneGenerator.detuningMultiplier = 0
toneGenerator.rampDuration = 0
adsr.attackDuration = 0.001
adsr.decayDuration = 0.3
adsr.sustainLevel = 0
adsr.releaseDuration = 0.03
adsr.rampDuration = 0
func setF(_ val:Double)
self.toneGenerator.frequency = val
func setA(_ val:Double)
self.toneGenerator.amplitude = val
func start()
toneGenerator.start()
adsr.start()
isStarted = true
func stop()
adsr.stop()
isStarted = false
In my ViewController, I declare:
let myNode = customNode()
and add it to AudioKit output inside viewDidLoad()
AudioKit.output = myNode
My viewController conforms to AKMIDIListener protocol, so I can trigger myNode with midi keyboard inputs.
Everything works, but I have infinite sustain on notes, and I guess the other values of adsr are off as well.
If I print myNode.adsr.sustainLevel it outputs 0.0.
If I call myNode.setup()
after is has been added to AudioKit.output or AudioKit.start()
nothing changes.
So I tried to add some sliders to my view to change adsr params while playing and it suddenly worked.
@IBAction func s_change(_ sender: NSSlider)
myNode.adsr.sustainLevel = sender.doubleValue
BTW, myNode.adsr.sustainLevel still prints 0.0
The same happened for the other adsr values: if I print them the output is the value set in init()
, but the sound isn't affected by those parameters. If I change them with sliders the sound is affected but not the printed values...
So, how can I set correct adsr parameters on init()
in my customNode class?
Mac OS High Sierra
Swift 4.2
AudioKit 4.5.2 / 4.5.3 / 4.5.4 (tried all of them)
swift macos audiokit
add a comment |
It seems like I can't init my custom AKNode properly, I've also tried to put all the code inside viewDidLoad (and not using classes) but the behaviour is identical.
Here's my class:
class customNode:AKNode,AKToggleable
var isStarted: Bool
let sine = AKTable(.sine)
var toneGenerator: AKOscillator
var adsr: AKAmplitudeEnvelope
override init()
isStarted = false
toneGenerator = AKOscillator(waveform: sine)
toneGenerator.frequency = 440
toneGenerator.amplitude = 0.5
adsr = AKAmplitudeEnvelope(toneGenerator)
super.init(avAudioNode: adsr.outputNode)
self.setup()
func setup()
toneGenerator.detuningOffset = 0
toneGenerator.detuningMultiplier = 0
toneGenerator.rampDuration = 0
adsr.attackDuration = 0.001
adsr.decayDuration = 0.3
adsr.sustainLevel = 0
adsr.releaseDuration = 0.03
adsr.rampDuration = 0
func setF(_ val:Double)
self.toneGenerator.frequency = val
func setA(_ val:Double)
self.toneGenerator.amplitude = val
func start()
toneGenerator.start()
adsr.start()
isStarted = true
func stop()
adsr.stop()
isStarted = false
In my ViewController, I declare:
let myNode = customNode()
and add it to AudioKit output inside viewDidLoad()
AudioKit.output = myNode
My viewController conforms to AKMIDIListener protocol, so I can trigger myNode with midi keyboard inputs.
Everything works, but I have infinite sustain on notes, and I guess the other values of adsr are off as well.
If I print myNode.adsr.sustainLevel it outputs 0.0.
If I call myNode.setup()
after is has been added to AudioKit.output or AudioKit.start()
nothing changes.
So I tried to add some sliders to my view to change adsr params while playing and it suddenly worked.
@IBAction func s_change(_ sender: NSSlider)
myNode.adsr.sustainLevel = sender.doubleValue
BTW, myNode.adsr.sustainLevel still prints 0.0
The same happened for the other adsr values: if I print them the output is the value set in init()
, but the sound isn't affected by those parameters. If I change them with sliders the sound is affected but not the printed values...
So, how can I set correct adsr parameters on init()
in my customNode class?
Mac OS High Sierra
Swift 4.2
AudioKit 4.5.2 / 4.5.3 / 4.5.4 (tried all of them)
swift macos audiokit
add a comment |
It seems like I can't init my custom AKNode properly, I've also tried to put all the code inside viewDidLoad (and not using classes) but the behaviour is identical.
Here's my class:
class customNode:AKNode,AKToggleable
var isStarted: Bool
let sine = AKTable(.sine)
var toneGenerator: AKOscillator
var adsr: AKAmplitudeEnvelope
override init()
isStarted = false
toneGenerator = AKOscillator(waveform: sine)
toneGenerator.frequency = 440
toneGenerator.amplitude = 0.5
adsr = AKAmplitudeEnvelope(toneGenerator)
super.init(avAudioNode: adsr.outputNode)
self.setup()
func setup()
toneGenerator.detuningOffset = 0
toneGenerator.detuningMultiplier = 0
toneGenerator.rampDuration = 0
adsr.attackDuration = 0.001
adsr.decayDuration = 0.3
adsr.sustainLevel = 0
adsr.releaseDuration = 0.03
adsr.rampDuration = 0
func setF(_ val:Double)
self.toneGenerator.frequency = val
func setA(_ val:Double)
self.toneGenerator.amplitude = val
func start()
toneGenerator.start()
adsr.start()
isStarted = true
func stop()
adsr.stop()
isStarted = false
In my ViewController, I declare:
let myNode = customNode()
and add it to AudioKit output inside viewDidLoad()
AudioKit.output = myNode
My viewController conforms to AKMIDIListener protocol, so I can trigger myNode with midi keyboard inputs.
Everything works, but I have infinite sustain on notes, and I guess the other values of adsr are off as well.
If I print myNode.adsr.sustainLevel it outputs 0.0.
If I call myNode.setup()
after is has been added to AudioKit.output or AudioKit.start()
nothing changes.
So I tried to add some sliders to my view to change adsr params while playing and it suddenly worked.
@IBAction func s_change(_ sender: NSSlider)
myNode.adsr.sustainLevel = sender.doubleValue
BTW, myNode.adsr.sustainLevel still prints 0.0
The same happened for the other adsr values: if I print them the output is the value set in init()
, but the sound isn't affected by those parameters. If I change them with sliders the sound is affected but not the printed values...
So, how can I set correct adsr parameters on init()
in my customNode class?
Mac OS High Sierra
Swift 4.2
AudioKit 4.5.2 / 4.5.3 / 4.5.4 (tried all of them)
swift macos audiokit
It seems like I can't init my custom AKNode properly, I've also tried to put all the code inside viewDidLoad (and not using classes) but the behaviour is identical.
Here's my class:
class customNode:AKNode,AKToggleable
var isStarted: Bool
let sine = AKTable(.sine)
var toneGenerator: AKOscillator
var adsr: AKAmplitudeEnvelope
override init()
isStarted = false
toneGenerator = AKOscillator(waveform: sine)
toneGenerator.frequency = 440
toneGenerator.amplitude = 0.5
adsr = AKAmplitudeEnvelope(toneGenerator)
super.init(avAudioNode: adsr.outputNode)
self.setup()
func setup()
toneGenerator.detuningOffset = 0
toneGenerator.detuningMultiplier = 0
toneGenerator.rampDuration = 0
adsr.attackDuration = 0.001
adsr.decayDuration = 0.3
adsr.sustainLevel = 0
adsr.releaseDuration = 0.03
adsr.rampDuration = 0
func setF(_ val:Double)
self.toneGenerator.frequency = val
func setA(_ val:Double)
self.toneGenerator.amplitude = val
func start()
toneGenerator.start()
adsr.start()
isStarted = true
func stop()
adsr.stop()
isStarted = false
In my ViewController, I declare:
let myNode = customNode()
and add it to AudioKit output inside viewDidLoad()
AudioKit.output = myNode
My viewController conforms to AKMIDIListener protocol, so I can trigger myNode with midi keyboard inputs.
Everything works, but I have infinite sustain on notes, and I guess the other values of adsr are off as well.
If I print myNode.adsr.sustainLevel it outputs 0.0.
If I call myNode.setup()
after is has been added to AudioKit.output or AudioKit.start()
nothing changes.
So I tried to add some sliders to my view to change adsr params while playing and it suddenly worked.
@IBAction func s_change(_ sender: NSSlider)
myNode.adsr.sustainLevel = sender.doubleValue
BTW, myNode.adsr.sustainLevel still prints 0.0
The same happened for the other adsr values: if I print them the output is the value set in init()
, but the sound isn't affected by those parameters. If I change them with sliders the sound is affected but not the printed values...
So, how can I set correct adsr parameters on init()
in my customNode class?
Mac OS High Sierra
Swift 4.2
AudioKit 4.5.2 / 4.5.3 / 4.5.4 (tried all of them)
swift macos audiokit
swift macos audiokit
edited Nov 15 '18 at 15:45
RX9
6112723
6112723
asked Nov 15 '18 at 14:32
Alberto PiccoloAlberto Piccolo
83
83
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53321724%2fakamplitudeenvelope-unexpected-behaviour%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53321724%2fakamplitudeenvelope-unexpected-behaviour%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown