Parse an OGG Vorbis file into SoundData.
(data: &[u8])
| 346 | |
| 347 | /// Parse an OGG Vorbis file into SoundData. |
| 348 | pub fn parse_ogg(data: &[u8]) -> Option<SoundData> { |
| 349 | let cursor = std::io::Cursor::new(data); |
| 350 | let mut reader = lewton::inside_ogg::OggStreamReader::new(cursor).ok()?; |
| 351 | let sample_rate = reader.ident_hdr.audio_sample_rate; |
| 352 | let channels = reader.ident_hdr.audio_channels as u16; |
| 353 | let mut samples = Vec::new(); |
| 354 | |
| 355 | while let Ok(Some(packet)) = reader.read_dec_packet_itl() { |
| 356 | for &sample in &packet { |
| 357 | samples.push(sample as f32 / 32768.0); |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | if samples.is_empty() { return None; } |
| 362 | Some(SoundData { samples, sample_rate, channels }) |
| 363 | } |
no test coverage detected