summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Barrett <tom@tombarrett.xyz>2020-03-04 09:11:08 -0600
committerTom Barrett <tom@tombarrett.xyz>2020-03-04 09:11:08 -0600
commitf57de5cd6075c071fe89bb7af898072b0a8daab6 (patch)
treea7bf31e5c791e5f0c4122f661b72a621ec3eff2b
parent7ef7e745c9be4d07dbfcc4e536709924c7c982d4 (diff)
compiles a semi optimized version always, sets up volume to be very low
-rw-r--r--Cargo.toml3
-rw-r--r--src/audio.rs8
-rw-r--r--src/constants.rs2
-rw-r--r--src/main.rs10
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::<Stereo<i16>, _>(&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();