Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rp2040 Chord Vco
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sdiy
rp2040 Chord Vco
Commits
8b166f21
Commit
8b166f21
authored
2 years ago
by
David Huss
Browse files
Options
Downloads
Patches
Plain Diff
Break out envelope into class
parent
560598ea
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
Soft/Drum/Drum.ino
+7
-8
7 additions, 8 deletions
Soft/Drum/Drum.ino
Soft/Drum/Envelopes.h
+33
-0
33 additions, 0 deletions
Soft/Drum/Envelopes.h
with
40 additions
and
8 deletions
Soft/Drum/Drum.ino
+
7
−
8
View file @
8b166f21
#include
<hardware/pwm.h>
#include
"Envelopes.h"
#define MODESWITCH_PIN_A 0
#define MODESWITCH_PIN_B 1
#define PUSHBUTTON_PIN 6
...
...
@@ -18,8 +19,8 @@
int
wave
[
SAMPLES
];
EnvelopeSimpleLinear
kick_volume_envelope
;
float
volume_envelope
=
0.0
;
float
pitch_envelope
=
0.0
;
float
pitch_sigh
=
0.0
;
...
...
@@ -89,7 +90,7 @@ void loop() {
osc_freq
=
KICK_BASE_FREQ
+
freq_pot
/
1023.0
*
KICK_FREQ_RANGE
;
// Bigger decay values make the envelope shorter
volume_
decay
=
0.000005
+
(
float
)
chord_pot
/
1023.0
/
3000.0
;
kick_
volume_
envelope
.
setSpeed
(
0.000005
+
(
float
)
chord_pot
/
1023.0
/
3000.0
)
;
pitch_decay
=
0.00001
+
(
float
)
inv_pot
/
1023.0
/
300.0
;
// Increase the amount of the pitch envelope if the pitch decay is longer
pitch_envelope_amount
=
0.5
+
(
1023.0
-
(
float
)
inv_pot
)
/
1023.0
*
1.5
;
...
...
@@ -117,6 +118,8 @@ void updateKickEnvelopes() {
if
(
pitch_envelope
<
0.0001
)
{
pitch_envelope
=
0.0
;
}
kick_volume_envelope
.
update
();
}
...
...
@@ -126,13 +129,9 @@ void on_pwm_wrap() {
pwm_clear_irq
(
slice_num
);
// Decrement the volume envelope
volume_envelope
-=
volume_decay
;
if
(
volume_envelope
<
0.0001
)
{
volume_envelope
=
0.0
;
}
// Set the output to the actual level
pwm_set_chan_level
(
slice_num
,
PWM_CHAN_A
,
volume_envelope
*
wave
[(
int
)
osc_progress
]
/
2
+
511
);
pwm_set_chan_level
(
slice_num
,
PWM_CHAN_A
,
kick_
volume_envelope
.
value
*
wave
[(
int
)
osc_progress
]
/
2
+
511
);
// Advance the oscillator and reset it if it reached the end
osc_progress
+=
osc_freq
+
pitch_envelope
+
pitch_sigh
*
pitch_sigh_amount
;
...
...
@@ -167,7 +166,7 @@ void readGates() {
void
resetEnvelopes
()
{
volume_envelope
=
1.0
;
kick_
volume_envelope
.
reset
()
;
pitch_envelope
=
pitch_envelope_amount
;
pitch_sigh
=
0.0
;
sigh_incrementer
=
0.0
;
...
...
This diff is collapsed.
Click to expand it.
Soft/Drum/Envelopes.h
0 → 100644
+
33
−
0
View file @
8b166f21
// A linear falling
class
EnvelopeSimpleLinear
{
public:
float
incrementer
=
1.0
;
float
value
;
float
speed
=
0.001
;
float
amount
=
1.0
;
void
update
();
void
reset
();
void
setAmount
(
float
speed
);
void
setSpeed
(
float
speed
);
};
void
EnvelopeSimpleLinear
::
update
()
{
this
->
incrementer
-=
this
->
speed
;
if
(
this
->
incrementer
<=
0.0
)
{
this
->
incrementer
=
0.0
;
}
this
->
value
=
this
->
incrementer
*
this
->
amount
;
}
void
EnvelopeSimpleLinear
::
reset
()
{
this
->
incrementer
=
1.0
;
this
->
value
=
0.0
;
}
void
EnvelopeSimpleLinear
::
setSpeed
(
float
speed
)
{
this
->
speed
=
speed
;
}
void
EnvelopeSimpleLinear
::
setAmount
(
float
speed
)
{
this
->
amount
=
amount
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment