diff --git a/.github/workflows/codspeed.yml b/.github/workflows/codspeed.yml new file mode 100644 index 0000000..b533aa8 --- /dev/null +++ b/.github/workflows/codspeed.yml @@ -0,0 +1,33 @@ +name: CodSpeed + +on: + pull_request: + branches: ["main"] + types: [opened, synchronize, reopened] + +env: + CARGO_TERM_COLOR: always + CARGO_INCREMENTAL: 0 + +jobs: + codspeed: + name: Run benchmarks + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: install libasound2-dev + run: | + sudo apt-get update + sudo apt-get install libasound2-dev + + - name: Set up Rust + run: cargo install cargo-codspeed --locked + + - name: Build the benchmarks + run: cargo codspeed build + + - name: Run the benchmarks + uses: CodSpeedHQ/action@v3 + with: + run: cargo codspeed run + token: ${{ secrets.CODSPEED_TOKEN }} diff --git a/Cargo.toml b/Cargo.toml index 308f5cd..7aeac3f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,8 +8,8 @@ keywords = ["audio", "wav"] license = "MIT OR Apache-2.0" repository = "https://github.com/AkiyukiOkayasu/pacmog" readme = "README.md" -edition = "2021" -rust-version = "1.81.0" +edition = "2024" +rust-version = "1.85.0" exclude = ["tests/resources/*"] [dependencies] @@ -25,7 +25,7 @@ winnow = { version = "0.7.10", default-features = false } [dev-dependencies] cpal = "0.15.3" approx = "0.5.1" -criterion = "0.5.1" +criterion = { package = "codspeed-criterion-compat", version = "*" } symphonia = { version = "0.5.4", features = ["aiff", "adpcm"] } anyhow = "1.0.98" diff --git a/README.md b/README.md index 0ff0a1f..78ae0a2 100644 --- a/README.md +++ b/README.md @@ -69,18 +69,6 @@ for sample in 0..num_samples { } ``` -## Test - -```bash -cargo test -``` - -## Benchmark - -```bash -cargo criterion -``` - ## no_std pacmog works with no_std by default. diff --git a/benches/bench.rs b/benches/bench.rs index 5c1e3cc..140ecb3 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -1,5 +1,5 @@ -use criterion::{black_box, criterion_group, criterion_main, Criterion}; -use pacmog::imaadpcm::{ImaAdpcmPlayer, I1F15}; +use criterion::{Criterion, black_box, criterion_group, criterion_main}; +use pacmog::imaadpcm::{I1F15, ImaAdpcmPlayer}; use pacmog::{PcmPlayer, PcmReader}; fn parse_wav(c: &mut Criterion) { diff --git a/examples/beep_imaadpcm.rs b/examples/beep_imaadpcm.rs index aaeada5..8fb5667 100644 --- a/examples/beep_imaadpcm.rs +++ b/examples/beep_imaadpcm.rs @@ -1,6 +1,6 @@ //! Play a sample mono ADPCM file. use cpal::traits::{DeviceTrait, HostTrait, StreamTrait}; -use pacmog::imaadpcm::{ImaAdpcmPlayer, I1F15}; +use pacmog::imaadpcm::{I1F15, ImaAdpcmPlayer}; use std::sync::mpsc; fn main() { diff --git a/examples/beep_imaadpcm_stereo.rs b/examples/beep_imaadpcm_stereo.rs index 0515165..b9755f1 100644 --- a/examples/beep_imaadpcm_stereo.rs +++ b/examples/beep_imaadpcm_stereo.rs @@ -1,6 +1,6 @@ //! Play a sample stereo ADPCM file. use cpal::traits::{DeviceTrait, HostTrait, StreamTrait}; -use pacmog::imaadpcm::{ImaAdpcmPlayer, I1F15}; +use pacmog::imaadpcm::{I1F15, ImaAdpcmPlayer}; use std::sync::mpsc; fn main() { diff --git a/src/aiff.rs b/src/aiff.rs index 56657e8..eb13aa5 100644 --- a/src/aiff.rs +++ b/src/aiff.rs @@ -1,9 +1,9 @@ use crate::{AudioFormat, PcmSpecs}; +use winnow::Parser; use winnow::binary::{be_i16, be_i32, be_u32}; use winnow::combinator::alt; use winnow::error::ModalResult; use winnow::token::{literal, take}; -use winnow::Parser; #[derive(thiserror::Error, Debug)] enum AiffError { @@ -209,7 +209,7 @@ fn extended2double(buffer: &[u8]) -> Result { #[cfg(test)] mod tests { - use super::{extended2double, ChunkId}; + use super::{ChunkId, extended2double}; use approx::assert_relative_eq; #[test] diff --git a/src/imaadpcm.rs b/src/imaadpcm.rs index fef6483..f2e2613 100644 --- a/src/imaadpcm.rs +++ b/src/imaadpcm.rs @@ -24,10 +24,10 @@ use crate::{AudioFormat, PcmReader, PcmReaderError, PcmSpecs}; use arbitrary_int::u4; pub use fixed::types::I1F15; use heapless::spsc::Queue; +use winnow::Parser; use winnow::binary::bits::{bits, take}; -use winnow::binary::{le_i16, le_i8, le_u8}; +use winnow::binary::{le_i8, le_i16, le_u8}; use winnow::error::{ContextError, ErrMode, ModalResult}; -use winnow::Parser; /// Index table for STEP_SIZE_TABLE. const INDEX_TABLE: [i8; 16] = [-1, -1, -1, -1, 2, 4, 6, 8, -1, -1, -1, -1, 2, 4, 6, 8]; @@ -59,7 +59,9 @@ pub enum ImaAdpcmError { CantDecodeImaAdpcm, #[error("The audio format is not IMA-ADPCM.")] NotImaAdpcm, - #[error("The number of elements in the output buffer must be at least equal to the number of IMA-ADPCM channels.")] + #[error( + "The number of elements in the output buffer must be at least equal to the number of IMA-ADPCM channels." + )] InsufficientOutputBufferChannels, #[error("Finish playing.")] FinishPlaying, @@ -309,7 +311,7 @@ fn parse_data_word(input: &mut &[u8]) -> ModalResult { #[cfg(test)] mod tests { - use crate::imaadpcm::{decode_sample, I1F15}; + use crate::imaadpcm::{I1F15, decode_sample}; use arbitrary_int::u4; // http://www.cs.columbia.edu/~hgs/audio/dvi/IMA_ADPCM.pdf diff --git a/src/wav.rs b/src/wav.rs index 2b6efcc..150b4d3 100644 --- a/src/wav.rs +++ b/src/wav.rs @@ -191,7 +191,7 @@ pub(super) fn calc_num_samples_per_channel( #[cfg(test)] mod tests { - use crate::{wav::calc_num_samples_per_channel, wav::ChunkId, PcmSpecs}; + use crate::{PcmSpecs, wav::ChunkId, wav::calc_num_samples_per_channel}; use super::WaveFormatTag; diff --git a/tests/integration_test.rs b/tests/integration_test.rs index d4f89e4..02991e5 100644 --- a/tests/integration_test.rs +++ b/tests/integration_test.rs @@ -1,7 +1,7 @@ use approx::assert_relative_eq; use pacmog::{ - imaadpcm::{ImaAdpcmPlayer, I1F15}, AudioFormat, PcmPlayer, PcmReader, + imaadpcm::{I1F15, ImaAdpcmPlayer}, }; static SINEWAVE: [f64; 3000] = [