|
How to get (milli)seconds from al_get_sample_length()? |
TeaRDoWN
Member #8,518
April 2007
|
How do I get seconds or milliseconds from al_get_sample_length()? My ~1s sample return ~6600. I guess the value needs to be divided...or? A5 examples or demos does not cover this. |
raynebc
Member #11,908
May 2010
|
My guess would be to obtain the sample frequency (al_get_sample_instance_frequency) and the number of channels (al_get_channel_count). The frequency is the number of samples per second per channel, so you should be able to find the length in milliseconds with: length = al_get_sample_length(sample) / al_get_channel_count(sample) / al_get_sample_instance_frequency(sample); |
Thomas Fjellstrom
Member #476
June 2000
|
That might also need to take into account stereo samples, you would then need to divide by two. -- |
Trent Gamblin
Member #261
April 2000
|
That'll give you the length in seconds, multiply by 1000 to get milliseconds. The channel count is the stereo part, it'll be 2 for a stereo sample.
|
TeaRDoWN
Member #8,518
April 2007
|
al_get_channel_count() or does not take a ALLEGRO_SOUND as parameter. Did you mean that function or al_get_sample_channels()? al_get_sample_length(sound) = 5641 length / channels / frequency = 0,032 Actual sound length is according to Window Movie Maker 0,5s. length / frequency = 0,51 |
Oscar Giner
Member #2,207
April 2002
|
TeaRDoWN said: al_get_sample_channels(sound) = 16 The value returned by al_get_sample_channels is not the number of channels directly, but one of these constants: ALLEGRO_CHANNEL_CONF_1 ALLEGRO_CHANNEL_CONF_2 ALLEGRO_CHANNEL_CONF_3 ALLEGRO_CHANNEL_CONF_4 ALLEGRO_CHANNEL_CONF_5_1 ALLEGRO_CHANNEL_CONF_6_1 ALLEGRO_CHANNEL_CONF_7_1
-- |
TeaRDoWN
Member #8,518
April 2007
|
Yes, but I just tried to figure out which function raynebc wanted me to use when he wrote al_get_channel_count(sample). |
raynebc
Member #11,908
May 2010
|
Off the top of my head, I don't know which function you should use, but whichever one directly returns the number of channels instead of a macro defined value. I did forget to mention dividing by 1000. |
|