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

Sample should have super traits #118

Open
bkfox opened this issue Apr 9, 2020 · 1 comment
Open

Sample should have super traits #118

bkfox opened this issue Apr 9, 2020 · 1 comment

Comments

@bkfox
Copy link

@bkfox bkfox commented Apr 9, 2020

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 bkfox changed the title Sample should have Default has super trait Sample should have super traits Apr 9, 2020
@mitchmindtree
Copy link
Member

@mitchmindtree mitchmindtree commented Apr 10, 2020

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.