-
Notifications
You must be signed in to change notification settings - Fork 11
Implement DSP/Cmajor code for 'Cabasa' (Midi note 69) #82
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| namespace Percupuff | ||
| { | ||
| namespace Drums | ||
| { | ||
| processor Cabasa { | ||
| input event (std::notes::NoteOn) eventIn; | ||
| output stream float<2> out; | ||
| input event Params paramsIn; | ||
|
|
||
| float triggerVelocity = 0.0f; | ||
| int midiNotePitch = 0; | ||
| float outputLevel = 0.5f; | ||
| float panning = 0.0f; | ||
|
|
||
| event paramsIn(Params p) { | ||
| midiNotePitch = int(p.cabasaMidi); | ||
| outputLevel = p.cabasaLevel * 0.01f; | ||
| panning = p.cabasaPanning; | ||
| } | ||
|
|
||
| event eventIn(std::notes::NoteOn n) { | ||
| if (int(n.pitch) == midiNotePitch) | ||
| triggerVelocity = sqrt(n.velocity); | ||
| } | ||
|
|
||
| node envelope = Envelope; | ||
| node noise = std::noise::White; | ||
|
|
||
| // Use one resonant SVF, this gives the metallic "clack" sound | ||
| node filter = std::filters::tpt::svf::Processor( | ||
| std::filters::tpt::svf::Mode::bandPass, 4000.0f, 5.0f | ||
| ); | ||
|
|
||
| void main() | ||
| { | ||
| envelope.attackIn <- 0.0008f; | ||
| let baseCutoff = 3800.0f; // Metallic "clack" frequency | ||
| let baseQ = 5.0f; // This resonance is the "metal" sound | ||
|
|
||
| loop | ||
| { | ||
| while (triggerVelocity == 0) | ||
| advance(); | ||
|
|
||
| let baseVel = triggerVelocity; | ||
| triggerVelocity = 0.0f; | ||
|
|
||
| float burstCount = 4 + (baseVel * 25); | ||
| // Slightly increased spacing for a "heavier" bead sound | ||
| float burstSpacing = 0.0005f + (1.0f - baseVel) * 0.0045f; | ||
|
|
||
| for (int i = 0; i < int(burstCount); ++i) | ||
| { | ||
| float velJitter = 0.8f + (noise.out * 0.2f); | ||
| float burstVel = baseVel * velJitter; | ||
|
|
||
| // Modified release for more "body" on each bead hit | ||
| envelope.releaseIn <- 0.004f + (noise.out * 0.001f); | ||
| envelope.triggerIn <- void; | ||
| envelope.advance(); | ||
|
|
||
| float gain = envelope.gainOut; | ||
|
|
||
| // Alternate stereo motion slightly | ||
| float altPan = ((i % 2 == 0) ? -0.4f : 0.4f) + (panning * 0.01f); | ||
|
|
||
| // Add jitter to cutoff and Q for a more natural, chaotic sound | ||
| filter.frequency <- baseCutoff + (noise.out * 400.0f); | ||
| filter.q <- baseQ + (noise.out * 0.5f); | ||
|
|
||
| while (gain > 0.001f) | ||
| { | ||
| float raw = noise.out; | ||
|
|
||
| // Run the noise through the filter | ||
| filter.in <- raw; | ||
| float filtered = filter.out; | ||
|
|
||
| float outSample = filtered * gain * burstVel * outputLevel; | ||
|
|
||
| float leftGain = 0.5f * (1.0f - altPan); | ||
| float rightGain = 0.5f * (1.0f + altPan); | ||
| out <- (outSample * leftGain, outSample * rightGain); | ||
|
|
||
| noise.advance(); | ||
| filter.advance(); | ||
| envelope.advance(); | ||
| advance(); | ||
|
|
||
| gain = envelope.gainOut; | ||
| } | ||
|
|
||
| float jitter = (noise.out * 0.0003f); | ||
| int silentSamples = int((burstSpacing + jitter) * 44100.0f); | ||
| for (int s = 0; s < silentSamples; ++s) | ||
| { | ||
| out <- (0.0f, 0.0f); // Output silence in stereo | ||
| advance(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Same comment as here: #80 (comment)
I don't think we need this
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.
oh wait no sorry, I am reading this wrong, this is to space out bursts of one "hit" of the instrument. We do need it, but we should use
float(processor.frequency)instead of hardcoding a 44.1khz sample rate.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.
Good catch, I added that!