0

I can't get SDL_Mixer to play sound on the raspberry. The program compiles and builds OK, but all I hear is a short squeak (like static) and nothing.

Any ideas?

#include <SDL/SDL.h>
#include <SDL/SDL_mixer.h>
#include <stdio.h>
#include <string>
#include <iostream>

int main()
{
    Mix_Chunk *snd1 = NULL;
    Mix_Music *m = NULL;

    if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
        std::cout << "Something went wrong";
    }

    if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024) < 0) {
        std::cout << "Kunne ikke loade musikk";
    }

    snd1 = Mix_LoadWAV("bicycle_bell.wav");

    if(snd1 == NULL) {
        std::cout << "Fant ikke filen";
    }

    Mix_PlayChannel(-1, snd1, 0);

    Mix_FreeChunk(snd1);
    Mix_Quit();

    return 1;
}
LogicStuff
  • 19,397
  • 6
  • 54
  • 74
Crytrus
  • 751
  • 1
  • 8
  • 14

1 Answers1

0

Solved it. The program terminated before the sound was playing.

When testing a simple:

while(Mix_playing(sound)); 

fixed it.

Crytrus
  • 751
  • 1
  • 8
  • 14