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: C++ compress data example  (Read 4044 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

C++ compress data example

Hello, I went through your site on github, the official site and the forum, but I did not find the answer.

I am developing an application where I collect data from a sensors and need to compress it for transfering. Data from sensors are 16-byte values ​​with a length of up to 3000 samples, so I thought wavpack might be useful. I would like to ask if you have an example that could be modified for my problem, which is to insert these samples (array of values) and read the compressed data.


Thank you very much for the answer.

Re: C++ compress data example

Reply #1
Hi. You don't mention whether you require lossless compression (which preserves the values exactly) or can tolerate some small error in the data (which would perhaps allow much better compression). Either way WavPack would work, but if you want to try lossless first, then another library I have might be better (and certainly easier to integrate). It's called SLAC and you can find it here. It will compress your sample data in a single call to a C function. The only thing you will need to do is copy the 16-bit data samples into an array of 32-bit integers.

Depending on your application you might be able to get away with lossy compression. The main problem with lossless compression is that the characteristics of the data to compress limits how much compression you can get, and if the values are very random you might not get very much compression at all. The WavPack lossy mode can compress much further, down to under 3 bits per sample if desired, while preserving much of the data. I would suggest starting with section 4.0 of the WavPack library documentation. Of course,. WavPack can do lossless too (and compress somewhat better) but it's more complex to integrate.

You don't mention it, but I assume that you are talking about a series of sample values taken in the time domain, right? The compressors I mention here are designed to take advantage of sample-to-sample correlation. Also, if you have multiple sensors then you would want to interleave the sample data (and SLAC can currently only handle two channels, although with either compressor it would be possible to compress the data into multiple streams).

Let me know if you still have trouble or have more questions.

Re: C++ compress data example

Reply #2
Hi Bryant.
you refer to the wavpack documentation which a 'how-to-use' or 'how-to-interface' the wavpack library.
It might be interesting for me to have a look to a documentiin describing how the compression is working. Do you know if and where I can find this kind of document?

Lastly, you mentioned that wavpack might do compression on multichannel signals, I guess not only using tome correlation but also spatial correlation.  can you confirm?

Re: C++ compress data example

Reply #3
Hi Bryant.
you refer to the wavpack documentation which a 'how-to-use' or 'how-to-interface' the wavpack library.
It might be interesting for me to have a look to a documentiin describing how the compression is working. Do you know if and where I can find this kind of document?
I wrote a section of the 4th Edition of David Salomon's book Data Compression: The Complete Reference on how WavPack's compression works. You can download that section here. If you have any other questions, ask on this forum.

Quote
Lastly, you mentioned that wavpack might do compression on multichannel signals, I guess not only using tome correlation but also spatial correlation.  can you confirm?
For multichannel files, WavPack separates the applicable channels into L+R pairs and utilizes correlation between the channels to improve the compression, but there's no further advantage taken say, front to back. So it's really just the techniques that apply to stereo.