author | peter1138 |
Tue, 22 Jan 2008 07:27:06 +0000 | |
changeset 8374 | 7a1b6c89cb89 |
parent 8131 | 160939e24ed3 |
child 8784 | c2e9d649a9ce |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
2189
5cdc11ffeaa4
(svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents:
2186
diff
changeset
|
3 |
#include "../stdafx.h" |
5cdc11ffeaa4
(svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents:
2186
diff
changeset
|
4 |
#include "../openttd.h" |
5cdc11ffeaa4
(svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents:
2186
diff
changeset
|
5 |
#include "../driver.h" |
5cdc11ffeaa4
(svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents:
2186
diff
changeset
|
6 |
#include "../mixer.h" |
8130
d2eb7d04f6e1
(svn r11691) -Codechange: move+rename helpers.hpp and only include it when it is really needed.
rubidium
parents:
7170
diff
changeset
|
7 |
#include "../core/alloc_func.hpp" |
2189
5cdc11ffeaa4
(svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents:
2186
diff
changeset
|
8 |
#include "win32_s.h" |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
9 |
#include <windows.h> |
2189
5cdc11ffeaa4
(svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents:
2186
diff
changeset
|
10 |
#include <mmsystem.h> |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
11 |
|
7170
923946ec324f
(svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents:
6247
diff
changeset
|
12 |
static FSoundDriver_Win32 iFSoundDriver_Win32; |
923946ec324f
(svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents:
6247
diff
changeset
|
13 |
|
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
14 |
static HWAVEOUT _waveout; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
15 |
static WAVEHDR _wave_hdr[2]; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
16 |
static int _bufsize; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
17 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
18 |
static void PrepareHeader(WAVEHDR *hdr) |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
19 |
{ |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
20 |
hdr->dwBufferLength = _bufsize * 4; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
21 |
hdr->dwFlags = 0; |
5609
dc6a58930ba4
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents:
5587
diff
changeset
|
22 |
hdr->lpData = MallocT<char>(_bufsize * 4); |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
23 |
if (hdr->lpData == NULL || |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
24 |
waveOutPrepareHeader(_waveout, hdr, sizeof(WAVEHDR)) != MMSYSERR_NOERROR) |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
25 |
error("waveOutPrepareHeader failed"); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
26 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
27 |
|
6247 | 28 |
static void FillHeaders() |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
29 |
{ |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
30 |
WAVEHDR *hdr; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
31 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
32 |
for (hdr = _wave_hdr; hdr != endof(_wave_hdr); hdr++) { |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
33 |
if (!(hdr->dwFlags & WHDR_INQUEUE)) { |
2977 | 34 |
MxMixSamples(hdr->lpData, hdr->dwBufferLength / 4); |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
35 |
if (waveOutWrite(_waveout, hdr, sizeof(WAVEHDR)) != MMSYSERR_NOERROR) |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
36 |
error("waveOutWrite failed"); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
37 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
38 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
39 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
40 |
|
2449
bcbfed6d3f58
(svn r2975) Use the correct types, not types which accidently have the same size on 32bit machines
tron
parents:
2189
diff
changeset
|
41 |
static void CALLBACK waveOutProc(HWAVEOUT hwo, UINT uMsg, DWORD_PTR dwInstance, |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
42 |
DWORD dwParam1, DWORD dwParam2) |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
43 |
{ |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
44 |
switch (uMsg) { |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
45 |
case WOM_DONE: |
5988
1aabf94612c6
(svn r8691) -Cleanup: Some proper #endif comments for sound/music/video files, and a little elimination of magic numbers in Win32SoundStart
Darkvater
parents:
5609
diff
changeset
|
46 |
if (_waveout != NULL) FillHeaders(); |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
47 |
break; |
5988
1aabf94612c6
(svn r8691) -Cleanup: Some proper #endif comments for sound/music/video files, and a little elimination of magic numbers in Win32SoundStart
Darkvater
parents:
5609
diff
changeset
|
48 |
default: break; |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
49 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
50 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
51 |
|
7170
923946ec324f
(svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents:
6247
diff
changeset
|
52 |
const char *SoundDriver_Win32::Start(const char* const* parm) |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
53 |
{ |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
54 |
WAVEFORMATEX wfex; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
55 |
wfex.wFormatTag = WAVE_FORMAT_PCM; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
56 |
wfex.nChannels = 2; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
57 |
wfex.wBitsPerSample = 16; |
5988
1aabf94612c6
(svn r8691) -Cleanup: Some proper #endif comments for sound/music/video files, and a little elimination of magic numbers in Win32SoundStart
Darkvater
parents:
5609
diff
changeset
|
58 |
wfex.nSamplesPerSec = GetDriverParamInt(parm, "hz", 11025); |
1aabf94612c6
(svn r8691) -Cleanup: Some proper #endif comments for sound/music/video files, and a little elimination of magic numbers in Win32SoundStart
Darkvater
parents:
5609
diff
changeset
|
59 |
wfex.nBlockAlign = (wfex.nChannels * wfex.wBitsPerSample) / 8; |
1aabf94612c6
(svn r8691) -Cleanup: Some proper #endif comments for sound/music/video files, and a little elimination of magic numbers in Win32SoundStart
Darkvater
parents:
5609
diff
changeset
|
60 |
wfex.nAvgBytesPerSec = wfex.nSamplesPerSec * wfex.nBlockAlign; |
1aabf94612c6
(svn r8691) -Cleanup: Some proper #endif comments for sound/music/video files, and a little elimination of magic numbers in Win32SoundStart
Darkvater
parents:
5609
diff
changeset
|
61 |
|
1aabf94612c6
(svn r8691) -Cleanup: Some proper #endif comments for sound/music/video files, and a little elimination of magic numbers in Win32SoundStart
Darkvater
parents:
5609
diff
changeset
|
62 |
_bufsize = GetDriverParamInt(parm, "bufsize", 1024); |
1aabf94612c6
(svn r8691) -Cleanup: Some proper #endif comments for sound/music/video files, and a little elimination of magic numbers in Win32SoundStart
Darkvater
parents:
5609
diff
changeset
|
63 |
|
2449
bcbfed6d3f58
(svn r2975) Use the correct types, not types which accidently have the same size on 32bit machines
tron
parents:
2189
diff
changeset
|
64 |
if (waveOutOpen(&_waveout, WAVE_MAPPER, &wfex, (DWORD_PTR)&waveOutProc, 0, CALLBACK_FUNCTION) != MMSYSERR_NOERROR) |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
65 |
return "waveOutOpen failed"; |
5988
1aabf94612c6
(svn r8691) -Cleanup: Some proper #endif comments for sound/music/video files, and a little elimination of magic numbers in Win32SoundStart
Darkvater
parents:
5609
diff
changeset
|
66 |
|
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
67 |
PrepareHeader(&_wave_hdr[0]); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
68 |
PrepareHeader(&_wave_hdr[1]); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
69 |
FillHeaders(); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
70 |
return NULL; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
71 |
} |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
72 |
|
7170
923946ec324f
(svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents:
6247
diff
changeset
|
73 |
void SoundDriver_Win32::Stop() |
2174
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
74 |
{ |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
75 |
HWAVEOUT waveout = _waveout; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
76 |
|
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
77 |
_waveout = NULL; |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
78 |
waveOutReset(waveout); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
79 |
waveOutUnprepareHeader(waveout, &_wave_hdr[0], sizeof(WAVEHDR)); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
80 |
waveOutUnprepareHeader(waveout, &_wave_hdr[1], sizeof(WAVEHDR)); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
81 |
waveOutClose(waveout); |
24d868f1c576
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
diff
changeset
|
82 |
} |