Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/codspeed.yml
Original file line number Diff line number Diff line change
@@ -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 }}
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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"

Expand Down
12 changes: 0 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions benches/bench.rs
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion examples/beep_imaadpcm.rs
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion examples/beep_imaadpcm_stereo.rs
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions src/aiff.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -209,7 +209,7 @@ fn extended2double(buffer: &[u8]) -> Result<f64, AiffError> {

#[cfg(test)]
mod tests {
use super::{extended2double, ChunkId};
use super::{ChunkId, extended2double};
use approx::assert_relative_eq;

#[test]
Expand Down
10 changes: 6 additions & 4 deletions src/imaadpcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -309,7 +311,7 @@ fn parse_data_word(input: &mut &[u8]) -> ModalResult<DataWordNibbles> {

#[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
Expand Down
2 changes: 1 addition & 1 deletion src/wav.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion tests/integration_test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use approx::assert_relative_eq;
use pacmog::{
imaadpcm::{ImaAdpcmPlayer, I1F15},
AudioFormat, PcmPlayer, PcmReader,
imaadpcm::{I1F15, ImaAdpcmPlayer},
};

static SINEWAVE: [f64; 3000] = [
Expand Down