Skip to content

Instantly share code, notes, and snippets.

@araml
Last active April 15, 2018 23:44
Show Gist options
  • Select an option

  • Save araml/7191ba537e497cc1ccd7e0199c65bdc6 to your computer and use it in GitHub Desktop.

Select an option

Save araml/7191ba537e497cc1ccd7e0199c65bdc6 to your computer and use it in GitHub Desktop.

Revisions

  1. araml revised this gist Apr 15, 2018. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions sdl_mixer_test.cpp
    Original file line number Diff line number Diff line change
    @@ -18,8 +18,8 @@ int main(int argc, char **argv) {
    bool run = true;
    SDL_Event e;

    Mix_Music *m1 = Mix_LoadMUS("mp3file"),
    *m2 = Mix_LoadMUS("mp3file");
    Mix_Music *m1 = Mix_LoadMUS("mp3file1"),
    *m2 = Mix_LoadMUS("mp3file2");


    Mix_PlayMusic(m1, -1);
    @@ -33,11 +33,11 @@ int main(int argc, char **argv) {
    }
    auto nnew = steady_clock::now();

    if (nnew - old > seconds{7} && m1_running) {
    if (nnew - old > seconds{4} && m1_running) {
    Mix_PlayMusic(m2, -1);
    old = nnew;
    m1_running = false;
    } else if (nnew - old > seconds{7}) {
    } else if (nnew - old > seconds{4}) {
    Mix_PlayMusic(m1, -1);
    old = nnew;
    m1_running = true;
  2. araml created this gist Apr 15, 2018.
    49 changes: 49 additions & 0 deletions sdl_mixer_test.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    // g++ sdl_mixer_test.cpp -o sdl_mixer -lSDL2 -lSDL2_mixer -std=c++11
    #include <SDL2/SDL.h>
    #include <chrono>
    #include <SDL2/SDL_mixer.h>

    using namespace std::chrono;

    SDL_Window *window = NULL;

    int main(int argc, char **argv) {
    SDL_Init(SDL_INIT_VIDEO);

    Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024);

    window = SDL_CreateWindow("Audio", SDL_WINDOWPOS_UNDEFINED,
    SDL_WINDOWPOS_UNDEFINED, 640, 400, SDL_WINDOW_SHOWN);

    bool run = true;
    SDL_Event e;

    Mix_Music *m1 = Mix_LoadMUS("mp3file"),
    *m2 = Mix_LoadMUS("mp3file");


    Mix_PlayMusic(m1, -1);

    auto old = steady_clock::now();
    bool test, m1_running = true;
    while (run) {
    while (SDL_PollEvent(&e)) {
    if (e.type == SDL_QUIT)
    run = false;
    }
    auto nnew = steady_clock::now();

    if (nnew - old > seconds{7} && m1_running) {
    Mix_PlayMusic(m2, -1);
    old = nnew;
    m1_running = false;
    } else if (nnew - old > seconds{7}) {
    Mix_PlayMusic(m1, -1);
    old = nnew;
    m1_running = true;
    }
    }

    return 0;
    }