Re: [pygame] duration of song

2007-07-14 Thread Dave LeCompte (really)
"Jason Coggins" <[EMAIL PROTECTED]> wrote:
> I was wanting to use .mp3 files.

Perhaps this suits your needs:
http://py.vaults.ca/apyllo.py?i=6226313

>>> import mp3
>>> mp3.mp3info("you-spin-me-round.mp3")
{'STEREO': False, 'FREQUENCY': 44100, 'COPYRIGHT': 0L, 'MM': 3, 'LAYER':
2, 'SS' : 2, 'VERSION': 1L, 'MODE': 3L, 'BITRATE': 128}


The duration in seconds would be MM*60+SS - although, I'd be suspicious of
the reliability of the data it generates. For variable bit rate MP3 files,
it uses an average bit rate field in the header, which I suspect might not
always be there, and if it is, it may not be accurate.

It might be close enough for your needs, however.


-Dave LeCompte


Re: [pygame] duration of song

2007-07-14 Thread Jason Coggins

I was wanting to use .mp3 files.

Jason

- Original Message - 
From: "Dave LeCompte (really)" <[EMAIL PROTECTED]>

To: 
Sent: Saturday, July 14, 2007 3:23 AM
Subject: Re: [pygame] duration of song



"Ian Mallett" <[EMAIL PROTECTED]> wrote:


On 7/13/07, Jason Coggins <[EMAIL PROTECTED]> wrote:


Actually I was thinking of using the length of the music played as a
variable in the program.



my_sound = pygame.mixer.sound([filename])
number_of_seconds_long = my_sound.get_length()


That works for OGG and WAV sounds, but does not work for other music
files, like MP3, MOD, and MIDI, right?


The only thing I can think of is:
- play the music through pygame.mixer.music.play()
- monitor the playback time with pygame.mixer.music.get_pos()
- when pygame.mixer.music.get_busy() returns False, you know how long the
music file was. If it helps, you'll know for next time.

That's probably not very helpful, either.


Which file format are you using for your music? Perhaps there is another
Python library that you can use to get the run length of your file.

-Dave LeCompte


Re: [pygame] duration of song

2007-07-14 Thread Jason Coggins
Upon further experimentation I have found that this method does only work for 
.ogg and .wav files but not .mp3 files and such.

I can tell the size of the file in bytes simply by viewing details of the file 
in a window but I was wanting to use different sound files (including some the 
user could load) and thus I needed a way for the program to determine the 
duration (in seconds) of the music file since the music file being played would 
vary.

Jason
  - Original Message - 
  From: Ian Mallett 
  To: pygame-users@seul.org 
  Sent: Saturday, July 14, 2007 4:16 AM
  Subject: Re: [pygame] duration of song


  On 7/14/07, Dave LeCompte (really) <[EMAIL PROTECTED]> wrote:
"Ian Mallett" <[EMAIL PROTECTED]> wrote:

> On 7/13/07, Jason Coggins <[EMAIL PROTECTED]> wrote: 
>>
>> Actually I was thinking of using the length of the music played as a
>> variable in the program.

> my_sound = pygame.mixer.sound([filename])
> number_of_seconds_long = my_sound.get_length() 

That works for OGG and WAV sounds, but does not work for other music
files, like MP3, MOD, and MIDI, right?

  Oh, opps.  You're probably right.  I'm curious now, why don't you know the 
length of the file? 



The only thing I can think of is:
- play the music through pygame.mixer.music.play ()
- monitor the playback time with pygame.mixer.music.get_pos()
- when pygame.mixer.music.get_busy() returns False, you know how long the
music file was. If it helps, you'll know for next time.

That's probably not very helpful, either. 


Which file format are you using for your music? Perhaps there is another
Python library that you can use to get the run length of your file.

-Dave LeCompte




Re: [pygame] duration of song

2007-07-14 Thread Noah Kantrowitz
PyMedia claims to support this, though it mentions you may need to
"play" the file for a second or two to initialize decoding and get the
full length.

--Noah

Dave LeCompte (really) wrote:
>> "Ian Mallett" <[EMAIL PROTECTED]> wrote:
>> On 7/14/07, Dave LeCompte (really) <[EMAIL PROTECTED]> wrote:
> 
>>> That works for OGG and WAV sounds, but does not work for other music
>>> files, like MP3, MOD, and MIDI, right?
>> Oh, opps.  You're probably right.  I'm curious now, why don't you know the
>> length of the file?
> 
> Conceivably, you might want to intelligently deal with music provided by
> the user. For example:
> 
> - some games, including "The Sims", allow players to put their own music
> into a certain directory, and the game will take advantage of the music.
> 
> - some games, including "Monster Rancher", use user-provided music as an
> integral part of gameplay. With "Monster Rancher", players inserted a CD,
> which seeded the procedural content routines for making monsters.
> 
> 
> I was thinking more about some crude ways to get approximate answers, and
> I was thinking that the file size on disk might be a guide to the duration
> of the song. For MP3, I think typical compression ratios (vs a 44kHz 16
> bit stereo WAV file) is something like 11:1, so you can do the math (or,
> better yet, just look at a collection of known MP3s and figure out an
> average multipler) to convert from bytes to seconds.
> 
> However, this doesn't work for MIDI or MOD music - for MIDI, a song with
> four instruments playing in harmony might use four times the space as a
> solo for the same length of time. MOD music is even less predictable, as
> the sound patches are a large part of the file size, and there's little
> knowing how many times any patch might be used.
> 
> 
> That said, I think that specific modules for the various file types exist
> that could be used to determine the duration of MP3 and MIDI, and maybe
> even MOD.
> 
> -Dave LeCompte
> 




signature.asc
Description: OpenPGP digital signature


Re: [pygame] duration of song

2007-07-14 Thread Dave LeCompte (really)
> "Ian Mallett" <[EMAIL PROTECTED]> wrote:
> On 7/14/07, Dave LeCompte (really) <[EMAIL PROTECTED]> wrote:

>> That works for OGG and WAV sounds, but does not work for other music
>> files, like MP3, MOD, and MIDI, right?
>
> Oh, opps.  You're probably right.  I'm curious now, why don't you know the
> length of the file?

Conceivably, you might want to intelligently deal with music provided by
the user. For example:

- some games, including "The Sims", allow players to put their own music
into a certain directory, and the game will take advantage of the music.

- some games, including "Monster Rancher", use user-provided music as an
integral part of gameplay. With "Monster Rancher", players inserted a CD,
which seeded the procedural content routines for making monsters.


I was thinking more about some crude ways to get approximate answers, and
I was thinking that the file size on disk might be a guide to the duration
of the song. For MP3, I think typical compression ratios (vs a 44kHz 16
bit stereo WAV file) is something like 11:1, so you can do the math (or,
better yet, just look at a collection of known MP3s and figure out an
average multipler) to convert from bytes to seconds.

However, this doesn't work for MIDI or MOD music - for MIDI, a song with
four instruments playing in harmony might use four times the space as a
solo for the same length of time. MOD music is even less predictable, as
the sound patches are a large part of the file size, and there's little
knowing how many times any patch might be used.


That said, I think that specific modules for the various file types exist
that could be used to determine the duration of MP3 and MIDI, and maybe
even MOD.

-Dave LeCompte


Re: [pygame] duration of song

2007-07-14 Thread Ian Mallett

On 7/14/07, Dave LeCompte (really) <[EMAIL PROTECTED]> wrote:


"Ian Mallett" <[EMAIL PROTECTED]> wrote:

> On 7/13/07, Jason Coggins <[EMAIL PROTECTED]> wrote:
>>
>> Actually I was thinking of using the length of the music played as a
>> variable in the program.

> my_sound = pygame.mixer.sound([filename])
> number_of_seconds_long = my_sound.get_length()

That works for OGG and WAV sounds, but does not work for other music
files, like MP3, MOD, and MIDI, right?



Oh, opps.  You're probably right.  I'm curious now, why don't you know the
length of the file?

The only thing I can think of is:

- play the music through pygame.mixer.music.play()
- monitor the playback time with pygame.mixer.music.get_pos()
- when pygame.mixer.music.get_busy() returns False, you know how long the
music file was. If it helps, you'll know for next time.

That's probably not very helpful, either.


Which file format are you using for your music? Perhaps there is another
Python library that you can use to get the run length of your file.

-Dave LeCompte



Re: [pygame] duration of song

2007-07-14 Thread Dave LeCompte (really)
"Ian Mallett" <[EMAIL PROTECTED]> wrote:

> On 7/13/07, Jason Coggins <[EMAIL PROTECTED]> wrote:
>>
>> Actually I was thinking of using the length of the music played as a
>> variable in the program.

> my_sound = pygame.mixer.sound([filename])
> number_of_seconds_long = my_sound.get_length()

That works for OGG and WAV sounds, but does not work for other music
files, like MP3, MOD, and MIDI, right?


The only thing I can think of is:
- play the music through pygame.mixer.music.play()
- monitor the playback time with pygame.mixer.music.get_pos()
- when pygame.mixer.music.get_busy() returns False, you know how long the
music file was. If it helps, you'll know for next time.

That's probably not very helpful, either.


Which file format are you using for your music? Perhaps there is another
Python library that you can use to get the run length of your file.

-Dave LeCompte


Re: [pygame] duration of song

2007-07-13 Thread Ian Mallett

my_sound = pygame.mixer.sound([filename])
number_of_seconds_long = my_sound.get_length()

On 7/13/07, Jason Coggins <[EMAIL PROTECTED]> wrote:


Actually I was thinking of using the length of the music played as a
variable in the program.

Jason

- Original Message -
From: "dbcad7" <[EMAIL PROTECTED]>
To: 
Sent: Monday, July 09, 2007 10:55 PM
Subject: RE: [pygame] duration of song


>
> I would thing that WinAmp, or Xmms, or even media player would show you
> that information when you play it..  but I suppose there are more
> complicated ways to find out.  :)
>
>
>
>
> --- On Sun 07/08, Jason Coggins < [EMAIL PROTECTED] > wrote:
> From: Jason Coggins [mailto: [EMAIL PROTECTED]
> To: pygame-users@seul.org
> Date: Sun, 8 Jul 2007 17:51:07 -0400
> Subject: [pygame] duration of song
>
> Does anyone know of a method to determine how long (in time) a music
file
> is?Jason
>
> ___
> Join Excite! - http://www.excite.com
> The most personalized portal on the Web!
>
>




Re: [pygame] duration of song

2007-07-13 Thread Jason Coggins
Actually I was thinking of using the length of the music played as a 
variable in the program.


Jason

- Original Message - 
From: "dbcad7" <[EMAIL PROTECTED]>

To: 
Sent: Monday, July 09, 2007 10:55 PM
Subject: RE: [pygame] duration of song




I would thing that WinAmp, or Xmms, or even media player would show you 
that information when you play it..  but I suppose there are more 
complicated ways to find out.  :)





--- On Sun 07/08, Jason Coggins < [EMAIL PROTECTED] > wrote:
From: Jason Coggins [mailto: [EMAIL PROTECTED]
To: pygame-users@seul.org
Date: Sun, 8 Jul 2007 17:51:07 -0400
Subject: [pygame] duration of song

Does anyone know of a method to determine how long (in time) a music file 
is?Jason


___
Join Excite! - http://www.excite.com
The most personalized portal on the Web!






RE: [pygame] duration of song

2007-07-09 Thread dbcad7

I would thing that WinAmp, or Xmms, or even media player would show you that 
information when you play it..  but I suppose there are more complicated ways 
to find out.  :)




 --- On Sun 07/08, Jason Coggins < [EMAIL PROTECTED] > wrote:
From: Jason Coggins [mailto: [EMAIL PROTECTED]
To: pygame-users@seul.org
Date: Sun, 8 Jul 2007 17:51:07 -0400
Subject: [pygame] duration of song

Does anyone know of a method to determine how long (in time) a music file 
is?Jason 

___
Join Excite! - http://www.excite.com
The most personalized portal on the Web!




Re: [pygame] duration of song

2007-07-08 Thread Ian Mallett

http://www.pygame.org/docs/ref/mixer.html#Sound.get_length

On 7/8/07, Jason Coggins <[EMAIL PROTECTED]> wrote:


Does anyone know of a method to determine how long (in time) a music file
is?

Jason




[pygame] duration of song

2007-07-08 Thread Jason Coggins
Does anyone know of a method to determine how long (in time) a music file 
is?


Jason