Skip to content

Commit

Permalink
0.3.1 Update
Browse files Browse the repository at this point in the history
Added support for the ot_random argument for creating single sample chain by selecting random samples within a specified folder.
  • Loading branch information
Icaro Ferre committed Jul 29, 2020
1 parent c5f4786 commit 258d6d3
Show file tree
Hide file tree
Showing 177 changed files with 125 additions and 327 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ If more than 64 samples are found within that folder then multiple OT files will

It's also possible to only generate the Octatrack OT file based on the original samples contained inside the specified ```--folder``` by using the ```--ot_file only``` argument.

The ```--ot_random true``` argument can be used to generate a single chain (concatenated wav + ot file for the Octatrack) using 64 samples randomly picked from the folder specified in the ```--folder``` argument. AudioHit will make sure not to pick the same file more than once.

## Roadmap / To-Do

Expand Down
77 changes: 74 additions & 3 deletions code/Cargo.lock

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

5 changes: 4 additions & 1 deletion code/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
name = "audiohit"
version = "0.3.0"
authors = ["Icaro Ferre"]
edition = "2018"



[dependencies]
ot_utils = {github = "https://github.com/icaroferre/ot_utils", version = "0.1.2" }
decibel = {github = "https://github.com/Digipom/decibel", version="0.1.2"}
hound = {github = "https://github.com/ruuda/hound/", version="3.4.0"}
argparse = {github = "http://github.com/tailhook/rust-argparse", version="0.2.1"}
stopwatch = {github = "https://github.com/ellisonch/rust-stopwatch", version="0.0.7"}
stopwatch = {github = "https://github.com/ellisonch/rust-stopwatch", version="0.0.7"}
rand = {github = "https://github.com/rust-random/rand", version="0.7.3"}
60 changes: 44 additions & 16 deletions code/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use std::fs;
use decibel::{AmplitudeRatio, DecibelRatio};
use argparse::{ArgumentParser, Store};
use stopwatch::{Stopwatch};
use rand::Rng;


extern crate argparse;
extern crate hound;
Expand All @@ -33,7 +35,7 @@ fn stof(s:&str) -> f32 {

fn main() {
//Version number
let versionnumber = "0.3";
let versionnumber = "0.3.1";

// Set default preset
let default = getpreset(0);
Expand All @@ -48,6 +50,7 @@ fn main() {
let mut fade_out_ms = default.1;
let mut thresh_db = default.2;
let mut ot_file = "".to_string();
let mut ot_random = "".to_string();

{ // Get variable values from arguments
let mut ap = ArgumentParser::new();
Expand All @@ -70,6 +73,9 @@ fn main() {
ap.refer(&mut ot_file)
.add_option(&["--ot_file"], Store,
"Concatenate samples and generate Octatrack .ot file (true / false)");
ap.refer(&mut ot_random)
.add_option(&["--ot_random"], Store,
"If true, only 1 sample chain will be generated and 64 samples will be chosen randomly");
ap.parse_args_or_exit();
}

Expand All @@ -84,16 +90,6 @@ fn main() {

let mut OT_Slicer = Slicer::new();


let spec = hound::WavSpec {
channels: 1,
sample_rate: 44100,
bits_per_sample: 16,
sample_format: hound::SampleFormat::Int,
};



// Single file processing
if filename != "0" {
let check_file: &Path = &filename.as_ref();
Expand All @@ -116,11 +112,11 @@ fn main() {
let extra_folders = find_sub_folders(&folder_path);

for folder in extra_folders {
processed_files += process_folder(&folder, &mut OT_Slicer, &ot_file, &fade_in_ms, &fade_out_ms, &thresh_db);
processed_files += process_folder(&folder, &mut OT_Slicer, &ot_file, &fade_in_ms, &fade_out_ms, &thresh_db, ot_random.clone());
}

// Process files found in main folder
processed_files += process_folder(&folder_path, &mut OT_Slicer, &ot_file, &fade_in_ms, &fade_out_ms, &thresh_db);
processed_files += process_folder(&folder_path, &mut OT_Slicer, &ot_file, &fade_in_ms, &fade_out_ms, &thresh_db, ot_random.clone());


}
Expand Down Expand Up @@ -318,9 +314,14 @@ fn createdir(dir:String) -> String {
dir
}

fn process_folder(folder_path:&String, OT_Slicer: &mut Slicer, ot_file: &String, fade_in_ms: &String, fade_out_ms: &String, thresh_db: &String) -> u16 {
fn process_folder(folder_path:&String, OT_Slicer: &mut Slicer, ot_file: &String, fade_in_ms: &String, fade_out_ms: &String, thresh_db: &String, ot_random: String) -> u16 {
let check_file: &Path = &folder_path.as_ref();
let mut processed_files : u16 = 0;
let mut random_files: bool = false;

if ot_random == "true".to_string() {
random_files = true;
}
// Validate directory
if check_file.is_dir() {

Expand Down Expand Up @@ -362,7 +363,14 @@ fn process_folder(folder_path:&String, OT_Slicer: &mut Slicer, ot_file: &String
// While 64 should be the theoretical max, we must do 32 at the time so the OT checksum doesn't overflow

let octatrack_max_files = 64;
let num_octa_files = ((valid_files.len() as f64 / octatrack_max_files as f64) as f64).ceil() as isize;
let mut num_octa_files = ((valid_files.len() as f64 / octatrack_max_files as f64) as f64).ceil() as isize;

if random_files {
num_octa_files = 1;
};

let mut selected_files : Vec<usize> = Vec::new();

println!("Number of Octatrack OT files: {}", num_octa_files);

for i in 0..num_octa_files {
Expand All @@ -388,9 +396,29 @@ fn process_folder(folder_path:&String, OT_Slicer: &mut Slicer, ot_file: &String
OT_Slicer.output_filename.push_str(suffix.as_str());
max_files = octatrack_max_files;
}

if random_files {
max_files = octatrack_max_files;
}

for file in 0..max_files {
let file_pos = file + (i * max_files as isize) as usize;
let mut file_pos : usize = file + (i * max_files as isize) as usize;

// Set file position to a random file that hasn't been picked yet
if random_files {
let mut rng = rand::thread_rng();
let mut found_valid_file: bool = false;
while found_valid_file == false {
let random_file = rng.gen_range(0, valid_files.len()); // Get random position
if selected_files.contains(&random_file) == false { // Check if has been picked before
file_pos = random_file.clone(); // Set file position to the random value
println!("Randomly selected file #{} ({} / 64)", random_file, file + 1);
selected_files.push(random_file); // Add random value to list of already picked values
found_valid_file = true; // Exit loop
}
}
}

if file_pos < valid_files.len() {
let file = &valid_files[file_pos];
println!("Processing file {}: {}", file_pos, file.display());
Expand Down
2 changes: 1 addition & 1 deletion code/target/rls/.rustc_info.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"rustc_fingerprint":10213109719584352265,"outputs":{"4476964694761187371":["___\nlib___.rlib\nlib___.dylib\nlib___.dylib\nlib___.a\nlib___.dylib\n/Users/icaroferre/.rustup/toolchains/stable-x86_64-apple-darwin\ndebug_assertions\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_feature=\"sse3\"\ntarget_feature=\"ssse3\"\ntarget_os=\"macos\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"apple\"\nunix\n",""],"1164083562126845933":["rustc 1.44.0 (49cae5576 2020-06-01)\nbinary: rustc\ncommit-hash: 49cae55760da0a43428eba73abcb659bb70cf2e4\ncommit-date: 2020-06-01\nhost: x86_64-apple-darwin\nrelease: 1.44.0\nLLVM version: 9.0\n",""]},"successes":{}}
{"rustc_fingerprint":10213109719584352265,"outputs":{"1164083562126845933":["rustc 1.44.0 (49cae5576 2020-06-01)\nbinary: rustc\ncommit-hash: 49cae55760da0a43428eba73abcb659bb70cf2e4\ncommit-date: 2020-06-01\nhost: x86_64-apple-darwin\nrelease: 1.44.0\nLLVM version: 9.0\n",""],"4476964694761187371":["___\nlib___.rlib\nlib___.dylib\nlib___.dylib\nlib___.a\nlib___.dylib\n/Users/icaroferre/.rustup/toolchains/stable-x86_64-apple-darwin\ndebug_assertions\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_feature=\"sse3\"\ntarget_feature=\"ssse3\"\ntarget_os=\"macos\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"apple\"\nunix\n",""]},"successes":{}}
Empty file removed code/target/rls/debug/.cargo-lock
Empty file.
Empty file.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

Empty file.

This file was deleted.

This file was deleted.

This file was deleted.

Empty file.

This file was deleted.

This file was deleted.

This file was deleted.

Empty file.

This file was deleted.

This file was deleted.

This file was deleted.

Empty file.

This file was deleted.

Loading

0 comments on commit 258d6d3

Please sign in to comment.