1 /*
2  * UADE
3  *
4  * Support for sound
5  *
6  * Copyright 2000 - 2005 Heikki Orsila <heikki.orsila@iki.fi>
7  */
8 
9 #include "sysconfig.h"
10 #include "sysdeps.h"
11 
12 #include "options.h"
13 #include "memory.h"
14 #include "custom.h"
15 #include "gensound.h"
16 #include "sd-sound.h"
17 #include "audio.h"
18 #include "uade.h"
19 
20 uae_u16 sndbuffer[MAX_SOUND_BUF_SIZE / 2];
21 uae_u16 *sndbufpt;
22 int sndbufsize;
23 
24 int sound_bytes_per_second;
25 
close_sound(void)26 void close_sound (void)
27 {
28 }
29 
30 /* Try to determine whether sound is available.  */
setup_sound(void)31 int setup_sound (void)
32 {
33    sound_available = 1;
34    return 1;
35 }
36 
37 
set_sound_freq(int x)38 void set_sound_freq(int x)
39 {
40   /* Validation is done later in init_sound() */
41   currprefs.sound_freq = x;
42   init_sound();
43 }
44 
45 
init_sound(void)46 void init_sound (void)
47 {
48   int channels;
49   int dspbits;
50   unsigned int rate;
51 
52   if (currprefs.sound_maxbsiz < 128 || currprefs.sound_maxbsiz > 16384) {
53     fprintf (stderr, "Sound buffer size %d out of range.\n", currprefs.sound_maxbsiz);
54     currprefs.sound_maxbsiz = 8192;
55   }
56   sndbufsize = 8192;
57 
58   dspbits = currprefs.sound_bits;
59   rate    = currprefs.sound_freq;
60   channels = currprefs.stereo ? 2 : 1;
61 
62   if (dspbits != (UADE_BYTES_PER_SAMPLE * 8)) {
63     fprintf(stderr, "Only 16 bit sounds supported.\n");
64     exit(-1);
65   }
66   if (rate < 1 || rate > SOUNDTICKS_NTSC) {
67     fprintf(stderr, "Too small or high a rate: %u\n", rate);
68     exit(-1);
69   }
70   if (channels != UADE_CHANNELS) {
71     fprintf(stderr, "Only stereo supported.\n");
72     exit(-1);
73   }
74 
75   sound_bytes_per_second = (dspbits / 8) *  channels * rate;
76 
77   audio_set_rate(rate);
78 
79   sound_available = 1;
80 
81   sndbufpt = sndbuffer;
82 }
83 
84 /* this should be called between subsongs when remote slave changes subsong */
flush_sound(void)85 void flush_sound (void)
86 {
87   sndbufpt = sndbuffer;
88 }
89