Total time of a sample

Any way I can get the total time (probably in milliseconds) of a sample
(Mix_Chunk) with SDL_Mixer?

Hi,

Try using Mix_QuerySpec to get the output frequency, sampleformat and
output channel count. Use this to calculate the output data rate
frequency * sample resolution * output channel count. For 16bit stereo
at 44100 sampling frequency (CD-Quality) you get 1411200bit/sec =
176400byte/sec. Use Mix_Chunk->alen for getting the size of the sample
and divide it by the output data rate. This should get you the exact or
rough sample duration, depending on whether SDL_Mixer pads frames or so.

Nikos Chantziaras schrieb:> Any way I can get the total time (probably in milliseconds) of a

sample (Mix_Chunk) with SDL_Mixer?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I was just looking at Ryan’s old code for this:

Uint32 points = 0;
Uint32 frames = 0;
int freq = 0;
Uint16 fmt = 0;
int chans = 0;
/* Chunks are converted to audio device format… /
if (!Mix_QuerySpec(&freq, &fmt, &chans))
return 0; /
never called Mix_OpenAudio()?! */

/* bytes / samplesize == sample points */
points = (chunk->alen / ((fmt & 0xFF) / 8));

/* sample points / channels == sample frames */
frames = (points / chans);

/* (sample frames * 1000) / frequency == play length in ms */
return ((frames * 1000) / freq);

The same can’t be done with the Mix_Music struct since it’s so opaque and
format-specific. I think this calls for SDL_sound… If anyone who knows
about this is listening, how mature is SDL_sound’s mixer?

Jonny DOn Tue, Apr 27, 2010 at 10:50 AM, Christoph Nelles <evilazrael at evilazrael.de wrote:

Hi,

Try using Mix_QuerySpec to get the output frequency, sampleformat and
output channel count. Use this to calculate the output data rate frequency *
sample resolution * output channel count. For 16bit stereo at 44100 sampling
frequency (CD-Quality) you get 1411200bit/sec = 176400byte/sec. Use
Mix_Chunk->alen for getting the size of the sample and divide it by the
output data rate. This should get you the exact or rough sample duration,
depending on whether SDL_Mixer pads frames or so.

Nikos Chantziaras schrieb:

Any way I can get the total time (probably in milliseconds) of a sample

(Mix_Chunk) with SDL_Mixer?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Thanks, Jonathan. That code sure came in handy!On 04/27/2010 11:19 PM, Jonathan Dearborn wrote:

I was just looking at Ryan’s old code for this:

Uint32 points = 0;
Uint32 frames = 0;
int freq = 0;
Uint16 fmt = 0;
int chans = 0;
/* Chunks are converted to audio device format… /
if (!Mix_QuerySpec(&freq, &fmt, &chans))
return 0; /
never called Mix_OpenAudio()?! */

/* bytes / samplesize == sample points */
points = (chunk->alen / ((fmt & 0xFF) / 8));

/* sample points / channels == sample frames */
frames = (points / chans);

/* (sample frames * 1000) / frequency == play length in ms */
return ((frames * 1000) / freq);

The same can’t be done with the Mix_Music struct since it’s so opaque
and format-specific. I think this calls for SDL_sound… If anyone who
knows about this is listening, how mature is SDL_sound’s mixer?

Jonny D

On Tue, Apr 27, 2010 at 10:50 AM, Christoph Nelles <evilazrael at evilazrael.de <mailto:evilazrael at evilazrael.de>> wrote:

Hi,

Try using Mix_QuerySpec to get the output frequency, sampleformat
and output channel count. Use this to calculate the output data rate
frequency * sample resolution * output channel count. For 16bit
stereo at 44100 sampling frequency (CD-Quality) you get
1411200bit/sec = 176400byte/sec. Use Mix_Chunk->alen for getting the
size of the sample and divide it by the output data rate. This
should get you the exact or rough sample duration, depending on
whether SDL_Mixer pads frames or so.

Nikos Chantziaras schrieb:

    Any way I can get the total time (probably in milliseconds) of a
    sample (Mix_Chunk) with SDL_Mixer?