1 #include "driver.h"
2
3
4
5 static int firstchannel,numchannels;
6
7
8 /* Start one of the samples loaded from disk. Note: channel must be in the range */
9 /* 0 .. Samplesinterface->channels-1. It is NOT the discrete channel to pass to */
10 /* mixer_play_sample() */
sample_start(int channel,int samplenum,int loop)11 void sample_start(int channel,int samplenum,int loop)
12 {
13 if (Machine->sample_rate == 0) return;
14 if (Machine->samples == 0) return;
15 if (Machine->samples->sample[samplenum] == 0) return;
16 if (channel >= numchannels)
17 {
18 logerror("error: sample_start() called with channel = %d, but only %d channels allocated\n",channel,numchannels);
19 return;
20 }
21 if (samplenum >= Machine->samples->total)
22 {
23 logerror("error: sample_start() called with samplenum = %d, but only %d samples available\n",samplenum,Machine->samples->total);
24 return;
25 }
26
27 if ( Machine->samples->sample[samplenum]->resolution == 8 )
28 {
29 //logerror("play 8 bit sample %d, channel %d\n",samplenum,channel);
30 mixer_play_sample(firstchannel + channel,
31 Machine->samples->sample[samplenum]->data,
32 Machine->samples->sample[samplenum]->length,
33 Machine->samples->sample[samplenum]->smpfreq,
34 loop);
35 }
36 else
37 {
38 //logerror("play 16 bit sample %d, channel %d\n",samplenum,channel);
39 mixer_play_sample_16(firstchannel + channel,
40 (short *) Machine->samples->sample[samplenum]->data,
41 Machine->samples->sample[samplenum]->length,
42 Machine->samples->sample[samplenum]->smpfreq,
43 loop);
44 }
45 }
46
sample_set_freq(int channel,int freq)47 void sample_set_freq(int channel,int freq)
48 {
49 if (Machine->sample_rate == 0) return;
50 if (Machine->samples == 0) return;
51 if (channel >= numchannels)
52 {
53 logerror("error: sample_adjust() called with channel = %d, but only %d channels allocated\n",channel,numchannels);
54 return;
55 }
56
57 mixer_set_sample_frequency(channel + firstchannel,freq);
58 }
59
sample_set_volume(int channel,int volume)60 void sample_set_volume(int channel,int volume)
61 {
62 if (Machine->sample_rate == 0) return;
63 if (Machine->samples == 0) return;
64 if (channel >= numchannels)
65 {
66 logerror("error: sample_adjust() called with channel = %d, but only %d channels allocated\n",channel,numchannels);
67 return;
68 }
69
70 mixer_set_volume(channel + firstchannel,volume * 100 / 255);
71 }
72
sample_stop(int channel)73 void sample_stop(int channel)
74 {
75 if (Machine->sample_rate == 0) return;
76 if (channel >= numchannels)
77 {
78 logerror("error: sample_stop() called with channel = %d, but only %d channels allocated\n",channel,numchannels);
79 return;
80 }
81
82 mixer_stop_sample(channel + firstchannel);
83 }
84
sample_playing(int channel)85 int sample_playing(int channel)
86 {
87 if (Machine->sample_rate == 0) return 0;
88 if (channel >= numchannels)
89 {
90 logerror("error: sample_playing() called with channel = %d, but only %d channels allocated\n",channel,numchannels);
91 return 0;
92 }
93
94 return mixer_is_sample_playing(channel + firstchannel);
95 }
96
97
98
samples_sh_start(const struct MachineSound * msound)99 int samples_sh_start(const struct MachineSound *msound)
100 {
101 int i;
102 int vol[MIXER_MAX_CHANNELS];
103 const struct Samplesinterface *intf = (const struct Samplesinterface *)msound->sound_interface;
104
105 /* read audio samples if available */
106 Machine->samples = readsamples(intf->samplenames,Machine->gamedrv->name);
107
108 numchannels = intf->channels;
109 for (i = 0;i < numchannels;i++)
110 vol[i] = intf->volume;
111 firstchannel = mixer_allocate_channels(numchannels,vol);
112 for (i = 0;i < numchannels;i++)
113 {
114 char buf[40];
115
116 sprintf(buf,"Sample #%d",i);
117 mixer_set_name(firstchannel + i,buf);
118 }
119 return 0;
120 }
121