Crates.io | x3 |
lib.rs | x3 |
version | 0.3.0 |
source | src |
created_at | 2019-03-06 02:35:03.976535 |
updated_at | 2020-09-28 06:16:47.510808 |
description | A CPU efficient audio encoder/decoder using the X3 codec. |
homepage | |
repository | https://github.com/psiphi75/x3-rust |
max_upload_size | |
id | 119038 |
size | 204,449 |
X3 is a simple and effective lossless audio compressor for low entropy sound. It is based on Shorten and has some of the features of FLAC but is designed specifically for use in underwater sound recording tags and buoys. It is much faster than FLAC, but does not acheive the compression ratio. The name comes from the compression factor that it usually achieves, i.e., 3 times. The algorithm is described in a paper in the Journal of the Acoustical Society of America 133:1387-1398, 2013.
This repository is a Rust port of the Matlab code from the original authors.
use x3::encodefile::wav_to_x3a;
use x3::decodefile::x3a_to_wav;
// Convert .wav to .x3a
wav_to_x3a("/path/to/input_file.x3a", "/path/to/output_file.wav").unwrap();
// Convert .x3a to .wav
x3a_to_wav("/path/to/input_file.wav", "/path/to/output_file.x3a").unwrap();
let wav: Vec<i16> = /* you need to add your wav data */;
// Can only handle signed 16 bit data with one channel.
let params = x3::Parameters::default();
let sample_rate = 44100;
let num_samples = wav.len();
// Create the channel data
let first_channel = x3::Channel::new(0, &wav, sample_rate, params);
// Create the output data
let x3_len = num_samples * 2;
let mut x3_out = vec![0u8; x3_len];
let bp = &mut BitPacker::new(&mut x3_out); // Packer where x3 compressed data is stored.
encoder::encode(&[&first_channel], bp).unwrap();
// Get the bytes
let x3_bytes = bp.as_bytes().unwrap();
Building the package will create the x3
binary executable. You can convert files
to/from x3a/wav.
Example:
# Convert from x3a to wav
./x3 --input /path/to/file.x3a --output /path/to/file.wav
# Convert from wav to x3a
./x3 --input /path/to/file.wav --output /path/to/file.x3a
The following items need to be worked on:
#![no_std]
option for embedded devices.Rust implementation of the X3 lossless audio compression protocol.
Copyright (C) 2019 Simon M. Werner simonwerner@gmail.com
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, see https://www.gnu.org/licenses.