Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between Mix_Chunk and Mix_Music?

When should I use Mix_Chunk instead of Mix_Music?

like image 421
user1188243 Avatar asked Feb 11 '12 00:02

user1188243


2 Answers

SDL_mixer supports playing both samples and music. The documentation puts it this way:

SDL_mixer is a sample multi-channel audio mixer library.

It supports any number of simultaneously playing channels of 16 bit stereo audio, plus a single channel of music

Since playing both types of audio are supported, there is a structure fo each type.

  • The Mix_Chunk structure represents a sample, or in other words a sound effect.
  • The Mix_Music structure represents a piece of music, something that can be played for an extended period of time, usually repeated.

When you want to play sound effects, you would use a Mix_Chunk and it's associated functions. When you want to play music, you would use a Mix_Music and it's associated functions.

It's important to remember that you can play multiple samples at once, but you can only play one music at a time.

like image 110
Zack The Human Avatar answered Nov 09 '22 08:11

Zack The Human


Mix_Chunk is used for playing sound samples, while Mix_Music is meant to play music.

One key difference between the two is that multiple Mix_Chunk can be played at once on different sound channels, whereas only one Mix_Music may be played at the time.

For example, if you're programming a game, you'd want to use Mix_Music for the background music and Mix_Chunk for sound effects (lasers, powerups, etc.)

More info

like image 36
bitgarden Avatar answered Nov 09 '22 07:11

bitgarden