~ubuntu-branches/ubuntu/trusty/netrek-client-cow/trusty

« back to all changes in this revision

Viewing changes to sound.c

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese, Barry deFreese
  • Date: 2009-06-16 15:27:20 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090616152720-whngeaf1w8l23u14
Tags: 3.3.0-1
[ Barry deFreese ]
* New upstream release.
* Install upstream desktop file. (Closes: #522587).
* Add quilt patch system.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
 
46
46
#if defined(HAVE_SDL) || defined(sgi)
47
47
enum {
48
 
        INTRO_WAV,
49
 
        FIRE_TORP_WAV,
50
 
        PHASER_WAV,
51
 
        FIRE_PLASMA_WAV,
52
 
        EXPLOSION_WAV,
53
 
        SBEXPLOSION_WAV,
54
 
        CLOAK_WAV,
55
 
        UNCLOAK_WAV,
56
 
        SHIELD_DOWN_WAV,
57
 
        SHIELD_UP_WAV,
58
 
        TORP_HIT_WAV,
59
 
        REDALERT_WAV,
60
 
        BUZZER_WAV,
61
 
        ENTER_SHIP_WAV,
62
 
        SELF_DESTRUCT_WAV,
63
 
        PLASMA_HIT_WAV,
64
 
        MESSAGE_WAV,
65
 
        ENGINE_WAV,
66
 
        THERMAL_WAV,
67
 
        FIRE_TORP_OTHER_WAV,
68
 
        PHASER_OTHER_WAV,
69
 
        FIRE_PLASMA_OTHER_WAV,
70
 
        EXPLOSION_OTHER_WAV,
71
 
        SBEXPLOSION_OTHER_WAV,
72
 
        NUM_WAVES
 
48
  INTRO_WAV,                    /*  0 */
 
49
  FIRE_TORP_WAV,                /*  1 */
 
50
  PHASER_WAV,                   /*  2 */
 
51
  FIRE_PLASMA_WAV,              /*  3 */
 
52
  EXPLOSION_WAV,                /*  4 */
 
53
  SBEXPLOSION_WAV,              /*  5 */
 
54
  CLOAK_WAV,                    /*  6 */
 
55
  UNCLOAK_WAV,                  /*  7 */
 
56
  SHIELD_DOWN_WAV,              /*  8 */
 
57
  SHIELD_UP_WAV,                /*  9 */
 
58
  TORP_HIT_WAV,                 /* 10 */
 
59
  REDALERT_WAV,                 /* 11 */
 
60
  BUZZER_WAV,                   /* 12 */
 
61
  ENTER_SHIP_WAV,               /* 13 */
 
62
  SELF_DESTRUCT_WAV,            /* 14 */
 
63
  PLASMA_HIT_WAV,               /* 15 */
 
64
  MESSAGE_WAV,                  /* 16 */
 
65
  ENGINE_WAV,                   /* 17 */
 
66
  THERMAL_WAV,                  /* 18 */
 
67
  FIRE_TORP_OTHER_WAV,          /* 19 */
 
68
  PHASER_OTHER_WAV,             /* 20 */
 
69
  FIRE_PLASMA_OTHER_WAV,        /* 21 */
 
70
  EXPLOSION_OTHER_WAV,          /* 22 */
 
71
  SBEXPLOSION_OTHER_WAV,        /* 23 */
 
72
  NUM_WAVES                     /* 24 */
73
73
};
74
74
#endif
75
75
 
167
167
        struct stat buf;
168
168
 
169
169
        if (stat(dir, &buf) < 0) {
170
 
                (void) fprintf(stderr, "stat of directory `%s' failed: %s\n", dir, strerror(errno));
171
170
                return 0;
172
171
        }
173
172
        return S_ISDIR(buf.st_mode);
894
893
        sounds[CLOAK_WAV] = Mix_LoadWAV(DATAFILE("nt_cloaked.wav"));
895
894
        sounds[ENTER_SHIP_WAV] = Mix_LoadWAV(DATAFILE("nt_enter_ship.wav"));
896
895
        sounds[EXPLOSION_WAV] = Mix_LoadWAV(DATAFILE("nt_explosion.wav"));
 
896
        sounds[SBEXPLOSION_WAV] = Mix_LoadWAV(DATAFILE("nt_sbexplosion.wav"));
897
897
        sounds[EXPLOSION_OTHER_WAV] = Mix_LoadWAV(DATAFILE("nt_explosion_other.wav"));
898
898
        sounds[FIRE_PLASMA_WAV] = Mix_LoadWAV(DATAFILE("nt_fire_plasma.wav"));
899
899
        sounds[FIRE_TORP_WAV] = Mix_LoadWAV(DATAFILE("nt_fire_torp.wav"));
910
910
        sounds[UNCLOAK_WAV] = Mix_LoadWAV(DATAFILE("nt_uncloak.wav"));
911
911
        sounds[REDALERT_WAV] = Mix_LoadWAV(DATAFILE("nt_warning.wav"));
912
912
 
 
913
#ifdef SOUND_WARN_MISSING
913
914
        for (i=0; i < NUM_WAVES; i++) {
914
915
                if (!sounds[i]) {
915
 
                        (void) fprintf(stderr, "Mix_LoadWAV sound[%d] could not be loaded."
 
916
                        (void) fprintf(stderr, "Mix_LoadWAV sound[%d] could not be loaded.\n"
916
917
                                                "Check soundDir in your .netrekrc: %s\n", i, Mix_GetError());
917
 
                        return -1;
918
918
                }
919
919
        }
 
920
#endif
920
921
        return 1;
921
922
}
922
923
 
972
973
                        if ((sd=getenv("SOUNDDIR")) != NULL)
973
974
                                sounddir = strdup(sd);
974
975
                        else
 
976
#if defined(sgi)
975
977
                                sounddir = "/usr/local/games/netrek-sgi/sounds";
 
978
#else
 
979
                                sounddir = "/usr/share/sounds/netrek-client-cow";
 
980
#endif
976
981
                }
977
982
                if (!isDirectory(sounddir)) {
978
 
                        (void) fprintf(stderr, "%s is not a directory, sound will not work\n", sounddir);
 
983
                        sounddir = "sounds";
 
984
                                if (!isDirectory(sounddir)) {
 
985
                                        (void) fprintf(stderr, "sound directory missing\n", sounddir);
 
986
                                        return;
 
987
                        }
 
988
                }
979
989
        }
980
990
#if defined(sgi)
981
991
        err = sfxInit(sounddir, 3);                     /* initialize up to three audio ports */
1038
1048
        printf("Init_Sound using SDL\n");
1039
1049
#endif
1040
1050
 
1041
 
    /* Initialize the SDL library */
1042
 
    if (SDL_Init(SDL_INIT_AUDIO) < 0) {
1043
 
      fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
1044
 
    }
1045
 
    atexit(SDL_Quit);
1046
 
 
1047
 
    /* Open the audio device at 8000 Hz 8 bit Microsoft PCM */
1048
 
    if (Mix_OpenAudio(8000, AUDIO_U8, 1, 512) < 0) {
1049
 
      fprintf(stderr,"Mix_OpenAudio: %s\n", Mix_GetError());
1050
 
      sound_init = 0;
1051
 
    } 
1052
 
 
1053
 
    /* If we successfully loaded the wav files, so shut-off sound_init and play
1054
 
     * the introduction
1055
 
     */
1056
 
    if (loadSounds()) {
1057
 
      if (Mix_PlayChannel(-1, sounds[INTRO_WAV], 0) < 0) {
1058
 
        fprintf(stderr, "Mix_PlayChannel: %s\n", Mix_GetError());
1059
 
      }
1060
 
    }
 
1051
        /* Initialize the SDL library */
 
1052
        if (SDL_Init(SDL_INIT_AUDIO) < 0) {
 
1053
          fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
 
1054
        }
 
1055
        atexit(SDL_Quit);
 
1056
 
 
1057
        /* Open the audio device at 8000 Hz 8 bit Microsoft PCM */
 
1058
        if (Mix_OpenAudio(8000, AUDIO_U8, 1, 512) < 0) {
 
1059
          fprintf(stderr,"Mix_OpenAudio: %s\n", Mix_GetError());
 
1060
          sound_init = 0;
 
1061
        }
 
1062
 
 
1063
        Mix_AllocateChannels(16);
 
1064
 
 
1065
        /* If we successfully loaded the wav files, so shut-off
 
1066
           sound_init and play the introduction */
 
1067
        if (loadSounds()) {
 
1068
          if (sounds[INTRO_WAV])
 
1069
            if (Mix_PlayChannel(-1, sounds[INTRO_WAV], 0) < 0) {
 
1070
              fprintf(stderr, "Mix_PlayChannel: %s\n", Mix_GetError());
 
1071
            }
 
1072
        }
1061
1073
#else
1062
 
    if (InitSound() == -1) {
1063
 
      sound_toggle = 0;
1064
 
      sound_init = 0;
1065
 
    } else {
1066
 
      sound_init = 1;
1067
 
      sound_toggle = 1;
1068
 
    }
1069
 
 
1070
 
    strcpy(sound_prefix, sounddir);
1071
 
    strcat(sound_prefix, "/");
1072
 
 
1073
 
    if (sound_toggle) {
1074
 
    strcpy(buf, sounddir);
1075
 
    strcat(buf, "/nt_intro");
1076
 
    StartSound(buf);
1077
 
    }
 
1074
        if (InitSound() == -1) {
 
1075
          sound_toggle = 0;
 
1076
          sound_init = 0;
 
1077
        } else {
 
1078
          sound_init = 1;
 
1079
          sound_toggle = 1;
 
1080
        }
 
1081
 
 
1082
        strcpy(sound_prefix, sounddir);
 
1083
        strcat(sound_prefix, "/");
 
1084
 
 
1085
        if (sound_toggle) {
 
1086
          strcpy(buf, sounddir);
 
1087
          strcat(buf, "/nt_intro");
 
1088
          StartSound(buf);
 
1089
        }
1078
1090
#endif
1079
 
  }
1080
1091
}
1081
1092
 
1082
1093
#if defined(HAVE_SDL) || defined(sgi)
1158
1169
        sfxPlay(sounds[waveform]);
1159
1170
 
1160
1171
#else
1161
 
        if (Mix_PlayChannel(-1, sounds[waveform], 0) < 0) {
1162
 
                (void) fprintf(stderr, "Mix_PlayChannel: %s\n", Mix_GetError());
1163
 
        }
 
1172
        if (sounds[waveform])
 
1173
          if (Mix_PlayChannel(-1, sounds[waveform], 0) < 0) {
 
1174
            (void) fprintf(stderr, "Mix_PlayChannel: %s\n", Mix_GetError());
 
1175
          }
1164
1176
#endif
1165
1177
 
1166
1178
#else