csabahruska/proteaaudio

MP3 support

nomeata opened this issue · 5 comments

I’m considering using proteaaudio in one of my projects where I currently shell out to sox. One feature I’ll probably miss is support for MP3 in addition to WAV and OGG. Is that by any chance on your road map and I can just wait for that, or would I have to work around it anyways?

IMO I could add MP3 support. This lib looks promising: https://github.com/lieff/minimp3
I prefer single file solutions without external dependencies.

That would be great!

I've added MP3 support. Please check it and if it works for you then I'll make a new release on Hackage.
aa48206

Works flawlessly!

In my application I need to handle different formats without knowing their filename, and will use logic like this

sampleFromMemory :: B.ByteString -> Float -> IO Sample
sampleFromMemory bs
  | B.take 4 bs == B.pack "RIFF" = sampleFromMemoryWav (B.toStrict bs)
  | B.take 4 bs == B.pack "OggS" = sampleFromMemoryOgg (B.toStrict bs)
  | B.take 3 bs == B.pack "ID3" || B.take 2 bs `elem`
      [B.pack "\xFF\xFB", B.pack "\xFF\xF3", B.pack "\xFF\xF2"]
  = sampleFromMemoryMp3 (B.toStrict bs)
  | otherwise = error "Could not detect audio format"
 where magic = B.take 4 bs

If you think that logic would actually be good to have in proteaaudio itself, I’ll of course prefer that :-)

Besides that I think I’m good for now, thanks!

Released proteaaudio-0.10.1 with mp3 support and sampleFromMemory.