Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
Hexmatrix
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
elektronik
Hexmatrix
Commits
1e4c3a09
Commit
1e4c3a09
authored
3 years ago
by
David Huss
Browse files
Options
Downloads
Patches
Plain Diff
Some minor refactoring
parent
e7c4658f
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
src/main.rs
+36
-35
36 additions, 35 deletions
src/main.rs
with
36 additions
and
35 deletions
src/main.rs
+
36
−
35
View file @
1e4c3a09
...
...
@@ -63,6 +63,37 @@ static VOLS16: [AtomicUsize; N_INPUTS] = arr![AtomicUsize::new(0); 16];
fn
get_volume_for_input_output_pair
(
input_index
:
usize
,
output_index
:
usize
)
->
f32
{
// For each input get the corrsponding atomic value for the volume control
match
input_index
{
0
=>
VOLS1
[
output_index
]
.load
(
Ordering
::
Relaxed
)
as
f32
/
usize
::
MAX
as
f32
,
1
=>
VOLS2
[
output_index
]
.load
(
Ordering
::
Relaxed
)
as
f32
/
usize
::
MAX
as
f32
,
2
=>
VOLS3
[
output_index
]
.load
(
Ordering
::
Relaxed
)
as
f32
/
usize
::
MAX
as
f32
,
3
=>
VOLS4
[
output_index
]
.load
(
Ordering
::
Relaxed
)
as
f32
/
usize
::
MAX
as
f32
,
4
=>
VOLS5
[
output_index
]
.load
(
Ordering
::
Relaxed
)
as
f32
/
usize
::
MAX
as
f32
,
5
=>
VOLS6
[
output_index
]
.load
(
Ordering
::
Relaxed
)
as
f32
/
usize
::
MAX
as
f32
,
6
=>
VOLS7
[
output_index
]
.load
(
Ordering
::
Relaxed
)
as
f32
/
usize
::
MAX
as
f32
,
7
=>
VOLS8
[
output_index
]
.load
(
Ordering
::
Relaxed
)
as
f32
/
usize
::
MAX
as
f32
,
8
=>
VOLS9
[
output_index
]
.load
(
Ordering
::
Relaxed
)
as
f32
/
usize
::
MAX
as
f32
,
9
=>
VOLS10
[
output_index
]
.load
(
Ordering
::
Relaxed
)
as
f32
/
usize
::
MAX
as
f32
,
10
=>
VOLS11
[
output_index
]
.load
(
Ordering
::
Relaxed
)
as
f32
/
usize
::
MAX
as
f32
,
11
=>
VOLS12
[
output_index
]
.load
(
Ordering
::
Relaxed
)
as
f32
/
usize
::
MAX
as
f32
,
12
=>
VOLS13
[
output_index
]
.load
(
Ordering
::
Relaxed
)
as
f32
/
usize
::
MAX
as
f32
,
13
=>
VOLS14
[
output_index
]
.load
(
Ordering
::
Relaxed
)
as
f32
/
usize
::
MAX
as
f32
,
14
=>
VOLS15
[
output_index
]
.load
(
Ordering
::
Relaxed
)
as
f32
/
usize
::
MAX
as
f32
,
15
=>
VOLS16
[
output_index
]
.load
(
Ordering
::
Relaxed
)
as
f32
/
usize
::
MAX
as
f32
,
_
=>
0.0
}
}
fn
port_has_connections
<
T
>
(
port
:
&
Port
<
T
>
)
->
bool
{
match
port
.connected_count
()
{
Ok
(
count
)
=>
count
>
0
,
_
=>
true
}
}
fn
main
()
{
let
matches
=
App
::
new
(
option_env!
(
"CARGO_PKG_NAME"
)
.unwrap
())
...
...
@@ -138,51 +169,21 @@ fn main() {
// (in this case for testing purposes: all to all)
inputs
.iter
()
.enumerate
()
.filter
(|(
_input_index
,
inport
)|
{
match
inport
.connected_count
()
{
Ok
(
count
)
=>
count
>
0
,
_
=>
true
}
})
.filter
(|(
_input_index
,
inport
)|
port_has_connections
(
inport
))
.for_each
(|(
input_index
,
inport
)|
{
// Get a slice [f32; 1024] of samples for each port
let
input_samples
=
inport
.as_slice
(
ps
);
let
input_samples
=
&
inport
.as_slice
(
ps
)
[
..
buffersize
]
;
// Sum each input to output buffer
output_buffers
.par_iter_mut
()
.enumerate
()
.filter
(|(
output_index
,
_buffer
)|
{
match
outputs
[
*
output_index
]
.connected_count
()
{
Ok
(
count
)
=>
count
>
0
,
_
=>
true
}
})
.filter
(|(
output_index
,
_buffer
)|
port_has_connections
(
&
outputs
[
*
output_index
]))
.for_each
(|(
output_index
,
b
)|
{
b
.par_iter_mut
()
.take
(
buffersize
)
.enumerate
()
.for_each
(|(
sample_index
,
sample
)|
{
// For each input get the corrsponding atomic value for the volume control
let
volume
=
match
input_index
{
0
=>
VOLS1
[
output_index
]
.load
(
Ordering
::
Relaxed
)
as
f32
/
usize
::
MAX
as
f32
,
1
=>
VOLS2
[
output_index
]
.load
(
Ordering
::
Relaxed
)
as
f32
/
usize
::
MAX
as
f32
,
2
=>
VOLS3
[
output_index
]
.load
(
Ordering
::
Relaxed
)
as
f32
/
usize
::
MAX
as
f32
,
3
=>
VOLS4
[
output_index
]
.load
(
Ordering
::
Relaxed
)
as
f32
/
usize
::
MAX
as
f32
,
4
=>
VOLS5
[
output_index
]
.load
(
Ordering
::
Relaxed
)
as
f32
/
usize
::
MAX
as
f32
,
5
=>
VOLS6
[
output_index
]
.load
(
Ordering
::
Relaxed
)
as
f32
/
usize
::
MAX
as
f32
,
6
=>
VOLS7
[
output_index
]
.load
(
Ordering
::
Relaxed
)
as
f32
/
usize
::
MAX
as
f32
,
7
=>
VOLS8
[
output_index
]
.load
(
Ordering
::
Relaxed
)
as
f32
/
usize
::
MAX
as
f32
,
8
=>
VOLS9
[
output_index
]
.load
(
Ordering
::
Relaxed
)
as
f32
/
usize
::
MAX
as
f32
,
9
=>
VOLS10
[
output_index
]
.load
(
Ordering
::
Relaxed
)
as
f32
/
usize
::
MAX
as
f32
,
10
=>
VOLS11
[
output_index
]
.load
(
Ordering
::
Relaxed
)
as
f32
/
usize
::
MAX
as
f32
,
11
=>
VOLS12
[
output_index
]
.load
(
Ordering
::
Relaxed
)
as
f32
/
usize
::
MAX
as
f32
,
12
=>
VOLS13
[
output_index
]
.load
(
Ordering
::
Relaxed
)
as
f32
/
usize
::
MAX
as
f32
,
13
=>
VOLS14
[
output_index
]
.load
(
Ordering
::
Relaxed
)
as
f32
/
usize
::
MAX
as
f32
,
14
=>
VOLS15
[
output_index
]
.load
(
Ordering
::
Relaxed
)
as
f32
/
usize
::
MAX
as
f32
,
15
=>
VOLS16
[
output_index
]
.load
(
Ordering
::
Relaxed
)
as
f32
/
usize
::
MAX
as
f32
,
_
=>
0.0
};
let
volume
=
get_volume_for_input_output_pair
(
input_index
,
output_index
);
if
volume
!=
0.0
{
// Multiply each input sample at position `sample_index` with the
...
...
@@ -199,7 +200,7 @@ fn main() {
outputs
.iter_mut
()
.enumerate
()
.for_each
(|(
output_index
,
outport
)|
{
outport
.as_mut_slice
(
ps
)
.clone_from_slice
(
&
output_buffers
[
output_index
][
..
buffersize
]);
outport
.as_mut_slice
(
ps
)
[
..
buffersize
]
.clone_from_slice
(
&
output_buffers
[
output_index
][
..
buffersize
]);
});
jack
::
Control
::
Continue
};
...
...
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