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
560598ea
Commit
560598ea
authored
2 years ago
by
David Huss
Browse files
Options
Downloads
Patches
Plain Diff
Add sigh, gate input
parent
f8c89195
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Soft/Drum/Drum.ino
+91
-32
91 additions, 32 deletions
Soft/Drum/Drum.ino
with
91 additions
and
32 deletions
Soft/Drum/Drum.ino
+
91
−
32
View file @
560598ea
...
@@ -9,12 +9,23 @@
...
@@ -9,12 +9,23 @@
#define DEBUG_MODE false
#define DEBUG_MODE false
#define SAMPLES 512
#define SAMPLES 512
// KICKDRUM SETTINGS
#define KICK_BASE_FREQ 0.15
#define KICK_FREQ_RANGE 2.0
#define KICK_SIGH_DELAY_MS 300
#define KICK_SIGH_AMOUNT 0.02
#define KICK_SIGH_SPEED 0.0004
int
wave
[
SAMPLES
];
int
wave
[
SAMPLES
];
float
volume_envelope
=
0.0
;
float
volume_envelope
=
0.0
;
float
pitch_envelope
=
0.0
;
float
pitch_envelope
=
0.0
;
float
pitch_sigh
=
0.0
;
double
last_trigger
=
0
;
bool
push_sw
,
old_push_sw
;
//push sw
bool
gate_high
,
old_gate_high
;
//push sw
int
freq_pot
;
int
freq_pot
;
float
osc_freq
;
float
osc_freq
;
...
@@ -23,14 +34,20 @@ float volume_decay;
...
@@ -23,14 +34,20 @@ float volume_decay;
int
inv_pot
;
int
inv_pot
;
float
pitch_decay
;
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
;
int
voct_input
;
float
osc_progress
=
0
;
float
osc_progress
=
0
;
int
slice_num
=
0
;
int
slice_num
=
0
;
int
is_on
=
0
;
void
setup
()
{
void
setup
()
{
Serial
.
begin
(
9600
);
// Mode select switch is a On-Off-On switch with the outer pins connected
// Mode select switch is a On-Off-On switch with the outer pins connected
// to the pins 0 and 1.
// to the pins 0 and 1.
pinMode
(
MODESWITCH_PIN_A
,
INPUT_PULLUP
);
pinMode
(
MODESWITCH_PIN_A
,
INPUT_PULLUP
);
...
@@ -38,9 +55,11 @@ void setup() {
...
@@ -38,9 +55,11 @@ void setup() {
// Push Button
// Push Button
pinMode
(
PUSHBUTTON_PIN
,
INPUT_PULLUP
);
//push sw
pinMode
(
PUSHBUTTON_PIN
,
INPUT_PULLUP
);
//push sw
// delay(1000);
for
(
int
i
=
0
;
i
<
SAMPLES
;
i
++
)
{
for
(
int
i
=
0
;
i
<
SAMPLES
;
i
++
)
{
wave
[
i
]
=
(
sin
(
2
*
M_PI
*
i
/
512
))
*
511
;
wave
[
i
]
=
(
sin
(
2
*
M_PI
*
i
/
SAMPLES
))
*
511
;
// Serial.println(wave[i]);
}
}
//-------------------PWM setting-------------------------------
//-------------------PWM setting-------------------------------
...
@@ -61,55 +80,95 @@ void setup() {
...
@@ -61,55 +80,95 @@ void setup() {
void
loop
()
{
void
loop
()
{
// put your main code here, to run repeatedly:
// put your main code here, to run repeatedly:
old_
push_sw
=
push_sw
;
old_
gate_high
=
gate_high
;
freq_pot
=
analogRead
(
FREQ_POT_PIN
);
freq_pot
=
analogRead
(
FREQ_POT_PIN
);
chord_pot
=
map
(
analogRead
(
CHORD_POT_PIN
),
0
,
1023
,
1023
,
0
);
chord_pot
=
map
(
analogRead
(
CHORD_POT_PIN
),
0
,
1023
,
1023
,
0
);
inv_pot
=
map
(
analogRead
(
INV_POT_PIN
),
0
,
1023
,
1023
,
0
);
inv_pot
=
map
(
analogRead
(
INV_POT_PIN
),
0
,
1023
,
1023
,
0
);
voct_input
=
analogRead
(
VOCT_PIN
);
// Serial.println(voct_input);
osc_freq
=
0.15
+
freq_pot
/
1023.0
;
osc_freq
=
KICK_BASE_FREQ
+
freq_pot
/
1023.0
*
KICK_FREQ_RANGE
;
volume_decay
=
0.00002
+
(
float
)
chord_pot
/
1023.0
/
1000.0
;
// Bigger decay values make the envelope shorter
float
_pitch_decay
=
(
inv_pot
/
1023.0
);
volume_decay
=
0.000005
+
(
float
)
chord_pot
/
1023.0
/
3000.0
;
pitch_decay
=
0.00001
+
(
float
)
inv_pot
/
1023.0
/
500.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
;
// -------------------push sw , play wave-------------------------------
// -------------------push sw , play wave-------------------------------
push_sw
=
digitalRead
(
PUSHBUTTON_PIN
);
readGates
();
// TODO: Add propper debouncing for the button here
if
(
push_sw
==
0
&&
old_push_sw
==
1
)
{
//when push sw ON
updateKickEnvelopes
();
// Change the selected waveform and ensure the selection is within bounds+1
//
}
if
(
push_sw
==
0
)
{
is_on
=
1
;
if
(
old_push_sw
==
1
)
{
osc_progress
=
0
;
volume_envelope
=
1.0
;
pitch_envelope
=
2.0
;
}
}
void
updateKickEnvelopes
()
{
// Increment the pitch sigh (a slight rise in pitch after
// the initial pitch envelope)
if
((
millis
()
-
last_trigger
)
>
KICK_SIGH_DELAY_MS
)
{
sigh_incrementer
+=
pitch_sigh_speed
;
if
(
sigh_incrementer
<
3.1415
)
{
pitch_sigh
=
max
(
0.0
,
sin
(
sigh_incrementer
));
}
else
{
}
else
{
is_on
=
0
;
pitch_sigh
=
0.
0
;
}
}
}
}
// Decrement the pitch envelope
// Timer that pushes out the actual audio.
void
on_pwm_wrap
()
{
pwm_clear_irq
(
slice_num
);
pitch_envelope
-=
pitch_decay
;
pitch_envelope
-=
pitch_decay
;
if
(
pitch_envelope
<
0.0001
)
{
if
(
pitch_envelope
<
0.0001
)
{
pitch_envelope
=
0.0
;
pitch_envelope
=
0.0
;
}
}
}
osc_progress
+=
osc_freq
+
pitch_envelope
;
if
(
osc_progress
>
SAMPLES
)
{
// Timer that pushes out the actual audio with a fixed frequency
osc_progress
=
0
;
// Code inside this block needs to be fast in order to meet the deadlines
}
void
on_pwm_wrap
()
{
pwm_clear_irq
(
slice_num
);
// Decrement the volume envelope
volume_envelope
-=
volume_decay
;
volume_envelope
-=
volume_decay
;
if
(
volume_envelope
<
0.0001
)
{
if
(
volume_envelope
<
0.0001
)
{
volume_envelope
=
0.0
;
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
,
volume_envelope
*
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
;
if
(
osc_progress
>
SAMPLES
)
{
osc_progress
=
0
;
}
}
// Reads the push button and V/Oct Input in order to trigger the gate
void
readGates
()
{
// Read the push button
gate_high
=
!
digitalRead
(
PUSHBUTTON_PIN
);
// If there is a value bigger than 1 on the V/Oct Input, trigger the drum
if
(
voct_input
>
512
)
{
gate_high
=
1
;
}
// If the module is first starting, supress any accidental triggering
if
(
millis
()
<
500
)
{
gate_high
=
0
;
}
// If there is a gate
if
(
gate_high
==
1
)
{
// Trigger only on first rising flank
if
(
old_gate_high
==
0
)
{
// Reset the oscillator and the envelopes
osc_progress
=
0
;
last_trigger
=
millis
();
resetEnvelopes
();
}
}
}
void
resetEnvelopes
()
{
volume_envelope
=
1.0
;
pitch_envelope
=
pitch_envelope_amount
;
pitch_sigh
=
0.0
;
sigh_incrementer
=
0.0
;
}
}
\ 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