1 /*
2 * snd_allegro.c
3 *
4 * allegro sound interface
5 */
6
7 /* $Id: snd_allegro.c,v 1.2 1999/10/31 14:43:02 nyef Exp $ */
8
9 #include <allegro.h>
10
11 #include "ui.h"
12 #include "snd.h"
13
14 AUDIOSTREAM *sound_stream;
15
snd_output_4_waves(int samples,u8 * wave1,u8 * wave2,u8 * wave3,u8 * wave4)16 void snd_output_4_waves(int samples, u8 *wave1, u8 *wave2, u8 *wave3, u8 *wave4)
17 {
18 unsigned char *final_wave;
19 int i;
20
21 if (sound_stream) {
22 final_wave = NULL;
23
24 while (!final_wave) { /* Wheee... Primitive Framesync. :-) */
25 final_wave = get_audio_stream_buffer(sound_stream);
26 }
27
28 for (i = 0; i < samples; i++) {
29 final_wave[i] = (wave1[i] + wave2[i] + wave3[i] + wave4[i]) >> 2;
30 }
31
32 free_audio_stream_buffer(sound_stream);
33 }
34 }
35
snd_init(void)36 void snd_init(void)
37 {
38 sound_stream = NULL;
39 }
40
snd_open(int samples_per_sync,int sample_rate)41 int snd_open(int samples_per_sync, int sample_rate)
42 {
43 if (install_sound(DIGI_AUTODETECT, MIDI_NONE, NULL) != 0) {
44 deb_printf("Error initializing sound system\n%s\n", allegro_error);
45 return 0;
46 } else {
47 sound_stream = play_audio_stream(samples_per_sync, 8, sample_rate, 255, 128);
48 if (!sound_stream) {
49 deb_printf("unable to create audio stream.\n");
50 return 0;
51 }
52 }
53 return 1;
54 }
55
snd_close(void)56 void snd_close(void)
57 {
58 if (sound_stream) {
59 stop_audio_stream(sound_stream);
60 }
61 }
62
63 /*
64 * $Log: snd_allegro.c,v $
65 * Revision 1.2 1999/10/31 14:43:02 nyef
66 * fixed to compile without warnings
67 * fixed to only stop the audio stream if we actually had one
68 *
69 * Revision 1.1 1999/10/31 02:37:46 nyef
70 * Initial revision
71 *
72 */
73