Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Trying to implement the wavpack library, having problems with floating (Read 4234 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Trying to implement the wavpack library, having problems with floating

I'm trying to implement wavpack into a music player, and i've got all the integer modes working nicely, but floating point remains distorted. Are there special considerations to be made that aren't mentioned in lib_use.txt?

Trying to implement the wavpack library, having problems with floating

Reply #1
I'm trying to implement wavpack into a music player, and i've got all the integer modes working nicely, but floating point remains distorted. Are there special considerations to be made that aren't mentioned in lib_use.txt?

Since you're looking at lib_use.txt I assume you're not using the "tiny decoder" which now automatically handles float data. In the standard library you need to convert the float data back into integers yourself. Assuming that you use the OPEN_NORMALIZE flag and set "norm_offset" to zero, the buffer will come back with 32-bit floating data in the range of +/- 1.0, although you will still have to clip it because float data may exceed 0 dB.

Something like this would be the simplest to convert to 16-bit integers in place:
Code: [Select]
    int32_t *lptr = buffer;

    while (num_samples--) {
        float fdata = * (float*) lptr;

        if (fdata > 1.0) fdata = 1.0;
        if (fdata < -1.0) fdata = -1.0;

        *lptr++ = (int32_t) (fdata * 32767.0);
    }


You can also use the "norm_offset" parameter to scale the values for you. For example, I use 23 in the winamp plugin to have the values returned in the same range as 24-bit integers (although they still must be clipped and converted, just not scaled).

Good luck and thanks for implementing WavPack support!

Trying to implement the wavpack library, having problems with floating

Reply #2
Thanks for this... I was having the same issues with my Media Center plugin but hadn't gotten around to finding out what the problem was.

Trying to implement the wavpack library, having problems with floating

Reply #3
I have one remaining problem, even though i use OPEN_WVC it doesn't actually open the correction file.
The correction file is in the same folder with the same name, any thought?

 

Trying to implement the wavpack library, having problems with floating

Reply #4
I figured out my problem, i didn't use MODE_WVC when opening files for metadata reading.