aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatarLarge Libravatar /dev/urandom <johnfkennedymaili2p>2025-02-15 05:09:20 +0100
committerLibravatarLarge Libravatar /dev/urandom <johnfkennedymaili2p>2025-02-15 05:09:20 +0100
commit34cde2ac630270591c071bb452e59de430a8f606 (patch)
tree3f231b58bd3ff240944db3cc7999c3affb35ef7c /src
parente398b9b012d3894eb6013a324336eb91c396c045 (diff)
downloadcosin25-invite-mountainbytes-34cde2ac630270591c071bb452e59de430a8f606.tar.gz
cosin25-invite-mountainbytes-34cde2ac630270591c071bb452e59de430a8f606.tar.bz2
cosin25-invite-mountainbytes-34cde2ac630270591c071bb452e59de430a8f606.tar.lz
cosin25-invite-mountainbytes-34cde2ac630270591c071bb452e59de430a8f606.zip

feat: working audio again

Diffstat (limited to 'src')
-rw-r--r--src/main.rs55
-rw-r--r--src/music.rs32
2 files changed, 44 insertions, 43 deletions
diff --git a/src/main.rs b/src/main.rs
index 714d540..24dcf8d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -27,33 +27,34 @@ pub fn main() {
let sdl_context = sdl2::init().unwrap();
#[cfg(all(feature = "music", not(feature = "32k")))]
- {
- let audio_subsystem = sdl_context.audio().unwrap();
-
- let desired_spec = AudioSpecDesired {
- freq: Some(48_000),
- #[cfg(feature = "stereo")]
- channels: Some(2),
- #[cfg(not(feature = "stereo"))]
- channels: Some(1),
- samples: Some(8192 as u16),
- };
-
- let device = audio_subsystem
- .open_playback(None, &desired_spec, |spec| {
- // initialize the audio callback
- Music {
- offset: 0,
- pcm: mmc2r_to_pcm(
- &mut MmC2r::new(include_bytes!("../uwudhd.mod"), spec.freq as isize).unwrap(),
- ),
- }
- })
- .unwrap();
-
- // Start playback
- device.resume();
- }
+ let audio_subsystem = sdl_context.audio().unwrap();
+
+ #[cfg(all(feature = "music", not(feature = "32k")))]
+ let desired_spec = AudioSpecDesired {
+ freq: Some(48_000),
+ #[cfg(feature = "stereo")]
+ channels: Some(2),
+ #[cfg(not(feature = "stereo"))]
+ channels: Some(1),
+ samples: Some(8192 as u16),
+ };
+
+ #[cfg(all(feature = "music", not(feature = "32k")))]
+ let device = audio_subsystem
+ .open_playback(None, &desired_spec, |spec| {
+ // initialize the audio callback
+ Music {
+ offset: 0,
+ pcm: mmc2r_to_pcm(
+ &mut MmC2r::new(include_bytes!("../uwudhd.mod"), spec.freq as isize).unwrap(),
+ ),
+ }
+ })
+ .unwrap();
+
+ // Start playback
+ #[cfg(all(feature = "music", not(feature = "32k")))]
+ device.resume();
let video_subsystem = sdl_context.video().unwrap();
diff --git a/src/music.rs b/src/music.rs
index 5a33d84..888de77 100644
--- a/src/music.rs
+++ b/src/music.rs
@@ -38,22 +38,22 @@ pub fn mmc2r_to_pcm(state: &mut MmC2r) -> Vec<i16> {
destination.push(sample);
}
}
- // #[cfg(not(feature = "stereo"))]
- // let destination = {
- // let stereo = destination;
- // let mut mono = Vec::<i16>::new();
- // let mut is_first_stereo_pair = true;
- // let mut stereo_pair_val = 0 as i16;
- // for sample in stereo {
- // if is_first_stereo_pair {
- // stereo_pair_val = sample;
- // } else {
- // mono.push(((sample as i32 + stereo_pair_val as i32) / 2) as i16);
- // }
- // is_first_stereo_pair = !is_first_stereo_pair;
- // }
- // mono
- // };
+ #[cfg(not(feature = "stereo"))]
+ let destination = {
+ let stereo = destination;
+ let mut mono = Vec::<i16>::new();
+ let mut is_first_stereo_pair = true;
+ let mut stereo_pair_val = 0 as i16;
+ for sample in stereo {
+ if is_first_stereo_pair {
+ stereo_pair_val = sample;
+ } else {
+ mono.push(((sample as i32 + stereo_pair_val as i32) / 2) as i16);
+ }
+ is_first_stereo_pair = !is_first_stereo_pair;
+ }
+ mono
+ };
destination
}