Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for symphonia_decoder and some ci #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
51 changes: 51 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Rust CI

on:
pull_request:
push:
branches:
- master
- staging
- trying

jobs:
build_and_test:
name: Build and test
strategy:
matrix:
include:
# Currently used Rust version, same as in `rust-toolchain` file.
- os: ubuntu-latest
rust: 1.60.0

# Minimum Supported Rust Version = 1.56.0
#
- os: ubuntu-latest
rust: 1.56.0
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@master

- name: Install alsa
run: sudo apt install alsa libasound2-dev

- name: Install ${{ matrix.rust }}
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
override: true

- name: Cache rust cargo artifacts
uses: swatinem/rust-cache@v1

- name: check
uses: actions-rs/cargo@v1
with:
command: check
args: -p creek-core -p creek-decode-symphonia -p creek-encode-wav --tests --features decode-all

- name: tests
uses: actions-rs/cargo@v1
with:
command: test
args: -p creek-core -p creek-decode-symphonia -p creek-encode-wav
2 changes: 1 addition & 1 deletion core/src/read/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub struct DataBlock<T: Copy + Clone + Default + Send> {
}

impl<T: Copy + Clone + Default + Send> DataBlock<T> {
pub(crate) fn new(num_channels: usize, block_size: usize) -> Self {
pub fn new(num_channels: usize, block_size: usize) -> Self {
let mut block: Vec<Vec<T>> = Vec::with_capacity(num_channels);
for _ in 0..num_channels {
let mut data: Vec<T> = Vec::with_capacity(block_size);
Expand Down
3 changes: 3 additions & 0 deletions decode_symphonia/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ repository = "https://github.com/RustyDAW/creek"
creek-core = { version = "0.1", path = "../core" }
symphonia = "0.5"

[dev-dependencies]
float-cmp = "*"

[features]
#aac = [ "symphonia/aac" ]
#alac = [ "symphonia/alac" ]
Expand Down
112 changes: 100 additions & 12 deletions decode_symphonia/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,23 +341,24 @@ impl Drop for SymphoniaDecoder {
#[cfg(test)]
mod tests {
use super::*;
use float_cmp::*;

#[test]
fn decoder_new() {
let files = vec![
// file | num_channels | num_frames | sample_rate
("./test_files/wav_u8_mono.wav", 1, 1323000, Some(44100)),
("./test_files/wav_i16_mono.wav", 1, 1323000, Some(44100)),
("./test_files/wav_i24_mono.wav", 1, 1323000, Some(44100)),
("./test_files/wav_i32_mono.wav", 1, 1323000, Some(44100)),
("./test_files/wav_f32_mono.wav", 1, 1323000, Some(44100)),
("./test_files/wav_i24_stereo.wav", 2, 1323000, Some(44100)),
//"./test_files/ogg_mono.ogg",
//"./test_files/ogg_stereo.ogg",
//"./test_files/mp3_constant_mono.mp3",
//"./test_files/mp3_constant_stereo.mp3",
//"./test_files/mp3_variable_mono.mp3",
//"./test_files/mp3_variable_stereo.mp3",
("../test_files/wav_u8_mono.wav", 1, 1323000, Some(44100)),
("../test_files/wav_i16_mono.wav", 1, 1323000, Some(44100)),
("../test_files/wav_i24_mono.wav", 1, 1323000, Some(44100)),
("../test_files/wav_i32_mono.wav", 1, 1323000, Some(44100)),
("../test_files/wav_f32_mono.wav", 1, 1323000, Some(44100)),
("../test_files/wav_i24_stereo.wav", 2, 1323000, Some(44100)),
//"../test_files/ogg_mono.ogg",
//"../test_files/ogg_stereo.ogg",
//"../test_files/mp3_constant_mono.mp3",
//"../test_files/mp3_constant_stereo.mp3",
//"../test_files/mp3_variable_mono.mp3",
//"../test_files/mp3_variable_stereo.mp3",
];

for file in files {
Expand All @@ -376,4 +377,91 @@ mod tests {
}
}
}

#[test]
fn decode_first_frame() {
let block_size = 10;

let decoder =
SymphoniaDecoder::new("../test_files/wav_u8_mono.wav".into(), 0, block_size, ());


let (mut decoder, file_info) = decoder.unwrap();
println!("{:?}", file_info.num_frames);

let mut data_block = DataBlock::new(1, block_size);
unsafe {
decoder.decode(&mut data_block).unwrap();
}

let samples = &mut data_block.block[0];
assert_eq!(samples.len(), block_size);


let first_frame = [
0.0,
0.046875,
0.09375,
0.1484375,
0.1953125,
0.2421875,
0.2890625,
0.3359375,
0.3828125,
0.421875
];


for i in 0..samples.len() {
assert!(approx_eq!(f32, first_frame[i], samples[i], ulps = 2));
}

let second_frame = [
0.46875,
0.5078125,
0.5390625,
0.578125,
0.609375,
0.640625,
0.671875,
0.6953125,
0.71875,
0.7421875,
];

unsafe {
decoder.decode(&mut data_block).unwrap();
}

let samples = &mut data_block.block[0];
for i in 0..samples.len() {
assert!(approx_eq!(f32, second_frame[i], samples[i], ulps = 2));
}

let last_frame = [
-0.0625,
-0.046875,
-0.0234375,
-0.0078125,
0.015625,
0.03125,
0.046875,
0.0625,
0.078125,
0.0859375,
];

// Seek to last frame
decoder.seek(file_info.num_frames - 1 - block_size).unwrap();

unsafe {
decoder.decode(&mut data_block).unwrap();
}
let samples = &mut data_block.block[0];
for i in 0..samples.len() {
assert!(approx_eq!(f32, last_frame[i], samples[i], ulps = 2));
}

assert_eq!(decoder.current_frame, file_info.num_frames - 1);
}
}