Files
@ r23371:9cd9ac4bfc93
Branch filter:
Location: cpp/openttd-patchpack/source/src/sound/win32_s.cpp - annotation
r23371:9cd9ac4bfc93
3.4 KiB
text/x-c
Update: Translations from eints
dutch: 80 changes by JanWillem
dutch: 80 changes by JanWillem
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | r5584:545d748cc681 r5584:545d748cc681 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r9111:983de9c5a848 r9111:983de9c5a848 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r8130:bece2e5c7460 r14248:a9050881acd7 r18052:582ae1880112 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r22466:254ae184fe62 r5584:545d748cc681 r21383:942c32fb8b0e r21383:942c32fb8b0e r7170:38b143754b40 r7170:38b143754b40 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r14329:fe5cc1dc3d3d r14329:fe5cc1dc3d3d r14367:05f5190d474d r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5609:a56ae00a9125 r14709:70e0ce4923c3 r5584:545d748cc681 r5584:545d748cc681 r14329:fe5cc1dc3d3d r5584:545d748cc681 r22466:254ae184fe62 r22466:254ae184fe62 r14367:05f5190d474d r14348:646b175e2ae8 r14329:fe5cc1dc3d3d r5584:545d748cc681 r14709:70e0ce4923c3 r14709:70e0ce4923c3 r14709:70e0ce4923c3 r14709:70e0ce4923c3 r5584:545d748cc681 r14367:05f5190d474d r14367:05f5190d474d r14348:646b175e2ae8 r14329:fe5cc1dc3d3d r5584:545d748cc681 r5584:545d748cc681 r10647:62911ec68e89 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r12675:08178fc9d621 r5988:7f6f0097eeb1 r5988:7f6f0097eeb1 r5988:7f6f0097eeb1 r18049:d6aadab953b4 r12675:08178fc9d621 r18049:d6aadab953b4 r5988:7f6f0097eeb1 r14709:70e0ce4923c3 r14709:70e0ce4923c3 r14329:fe5cc1dc3d3d r14709:70e0ce4923c3 r14709:70e0ce4923c3 r14709:70e0ce4923c3 r5988:7f6f0097eeb1 r14709:70e0ce4923c3 r14709:70e0ce4923c3 r12350:654ff1f37bc4 r14709:70e0ce4923c3 r22203:5bd482cbc593 r14709:70e0ce4923c3 r14709:70e0ce4923c3 r14709:70e0ce4923c3 r14329:fe5cc1dc3d3d r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r7170:38b143754b40 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r14367:05f5190d474d r5584:545d748cc681 r14367:05f5190d474d r14367:05f5190d474d r14329:fe5cc1dc3d3d r14367:05f5190d474d r14367:05f5190d474d r5584:545d748cc681 r5584:545d748cc681 r14367:05f5190d474d r14329:fe5cc1dc3d3d r14329:fe5cc1dc3d3d r14367:05f5190d474d r5584:545d748cc681 | /* $Id$ */
/*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file win32_s.cpp Handling of sound for Windows. */
#include "../stdafx.h"
#include "../openttd.h"
#include "../driver.h"
#include "../mixer.h"
#include "../core/alloc_func.hpp"
#include "../core/bitmath_func.hpp"
#include "../core/math_func.hpp"
#include "win32_s.h"
#include <windows.h>
#include <mmsystem.h>
#include "../os/windows/win32.h"
#include "../safeguards.h"
static FSoundDriver_Win32 iFSoundDriver_Win32;
static HWAVEOUT _waveout;
static WAVEHDR _wave_hdr[2];
static int _bufsize;
static HANDLE _thread;
static DWORD _threadId;
static HANDLE _event;
static void PrepareHeader(WAVEHDR *hdr)
{
hdr->dwBufferLength = _bufsize * 4;
hdr->dwFlags = 0;
hdr->lpData = MallocT<char>(_bufsize * 4);
if (waveOutPrepareHeader(_waveout, hdr, sizeof(WAVEHDR)) != MMSYSERR_NOERROR) throw "waveOutPrepareHeader failed";
}
static DWORD WINAPI SoundThread(LPVOID arg)
{
SetWin32ThreadName(-1, "ottd:win-sound");
do {
for (WAVEHDR *hdr = _wave_hdr; hdr != endof(_wave_hdr); hdr++) {
if ((hdr->dwFlags & WHDR_INQUEUE) != 0) continue;
MxMixSamples(hdr->lpData, hdr->dwBufferLength / 4);
if (waveOutWrite(_waveout, hdr, sizeof(WAVEHDR)) != MMSYSERR_NOERROR) {
MessageBox(NULL, _T("Sounds are disabled until restart."), _T("waveOutWrite failed"), MB_ICONINFORMATION);
return 0;
}
}
WaitForSingleObject(_event, INFINITE);
} while (_waveout != NULL);
return 0;
}
const char *SoundDriver_Win32::Start(const char * const *parm)
{
WAVEFORMATEX wfex;
wfex.wFormatTag = WAVE_FORMAT_PCM;
wfex.nChannels = 2;
wfex.wBitsPerSample = 16;
wfex.nSamplesPerSec = GetDriverParamInt(parm, "hz", 44100);
wfex.nBlockAlign = (wfex.nChannels * wfex.wBitsPerSample) / 8;
wfex.nAvgBytesPerSec = wfex.nSamplesPerSec * wfex.nBlockAlign;
/* Limit buffer size to prevent overflows. */
_bufsize = GetDriverParamInt(parm, "bufsize", (GB(GetVersion(), 0, 8) > 5) ? 8192 : 4096);
_bufsize = min(_bufsize, UINT16_MAX);
try {
if (NULL == (_event = CreateEvent(NULL, FALSE, FALSE, NULL))) throw "Failed to create event";
if (waveOutOpen(&_waveout, WAVE_MAPPER, &wfex, (DWORD_PTR)_event, 0, CALLBACK_EVENT) != MMSYSERR_NOERROR) throw "waveOutOpen failed";
MxInitialize(wfex.nSamplesPerSec);
PrepareHeader(&_wave_hdr[0]);
PrepareHeader(&_wave_hdr[1]);
if (NULL == (_thread = CreateThread(NULL, 8192, SoundThread, 0, 0, &_threadId))) throw "Failed to create thread";
} catch (const char *error) {
this->Stop();
return error;
}
return NULL;
}
void SoundDriver_Win32::Stop()
{
HWAVEOUT waveout = _waveout;
/* Stop the sound thread. */
_waveout = NULL;
SetEvent(_event);
WaitForSingleObject(_thread, INFINITE);
/* Close the sound device. */
waveOutReset(waveout);
waveOutUnprepareHeader(waveout, &_wave_hdr[0], sizeof(WAVEHDR));
waveOutUnprepareHeader(waveout, &_wave_hdr[1], sizeof(WAVEHDR));
waveOutClose(waveout);
CloseHandle(_thread);
CloseHandle(_event);
}
|