From 33c093e9d00ea92e70af652f22f66bc32e9fb184 Mon Sep 17 00:00:00 2001 From: Rafal Mielniczuk Date: Wed, 2 Oct 2024 23:35:21 +0100 Subject: [PATCH] Add midi player Converts to wav form and sends to sound-daemon doom lvl 1 midi file provided. --- Cargo.lock | 52 ++++-- Makefile | 2 +- disk-scripts/install_os.sh | 4 +- sysroot/assets/D_E1M1.mid | Bin 0 -> 23322 bytes userspace/Cargo.lock | 93 ++++++++++- userspace/Cargo.toml | 2 +- userspace/playaudio/Cargo.toml | 26 +++ userspace/playaudio/src/playmidi/bin/main.rs | 85 ++++++++++ userspace/playaudio/src/playwav/bin/main.rs | 56 +++++++ userspace/playwav/Cargo.toml | 10 -- userspace/playwav/src/main.rs | 158 ------------------ .../sound-daemon/src/sound-daemon/bin/main.rs | 8 +- 12 files changed, 306 insertions(+), 190 deletions(-) create mode 100644 sysroot/assets/D_E1M1.mid create mode 100644 userspace/playaudio/Cargo.toml create mode 100644 userspace/playaudio/src/playmidi/bin/main.rs create mode 100644 userspace/playaudio/src/playwav/bin/main.rs delete mode 100644 userspace/playwav/Cargo.toml delete mode 100644 userspace/playwav/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index ca28d292..016c3f08 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -32,9 +32,9 @@ checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "autocfg" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "bit_field" @@ -85,7 +85,7 @@ dependencies = [ "bitmaps", "chrono", "downcast-rs", - "hashbrown", + "hashbrown 0.15.0", "intrusive-collections", "lazy_static", "linked_list_allocator", @@ -106,6 +106,18 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "foldhash" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" + [[package]] name = "hashbrown" version = "0.14.5" @@ -116,6 +128,17 @@ dependencies = [ "allocator-api2", ] +[[package]] +name = "hashbrown" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash", +] + [[package]] name = "intrusive-collections" version = "0.9.7" @@ -159,7 +182,7 @@ version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37ee39891760e7d94734f6f63fedc29a2e4a152f836120753a72503f09fcf904" dependencies = [ - "hashbrown", + "hashbrown 0.14.5", ] [[package]] @@ -182,9 +205,12 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "82881c4be219ab5faaf2ad5e5e5ecdff8c66bd7402ca3160975c93b24961afd1" +dependencies = [ + "portable-atomic", +] [[package]] name = "paste" @@ -192,6 +218,12 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" +[[package]] +name = "portable-atomic" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2" + [[package]] name = "ppv-lite86" version = "0.2.20" @@ -247,9 +279,9 @@ checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" [[package]] name = "raw-cpuid" -version = "11.1.0" +version = "11.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb9ee317cfe3fbd54b36a511efc1edd42e216903c9cd575e686dd68a2ba90d8d" +checksum = "1ab240315c661615f2ee9f0f2cd32d5a7343a84d5ebcccb99d46e6637565e7b0" dependencies = [ "bitflags", ] @@ -280,9 +312,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.77" +version = "2.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" dependencies = [ "proc-macro2", "quote", diff --git a/Makefile b/Makefile index 0912faa2..f5b3a67b 100644 --- a/Makefile +++ b/Makefile @@ -85,7 +85,7 @@ endif debug: $(disk) #qemu-system-x86_64 -drive format=raw,file=$(iso) -serial stdio -no-reboot -s -S -smp cpus=4 -no-shutdown -netdev tap,helper=/usr/lib/qemu/qemu-bridge-helper,id=ck_net0 -device e1000,netdev=ck_net0,id=ck_nic0 #qemu-system-x86_64 -serial stdio -no-reboot -s -S -m 5811 -smp cpus=4 -no-shutdown -netdev user,id=mynet0,net=192.168.1.0/24,dhcpstart=192.168.1.128,hostfwd=tcp::4444-:80 -device e1000e,netdev=mynet0,id=ck_nic0 -drive format=raw,file=disk.img,if=none,id=test-img -device ich9-ahci,id=ahci -device ide-hd,drive=test-img,bus=ahci.0 -monitor /dev/stdout - qemu-system-x86_64 -serial stdio -no-reboot -s -S -m 5811 -smp cpus=4 -no-shutdown -netdev tap,helper=/usr/lib/qemu/qemu-bridge-helper,id=hn0 -device e1000,netdev=hn0,id=nic1 -drive format=raw,file=disk.img,if=none,id=test-img -device ich9-ahci,id=ahci -device ide-hd,drive=test-img,bus=ahci.0 -audio driver=pipewire,model=hda -monitor /dev/stdout -enable-kvm + qemu-system-x86_64 -serial stdio -no-reboot -s -S -m 5811 -smp cpus=4 -no-shutdown -netdev tap,helper=/usr/lib/qemu/qemu-bridge-helper,id=hn0 -device e1000,netdev=hn0,id=nic1 -drive format=raw,file=disk.img,if=none,id=test-img -device ich9-ahci,id=ahci -device ide-hd,drive=test-img,bus=ahci.0 -audio driver=pipewire,model=hda -monitor /dev/stdout gdb: @rust-gdb "$(kernel)" -ex "target remote :1234" diff --git a/disk-scripts/install_os.sh b/disk-scripts/install_os.sh index 426ca893..ebdfc222 100755 --- a/disk-scripts/install_os.sh +++ b/disk-scripts/install_os.sh @@ -32,7 +32,7 @@ fi sudo umount mnt PROGS="test testcpp hello stack nyancat ttytest fork poweroff stat fbdoom doom1.wad open_sleep" -RUST_PROGS="init shell mount umount unixsocket-server unixsocket-client forktest mprotecttest playwav threads sound-daemon" +RUST_PROGS="init shell mount umount unixsocket-server unixsocket-client forktest mprotecttest playwav playmidi threads sound-daemon" sudo mount /dev/loop0p2 mnt sudo chown -R $USER:$USER mnt @@ -47,6 +47,8 @@ for prog in $RUST_PROGS; do done cp sysroot/assets/imperial.wav mnt/ +cp sysroot/assets/D_E1M1.mid mnt/ +cp sysroot/assets/FluidR3_GM.sf2 mnt/ rsync -a sysroot/cykusz/usr mnt/ rsync -a sysroot/cykusz/etc mnt/ diff --git a/sysroot/assets/D_E1M1.mid b/sysroot/assets/D_E1M1.mid new file mode 100644 index 0000000000000000000000000000000000000000..bfd6eb116edb2d6c44325bc285a60f47e88ecc78 GIT binary patch literal 23322 zcmdU%%W_;ta)wWL<4#f{K}U=iV@J@U6s<)A0zd#l02G^mAP^!cYBVE_ER8l}QoJDm z0u*(%!hm+%o#w9JVrF*U+1~jrs3#eJe`aN$(~ZWBl4imS!~wdiDzmb(GXKi@4{rYM z-t8>QhWM#u@7(;|&ciJGbRhe$f6o3id^`Ko*gtlj|NT$dpZVy|WA{4G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DC-}jC51#F4alamVTl^zl z_C0SJzqZ5G=lv_y+|n3{2W;{E=it}M?xpfS6RdMGe(f1?%DVWq%Lnjlmo+xnsGDC4@2`tr3lFvr zzqWZyey!}^pIf+amA2=#5o4*U*#jiE~axQ)?{9>JR zihH=Da9QlDhzr4E2`rV~A2^aTwx;?cJdMc3$Kls<#@sIRTf6zS38U%Em-0L3OJS`e__YN_JDOiR#~J7( z{94CqcJD;LZhoy}G{avVJi_|<-JJ1jb@uG$*G_ldg%Ykgm|x3z3VDHngI}w&kL2y= z*YZA?=~wV;{eR0`I)Y!Td%2VHYl#cT;Ma=t8NP8Czc%rt;TCfzS6cgn`L%vGSLW9W zs}1kt*Yf{yo^|tUtya+D9r47k6=uk=oAYbesI9ERQCcNFF2hmcDL#|&Ysrb?GdaHq zer=i8!+R>mS6blyOuV9n&;1>SIrvC=r(}*hKj}OJzm;b`15Zc3GYLhf1S+!5AU~Sr2qf` literal 0 HcmV?d00001 diff --git a/userspace/Cargo.lock b/userspace/Cargo.lock index 54401ad5..240b3196 100644 --- a/userspace/Cargo.lock +++ b/userspace/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "autocfg" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "bitflags" @@ -14,6 +14,12 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +[[package]] +name = "bytemuck" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94bbb0ad554ad961ddc5da507a12a29b14e4ae5bda06b19f575a3e6079d2e2ae" + [[package]] name = "chrono" version = "0.4.38" @@ -54,13 +60,45 @@ dependencies = [ ] [[package]] -name = "playwav" +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + +[[package]] +name = "playaudio" version = "0.1.0" dependencies = [ + "rustysynth", "syscall-defs", "syscall-user", + "wavers", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", ] +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustysynth" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bff572eb558d73c5f5e0fd82c19dd82bb010234d2a65d54f52e93da5856241c7" + [[package]] name = "shell" version = "0.1.0" @@ -78,6 +116,17 @@ dependencies = [ "syscall-user", ] +[[package]] +name = "syn" +version = "2.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "syscall-defs" version = "0.1.0" @@ -101,6 +150,26 @@ dependencies = [ "syscall-user", ] +[[package]] +name = "thiserror" +version = "1.0.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "umount" version = "0.1.0" @@ -109,6 +178,12 @@ dependencies = [ "syscall-user", ] +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + [[package]] name = "unixsockets" version = "0.1.0" @@ -116,3 +191,15 @@ dependencies = [ "syscall-defs", "syscall-user", ] + +[[package]] +name = "wavers" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab501e9e5b13446d3a6e846de0c190c96b85ca3eced3bd00460edc67654500c8" +dependencies = [ + "bytemuck", + "num-traits", + "paste", + "thiserror", +] diff --git a/userspace/Cargo.toml b/userspace/Cargo.toml index 07a668d1..64579ce7 100644 --- a/userspace/Cargo.toml +++ b/userspace/Cargo.toml @@ -1,3 +1,3 @@ [workspace] resolver = "2" -members = ["init", "shell", "mount", "umount", "syscall-user", "unixsockets", "testprogs", "playwav", "sound-daemon"] \ No newline at end of file +members = ["init", "shell", "mount", "umount", "syscall-user", "unixsockets", "testprogs", "playaudio", "sound-daemon"] \ No newline at end of file diff --git a/userspace/playaudio/Cargo.toml b/userspace/playaudio/Cargo.toml new file mode 100644 index 00000000..e9eb5238 --- /dev/null +++ b/userspace/playaudio/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "playaudio" +version = "0.1.0" +edition = "2021" + +[[bin]] +name = "playwav" +test = false +bench = false +path = "src/playwav/bin/main.rs" + +[[bin]] +name = "playmidi" +test = false +bench = false +path = "src/playmidi/bin/main.rs" + +[dependencies] +rustysynth = "*" +wavers = "*" + +[dependencies.syscall-defs] +path = "../../syscall-defs" + +[dependencies.syscall-user] +path = "../syscall-user" diff --git a/userspace/playaudio/src/playmidi/bin/main.rs b/userspace/playaudio/src/playmidi/bin/main.rs new file mode 100644 index 00000000..62702f4d --- /dev/null +++ b/userspace/playaudio/src/playmidi/bin/main.rs @@ -0,0 +1,85 @@ +use rustysynth::{MidiFile, MidiFileSequencer, SoundFont, Synthesizer, SynthesizerSettings}; +use std::fs::File; +use std::io::Write; +use std::os::unix::net::UnixStream; +use std::process::ExitCode; +use std::sync::Arc; +use wavers::Samples; + +fn main() -> Result<(), ExitCode> { + let mut args = std::env::args(); + + if args.len() < 3 { + println!("Usage: playmidi "); + return Err(ExitCode::FAILURE); + } + args.next(); + + let soundfont_path = args.next().unwrap(); + let midi_path = args.next().unwrap(); + + println!("soundfont: {soundfont_path}, midi: {midi_path}"); + + let mut sf2 = File::open(soundfont_path).unwrap(); + let sound_font = Arc::new(SoundFont::new(&mut sf2).unwrap()); + + println!("Creating sequencer..."); + + // Create the MIDI file sequencer. + let settings = SynthesizerSettings::new(44100); + let synthesizer = Synthesizer::new(&sound_font, &settings).unwrap(); + let mut sequencer = MidiFileSequencer::new(synthesizer); + + println!("Loading midi..."); + + // Load the MIDI file. + let mut mid = File::open(midi_path).unwrap(); + let midi_file = Arc::new(MidiFile::new(&mut mid).unwrap()); + + println!("Sequencer play..."); + + sequencer.play(&midi_file, false); + + // The output buffer. + let sample_count = (settings.sample_rate as f64 * midi_file.get_length()) as usize; + let mut left: Vec = vec![0_f32; sample_count]; + let mut right: Vec = vec![0_f32; sample_count]; + + println!("Render waveform {} {}", left.len(), right.len()); + + // Render the waveform. + sequencer.render(&mut left, &mut right); + + println!("Convert..."); + + let left: Samples = wavers::Samples::from(left).convert(); + let right: Samples = wavers::Samples::from(right).convert(); + + println!("Collect..."); + + let both = left + .iter() + .zip(right.iter()) + .map(|(a, b)| (*a, *b)) + .collect::>(); + + println!("Send..."); + + let mut socket = UnixStream::connect("/sound-daemon.pid").map_err(|_e| ExitCode::from(3))?; + + let buf = unsafe { std::slice::from_raw_parts(both.as_ptr() as *const u8, both.len() * 4) }; + + let mut written = 0; + loop { + let n = socket + .write(&buf[written..]) + .map_err(|_e| ExitCode::from(4))?; + written += n; + if written == buf.len() { + break; + } + } + println!("write finished"); + + Ok(()) +} diff --git a/userspace/playaudio/src/playwav/bin/main.rs b/userspace/playaudio/src/playwav/bin/main.rs new file mode 100644 index 00000000..82b0a5cf --- /dev/null +++ b/userspace/playaudio/src/playwav/bin/main.rs @@ -0,0 +1,56 @@ +#![feature(seek_stream_len)] +#![feature(raw_ref_op)] + +use std::io::{Seek, Write}; +use std::os::fd::AsRawFd; +use std::os::unix::net::UnixStream; +use std::process::ExitCode; +use std::ptr::slice_from_raw_parts; +use syscall_defs::{MMapFlags, MMapProt}; + +fn send_to_daemon(song: &str) -> Result<(), ExitCode> { + let mut wav = std::fs::File::open(song).map_err(|_e| ExitCode::from(1))?; + let wav_size = wav.stream_len().map_err(|_e| ExitCode::from(2))? as usize; + + let wav_map = syscall_user::mmap( + None, + wav_size, + MMapProt::PROT_READ, + MMapFlags::MAP_PRIVATE, + Some(wav.as_raw_fd() as usize), + 0, + ) + .map_err(|_e| ExitCode::from(1))?; + + let buf = unsafe { &*slice_from_raw_parts(wav_map as *const u8, wav_size) }; + + let mut socket = UnixStream::connect("/sound-daemon.pid").map_err(|_e| ExitCode::from(3))?; + + //println!("writing {} bytes", buf.len()); + let mut written = 0; + loop { + let n = socket + .write(&buf[written..]) + .map_err(|_e| ExitCode::from(4))?; + written += n; + if written == buf.len() { + break; + } + } + println!("write finished"); + + Ok(()) +} + +fn main() -> Result<(), ExitCode> { + let mut args = std::env::args(); + + if args.len() < 2 { + println!("Usage: playwav "); + return Err(ExitCode::from(1)); + } + args.next(); + + let file = args.next().unwrap(); + Ok(send_to_daemon(file.as_str())?) +} diff --git a/userspace/playwav/Cargo.toml b/userspace/playwav/Cargo.toml deleted file mode 100644 index ef11d9e2..00000000 --- a/userspace/playwav/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "playwav" -version = "0.1.0" -edition = "2021" - -[dependencies.syscall-defs] -path = "../../syscall-defs" - -[dependencies.syscall-user] -path = "../syscall-user" diff --git a/userspace/playwav/src/main.rs b/userspace/playwav/src/main.rs deleted file mode 100644 index eb56a968..00000000 --- a/userspace/playwav/src/main.rs +++ /dev/null @@ -1,158 +0,0 @@ -#![feature(seek_stream_len)] -#![feature(raw_ref_op)] - -use std::io::{Seek, Write}; -use std::os::fd::AsRawFd; -use std::os::unix::net::UnixStream; -use std::process::ExitCode; -use std::ptr::{slice_from_raw_parts, slice_from_raw_parts_mut}; -use syscall_defs::{MMapFlags, MMapProt}; - -fn play(song: &str) -> Result<(), ExitCode> { - let mut wav = std::fs::File::open(song).map_err(|_e| ExitCode::from(1))?; - - let wav_size = wav.stream_len().map_err(|_e| ExitCode::from(2))? as usize; - - let hda_dev = std::fs::File::open("/dev/hda").map_err(|_e| ExitCode::from(3))?; - - let hda_map = syscall_user::mmap( - None, - 2048 * 32 + 4096, - MMapProt::PROT_READ | MMapProt::PROT_WRITE, - MMapFlags::MAP_SHARED, - Some(hda_dev.as_raw_fd() as usize), - 0, - ) - .map_err(|_e| ExitCode::from(4))?; - - let wav_map = syscall_user::mmap( - None, - wav_size, - MMapProt::PROT_READ, - MMapFlags::MAP_PRIVATE, - Some(wav.as_raw_fd() as usize), - 0, - ) - .map_err(|_e| ExitCode::from(4))?; - - for addr in (wav_map..wav_map + wav_size).step_by(4096) { - let _ = unsafe { - // prefault to read the file into memory - (addr as *const u64).read_volatile() - }; - } - - //println!("file size: {}", wav_size); - - let get_current_hda_block = - || unsafe { (hda_map as *const u64).offset(4).read_volatile() as usize / 2048 }; - - let mut file_block = 0; - let buf_block_count = 32; - - let wav_data = unsafe { &*slice_from_raw_parts((wav_map + 44) as *const u8, wav_size - 44) }; - let hda_data = - unsafe { &mut *slice_from_raw_parts_mut((hda_map + 4096) as *mut u8, 2048 * 32) }; - - let mut wp_block = (get_current_hda_block() + 6) % buf_block_count; - - while file_block * 2048 < wav_data.len() { - let rem = wav_data.len() - (file_block * 2048); - - let chunk = std::cmp::min(rem, 2048); - - while ((get_current_hda_block() + 3) % buf_block_count) != wp_block { - // yield cpu for other tasks - let _ = syscall_user::yield_execution(); - } - - hda_data[wp_block * 2048..wp_block * 2048 + chunk] - .copy_from_slice(&wav_data[file_block * 2048..file_block * 2048 + chunk]); - - wp_block = (wp_block + 1) % buf_block_count; - file_block += 1; - } - - while get_current_hda_block() != wp_block { - // yield cpu for other tasks - let _ = syscall_user::yield_execution(); - } - - hda_data.fill(0); //silence - - Ok(()) -} - -fn send_to_daemon(song: &str) -> Result<(), ExitCode> { - let mut wav = std::fs::File::open(song).map_err(|_e| ExitCode::from(1))?; - let wav_size = wav.stream_len().map_err(|_e| ExitCode::from(2))? as usize; - - let wav_map = syscall_user::mmap( - None, - wav_size, - MMapProt::PROT_READ, - MMapFlags::MAP_PRIVATE, - Some(wav.as_raw_fd() as usize), - 0, - ) - .map_err(|_e| ExitCode::from(1))?; - - let buf = unsafe { &*slice_from_raw_parts(wav_map as *const u8, wav_size) }; - - let mut socket = UnixStream::connect("/sound-daemon.pid").map_err(|_e| ExitCode::from(3))?; - - //println!("writing {} bytes", buf.len()); - let mut written = 0; - loop { - let n = socket - .write(&buf[written..]) - .map_err(|_e| ExitCode::from(4))?; - written += n; - if written == buf.len() { - break; - } - } - println!("write finished"); - - Ok(()) -} - -fn main() -> Result<(), ExitCode> { - let mut args = std::env::args(); - - if args.len() < 2 { - println!("Usage: playwav [-d] "); - return Err(ExitCode::from(1)); - } - - args.next(); - let mut daemonize = false; - - let mut file = args.next().unwrap(); - if let Some(arg2) = args.next() { - if file == "-d" { - daemonize = true; - file = arg2; - } - } - - if !daemonize { - return Ok(send_to_daemon(file.as_str())?); - } - - let daemon = syscall_user::fork().expect("fork failed"); - - if daemon > 0 { - return Ok(()); - } - - let _sid = syscall_user::setsid().expect("setsid failed"); - - syscall_user::chdir("/").expect("chdir failed"); - - syscall_user::close(0).expect("close 0 faield"); - syscall_user::close(1).expect("close 1 faield"); - syscall_user::close(2).expect("close 2 faield"); - - Ok(play(file.as_str())?) -} diff --git a/userspace/sound-daemon/src/sound-daemon/bin/main.rs b/userspace/sound-daemon/src/sound-daemon/bin/main.rs index ce21e1d6..8105c3f4 100644 --- a/userspace/sound-daemon/src/sound-daemon/bin/main.rs +++ b/userspace/sound-daemon/src/sound-daemon/bin/main.rs @@ -38,9 +38,7 @@ impl SoundChunk { } fn as_bytes_mut(&mut self) -> &mut [u8; 2048] { - unsafe { - std::mem::transmute::<&mut [i16; 1024], &mut [u8; 2048]>(&mut self.0) - } + unsafe { std::mem::transmute::<&mut [i16; 1024], &mut [u8; 2048]>(&mut self.0) } } } @@ -190,9 +188,7 @@ fn sound_daemon() -> Result<(), ExitCode> { loop { let mut polls = output.poll_fds(); - if let Ok(res) = - syscall_user::poll(polls.as_mut_slice(), 0) - { + if let Ok(res) = syscall_user::poll(polls.as_mut_slice(), 0) { if res > 0 { for (id, ev) in polls.iter().enumerate() { if id == 0 && ev.revents.contains(PollEventFlags::READ) {