From f57de5cd6075c071fe89bb7af898072b0a8daab6 Mon Sep 17 00:00:00 2001 From: Tom Barrett Date: Wed, 4 Mar 2020 09:11:08 -0600 Subject: compiles a semi optimized version always, sets up volume to be very low --- Cargo.toml | 3 +++ src/audio.rs | 8 +++++++- src/constants.rs | 2 ++ src/main.rs | 10 +++++----- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 96fc0cf..381f81e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,3 +10,6 @@ luminance-derive = "0.5.3" luminance-glfw = "0.12.1" alto = "3.0.4" lewton = "0.10.0" + +[profile.dev] +opt-level = 2 diff --git a/src/audio.rs b/src/audio.rs index bbc3a53..ac6bc12 100644 --- a/src/audio.rs +++ b/src/audio.rs @@ -2,6 +2,8 @@ use alto::{Alto, Stereo, StreamingSource}; use lewton::inside_ogg::OggStreamReader; use std::fs::File; +use crate::constants; + pub fn init() -> StreamingSource { let mut source = OggStreamReader::new(File::open("data/djbLUETOOTH.ogg").unwrap()).unwrap(); let alto = Alto::load_default().unwrap(); @@ -10,7 +12,11 @@ pub fn init() -> StreamingSource { let mut stream = audio_context.new_streaming_source().unwrap(); let sample_rate = source.ident_hdr.audio_sample_rate as i32; - while let Ok(Some(samples)) = source.read_dec_packet_itl() { + while let Ok(Some(mut samples)) = source.read_dec_packet_itl() { + samples = samples + .into_iter() + .map(|s| (s as f32 * constants::VOLUME) as i16) + .collect(); let audio_buffer = audio_context .new_buffer::, _>(&samples, sample_rate) .unwrap(); diff --git a/src/constants.rs b/src/constants.rs index cc26d4a..e981c8c 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -17,3 +17,5 @@ pub const C64_GREY: [u8; 3] = [119, 119, 119]; pub const C64_LIGHT_GREEN: [u8; 3] = [170, 255, 102]; pub const C64_LIGHT_BLUE: [u8; 3] = [0, 136, 255]; pub const C64_LIGHT_GREY: [u8; 3] = [187, 187, 187]; + +pub const VOLUME: f32 = 0.02; diff --git a/src/main.rs b/src/main.rs index 546628f..d81d45c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,10 @@ -pub mod audio; pub mod constants; +pub mod audio; +pub mod vertex; pub mod n1ck; pub mod tom; -pub mod vertex; +use alto::Source; use luminance::context::GraphicsContext; use luminance::pipeline::{PipelineState, Viewport}; use luminance::shader::program::Program; @@ -60,9 +61,8 @@ fn main() { .unwrap() .ignore_warnings(); - // only uncomment if building as release 'cargo run --release' - //let mut stream = audio::init(); - //stream.play(); + let mut stream = audio::init(); + stream.play(); let mut tom = Tom::new(); let mut n1ck = N1ck::new(); -- cgit v1.2.3