RE: [Flashcoders] Determining sound sample rate?
I would go for the second frame. I've done some testing with loading MP3's in bytearrays then creating a SWF in a bytearray with the mp3 data. When I use the info from frame 1, 50% of the mp3's play with a wrong samplerate/bitrate. I think this is done by the Xing encoder. When I skip frame 1, all is ok. Greetz, Bernard -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens ben gomez farrell Verzonden: woensdag 23 april 2008 3:42 Aan: Flash Coders List Onderwerp: Re: [Flashcoders] Determining sound sample rate? Thanks! That should get me on my way. This, in combination with the last reply about getting raw ID3, should help me out. So thanks to both of ya. ben Juan Pablo Califano wrote: Hi, as far as I know, the info you're looking for is not in the ID3 tags (which are not mandatory by the way). An mp3 file is a formed by an arbitrary number of frames, which carry information about chunks of the sound stream; each one contains a header and the actual audio data. There's no global file header, but if you're looking for the sample rate, I think it's fair to assume that the sample rate stored in the header of the first frame is the sample rate of the whole file (that might not be true if you were looking for, say, the bitrate). So, I think you can get that data if you read the file directly in binary format, look for the first frame, and read the bits indicating the sample rate. A good reference for the format spec: http://mpgedit.org/mpgedit/mpeg_format/MP3Format.html And this graphic may help to visualize the meaning of each bit in a frame header: http://upload.wikimedia.org/wikipedia/commons/0/01/Mp3filestructure.svg By the way, if you want to inspect the raw file, you should use an hexadecimal editor, you won't get far with a text editor. There are many available, some of them are free, like Hexplorer, which is what I've been using for a while. ( you can find it here: http://artemis.wszib.edu.pl/~mdudek/ ) I don't know much about the mp3 format specifically, but I have worked a bit with raw files, so if you want to give it a try and need some help, maybe I can lend you a hand. Cheers Juan Pablo Califano 2008/4/21, Steven Sacks [EMAIL PROTECTED]: Ben has an open source project on Google code that is the evolution of his old classes called Metaphile. http://code.google.com/p/metaphile/ ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Determining sound sample rate?
Bernard, are you sure the sample rate is sometimes wrong in the first frame or you mean just the bitrate? I've put some code together to read the tags and I always seem to get the right value for the sample rate (even for Xing-encoded mp3's -- assuming those are the ones with a Xing string within the first frame). In most cases, it's true that the bitrate in the first frame doesn't match the bitrate you can read if you hover the file name in Windows Explorer (in Windows, of course), but that's most likely due to variable bitrates. (By the way, I'm curious about how the explorer -- or any other software -- determines that average bitrate; is it really an average of all frames, is just the bitrate of a fixed frame... does anyone have any clue?) Anyway, it seems in some cases, the first frame stores some kind of metadata (I've seen the string LAME3.92 within the first frame of a Xing-encoded file, for instance), so it's probably a good idea to go for the second frame. Cheers Juan Pablo Califano 2008/4/23, Bernard Visscher [EMAIL PROTECTED]: I would go for the second frame. I've done some testing with loading MP3's in bytearrays then creating a SWF in a bytearray with the mp3 data. When I use the info from frame 1, 50% of the mp3's play with a wrong samplerate/bitrate. I think this is done by the Xing encoder. When I skip frame 1, all is ok. Greetz, Bernard -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens ben gomez farrell Verzonden: woensdag 23 april 2008 3:42 Aan: Flash Coders List Onderwerp: Re: [Flashcoders] Determining sound sample rate? Thanks! That should get me on my way. This, in combination with the last reply about getting raw ID3, should help me out. So thanks to both of ya. ben Juan Pablo Califano wrote: Hi, as far as I know, the info you're looking for is not in the ID3 tags (which are not mandatory by the way). An mp3 file is a formed by an arbitrary number of frames, which carry information about chunks of the sound stream; each one contains a header and the actual audio data. There's no global file header, but if you're looking for the sample rate, I think it's fair to assume that the sample rate stored in the header of the first frame is the sample rate of the whole file (that might not be true if you were looking for, say, the bitrate). So, I think you can get that data if you read the file directly in binary format, look for the first frame, and read the bits indicating the sample rate. A good reference for the format spec: http://mpgedit.org/mpgedit/mpeg_format/MP3Format.html And this graphic may help to visualize the meaning of each bit in a frame header: http://upload.wikimedia.org/wikipedia/commons/0/01/Mp3filestructure.svg By the way, if you want to inspect the raw file, you should use an hexadecimal editor, you won't get far with a text editor. There are many available, some of them are free, like Hexplorer, which is what I've been using for a while. ( you can find it here: http://artemis.wszib.edu.pl/~mdudek/ ) I don't know much about the mp3 format specifically, but I have worked a bit with raw files, so if you want to give it a try and need some help, maybe I can lend you a hand. Cheers Juan Pablo Califano 2008/4/21, Steven Sacks [EMAIL PROTECTED]: Ben has an open source project on Google code that is the evolution of his old classes called Metaphile. http://code.google.com/p/metaphile/ ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] Determining sound sample rate?
Well, I was just looking @ my code when you posted this. I found that I read the channels wrong for stereo (not joint), I use the channel data to calculate how many samples I need. I now tried starting @ frame 1 and no problems yet. So I think it's my mistake, but I can't see why frame 2 always worked for me :S About the Meta data, that's true, but that is ignored when the correct seek is used :) -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Juan Pablo Califano Verzonden: woensdag 23 april 2008 14:40 Aan: Flash Coders List Onderwerp: Re: [Flashcoders] Determining sound sample rate? Bernard, are you sure the sample rate is sometimes wrong in the first frame or you mean just the bitrate? I've put some code together to read the tags and I always seem to get the right value for the sample rate (even for Xing-encoded mp3's -- assuming those are the ones with a Xing string within the first frame). In most cases, it's true that the bitrate in the first frame doesn't match the bitrate you can read if you hover the file name in Windows Explorer (in Windows, of course), but that's most likely due to variable bitrates. (By the way, I'm curious about how the explorer -- or any other software -- determines that average bitrate; is it really an average of all frames, is just the bitrate of a fixed frame... does anyone have any clue?) Anyway, it seems in some cases, the first frame stores some kind of metadata (I've seen the string LAME3.92 within the first frame of a Xing-encoded file, for instance), so it's probably a good idea to go for the second frame. Cheers Juan Pablo Califano 2008/4/23, Bernard Visscher [EMAIL PROTECTED]: I would go for the second frame. I've done some testing with loading MP3's in bytearrays then creating a SWF in a bytearray with the mp3 data. When I use the info from frame 1, 50% of the mp3's play with a wrong samplerate/bitrate. I think this is done by the Xing encoder. When I skip frame 1, all is ok. Greetz, Bernard -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens ben gomez farrell Verzonden: woensdag 23 april 2008 3:42 Aan: Flash Coders List Onderwerp: Re: [Flashcoders] Determining sound sample rate? Thanks! That should get me on my way. This, in combination with the last reply about getting raw ID3, should help me out. So thanks to both of ya. ben Juan Pablo Califano wrote: Hi, as far as I know, the info you're looking for is not in the ID3 tags (which are not mandatory by the way). An mp3 file is a formed by an arbitrary number of frames, which carry information about chunks of the sound stream; each one contains a header and the actual audio data. There's no global file header, but if you're looking for the sample rate, I think it's fair to assume that the sample rate stored in the header of the first frame is the sample rate of the whole file (that might not be true if you were looking for, say, the bitrate). So, I think you can get that data if you read the file directly in binary format, look for the first frame, and read the bits indicating the sample rate. A good reference for the format spec: http://mpgedit.org/mpgedit/mpeg_format/MP3Format.html And this graphic may help to visualize the meaning of each bit in a frame header: http://upload.wikimedia.org/wikipedia/commons/0/01/Mp3filestructure.svg By the way, if you want to inspect the raw file, you should use an hexadecimal editor, you won't get far with a text editor. There are many available, some of them are free, like Hexplorer, which is what I've been using for a while. ( you can find it here: http://artemis.wszib.edu.pl/~mdudek/ ) I don't know much about the mp3 format specifically, but I have worked a bit with raw files, so if you want to give it a try and need some help, maybe I can lend you a hand. Cheers Juan Pablo Califano 2008/4/21, Steven Sacks [EMAIL PROTECTED]: Ben has an open source project on Google code that is the evolution of his old classes called Metaphile. http://code.google.com/p/metaphile/ ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http
Re: [Flashcoders] Determining sound sample rate?
Hi, as far as I know, the info you're looking for is not in the ID3 tags (which are not mandatory by the way). An mp3 file is a formed by an arbitrary number of frames, which carry information about chunks of the sound stream; each one contains a header and the actual audio data. There's no global file header, but if you're looking for the sample rate, I think it's fair to assume that the sample rate stored in the header of the first frame is the sample rate of the whole file (that might not be true if you were looking for, say, the bitrate). So, I think you can get that data if you read the file directly in binary format, look for the first frame, and read the bits indicating the sample rate. A good reference for the format spec: http://mpgedit.org/mpgedit/mpeg_format/MP3Format.html And this graphic may help to visualize the meaning of each bit in a frame header: http://upload.wikimedia.org/wikipedia/commons/0/01/Mp3filestructure.svg By the way, if you want to inspect the raw file, you should use an hexadecimal editor, you won't get far with a text editor. There are many available, some of them are free, like Hexplorer, which is what I've been using for a while. ( you can find it here: http://artemis.wszib.edu.pl/~mdudek/ ) I don't know much about the mp3 format specifically, but I have worked a bit with raw files, so if you want to give it a try and need some help, maybe I can lend you a hand. Cheers Juan Pablo Califano 2008/4/21, Steven Sacks [EMAIL PROTECTED]: Ben has an open source project on Google code that is the evolution of his old classes called Metaphile. http://code.google.com/p/metaphile/ ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Determining sound sample rate?
Thanks! That should get me on my way. This, in combination with the last reply about getting raw ID3, should help me out. So thanks to both of ya. ben Juan Pablo Califano wrote: Hi, as far as I know, the info you're looking for is not in the ID3 tags (which are not mandatory by the way). An mp3 file is a formed by an arbitrary number of frames, which carry information about chunks of the sound stream; each one contains a header and the actual audio data. There's no global file header, but if you're looking for the sample rate, I think it's fair to assume that the sample rate stored in the header of the first frame is the sample rate of the whole file (that might not be true if you were looking for, say, the bitrate). So, I think you can get that data if you read the file directly in binary format, look for the first frame, and read the bits indicating the sample rate. A good reference for the format spec: http://mpgedit.org/mpgedit/mpeg_format/MP3Format.html And this graphic may help to visualize the meaning of each bit in a frame header: http://upload.wikimedia.org/wikipedia/commons/0/01/Mp3filestructure.svg By the way, if you want to inspect the raw file, you should use an hexadecimal editor, you won't get far with a text editor. There are many available, some of them are free, like Hexplorer, which is what I've been using for a while. ( you can find it here: http://artemis.wszib.edu.pl/~mdudek/ ) I don't know much about the mp3 format specifically, but I have worked a bit with raw files, so if you want to give it a try and need some help, maybe I can lend you a hand. Cheers Juan Pablo Califano 2008/4/21, Steven Sacks [EMAIL PROTECTED]: Ben has an open source project on Google code that is the evolution of his old classes called Metaphile. http://code.google.com/p/metaphile/ ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Determining sound sample rate?
You are probably best off finding some code that reads the file headers from an MP3 file and do this manually as the Sound API's are not upto this. Not quite what you want, but here is a starter for 10 that reads ID3 tags: http://blog.benstucki.net/?id=24 ben gomez farrell wrote: OK, I totally don't mean to rehash the debate on the sound player bug - but like a week after you all had that conversation, I'm actually running into something that's related. My problem is using Sound.play(), and passing in the milliseconds. As you might be aware, the milliseconds is only accurate if you use 44.1khz sound. But, fortunately, it's a simple equation to run on your time to get the time parameter with the desired effect. So now, as long as I know the sampling rate, I can pause and play to my heart's content. I wanted to take it one step further though.is there any way to get the sampling rate through code? I imagine if you got the bytestotal and the length of the sound it would related, but that might be thrown off by the fact that it was mono or stereo. Has anybody come up with a good way of determining this? thanks! ben ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders -- Glen Pike 01326 218440 www.glenpike.co.uk http://www.glenpike.co.uk ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Determining sound sample rate?
Thanks! This crossed my mind - and I even popped open an MP3 in word pad to see if anything was written in plan text. High hopes I know, but no luck. I guess thats what I'll have to resort to. thanks again ben Glen Pike wrote: You are probably best off finding some code that reads the file headers from an MP3 file and do this manually as the Sound API's are not upto this. Not quite what you want, but here is a starter for 10 that reads ID3 tags: http://blog.benstucki.net/?id=24 ben gomez farrell wrote: OK, I totally don't mean to rehash the debate on the sound player bug - but like a week after you all had that conversation, I'm actually running into something that's related. My problem is using Sound.play(), and passing in the milliseconds. As you might be aware, the milliseconds is only accurate if you use 44.1khz sound. But, fortunately, it's a simple equation to run on your time to get the time parameter with the desired effect. So now, as long as I know the sampling rate, I can pause and play to my heart's content. I wanted to take it one step further though.is there any way to get the sampling rate through code? I imagine if you got the bytestotal and the length of the sound it would related, but that might be thrown off by the fact that it was mono or stereo. Has anybody come up with a good way of determining this? thanks! ben ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Determining sound sample rate?
Ben has an open source project on Google code that is the evolution of his old classes called Metaphile. http://code.google.com/p/metaphile/ ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders