5

When should I use Mix_Chunk instead of Mix_Music?

Zsolt Botykai
  • 50,406
  • 14
  • 85
  • 110
user1188243
  • 61
  • 1
  • 5

2 Answers2

10

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.

Zack The Human
  • 8,373
  • 7
  • 39
  • 60
  • 2
    Whats the actual difference between them though? Why wouldn't I want to use a Mix_Chunk to play an extended audio file? It seems like Mix_Music is strictly less powerful than Mix_Chunk and has no benefit? Does it stream the audio or something? Is there a reason you're limited to just one? – Alex Sep 13 '14 at 01:02
  • 1
    @Alex, The audio quality of Mix_Chunk and Mix_Music greatly differ. Mix_Music has a better quality while Mix_Chunk gives off audio that sound like its frequencies were limited, thus, giving off a somewhat broken sound as compared to Mix_Music. – kdyz Sep 21 '14 at 02:42
7

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

bitgarden
  • 10,461
  • 3
  • 18
  • 25