Computer Science Canada Anyway to get the length of a music file? |
Author: | copthesaint [ Tue Jun 16, 2009 1:27 pm ] |
Post subject: | Anyway to get the length of a music file? |
I was wondering if anyone could help me get the length of a music file. Thats all. |
Author: | Kharybdis [ Tue Jun 16, 2009 2:08 pm ] |
Post subject: | RE:Anyway to get the length of a music file? |
Only way i can think of right now is to use the Time Commands and to play the song. When it starts the loop again, check how much time it took to play it. There's other ways though.. which are more useful than the one above. |
Author: | copthesaint [ Tue Jun 16, 2009 2:15 pm ] |
Post subject: | Re: Anyway to get the length of a music file? |
yea... Not really usefull at all... Would be a horrible way to get the length. ![]() I want to know how to get the exact length of a song. |
Author: | Dan [ Tue Jun 16, 2009 2:32 pm ] |
Post subject: | RE:Anyway to get the length of a music file? |
There is no comand in turing to get the length or any other data about a music/sound file. In theroy you could make your own command for each file format if you read up on there specs and find out how to extract the length from the file using the read command. Also it might be posible to make a program in another langue that returns the length and call it from turing. |
Author: | andrew. [ Tue Jun 16, 2009 3:31 pm ] |
Post subject: | Re: RE:Anyway to get the length of a music file? |
Dan @ Tue Jun 16, 2009 2:32 pm wrote: Also it might be posible to make a program in another langue that returns the length and call it from turing. |
Author: | BigBear [ Tue Jun 16, 2009 4:20 pm ] |
Post subject: | RE:Anyway to get the length of a music file? |
You could use File.Status to find the size of the file in bytes. Song's are usually a megabyte per minute but that depends on the quality |
Author: | ecookman [ Tue Jun 16, 2009 6:05 pm ] |
Post subject: | RE:Anyway to get the length of a music file? |
in general just right click it and go to properties, or play it and look at the elapsed time at the ens |
Author: | DtY [ Tue Jun 16, 2009 6:23 pm ] |
Post subject: | RE:Anyway to get the length of a music file? |
Are you using uncompressed wavs? If you know that it is sampled at 44.1KHz, and is 16bits/sample (most likely, you might want to double check though), you could figure out the approximate length (if you want the exact length, do the same thing but without the headers) with this forumla: let x = filesize in bytes 44.1KHz at 16bits/sample means that: 1 sec audio = 88200 bytes. therefore: length in seconds =~ floor(x/88200) The headers will throw off your length though. Wav actually stores the filesize of just the data chunk though, so you can easily read the file and look for it. |
Author: | Dan [ Tue Jun 16, 2009 9:39 pm ] |
Post subject: | Re: RE:Anyway to get the length of a music file? |
andrew. @ 16th June 2009, 3:31 pm wrote: Dan @ Tue Jun 16, 2009 2:32 pm wrote: Also it might be posible to make a program in another langue that returns the length and call it from turing. Well there are a few ways. One is a local client/server type system using the Net comands to use a TCP connection to a program made in another langue on the same computer. You could use the exec command witch gets backs at least how the program exited (you could make that equal to the length) or it could make a file with the length. Finaly if you are advanced enought you could try to get the external command to work (witch i have only been able to do in a limited way to load functuons in some of the turing dll files). Or like i side you could make your own system for reading the media file using the read comands. |
Author: | copthesaint [ Tue Jun 16, 2009 11:49 pm ] |
Post subject: | Re: Anyway to get the length of a music file? |
Hmm Dan, What would I have to search to learn how to decode an mp3 file, wav, and midi? I know for Mp3 that the info of the song including duration is in the first line but how do I convert it to text form? I would be interested learning about this. Also whats Music.PreLoad (SongFileName) for? |
Author: | DtY [ Wed Jun 17, 2009 6:21 am ] |
Post subject: | RE:Anyway to get the length of a music file? |
Here's a description of wav: http://ccrma.stanford.edu/courses/422/projects/WaveFormat/ I don't know about mp3 though. |
Author: | BigBear [ Wed Jun 17, 2009 7:23 am ] |
Post subject: | Re: Anyway to get the length of a music file? |
I renamed a .mp3 file to .txt and above all of the garbabled characters there is this Quote: ID3 vTIT2 Walking On The SunPRIV ' WM/MediaClassPrimaryID ?}`?#??K??H?*(DPRIV ) WM/MediaClassSecondaryID TPUB InterscopeTCON (12)PRIV PeakValue ? PRIV AverageLevel G$ TRCK 3TYER 1997PRIV WM/WMContentID ?id???@??X{??zPRIV ? WM/UniqueFileIdentifier A M G a _ i d = R 3 3 0 2 9 8 ; A M G p _ i d = P 2 1 5 6 6 7 ; A M G t _ i d = T 1 6 9 5 4 7 2 TALB Fush Yu Mang [Clean]TPE2 Smash MouthPRIV " WM/WMCollectionID 2"?w?O?B?? PRIV ' WM/WMCollectionGroupID 2"?w?O?B?? PRIV WM/Provider A M G TCOM Smash MouthTPE1 Smash Mouth
How do you get the size from the first line. How do you use read to access a .mp3 file? |
Author: | Dan [ Thu Jun 18, 2009 2:40 am ] |
Post subject: | Re: Anyway to get the length of a music file? |
BigBear @ 17th June 2009, 7:23 am wrote: I renamed a .mp3 file to .txt and above all of the garbabled characters there is this
Quote: ID3 vTIT2 Walking On The SunPRIV ' WM/MediaClassPrimaryID ?}`?#??K??H?*(DPRIV ) WM/MediaClassSecondaryID TPUB InterscopeTCON (12)PRIV PeakValue ? PRIV AverageLevel G$ TRCK 3TYER 1997PRIV WM/WMContentID ?id???@??X{??zPRIV ? WM/UniqueFileIdentifier A M G a _ i d = R 3 3 0 2 9 8 ; A M G p _ i d = P 2 1 5 6 6 7 ; A M G t _ i d = T 1 6 9 5 4 7 2 TALB Fush Yu Mang [Clean]TPE2 Smash MouthPRIV " WM/WMCollectionID 2"?w?O?B?? PRIV ' WM/WMCollectionGroupID 2"?w?O?B?? PRIV WM/Provider A M G TCOM Smash MouthTPE1 Smash Mouth
How do you get the size from the first line. How do you use read to access a .mp3 file? It's a binnary format, meaning it's not in plain text. Each charactor you are seeing is a byte of data of value 0 to 255 witch is interperted based on the format the file is writen in. Since you are opening it in a text editor it is trying to read it as ASCII formated text and showing gibrish as it is realy a mp3 file. As for how, you would have to find the spefication for the type of media file you are dealing with and see if it spefies the length anywhere and then read in thoses bytes and translate it into a time. Read lets you read in (a) byte(s) as some type in turing (be it an int, char, or some kind of record) and you can find out more here: http://compsci.ca/holtsoft/doc/read.html Unforntaly for MPEG Audio (MP3) i don't think the length is simply encoded in format in a few bytes but needs to be determined by some claulations based on the biterate, samplerate, and padding (i don't know what the correct formal is tho, it would take some research on your part). If the MP3 file has ID3 tags it is posible that the length could be found in a tag. More info on ID3 tags can be found here: http://en.wikipedia.org/wiki/ID3 But it should be noted that not all MP3 files have vaild or any ID3 tags. |
Author: | DtY [ Thu Jun 18, 2009 6:49 am ] |
Post subject: | RE:Anyway to get the length of a music file? |
Does this need to work with all MP3s? Or will you be giving out all them that it needs to work with? If you can read ID3 tags, you can put the length manually into the comment field. |