# (Time) Length of SDL\_mixer chunks?

**URL:** <https://discourse.libsdl.org/t/time-length-of-sdl-mixer-chunks/12852>\
**Category:** SDL Development\
**Created:** [December 22, 2005, 9:00pm UTC](https://discourse.libsdl.org/t/time-length-of-sdl-mixer-chunks/12852 "2005-12-22T21:00:18Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![icculus](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/icculus/32/81_2.png) [@icculus](https://discourse.libsdl.org/u/icculus)\
**Post date:** [January 2, 2006, 12:55am UTC](https://discourse.libsdl.org/t/time-length-of-sdl-mixer-chunks/12852/2 "2006-01-02T00:55:18Z")

</div>

> is it possible to get the time length of a loaded chunk in SDL\_mixer? In  
> seconds, ticks, or the like?

/\* untested code follows… \*/  
Uint32 getChunkTimeMilliseconds(Mix\_Chunk _chunk)  
{  
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);

```

}

–ryan.

---

_[View the full topic](https://discourse.libsdl.org/t/time-length-of-sdl-mixer-chunks/12852)._
