mirror of
https://github.com/Dingo-Shenanigans/ReSkate.git
synced 2026-10-17 19:47:08 +02:00
Sources - Local Files: add a folder of music from the setup page (MP3, M4A, AAC, Ogg, FLAC, WAV; up to 200 songs a folder, 12 folders). Names and covers come from the files' tags. Each folder is a tile in its own row. - Online Radio: find stations by name (radio-browser.info) or add a stream's address (MP3, AAC, .pls, .m3u; no HLS). Each station is a tile in its own row; the track name follows what the station sends. Up to 24. - Both are decoded by the library built into the DLL (SpotifyHelper), which now plays files and HTTP streams as well as a program's output, reads tags and embedded pictures, and accepts MPEG-2 ADTS from AAC stations. Sound - Five-band equaliser (60 Hz, 250 Hz, 1 kHz, 4 kHz, 12 kHz) and loudness levelling, applied to every source on its way into the game. - Loudness, the speakers option, the equaliser and levelling are now kept in music-settings.json between sessions. Setup page - Remade in the mod's own colours and type, with numbered steps per source. - Queue pinned to the right: now playing, the playlist's songs with covers, find, and press to jump. Spotify's own queue shows once signed in. - Cards for Local files and Online radio; equaliser and levelling under Sound. In game - MUSIC page in the menu: player and queue, sound settings, source status and a button for the setup page. - "Loading song..." notice in the corner for songs that take a moment, with a switch to hide it. Presses made while a song is loading no longer restart it. - The Spotify row is hidden when Spotify is not in use. - Console: "spotify ..." is now "music ..." (music, music setup, music gain, music through, music spotify client|login|logout). Logs - The music sources' working lines (traces, per-song and per-bind lines, librespot's own) are debug only; stack captures are skipped unless debug logging is on. Grind exits: the per-pop line is debug only too. - A "Pace:" line when the game takes the sound faster or slower than real time, to find why music sounds fast after tabbing back in. Chat filter - A run of digits is a number, not a word spelled with look-alikes: a race time such as 2:55.0 is no longer masked.
53 lines
2.3 KiB
Rust
53 lines
2.3 KiB
Rust
//! By hand: plays a stream for a while and says how much sound came of it.
|
|
//! cargo run --release --example decode -- run <program> <argument>...
|
|
//! cargo run --release --example decode -- file <path>
|
|
//! cargo run --release --example decode -- url <address> [seconds]
|
|
use std::ffi::{c_char, CStr, CString};
|
|
use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
|
|
|
|
static FRAMES: AtomicU64 = AtomicU64::new(0);
|
|
static RATE: AtomicU64 = AtomicU64::new(0);
|
|
static DONE: AtomicBool = AtomicBool::new(false);
|
|
|
|
extern "C" fn sound(_samples: *const f32, frames: u32, rate: u32) {
|
|
FRAMES.fetch_add(u64::from(frames), Ordering::Relaxed);
|
|
RATE.store(u64::from(rate), Ordering::Relaxed);
|
|
}
|
|
extern "C" fn ended(stream: u64, how: *const c_char) {
|
|
println!("stream {stream}: {}", unsafe { CStr::from_ptr(how) }.to_string_lossy());
|
|
DONE.store(true, Ordering::Relaxed);
|
|
}
|
|
extern "C" fn titled(_stream: u64, title: *const c_char) {
|
|
println!("playing: {}", unsafe { CStr::from_ptr(title) }.to_string_lossy());
|
|
}
|
|
|
|
fn main() {
|
|
let mut arguments = std::env::args().skip(1);
|
|
let how = arguments.next().expect("run, file or url");
|
|
let first = CString::new(arguments.next().expect("what to play")).unwrap();
|
|
let rest: Vec<String> = arguments.collect();
|
|
let mut seconds = 0u64;
|
|
let stream = match how.as_str() {
|
|
"run" => {
|
|
let rest = CString::new(rest.join("\n")).unwrap();
|
|
reskate_spotify::stream::reskate_stream_play(first.as_ptr(), rest.as_ptr(), sound, ended)
|
|
}
|
|
"file" => reskate_spotify::stream::reskate_stream_play_file(first.as_ptr(), sound, ended),
|
|
_ => {
|
|
seconds = rest.first().and_then(|text| text.parse().ok()).unwrap_or(8);
|
|
reskate_spotify::stream::reskate_stream_play_url(first.as_ptr(), sound, ended, titled)
|
|
}
|
|
};
|
|
println!("began stream {stream}");
|
|
let started = std::time::Instant::now();
|
|
while !DONE.load(Ordering::Relaxed) {
|
|
std::thread::sleep(std::time::Duration::from_millis(50));
|
|
if seconds > 0 && started.elapsed().as_secs() >= seconds {
|
|
reskate_spotify::stream::reskate_stream_stop();
|
|
seconds = 0;
|
|
}
|
|
}
|
|
let (frames, rate) = (FRAMES.load(Ordering::Relaxed), RATE.load(Ordering::Relaxed));
|
|
println!("{frames} frames at {rate} Hz: {:.1} s of sound", frames as f64 / rate.max(1) as f64);
|
|
}
|