lordmulder / DynamicAudioNormalizer

Dynamic Audio Normalizer
Other
251 stars 36 forks source link

float type #18

Closed mipac closed 4 years ago

mipac commented 4 years ago

Hi, The API code is based on double floatting point operations. Is it possible to template the code to be able to use it with float, or is this a bad idea because of internal reason, like quantization problem or something like that?

regards, Michel

lordmulder commented 4 years ago

No, we cannot use templates here 😞

That is because C++ templates require that the entire template function is defined directly in the header file. The compiler generates the code for a template function right at the place where it gets invoked. So, it is not possible to declare a template function in the header file and have the implementation in a separate source code file. Especially, we can not "export" template functions from a library (DLL).

What would be possible is to provide float-overloads of the MDynamicAudioNormalizer::process() and MDynamicAudioNormalizer::processInplace() functions. But we certainly don't want to duplicate all the internal code as float and double versions! So, the float-API would just convert the input to double, internally, and call the double-API. The result will be converted back to float.

But, of course, this kind of implementation will make the float-API not more efficient than the double-API. In fact, the float-API would even be slightly slower, because of the additional conversions. That arises the question: Why do we need a float-API at all? After all, the primary reason of using float in your code, instead of double, is improved speed – at the cost of lower precision.

Best regards.

mipac commented 4 years ago

ok, thanks a lot for the reply

Le lun. 28 oct. 2019 à 21:30, LoRd_MuldeR notifications@github.com a écrit :

No, we cannot use templates here 😞

That is because C++ templates require that the entire template function is defined directly in the header file. That is because the compiler generates the code for template functions right when reading the header file. So, it is not possible to declare a template function in the header file and have the implementation in a separate source code file. In particular, we can not "export" template functions from a library (DLL).

What would be possible is to provide float-overloads of the MDynamicAudioNormalizer::process() and MDynamicAudioNormalizer::processInplace() functions. But we certainly don't want to duplicate all the internal code as float and double versions! So, the float-API would just convert the input to double (internally) and call the double-API. The result will be converted back to float.

But, of course, the will make the float-API not more efficient than the double-API. In fact, the float-API would be slightly slower, because of the additional conversions. That arises the question: Why do we need a float-API at all? After all, the primary reason of using float instead of double is improved speed – at the cost of lowered precision.

Best regards.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/lordmulder/DynamicAudioNormalizer/issues/18?email_source=notifications&email_token=ABMPSAYTSSFSZ6RNMOSK5K3QQ5DXLA5CNFSM4JFZ4562YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECOJIRI#issuecomment-547132485, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABMPSA5GOWEPPOHJSRO4K5DQQ5DXLANCNFSM4JFZ456Q .