-3

When I want to process an audio in a byte level, I always convert it in .wav format and then do my processing. For example in my last project, I was trying to generate a kind of special waveform image of my audio file to use it in a video clip. Then I converted my .mp3 file to .wav file (mono, 8 bit, 6KHz) using an online tool and then I maked my waveform picture programmatically.

Now I want to be able to do my processing on an .mp3 file directly without conversion, like the code below:

aFrom := 60000;   // From 00:01:00.000
aLength := 20000; // 20 Second 
aChannels := 1;   // mono
aBitsPerChannel := 8;
aFreq := 6000;

aBufSize := Open_MP3_As('d:\Until The Last Moment.mp3',
  aBuffer, aFrom, aLength,
  aChannels, aBitsPerChannel, aFreq);

for i := 0 to aBufSize - 1 do
begin
  // Processing aBuffer[i]
end;

this is just an example of showing what in my mind is. As you can see, the metadata and the details of the .mp3 file is not important for me.

This would be very useful because I can embed this ability to my audio tools and let the user use my tools very faster and easier. I know that it could be a very complicated code because at the first time, the .mp3 file must be converted to .wav file (with the specific given parameters), then it must remove the header, slice it and put it in the aBuffer and return the amount of samples in aBuffer.

M Ahmadzadeh
  • 121
  • 7
  • 3
    There are TONS of libraries/components readily available for processing audio/media data. Have you looked around yet? Have you tried any of them? – Remy Lebeau Aug 20 '18 at 21:01
  • Do you know any, that I can use them as simple as the code I wrote? or I must struggle with some complicated (and maybe not free) components and then I increase the size of my project. – M Ahmadzadeh Aug 20 '18 at 21:18
  • 3
    The less work you have to do, the more the library you'll use. That would probably mean a bigger library used by a smaller project. In any case, 3rd party recommendations are off topic. – Sertac Akyuz Aug 20 '18 at 21:30
  • Yes you are right, but I'm looking for a true answer, can anybody recommend a FREE library with which I can do the same thing? – M Ahmadzadeh Aug 21 '18 at 06:43
  • 1
    @MohammadAhmadzadeh Just go and check some audio libraries that allow mp3 playback with search capability. Why with search capability? Becouse in most cases such libraries also have ability to render rugh visual representation of waweform which is what you are looking for. Unrotunately I have no expirience with any of the free ones out there. But I do have some expirience with BASS audio library (https://www.un4seen.com/) which has such capabilities and much more. But it is not for free. – SilverWarior Aug 21 '18 at 13:21

1 Answers1

-2

This could solve my problem very quickly, I hope it helps:

use This Link to run this command-line:

ffmpeg.exe -ss 60 -t 20 -y -i input.mp3 -ac 1 -ar 6000 -acodec pcm_u8 output.wav

this will convert .mp3 file to .wav with the given parameters.

Then you have the .wav file, just open it, skip the wave header and then read it in the aBuffer.

That's it.

M Ahmadzadeh
  • 121
  • 7
  • 3
    How can this be an answer, when you specifically said in your question: *Now I want to be able to do my processing on an .mp3 file directly without conversion...*? – Tom Brunberg Aug 22 '18 at 04:07
  • You are write, it is a conversion, but not by me manually. In my normal programming I had to convert an mp3 file to wav file using Adobe Audition in order to be able to open it. But now my application browses for an mp3 file and convert it automatically (and fast) in background.The good point is that before I find this solution, I could not write a program to work with mp3 files, but now I am able to write a program that not only it can process mp3 files but all known files by ffmpeg like mkv, mp4, wma, .... – M Ahmadzadeh Aug 31 '18 at 19:19