author | rubidium |
Tue, 25 Dec 2007 09:48:53 +0000 | |
changeset 8626 | 440dfcd14c4a |
parent 7666 | a5fccd76176a |
child 8627 | 448ebf3a8291 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
2189
d240b9097139
(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" |
d240b9097139
(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" |
d240b9097139
(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" |
d240b9097139
(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 "../functions.h" |
d240b9097139
(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
|
7 |
#include "../mixer.h" |
8626
440dfcd14c4a
(svn r11691) -Codechange: move+rename helpers.hpp and only include it when it is really needed.
rubidium
parents:
7666
diff
changeset
|
8 |
#include "../core/alloc_func.hpp" |
2189
d240b9097139
(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
|
9 |
#include "win32_s.h" |
0 | 10 |
#include <windows.h> |
2189
d240b9097139
(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
|
11 |
#include <mmsystem.h> |
0 | 12 |
|
7666
a5fccd76176a
(svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents:
6573
diff
changeset
|
13 |
static FSoundDriver_Win32 iFSoundDriver_Win32; |
a5fccd76176a
(svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents:
6573
diff
changeset
|
14 |
|
0 | 15 |
static HWAVEOUT _waveout; |
16 |
static WAVEHDR _wave_hdr[2]; |
|
17 |
static int _bufsize; |
|
2171
008122046f7f
(svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
2163
diff
changeset
|
18 |
|
0 | 19 |
static void PrepareHeader(WAVEHDR *hdr) |
20 |
{ |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
21 |
hdr->dwBufferLength = _bufsize * 4; |
0 | 22 |
hdr->dwFlags = 0; |
5860
7fdc9b423ba1
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents:
5838
diff
changeset
|
23 |
hdr->lpData = MallocT<char>(_bufsize * 4); |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
24 |
if (hdr->lpData == NULL || |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
25 |
waveOutPrepareHeader(_waveout, hdr, sizeof(WAVEHDR)) != MMSYSERR_NOERROR) |
0 | 26 |
error("waveOutPrepareHeader failed"); |
27 |
} |
|
28 |
||
6573 | 29 |
static void FillHeaders() |
0 | 30 |
{ |
31 |
WAVEHDR *hdr; |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
32 |
|
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
33 |
for (hdr = _wave_hdr; hdr != endof(_wave_hdr); hdr++) { |
0 | 34 |
if (!(hdr->dwFlags & WHDR_INQUEUE)) { |
2977 | 35 |
MxMixSamples(hdr->lpData, hdr->dwBufferLength / 4); |
0 | 36 |
if (waveOutWrite(_waveout, hdr, sizeof(WAVEHDR)) != MMSYSERR_NOERROR) |
37 |
error("waveOutWrite failed"); |
|
38 |
} |
|
39 |
} |
|
40 |
} |
|
41 |
||
2449
29c0920aee6d
(svn r2975) Use the correct types, not types which accidently have the same size on 32bit machines
tron
parents:
2189
diff
changeset
|
42 |
static void CALLBACK waveOutProc(HWAVEOUT hwo, UINT uMsg, DWORD_PTR dwInstance, |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
43 |
DWORD dwParam1, DWORD dwParam2) |
0 | 44 |
{ |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
45 |
switch (uMsg) { |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
46 |
case WOM_DONE: |
6314
f738bcf05ad6
(svn r8691) -Cleanup: Some proper #endif comments for sound/music/video files, and a little elimination of magic numbers in Win32SoundStart
Darkvater
parents:
5860
diff
changeset
|
47 |
if (_waveout != NULL) FillHeaders(); |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
48 |
break; |
6314
f738bcf05ad6
(svn r8691) -Cleanup: Some proper #endif comments for sound/music/video files, and a little elimination of magic numbers in Win32SoundStart
Darkvater
parents:
5860
diff
changeset
|
49 |
default: break; |
0 | 50 |
} |
51 |
} |
|
52 |
||
7666
a5fccd76176a
(svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents:
6573
diff
changeset
|
53 |
const char *SoundDriver_Win32::Start(const char* const* parm) |
0 | 54 |
{ |
55 |
WAVEFORMATEX wfex; |
|
56 |
wfex.wFormatTag = WAVE_FORMAT_PCM; |
|
57 |
wfex.nChannels = 2; |
|
58 |
wfex.wBitsPerSample = 16; |
|
6314
f738bcf05ad6
(svn r8691) -Cleanup: Some proper #endif comments for sound/music/video files, and a little elimination of magic numbers in Win32SoundStart
Darkvater
parents:
5860
diff
changeset
|
59 |
wfex.nSamplesPerSec = GetDriverParamInt(parm, "hz", 11025); |
f738bcf05ad6
(svn r8691) -Cleanup: Some proper #endif comments for sound/music/video files, and a little elimination of magic numbers in Win32SoundStart
Darkvater
parents:
5860
diff
changeset
|
60 |
wfex.nBlockAlign = (wfex.nChannels * wfex.wBitsPerSample) / 8; |
f738bcf05ad6
(svn r8691) -Cleanup: Some proper #endif comments for sound/music/video files, and a little elimination of magic numbers in Win32SoundStart
Darkvater
parents:
5860
diff
changeset
|
61 |
wfex.nAvgBytesPerSec = wfex.nSamplesPerSec * wfex.nBlockAlign; |
f738bcf05ad6
(svn r8691) -Cleanup: Some proper #endif comments for sound/music/video files, and a little elimination of magic numbers in Win32SoundStart
Darkvater
parents:
5860
diff
changeset
|
62 |
|
f738bcf05ad6
(svn r8691) -Cleanup: Some proper #endif comments for sound/music/video files, and a little elimination of magic numbers in Win32SoundStart
Darkvater
parents:
5860
diff
changeset
|
63 |
_bufsize = GetDriverParamInt(parm, "bufsize", 1024); |
f738bcf05ad6
(svn r8691) -Cleanup: Some proper #endif comments for sound/music/video files, and a little elimination of magic numbers in Win32SoundStart
Darkvater
parents:
5860
diff
changeset
|
64 |
|
2449
29c0920aee6d
(svn r2975) Use the correct types, not types which accidently have the same size on 32bit machines
tron
parents:
2189
diff
changeset
|
65 |
if (waveOutOpen(&_waveout, WAVE_MAPPER, &wfex, (DWORD_PTR)&waveOutProc, 0, CALLBACK_FUNCTION) != MMSYSERR_NOERROR) |
0 | 66 |
return "waveOutOpen failed"; |
6314
f738bcf05ad6
(svn r8691) -Cleanup: Some proper #endif comments for sound/music/video files, and a little elimination of magic numbers in Win32SoundStart
Darkvater
parents:
5860
diff
changeset
|
67 |
|
0 | 68 |
PrepareHeader(&_wave_hdr[0]); |
69 |
PrepareHeader(&_wave_hdr[1]); |
|
70 |
FillHeaders(); |
|
71 |
return NULL; |
|
72 |
} |
|
73 |
||
7666
a5fccd76176a
(svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents:
6573
diff
changeset
|
74 |
void SoundDriver_Win32::Stop() |
0 | 75 |
{ |
76 |
HWAVEOUT waveout = _waveout; |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
77 |
|
0 | 78 |
_waveout = NULL; |
79 |
waveOutReset(waveout); |
|
80 |
waveOutUnprepareHeader(waveout, &_wave_hdr[0], sizeof(WAVEHDR)); |
|
81 |
waveOutUnprepareHeader(waveout, &_wave_hdr[1], sizeof(WAVEHDR)); |
|
82 |
waveOutClose(waveout); |
|
83 |
} |