1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #include <common/scummsys.h>
24 #include "engines/engine.h"
25 #include "audio/mixer_intern.h"
26 #include "dc.h"
27 
28 EXTERN_C void *memcpy4s(void *s1, const void *s2, unsigned int n);
29 
initSound()30 uint OSystem_Dreamcast::initSound()
31 {
32   stop_sound();
33   do_sound_command(CMD_SET_FREQ_EXP(FREQ_22050_EXP));
34   do_sound_command(CMD_SET_STEREO(1));
35   do_sound_command(CMD_SET_BUFFER(SOUND_BUFFER_SHIFT));
36   return read_sound_int(&SOUNDSTATUS->freq);
37 }
38 
checkSound()39 void OSystem_Dreamcast::checkSound()
40 {
41   int n;
42   int curr_ring_buffer_samples;
43 
44   if (!_mixer)
45     return;
46 
47   if (read_sound_int(&SOUNDSTATUS->mode) != MODE_PLAY)
48     start_sound();
49 
50   curr_ring_buffer_samples = read_sound_int(&SOUNDSTATUS->ring_length);
51 
52   n = read_sound_int(&SOUNDSTATUS->samplepos);
53 
54   if ((n-=fillpos)<0)
55     n += curr_ring_buffer_samples;
56 
57   n = ADJUST_BUFFER_SIZE(n-10);
58 
59   if (n<100)
60     return;
61 
62   _mixer->mixCallback((byte *)temp_sound_buffer,
63 		      2*SAMPLES_TO_BYTES(n));
64 
65   if (fillpos+n > curr_ring_buffer_samples) {
66     int r = curr_ring_buffer_samples - fillpos;
67     memcpy4s(RING_BUF+fillpos, temp_sound_buffer, SAMPLES_TO_BYTES(r));
68     fillpos = 0;
69     n -= r;
70     memcpy4s(RING_BUF, temp_sound_buffer+r, SAMPLES_TO_BYTES(n));
71   } else {
72     memcpy4s(RING_BUF+fillpos, temp_sound_buffer, SAMPLES_TO_BYTES(n));
73   }
74   if ((fillpos += n) >= curr_ring_buffer_samples)
75     fillpos = 0;
76 }
77