direct sound ja parempi syncca
This commit is contained in:
38
src/main.cpp
38
src/main.cpp
@ -41,7 +41,7 @@ static int pidPost;
|
||||
void entrypoint(void)
|
||||
#else
|
||||
#include "editor.h"
|
||||
#include "song.h"
|
||||
|
||||
int __cdecl main(int argc, char* argv[])
|
||||
#endif
|
||||
{
|
||||
@ -49,7 +49,8 @@ int __cdecl main(int argc, char* argv[])
|
||||
#if FULLSCREEN
|
||||
ChangeDisplaySettings(&screenSettings, CDS_FULLSCREEN);
|
||||
ShowCursor(0);
|
||||
const HDC hDC = GetDC(CreateWindow((LPCSTR)0xC018, 0, WS_POPUP | WS_VISIBLE | WS_MAXIMIZE, 0, 0, 0, 0, 0, 0, 0, 0));
|
||||
HWND window = CreateWindow((LPCSTR)0xC018, 0, WS_POPUP | WS_VISIBLE | WS_MAXIMIZE, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
const HDC hDC = GetDC(window);
|
||||
#else
|
||||
#ifdef EDITOR_CONTROLS
|
||||
HWND window = CreateWindow("static", 0, WS_POPUP | WS_VISIBLE, 0, 0, XRES, YRES, 0, 0, 0, 0);
|
||||
@ -77,12 +78,21 @@ int __cdecl main(int argc, char* argv[])
|
||||
// initialize sound
|
||||
#ifndef EDITOR_CONTROLS
|
||||
#if USE_AUDIO
|
||||
CreateThread(0, 0, (LPTHREAD_START_ROUTINE)su_render_song, lpSoundBuffer, 0, 0);
|
||||
waveOutOpen(&hWaveOut, WAVE_MAPPER, &WaveFMT, NULL, 0, CALLBACK_NULL);
|
||||
waveOutPrepareHeader(hWaveOut, &WaveHDR, sizeof(WaveHDR));
|
||||
waveOutWrite(hWaveOut, &WaveHDR, sizeof(WaveHDR));
|
||||
|
||||
LPDIRECTSOUND direct_sound;
|
||||
LPDIRECTSOUNDBUFFER direct_sound_buffer;
|
||||
DirectSoundCreate(0, &direct_sound, 0);
|
||||
|
||||
IDirectSound_SetCooperativeLevel(direct_sound, window, DSSCL_PRIORITY);
|
||||
IDirectSound_CreateSoundBuffer(direct_sound, &buffer_description, &direct_sound_buffer, NULL);
|
||||
|
||||
LPVOID p1;
|
||||
DWORD l1;
|
||||
IDirectSoundBuffer_Lock(direct_sound_buffer, 0, SU_LENGTH_IN_SAMPLES * SU_CHANNEL_COUNT * SU_SAMPLE_SIZE, &p1, &l1, NULL, NULL, 0);
|
||||
CreateThread(0, 0, (LPTHREAD_START_ROUTINE)su_render_song, p1, 0, 0);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#else
|
||||
Leviathan::Editor editor = Leviathan::Editor();
|
||||
editor.updateShaders(&pidMain, &pidPost, true);
|
||||
@ -94,9 +104,13 @@ int __cdecl main(int argc, char* argv[])
|
||||
double position = 0.0;
|
||||
#endif
|
||||
|
||||
long playCursor = 0;
|
||||
// main loop
|
||||
direct_sound_buffer->Play(0, 0, 0);
|
||||
do
|
||||
{
|
||||
|
||||
direct_sound_buffer->GetCurrentPosition((DWORD*)&playCursor, NULL);
|
||||
float syncs[1 + SU_NUMSYNCS];
|
||||
|
||||
|
||||
@ -117,7 +131,7 @@ int __cdecl main(int argc, char* argv[])
|
||||
#ifndef EDITOR_CONTROLS
|
||||
// if you don't have an audio system figure some other way to pass time to your shader
|
||||
#if USE_AUDIO
|
||||
waveOutGetPosition(hWaveOut, &MMTime, sizeof(MMTIME));
|
||||
|
||||
// it is possible to upload your vars as vertex color attribute (gl_Color) to save one function import
|
||||
#if NO_UNIFORMS
|
||||
glColor3ui(MMTime.u.sample, 0, 0);
|
||||
@ -132,13 +146,11 @@ int __cdecl main(int argc, char* argv[])
|
||||
|
||||
#endif
|
||||
|
||||
syncs[0] = MMTime.u.sample / (2 * sizeof(SUsample));
|
||||
syncs[0] = (float)playCursor / (2 * sizeof(SUsample));
|
||||
|
||||
for (int i = 0; i < SU_NUMSYNCS; ++i)
|
||||
{
|
||||
syncs[i + 1] = syncBuf[
|
||||
(MMTime.u.sample >> 8) * SU_NUMSYNCS + i
|
||||
];
|
||||
syncs[i + 1] = syncBuf[(playCursor / (2 * sizeof(SUsample)) >> 8) * SU_NUMSYNCS + i];
|
||||
}
|
||||
|
||||
PFNGLUNIFORM1FVPROC glUniform1fvProc = ((PFNGLUNIFORM1FVPROC)wglGetProcAddress("glUniform1fv"));
|
||||
@ -178,7 +190,7 @@ int __cdecl main(int argc, char* argv[])
|
||||
|
||||
} while(!GetAsyncKeyState(VK_ESCAPE)
|
||||
#if USE_AUDIO
|
||||
&& MMTime.u.sample < SU_LENGTH_IN_SAMPLES
|
||||
&& playCursor < SU_LENGTH_IN_SAMPLES * 2 * sizeof(SUsample)
|
||||
#endif
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user