程式語言 - Simple DirectMedia Layer (SDL) - v1.2 - C/C++ - Music Effect from Memory



參考資訊:
https://www.libsdl.org/release/SDL-1.2.15/docs/html/index.html

main.c

#include <stdio.h>
#include <stdlib.h>
#include <SDL.h>
#include <SDL_mixer.h>

#include "hex_wav.h"
#include "hex_effect.h"

int main(int argc, char **argv)
{
    SDL_RWops *rw = NULL;

    SDL_Init(SDL_INIT_AUDIO);
    Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 4096);

    rw = SDL_RWFromMem(hex_wav, sizeof(hex_wav));
    Mix_Music *music = Mix_LoadMUS_RW(rw);

    rw = SDL_RWFromMem(hex_effect, sizeof(hex_effect));
    Mix_Chunk *effect = Mix_LoadWAV_RW(rw, 1);

    Mix_PlayMusic(music, 1);
    Mix_PlayChannel(-1, effect, 0);
    SDL_Delay(3000);

    Mix_HaltMusic();
    Mix_FreeChunk(effect);
    Mix_FreeMusic(music);
    Mix_CloseAudio();
    SDL_Quit();
    return 0;
}

編譯

$ gcc main.c -o main -lSDL -lSDL_mixer -I/usr/include/SDL