LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-10-2017, 05:47 AM   #1
andrei.n
LQ Newbie
 
Registered: Dec 2014
Distribution: Fedora, Debian, lfs
Posts: 16

Rep: Reputation: 0
Need to convert mp3 to a raw 16-bit stream...


Hello,

I am trying to use chromaprint to generate an audio file fingerprint, but it only accepts raw audio 16-bit input. I tried to find a library that makes the conversion, but only could find commands which produce wav files of unspecified format and libraries that produce PCM. What is the best way to get a stream of 16-bit integers from an mp3 file? I would prefer if it were a c library rather than an executable.

Thank you.
 
Old 05-10-2017, 06:15 AM   #2
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 20 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2916Reputation: 2916Reputation: 2916Reputation: 2916Reputation: 2916Reputation: 2916Reputation: 2916Reputation: 2916Reputation: 2916Reputation: 2916Reputation: 2916
FFmpeg should do the trick?

https://trac.ffmpeg.org/wiki/audio%20types

The underlying libavcodec library could meet your preference for a c library solution.
 
Old 05-10-2017, 06:24 AM   #3
andrei.n
LQ Newbie
 
Registered: Dec 2014
Distribution: Fedora, Debian, lfs
Posts: 16

Original Poster
Rep: Reputation: 0
I'm not sure these PCM are compatible with raw. And I tried to find examples using libavcodec, and they're all 500 lines and I couldn't find any documentation...

I've also found some mad library examples, but it also only generates PCM, like here: https://github.com/bbc/audiowaveform...c/madlld-1.1p1
 
Old 05-10-2017, 06:31 AM   #4
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 20 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2916Reputation: 2916Reputation: 2916Reputation: 2916Reputation: 2916Reputation: 2916Reputation: 2916Reputation: 2916Reputation: 2916Reputation: 2916Reputation: 2916
https://oxygene.sk/2016/12/chromaprint-1-4-released/

Quote:
Or you can fingerprint raw pcm data from an external audio input
 
Old 05-10-2017, 07:25 AM   #5
andrei.n
LQ Newbie
 
Registered: Dec 2014
Distribution: Fedora, Debian, lfs
Posts: 16

Original Poster
Rep: Reputation: 0
Thanks. I'll have to study more these different formats...
 
Old 05-10-2017, 07:39 AM   #6
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 20 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2916Reputation: 2916Reputation: 2916Reputation: 2916Reputation: 2916Reputation: 2916Reputation: 2916Reputation: 2916Reputation: 2916Reputation: 2916Reputation: 2916
Quote:
Originally Posted by andrei.n View Post
Thanks. I'll have to study more these different formats...
Ok. This link indicates that the int is signed - https://www.ffmpeg.org/ffmpeg-format...#chromaprint-1

Linux on x86 is little endian.

Let us know how you get on.
 
Old 05-11-2017, 07:21 AM   #7
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873
SoX is probably the more capable thing to convert the file. Although it sounds more like you want to re-invent the wheel. There's many formats, which exactly are you trying to get? signed / unsigned, 8 / 16 / 24 / 32 bit? raw / pcm / au / uLaw / ... ... ...? big endian / little endian? mono / stereo / surround?

If you have an existing desired destination file you can run file, identify, ffprobe (avprobe), on it to give it's specs.

$ file audio.wav
$ identify audio.wav
$ ffprobe audio.wav

At which point we'll better know what options to pass to sox.

$ sox [input options] file.voodoo [output options] file.magic [effects and filters]
 
Old 05-11-2017, 07:36 AM   #8
andrei.n
LQ Newbie
 
Registered: Dec 2014
Distribution: Fedora, Debian, lfs
Posts: 16

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Shadow_7 View Post
SoX is probably the more capable thing to convert the file. Although it sounds more like you want to re-invent the wheel. There's many formats, which exactly are you trying to get? signed / unsigned, 8 / 16 / 24 / 32 bit? raw / pcm / au / uLaw / ... ... ...? big endian / little endian? mono / stereo / surround?

If you have an existing desired destination file you can run file, identify, ffprobe (avprobe), on it to give it's specs.

$ file audio.wav
$ identify audio.wav
$ ffprobe audio.wav

At which point we'll better know what options to pass to sox.

$ sox [input options] file.voodoo [output options] file.magic [effects and filters]
Thank you for the suggestion. I need 16-bit raw, it can be mono or stereo, whatever the original mp3 is.
 
Old 05-11-2017, 11:50 AM   #9
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873
$ sox file.mp3 -c 1 -r 44100 -b 16 -e signed-integer --endian little -t raw output.bin

Still not sure if you want signed or unsigned, or big or little endian. But that's a basic way to output a raw audio file.
 
Old 07-20-2017, 03:52 AM   #10
Bianting
LQ Newbie
 
Registered: Jul 2017
Posts: 1

Rep: Reputation: Disabled
built an editor library may be a good idea
 
  


Reply

Tags
decode, mp3


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert .rec to wav, mp3, or raw geekbynature Linux - General 1 02-15-2010 05:00 AM
How to convert mp3 to raw data using the command line donnied Linux - Newbie 1 10-17-2009 05:29 PM
convert WMA to MP3 stream on-the-fly Crit Linux - Server 2 09-30-2009 06:09 PM
How to record a stream and start a new outputXXX.avi/mp3 for each new stream title ? frenchn00b Linux - General 4 08-04-2008 05:40 AM
searching for app that will stream mp3 to shoutcast along with mp3 metadata h2gofast Linux - Software 3 01-10-2007 03:41 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration