Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use block/chunk abstraction for processing; add gainnode #17

Merged
merged 7 commits into from May 23, 2018
Merged

Conversation

@Manishearth
Copy link
Member

Manishearth commented May 22, 2018

No description provided.

@Manishearth Manishearth changed the title Use block/chunk abstraction for processing Use block/chunk abstraction for processing; add gainnode May 22, 2018
@Manishearth
Copy link
Member Author

Manishearth commented May 22, 2018

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.

@Manishearth Manishearth mentioned this pull request May 22, 2018
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.

@sdroege

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.

@Manishearth

Manishearth May 23, 2018

Author Member

How would I do that?

This comment has been minimized.

@sdroege

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.

@Manishearth

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.

@sdroege

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.

@Manishearth

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.

@Manishearth
Copy link
Member Author

Manishearth commented May 23, 2018

@sdroege
Copy link
Contributor

sdroege commented May 23, 2018

Do you have a list of features that would make rustdoc pleasant here?

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.

@Manishearth
Copy link
Member Author

Manishearth commented May 23, 2018

e? @ferjm

@ferjm
ferjm approved these changes May 23, 2018
Copy link
Member

ferjm left a comment

Looks great and ready to be merged after addressing @sdroege feedback. Thanks!


[dependencies.num-traits]
optional = true
version = "0.1"

This comment has been minimized.

@ferjm

ferjm May 23, 2018

Member

Note that I removed some of these dependencies in #16

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.

@ferjm

ferjm May 23, 2018

Member

\o/ glad to see more nodes

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.

@ferjm

ferjm May 23, 2018

Member

Not a big deal, but the comment needs to be removed or updated.

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.

@ferjm

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.

@ferjm

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.

@Manishearth

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.

@ferjm

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.

@Manishearth

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 Manishearth merged commit 3c486eb into master May 23, 2018
@Manishearth Manishearth deleted the blocks branch May 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.