Mp3 Compare

Just starting out? Need help? Post your questions and find answers here.
BabyBacon
New User
New User
Posts: 8
Joined: Wed Feb 01, 2006 11:47 pm
Location: Sweden

Mp3 Compare

Post by BabyBacon »

Hi!

This is my first time at pb's forum, and Im pretty new to the whole world of purebasic. Now to my problem. I've tring to compare to mp3files, so I can get the position where the larger mp3file has the same part as in the litle mp3. But I cant figureout how to compare them nice and fast. Should I read the big file to memory and go throu it with some magic algorithm, or?

I want to know how many times that small soundsample exist in the big file, and at what place, not nessisery the position in time.

Must be some easier way to do it then the way Im thinking of.

Many Kisses for the one who can help me :wink:

Ps. the big file is over 1GB, the small is 10KBDs.
Crapholio is coming to town!
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post by josku_x »

Hello!

I am afraid you can't compare the files without loading them somewhere.
Well, I came up with this. It is a modified version of my MCI-Commands.pb file. (I didn't release it on these forums, so no need to search)

Code: Select all

; This is a modified version of MCI-Commands.pb. Made by: Josku_X
Procedure.s GetShortFileName(LongFileName$)
 Static ShortPathName$, RetVal, iLen
 ShortPathName$ = Space(256)
 iLen = Len(ShortPathName$)
 RetVal = GetShortPathName_(LongFileName$, ShortPathName$, iLen)
 ShortFileName$ = Left(ShortPathName$, RetVal)
ProcedureReturn ShortFileName$
EndProcedure
Procedure MCI_OpenFile(Alias$, FileName$)
 ShortName$ = GetShortFileName(FileName$)
 Command=mciSendString_("open " + Chr(34)+FileName$+Chr(34) + " type mpegvideo alias "+Alias$, 0, 0, 0)
If Command=0
 ProcedureReturn #True
Else
 ProcedureReturn #False
EndIf
EndProcedure
Procedure MCI_Close(Alias$)
ProcedureReturn mciSendString_("close " + Alias$, 0, 0, 0)
EndProcedure
Procedure MCI_GetLength(Alias$)
 Buffer.s = Space(256)
 mciSendString_("status " + Alias$ + " length", @Buffer, 256, 0)
ProcedureReturn Val(Buffer)
EndProcedure

SmallFile$=OpenFileRequester("Please select the small file.","","Everything|*.*",0)
LargeFile$=OpenFileRequester("Please select the large file.","","Everything|*.*",0)

If MCI_OpenFile("Small", SmallFile$)
 SmallLength=MCI_GetLength("Small")
 MCI_Close("Small")
EndIf
If MCI_OpenFile("Large", LargeFile$)
 LargeLength=MCI_GetLength("Large")
 MCI_Close("Large")
EndIf

Debug Str(LargeLength/SmallLength)+" Times"
EDIT:
Ps. the big file is over 1GB, the small is 10KBDs.
Are you sure those files are mp3's ??? :?

EDIT2: I tested my code with some movies over 1gb and it is very fast, so you don't have to be afraid of slow loads. (my processor: 3.2 GHz Intel Pentium 4 HT)
BabyBacon
New User
New User
Posts: 8
Joined: Wed Feb 01, 2006 11:47 pm
Location: Sweden

Post by BabyBacon »

Thank you!

I'll try your code right away!

Yes they are mp3, 128kbit. Im recording webradio all day long, thats why its so big files. Im making a study over how many time each song is played.

Hugs & Kissed for you =)
Crapholio is coming to town!
Froggerprogger
Enthusiast
Enthusiast
Posts: 423
Joined: Fri Apr 25, 2003 5:22 pm
Contact:

Post by Froggerprogger »

Ohoh. That means that you try to find audiomaterial in another one, that is not exactly the same. That is not trivial:
- I see no way how a frame-based search inside the MP3 could be realized, because the song will always start at a different time-position inside a frame, so the frame will look totally different
- Even if you decode the MP3s to RAW-PCM, a search will be complicated, because you have to search for samplevalues that are similar, but not exactly similar to the search-data. So you have to define a non-trivial distance-function. Because if the sound is a just bit different each time the song is played, e.g. because it is compressed in a different way, or the loudness is different, your distance-function have to recognize that. In addition if you try to 'find' a song given by a CD-record and so a totally different sound (find clear CD-sound in webradio-stuff-sound) it will be really comprehensive and could reach for a diploma-thesis. You'll have to compare the FFT's then while the blocks for the FFT have to be in sync.

So, good luck! :wink:

Another simple idea: Some webradios stream an information-string about which song is played at the moment. Winamp e.g. shows these strings. You could record them in sync with your MP3 and simply make a text-search for your song.
%1>>1+1*1/1-1!1|1&1<<$1=1
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post by josku_x »

@BabyBacon: WOW! THat was a kiss, but damn, my wife is angry now! :shock: :lol:
BabyBacon
New User
New User
Posts: 8
Joined: Wed Feb 01, 2006 11:47 pm
Location: Sweden

good ide, BUT

Post by BabyBacon »

Hi again!

I dont understand how they can be so diffrent? I record it at the same bitrate, the same everything and its all ready digital. And I also only get that little part of the song that I need. BUT I dont know much about mp3 and sounds so your probebly totaly right :cry:

If some cleaver person figure this out, please tell me :)

Btw It seems hard to make it work cause I cant find anything about this at google either.

// BabyBacon

Ps. Tell your wife it was only a virtual kiss :wink: Ds.
Crapholio is coming to town!
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

cannot, look into theory behind mp3 and lossy music encoding and you see why
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Froggerprogger
Enthusiast
Enthusiast
Posts: 423
Joined: Fri Apr 25, 2003 5:22 pm
Contact:

Post by Froggerprogger »

@BabyBacon
At least give it a try. If the little part you are searching for is from the same material, and not from one of your CDs, it is similar to the material you are searching in. So you might convert the big MP3-file piecewise to WAV-Data (RAW PCM), e.g. using the lame-decoder. Then you could search for it like this:
Just parse the data from start to end and compare it samplewise to your small file. Another way could be to build average-values of e.g. 20 samples and try to compare these ones.
You could improve this by an automatic loudness-correction in this way, that the compared sampleblocks might differ, but the difference must be constant for a while.
Further you could easily ignore the lower 2, 3 or 4 bits, because there nothing else than noise is stored.
%1>>1+1*1/1-1!1|1&1<<$1=1
Post Reply