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

Wavbrro format #64

Merged
merged 6 commits into from
Nov 3, 2023
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
160 changes: 160 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
"optimizer",
"prometheus-remote",
"tools",
"wavbrro",
]
resolver = "2"

Expand Down
2 changes: 1 addition & 1 deletion brro-compressor/src/utils/readers/bro_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::fs::File;
use std::io::{self, Error, Read};
use std::path::Path;

// Function to process a WAV file
// Function to process a BRRO file
fn process_bro_file(file_path: &Path) -> io::Result<Vec<u8>> {
let mut file = File::open(file_path)?;
let mut contents = Vec::new();
Expand Down
1 change: 1 addition & 0 deletions tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ description = "Tools for testing/supporting the development/validation of the co

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
wavbrro = { path = "../wavbrro" }
sysinfo = "0.29.0"
hound = "3.5"
chrono = "0.4.26"
Expand Down
12 changes: 12 additions & 0 deletions tools/src/bin/wav2wbro.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use wavbrro::wavbrro::WavBrro;
use log::debug;
//use clap::{arg, command, Parser};

fn main() {
env_logger::init();
//let arguments = Args::parse();
//debug!("{:?}", arguments);
debug!("Test, 1,23");
let mut wb = WavBrro::new();
wb.add_sample(34.1);
}
16 changes: 16 additions & 0 deletions wavbrro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "wavbrro"
version = "0.1.0"
authors = ["Carlos Rolo <[email protected]>"]
edition = "2021"
license = "Apache-2.0"
description = "An adaptation of the WAV format for use by the BRRO compressor"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
env_logger = "0.10.0"
cjrolo marked this conversation as resolved.
Show resolved Hide resolved
log = "0.4.0"
rkyv = { version = "0.7.42", features = ["validation"] }

[dev-dependencies]
env_logger = "0.10.0"
40 changes: 40 additions & 0 deletions wavbrro/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# WAVBRRO

**NOTE:** This needs some serious work!

WAVBRRO is a based on the WAV format to be used to store raw timeseries data.

## SPEC

The spec for WAVBRRO is the following:

Extension: .wbro

- Header, 12 Bytes
- 0..3 "WBRO"
- 4..7 Sample number (u32)
- 8..12 "WBRO"
- Internal Structure
- Sample number: u32
- Bitdepth: u8 [0 -> u8, 1 -> i16, 2 -> i32, 3 -> i64, 4 -> f32, 5 -> f64]
- Samples
- Blocks of 2048 samples

### Reading/Writting WAVBRRO

Check the tests in the `wavbrro.rs`

### What it doesn't support

WAVBRRO doesn't support the following bitdepths

- Windows OS
- Timestamps (VSRI will land here eventually)
- Anything other than f64
- Anything bigger than 64bit bitdepth

### Next steps

- Implement streaming read and write
- Seeking for a specific block
- Support other bitdepth
3 changes: 3 additions & 0 deletions wavbrro/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod wavbrro;
pub mod read;
pub mod write;
21 changes: 21 additions & 0 deletions wavbrro/src/read.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use std::io::{self, Read, Seek, SeekFrom};
use std::fs;
use std::fs::File;
use std::path::Path;

// Function to check if a file is a WAV file
pub fn is_wavbrro_file(file_path: &Path) -> bool {
// Open the file for reading and read the first 12 bytes (header) of the file
let mut file = fs::File::open(file_path).expect("Can't open file!");
let mut header = [0u8; 12];
file.read_exact(&mut header).expect("File is too small!");
&header[0..4] == b"WBRO" && &header[8..12] == b"WBRO"
}

pub fn read_wavbrro_file(file_path: &Path) -> io::Result<Vec<u8>> {
let mut file = File::open(file_path)?;
let mut contents = Vec::new();
file.seek(SeekFrom::Start(12))?;
file.read_to_end(&mut contents)?;
Ok(contents)
}
Loading