Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audio Compression #37

Open
trekhopton opened this issue Jan 22, 2019 · 7 comments
Open

Audio Compression #37

trekhopton opened this issue Jan 22, 2019 · 7 comments
Milestone

Comments

@trekhopton
Copy link

Hi,
I'm interested to know if this package compresses audio when encoding it to flac. I have tried out the wav2flac program in the cmd folder however when given a 5 second stereo wav file sampled at 48kHz, the flac file produced is larger by 240kb.

Since wav is uncompressed and flac is supposed to be encoded using lossless compression, I was expecting a smaller file size. Am I missing something?
Thanks,
-Trek

@mewmew
Copy link
Member

mewmew commented Jan 22, 2019

Hi Trek!

I'm interested to know if this package compresses audio when encoding it to flac.

The quick answer is, it does not. At least not currently. This is tracked by #35 which covers the implementation of LPC encoding of audio samples.

I have tried out the wav2flac program in the cmd folder however when given a 5 second stereo wav file sampled at 48kHz, the flac file produced is larger by 240kb.

Since wav is uncompressed and flac is supposed to be encoded using lossless compression, I was expecting a smaller file size. Am I missing something?

That sounds about right. The audio samples are currently encoded using the verbatim (i.e. uncompressed) method, or the constant method (when all audio samples of a frame are the same). However, as noted above, LPC encoding is yet to be implemented, and it is only once this has been implemented that you will see a compression of audio streams.

My brother @karlek and I are coding on the flac project when we get the feeling to, and usually that is during summer hackathons :)

If you are interested in audio encoding and would be interested in contributing to the project, feel most welcome to take a stab at implementing LPC encoding :)

Take a look at encode_subframe.go for the LPC encoding method yet to be implemented.

	// Encode audio samples.
	switch subframe.Pred {
	case frame.PredConstant:
		if err := encodeConstantSamples(bw, hdr.BitsPerSample, subframe.Samples); err != nil {
			return errutil.Err(err)
		}
	case frame.PredVerbatim:
		if err := encodeVerbatimSamples(bw, hdr, subframe.Samples); err != nil {
			return errutil.Err(err)
		}
	//case frame.PredFixed:
	//	if err := encodeFixedSamples(bw, hdr, subframe.Samples, subframe.Order); err != nil {
	//		return errutil.Err(err)
	//	}
	//case frame.PredFIR:
	//	if err := encodeFIRSamples(bw, hdr, subframe.Samples, subframe.Order); err != nil {
	//		return errutil.Err(err)
	//	}

Cheers,
Robin

@severincognito
Copy link

Hello, are there any plans now to move this issue forward?
Thanks for this very well made library!

@mewmew
Copy link
Member

mewmew commented Mar 5, 2023

Hi @severincognito!

Neither Henry nor I are looking into implementing compression of audio samples for the foreseeable time in the future. That being said, anyone in the community who feel up to the task is warmly invited to take up the challenge.

As noted above in #37 (comment) the missing component is support LPC encoding (as tracked by issue #35).

Do you have experience with audio codes @severincognito? Or even better, feel like learning something new? : ) Should you feel up for the challenge @karlek and I can try to guide you if you get stuck in any part of the mewkiz/flac code base.

Wish you a most lovely Spring.

Warm regards,
Robin & Henry

@ilyassBZ
Copy link

can i work on this ? i saw the comm #35 and u already did imp encodeFIRSamples and fixedS ..... so what the problem now is it u wanna implement wav2flac or what u wanna do exactly ....

@wader
Copy link

wader commented Dec 27, 2023

can i work on this ? i saw the comm #35 and u already did imp encodeFIRSamples and fixedS ..... so what the problem now is it u wanna implement wav2flac or what u wanna do exactly ....

As i understand it #35 only adds support for encoding the LPC sample format but does not include any code for doing linear prediction. So if you want to implement a wav2flac that should compress, instead of just use verbatim frames, you would have to implement something that takes raw samples and produce Subframe:s that are filled in using some kind of linear prediction calculation and then encode those (and probably only if it makes sense compression-wise).

I don't know much about linear prediction but in the #35 description there is link to #32 (comment) with some pointers.

@ilyassBZ
Copy link

i will work on it in this weekend then im also don't know much about linear prediction but i will learn and work on it in the same time what the worse thing could hpn lol

@mewmew
Copy link
Member

mewmew commented Jan 2, 2024

i will work on it in this weekend then im also don't know much about linear prediction but i will learn and work on it in the same time what the worse thing could hpn lol

That's the spirit!

And, precisely like @wader pointed out. The #35 PR implemented encoding of LPC audio samples. The remaining part now is to do the linear prediction, i.e. to find good coefficients for storing the audio samples such that they take less space.

Wish you happy coding @ilyassBZ and a good learning adventure : )

Cheerful regards from Chile,
Robin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants