faiface / beep

A little package that brings sound to any Go application. Suitable for playback and audio-processing.
MIT License
2.08k stars 152 forks source link

flac: implement support for flac decoding #9

Closed mewmew closed 7 years ago

mewmew commented 7 years ago

NOT YET READY FOR MERGE.

This is an initial PR which adds decoding support for FLAC to beep.

My brother and I have been able to play all the FLAC music we've managed to come across, so decoding and playback seems to work well :) (Example playback program at play.golang.org: https://play.golang.org/p/2RafKiP7Cy)

What is left to do is to implement support for seeking. As of yet, we do not know how to do that in a clean way; given that FLAC is a streaming format with potentially dynamic size of audio frames.

Preliminary work to add seek to the FLAC backend is underway in the dev branch. However, the current solution is very naiive and does not take sync codes into accounts. Any help in this direction would be much appreciated.

Cheers, /@karlek and @mewmew

mewmew commented 7 years ago

Please note, it is a design decision to keep the back-end separate from the beep repository (which is considered a front-end). This way, the same back-end FLAC library can be used by several front-ends. Currently there exist support in Azul3D, and future support for go-audio/audio is planned.

However, all the code is in the public domain, so if it makes sense to include the back-end code in the beep repository, feel free to do so. Perhaps under vendor or with dep or something.

faiface commented 7 years ago

Awesome!

Regarding seeking, after taking a quick look (so this is probably nothing new to you), FLAC format claims to enable fast seeking, so it must not be so hard. Here https://xiph.org/flac/format.html it's roughly described how seeking can be done. That's all help I can provide right now. In a few weeks, I will have more time and be able to try and implement it, if necessary.

If everything except for seeking works fine, I am open to merging this PR even now and keep the seeking unimplemented for the time being. It's still possible to load the whole file into a buffer and seek there.

So, what do you think? Will you be able to implement the seeking in a few days/weeks, or should we merge now and do seeking later?

mewmew commented 7 years ago

Awesome!

Regarding seeking, after taking a quick look (so this is probably nothing new to you), FLAC format claims to enable fast seeking, so it must not be so hard. Here https://xiph.org/flac/format.html it's roughly described how seeking can be done. That's all help I can provide right now. In a few weeks, I will have more time and be able to try and implement it, if necessary.

If you'd like to take a stab at implementing seek, you'd be most welcome to :) The issue to implement seek support in the FLAC back-end is located at https://github.com/mewkiz/flac/issues/16

If everything except for seeking works fine, I am open to merging this PR even now and keep the seeking unimplemented for the time being. It's still possible to load the whole file into a buffer and seek there.

So, what do you think? Will you be able to implement the seeking in a few days/weeks, or should we merge now and do seeking later?

You can definitely merge this as is. If anything, it may help iron out bugs as more users with different FLAC files can stress test various parts of the library.

Perhaps mark it as work in progress in the doc comment of the package, and mention that seek support is not yet implemented.

Btw, I've been playing around with pixel lately. It is really a quite lovely package you've build. I offer my sincere gratitude.

Cheers /u

faiface commented 7 years ago

Ok, I'll merge now and add a notice about the unimplemented features. Hope to get them implemented soon! (Either by you, or by me).

And thanks for the nice comments on Pixel :). Although I'm still not really satisfied with Pixel from the design standpoint (I'm much more satisfied with Beep). And I sort of know how I'd like to change some things, but ugh, time and motivation. And many things that are planned to get into Pixel but still aren't there. I'm still planning on "recruiting" a bunch of contributors for Pixel and I will execute this plan someday.

mewmew commented 7 years ago

And thanks for the nice comments on Pixel :). Although I'm still not really satisfied with Pixel from the design standpoint (I'm much more satisfied with Beep).

I was very pleasantly surprised when I stumbled across the beep API, and it took some time to grok the power of it. But that was certainly a rewarding experience, especially for someone who is interested in but havn't played to much with functionally inspired APIs.

Really glad you decided to write up your design ideas into a more high-level picture; https://faiface.github.io/post/how-i-built-audio-lib-composite-pattern/

With you happy hacking! :)

Cheers /u