mackron / miniaudio

Audio playback and capture library written in C, in a single source file.
https://miniaud.io
Other
4.07k stars 361 forks source link

ma_noise_set_type() - changing the type of noise dynamically crashes #585

Closed michal-z closed 1 year ago

michal-z commented 1 year ago

Documentation states that it should be possible to change the type of the noise dynamically:

The amplitude, seed, and type can be changed dynamically with `ma_noise_set_amplitude()`,
`ma_noise_set_seed()`, and `ma_noise_set_type()` respectively.

I get a crash when trying to change the noise type after calling ma_noise_init(). Looking at the ma_noise_init() code I can see:

    /* Pink. */
    if (pConfig->type == ma_noise_type_pink) {
        // ...
    }

    /* Brownian. */
    if (pConfig->type == ma_noise_type_brownian) {
       // ...
    }

So, there is a dedicated init code for different noise types and this code is not executed when the noise type is changed dynamically with ma_noise_set_type().

mackron commented 1 year ago

Thanks for the report. That function should never have been supported in the first place. This was a mistake on my part. I've updated the dev branch so that it just returns an error and triggers an assert when run in debug mode. Considering anyone who would have used it would have got a crash anyway this shouldn't cause any additional disruption. The assert will let the developer know at development time. I'll remove the function completely in version 0.12 which will be an API-breaking release.