Open freesig opened 6 years ago
Yep the sample
crate has a conversion for just about every sample type under the sun and hundreds of tests for them!
This method is probably the easiest way to do the conversions. E.g.
my_sample.to_sample::<f32>()
Would it be ok to add this as a cpal dependency?
I feel like we'd just be reinventing your work otherwise
I'm pretty unhappy with the state of conversions. It's all done with a really messy macro. We could rewrite it using enums to represent which is from and to types of conversion. ie.
This still doesnt help if you are going to a smaller type ie i16 to i32 It also introduces a runtime cost. Not sure how bad it would be but it is happening in the audio callback.
Another way could be to impl from for each possible conversion. Then we can just call into() I think this could be a good way to go. Although there might be some code duplication we could always make some helper functions that are shared between eg. i8::from(i16) and i16::from(i64) and conversions that have the same logic for there conversion. I think it could be worth pulling this into it's own module or even it's own crate as I recon it could be cool to have a crate that's tested and fast for sample conversion