File: snd.c

package info (click to toggle)
biniax2 1.30-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 5,048 kB
  • sloc: ansic: 12,972; makefile: 20
file content (151 lines) | stat: -rwxr-xr-x 4,303 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/******************************************************************************
BINIAX SOUND-RELATED IMPLEMENTATIONS
COPYRIGHT JORDAN TUZSUZOV, (C) 2005-2009

  This software is provided 'as-is', without any express or implied
  warranty.  In no event will the authors be held liable for any damages
  arising from the use of this software.

  Permission is granted to anyone to use this software for any purpose,
  including commercial applications, and to alter it and redistribute it
  freely, subject to the following restrictions:

  1. The origin of this software must not be misrepresented; you must not
     claim that you wrote the original software. If you use this software
     in a product, an acknowledgment in the product documentation would be
     appreciated but is not required.
  2. Altered source versions must be plainly marked as such, and must not be
     misrepresented as being the original software.
  3. This notice may not be removed or altered from any source distribution.

LICENSE ORIGIN : http://www.gzip.org/zlib/zlib_license.html

For complete product license refer to LICENSE.TXT file

******************************************************************************/

/******************************************************************************
INCLUDES
******************************************************************************/

#include <stdlib.h>
#include <SDL_mixer.h>

#include "inc.h"

/******************************************************************************
LOCALS
******************************************************************************/

BNX_SND _Snd;

/******************************************************************************
FUNCTIONS
******************************************************************************/

BNX_BOOL sndInit()
{
	BNX_INT32	audio_rate		= 44000;
	BNX_UINT16	audio_format	= AUDIO_S16;
	BNX_INT32	audio_channels	= 2;
	BNX_BOOL	loaded			= BNX_TRUE;

	if ( Mix_OpenAudio( audio_rate, audio_format, audio_channels, 1024 ) < 0 )
	{
		cfgSetMusic( BNX_FALSE );
		cfgSetSound( BNX_FALSE );
		return BNX_TRUE;
	}
	else
	{
		Mix_QuerySpec( &audio_rate, &audio_format, &audio_channels );
	}

	Mix_VolumeMusic( MIX_MAX_VOLUME >> 1 );

	_Snd.sounds[ 1 ] = Mix_LoadWAV( DATADIR "/sound/sfx1.wav" );
	_Snd.sounds[ 2 ] = Mix_LoadWAV( DATADIR "/sound/sfx2.wav" );
	_Snd.sounds[ 3 ] = Mix_LoadWAV( DATADIR "/sound/sfx3.wav" );
	_Snd.sounds[ 4 ] = Mix_LoadWAV( DATADIR "/sound/sfx4.wav" );
	_Snd.sounds[ 5 ] = Mix_LoadWAV( DATADIR "/sound/sfx5.wav" );

	_Snd.music[ 0 ] = Mix_LoadMUS( DATADIR "/music/biniax_common00.it" );
	_Snd.music[ 1 ] = Mix_LoadMUS( DATADIR "/music/biniax_common01.it" );
	_Snd.music[ 2 ] = Mix_LoadMUS( DATADIR "/music/biniax_common02.it" );
	_Snd.music[ 3 ] = Mix_LoadMUS( DATADIR "/music/biniax_common03.it" );
	_Snd.music[ 4 ] = Mix_LoadMUS( DATADIR "/music/biniax_common04.it" );
	_Snd.music[ 5 ] = Mix_LoadMUS( DATADIR "/music/biniax_common05.it" );
	_Snd.music[ 6 ] = Mix_LoadMUS( DATADIR "/music/biniax_common06.it" );
	_Snd.music[ 7 ] = Mix_LoadMUS( DATADIR "/music/biniax_common07.it" );

	return loaded;
}

void sndUpdate()
{
	return;
}

void sndPlay( BNX_GAME *game )
{
	BNX_UINT32 snd		= 0;
	BNX_UINT32 sndmask	= 1;

	if ( cfgGetSound() == BNX_FALSE )
	{
		return;
	}

	while ( game->sounds != cSndNone && snd <= cSndLast )
	{
		sndmask = 1 << snd;
		if ( (game->sounds & sndmask) != cSndNone )
		{
			if ( _Snd.sounds[ snd ] != NULL )
			{
				Mix_PlayChannel( snd % cSndChannels, _Snd.sounds[ snd ], 0 );
			}
		}
		game->sounds &= ~sndmask;
		snd ++;
	}
}

void sndPlayMusic( BNX_INT16 index )
{
	if ( cfgGetMusic() == BNX_FALSE )
	{
		return;
	}

	if ( index >= 0 && index < cSndMaxMusic )
	{
		_Snd.curMusic = index;
		Mix_PlayMusic( _Snd.music[ index ], 1 );
	}
}

void sndUpdateMusic( BNX_GAME *game, BNX_BOOL change )
{
	BNX_INT32	newMusic;

	if ( cfgGetMusic() == BNX_FALSE )
	{
		return;
	}

	if ( Mix_PlayingMusic() == 0 )
	{
		if ( change == BNX_TRUE )
		{
			do
			{
				newMusic = sysRand( cSndMaxMusic-1 );
			} while( _Snd.curMusic == newMusic );
			
			_Snd.curMusic = newMusic;
		}

		sndPlayMusic( _Snd.curMusic );
	}
}