Documentation de la bibliothèque MLV-3.1.0

advanced/04_sound.c

Ce programme montre comment il est possible de faire jouer des échantillons sonores à votre programme.

#include <MLV/MLV_all.h>
//
// Attention !
// Pour pouvoir compiler ce programme sous windows et sous macintosh,
// il faut, pour la déclaration du main, respecter strictement la syntaxe
// suivante :
//
int main( int argc, char *argv[] ){
MLV_Sound* sound;
//
// Créer ne fenetre
//
MLV_create_window( "advanced - 4 - sound", "sound", 640, 480 );
//
// Initialise l'infrastructure son de la librairie MLV.
//
if( MLV_init_audio() ){
fprintf(
stderr,
"L'infrasctructure audio de la librairie MLV ne s'est pas \
correctement initialisé."
);
exit(1);
}
//
// Charge en mémoire un fichier contenant un morceau de musique.
//
sound = MLV_load_sound( "gallop.ogg" );
//
// Affiche la consigne
//
10,100,
"Appuyer sur une touche pour faire jouer du son.",
);
10,160,
"Pour quitter, appuyer sur la touche echap.",
);
//
// Des que l'utilisateur appuye sur une touche, on joue de la musique.
// Tant que l'utilisateur n'appuye pas sur echap, le programe continue
// à tourner
//
touche=MLV_KEYBOARD_NONE;
while( touche != MLV_KEYBOARD_ESCAPE ){
MLV_wait_keyboard( &touche, NULL, NULL);
MLV_play_sound( sound, 1.0 );
}
//
// Arrête toutes les échantillons.
//
//
// Ferme les morceaux de musiques qui ont été ouverts.
//
MLV_free_sound( sound );
//
// Arrête l'infrastructure son de la librairie MLV.
//
//
// Ferme la fenetre
//
return 0;
}
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010,2011,2012,2013 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
MLV_free_audio
void MLV_free_audio()
Ferme proprement les différents périphériques audios.
MLV_create_window
void MLV_create_window(const char *window_name, const char *icone_name, unsigned int width, unsigned int height)
Créé une fenêtre dont la taille, et les différents noms sont passés en paramètres.
MLV_Keyboard_button
MLV_Keyboard_button
Énumère l'ensemble des codes des touches du clavier.
Definition: MLV_keyboard.h:50
MLV_free_window
void MLV_free_window()
Ferme la fenêtre de la bibliothèque MLV.
MLV_stop_all_sounds
void MLV_stop_all_sounds()
Arrête tous les échantillons sonores.
MLV_update_window
void MLV_update_window()
Met à jour l'affichage de la fenêtre.
MLV_draw_text
void MLV_draw_text(int x, int y, const char *text, MLV_Color color,...)
Imprime un texte donné à une position et une couleur données.
MLV_COLOR_GREEN
#define MLV_COLOR_GREEN
Definition: MLV_color.h:931
MLV_Sound
struct _MLV_Sound MLV_Sound
Ce type code un échantillon sonore.
Definition: MLV_audio.h:53
MLV_play_sound
void MLV_play_sound(const MLV_Sound *sound, float volume)
Joue un échantillon sonore chargé en mémoire.
MLV_free_sound
void MLV_free_sound(MLV_Sound *sound)
Ferme un échantillon sonore chargé en mémoire.
MLV_all.h
Fichier d'entête principal incluant tous les autres fichiers entêtes de la bibliothèque MLV.
MLV_load_sound
MLV_Sound * MLV_load_sound(const char *file_sound)
Charge un ficher contenant un échantillon sonore en mémoire.
MLV_init_audio
int MLV_init_audio()
Cette fonction initialise la bibliothèque MLV pour pouvoir jouer de la musique et des sons.
MLV_wait_keyboard
void MLV_wait_keyboard(MLV_Keyboard_button *sym, MLV_Keyboard_modifier *mod, int *unicode)
Suspend l'exécution jusqu'à ce que l'utilisateur appuie sur une touche du clavier.