• Viernes 29 de Marzo de 2024, 14:59

Autor Tema:  Re: Como Poner Un Wav En Allegro  (Leído 2926 veces)

Cesar2990

  • Nuevo Miembro
  • *
  • Mensajes: 7
    • Ver Perfil
Re: Como Poner Un Wav En Allegro
« en: Domingo 15 de Junio de 2008, 03:15 »
0
Hola amigos e estado intentado ponerle sonido a mi juego pero no da aca les dejo el codigo espero q me puedan ayudar o si hay algun otro codigo les agradeceria que lo postearan gracias :D

Código: Text
  1.  
  2.  
  3. #include "allegro.h"
  4.  
  5. int main(int argc, char *argv[])
  6. {
  7.    SAMPLE *the_sample;
  8.    int pan = 128;
  9.    int pitch = 1000;
  10.  
  11.    allegro_init();
  12.  
  13.    if (argc != 2) {
  14.       allegro_message("Usage: 'exsample filename.[wav|voc]'\n");
  15.       return 1;
  16.    }
  17.  
  18.    install_keyboard();
  19.    install_timer();
  20.  
  21.    /* install a digital sound driver */
  22.    if (install_sound(DIGI_AUTODETECT, MIDI_NONE, argv[0]) != 0) {
  23.       allegro_message("Error initialising sound system\n%s\n", allegro_error);
  24.       return 1;
  25.    }
  26.  
  27.    /* read in the WAV file */
  28.    the_sample = load_sample("Incio.wav");//argv[1]);
  29.    if (!the_sample) {
  30.       allegro_message("Error reading WAV file '%s'\n", argv[1]);
  31.       return 1;
  32.    }
  33.  
  34.    if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0) {
  35.       set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
  36.       allegro_message("Unable to set any graphic mode\n%s\n", allegro_error);
  37.       return 1;
  38.    }
  39.    set_palette(desktop_palette);
  40.    clear_to_color(screen, makecol(255,255,255));
  41.    text_mode(-1);
  42.  
  43.    textprintf_centre(screen, font, SCREEN_W/2, SCREEN_H/3, makecol(0, 0, 0),
  44.          "Driver: %s", digi_driver->name);
  45.    textprintf_centre(screen, font, SCREEN_W/2, SCREEN_H/2, makecol(0, 0, 0),
  46.          "Playing %s", argv[1]);
  47.    textprintf_centre(screen, font, SCREEN_W/2, SCREEN_H*2/3, makecol(0, 0, 0),
  48.          "Use the arrow keys to adjust it");
  49.  
  50.    /* start up the sample */
  51.    play_sample(the_sample, 255, pan, pitch, TRUE);
  52.  
  53.    do {
  54.       poll_keyboard();
  55.  
  56.       /* alter the pan position? */
  57.       if ((key[KEY_LEFT]) && (pan > 0))
  58.    pan--;
  59.       else if ((key[KEY_RIGHT]) && (pan < 255))
  60.    pan++;
  61.  
  62.       /* alter the pitch? */
  63.       if ((key[KEY_UP]) && (pitch < 16384))
  64.    pitch = ((pitch * 513) / 512) + 1;
  65.       else if ((key[KEY_DOWN]) && (pitch > 64))
  66.    pitch = ((pitch * 511) / 512) - 1;
  67.  
  68.       /* adjust the sample */
  69.       adjust_sample(the_sample, 255, pan, pitch, TRUE);
  70.  
  71.       /* delay a bit */
  72.       rest(2);
  73.  
  74.    } while ((!key[KEY_ESC]) && (!key[KEY_SPACE]));
  75.  
  76.    /* destroy the sample */
  77.    destroy_sample(the_sample);
  78.  
  79.    return 0;
  80. }
  81.  
  82. END_OF_MAIN();
  83.  
  84.  

Cesar2990

  • Nuevo Miembro
  • *
  • Mensajes: 7
    • Ver Perfil
Re: Como Poner Un Wav En Allegro
« Respuesta #1 en: Miércoles 18 de Junio de 2008, 06:11 »
0
Bueno para los que algun dia quiera ponerle audio a su juego aca dejo el codigo hasta pronto

Código: Text
  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <allegro.h> //   <--- OJO, no olvidar cargar el binario en Proyecto-> Propiedades-> parámetros
  5.  
  6. int main(int argc, char *argv[])
  7. {  int  x;
  8.   // Inicializamos Allegro
  9. allegro_init();
  10.  
  11. // Instalamos driver de sonido, si devuelve un 0 es porque funciona correctamente
  12.     x = install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL);
  13.   if (x != 0 ) { printf("\nError con el driver de sonido");  return 1;  }
  14.  
  15. // cargamos el "sample"  - fichero de sonido digital -
  16.  SAMPLE *sample = load_wav("sonido.wav");
  17.  if (!sample) {    printf("Error leyendo  el fichero de sonido\n"); return 2; }
  18.  
  19.  // Hacemos sonar el sample                // 100 = volumen   128 = sonido balanceado   0 = sin bucle
  20.     play_sample(sample,100,128,1000,0);
  21.    
  22.    
  23.   system("PAUSE");    
  24.   return 0;
  25. }
  26.  
  27. END_OF_MAIN();
  28.  
  29.