Changeset 141

Show
Ignore:
Timestamp:
05/14/07 19:27:04 (1 year ago)
Author:
takkaria
Message:

Switch to new model for producing sound: instead of a TERM_XTRA_SOUND hook, we now have a simple "sound_hook" which should be set to the appropriate function to play a sound. Introduce a new modular system for sound modules for ports that use main.c (for the future, in case we want to use e.g. gstreamer). Allow sound to be toggled as an in-game option. (Closes #122.)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/configure.ac

    r127 r141  
    8686        [enable_sdl=$enableval], 
    8787        [enable_sdl=no]) 
     88 
     89dnl Sound modules 
     90AC_ARG_ENABLE(sdl_mixer, 
     91        [  --disable-sdl-mixer                  Disables SDL mixer sound support], 
     92        [disable_sdl_mixer=$disable_sdl_mixer], 
     93        [disable_sdl_mixer=no]) 
     94 
    8895 
    8996dnl curses checking 
     
    169176fi 
    170177 
     178dnl SDL mixer checking 
     179 
     180if test "$disable_sdl_mixer" != "yes"; then 
     181        AC_CHECK_LIB(SDL_mixer, Mix_OpenAudio, found_sdl_mixer=yes, found_sdl_mixer=no) 
     182 
     183        if test "$found_sdl_mixer" = "yes"; then 
     184                AC_DEFINE(SDL_SOUND, 1, [Enabled SDL_mixer sound support]) 
     185                LDFLAGS="${LDFLAGS} -lSDL_mixer" 
     186        else 
     187                AC_DEFINE(SDL_SOUND, 0, [Disabled SDL_mixer sound support]) 
     188        fi 
     189fi 
     190 
     191 
    171192dnl Check for headers. 
    172193dnl AC_HEADER_STDBOOL -- not yet 
  • trunk/src/Makefile.src

    r134 r141  
    1313 
    1414ZFILES = z-file z-form z-rand z-term z-type z-util z-virt 
    15 MAINFILES = main maid-x11
    16         $(addprefix main-,crb gcu gtk ros sdl win x11 xaw) 
     15MAINFILES = main maid-x11 main-crb main-gcu main-gtk main-ros main-sdl
     16            main-win main-x11 main-xaw snd-sdl 
    1717 
    1818ANGFILES = \ 
     
    5858        xtra2 
    5959 
     60 
  • trunk/src/Makefile.std

    r128 r141  
    4646 
    4747 
     48## Support SDL_mixer for sound 
     49#SOUND_sdl = -DSOUND_SDL $(shell sdl-config --cflags) $(shell sdl-config --libs) -lSDL_mixer 
     50 
     51 
     52 
    4853# Basic compiler stuff 
    4954CC = gcc 
     
    7378 
    7479# Extract CFLAGS and LIBS from the system definitions 
    75 MODULES = $(SYS_x11) $(SYS_gcu) $(SYS_xaw) $(SYS_gtk) $(SYS_sdl) 
     80MODULES = $(SYS_x11) $(SYS_gcu) $(SYS_xaw) $(SYS_gtk) $(SYS_sdl) $(SOUND_sdl) 
    7681CFLAGS += $(patsubst -l%,,$(MODULES)) $(INCLUDES) 
    7782LIBS += $(patsubst -D%,,$(patsubst -I%,, $(MODULES))) 
     
    8994# Object definitions 
    9095X11OBJS = maid-x11.o main-x11.o main-xaw.o main-gtk.o 
    91 MAINOBJS = main.o main-gcu.o main-sdl.o $(X11OBJS) 
     96MAINOBJS = main.o main-gcu.o main-sdl.o snd-sdl.o $(X11OBJS) 
    9297OBJS = $(BASEOBJS) $(MAINOBJS) 
    9398 
     
    171176$(MAINOBJS) : main.h $(INCS) 
    172177 
     178 
  • trunk/src/defines.h

    r137 r141  
    24262426#define OPT_rogue_like_commands         0 
    24272427#define OPT_quick_messages                      1 
    2428  
     2428#define OPT_use_sound               2 
    24292429#define OPT_query_floor                         3 
    24302430#define OPT_use_old_target                      4 
     
    25282528#define rogue_like_commands             op_ptr->opt[OPT_rogue_like_commands] 
    25292529#define quick_messages                  op_ptr->opt[OPT_quick_messages] 
     2530#define use_sound                               op_ptr->opt[OPT_use_sound] 
    25302531#define query_floor                             op_ptr->opt[OPT_query_floor] 
    25312532#define use_old_target                  op_ptr->opt[OPT_use_old_target] 
  • trunk/src/externs.h

    r136 r141  
    111111extern s32b turn; 
    112112extern s32b old_turn; 
    113 extern bool use_sound; 
    114113extern int use_graphics; 
    115114extern bool use_bigtile; 
     
    248247extern int text_out_indent; 
    249248extern bool use_transparency; 
     249extern void (*sound_hook)(int); 
    250250extern autoinscription *inscriptions; 
    251251extern u16b inscriptions_count; 
  • trunk/src/main-crb.c

    r136 r141  
    13021302static SInt16 sound_volume = SOUND_VOLUME_MAX; 
    13031303 
     1304 
     1305 
    13041306/* 
    13051307 * QuickTime sound, by Ron Anderson 
     
    14091411        /* Stop QuickTime */ 
    14101412        ExitMovies(); 
     1413 
     1414        /* Register the sound hook */ 
     1415        sound_hook = play_sound; 
    14111416} 
    14121417 
     
    14901495 * 
    14911496 * Globals referenced: channel_initialised, channels[], samples[], 
    1492  *   sample_refs[]
     1497 *   sample_refs[], sound_volume
    14931498 * Globals updated: channel_initialised, channels[], sample_refs[]. 
    14941499 */ 
    14951500 
    1496 static void play_sound(int num, SInt16 vol
     1501static void play_sound(int num
    14971502{ 
    14981503        OSErr err; 
     
    15051510        static SInt16 channel_occupants[MAX_CHANNELS]; 
    15061511        static SndCommand volume_cmd, quiet_cmd; 
     1512 
     1513        SInt16 vol = sound_volume; 
    15071514 
    15081515        /* Initialise sound channels */ 
     
    15951602} 
    15961603 
     1604 
     1605 
    15971606/*** Support for the "z-term.c" package ***/ 
    15981607 
     
    17111720                        /* Make a noise */ 
    17121721                        SysBeep(1); 
    1713  
    1714                         /* Success */ 
    1715                         return (0); 
    1716                 } 
    1717  
    1718                 /* Make a sound */ 
    1719                 case TERM_XTRA_SOUND: 
    1720                 { 
    1721                         /* Play sound */ 
    1722                         play_sound(v, sound_volume); 
    17231722 
    17241723                        /* Success */ 
  • trunk/src/main-ros.c

    r136 r141  
    35103510                                while ((Time_Monotonic() - start) < v); 
    35113511                        } 
    3512                         return 0; 
    3513                 } 
    3514  
    3515                 /* Play a sound :) */ 
    3516                 case TERM_XTRA_SOUND: 
    3517                 { 
    3518                         if (enable_sound) play_sound(v); 
    3519  
    35203512                        return 0; 
    35213513                } 
     
    70787070 
    70797071 
    7080  
    70817072static void initialise_sound(void) 
    70827073{ 
     
    70857076        read_sound_config(); 
    70867077        check_playit(); 
     7078 
     7079        /* Set the sound hook */ 
     7080        sound_hook = play_sound; 
     7081 
    70877082        Hourglass_Off(); 
    70887083} 
     
    71117106{ 
    71127107        /* Paranoia */ 
    7113         if (!sound_initd) 
    7114         { 
     7108        if (!sound_initd || !enable_sound) 
    71157109                return; 
    7116         } 
    71177110 
    71187111        /* Paranoia */ 
     
    88268819 
    88278820 
     8821 
  • trunk/src/main-win.c

    r136 r141  
    21122112                } 
    21132113 
    2114                 /* Make a special sound */ 
    2115                 case TERM_XTRA_SOUND: 
    2116                 { 
    2117                         return (Term_xtra_win_sound(v)); 
    2118                 } 
    2119  
    21202114                /* Process random events */ 
    21212115                case TERM_XTRA_BORED: 
     
    51015095#endif /* USE_SAVER */ 
    51025096 
     5097#if USE_SOUND 
     5098 
     5099        /* Set the sound hook */ 
     5100        sound_hook = Term_xtra_win_sound(v); 
     5101 
     5102#endif /* USE_SOUND */ 
     5103 
    51035104        /* Did the user double click on a save file? */ 
    51045105        check_for_save_file(lpCmdLine); 
  • trunk/src/main-xxx.c

    r136 r141  
    327327                } 
    328328 
    329                 case TERM_XTRA_SOUND: 
    330                 { 
    331                         /* 
    332                          * Make a sound XXX XXX XXX 
    333                          * 
    334                          * This action should produce sound number "v", where the 
    335                          * "name" of that sound is "sound_names[v]".  This method 
    336                          * is still under construction. 
    337                          * 
    338                          * This action is optional, and not very important. 
    339                          */ 
    340  
    341                         return (0); 
    342                 } 
    343  
    344329                case TERM_XTRA_BORED: 
    345330                { 
     
    709694 
    710695 
     696 
     697/* 
     698 * Make a sound. 
     699 * 
     700 * This action should produce sound number "v", where the 
     701 * "name" of that sound is "sound_names[v]". 
     702 * 
     703 * This action is optional, and not very important. 
     704 */ 
     705static void xxx_sound(int v) 
     706{ 
     707        return; 
     708} 
     709 
     710 
    711711/* 
    712712 * Init some stuff 
     
    726726        /* Prepare the filepaths */ 
    727727        init_file_paths(path); 
     728 
     729 
     730#ifdef USE_SOUND 
     731 
     732        /* Set up sound hook */ 
     733        sound_hook = xxx_sound; 
     734 
     735#endif /* USE_SOUND */ 
    728736} 
    729737 
  • trunk/src/main.c

    r128 r141  
    5252 
    5353 
     54#ifdef USE_SOUND 
     55 
     56/* 
     57 * List of sound modules in the order they should be tried. 
     58 */ 
     59static const struct module sound_modules[] = 
     60{ 
     61#ifdef SOUND_SDL 
     62        { "sdl", "SDL_mixer sound module", init_sound_sdl }, 
     63#endif /* SOUND_SDL */ 
     64 
     65        { "dummy", "Dummy module", NULL }, 
     66}; 
     67 
     68#endif 
     69 
     70 
    5471/* 
    5572 * A hook for "quit()". 
     
    437454                                puts("Usage: angband [options] [-- subopts]"); 
    438455                                puts("  -n       Start a new character"); 
     456                                puts("  -w       Resurrect dead character"); 
    439457                                puts("  -f       Request fiddle (verbose) mode"); 
    440                                 puts("  -w       Request wizard mode"); 
    441458                                puts("  -v       Request sound mode"); 
    442459                                puts("  -g       Request graphics mode"); 
     
    495512        if (!done) quit("Unable to prepare any 'display module'!"); 
    496513 
     514 
     515#ifdef USE_SOUND 
     516 
     517        /* Try the modules in the order specified by sound_modules[] */ 
     518        for (i = 0; i < (int)N_ELEMENTS(sound_modules) - 1; i++) 
     519        { 
     520                if (0 == sound_modules[i].init(argc, argv)) 
     521                        break; 
     522        } 
     523 
     524#endif 
     525 
     526 
    497527        /* Catch nasty signals */ 
    498528        signals_init(); 
  • trunk/src/main.h

    r85 r141  
    1313 
    1414#include "angband.h" 
     15 
     16extern errr init_sound_sdl(int argc, char **argv); 
     17 
    1518 
    1619extern errr init_lfb(int argc, char **argv); 
  • trunk/src/tables.c

    r123 r141  
    13991399        "rogue_like_commands",          /* OPT_rogue_like_commands */ 
    14001400        "quick_messages",                       /* OPT_quick_messages */ 
    1401         NULL,                                          /* xxx floor_query_flag */ 
     1401        "use_sound",                           /* OPT_use_sound */ 
    14021402        "query_floor",                          /* OPT_query_floor */ 
    14031403        "use_old_target",                       /* OPT_use_old_target */ 
     
    16631663        "Rogue-like commands",                                          /* OPT_rogue_like_commands */ 
    16641664        "Activate quick messages",                                      /* OPT_quick_messages */ 
    1665         NULL,                                                                          /* xxx floor_query_flag */ 
     1665        "Use sound",                                                           /* OPT_use_sound */ 
    16661666        "Display things before picking them up",        /* OPT_query_floor */ 
    16671667        "Use old target by default",                            /* OPT_use_old_target */ 
     
    19271927        FALSE,          /* OPT_rogue_like_commands */ 
    19281928        TRUE,           /* OPT_quick_messages */ 
    1929         FALSE,          /* xxx floor_query_flag */ 
     1929        FALSE,          /* OPT_use_sound */ 
    19301930        TRUE,           /* OPT_query_floor */ 
    19311931        FALSE,          /* OPT_use_old_target */ 
     
    21922192 
    21932193        { 
     2194                OPT_use_sound, 
    21942195                OPT_rogue_like_commands, 
    21952196                OPT_easy_alter, 
     
    22092210                OPT_quick_messages, 
    22102211                OPT_hilite_player, 
    2211                 OPT_NONE, 
    22122212                OPT_NONE, 
    22132213                OPT_NONE 
  • trunk/src/util.c

    r136 r141  
    13581358 
    13591359 
     1360 
    13601361/* 
    13611362 * Hack -- Make a (relevant?) sound 
     
    13661367        if (!use_sound) return; 
    13671368 
    1368         /* Make a sound (if allowed) */ 
    1369         Term_xtra(TERM_XTRA_SOUND, val); 
     1369        /* Make a noise */ 
     1370        if (sound_hook) 
     1371                sound_hook(val); 
    13701372} 
    13711373 
  • trunk/src/variable.c

    r136 r141  
    8383s32b old_turn;                  /* Hack -- Level feeling counter */ 
    8484 
    85 bool use_sound;                 /* The "sound" mode is enabled */ 
     85 
    8686int use_graphics;               /* The "graphics" mode is enabled */ 
    8787bool use_bigtile = FALSE; 
     
    849849 
    850850/* 
     851 * Sound hook (for playing FX). 
     852 */ 
     853void (*sound_hook)(int sound); 
     854 
     855 
     856/* 
    851857 * For autoinscriptions. 
    852858 */ 
  • trunk/src/z-term.h

    r120 r141  
    286286 * The "TERM_XTRA_SHAPE" action uses "v" to "show" the cursor 
    287287 * The "TERM_XTRA_FROSH" action uses "v" for the index of the row 
    288  * The "TERM_XTRA_SOUND" action uses "v" for the index of a sound 
    289288 * The "TERM_XTRA_ALIVE" action uses "v" to "activate" (or "close") 
    290289 * The "TERM_XTRA_LEVEL" action uses "v" to "resume" (or "suspend") 
     
    300299#define TERM_XTRA_FRESH 6       /* Flush all rows (optional) */ 
    301300#define TERM_XTRA_NOISE 7       /* Make a noise (optional) */ 
    302 #define TERM_XTRA_SOUND 8       /* Make a sound (optional) */ 
    303301#define TERM_XTRA_BORED 9       /* Handle stuff when bored (optional) */ 
    304302#define TERM_XTRA_REACT 10      /* React to global changes (optional) */ 
     
    391389 
    392390 
     391