Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upUse block/chunk abstraction for processing; add gainnode #17
Conversation
|
I replaced the hashmap with a vec because there's no guaranteed order for hashmap iteration. When we add graph support we'll replace it with a petgraph graph. |
| debug_assert!(chunks.len() == 1); | ||
| let data = &mut chunks.blocks[0].data; | ||
| let data = data.as_mut_byte_slice().expect("casting failed"); | ||
| buffer.copy_from_slice(0, data).expect("copying failed"); |
This comment has been minimized.
This comment has been minimized.
sdroege
May 23, 2018
Contributor
This looks like a potentially unneeded copy. You can wrap a buffer around any AsRef<[u8]> or AsMut<[u8]> if that helps anything here
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
sdroege
May 23, 2018
Contributor
Currently there is only minimal support for custom memory types in the bindings (see here), but it's probably sufficient for what you need. From a mutable slice and from an immutable slice
This comment has been minimized.
This comment has been minimized.
Manishearth
May 23, 2018
Author
Member
Ah. Due to the way rustdoc deals with typedefs those functions don't show up in the docs where you'd expect
This comment has been minimized.
This comment has been minimized.
sdroege
May 23, 2018
Contributor
Yeah, personally I'm not using rustdoc because of that for anything built on top of gtk-rs. Easier to navigate the sources :)
This comment has been minimized.
This comment has been minimized.
Manishearth
May 23, 2018
Author
Member
Okay so it looks like I'd need to convert between Box<[u8]> and Box<[f32]> here (and in future versions, between vecs), and byte-slice-cast doesn't support that yet. Filing a bug at sdroege/byte-slice-cast#1 . It's not hard to write but I don't want to do one-off unsafe code in servo-media for it.
|
Do you have a list of features that would make rustdoc pleasant here?
I can try and implement them on the side, or mentor others to do so. Not
urgent, but worth fixing anyway.
The typedef one has been a constant paper cut for me in multiple codebases.
On May 22, 2018 11:39 PM, "Sebastian Dröge" <notifications@github.com> wrote:
*@sdroege* commented on this pull request.
------------------------------
In src/backends/gstreamer/audio_sink.rs
<#17 (comment)>:
@@ -87,9 +61,13 @@ impl AudioSink for GStreamerAudioSink {
.into();
buffer.set_pts(pts);
buffer.set_duration(next_pts - pts);
- let mut map = buffer.map_writable().unwrap();
- let data = map.as_mut_slice();
- graph_.process(data, rate);
+
+ let mut chunks = graph_.process(rate);
+ debug_assert!(chunks.len() == 1);
+ let data = &mut chunks.blocks[0].data;
+ let data = data.as_mut_byte_slice().expect("casting failed");
+ buffer.copy_from_slice(0, data).expect("copying failed");
Yeah, personally I'm not using rustdoc because of that for anything built
on top of gtk-rs. Easier to navigate the sources :)
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#17 (comment)>, or mute the
thread
<https://github.com/notifications/unsubscribe-auth/ABivSNjaCrdul_IiuoXU7T6dmm4Hccsvks5t1QQXgaJpZM4UJb8Q>
.
|
The typedef one is the most annoying one, I'll try remembering others. Guillaume Gomez probably remembers some more too :) It improved quite a bit over the last months though. |
|
e? @ferjm |
|
|
||
| [dependencies.num-traits] | ||
| optional = true | ||
| version = "0.1" |
This comment has been minimized.
This comment has been minimized.
| use std::{thread, time}; | ||
|
|
||
| fn main() { | ||
| if let Ok(servo_media) = ServoMedia::get() { | ||
| let mut graph = servo_media.create_audio_graph().unwrap(); | ||
| graph.create_node(AudioNodeType::OscillatorNode(Default::default())); | ||
| let mut options = GainNodeOptions::default(); | ||
| options.gain = 0.5; | ||
| graph.create_node(AudioNodeType::GainNode(options)); |
This comment has been minimized.
This comment has been minimized.
| use std::sync::mpsc::Receiver; | ||
| use std::sync::Arc; | ||
|
|
||
| #[cfg(feature = "gst")] | ||
| use backends::gstreamer::audio_sink::GStreamerAudioSink; | ||
|
|
||
| pub enum AudioGraphThreadMsg { | ||
| CreateNode(usize, AudioNodeType), | ||
| CreateNode(AudioNodeType), | ||
| ResumeProcessing, | ||
| PauseProcessing, | ||
| } | ||
|
|
||
| pub struct AudioGraphThread { | ||
| // XXX Test with a hash map for now. This should end up |
This comment has been minimized.
This comment has been minimized.
| AudioNodeType::GainNode(options) => { | ||
| let node = Box::new(GainNode::new(options)); | ||
| let mut nodes = self.nodes.borrow_mut(); | ||
| nodes.push(node); | ||
| } | ||
| _ => unimplemented!(), | ||
| } |
This comment has been minimized.
This comment has been minimized.
ferjm
May 23, 2018
•
Member
nit:
let node: Box<AudioNodeEngine> = match node_type {
AudioNodeType::OscillatorNode(options) => Box::new(OscillatorNode::new(options)),
AudioNodeType::GainNode(options) => Box::new(GainNode::new(options)),
_ => unimplemented()!,
};
let mut nodes = self.nodes.borrow_mut();
nodes.push(node)| ResumeProcessing, | ||
| PauseProcessing, | ||
| } | ||
|
|
||
| pub struct AudioGraphThread { | ||
| // XXX Test with a hash map for now. This should end up | ||
| // being a graph, like https://docs.rs/petgraph/0.4.12/petgraph/. | ||
| nodes: RefCell<HashMap<usize, Box<AudioNodeEngine>>>, | ||
| nodes: RefCell<Vec<Box<AudioNodeEngine>>>, |
This comment has been minimized.
This comment has been minimized.
ferjm
May 23, 2018
Member
Sorry, I forgot to mention this. Can we also leave the HashMap until we use something like petgraph.GraphMap, please? We need it to implement node methods like #21.
This comment has been minimized.
This comment has been minimized.
Manishearth
May 23, 2018
Author
Member
We can't, hashmaps don't have ordered iteration. I was getting nondeterministic panics because sometimes the gain node came before the oscillator.
For node methods I was thinking we'd just use indices for now. The caller knows what the indices will be.
This comment has been minimized.
This comment has been minimized.
ferjm
May 23, 2018
•
Member
I meant leaving both, the HashMap and the Vec. Or maybe using something like linked_hash_map. But I guess Vec indices also works for now.
This comment has been minimized.
This comment has been minimized.
Manishearth
May 23, 2018
Author
Member
Yeah I don't want to tune up the abstraction here too much since we'll replace it soon anyway.
Manishearth commentedMay 22, 2018
No description provided.