Created
May 31, 2017 22:58
-
-
Save ander94lakx/a8a0a4e8b13e5e28b5b8d20f9a077930 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <SDL2/SDL.h> | |
#include <SDL2/SDL_mixer.h> // Esta vez incluimos el SDL_mixer.h, que hara que todo sea mas facil | |
// OJO: para ello hay que instalar los paquetes | |
// libsdl2-mixer-2.0-0 | |
// libsdl2-mixer-dev | |
// Instalar en Ubuntu: sudo apt-get install libsdl2-mixer-2.0-0 libsdl2-mixer-dev | |
int main(int argc, char **argv) | |
{ | |
// Inicializamos SDL2 | |
SDL_Init(SDL_INIT_AUDIO); | |
// Inicializamos el SDL mixer (es como un reproductor de musica, basicamente, en el que podemos añadir pistas) | |
Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048); | |
// Cargamos el fichero de audio | |
Mix_Chunk* sonido = Mix_LoadWAV("soinuak/piano/DO.wav"); | |
// Si quisieramos reproducir musica, para cargarla hariamos esto: | |
//Mix_Music *musica = Mix_LoadMUS("Cancion.mp3"); | |
// Lo reproducimos | |
Mix_PlayChannel(-1, sonido, 0); | |
// Si en vez de un sonido, quisieramso reproducir la musica, hariamos esto: | |
//Mix_PlayMusic(musica, -1); | |
SDL_Delay(1000); // Esperamos para poder oirlo | |
Mix_FreeChunk(sonido); // Liberamos el sonido | |
//Mix_FreeMusic(musica); | |
Mix_CloseAudio(); // Cerramos el audio | |
SDL_Quit(); // Cerramos SDL2 | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment