Skip to content

Commit

Permalink
added audio and synchronisation
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBlueRuby committed Nov 1, 2022
1 parent 9ee2158 commit b074532
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Binary file added bad-apple-audio.mp3
Binary file not shown.
26 changes: 25 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
use std::{ fs };
use std::{fs, io::BufReader, thread, time::Duration};

use rodio::{source::Source, Decoder, OutputStream};

fn main() {
print!("\x1B[2J\x1B[1;1H");

let f = "ascii.txt";

let mut frame_raw = fs::read_to_string(f).expect("Error reading file!");
frame_raw = frame_raw.replace(".", " ");

let frames: Vec<&str> = frame_raw.split("SPLIT").collect();

let mut frame_num = 0;

let (_stream, audio_stream_handle) = OutputStream::try_default().unwrap();
let audio_file = BufReader::new(fs::File::open("bad-apple-audio.mp3").unwrap());
let audio_source = Decoder::new(audio_file).unwrap();
audio_stream_handle
.play_raw(audio_source.convert_samples())
.unwrap();

while frame_num <= 2180 {
print!("\x1b[1;1H"); //equiv to cls or clear
print!("{}", frames[frame_num]);

frame_num += 1;

thread::sleep(Duration::from_secs_f32(1.0 / 10.625));
}

print!("\x1B[2J\x1B[1;1H");
}

0 comments on commit b074532

Please sign in to comment.