[experiment] force chunking when using dynamic sources

Open
#909 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
12/100
Issue type
Refactor
Clarity
Needs clarification
Activity status
Quiet
Tech stack
rust

Research direction

The payload names no files, only the mixer's Box<dyn Source> storage and a sketched Chunked wrapper with a next method on Mixer. Start by finding where the mixer boxes its sources and how next() pulls samples, then benchmark the current path. Done would mean a measured comparison with a proposed design agreed in the thread, which is not yet settled.

Written by the indexing model from the issue text.

Description

enhancement

I suspect one thing that can really slow the mixer down is that it takes Box<dyn Source>. Since the next() calls cannot be inlined here this probably slows everything down. We can make this less of an issue by getting chunks (up to some size) in the mixer. Roughly:

impl source -> Sample
chunked(impl source) -> [Sample]    // returns array
Box<dyn chunked> -> [Sample]        // return array
Mixer() -> Sample (uses the chunks internally)

Now the only way to get a nice API with this is to hide the whole chunking inside the mixer. Like this:

struct Mixer {...}

impl Mixer {
    fn add(&mut self, s: impl Source) {
        let chunked = Chunked::from(s);
        let chunked = Box::new(chunked) as Box<dyn Chunk>;
        self.sources.push(chunked)
    }
    ...
}

impl Iterator for Mixer {
    fn next(&mut self) -> Option<Sample> {
        if self.cached_chunks.is_empty() {
             for chunked in self.sources {
                  self.cached_chunks.push(chunked.next_chunk())?;
             }
        }
        
        let mut sample = 0.0;
        for chunk in &mut self.cached_chunks {
            sample += chunk.pop_front();
        }
        Some(sample)
    }
}

Dominant language
Rust
Stars
2.5k
Forks
338
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from RustAudio/rodio

All issues in RustAudio/rodio

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.