The best way to do this is to apply a 30 second truncation, fade out and fade out to WAV audio files before converting it to MP3. If your conversion library has a method that accepts an array of samples, this is very easy to do. If the method accepts only a WAV file (either in memory or on disk), then this is a little less simple, since you need to learn the format of a WAV file (which is easy to write, but somewhat harder to read). In any case, applying gain and / or attenuation to time domain data (like in a WAV file) is much simpler than trying to apply these effects to frequency domain data (like in an MP3 file).
Of course, if your conversion library already does all of this, it's best to use it and not worry about it yourself.
Musigenesis
source share