1 /*
2  * Schism Tracker - a cross-platform Impulse Tracker clone
3  * copyright (c) 2003-2005 Storlek <storlek@rigelseven.com>
4  * copyright (c) 2005-2008 Mrs. Brisby <mrs.brisby@nimh.org>
5  * copyright (c) 2009 Storlek & Mrs. Brisby
6  * copyright (c) 2010-2012 Storlek
7  * URL: http://schismtracker.org/
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23 
24 #include "headers.h"
25 
26 #include "util.h"
27 #include "osdefs.h"
28 
29 #ifndef WIN32
30 # error Why do you want to build this if you do not intend to use it?
31 #endif
32 
33 #include <windows.h>
34 #include <mmsystem.h>
35 
36 /*  Note: [Gargaj]
37 
38       WinMM DOES support max volumes up to 65535, but the scroller is
39       so goddamn slow and it only supports 3 digits anyway, that
40       it doesn't make any sense to keep the precision.
41 */
42 
43 int win32mm_volume_get_max(void)
44 {
45 	return 0xFF;
46 }
47 
48 static HWAVEOUT open_mixer(void)
49 {
50 	HWAVEOUT hwo=NULL;
51 	WAVEFORMATEX pwfx;
52 #if 0
53 	pwfx.wFormatTag = WAVE_FORMAT_UNKNOWN;
54 	pwfx.nChannels = 0;
55 	pwfx.nSamplesPerSec = 0;
56 	pwfx.wBitsPerSample = 0;
57 	pwfx.nBlockAlign = 0;
58 	pwfx.nAvgBytesPerSec = 0;
59 	pwfx.cbSize = 0;
60 #else
61 	pwfx.wFormatTag = WAVE_FORMAT_PCM;
log_draw_const(void)62 	pwfx.nChannels = 1;
63 	pwfx.nSamplesPerSec = 44100;
64 	pwfx.wBitsPerSample = 8;
65 	pwfx.nBlockAlign = 4;
66 	pwfx.nAvgBytesPerSec = 44100*1*1;
67 	pwfx.cbSize = 0;
log_handle_key(struct key_event * k)68 #endif
69 	if (waveOutOpen(&hwo, WAVE_MAPPER, &pwfx, 0, 0, CALLBACK_NULL)!=MMSYSERR_NOERROR)
70 		return NULL;
71 	return hwo;
72 }
73 
74 void win32mm_volume_read(int *left, int *right)
75 {
76 	DWORD vol;
77 
78 	*left = *right = 0;
79 
80 	waveOutGetVolume(NULL,&vol);
81 
82 	*left = (vol & 0xFFFF) >> 8;
83 	*right = (vol >> 16) >> 8;
84 }
85 
86 void win32mm_volume_write(int left, int right)
87 {
88 	DWORD vol = ((left & 0xFF)<<8) | ((right & 0xFF)<<(16+8));
89 
90 	waveOutSetVolume(NULL,vol);
91 }
92