Skip to content

Phase1b of audio engine rewrite - #904

Open
yara-blue wants to merge 11 commits into
masterfrom
phase1b
Open

Phase1b of audio engine rewrite#904
yara-blue wants to merge 11 commits into
masterfrom
phase1b

Conversation

@yara-blue

@yara-blue yara-blue commented Jul 23, 2026

Copy link
Copy Markdown
Member

review after #903 (this includes it's changes)

Tracking issue: #901

  • Expands the fixed source impl. to match const source
  • de-duplicates methods between them using a new common::source module and macros
  • makes a note in the changelog
  • uses Placeholder to have docs and examples point to not yet landed code

@yara-blue
yara-blue requested a review from roderickvd July 23, 2026 21:28
@yara-blue
yara-blue force-pushed the phase1b branch 2 times, most recently from a0b8f73 to 429345a Compare July 26, 2026 20:59

@roderickvd roderickvd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this is built on top of #903 so I didn't duplicate any of my review points there to here.

Comment thread src/fixed_source.rs
}

/// A [`ConstSource`] adapted from a [`FixedSource`].
pub struct IntoConstSource<const SR: u32, const CH: u16, S: FixedSource>(S);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one and IntoDynamicSource should forward try_seek.

Comment thread src/const_source.rs
}
}

impl<const SR: u32, const CH: u16, S> FixedSource for IntoFixedSource<SR, CH, S>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should forward try_seek.

Comment thread src/fixed_source/chain.rs
}

#[derive(Debug, Clone, Copy, thiserror::Error, PartialEq, Eq)]
pub struct ParamsMismatch {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider exporting this one so users can downcast to it.

};
}

macro_rules! iter_impl {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should re-add size_hint().

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems misplaced or having the wrong name.

@yara-blue yara-blue Aug 23, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how so? it is the documentation for FixedSource::collect_into_buffer and ConstSource::collect_into_buffer.

I'll expand the text a little to make that more clear.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it was out of place because the title was about building a SamplesBuffer, not about collecting into a buffer, and went on to describe a panic that wouldn't be occurring in new (the "builder") anymore, but in total_duration.

Comment thread src/generators/silence.rs

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per #913 we should add the ability to create one with an arbitrary channel count. Over there we targeted it for phase 4, so just mentioning it here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For silence the idea is to always put it through a channel convertor. My hope being that the optimizer can figure it out. If that is false and perf. becomes an issue we could specialize it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automatic optimization would be great, but how would that work?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the compiler knows that Silence::next returns a constant value (namely: Some(0.0)).

Lets take this fragment of the channel convertor:

        let result = match self.next_output_sample_pos {
            0 => {
                let value = self.input.next();
                self.sample_repeat = value;
                value
            }
            x if x < self.from.get() => self.input.next(),
            1 => self.sample_repeat,
            _ => Some(Sample::EQUILIBRIUM),
        };

Every self.input.next() gets replaced with Some(0):

        let result = match self.next_output_sample_pos {
            0 => {
                self.sample_repeat = 0.0;
                0.0
            }
            x if x < self.from.get() => 0.0,
            1 => self.sample_repeat,
            _ => Some(0.0),
        };

Now its simple to see that self.sample_repeat is also constant. So everywhere we see it replace with a 0.0.

        let result = match self.next_output_sample_pos {
            0 => {
                0.0
            }
            x if x < self.from.get() => 0.0,
            1 => 0.0,
            _ => Some(0.0),
        };

And this is now just a match statement returning 0.0 always so result can be set to 0.0.

There is some other stuff like self.from.get() and self.next_output_sample_pos() but that has also become dead code so the optimizer throws that out as well. And now we've gotten to the point where ChannelCountConvertor::next() can be replaced with just 0.0. This should domino up any audio pipeline.

Now if you put silence in a box and cast it to a Box... then this stops working.

Whether this all happens? It probably does, these are basic optimizations. You can never know for sure, sometimes a suggestion here and there is needed (a little #[inline] usually).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks for that write-up, that makes sense. As long as it doesn't get fed into Rubato or something, because then all bets would be off I imagine.

@yara-blue
yara-blue force-pushed the phase1b branch 2 times, most recently from 93c0e6c to f4f9169 Compare August 23, 2026 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants