1 /*
2  * OpenBOR - http://www.chronocrash.com
3  * -----------------------------------------------------------------------
4  * All rights reserved, see LICENSE in OpenBOR root for details.
5  *
6  * Copyright (c) 2004 - 2014 OpenBOR Team
7  */
8 
9 #ifndef SOUNDMIX_H
10 #define SOUNDMIX_H
11 
12 #include "types.h"
13 
14 /*
15 **	Sound mixer.
16 **	Now supports ADPCM instead of MP3 (costs less CPU time).
17 **
18 **	Also plays WAV files (unsigned, mono, both 8-bit and 16-bit).
19 */
20 
21 // 20:12 fixed-point conversion macros.
22 // The maximum size of a sound is linked directly
23 // to the range of the fixed-point variables!
24 #define		INT_TO_FIX(i)		((unsigned int)i<<12)
25 #define		FIX_TO_INT(f)		((unsigned int)f>>12)
26 #define		MAX_SOUND_LEN		0xFFFFF
27 #define		CHANNEL_PLAYING		1
28 #define		CHANNEL_LOOPING		2
29 #define		MUSIC_NUM_BUFFERS	4
30 #define		MUSIC_BUF_SIZE		(16*1024)	// In samples
31 #define		SOUND_MONO			1
32 #define		SOUND_STEREO		2
33 
34 typedef struct
35 {
36     int            active;
37     int            paused;
38     short 		   *buf[MUSIC_NUM_BUFFERS];
39     unsigned int   fp_playto[MUSIC_NUM_BUFFERS];
40     unsigned int   fp_samplepos;  // Position (fixed-point)
41     unsigned int   fp_period;	  // Period (fixed-point)
42     int			   playing_buffer;
43     int            volume[2];
44     int            channels;
45 } musicchannelstruct;
46 
47 extern musicchannelstruct musicchannel;
48 extern int playfrequency;
49 
50 void sound_stop_playback();
51 int sound_start_playback(int bits, int frequency);
52 void sound_exit();
53 int sound_init(int channels);
54 
55 extern int sample_play_id;
56 
57 // Returns interval in milliseconds
58 u32 sound_getinterval();
59 int sound_load_sample(char *filename, char *packfilename, int iLog);
60 int sound_reload_sample(int index);
61 void sound_unload_sample(int index);
62 void sound_unload_all_samples();
63 int sound_query_channel(int playid);
64 int sound_id(int channel);
65 int sound_is_active(int channel);
66 int sound_play_sample(int samplenum, unsigned int priority, int lvolume, int rvolume, unsigned int speed);
67 int sound_loop_sample(int samplenum, unsigned int priority, int lvolume, int rvolume, unsigned int speed);
68 void sound_stop_sample(int channel);
69 void sound_stopall_sample();
70 void sound_pause_sample(int toggle);
71 void sound_pause_single_sample(int toggle, int channel);
72 void sound_volume_sample(int channel, int lvolume, int rvolume);
73 int sound_getpos_sample(int channel);
74 
75 #ifdef DC
76 int sound_was_music_opened();
77 #endif
78 
79 int sound_open_music(char *filename, char *packname, int volume, int loop, u32 music_offset);
80 void sound_close_music();
81 void sound_update_music();
82 void sound_volume_music(int left, int right);
83 void sound_music_tempo(int music_tempo);
84 int sound_query_music(char *artist, char *title);
85 void sound_pause_music(int toggle);
86 
87 void update_sample(unsigned char *buf, int size);
88 
89 int maxchannels(void);
90 
91 #endif
92