When should I use Mix_Chunk
instead of Mix_Music
?
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.
Mix_Chunk
structure represents a sample, or in other words a sound effect.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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With