author | rubidium |
Thu, 01 Feb 2007 15:49:12 +0000 | |
changeset 5893 | 7e431a4abebb |
parent 5609 | dc6a58930ba4 |
child 6247 | 7d81e3a5d803 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1498
diff
changeset
|
4 |
#include "openttd.h" |
2163
b17b313113a0
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
1891
diff
changeset
|
5 |
#include "functions.h" |
679
04ca2cd69420
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
337
diff
changeset
|
6 |
#include "map.h" |
1496
15d859a626e8
(svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents:
1136
diff
changeset
|
7 |
#include "mixer.h" |
0 | 8 |
#include "sound.h" |
9 |
#include "vehicle.h" |
|
10 |
#include "window.h" |
|
11 |
#include "viewport.h" |
|
12 |
#include "fileio.h" |
|
4656
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4171
diff
changeset
|
13 |
#include "newgrf_sound.h" |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
14 |
#include "helpers.hpp" |
0 | 15 |
|
1496
15d859a626e8
(svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents:
1136
diff
changeset
|
16 |
static uint _file_count; |
4171 | 17 |
static FileEntry *_files; |
0 | 18 |
|
3898
7c1f84e3b60b
(svn r4975) - Codechange: increase the number of file handles from 32 to 64 (arbitrary powers of 2!) to allow more GRF files to be loaded.
peter1138
parents:
3716
diff
changeset
|
19 |
#define SOUND_SLOT 63 |
2594
0e76c769f002
(svn r3131) Enable panning of audio relative to screen position.
peter1138
parents:
2372
diff
changeset
|
20 |
// Number of levels of panning per side |
0e76c769f002
(svn r3131) Enable panning of audio relative to screen position.
peter1138
parents:
2372
diff
changeset
|
21 |
#define PANNING_LEVELS 16 |
0 | 22 |
|
23 |
||
1496
15d859a626e8
(svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents:
1136
diff
changeset
|
24 |
static void OpenBankFile(const char *filename) |
0 | 25 |
{ |
2371
a8344121fa3c
(svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents:
2186
diff
changeset
|
26 |
uint count; |
a8344121fa3c
(svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents:
2186
diff
changeset
|
27 |
uint i; |
0 | 28 |
|
29 |
FioOpenFile(SOUND_SLOT, filename); |
|
2371
a8344121fa3c
(svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents:
2186
diff
changeset
|
30 |
count = FioReadDword() / 8; |
5609
dc6a58930ba4
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents:
5587
diff
changeset
|
31 |
FileEntry *fe = CallocT<FileEntry>(count); |
2371
a8344121fa3c
(svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents:
2186
diff
changeset
|
32 |
|
a8344121fa3c
(svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents:
2186
diff
changeset
|
33 |
if (fe == NULL) { |
a8344121fa3c
(svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents:
2186
diff
changeset
|
34 |
_file_count = 0; |
a8344121fa3c
(svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents:
2186
diff
changeset
|
35 |
_files = NULL; |
2372 | 36 |
return; |
2371
a8344121fa3c
(svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents:
2186
diff
changeset
|
37 |
} |
a8344121fa3c
(svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents:
2186
diff
changeset
|
38 |
|
a8344121fa3c
(svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents:
2186
diff
changeset
|
39 |
_file_count = count; |
a8344121fa3c
(svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents:
2186
diff
changeset
|
40 |
_files = fe; |
0 | 41 |
|
42 |
FioSeekTo(0, SEEK_SET); |
|
43 |
||
1496
15d859a626e8
(svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents:
1136
diff
changeset
|
44 |
for (i = 0; i != count; i++) { |
15d859a626e8
(svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents:
1136
diff
changeset
|
45 |
fe[i].file_offset = FioReadDword(); |
15d859a626e8
(svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents:
1136
diff
changeset
|
46 |
fe[i].file_size = FioReadDword(); |
0 | 47 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
0
diff
changeset
|
48 |
|
337
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
49 |
for (i = 0; i != count; i++, fe++) { |
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
50 |
char name[255]; |
0 | 51 |
|
337
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
52 |
FioSeekTo(fe->file_offset, SEEK_SET); |
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
53 |
|
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
54 |
// Check for special case, see else case |
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
55 |
FioReadBlock(name, FioReadByte()); // Read the name of the sound |
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
56 |
if (strcmp(name, "Corrupt sound") != 0) { |
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
57 |
FioSeekTo(12, SEEK_CUR); // Skip past RIFF header |
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
58 |
|
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
59 |
// Read riff tags |
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
60 |
for (;;) { |
2371
a8344121fa3c
(svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents:
2186
diff
changeset
|
61 |
uint32 tag = FioReadDword(); |
a8344121fa3c
(svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents:
2186
diff
changeset
|
62 |
uint32 size = FioReadDword(); |
337
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
63 |
|
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
64 |
if (tag == ' tmf') { |
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
65 |
FioReadWord(); // wFormatTag |
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
66 |
fe->channels = FioReadWord(); // wChannels |
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
67 |
FioReadDword(); // samples per second |
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
68 |
fe->rate = 11025; // seems like all samples should be played at this rate. |
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
69 |
FioReadDword(); // avg bytes per second |
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
70 |
FioReadWord(); // alignment |
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
71 |
fe->bits_per_sample = FioReadByte(); // bits per sample |
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
72 |
FioSeekTo(size - (2 + 2 + 4 + 4 + 2 + 1), SEEK_CUR); |
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
73 |
} else if (tag == 'atad') { |
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
74 |
fe->file_size = size; |
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
75 |
fe->file_offset = FioGetPos() | (SOUND_SLOT << 24); |
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
76 |
break; |
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
77 |
} else { |
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
78 |
fe->file_size = 0; |
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
79 |
break; |
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
80 |
} |
0 | 81 |
} |
337
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
82 |
} else { |
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
83 |
/* |
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
84 |
* Special case for the jackhammer sound |
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
85 |
* (name in sample.cat is "Corrupt sound") |
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
86 |
* It's no RIFF file, but raw PCM data |
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
87 |
*/ |
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
88 |
fe->channels = 1; |
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
89 |
fe->rate = 11025; |
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
90 |
fe->bits_per_sample = 8; |
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
91 |
fe->file_offset = FioGetPos() | (SOUND_SLOT << 24); |
0 | 92 |
} |
93 |
} |
|
94 |
} |
|
95 |
||
4656
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4171
diff
changeset
|
96 |
uint GetNumOriginalSounds(void) |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4171
diff
changeset
|
97 |
{ |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4171
diff
changeset
|
98 |
return _file_count; |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4171
diff
changeset
|
99 |
} |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4171
diff
changeset
|
100 |
|
1496
15d859a626e8
(svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents:
1136
diff
changeset
|
101 |
static bool SetBankSource(MixerChannel *mc, uint bank) |
0 | 102 |
{ |
4171 | 103 |
const FileEntry *fe; |
0 | 104 |
uint i; |
105 |
||
4656
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4171
diff
changeset
|
106 |
if (bank >= GetNumSounds()) return false; |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4171
diff
changeset
|
107 |
fe = GetSound(bank); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
0
diff
changeset
|
108 |
|
2371
a8344121fa3c
(svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents:
2186
diff
changeset
|
109 |
if (fe->file_size == 0) return false; |
a8344121fa3c
(svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents:
2186
diff
changeset
|
110 |
|
5609
dc6a58930ba4
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents:
5587
diff
changeset
|
111 |
int8 *mem = MallocT<int8>(fe->file_size); |
2371
a8344121fa3c
(svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents:
2186
diff
changeset
|
112 |
if (mem == NULL) return false; |
a8344121fa3c
(svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents:
2186
diff
changeset
|
113 |
|
0 | 114 |
FioSeekToFile(fe->file_offset); |
115 |
FioReadBlock(mem, fe->file_size); |
|
116 |
||
337
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
117 |
for (i = 0; i != fe->file_size; i++) |
1136 | 118 |
mem[i] += -128; // Convert unsigned sound data to signed |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
0
diff
changeset
|
119 |
|
0 | 120 |
assert(fe->bits_per_sample == 8 && fe->channels == 1 && fe->file_size != 0 && fe->rate != 0); |
121 |
||
1496
15d859a626e8
(svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents:
1136
diff
changeset
|
122 |
MxSetChannelRawSrc(mc, mem, fe->file_size, fe->rate, MX_AUTOFREE); |
0 | 123 |
|
124 |
return true; |
|
125 |
} |
|
126 |
||
1496
15d859a626e8
(svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents:
1136
diff
changeset
|
127 |
bool SoundInitialize(const char *filename) |
0 | 128 |
{ |
1496
15d859a626e8
(svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents:
1136
diff
changeset
|
129 |
OpenBankFile(filename); |
0 | 130 |
return true; |
131 |
} |
|
132 |
||
133 |
// Low level sound player |
|
2594
0e76c769f002
(svn r3131) Enable panning of audio relative to screen position.
peter1138
parents:
2372
diff
changeset
|
134 |
static void StartSound(uint sound, int panning, uint volume) |
0 | 135 |
{ |
4171 | 136 |
MixerChannel *mc; |
2594
0e76c769f002
(svn r3131) Enable panning of audio relative to screen position.
peter1138
parents:
2372
diff
changeset
|
137 |
uint left_vol, right_vol; |
2371
a8344121fa3c
(svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents:
2186
diff
changeset
|
138 |
|
a8344121fa3c
(svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents:
2186
diff
changeset
|
139 |
if (volume == 0) return; |
2977 | 140 |
mc = MxAllocateChannel(); |
2371
a8344121fa3c
(svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents:
2186
diff
changeset
|
141 |
if (mc == NULL) return; |
a8344121fa3c
(svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents:
2186
diff
changeset
|
142 |
if (!SetBankSource(mc, sound)) return; |
2594
0e76c769f002
(svn r3131) Enable panning of audio relative to screen position.
peter1138
parents:
2372
diff
changeset
|
143 |
|
0e76c769f002
(svn r3131) Enable panning of audio relative to screen position.
peter1138
parents:
2372
diff
changeset
|
144 |
panning = clamp(panning, -PANNING_LEVELS, PANNING_LEVELS); |
0e76c769f002
(svn r3131) Enable panning of audio relative to screen position.
peter1138
parents:
2372
diff
changeset
|
145 |
left_vol = (volume * PANNING_LEVELS) - (volume * panning); |
0e76c769f002
(svn r3131) Enable panning of audio relative to screen position.
peter1138
parents:
2372
diff
changeset
|
146 |
right_vol = (volume * PANNING_LEVELS) + (volume * panning); |
0e76c769f002
(svn r3131) Enable panning of audio relative to screen position.
peter1138
parents:
2372
diff
changeset
|
147 |
MxSetChannelVolume(mc, left_vol * 128 / PANNING_LEVELS, right_vol * 128 / PANNING_LEVELS); |
2371
a8344121fa3c
(svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents:
2186
diff
changeset
|
148 |
MxActivateChannel(mc); |
0 | 149 |
} |
150 |
||
151 |
||
152 |
static const byte _vol_factor_by_zoom[] = {255, 190, 134}; |
|
153 |
||
154 |
static const byte _sound_base_vol[] = { |
|
155 |
128, 90, 128, 128, 128, 128, 128, 128, |
|
156 |
128, 90, 90, 128, 128, 128, 128, 128, |
|
157 |
128, 128, 128, 80, 128, 128, 128, 128, |
|
158 |
128, 128, 128, 128, 128, 128, 128, 128, |
|
159 |
128, 128, 90, 90, 90, 128, 90, 128, |
|
160 |
128, 90, 128, 128, 128, 90, 128, 128, |
|
161 |
128, 128, 128, 128, 90, 128, 128, 128, |
|
162 |
128, 90, 128, 128, 128, 128, 128, 128, |
|
163 |
128, 128, 90, 90, 90, 128, 128, 128, |
|
164 |
90, |
|
165 |
}; |
|
166 |
||
167 |
static const byte _sound_idx[] = { |
|
2371
a8344121fa3c
(svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents:
2186
diff
changeset
|
168 |
2, 3, 4, 5, 6, 7, 8, 9, |
0 | 169 |
10, 11, 12, 13, 14, 15, 16, 17, |
170 |
18, 19, 20, 21, 22, 23, 24, 25, |
|
171 |
26, 27, 28, 29, 30, 31, 32, 33, |
|
2371
a8344121fa3c
(svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents:
2186
diff
changeset
|
172 |
34, 35, 36, 37, 38, 39, 40, 0, |
a8344121fa3c
(svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents:
2186
diff
changeset
|
173 |
1, 41, 42, 43, 44, 45, 46, 47, |
0 | 174 |
48, 49, 50, 51, 52, 53, 54, 55, |
175 |
56, 57, 58, 59, 60, 61, 62, 63, |
|
176 |
64, 65, 66, 67, 68, 69, 70, 71, |
|
177 |
72, |
|
178 |
}; |
|
179 |
||
4656
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4171
diff
changeset
|
180 |
void SndCopyToPool(void) |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4171
diff
changeset
|
181 |
{ |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4171
diff
changeset
|
182 |
uint i; |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4171
diff
changeset
|
183 |
|
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4171
diff
changeset
|
184 |
for (i = 0; i < _file_count; i++) { |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4171
diff
changeset
|
185 |
FileEntry *orig = &_files[_sound_idx[i]]; |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4171
diff
changeset
|
186 |
FileEntry *fe = AllocateFileEntry(); |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4171
diff
changeset
|
187 |
|
5024
5e98bf731469
(svn r7065) Use simple assignment instead of memcpy()
tron
parents:
4656
diff
changeset
|
188 |
*fe = *orig; |
4656
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4171
diff
changeset
|
189 |
fe->volume = _sound_base_vol[i]; |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4171
diff
changeset
|
190 |
fe->priority = 0; |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4171
diff
changeset
|
191 |
} |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4171
diff
changeset
|
192 |
} |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4171
diff
changeset
|
193 |
|
337
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
194 |
static void SndPlayScreenCoordFx(SoundFx sound, int x, int y) |
0 | 195 |
{ |
5137
54425dc8b5b3
(svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents:
5124
diff
changeset
|
196 |
Window* const *wz; |
0 | 197 |
|
2371
a8344121fa3c
(svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents:
2186
diff
changeset
|
198 |
if (msf.effect_vol == 0) return; |
0 | 199 |
|
5124
2ca62776430e
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5024
diff
changeset
|
200 |
FOR_ALL_WINDOWS(wz) { |
2ca62776430e
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5024
diff
changeset
|
201 |
const ViewPort *vp = (*wz)->viewport; |
2371
a8344121fa3c
(svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents:
2186
diff
changeset
|
202 |
|
a8344121fa3c
(svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents:
2186
diff
changeset
|
203 |
if (vp != NULL && |
0 | 204 |
IS_INSIDE_1D(x, vp->virtual_left, vp->virtual_width) && |
205 |
IS_INSIDE_1D(y, vp->virtual_top, vp->virtual_height)) { |
|
2594
0e76c769f002
(svn r3131) Enable panning of audio relative to screen position.
peter1138
parents:
2372
diff
changeset
|
206 |
int left = (x - vp->virtual_left); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
0
diff
changeset
|
207 |
|
0 | 208 |
StartSound( |
4656
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4171
diff
changeset
|
209 |
sound, |
2594
0e76c769f002
(svn r3131) Enable panning of audio relative to screen position.
peter1138
parents:
2372
diff
changeset
|
210 |
left / (vp->virtual_width / ((PANNING_LEVELS << 1) + 1)) - PANNING_LEVELS, |
4656
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4171
diff
changeset
|
211 |
(GetSound(sound)->volume * msf.effect_vol * _vol_factor_by_zoom[vp->zoom]) >> 15 |
0 | 212 |
); |
213 |
return; |
|
214 |
} |
|
215 |
} |
|
216 |
||
217 |
} |
|
218 |
||
337
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
219 |
void SndPlayTileFx(SoundFx sound, TileIndex tile) |
0 | 220 |
{ |
3645
7f950533d510
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3421
diff
changeset
|
221 |
/* emits sound from center of the tile */ |
7f950533d510
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3421
diff
changeset
|
222 |
int x = TileX(tile) * TILE_SIZE + TILE_SIZE / 2; |
7f950533d510
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3421
diff
changeset
|
223 |
int y = TileY(tile) * TILE_SIZE + TILE_SIZE / 2; |
337
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
224 |
Point pt = RemapCoords(x, y, GetSlopeZ(x, y)); |
0 | 225 |
SndPlayScreenCoordFx(sound, pt.x, pt.y); |
226 |
} |
|
227 |
||
337
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
228 |
void SndPlayVehicleFx(SoundFx sound, const Vehicle *v) |
0 | 229 |
{ |
230 |
SndPlayScreenCoordFx(sound, |
|
337
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
231 |
(v->left_coord + v->right_coord) / 2, |
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
232 |
(v->top_coord + v->bottom_coord) / 2 |
0 | 233 |
); |
234 |
} |
|
235 |
||
337
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
236 |
void SndPlayFx(SoundFx sound) |
0 | 237 |
{ |
238 |
StartSound( |
|
4656
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4171
diff
changeset
|
239 |
sound, |
2594
0e76c769f002
(svn r3131) Enable panning of audio relative to screen position.
peter1138
parents:
2372
diff
changeset
|
240 |
0, |
4656
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4171
diff
changeset
|
241 |
(GetSound(sound)->volume * msf.effect_vol) >> 7 |
0 | 242 |
); |
243 |
} |