Expose PCM data in Rust

This commit is contained in:
Rob Watson 2020-09-06 00:02:19 +02:00
parent a794e7fd28
commit 981426b681
2 changed files with 5 additions and 1 deletions

View File

@ -22,4 +22,5 @@ version = "0.3.44"
features = [ features = [
"console", "console",
"AudioContext", "AudioContext",
"AudioBuffer",
] ]

View File

@ -64,7 +64,10 @@ impl Agent for AudioAgent {
} }
} }
Msg::AudioDecoded(samples) => { Msg::AudioDecoded(samples) => {
ConsoleService::log(&format!("Success decoding: {:?}", samples)); let audio_buffer = web_sys::AudioBuffer::from(samples);
let data = audio_buffer.get_channel_data(0).unwrap(); // TODO: error handling
let vec: Vec<f32> = data.to_vec();
ConsoleService::log(&format!("Success decoding: {:?}", vec));
} }
Msg::AudioDecodingFailed(err) => { Msg::AudioDecodingFailed(err) => {
ConsoleService::error(&format!("Error decoding: {:?}", err)); ConsoleService::error(&format!("Error decoding: {:?}", err));