from scipy.io import wavfile
import numpy as np
import zstd
sampling_rate, samples = wavfile.read(r'data/bootleg-compress/music_orig.wav')
orig = samples.tobytes()
naive_compressed = zstd.ZSTD_compress(orig)
deltas = np.diff(samples, prepend=samples.dtype.type(0), axis=0) # Per-channel deltas.
compressed_deltas = zstd.ZSTD_compress(deltas.ravel()) # Interleave channels and compress.
decompressed_deltas = np.frombuffer(zstd.ZSTD_uncompress(compressed_deltas), dtype=samples.dtype)
decompressed = np.cumsum(decompressed_deltas.reshape(deltas.shape), axis=0, dtype=samples.dtype)
assert np.array_equal(samples, decompressed)
print(len(orig))
print(len(naive_compressed))
print(len(compressed_deltas))
giving: 17432876
15518973
12817602
Looks like my initial estimation of 2-4 was way off (when FLAC achieves ~2 this should've been a red flag), but you do get a ~1.36x reduction in space at basically memory read speed.But unless it's a non commercial project, the cost shouldn't be a big deal, so it's still a bit strange.
Physics are actually farmed out to the clients themselves, it's a bit of a quirky idea, but it actually works if one isn't concerned with accuracy.
Edit: Had high hopes for High Fidelity, and came very close to asking for a job there ;) Shame it’s kaput, didn’t know that :(
High Fidelity the company is still around, but they pivoted multiple times radically. Initially their plan was social VR of sorts. Then they tried to make a corporate product for meetings and such, and gave up on that right before COVID19 hit!
And after that they ripped out all the 3D and VR and scaled down to a 2D, overhead spatial audio web thing. Think something like Zoom, only you have an icon that you can move around to get closer or further to other people.
The original code still lives on, we picked it up and are working on improvements. Feel free to visit out Discord (see my profile).
It's a community-led continuation of High Fidelity, a dead commercial project. They made their own proprietary codec with excellent performance we can't use and managed to have a couple thousand people in the same server.
There is some correlation between the cost of a hardware implementation and complexity of a software implementation. SBC is a very simple codec, but AptX and LC3 might not be much better than Opus.
Opus is a very good codec, but it's not amazing CPU-wise. I work on a VR world, and audio encoding is usually our most limiting factor when running on an VPS. We have the capability to negotiate codecs, so the high cpu/low bandwidth use case is already covered.
What I'm looking for specifically:
* Low CPU usage
* Support for high bitrate, suitable for music and sounds other than voice
* Low latency