Page 1 of 1

[SOLVED] wavPack decoder

Posted: Sat Sep 10, 2016 12:01 am
by es_91
For wavPack an official dll package exists on their major web page http://www.wavpack.com/ for download and usag of the .lib file distributed using, for example, the code postd by wilbert below:
wilbert wrote:

Code: Select all

EnumerationBinary
  #OPEN_WVC
  #OPEN_TAGS
  #OPEN_WRAPPER
  #OPEN_2CH_MAX
  #OPEN_NORMALIZE
  #OPEN_STREAMING
  #OPEN_EDIT_TAGS
  #OPEN_FILE_UTF8
EndEnumeration

ImportC "wavpackdll.lib"
  WavpackCloseFile (*wpc)
  WavpackGetBitsPerSample (*wpc)
  WavpackGetBytesPerSample (*wpc)
  WavpackGetNumChannels (*wpc)
  WavpackGetNumSamples (*wpc)
  WavpackGetReducedChannels (*wpc)
  WavpackGetSampleRate (*wpc)
  WavpackOpenFileInput (infilename.p-ascii, *error, flags, norm_offset)
  WavpackSeekSample (*wpc, sample)
  WavpackUnpackSamples (*wpc, *buffer, samples)
EndImport

*error = AllocateMemory(81)
*wpc = WavpackOpenFileInput("32bit_float.wv", *error, 0, 0)
If *wpc = 0
  Debug PeekS(*error, -1, #PB_Ascii)
Else
  
  numChannels = WavpackGetNumChannels(*wpc)
  bitsPerSample = WavpackGetBitsPerSample(*wpc)
  bytesPerSample = WavpackGetBytesPerSample(*wpc)
  sampleRate = WavpackGetSampleRate(*wpc)
  numSamples = WavpackGetNumSamples(*wpc)
  
  Debug "Channels : " + Str(numChannels)
  Debug "Bits per sample : " + Str(bitsPerSample)
  Debug "Bytes per sample : " + Str(bytesPerSample)
  Debug "Sample rate : " + Str(sampleRate)
  Debug ""
  Debug "Number of samples : " + Str(numSamples)
  
  BufferSize = 4 * numSamples * numChannels
  *Buffer = AllocateMemory(BufferSize)
  If *Buffer And WavpackUnpackSamples(*wpc, *Buffer, numSamples) = numSamples
    Debug "Decoded"
  Else
    Debug "Decode error"
  EndIf
  
  WavpackCloseFile(*wpc)
  
EndIf
PS: don't forget it requires "32bit_float.wv" maybe you want to put some openFileRequester () there. 8)

Re: [USERLIB] wavPack decoder

Posted: Sat Sep 10, 2016 12:39 am
by Keya
es_91 wrote:Soon, i believe, the last mp3 patents in US are running out ... maybe one day Fred and Timo will provide MP3 decoder plugins within PureBasic?
i could be mistaken but i'm pretty sure you only need a license from Fraunhoffer or whatever if you want to write a (commercial) ENCODER for mp3 - everyone is free to write their own decoder, including commercial - again, if i'm not mistaken. I think the LAME codec is able to get away with encoding because it's free. But don't quote me on any of this!

Re: [USERLIB] wavPack decoder

Posted: Sat Sep 10, 2016 1:01 am
by es_91
Keya wrote:But don't quote me on any of this!
I won't. :P

[edited]
The basic MP3 decoding and encoding technology is patent-free in the European Union, all patents having expired there. In the United States, the technology will be substantially patent-free on 31 December 2017 (see below).
en. wikipedia. org /wiki /MP3 #Licensing, ownership and legislation

Re: [USERLIB] wavPack decoder

Posted: Sat Sep 10, 2016 1:09 am
by Keya
Stages in becoming a programmer:
1) Become a lawyer
2) Learn programming
3) Get sued by a troll over some ridiculous software patent
Congratulations, YOU'VE MADE IT!

Re: [USERLIB] wavPack decoder

Posted: Sat Sep 10, 2016 3:58 am
by es_91
guess you gotta do IT with a little protection these days ...

Re: [USERLIB] wavPack decoder

Posted: Sat Sep 10, 2016 5:28 am
by wilbert

Re: [USERLIB] wavPack decoder

Posted: Sat Sep 10, 2016 6:54 am
by es_91
[...] Sorry, no experience, no skills.

But I'll give it a try if that's what you meant. ..which you surely did. ^^

Re: [USERLIB] wavPack decoder

Posted: Sat Sep 10, 2016 7:17 am
by wilbert
es_91 wrote:But I'll give it a try if that's what you meant. ..which you surely did. ^^
The zip file contains a pre-build dll and lib for Windows both x86 and x64. :wink:
http://www.wavpack.com/wavpackdll.zip

Code: Select all

EnumerationBinary
  #OPEN_WVC
  #OPEN_TAGS
  #OPEN_WRAPPER
  #OPEN_2CH_MAX
  #OPEN_NORMALIZE
  #OPEN_STREAMING
  #OPEN_EDIT_TAGS
  #OPEN_FILE_UTF8
EndEnumeration

EnumerationBinary
  #MODE_WVC
  #MODE_LOSSLESS
  #MODE_HYBRID
  #MODE_FLOAT
  #MODE_VALID_TAG
  #MODE_HIGH
  #MODE_FAST
  #MODE_EXTRA
  #MODE_APETAG
  #MODE_SFX
  #MODE_VERY_HIGH
  #MODE_MD5
  #MODE_XMODE = $7000
  #MODE_DNS = $8000
EndEnumeration

ImportC "wavpackdll.lib"
  WavpackCloseFile (*wpc)
  WavpackGetBitsPerSample (*wpc)
  WavpackGetBytesPerSample (*wpc)
  WavpackGetMode (*wpc)
  WavpackGetNumChannels (*wpc)
  WavpackGetNumSamples (*wpc)
  WavpackGetReducedChannels (*wpc)
  WavpackGetSampleRate (*wpc)
  WavpackOpenFileInput (infilename.p-ascii, *error, flags, norm_offset)
  WavpackSeekSample (*wpc, sample)
  WavpackUnpackSamples (*wpc, *buffer, samples)
EndImport

*error = AllocateMemory(81)
*wpc = WavpackOpenFileInput("32bit_float.wv", *error, 0, 0)
If *wpc = 0
  Debug PeekS(*error, -1, #PB_Ascii)
Else
  
  numChannels = WavpackGetNumChannels(*wpc)
  bitsPerSample = WavpackGetBitsPerSample(*wpc)
  bytesPerSample = WavpackGetBytesPerSample(*wpc)
  sampleRate = WavpackGetSampleRate(*wpc)
  numSamples = WavpackGetNumSamples(*wpc)
  
  Debug "Channels : " + Str(numChannels)
  Debug "Bits per sample : " + Str(bitsPerSample)
  Debug "Bytes per sample : " + Str(bytesPerSample)
  Debug "Sample rate : " + Str(sampleRate)
  Debug ""
  Debug "Number of samples : " + Str(numSamples)
  
  BufferSize = 4 * numSamples * numChannels
  *Buffer = AllocateMemory(BufferSize)
  If *Buffer And WavpackUnpackSamples(*wpc, *Buffer, numSamples) = numSamples
    Debug "Decoded"
  Else
    Debug "Decode error"
  EndIf
  
  WavpackCloseFile(*wpc)
  
EndIf

Re: [USERLIB] wavPack decoder

Posted: Sat Sep 10, 2016 7:43 am
by es_91
My bad. Thank you. Much appreciated! 8)

Re: [USERLIB] wavPack decoder

Posted: Sat Sep 10, 2016 8:00 am
by wilbert
es_91 wrote:Nice to have wavPack.
It seems like you have to convert the samples yourself to the sample format you wish. :shock:

Re: [USERLIB] wavPack decoder

Posted: Sat Sep 10, 2016 9:22 am
by es_91
Yes. That is something wavPack does not want to do. Equal to this: wavPack will not convert CD-resoluted material too far below 200 kbit/s. That again, for quality purposes. With lower resoluting material, rates below 50 kbit/s are possible.

If you wish to not just compress or reduce data, but also to resample it, wavPack probably won't offer a build-in solution.

And honestly, i think that is the right choice.