-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Loudness related thing support #60
Conversation
I see you've updated this so it can be merged! I'm excited to take a close look at this PR soon. :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a few questions about the implementation, particularly the way that "greater than" triggers are implemented.
rms = Math.max(rms, this._lastValue * 0.6); | ||
} | ||
this._lastValue = rms; | ||
rms *= 1.63; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be missing a lot of explanatory comments from Scratch's implementation.
this.fireGreatherThanTrigger(Trigger.LOUDNESS_GREATER_THAN); | ||
} | ||
this._prevLoudness = this.loudnessHandler.loudness; | ||
this.fireGreatherThanTrigger(Trigger.TIMER_GREATER_THAN); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scratch seems to implement "edge-activated hats" (what we call "greater-than triggers" here) a bit differently--every step, it evaluates the predicate of the hat (e.g. "is loudness greater than N? is timer greater than N?") which returns either a true or false value. It fires those hat blocks if the predicate evaluates to true and it evaluated to false on the previous step (the predicate is on a rising edge).
This seems like it'd require less per-trigger logic, and the predicate logic can be encapsulated more cleanly. Would that be worth doing?
@@ -305,6 +304,10 @@ class SpriteBase { | |||
get answer() { | |||
return this._project.answer; | |||
} | |||
|
|||
async loudness() { | |||
return this._project.loudnessHandler.getLoudness(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like Scratch only recomputes loudness once per step.
This adds LoudnessHandler, which is mostly copy-paste from scratch-audio. Also, adds
Project.fireGreaterThanTrigger
andTrigger.getOption
/Trigger.castOption
as well asTrigger.executed
. In terms of blocks, it addsloudness
andwhen () > ()
trigger.