src/sound.cpp
author rubidium
Thu, 18 Dec 2008 12:23:08 +0000
changeset 10436 8d3a9fbe8f19
parent 10288 9c6717bac8a1
permissions -rw-r--r--
(svn r14689) -Change: make configure die on commonly made user mistakes, like not having SDL development files or zlib headers installed; you can still compile a dedicated server or a binary without zlib, but you have to explicitly force it.
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
9111
48ce04029fe4 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 8992
diff changeset
     3
/** @file sound.cpp Handling of playing sounds. */
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6247
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1498
diff changeset
     6
#include "openttd.h"
6453
226bcddeba32 (svn r9609) -Codechange: Move some function prototypes out of functions.h and into landscape.h, and add a few where they didn't exist.
maedhros
parents: 6420
diff changeset
     7
#include "landscape.h"
1496
15d859a626e8 (svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents: 1136
diff changeset
     8
#include "mixer.h"
8157
1505def01945 (svn r11719) -Codechange: split sound.h in a header with types and one with functions.
rubidium
parents: 8144
diff changeset
     9
#include "sound_func.h"
10039
1f236afd6cd1 (svn r14199) -Codechange: split fileio.h into fileio_type.h and fileio_func.h so not everything that includes saveload.h needs to include everything else too.
rubidium
parents: 9542
diff changeset
    10
#include "fileio_func.h"
4656
9c1d8c4d3e60 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4171
diff changeset
    11
#include "newgrf_sound.h"
7805
7ab20f94cc80 (svn r11355) -Fix [FS#1377]: loading too many GRFs was not handled gracefully causing crashes and such.
rubidium
parents: 7591
diff changeset
    12
#include "fios.h"
8106
e6790dd9e750 (svn r11667) -Codechange: split window.h into a header that defines some 'global' window related types, on that defined 'global' window functions and one that defines functions and types only used by *_gui.cpps.
rubidium
parents: 8095
diff changeset
    13
#include "window_gui.h"
8130
d2eb7d04f6e1 (svn r11691) -Codechange: move+rename helpers.hpp and only include it when it is really needed.
rubidium
parents: 8106
diff changeset
    14
#include "core/alloc_func.hpp"
8139
4e91c448c409 (svn r11701) -Codechange: removal unnecessary inclusions of map.h (and split map.h).
rubidium
parents: 8131
diff changeset
    15
#include "map_func.h"
8144
65cec0877b78 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents: 8139
diff changeset
    16
#include "vehicle_base.h"
8439
6913310b9a18 (svn r12009) -Fix [FS#1707]: Avoid loading sample.cat if it 'looks' incorrect, and avoid later null pointer dereferences by moving volume lookup deeper.
peter1138
parents: 8224
diff changeset
    17
#include "debug.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
1496
15d859a626e8 (svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents: 1136
diff changeset
    19
static uint _file_count;
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 3898
diff changeset
    20
static FileEntry *_files;
8157
1505def01945 (svn r11719) -Codechange: split sound.h in a header with types and one with functions.
rubidium
parents: 8144
diff changeset
    21
MusicFileSettings msf;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
2594
0e76c769f002 (svn r3131) Enable panning of audio relative to screen position.
peter1138
parents: 2372
diff changeset
    23
// Number of levels of panning per side
0e76c769f002 (svn r3131) Enable panning of audio relative to screen position.
peter1138
parents: 2372
diff changeset
    24
#define PANNING_LEVELS 16
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
10288
9c6717bac8a1 (svn r14527) -Fix: allocate stub (empty) sound entries when loading an empty/corrupt/incorrectly sized sample.cat instead of making valid NewGRFs fail to load.
rubidium
parents: 10039
diff changeset
    26
/** The number of sounds in the original sample.cat */
9c6717bac8a1 (svn r14527) -Fix: allocate stub (empty) sound entries when loading an empty/corrupt/incorrectly sized sample.cat instead of making valid NewGRFs fail to load.
rubidium
parents: 10039
diff changeset
    27
static const uint ORIGINAL_SAMPLE_COUNT = 73;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
1496
15d859a626e8 (svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents: 1136
diff changeset
    29
static void OpenBankFile(const char *filename)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    30
{
10288
9c6717bac8a1 (svn r14527) -Fix: allocate stub (empty) sound entries when loading an empty/corrupt/incorrectly sized sample.cat instead of making valid NewGRFs fail to load.
rubidium
parents: 10039
diff changeset
    31
	FileEntry *fe = CallocT<FileEntry>(ORIGINAL_SAMPLE_COUNT);
9c6717bac8a1 (svn r14527) -Fix: allocate stub (empty) sound entries when loading an empty/corrupt/incorrectly sized sample.cat instead of making valid NewGRFs fail to load.
rubidium
parents: 10039
diff changeset
    32
	_file_count = ORIGINAL_SAMPLE_COUNT;
9c6717bac8a1 (svn r14527) -Fix: allocate stub (empty) sound entries when loading an empty/corrupt/incorrectly sized sample.cat instead of making valid NewGRFs fail to load.
rubidium
parents: 10039
diff changeset
    33
	_files = fe;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    35
	FioOpenFile(SOUND_SLOT, filename);
9390
88d36f907e96 (svn r13301) -Fix [FS#1997]: resolve more MSVC 9 x64 warnings.
rubidium
parents: 9111
diff changeset
    36
	size_t pos = FioGetPos();
8439
6913310b9a18 (svn r12009) -Fix [FS#1707]: Avoid loading sample.cat if it 'looks' incorrect, and avoid later null pointer dereferences by moving volume lookup deeper.
peter1138
parents: 8224
diff changeset
    37
	uint count = FioReadDword() / 8;
6913310b9a18 (svn r12009) -Fix [FS#1707]: Avoid loading sample.cat if it 'looks' incorrect, and avoid later null pointer dereferences by moving volume lookup deeper.
peter1138
parents: 8224
diff changeset
    38
6913310b9a18 (svn r12009) -Fix [FS#1707]: Avoid loading sample.cat if it 'looks' incorrect, and avoid later null pointer dereferences by moving volume lookup deeper.
peter1138
parents: 8224
diff changeset
    39
	/* Simple check for the correct number of original sounds. */
10288
9c6717bac8a1 (svn r14527) -Fix: allocate stub (empty) sound entries when loading an empty/corrupt/incorrectly sized sample.cat instead of making valid NewGRFs fail to load.
rubidium
parents: 10039
diff changeset
    40
	if (count != ORIGINAL_SAMPLE_COUNT) {
9c6717bac8a1 (svn r14527) -Fix: allocate stub (empty) sound entries when loading an empty/corrupt/incorrectly sized sample.cat instead of making valid NewGRFs fail to load.
rubidium
parents: 10039
diff changeset
    41
		/* Corrupt sample data? Just leave the allocated memory as those tell
9c6717bac8a1 (svn r14527) -Fix: allocate stub (empty) sound entries when loading an empty/corrupt/incorrectly sized sample.cat instead of making valid NewGRFs fail to load.
rubidium
parents: 10039
diff changeset
    42
		 * there is no sound to play (size = 0 due to calloc). Not allocating
9c6717bac8a1 (svn r14527) -Fix: allocate stub (empty) sound entries when loading an empty/corrupt/incorrectly sized sample.cat instead of making valid NewGRFs fail to load.
rubidium
parents: 10039
diff changeset
    43
		 * the memory disables valid NewGRFs that replace sounds. */
8439
6913310b9a18 (svn r12009) -Fix [FS#1707]: Avoid loading sample.cat if it 'looks' incorrect, and avoid later null pointer dereferences by moving volume lookup deeper.
peter1138
parents: 8224
diff changeset
    44
		DEBUG(misc, 6, "Incorrect number of sounds in '%s', ignoring.", filename);
6913310b9a18 (svn r12009) -Fix [FS#1707]: Avoid loading sample.cat if it 'looks' incorrect, and avoid later null pointer dereferences by moving volume lookup deeper.
peter1138
parents: 8224
diff changeset
    45
		return;
6913310b9a18 (svn r12009) -Fix [FS#1707]: Avoid loading sample.cat if it 'looks' incorrect, and avoid later null pointer dereferences by moving volume lookup deeper.
peter1138
parents: 8224
diff changeset
    46
	}
6913310b9a18 (svn r12009) -Fix [FS#1707]: Avoid loading sample.cat if it 'looks' incorrect, and avoid later null pointer dereferences by moving volume lookup deeper.
peter1138
parents: 8224
diff changeset
    47
7591
06202df3799e (svn r11118) -Fix: sample.cat can now be in a tar-file too, how nice!
truelight
parents: 7570
diff changeset
    48
	FioSeekTo(pos, SEEK_SET);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    49
10288
9c6717bac8a1 (svn r14527) -Fix: allocate stub (empty) sound entries when loading an empty/corrupt/incorrectly sized sample.cat instead of making valid NewGRFs fail to load.
rubidium
parents: 10039
diff changeset
    50
	for (uint i = 0; i != ORIGINAL_SAMPLE_COUNT; i++) {
7570
5d5d9b6af0ef (svn r11095) -Codechange: don't abuse 'file_pos' by storing the file_slot in it too, but use a nice seperate variable for it
truelight
parents: 6891
diff changeset
    51
		fe[i].file_slot = SOUND_SLOT;
7591
06202df3799e (svn r11118) -Fix: sample.cat can now be in a tar-file too, how nice!
truelight
parents: 7570
diff changeset
    52
		fe[i].file_offset = FioReadDword() + pos;
1496
15d859a626e8 (svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents: 1136
diff changeset
    53
		fe[i].file_size = FioReadDword();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    54
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 0
diff changeset
    55
10288
9c6717bac8a1 (svn r14527) -Fix: allocate stub (empty) sound entries when loading an empty/corrupt/incorrectly sized sample.cat instead of making valid NewGRFs fail to load.
rubidium
parents: 10039
diff changeset
    56
	for (uint i = 0; i != ORIGINAL_SAMPLE_COUNT; i++, fe++) {
337
cbe0c766c947 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    57
		char name[255];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    58
337
cbe0c766c947 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    59
		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
    60
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6247
diff changeset
    61
		/* Check for special case, see else case */
337
cbe0c766c947 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    62
		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
    63
		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
    64
			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
    65
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6247
diff changeset
    66
			/* Read riff tags */
337
cbe0c766c947 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    67
			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
    68
				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
    69
				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
    70
cbe0c766c947 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    71
				if (tag == ' tmf') {
cbe0c766c947 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    72
					FioReadWord(); // wFormatTag
cbe0c766c947 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    73
					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
    74
					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
    75
					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
    76
					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
    77
					FioReadWord();    // alignment
cbe0c766c947 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    78
					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
    79
					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
    80
				} 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
    81
					fe->file_size = size;
7570
5d5d9b6af0ef (svn r11095) -Codechange: don't abuse 'file_pos' by storing the file_slot in it too, but use a nice seperate variable for it
truelight
parents: 6891
diff changeset
    82
					fe->file_slot = SOUND_SLOT;
5d5d9b6af0ef (svn r11095) -Codechange: don't abuse 'file_pos' by storing the file_slot in it too, but use a nice seperate variable for it
truelight
parents: 6891
diff changeset
    83
					fe->file_offset = FioGetPos();
337
cbe0c766c947 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    84
					break;
cbe0c766c947 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    85
				} else {
cbe0c766c947 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    86
					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
    87
					break;
cbe0c766c947 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    88
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    89
			}
337
cbe0c766c947 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    90
		} else {
cbe0c766c947 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    91
			/*
cbe0c766c947 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    92
			 * 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
    93
			 * (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
    94
			 * 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
    95
			 */
cbe0c766c947 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    96
			fe->channels = 1;
cbe0c766c947 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    97
			fe->rate = 11025;
cbe0c766c947 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    98
			fe->bits_per_sample = 8;
7570
5d5d9b6af0ef (svn r11095) -Codechange: don't abuse 'file_pos' by storing the file_slot in it too, but use a nice seperate variable for it
truelight
parents: 6891
diff changeset
    99
			fe->file_slot = SOUND_SLOT;
5d5d9b6af0ef (svn r11095) -Codechange: don't abuse 'file_pos' by storing the file_slot in it too, but use a nice seperate variable for it
truelight
parents: 6891
diff changeset
   100
			fe->file_offset = FioGetPos();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   101
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   102
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   103
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   104
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 5609
diff changeset
   105
uint GetNumOriginalSounds()
4656
9c1d8c4d3e60 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4171
diff changeset
   106
{
9c1d8c4d3e60 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4171
diff changeset
   107
	return _file_count;
9c1d8c4d3e60 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4171
diff changeset
   108
}
9c1d8c4d3e60 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4171
diff changeset
   109
8439
6913310b9a18 (svn r12009) -Fix [FS#1707]: Avoid loading sample.cat if it 'looks' incorrect, and avoid later null pointer dereferences by moving volume lookup deeper.
peter1138
parents: 8224
diff changeset
   110
static bool SetBankSource(MixerChannel *mc, const FileEntry *fe)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   111
{
8439
6913310b9a18 (svn r12009) -Fix [FS#1707]: Avoid loading sample.cat if it 'looks' incorrect, and avoid later null pointer dereferences by moving volume lookup deeper.
peter1138
parents: 8224
diff changeset
   112
	assert(fe != NULL);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 0
diff changeset
   113
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
   114
	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
   115
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
   116
	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
   117
	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
   118
7570
5d5d9b6af0ef (svn r11095) -Codechange: don't abuse 'file_pos' by storing the file_slot in it too, but use a nice seperate variable for it
truelight
parents: 6891
diff changeset
   119
	FioSeekToFile(fe->file_slot, fe->file_offset);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
	FioReadBlock(mem, fe->file_size);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   121
8439
6913310b9a18 (svn r12009) -Fix [FS#1707]: Avoid loading sample.cat if it 'looks' incorrect, and avoid later null pointer dereferences by moving volume lookup deeper.
peter1138
parents: 8224
diff changeset
   122
	for (uint i = 0; i != fe->file_size; i++) {
1136
186d65f60c82 (svn r1637) -Fix: VS6 warning
darkvater
parents: 926
diff changeset
   123
		mem[i] += -128; // Convert unsigned sound data to signed
8439
6913310b9a18 (svn r12009) -Fix [FS#1707]: Avoid loading sample.cat if it 'looks' incorrect, and avoid later null pointer dereferences by moving volume lookup deeper.
peter1138
parents: 8224
diff changeset
   124
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 0
diff changeset
   125
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   126
	assert(fe->bits_per_sample == 8 && fe->channels == 1 && fe->file_size != 0 && fe->rate != 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   127
1496
15d859a626e8 (svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents: 1136
diff changeset
   128
	MxSetChannelRawSrc(mc, mem, fe->file_size, fe->rate, MX_AUTOFREE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   129
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   130
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   131
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   132
1496
15d859a626e8 (svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents: 1136
diff changeset
   133
bool SoundInitialize(const char *filename)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   134
{
1496
15d859a626e8 (svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents: 1136
diff changeset
   135
	OpenBankFile(filename);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   136
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   137
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   138
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6247
diff changeset
   139
/* Low level sound player */
2594
0e76c769f002 (svn r3131) Enable panning of audio relative to screen position.
peter1138
parents: 2372
diff changeset
   140
static void StartSound(uint sound, int panning, uint volume)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   141
{
8439
6913310b9a18 (svn r12009) -Fix [FS#1707]: Avoid loading sample.cat if it 'looks' incorrect, and avoid later null pointer dereferences by moving volume lookup deeper.
peter1138
parents: 8224
diff changeset
   142
	if (volume == 0) 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
   143
8439
6913310b9a18 (svn r12009) -Fix [FS#1707]: Avoid loading sample.cat if it 'looks' incorrect, and avoid later null pointer dereferences by moving volume lookup deeper.
peter1138
parents: 8224
diff changeset
   144
	const FileEntry *fe = GetSound(sound);
6913310b9a18 (svn r12009) -Fix [FS#1707]: Avoid loading sample.cat if it 'looks' incorrect, and avoid later null pointer dereferences by moving volume lookup deeper.
peter1138
parents: 8224
diff changeset
   145
	if (fe == NULL) return;
6913310b9a18 (svn r12009) -Fix [FS#1707]: Avoid loading sample.cat if it 'looks' incorrect, and avoid later null pointer dereferences by moving volume lookup deeper.
peter1138
parents: 8224
diff changeset
   146
6913310b9a18 (svn r12009) -Fix [FS#1707]: Avoid loading sample.cat if it 'looks' incorrect, and avoid later null pointer dereferences by moving volume lookup deeper.
peter1138
parents: 8224
diff changeset
   147
	MixerChannel *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
   148
	if (mc == NULL) return;
8439
6913310b9a18 (svn r12009) -Fix [FS#1707]: Avoid loading sample.cat if it 'looks' incorrect, and avoid later null pointer dereferences by moving volume lookup deeper.
peter1138
parents: 8224
diff changeset
   149
6913310b9a18 (svn r12009) -Fix [FS#1707]: Avoid loading sample.cat if it 'looks' incorrect, and avoid later null pointer dereferences by moving volume lookup deeper.
peter1138
parents: 8224
diff changeset
   150
	if (!SetBankSource(mc, fe)) return;
6913310b9a18 (svn r12009) -Fix [FS#1707]: Avoid loading sample.cat if it 'looks' incorrect, and avoid later null pointer dereferences by moving volume lookup deeper.
peter1138
parents: 8224
diff changeset
   151
6913310b9a18 (svn r12009) -Fix [FS#1707]: Avoid loading sample.cat if it 'looks' incorrect, and avoid later null pointer dereferences by moving volume lookup deeper.
peter1138
parents: 8224
diff changeset
   152
	/* Apply the sound effect's own volume. */
6913310b9a18 (svn r12009) -Fix [FS#1707]: Avoid loading sample.cat if it 'looks' incorrect, and avoid later null pointer dereferences by moving volume lookup deeper.
peter1138
parents: 8224
diff changeset
   153
	volume = (fe->volume * volume) / 128;
2594
0e76c769f002 (svn r3131) Enable panning of audio relative to screen position.
peter1138
parents: 2372
diff changeset
   154
7922
a7e266f966d9 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents: 7805
diff changeset
   155
	panning = Clamp(panning, -PANNING_LEVELS, PANNING_LEVELS);
8439
6913310b9a18 (svn r12009) -Fix [FS#1707]: Avoid loading sample.cat if it 'looks' incorrect, and avoid later null pointer dereferences by moving volume lookup deeper.
peter1138
parents: 8224
diff changeset
   156
	uint left_vol = (volume * PANNING_LEVELS) - (volume * panning);
6913310b9a18 (svn r12009) -Fix [FS#1707]: Avoid loading sample.cat if it 'looks' incorrect, and avoid later null pointer dereferences by moving volume lookup deeper.
peter1138
parents: 8224
diff changeset
   157
	uint right_vol = (volume * PANNING_LEVELS) + (volume * panning);
2594
0e76c769f002 (svn r3131) Enable panning of audio relative to screen position.
peter1138
parents: 2372
diff changeset
   158
	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
   159
	MxActivateChannel(mc);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   160
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
6853
011888c570df (svn r10093) -Revert: removed 16x zoom-out as it is broken beyond repair
truelight
parents: 6654
diff changeset
   163
static const byte _vol_factor_by_zoom[] = {255, 190, 134, 87};
9542
bc9789270025 (svn r13551) -Codechange: store offsets to different zoom levels in a distinguished struct instead in the data stream for 8bpp-optimized
smatz
parents: 9390
diff changeset
   164
assert_compile(lengthof(_vol_factor_by_zoom) == ZOOM_LVL_COUNT);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   165
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   166
static const byte _sound_base_vol[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
	128,  90, 128, 128, 128, 128, 128, 128,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   168
	128,  90,  90, 128, 128, 128, 128, 128,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   169
	128, 128, 128,  80, 128, 128, 128, 128,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   170
	128, 128, 128, 128, 128, 128, 128, 128,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   171
	128, 128,  90,  90,  90, 128,  90, 128,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   172
	128,  90, 128, 128, 128,  90, 128, 128,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
	128, 128, 128, 128,  90, 128, 128, 128,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   174
	128,  90, 128, 128, 128, 128, 128, 128,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   175
	128, 128,  90,  90,  90, 128, 128, 128,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   176
	 90,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   177
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   179
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
   180
	 2,  3,  4,  5,  6,  7,  8,  9,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   181
	10, 11, 12, 13, 14, 15, 16, 17,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   182
	18, 19, 20, 21, 22, 23, 24, 25,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   183
	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
   184
	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
   185
	 1, 41, 42, 43, 44, 45, 46, 47,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   186
	48, 49, 50, 51, 52, 53, 54, 55,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
	56, 57, 58, 59, 60, 61, 62, 63,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
	64, 65, 66, 67, 68, 69, 70, 71,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
	72,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   191
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 5609
diff changeset
   192
void SndCopyToPool()
4656
9c1d8c4d3e60 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4171
diff changeset
   193
{
8857
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8604
diff changeset
   194
	for (uint i = 0; i < _file_count; i++) {
4656
9c1d8c4d3e60 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4171
diff changeset
   195
		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
   196
		FileEntry *fe = AllocateFileEntry();
9c1d8c4d3e60 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4171
diff changeset
   197
5024
5e98bf731469 (svn r7065) Use simple assignment instead of memcpy()
tron
parents: 4656
diff changeset
   198
		*fe = *orig;
4656
9c1d8c4d3e60 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4171
diff changeset
   199
		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
   200
		fe->priority = 0;
9c1d8c4d3e60 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4171
diff changeset
   201
	}
9c1d8c4d3e60 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4171
diff changeset
   202
}
9c1d8c4d3e60 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4171
diff changeset
   203
8992
0b2fb43cc875 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents: 8857
diff changeset
   204
/**
0b2fb43cc875 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents: 8857
diff changeset
   205
 * Decide 'where' (between left and right speaker) to play the sound effect.
0b2fb43cc875 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents: 8857
diff changeset
   206
 * @param sound Sound effect to play
0b2fb43cc875 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents: 8857
diff changeset
   207
 * @param left   Left edge of virtual coordinates where the sound is produced
0b2fb43cc875 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents: 8857
diff changeset
   208
 * @param right  Right edge of virtual coordinates where the sound is produced
0b2fb43cc875 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents: 8857
diff changeset
   209
 * @param top    Top edge of virtual coordinates where the sound is produced
0b2fb43cc875 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents: 8857
diff changeset
   210
 * @param bottom Bottom edge of virtual coordinates where the sound is produced
0b2fb43cc875 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents: 8857
diff changeset
   211
 */
8588
2674b9a4be81 (svn r12169) -Change [FS#1696]: play sounds when there is only small part of tile/vehicle visible too (original idea by Dominik)
smatz
parents: 8439
diff changeset
   212
static void SndPlayScreenCoordFx(SoundFx sound, int left, int right, int top, int bottom)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   213
{
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
   214
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
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
   216
	if (msf.effect_vol == 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   217
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5024
diff changeset
   218
	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
   219
		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
   220
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
   221
		if (vp != NULL &&
8588
2674b9a4be81 (svn r12169) -Change [FS#1696]: play sounds when there is only small part of tile/vehicle visible too (original idea by Dominik)
smatz
parents: 8439
diff changeset
   222
				left < vp->virtual_left + vp->virtual_width && right > vp->virtual_left &&
2674b9a4be81 (svn r12169) -Change [FS#1696]: play sounds when there is only small part of tile/vehicle visible too (original idea by Dominik)
smatz
parents: 8439
diff changeset
   223
				top < vp->virtual_top + vp->virtual_height && bottom > vp->virtual_top) {
2674b9a4be81 (svn r12169) -Change [FS#1696]: play sounds when there is only small part of tile/vehicle visible too (original idea by Dominik)
smatz
parents: 8439
diff changeset
   224
			int screen_x = (left + right) / 2 - vp->virtual_left;
8595
718ce3c308fb (svn r12176) -Codechange: one division less when playing sounds (patch by Dominik)
smatz
parents: 8588
diff changeset
   225
			int width = (vp->virtual_width == 0 ? 1 : vp->virtual_width);
718ce3c308fb (svn r12176) -Codechange: one division less when playing sounds (patch by Dominik)
smatz
parents: 8588
diff changeset
   226
			int panning = (screen_x * PANNING_LEVELS * 2) / width - PANNING_LEVELS;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 0
diff changeset
   227
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   228
			StartSound(
4656
9c1d8c4d3e60 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4171
diff changeset
   229
				sound,
8595
718ce3c308fb (svn r12176) -Codechange: one division less when playing sounds (patch by Dominik)
smatz
parents: 8588
diff changeset
   230
				panning,
8439
6913310b9a18 (svn r12009) -Fix [FS#1707]: Avoid loading sample.cat if it 'looks' incorrect, and avoid later null pointer dereferences by moving volume lookup deeper.
peter1138
parents: 8224
diff changeset
   231
				(msf.effect_vol * _vol_factor_by_zoom[vp->zoom - ZOOM_LVL_BEGIN]) / 256
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   232
			);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   233
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   235
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   237
337
cbe0c766c947 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
   238
void SndPlayTileFx(SoundFx sound, TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   239
{
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3421
diff changeset
   240
	/* emits sound from center of the tile */
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3421
diff changeset
   241
	int x = TileX(tile) * TILE_SIZE + TILE_SIZE / 2;
8588
2674b9a4be81 (svn r12169) -Change [FS#1696]: play sounds when there is only small part of tile/vehicle visible too (original idea by Dominik)
smatz
parents: 8439
diff changeset
   242
	int y = TileY(tile) * TILE_SIZE - TILE_SIZE / 2;
8604
36135d25a700 (svn r12186) -Fix [FS#1784](r12169): assert when trying to play tile sound at NW border of map (placing buyos, leveling land)
smatz
parents: 8595
diff changeset
   243
	uint z = (y < 0 ? 0 : GetSlopeZ(x, y));
36135d25a700 (svn r12186) -Fix [FS#1784](r12169): assert when trying to play tile sound at NW border of map (placing buyos, leveling land)
smatz
parents: 8595
diff changeset
   244
	Point pt = RemapCoords(x, y, z);
8588
2674b9a4be81 (svn r12169) -Change [FS#1696]: play sounds when there is only small part of tile/vehicle visible too (original idea by Dominik)
smatz
parents: 8439
diff changeset
   245
	y += 2 * TILE_SIZE;
2674b9a4be81 (svn r12169) -Change [FS#1696]: play sounds when there is only small part of tile/vehicle visible too (original idea by Dominik)
smatz
parents: 8439
diff changeset
   246
	Point pt2 = RemapCoords(x, y, GetSlopeZ(x, y));
2674b9a4be81 (svn r12169) -Change [FS#1696]: play sounds when there is only small part of tile/vehicle visible too (original idea by Dominik)
smatz
parents: 8439
diff changeset
   247
	SndPlayScreenCoordFx(sound, pt.x, pt2.x, pt.y, pt2.y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   248
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   249
337
cbe0c766c947 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
   250
void SndPlayVehicleFx(SoundFx sound, const Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   251
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   252
	SndPlayScreenCoordFx(sound,
8588
2674b9a4be81 (svn r12169) -Change [FS#1696]: play sounds when there is only small part of tile/vehicle visible too (original idea by Dominik)
smatz
parents: 8439
diff changeset
   253
		v->left_coord, v->right_coord,
2674b9a4be81 (svn r12169) -Change [FS#1696]: play sounds when there is only small part of tile/vehicle visible too (original idea by Dominik)
smatz
parents: 8439
diff changeset
   254
		v->top_coord, v->top_coord
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
	);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
337
cbe0c766c947 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
   258
void SndPlayFx(SoundFx sound)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   259
{
8439
6913310b9a18 (svn r12009) -Fix [FS#1707]: Avoid loading sample.cat if it 'looks' incorrect, and avoid later null pointer dereferences by moving volume lookup deeper.
peter1138
parents: 8224
diff changeset
   260
	StartSound(sound, 0, msf.effect_vol);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
}