src/sound.cpp
author belugas
Sun, 15 Jun 2008 02:48:25 +0000
changeset 10965 a2b5f6f9be0c
parent 10751 ebd94f2d6385
child 10997 968df7476121
permissions -rw-r--r--
(svn r13519) -Feature[newGRF]: Implement var 63, variational action2 variable for Houses.
Or, in more simple terms, the check for the animation frame of nearby house.
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
10429
1b99254f9607 (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: 10255
diff changeset
     3
/** @file sound.cpp Handling of playing sounds. */
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6573
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1498
diff changeset
     6
#include "openttd.h"
6949
72d11a1e1e60 (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: 6916
diff changeset
     7
#include "landscape.h"
1496
3d0b86f5dcb8 (svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents: 1136
diff changeset
     8
#include "mixer.h"
8653
a83f7a536919 (svn r11719) -Codechange: split sound.h in a header with types and one with functions.
rubidium
parents: 8640
diff changeset
     9
#include "sound_func.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    10
#include "fileio.h"
4656
acffecd6f484 (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"
8301
47e8f031a6ab (svn r11355) -Fix [FS#1377]: loading too many GRFs was not handled gracefully causing crashes and such.
rubidium
parents: 8087
diff changeset
    12
#include "fios.h"
8602
9e75e594a068 (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: 8591
diff changeset
    13
#include "window_gui.h"
8626
440dfcd14c4a (svn r11691) -Codechange: move+rename helpers.hpp and only include it when it is really needed.
rubidium
parents: 8602
diff changeset
    14
#include "core/alloc_func.hpp"
8635
3bbb6f87fced (svn r11701) -Codechange: removal unnecessary inclusions of map.h (and split map.h).
rubidium
parents: 8627
diff changeset
    15
#include "map_func.h"
8640
1e93b81e96d2 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents: 8635
diff changeset
    16
#include "vehicle_base.h"
8935
9088834ecd43 (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: 8720
diff changeset
    17
#include "debug.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
1496
3d0b86f5dcb8 (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
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 3898
diff changeset
    20
static FileEntry *_files;
8653
a83f7a536919 (svn r11719) -Codechange: split sound.h in a header with types and one with functions.
rubidium
parents: 8640
diff changeset
    21
MusicFileSettings msf;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
2594
c65db1a9f630 (svn r3131) Enable panning of audio relative to screen position.
peter1138
parents: 2372
diff changeset
    23
// Number of levels of panning per side
c65db1a9f630 (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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    26
1496
3d0b86f5dcb8 (svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents: 1136
diff changeset
    27
static void OpenBankFile(const char *filename)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
{
2371
fafe059a4472 (svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents: 2186
diff changeset
    29
	uint i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    30
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
	FioOpenFile(SOUND_SLOT, filename);
10751
ebd94f2d6385 (svn r13301) -Fix [FS#1997]: resolve more MSVC 9 x64 warnings.
rubidium
parents: 10429
diff changeset
    32
	size_t pos = FioGetPos();
8935
9088834ecd43 (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: 8720
diff changeset
    33
	uint count = FioReadDword() / 8;
9088834ecd43 (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: 8720
diff changeset
    34
9088834ecd43 (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: 8720
diff changeset
    35
	/* Simple check for the correct number of original sounds. */
9088834ecd43 (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: 8720
diff changeset
    36
	if (count != 73) {
9088834ecd43 (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: 8720
diff changeset
    37
		DEBUG(misc, 6, "Incorrect number of sounds in '%s', ignoring.", filename);
9088834ecd43 (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: 8720
diff changeset
    38
		_file_count = 0;
9088834ecd43 (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: 8720
diff changeset
    39
		_files = NULL;
9088834ecd43 (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: 8720
diff changeset
    40
		return;
9088834ecd43 (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: 8720
diff changeset
    41
	}
9088834ecd43 (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: 8720
diff changeset
    42
5860
7fdc9b423ba1 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5838
diff changeset
    43
	FileEntry *fe = CallocT<FileEntry>(count);
2371
fafe059a4472 (svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents: 2186
diff changeset
    44
fafe059a4472 (svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents: 2186
diff changeset
    45
	if (fe == NULL) {
fafe059a4472 (svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents: 2186
diff changeset
    46
		_file_count = 0;
fafe059a4472 (svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents: 2186
diff changeset
    47
		_files = NULL;
2372
f751e366f618 (svn r2898) Fix typo in r2897
tron
parents: 2371
diff changeset
    48
		return;
2371
fafe059a4472 (svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents: 2186
diff changeset
    49
	}
fafe059a4472 (svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents: 2186
diff changeset
    50
fafe059a4472 (svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents: 2186
diff changeset
    51
	_file_count = count;
fafe059a4472 (svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents: 2186
diff changeset
    52
	_files = fe;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    53
8087
064305edb998 (svn r11118) -Fix: sample.cat can now be in a tar-file too, how nice!
truelight
parents: 8066
diff changeset
    54
	FioSeekTo(pos, SEEK_SET);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    55
1496
3d0b86f5dcb8 (svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents: 1136
diff changeset
    56
	for (i = 0; i != count; i++) {
8066
7acd480e05c9 (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: 7387
diff changeset
    57
		fe[i].file_slot = SOUND_SLOT;
8087
064305edb998 (svn r11118) -Fix: sample.cat can now be in a tar-file too, how nice!
truelight
parents: 8066
diff changeset
    58
		fe[i].file_offset = FioReadDword() + pos;
1496
3d0b86f5dcb8 (svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents: 1136
diff changeset
    59
		fe[i].file_size = FioReadDword();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    60
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 0
diff changeset
    61
337
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    62
	for (i = 0; i != count; i++, fe++) {
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    63
		char name[255];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    64
337
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    65
		FioSeekTo(fe->file_offset, SEEK_SET);
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    66
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6573
diff changeset
    67
		/* Check for special case, see else case */
337
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    68
		FioReadBlock(name, FioReadByte()); // Read the name of the sound
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    69
		if (strcmp(name, "Corrupt sound") != 0) {
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    70
			FioSeekTo(12, SEEK_CUR); // Skip past RIFF header
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    71
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6573
diff changeset
    72
			/* Read riff tags */
337
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    73
			for (;;) {
2371
fafe059a4472 (svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents: 2186
diff changeset
    74
				uint32 tag = FioReadDword();
fafe059a4472 (svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents: 2186
diff changeset
    75
				uint32 size = FioReadDword();
337
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    76
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    77
				if (tag == ' tmf') {
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    78
					FioReadWord(); // wFormatTag
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    79
					fe->channels = FioReadWord(); // wChannels
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    80
					FioReadDword();   // samples per second
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    81
					fe->rate = 11025; // seems like all samples should be played at this rate.
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    82
					FioReadDword();   // avg bytes per second
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    83
					FioReadWord();    // alignment
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    84
					fe->bits_per_sample = FioReadByte(); // bits per sample
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    85
					FioSeekTo(size - (2 + 2 + 4 + 4 + 2 + 1), SEEK_CUR);
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    86
				} else if (tag == 'atad') {
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    87
					fe->file_size = size;
8066
7acd480e05c9 (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: 7387
diff changeset
    88
					fe->file_slot = SOUND_SLOT;
7acd480e05c9 (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: 7387
diff changeset
    89
					fe->file_offset = FioGetPos();
337
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    90
					break;
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    91
				} else {
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    92
					fe->file_size = 0;
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    93
					break;
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    94
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    95
			}
337
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    96
		} else {
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    97
			/*
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    98
			 * Special case for the jackhammer sound
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    99
			 * (name in sample.cat is "Corrupt sound")
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
   100
			 * It's no RIFF file, but raw PCM data
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
   101
			 */
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
   102
			fe->channels = 1;
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
   103
			fe->rate = 11025;
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
   104
			fe->bits_per_sample = 8;
8066
7acd480e05c9 (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: 7387
diff changeset
   105
			fe->file_slot = SOUND_SLOT;
7acd480e05c9 (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: 7387
diff changeset
   106
			fe->file_offset = FioGetPos();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   107
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   110
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 5860
diff changeset
   111
uint GetNumOriginalSounds()
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4171
diff changeset
   112
{
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4171
diff changeset
   113
	return _file_count;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4171
diff changeset
   114
}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4171
diff changeset
   115
8935
9088834ecd43 (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: 8720
diff changeset
   116
static bool SetBankSource(MixerChannel *mc, const FileEntry *fe)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   117
{
8935
9088834ecd43 (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: 8720
diff changeset
   118
	assert(fe != NULL);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 0
diff changeset
   119
2371
fafe059a4472 (svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents: 2186
diff changeset
   120
	if (fe->file_size == 0) return false;
fafe059a4472 (svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents: 2186
diff changeset
   121
5860
7fdc9b423ba1 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5838
diff changeset
   122
	int8 *mem = MallocT<int8>(fe->file_size);
2371
fafe059a4472 (svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents: 2186
diff changeset
   123
	if (mem == NULL) return false;
fafe059a4472 (svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents: 2186
diff changeset
   124
8066
7acd480e05c9 (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: 7387
diff changeset
   125
	FioSeekToFile(fe->file_slot, fe->file_offset);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   126
	FioReadBlock(mem, fe->file_size);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   127
8935
9088834ecd43 (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: 8720
diff changeset
   128
	for (uint i = 0; i != fe->file_size; i++) {
1136
052a24d24813 (svn r1637) -Fix: VS6 warning
darkvater
parents: 926
diff changeset
   129
		mem[i] += -128; // Convert unsigned sound data to signed
8935
9088834ecd43 (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: 8720
diff changeset
   130
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 0
diff changeset
   131
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   132
	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
   133
1496
3d0b86f5dcb8 (svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents: 1136
diff changeset
   134
	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
   135
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
1496
3d0b86f5dcb8 (svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents: 1136
diff changeset
   139
bool SoundInitialize(const char *filename)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   140
{
1496
3d0b86f5dcb8 (svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents: 1136
diff changeset
   141
	OpenBankFile(filename);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   142
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   143
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   144
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6573
diff changeset
   145
/* Low level sound player */
2594
c65db1a9f630 (svn r3131) Enable panning of audio relative to screen position.
peter1138
parents: 2372
diff changeset
   146
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
   147
{
8935
9088834ecd43 (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: 8720
diff changeset
   148
	if (volume == 0) return;
2371
fafe059a4472 (svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents: 2186
diff changeset
   149
8935
9088834ecd43 (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: 8720
diff changeset
   150
	const FileEntry *fe = GetSound(sound);
9088834ecd43 (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: 8720
diff changeset
   151
	if (fe == NULL) return;
9088834ecd43 (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: 8720
diff changeset
   152
9088834ecd43 (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: 8720
diff changeset
   153
	MixerChannel *mc = MxAllocateChannel();
2371
fafe059a4472 (svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents: 2186
diff changeset
   154
	if (mc == NULL) return;
8935
9088834ecd43 (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: 8720
diff changeset
   155
9088834ecd43 (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: 8720
diff changeset
   156
	if (!SetBankSource(mc, fe)) return;
9088834ecd43 (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: 8720
diff changeset
   157
9088834ecd43 (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: 8720
diff changeset
   158
	/* Apply the sound effect's own volume. */
9088834ecd43 (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: 8720
diff changeset
   159
	volume = (fe->volume * volume) / 128;
2594
c65db1a9f630 (svn r3131) Enable panning of audio relative to screen position.
peter1138
parents: 2372
diff changeset
   160
8418
b49fc6be1ab9 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents: 8301
diff changeset
   161
	panning = Clamp(panning, -PANNING_LEVELS, PANNING_LEVELS);
8935
9088834ecd43 (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: 8720
diff changeset
   162
	uint left_vol = (volume * PANNING_LEVELS) - (volume * panning);
9088834ecd43 (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: 8720
diff changeset
   163
	uint right_vol = (volume * PANNING_LEVELS) + (volume * panning);
2594
c65db1a9f630 (svn r3131) Enable panning of audio relative to screen position.
peter1138
parents: 2372
diff changeset
   164
	MxSetChannelVolume(mc, left_vol * 128 / PANNING_LEVELS, right_vol * 128 / PANNING_LEVELS);
2371
fafe059a4472 (svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents: 2186
diff changeset
   165
	MxActivateChannel(mc);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   166
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   168
7349
2ebfdf726932 (svn r10093) -Revert: removed 16x zoom-out as it is broken beyond repair
truelight
parents: 7150
diff changeset
   169
static const byte _vol_factor_by_zoom[] = {255, 190, 134, 87};
8591
46eca2eb57ba (svn r11656) -Codechange: add ZOOM_LVL_BEGIN and postfix operators so ZoomLevel can be used in some iterations
smatz
parents: 8450
diff changeset
   170
assert_compile(lengthof(_vol_factor_by_zoom) == ZOOM_LVL_END - ZOOM_LVL_BEGIN);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   171
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   172
static const byte _sound_base_vol[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
	128,  90, 128, 128, 128, 128, 128, 128,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   174
	128,  90,  90, 128, 128, 128, 128, 128,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   175
	128, 128, 128,  80, 128, 128, 128, 128,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   176
	128, 128, 128, 128, 128, 128, 128, 128,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   177
	128, 128,  90,  90,  90, 128,  90, 128,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
	128,  90, 128, 128, 128,  90, 128, 128,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   179
	128, 128, 128, 128,  90, 128, 128, 128,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   180
	128,  90, 128, 128, 128, 128, 128, 128,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   181
	128, 128,  90,  90,  90, 128, 128, 128,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   182
	 90,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   183
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   185
static const byte _sound_idx[] = {
2371
fafe059a4472 (svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents: 2186
diff changeset
   186
	 2,  3,  4,  5,  6,  7,  8,  9,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
	10, 11, 12, 13, 14, 15, 16, 17,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
	18, 19, 20, 21, 22, 23, 24, 25,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
	26, 27, 28, 29, 30, 31, 32, 33,
2371
fafe059a4472 (svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents: 2186
diff changeset
   190
	34, 35, 36, 37, 38, 39, 40,  0,
fafe059a4472 (svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents: 2186
diff changeset
   191
	 1, 41, 42, 43, 44, 45, 46, 47,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   192
	48, 49, 50, 51, 52, 53, 54, 55,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   193
	56, 57, 58, 59, 60, 61, 62, 63,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   194
	64, 65, 66, 67, 68, 69, 70, 71,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   195
	72,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   196
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   197
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 5860
diff changeset
   198
void SndCopyToPool()
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4171
diff changeset
   199
{
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9100
diff changeset
   200
	for (uint i = 0; i < _file_count; i++) {
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4171
diff changeset
   201
		FileEntry *orig = &_files[_sound_idx[i]];
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4171
diff changeset
   202
		FileEntry *fe = AllocateFileEntry();
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4171
diff changeset
   203
5024
f13f2f2d43f9 (svn r7065) Use simple assignment instead of memcpy()
tron
parents: 4656
diff changeset
   204
		*fe = *orig;
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4171
diff changeset
   205
		fe->volume = _sound_base_vol[i];
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4171
diff changeset
   206
		fe->priority = 0;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4171
diff changeset
   207
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4171
diff changeset
   208
}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4171
diff changeset
   209
10255
5600b575e6e7 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents: 10083
diff changeset
   210
/**
5600b575e6e7 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents: 10083
diff changeset
   211
 * Decide 'where' (between left and right speaker) to play the sound effect.
5600b575e6e7 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents: 10083
diff changeset
   212
 * @param sound Sound effect to play
5600b575e6e7 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents: 10083
diff changeset
   213
 * @param left   Left edge of virtual coordinates where the sound is produced
5600b575e6e7 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents: 10083
diff changeset
   214
 * @param right  Right edge of virtual coordinates where the sound is produced
5600b575e6e7 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents: 10083
diff changeset
   215
 * @param top    Top edge of virtual coordinates where the sound is produced
5600b575e6e7 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents: 10083
diff changeset
   216
 * @param bottom Bottom edge of virtual coordinates where the sound is produced
5600b575e6e7 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents: 10083
diff changeset
   217
 */
9084
6c346455a7e7 (svn r12169) -Change [FS#1696]: play sounds when there is only small part of tile/vehicle visible too (original idea by Dominik)
smatz
parents: 8935
diff changeset
   218
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
   219
{
5137
a1f26c30fecd (svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents: 5124
diff changeset
   220
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   221
2371
fafe059a4472 (svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents: 2186
diff changeset
   222
	if (msf.effect_vol == 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   223
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5024
diff changeset
   224
	FOR_ALL_WINDOWS(wz) {
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5024
diff changeset
   225
		const ViewPort *vp = (*wz)->viewport;
2371
fafe059a4472 (svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents: 2186
diff changeset
   226
fafe059a4472 (svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
tron
parents: 2186
diff changeset
   227
		if (vp != NULL &&
9084
6c346455a7e7 (svn r12169) -Change [FS#1696]: play sounds when there is only small part of tile/vehicle visible too (original idea by Dominik)
smatz
parents: 8935
diff changeset
   228
				left < vp->virtual_left + vp->virtual_width && right > vp->virtual_left &&
6c346455a7e7 (svn r12169) -Change [FS#1696]: play sounds when there is only small part of tile/vehicle visible too (original idea by Dominik)
smatz
parents: 8935
diff changeset
   229
				top < vp->virtual_top + vp->virtual_height && bottom > vp->virtual_top) {
6c346455a7e7 (svn r12169) -Change [FS#1696]: play sounds when there is only small part of tile/vehicle visible too (original idea by Dominik)
smatz
parents: 8935
diff changeset
   230
			int screen_x = (left + right) / 2 - vp->virtual_left;
9091
c1cddeb8511c (svn r12176) -Codechange: one division less when playing sounds (patch by Dominik)
smatz
parents: 9084
diff changeset
   231
			int width = (vp->virtual_width == 0 ? 1 : vp->virtual_width);
c1cddeb8511c (svn r12176) -Codechange: one division less when playing sounds (patch by Dominik)
smatz
parents: 9084
diff changeset
   232
			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
   233
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
			StartSound(
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4171
diff changeset
   235
				sound,
9091
c1cddeb8511c (svn r12176) -Codechange: one division less when playing sounds (patch by Dominik)
smatz
parents: 9084
diff changeset
   236
				panning,
8935
9088834ecd43 (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: 8720
diff changeset
   237
				(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
   238
			);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   239
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   242
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   243
337
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
   244
void SndPlayTileFx(SoundFx sound, TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   245
{
3645
86af43f87885 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3421
diff changeset
   246
	/* emits sound from center of the tile */
86af43f87885 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3421
diff changeset
   247
	int x = TileX(tile) * TILE_SIZE + TILE_SIZE / 2;
9084
6c346455a7e7 (svn r12169) -Change [FS#1696]: play sounds when there is only small part of tile/vehicle visible too (original idea by Dominik)
smatz
parents: 8935
diff changeset
   248
	int y = TileY(tile) * TILE_SIZE - TILE_SIZE / 2;
9100
a68061bad214 (svn r12186) -Fix [FS#1784](r12169): assert when trying to play tile sound at NW border of map (placing buyos, leveling land)
smatz
parents: 9091
diff changeset
   249
	uint z = (y < 0 ? 0 : GetSlopeZ(x, y));
a68061bad214 (svn r12186) -Fix [FS#1784](r12169): assert when trying to play tile sound at NW border of map (placing buyos, leveling land)
smatz
parents: 9091
diff changeset
   250
	Point pt = RemapCoords(x, y, z);
9084
6c346455a7e7 (svn r12169) -Change [FS#1696]: play sounds when there is only small part of tile/vehicle visible too (original idea by Dominik)
smatz
parents: 8935
diff changeset
   251
	y += 2 * TILE_SIZE;
6c346455a7e7 (svn r12169) -Change [FS#1696]: play sounds when there is only small part of tile/vehicle visible too (original idea by Dominik)
smatz
parents: 8935
diff changeset
   252
	Point pt2 = RemapCoords(x, y, GetSlopeZ(x, y));
6c346455a7e7 (svn r12169) -Change [FS#1696]: play sounds when there is only small part of tile/vehicle visible too (original idea by Dominik)
smatz
parents: 8935
diff changeset
   253
	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
   254
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
337
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
   256
void SndPlayVehicleFx(SoundFx sound, const Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
	SndPlayScreenCoordFx(sound,
9084
6c346455a7e7 (svn r12169) -Change [FS#1696]: play sounds when there is only small part of tile/vehicle visible too (original idea by Dominik)
smatz
parents: 8935
diff changeset
   259
		v->left_coord, v->right_coord,
6c346455a7e7 (svn r12169) -Change [FS#1696]: play sounds when there is only small part of tile/vehicle visible too (original idea by Dominik)
smatz
parents: 8935
diff changeset
   260
		v->top_coord, v->top_coord
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
	);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
337
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
   264
void SndPlayFx(SoundFx sound)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
{
8935
9088834ecd43 (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: 8720
diff changeset
   266
	StartSound(sound, 0, msf.effect_vol);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
}