Skip to content

Commit

Permalink
XXX WIP massive refactoring for v0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
phip1611 committed Apr 7, 2024
1 parent ad00de5 commit edda525
Show file tree
Hide file tree
Showing 29 changed files with 1,166 additions and 1,471 deletions.
10 changes: 10 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# https://doc.rust-lang.org/cargo/reference/config.html
#
# Compile for maximum performance. Only relevant for example binaries in this
# repository.

[build]
rustflags = [
"-C",
"target-cpu=native",
]
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
max_line_length = 80

[*.yml]
indent_size = 2
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use nix
100 changes: 100 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Build

# Triggers the workflow on push or pull request events (for any branch in a repository)
on: [ push, pull_request ]

env:
CARGO_TERM_COLOR: always

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- stable
- nightly
- 1.59.0 # MSRV
steps:
- uses: actions/checkout@v2
# Important preparation step: override the latest default Rust version in GitHub CI
# with the current value of the iteration in the "strategy.matrix.rust"-array.
- uses: actions-rs/toolchain@v1
with:
profile: default
toolchain: ${{ matrix.rust }}
override: true
# required because of "cpal"
- run: sudo apt update && sudo apt install libasound2-dev -y
- run: cargo build --all-targets
- run: cargo test

build_nostd:
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- stable
- nightly
- 1.59.0 # MSRV
steps:
- uses: actions/checkout@v2
# Important preparation step: override the latest default Rust version in GitHub CI
# with the current value of the iteration in the "strategy.matrix.rust"-array.
- uses: actions-rs/toolchain@v1
with:
profile: default
toolchain: ${{ matrix.rust }}
override: true
# required because of "cpal"
- run: sudo apt update && sudo apt install libasound2-dev -y
# install some no_std target
- run: rustup target add thumbv7em-none-eabihf
# reset CPU=native
- run: RUSTFLAGS="-C target-cpu=" cargo build --no-default-features --target thumbv7em-none-eabihf

build_external_examples:
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- stable
- nightly
- 1.59.0 # MSRV
steps:
- uses: actions/checkout@v2
# Important preparation step: override the latest default Rust version in GitHub CI
# with the current value of the iteration in the "strategy.matrix.rust"-array.
- uses: actions-rs/toolchain@v1
with:
profile: default
toolchain: ${{ matrix.rust }}
override: true
# required because of "cpal"
- run: sudo apt update && sudo apt install libasound2-dev -y
- run: cd "external-examples"
- run: cargo build

style_checks:
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- stable
steps:
- uses: actions/checkout@v2
# Important preparation step: override the latest default Rust version in GitHub CI
# with the current value of the iteration in the "strategy.matrix.rust"-array.
- uses: actions-rs/toolchain@v1
with:
profile: default
toolchain: ${{ matrix.rust }}
override: true
# required because of "cpal"
- run: sudo apt update && sudo apt install libasound2-dev -y
- name: Rustfmt (checks all source code/all features)
run: cargo fmt -- --check
- name: Clippy
run: cargo clippy --all-targets
- name: Rustdoc
run: cargo doc
9 changes: 0 additions & 9 deletions .travis.yml

This file was deleted.

61 changes: 44 additions & 17 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,34 +1,61 @@
[package]
name = "beat-detector"
description = """
Audio beat detection library, that supports different audio input devices as source.
You can pass a callback for each found beat to the library.
beat-detector is a `no_std`-compatible and alloc-free library written in Rust
for detecting beats in audio. It can be used for both post- and live analysis.
"""
version = "0.1.2"
version = "0.2.0"
authors = ["Philipp Schuster <[email protected]>"]
edition = "2018"
edition = "2021"
license = "MIT"
keywords = ["audio", "beat", "beat-detection" ]
categories = [ "multimedia::audio" ]
keywords = ["audio", "beat", "beat-detection"]
categories = ["multimedia::audio", "no-std"]
readme = "README.md"
homepage = "https://github.com/phip1611/beat-detector"
repository = "https://github.com/phip1611/beat-detector"
documentation = "https://docs.rs/beat-detector"
exclude = [
".cargo",
".editorconfig",
".github",
"check-build.sh",
"demo.gif",
"src/bin", # not supposed to be distributed+installable via cargo
"res"
]
rust-version = "1.71.0" # TODO real MSRV

[features]
default = ["recording"]
std = []
recording = ["std", "dep:cpal"]

[dependencies]
lowpass-filter = "0.2.4"
spectrum-analyzer = "1.1.0"
cpal = "0.13.3"
ringbuffer = "0.7.1"
# +++ NOSTD DEPENDENCIES +++

[dev-dependencies]
minimp3 = "0.5.1"
ctrlc = { version = "3.1.9", features = ["termination"] } # for examples
ws2818-rgb-led-spi-driver = "2.0.0" # for examples
rand = "0.8.3" # for examples
biquad = "0.4" # lowpass filter
log = { version = "0.4", default-features = false }
libm = "0.2"# floating point operations
ringbuffer = "0.15.0"

# +++ STD DEPENDENCIES +++
cpal = { version = "0.15", optional = true }

[dev-dependencies]
# read .wav audio files in tests
wav = "1.0"
# for examples
ctrlc = { version = "3.4", features = ["termination"] }

# otherwise FFT and other code is too slow
[profile.dev]
opt-level = 1
# otherwise many code is too slow
# remove when using the debugger
# opt-level = 1

[profile.release]
# Trimed to maximum performance.
#
# These changes only affects examples and tests build inside this crate but
# (I think!) not libraries that include this.
codegen-units = 1
lto = true
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Philipp Schuster
Copyright (c) 2024 Philipp Schuster

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
# Beat Detector - Audio Beat Detection Library Written In Rust

# Performance / Latency
On a realistic workload each analysis step of my algorithm, i.e., on each new audio input, took 0.5ms on a Raspberry
Pi and 0.05ms on an Intel i5-10600K. The benchmark binary was build as optimized release build. Thus, this is the
minimum latency you have to expect plus additional latency from the audio input interface.
The benchmark can be executed with: `cargo run --release --example --bench`

TODO: performance/latency over memory usage. Thus higher memory usage and more buffers for maximum performance

---

This is a Rust library that enables beat detection on live audio data input.
One use case is that you have an audio/aux-splitter on your computer where one
end goes into the sound system whereas the other goes into the microphone input
One use case is that you have an audio/aux-splitter on your computer where one
end goes into the sound system whereas the other goes into the microphone input
of a Raspberry Pi.

The crate provides multiple strategies that you can connect to the audio source.
Expand Down Expand Up @@ -74,4 +84,4 @@ fn select_strategy() -> StrategyKind {
```

## MSRV (Minimal Supported Rust Version)
1.52.1 stable
1.59.0 stable
14 changes: 14 additions & 0 deletions check-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

echo "checks that this builds on std+no_std + that all tests run"

cargo build --all-targets # build works
cargo test --all-targets # tests work
# install some no_std target
rustup target add thumbv7em-none-eabihf
# test no_std-build
RUSTFLAGS="-C target-cpu=" cargo build --no-default-features --target thumbv7em-none-eabihf

cargo doc
cargo fmt -- --check
cargo clippy --all-targets
100 changes: 0 additions & 100 deletions examples/audio_input_beat_detection.rs

This file was deleted.

Loading

0 comments on commit edda525

Please sign in to comment.