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 #ifdef __SYMBIAN32__
24 
25 #include "backends/mixer/symbiansdl/symbiansdl-mixer.h"
26 #include "common/system.h"
27 
28 #ifdef SAMPLES_PER_SEC_8000 // the GreanSymbianMMP format cannot handle values for defines :(
29   #define SAMPLES_PER_SEC 8000
30 #else
31   #define SAMPLES_PER_SEC 16000
32 #endif
33 
SymbianSdlMixerManager()34 SymbianSdlMixerManager::SymbianSdlMixerManager()
35 	:
36 	_stereoMixBuffer(0) {
37 
38 }
39 
~SymbianSdlMixerManager()40 SymbianSdlMixerManager::~SymbianSdlMixerManager() {
41 	delete[] _stereoMixBuffer;
42 }
43 
startAudio()44 void SymbianSdlMixerManager::startAudio() {
45 	// Need to create mixbuffer for stereo mix to downmix
46 	if (_obtained.channels != 2) {
47 		_stereoMixBuffer = new byte [_obtained.size * 2]; // * 2 for stereo values
48 	}
49 
50 	SdlMixerManager::startAudio();
51 }
52 
callbackHandler(byte * samples,int len)53 void SymbianSdlMixerManager::callbackHandler(byte *samples, int len) {
54 	assert(_mixer);
55 #if defined(S60) && !defined(S60V3)
56 	// If not stereo then we need to downmix
57 	if (_obtained.channels != 2) {
58 		_mixer->mixCallback(_stereoMixBuffer, len * 2);
59 
60 		int16 *bitmixDst = (int16 *)samples;
61 		int16 *bitmixSrc = (int16 *)_stereoMixBuffer;
62 
63 		for (int loop = len / 2; loop >= 0; loop --) {
64 			*bitmixDst = (*bitmixSrc + *(bitmixSrc + 1)) >> 1;
65 			bitmixDst++;
66 			bitmixSrc += 2;
67 		}
68 	} else
69 #else
70 	_mixer->mixCallback(samples, len);
71 #endif
72 }
73 
74 #endif
75