dasp icon indicating copy to clipboard operation
dasp copied to clipboard

Sample should have super traits

Open bkfox opened this issue 5 years ago • 1 comments

Few supertrait would be really usefull for Sample in order to use it as generic parameter:

  • Default: would ease container resize and have an initial zero value when using Sample as type bound for a generic parameter, such as buffer.resize(1024, S::default());
  • Add: simplify addition between samples;

bkfox avatar Apr 09 '20 16:04 bkfox

Hi @bkfox, thanks for the issue!

You can achieve your default case by using the Sample::equilibrium() method. This also provides slightly more predictable behaviour if you happen to be working with unsigned data for some reason where the signal equilibrium is not equal to the default value.

As an alternative to Add, you should be able to use the Sample::add_amp method.

Also, keep in mind that you can define your own sample trait for your project that better suits your needs if Sample doesn't tick all your boxes, e.g.

trait MySample: Sample + hound::Sample + Add + Default {}
impl<T> MySample for T where T: Sample + hound::Sample + Add + Default {}

I hope this helps!

mitchmindtree avatar Apr 10 '20 19:04 mitchmindtree