MCPcopy Create free account
hub / github.com/Bloom-Engine/engine / parse_mp3

Function parse_mp3

native/shared/src/audio.rs:321–345  ·  view source on GitHub ↗
(data: &[u8])

Source from the content-addressed store, hash-verified

319/// Parse an MP3 file into SoundData.
320#[cfg(feature = "mp3")]
321pub fn parse_mp3(data: &[u8]) -> Option<SoundData> {
322 let mut decoder = minimp3::Decoder::new(std::io::Cursor::new(data));
323 let mut samples = Vec::new();
324 let mut sample_rate = 0u32;
325 let mut channels = 0u16;
326
327 loop {
328 match decoder.next_frame() {
329 Ok(frame) => {
330 if sample_rate == 0 {
331 sample_rate = frame.sample_rate as u32;
332 channels = frame.channels as u16;
333 }
334 for &s in &frame.data {
335 samples.push(s as f32 / 32768.0);
336 }
337 }
338 Err(minimp3::Error::Eof) => break,
339 Err(_) => return None,
340 }
341 }
342
343 if samples.is_empty() { return None; }
344 Some(SoundData { samples, sample_rate, channels })
345}
346
347/// Parse an OGG Vorbis file into SoundData.
348pub fn parse_ogg(data: &[u8]) -> Option<SoundData> {

Callers 15

bloom_load_soundFunction · 0.85
bloom_load_musicFunction · 0.85
bloom_stage_soundFunction · 0.85
bloom_load_soundFunction · 0.85
bloom_load_musicFunction · 0.85
bloom_stage_soundFunction · 0.85
bloom_load_soundFunction · 0.85
bloom_load_musicFunction · 0.85
bloom_stage_soundFunction · 0.85
bloom_load_soundFunction · 0.85
bloom_load_musicFunction · 0.85
bloom_stage_soundFunction · 0.85

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected