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
Compare revisions
560598ea6ebca6855f379ddf54dea9b7c5f04a16 to 93d590284873e1f59f7a9adf50992423c0ed12a2
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
sdiy/rp2040-chord-vco
Select target project
No results found
93d590284873e1f59f7a9adf50992423c0ed12a2
Select Git revision
Loading items
Swap
Target
sdiy/rp2040-chord-vco
Select target project
sdiy/rp2040-chord-vco
1 result
560598ea6ebca6855f379ddf54dea9b7c5f04a16
Select Git revision
Loading items
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (2)
Break out envelope into class
· 8b166f21
David Huss
authored
2 years ago
8b166f21
Add log envelope
· 93d59028
David Huss
authored
2 years ago
93d59028
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
Soft/Drum/Drum.ino
+13
-20
13 additions, 20 deletions
Soft/Drum/Drum.ino
Soft/Drum/Envelopes.h
+103
-0
103 additions, 0 deletions
Soft/Drum/Envelopes.h
with
116 additions
and
20 deletions
Soft/Drum/Drum.ino
View file @
93d59028
#include
<hardware/pwm.h>
#include
"Envelopes.h"
#define MODESWITCH_PIN_A 0
#define MODESWITCH_PIN_B 1
#define PUSHBUTTON_PIN 6
...
...
@@ -18,9 +19,9 @@
int
wave
[
SAMPLES
];
EnvelopeSimpleLinear
kick_volume_envelope
;
EnvelopeSimpleLog
kick_pitch_envelope
;
float
volume_envelope
=
0.0
;
float
pitch_envelope
=
0.0
;
float
pitch_sigh
=
0.0
;
double
last_trigger
=
0
;
...
...
@@ -33,8 +34,6 @@ int chord_pot;
float
volume_decay
;
int
inv_pot
;
float
pitch_decay
;
float
pitch_envelope_amount
;
float
pitch_sigh_amount
=
KICK_SIGH_AMOUNT
;
float
pitch_sigh_speed
=
KICK_SIGH_SPEED
;
float
sigh_incrementer
=
0.0
;
...
...
@@ -89,10 +88,11 @@ 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
;
pitch_
decay
=
0.00001
+
(
float
)
inv_pot
/
1023.0
/
3
00.0
;
kick_
volume_
envelope
.
setSpeed
(
0.000005
+
(
float
)
chord_pot
/
1023.0
/
3000.0
)
;
kick_
pitch_
envelope
.
setSpeed
(
0.00001
+
(
float
)
inv_pot
/
1023.0
/
8
00.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
;
kick_pitch_envelope
.
setAmount
(
2.0
+
(
1023.0
-
(
float
)
inv_pot
)
/
1023.0
*
8.5
);
// kick_pitch_envelope.setAmount(0.0);
// -------------------push sw , play wave-------------------------------
readGates
();
...
...
@@ -112,11 +112,8 @@ void updateKickEnvelopes() {
}
}
// Decrement the pitch envelope
pitch_envelope
-=
pitch_decay
;
if
(
pitch_envelope
<
0.0001
)
{
pitch_envelope
=
0.0
;
}
kick_pitch_envelope
.
update
();
kick_volume_envelope
.
update
();
}
...
...
@@ -126,16 +123,12 @@ 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
;
osc_progress
+=
osc_freq
+
kick_
pitch_envelope
.
value
+
pitch_sigh
*
pitch_sigh_amount
;
if
(
osc_progress
>
SAMPLES
)
{
osc_progress
=
0
;
}
...
...
@@ -167,8 +160,8 @@ void readGates() {
void
resetEnvelopes
()
{
volume_envelope
=
1.0
;
pitch_envelope
=
pitch_envelope
_amount
;
kick_
volume_envelope
.
reset
()
;
kick_
pitch_envelope
.
reset
()
;
pitch_sigh
=
0.0
;
sigh_incrementer
=
0.0
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Soft/Drum/Envelopes.h
0 → 100644
View file @
93d59028
// ---- A simple linear falling envelope -------
class
EnvelopeSimpleLinear
{
public:
float
counter
=
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
->
counter
-=
this
->
speed
;
if
(
this
->
counter
<=
0.0
)
{
this
->
counter
=
0.0
;
}
this
->
value
=
this
->
counter
*
this
->
amount
;
}
void
EnvelopeSimpleLinear
::
reset
()
{
this
->
counter
=
1.0
;
this
->
value
=
0.0
;
}
void
EnvelopeSimpleLinear
::
setSpeed
(
float
speed
)
{
this
->
speed
=
speed
;
}
void
EnvelopeSimpleLinear
::
setAmount
(
float
amount
)
{
this
->
amount
=
amount
;
}
// ---- A simple logarithmic falling envelope -------
class
EnvelopeSimpleLog
{
public:
float
counter
=
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
EnvelopeSimpleLog
::
update
()
{
this
->
counter
-=
this
->
speed
;
if
(
this
->
counter
<=
0.0
)
{
this
->
counter
=
0.0
;
}
this
->
value
=
max
(
0.0
,
(
log10
(
0.005
+
1.0
-
this
->
counter
)
*-
1.0
))
/
2.3
*
this
->
amount
;
}
void
EnvelopeSimpleLog
::
reset
()
{
this
->
counter
=
1.0
;
this
->
value
=
0.0
;
}
void
EnvelopeSimpleLog
::
setSpeed
(
float
speed
)
{
this
->
speed
=
speed
;
}
void
EnvelopeSimpleLog
::
setAmount
(
float
amount
)
{
this
->
amount
=
amount
;
}
// // ---- A simple logarithmic falling envelope -------
// class EnvelopeSigh {
// public:
// float counter = 0.0;
// float value;
// float speed = 0.001;
// float delay = 300;
// float amount = 1.0;
// void update();
// void reset();
// void setAmount(float speed);
// void setSpeed(float speed);
// void setDelay(float speed);
// };
// void EnvelopeSimpleLog::update() {
// this->counter -= this->speed;
// if (this->counter <= 0.0) {
// this->counter = 0.0;
// }
// this->value = max(0.0, (log10(0.005 + 1.0 - this->counter)*-1.0))/2.3 * this->amount;
// }
// void EnvelopeSimpleLog::reset() {
// this->counter = 1.0;
// this->value = 0.0;
// }
// void EnvelopeSimpleLog::setSpeed(float speed) {
// this->speed = speed;
// }
// void EnvelopeSimpleLog::setAmount(float amount) {
// this->amount = amount;
// }
\ No newline at end of file
This diff is collapsed.
Click to expand it.