How can I set a sleep between loop using sdl-mixer?

566 views Asked by At

I'm trying to play music using SDL2_Mixer library in Ubuntu 18.04.

I succeed to play .wav file loop forever as below code.

#define ERROR_BEEP "../audio/beep.wav"

#include <SDL2/SDL.h>
#include <SDL2/SDL_mixer.h>
    
    void main()
    {
        SDL_AudioSpec wavSpec;
        
        SDL_Init(SDL_INIT_AUDIO)
        Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 4096) >= 0)
        
        SDL_LoadWAV(ERROR_BEEP, &wavSpec, &wavBuffer, &wavLength);
    
        Mix_Music *now_playing_= Mix_LoadMUS(ERROR_BEEP);
        Mix_PlayMusic(now_playing_, -1);

        SDL_Delay(10000);
        Mix_HaltMusic();
        Mix_FreeMusic(now_playing_);
        now_playing_=NULL;
    }

My beep.wav plays well repeatedly. However, the beep file is played immediately and the alarm sound is too loud. (ex: beep!beep!beep!)

Is there any way to put sleep between beep repeating loop? (ex: beep!...beep!...beep!...)

0

There are 0 answers