Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
goertzel-nostd
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stephen D
goertzel-nostd
Commits
f56b7a67
Commit
f56b7a67
authored
3 years ago
by
Stephen D
Browse files
Options
Downloads
Patches
Plain Diff
replace i16 with f32
parent
bcbab5ed
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/lib.rs
+8
-8
8 additions, 8 deletions
src/lib.rs
with
8 additions
and
8 deletions
src/lib.rs
+
8
−
8
View file @
f56b7a67
...
...
@@ -46,15 +46,15 @@ impl Parameters {
}
}
pub
fn
mag
(
self
,
samples
:
&
[
i16
])
->
f32
{
pub
fn
mag
(
self
,
samples
:
&
[
f32
])
->
f32
{
self
.start
()
.add_samples
(
samples
)
.finish_mag
()
}
}
impl
Partial
{
pub
fn
add_samples
(
mut
self
,
samples
:
&
[
i16
])
->
Self
{
pub
fn
add_samples
(
mut
self
,
samples
:
&
[
f32
])
->
Self
{
for
&
sample
in
samples
{
let
this
=
self
.params.term_coefficient
*
self
.prev
-
self
.prevprev
+
(
sample
as
f32
)
;
let
this
=
self
.params.term_coefficient
*
self
.prev
-
self
.prevprev
+
sample
;
self
.prevprev
=
self
.prev
;
self
.prev
=
this
;
}
...
...
@@ -77,11 +77,11 @@ impl Partial {
#[test]
fn
zero_data
()
{
let
p
=
Parameters
::
new
(
1800.
,
8000
,
256
);
assert!
(
p
.start
()
.add_samples
(
&
[
0
;
256
])
.finish_mag
()
==
0.
);
assert!
(
p
.start
()
.add_samples
(
&
[
0
.0
;
256
])
.finish_mag
()
==
0.
);
assert!
(
p
.start
()
.add_samples
(
&
[
0
;
128
])
.add_samples
(
&
[
0
;
128
])
.add_samples
(
&
[
0
.0
;
128
])
.add_samples
(
&
[
0
.0
;
128
])
.finish_mag
()
==
0.
);
...
...
@@ -89,13 +89,13 @@ fn zero_data() {
#[test]
fn
sine
()
{
let
mut
buf
=
[
0
;
8000
];
let
mut
buf
=
[
0
.0
;
8000
];
for
&
freq
in
[
697.
,
1200.
,
1800.
,
1633.
]
.iter
()
{
// Generate a 1 second sine wave at freq hz
let
step
=
1.
/
8000.
;
for
(
i
,
v
)
in
buf
.iter_mut
()
.enumerate
()
{
let
time
=
i
as
f32
*
step
;
*
v
=
(
(
time
*
freq
*
PI
*
2.
)
.sin
()
*
std
::
i16
::
MAX
as
f32
)
as
i16
;
*
v
=
(
time
*
freq
*
PI
*
2.
)
.sin
();
}
let
p
=
Parameters
::
new
(
freq
,
8000
,
8000
);
...
...
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