1 /*
2 * Triplane Classic - a side-scrolling dogfighting game.
3 * Copyright (C) 1996,1997,2009 Dodekaedron Software Creations Oy
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * tjt@users.sourceforge.net
19 */
20
21 #include "io/sound.h"
22 #include "triplane.h"
23 #include <stdio.h>
24 #include <stdlib.h>
25
26 int is_there_sound = 1;
27 int reverbed_channels = 0;
28 int soundcard_type = SOUNDCARD_NONE;
29
play_sample(sb_sample * sample_ptr)30 int play_sample(sb_sample * sample_ptr) {
31 if (is_there_sound) {
32
33 sample_ptr->right_volume = SAMPLE_VOLUME;
34 sample_ptr->left_volume = SAMPLE_VOLUME;
35
36 sdl_play_sample(sample_ptr);
37 }
38 return 0;
39 }
40
play_2d_sample(sb_sample * sample_ptr,int player,int target)41 int play_2d_sample(sb_sample * sample_ptr, int player, int target) {
42 int balance = 7;
43
44 if (!playing_solo) {
45 play_sample(sample_ptr);
46
47 return 0;
48
49 }
50
51 if (is_there_sound) {
52 balance = target - player;
53 if (reverbed_channels)
54 balance = -balance;
55
56 balance = balance >> 4;
57
58 if (balance > 0) {
59 if (balance > SAMPLE_VOLUME)
60 balance = SAMPLE_VOLUME;
61
62 sample_ptr->right_volume = SAMPLE_VOLUME;
63 sample_ptr->left_volume = SAMPLE_VOLUME - balance;
64
65 } else {
66 balance = -balance;
67 if (balance > SAMPLE_VOLUME)
68 balance = SAMPLE_VOLUME;
69
70 sample_ptr->right_volume = SAMPLE_VOLUME - balance;
71 sample_ptr->left_volume = SAMPLE_VOLUME;
72
73
74 }
75 sdl_play_sample(sample_ptr);
76 }
77
78 return 0;
79 }
80
init_sounds(void)81 void init_sounds(void) {
82 soundcard_type = SOUNDCARD_NONE;
83
84 if (sdl_init_sounds() != 0) {
85 is_there_sound = 0;
86 printf("SDL sound init failed. Switching sounds off.\n");
87
88 } else {
89 is_there_sound = 1;
90 soundcard_type = SOUNDCARD_SDL;
91 }
92
93 return;
94 }
95
uninit_sounds(void)96 void uninit_sounds(void) {
97 is_there_sound = 0;
98 sdl_uninit_sounds();
99 }
100
sample_load(const char * samplename)101 sb_sample *sample_load(const char *samplename) {
102 sb_sample *sample;
103
104 sample = sdl_sample_load(samplename);
105
106 if (sample == NULL) {
107 printf("Cannon't locate data %s\n", samplename);
108 exit(1);
109 }
110 return sample;
111 }
112