Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
circuitpython/shared-module/synthio/LFO.c at main · niederr/circuitpython · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
niederr
/
circuitpython
Public
forked from
adafruit/circuitpython
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Files
Expand file tree
main
Breadcrumbs
circuitpython
/
shared-module
/
synthio
/
LFO.c
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
121 lines (95 loc) · 3.66 KB
main
Breadcrumbs
circuitpython
/
shared-module
/
synthio
/
LFO.c
Copy path
Top
File metadata and controls
Code
Blame
121 lines (95 loc) · 3.66 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// This file is part of the CircuitPython project: https://circuitpython.org
//
// SPDX-FileCopyrightText: Copyright (c) 2023 Jeff Epler for Adafruit Industries
//
// SPDX-License-Identifier: MIT
#include
"shared-bindings/synthio/LFO.h"
#include
"shared-module/synthio/LFO.h"
#include
<math.h>
#define
ONE
(MICROPY_FLOAT_CONST(1.))
#define
ZERO
(MICROPY_FLOAT_CONST(0.))
#define
ALMOST_ONE
(MICROPY_FLOAT_CONST(32767.) / 32768)
mp_float_t
common_hal_synthio_lfo_tick
(
mp_obj_t
self_in
) {
synthio_lfo_obj_t
*
lfo
=
MP_OBJ_TO_PTR
(
self_in
);
mp_float_t
rate
=
synthio_block_slot_get
(
&
lfo
->
rate
)
*
synthio_global_rate_scale
;
mp_float_t
phase_offset
=
synthio_block_slot_get
(
&
lfo
->
phase_offset
);
mp_float_t
accum
=
lfo
->
accum
+
rate
+
phase_offset
;
if
(
lfo
->
once
) {
if
(
rate
>
0
) {
if
(
accum
>
ALMOST_ONE
) {
accum
=
ALMOST_ONE
;
}
}
else
if
(
rate
<
0
&&
accum
<
ZERO
) {
accum
=
ZERO
;
}
}
else
{
accum
=
accum
-
MICROPY_FLOAT_C_FUN
(
floor
)(
accum
);
}
lfo
->
accum
=
accum
-
phase_offset
;
int
len
=
lfo
->
waveform_bufinfo
.
len
;
mp_float_t
scaled_accum
=
accum
*
(
len
-
lfo
->
once
);
size_t
idx
=
(
size_t
)
MICROPY_FLOAT_C_FUN
(
floor
)(
scaled_accum
);
assert
(
idx
<
lfo
->
waveform_bufinfo
.
len
);
int16_t
*
waveform
=
lfo
->
waveform_bufinfo
.
buf
;
mp_float_t
value
=
waveform
[
idx
];
if
(
lfo
->
interpolate
) {
mp_float_t
frac
=
scaled_accum
-
idx
;
size_t
idxp1
=
idx
+
1
;
if
(
idxp1
==
lfo
->
waveform_bufinfo
.
len
) {
idxp1
=
lfo
->
once
?
idx
:
0
;
}
value
=
value
*
(
1
-
frac
)
+
waveform
[
idxp1
]
*
frac
;
}
mp_float_t
scale
=
synthio_block_slot_get
(
&
lfo
->
scale
);
mp_float_t
offset
=
synthio_block_slot_get
(
&
lfo
->
offset
);
value
=
MICROPY_FLOAT_C_FUN
(
ldexp
)(
value
,
-15
)
*
scale
+
offset
;
return
value
;
}
mp_obj_t
common_hal_synthio_lfo_get_waveform_obj
(
synthio_lfo_obj_t
*
self
) {
return
self
->
waveform_obj
;
}
mp_obj_t
common_hal_synthio_lfo_get_rate_obj
(
synthio_lfo_obj_t
*
self
) {
return
self
->
rate
.
obj
;
}
void
common_hal_synthio_lfo_set_rate_obj
(
synthio_lfo_obj_t
*
self
,
mp_obj_t
arg
) {
synthio_block_assign_slot
(
arg
,
&
self
->
rate
,
MP_QSTR_rate
);
}
mp_obj_t
common_hal_synthio_lfo_get_scale_obj
(
synthio_lfo_obj_t
*
self
) {
return
self
->
scale
.
obj
;
}
void
common_hal_synthio_lfo_set_scale_obj
(
synthio_lfo_obj_t
*
self
,
mp_obj_t
arg
) {
synthio_block_assign_slot
(
arg
,
&
self
->
scale
,
MP_QSTR_scale
);
}
mp_obj_t
common_hal_synthio_lfo_get_phase_offset_obj
(
synthio_lfo_obj_t
*
self
) {
return
self
->
phase_offset
.
obj
;
}
void
common_hal_synthio_lfo_set_phase_offset_obj
(
synthio_lfo_obj_t
*
self
,
mp_obj_t
arg
) {
synthio_block_assign_slot
(
arg
,
&
self
->
phase_offset
,
MP_QSTR_phase_offset
);
}
mp_obj_t
common_hal_synthio_lfo_get_offset_obj
(
synthio_lfo_obj_t
*
self
) {
return
self
->
offset
.
obj
;
}
void
common_hal_synthio_lfo_set_offset_obj
(
synthio_lfo_obj_t
*
self
,
mp_obj_t
arg
) {
synthio_block_assign_slot
(
arg
,
&
self
->
offset
,
MP_QSTR_offset
);
}
bool
common_hal_synthio_lfo_get_once
(
synthio_lfo_obj_t
*
self
) {
return
self
->
once
;
}
void
common_hal_synthio_lfo_set_once
(
synthio_lfo_obj_t
*
self
,
bool
arg
) {
self
->
once
=
arg
;
}
bool
common_hal_synthio_lfo_get_interpolate
(
synthio_lfo_obj_t
*
self
) {
return
self
->
interpolate
;
}
void
common_hal_synthio_lfo_set_interpolate
(
synthio_lfo_obj_t
*
self
,
bool
arg
) {
self
->
interpolate
=
arg
;
}
mp_float_t
common_hal_synthio_lfo_get_value
(
synthio_lfo_obj_t
*
self
) {
return
self
->
base
.
value
;
}
mp_float_t
common_hal_synthio_lfo_get_phase
(
synthio_lfo_obj_t
*
self
) {
return
self
->
accum
;
}
void
common_hal_synthio_lfo_retrigger
(
synthio_lfo_obj_t
*
self
) {
self
->
accum
=
0
;
}
You can’t perform that action at this time.