Skip to content

Commit

Permalink
fix example and bench codes
Browse files Browse the repository at this point in the history
  • Loading branch information
AkiyukiOkayasu committed Aug 20, 2024
1 parent ef2f64c commit 43e788d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion benches/bench.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use pacmog::imaadpcm::{ImaAdpcmPlayer, I1F15};
use pacmog::PcmReader;
use pacmog::PcmReaderBuilder;

fn parse_wav(c: &mut Criterion) {
let wav = include_bytes!("../tests/resources/Sine440Hz_1ch_48000Hz_16.wav");
Expand Down
4 changes: 2 additions & 2 deletions examples/beep.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Play a sample WAV file.
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
use pacmog::PcmReader;
use pacmog::PcmReaderBuilder;
use std::sync::mpsc;

fn main() {
Expand All @@ -15,7 +15,7 @@ fn main() {
println!("Default output config: {config:?}");
let channels = config.channels() as usize;

let reader = PcmReader::new(wav).unwrap();
let reader = PcmReaderBuilder::new(wav).build().unwrap();
let mut sample_index = 0;

println!("PCM spec: {:?}", reader.get_pcm_specs());
Expand Down
2 changes: 1 addition & 1 deletion examples/print_sample_values.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use pacmog::{PcmReader, PcmReaderBuilder};
use pacmog::PcmReaderBuilder;
use std::{fs, io::Write};

fn main() {
Expand Down
4 changes: 2 additions & 2 deletions examples/read_wav_no_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
#![no_std]

use pacmog::PcmReader;
use pacmog::PcmReaderBuilder;

fn main() {
let wav = include_bytes!("../tests/resources/Sine440Hz_1ch_48000Hz_16.wav");
let reader = PcmReader::new(wav).unwrap();
let reader = PcmReaderBuilder::new(wav).build().unwrap();
for sample in 0..48000 {
let _s = reader.read_sample(0, sample);
}
Expand Down
30 changes: 15 additions & 15 deletions 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,
AudioFormat, PcmPlayer, PcmReaderBuilder,
};

const SINEWAVE: [f32; 3000] = [
Expand Down Expand Up @@ -3028,7 +3028,7 @@ fn fixed_test() {
#[test]
fn wav_linearpcm_specs() {
let wav = include_bytes!("./resources/Sine440Hz_1ch_48000Hz_16.wav");
let reader = PcmReader::new(wav).unwrap();
let reader = PcmReaderBuilder::new(wav).build().unwrap();
let spec = reader.get_pcm_specs();
assert_eq!(spec.bit_depth, 16);
assert_eq!(spec.audio_format, AudioFormat::LinearPcmLe);
Expand All @@ -3040,7 +3040,7 @@ fn wav_linearpcm_specs() {
#[test]
fn aiff_linearpcm_specs() {
let data = include_bytes!("./resources/Sine440Hz_1ch_48000Hz_16.aif");
let reader = PcmReader::new(data).unwrap();
let reader = PcmReaderBuilder::new(data).build().unwrap();
let spec = reader.get_pcm_specs();
assert_eq!(spec.bit_depth, 16);
assert_eq!(spec.audio_format, AudioFormat::LinearPcmBe); //Big endian
Expand All @@ -3052,7 +3052,7 @@ fn aiff_linearpcm_specs() {
#[test]
fn wav_float32_specs() {
let wav = include_bytes!("./resources/Sine440Hz_1ch_48000Hz_32FP.wav");
let reader = PcmReader::new(wav).unwrap();
let reader = PcmReaderBuilder::new(wav).build().unwrap();
let spec = reader.get_pcm_specs();
assert_eq!(spec.bit_depth, 32);
assert_eq!(spec.audio_format, AudioFormat::IeeeFloatLe); //Little endian
Expand All @@ -3064,7 +3064,7 @@ fn wav_float32_specs() {
#[test]
fn aiff_float32_specs() {
let data = include_bytes!("./resources/Sine440Hz_1ch_48000Hz_32FP.aif");
let reader = PcmReader::new(data).unwrap();
let reader = PcmReaderBuilder::new(data).build().unwrap();
let spec = reader.get_pcm_specs();
assert_eq!(spec.bit_depth, 32);
assert_eq!(spec.audio_format, AudioFormat::IeeeFloatBe); //Big endian
Expand All @@ -3076,7 +3076,7 @@ fn aiff_float32_specs() {
#[test]
fn wav_16bit() {
let wav = include_bytes!("./resources/Sine440Hz_1ch_48000Hz_16.wav");
let reader = PcmReader::new(wav).unwrap();
let reader = PcmReaderBuilder::new(wav).build().unwrap();
let spec = reader.get_pcm_specs();
assert_eq!(spec.num_samples, 240000);
assert_eq!(spec.sample_rate, 48000);
Expand All @@ -3097,7 +3097,7 @@ fn wav_16bit() {
#[test]
fn wav_24bit() {
let wav = include_bytes!("./resources/Sine440Hz_1ch_48000Hz_24.wav");
let reader = PcmReader::new(wav).unwrap();
let reader = PcmReaderBuilder::new(wav).build().unwrap();
let spec = reader.get_pcm_specs();
assert_eq!(spec.num_samples, 240000);
assert_eq!(spec.sample_rate, 48000);
Expand All @@ -3114,7 +3114,7 @@ fn wav_24bit() {
#[test]
fn wav_32bit() {
let wav = include_bytes!("./resources/Sine440Hz_1ch_48000Hz_32.wav");
let reader = PcmReader::new(wav).unwrap();
let reader = PcmReaderBuilder::new(wav).build().unwrap();
let spec = reader.get_pcm_specs();
assert_eq!(spec.num_samples, 240000);
assert_eq!(spec.sample_rate, 48000);
Expand Down Expand Up @@ -3186,7 +3186,7 @@ fn wav_player_32bit() {
#[test]
fn wav_32bit_float() {
let wav = include_bytes!("./resources/Sine440Hz_1ch_48000Hz_32FP.wav");
let reader = PcmReader::new(wav).unwrap();
let reader = PcmReaderBuilder::new(wav).build().unwrap();
let spec = reader.get_pcm_specs();
assert_eq!(spec.num_samples, 240000);
assert_eq!(spec.sample_rate, 48000);
Expand All @@ -3203,7 +3203,7 @@ fn wav_32bit_float() {
#[test]
fn wav_64bit_float() {
let wav = include_bytes!("./resources/Sine440Hz_1ch_48000Hz_64FP.wav");
let reader = PcmReader::new(wav).unwrap();
let reader = PcmReaderBuilder::new(wav).build().unwrap();
let spec = reader.get_pcm_specs();
assert_eq!(spec.num_samples, 240000);
assert_eq!(spec.sample_rate, 48000);
Expand All @@ -3220,7 +3220,7 @@ fn wav_64bit_float() {
#[test]
fn aiff_16bit() {
let aiff = include_bytes!("./resources/Sine440Hz_1ch_48000Hz_16.aif");
let reader = PcmReader::new(aiff).unwrap();
let reader = PcmReaderBuilder::new(aiff).build().unwrap();
let spec = reader.get_pcm_specs();
assert_eq!(spec.num_samples, 240000);
assert_eq!(spec.sample_rate, 48000);
Expand All @@ -3241,7 +3241,7 @@ fn aiff_16bit() {
#[test]
fn aiff_24bit() {
let aiff = include_bytes!("./resources/Sine440Hz_1ch_48000Hz_24.aif");
let reader = PcmReader::new(aiff).unwrap();
let reader = PcmReaderBuilder::new(aiff).build().unwrap();
let spec = reader.get_pcm_specs();
assert_eq!(spec.num_samples, 240000);
assert_eq!(spec.sample_rate, 48000);
Expand All @@ -3258,7 +3258,7 @@ fn aiff_24bit() {
#[test]
fn aiff_32bit() {
let aiff = include_bytes!("./resources/Sine440Hz_1ch_48000Hz_32.aif");
let reader = PcmReader::new(aiff).unwrap();
let reader = PcmReaderBuilder::new(aiff).build().unwrap();
let spec = reader.get_pcm_specs();
assert_eq!(spec.num_samples, 240000);
assert_eq!(spec.sample_rate, 48000);
Expand All @@ -3275,7 +3275,7 @@ fn aiff_32bit() {
#[test]
fn aiff_32bit_float() {
let aiff = include_bytes!("./resources/Sine440Hz_1ch_48000Hz_32FP.aif");
let reader = PcmReader::new(aiff).unwrap();
let reader = PcmReaderBuilder::new(aiff).build().unwrap();
let spec = reader.get_pcm_specs();
assert_eq!(spec.num_samples, 240000);
assert_eq!(spec.sample_rate, 48000);
Expand All @@ -3292,7 +3292,7 @@ fn aiff_32bit_float() {
#[test]
fn aiff_64bit_float() {
let aiff = include_bytes!("./resources/Sine440Hz_1ch_48000Hz_64FP.aif");
let reader = PcmReader::new(aiff).unwrap();
let reader = PcmReaderBuilder::new(aiff).build().unwrap();
let spec = reader.get_pcm_specs();
assert_eq!(spec.num_samples, 240000);
assert_eq!(spec.sample_rate, 48000);
Expand Down

0 comments on commit 43e788d

Please sign in to comment.