direct sound ja parempi syncca
This commit is contained in:
@ -7,7 +7,10 @@
|
||||
#define VC_LEANMEAN
|
||||
#define VC_EXTRALEAN
|
||||
|
||||
#pragma pack(push, 8)
|
||||
#include <windows.h>
|
||||
#pragma pack(pop)
|
||||
|
||||
#include <GL/gl.h>
|
||||
|
||||
// global resolution
|
||||
@ -46,43 +49,44 @@ static DEVMODE screenSettings = {
|
||||
};
|
||||
|
||||
#if USE_AUDIO
|
||||
#include <mmsystem.h>
|
||||
#include <mmreg.h>
|
||||
// this file is auto generated by sointu
|
||||
#include "sointu/song.h"
|
||||
#ifndef DSBCAPS_TRUEPLAYPOSITION // Not defined in MinGW dsound headers, so let's add it
|
||||
#define DSBCAPS_TRUEPLAYPOSITION 0x00080000
|
||||
#endif
|
||||
#include <mmreg.h>
|
||||
#include <dsound.h>
|
||||
|
||||
|
||||
SUsample sound_buffer[SU_LENGTH_IN_SAMPLES * SU_CHANNEL_COUNT];
|
||||
WAVEFORMATEX wave_format = {
|
||||
#ifdef SU_SAMPLE_FLOAT
|
||||
WAVE_FORMAT_IEEE_FLOAT,
|
||||
#else
|
||||
WAVE_FORMAT_PCM,
|
||||
#endif
|
||||
SU_CHANNEL_COUNT,
|
||||
SU_SAMPLE_RATE,
|
||||
SU_SAMPLE_RATE * SU_SAMPLE_SIZE * SU_CHANNEL_COUNT,
|
||||
SU_SAMPLE_SIZE * SU_CHANNEL_COUNT,
|
||||
SU_SAMPLE_SIZE * 8,
|
||||
0
|
||||
};
|
||||
#pragma data_seg(".descfmt")
|
||||
DSBUFFERDESC buffer_description = {
|
||||
sizeof(DSBUFFERDESC),
|
||||
DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS | DSBCAPS_TRUEPLAYPOSITION,
|
||||
SU_LENGTH_IN_SAMPLES * SU_SAMPLE_SIZE * SU_CHANNEL_COUNT,
|
||||
0,
|
||||
&wave_format,
|
||||
0
|
||||
};
|
||||
|
||||
#pragma bss_seg(".syncbuf")
|
||||
extern "C" {
|
||||
int _fltused = 1;
|
||||
float syncBuf[SU_SYNCBUFFER_LENGTH+1];
|
||||
}
|
||||
|
||||
#pragma data_seg(".sointuout")
|
||||
static SUsample lpSoundBuffer[(int)SU_LENGTH_IN_SAMPLES * 2];
|
||||
static HWAVEOUT hWaveOut;
|
||||
|
||||
#pragma data_seg(".wavefmt")
|
||||
static WAVEFORMATEX WaveFMT =
|
||||
{
|
||||
WAVE_FORMAT_IEEE_FLOAT,
|
||||
2, // channels
|
||||
SU_SAMPLE_RATE, // samples per sec
|
||||
SU_SAMPLE_RATE*sizeof(SUsample) * 2, // bytes per sec
|
||||
sizeof(SUsample) * 2, // block alignment;
|
||||
sizeof(SUsample) * 8, // bits per sample
|
||||
0 // extension not needed
|
||||
};
|
||||
|
||||
#pragma data_seg(".wavehdr")
|
||||
static WAVEHDR WaveHDR =
|
||||
{
|
||||
(LPSTR)lpSoundBuffer, SU_LENGTH_IN_SAMPLES * sizeof(SUsample) * 2, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
static MMTIME MMTime =
|
||||
{
|
||||
TIME_SAMPLES, 0
|
||||
};
|
||||
#endif
|
||||
|
||||
// currently unused definitions
|
||||
|
||||
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
|
||||
);
|
||||
|
||||
|
||||
@ -3,29 +3,25 @@ precision mediump float;
|
||||
out vec4 o;
|
||||
const float PI = 22./7.;
|
||||
layout(location = 0) uniform float syncs[7];
|
||||
float u_time = syncs[0]/44100.;
|
||||
float u_time = syncs[0];
|
||||
|
||||
vec3 render(vec2 uv, float time) {
|
||||
|
||||
if (uv.y >= 0.0 && uv.y <= 0.01 ) {
|
||||
return vec3(abs(syncs[5]));
|
||||
float pos = syncs[4];
|
||||
if (uv.x >= pos && uv.x <= pos+0.01 ) {
|
||||
return vec3(1.);
|
||||
}
|
||||
|
||||
if (uv.y >= -0.21 && uv.y <= -0.2 ) {
|
||||
return vec3(abs(syncs[6]*1.3));
|
||||
if (uv.x >= 0.0 && uv.x <= 0.01 ) {
|
||||
return vec3(abs(syncs[3]*2));
|
||||
}
|
||||
|
||||
|
||||
return vec3(0.1, 0.2, 0.3);
|
||||
return vec3(0.1, 0.2, 0.3) * abs(syncs[1]*1.2);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void main() {
|
||||
vec2 u_resolution = vec2(1920,1080);
|
||||
vec2 qor = gl_FragCoord.xy/u_resolution.xy;
|
||||
vec2 uv = -1.0+2.0*qor;
|
||||
uv.x *= uv.x/u_resolution.y;
|
||||
vec2 uv = gl_FragCoord.xy * 2. / vec2(1920,1080);
|
||||
vec3 col = render(uv, u_time);
|
||||
o = vec4(col,1.0);
|
||||
}
|
||||
|
||||
@ -10,18 +10,20 @@ const char *fragment_frag =
|
||||
"out vec4 f;"
|
||||
"const float m=22./7.;"
|
||||
"layout(location=0)uniform float v[7];"
|
||||
"float n=v[0]/441e2;"
|
||||
"float n=v[0];"
|
||||
"vec3 s(vec2 f)"
|
||||
"{"
|
||||
"float m=v[4];"
|
||||
"return f.x>=m&&f.x<=m+.01?"
|
||||
"vec3(1):"
|
||||
"f.x>=0.&&f.x<=.01?"
|
||||
"vec3(abs(v[3]*2)):"
|
||||
"vec3(.1,.2,.3)*abs(v[1]*1.2);"
|
||||
"}"
|
||||
"void main()"
|
||||
"{"
|
||||
"vec2 m=vec2(1920,1080),n=gl_FragCoord.xy/m.xy;"
|
||||
"n=-1.+2.*n;"
|
||||
"n.x*=n.x/m.y;"
|
||||
"vec3 a=n.y>=0.&&n.y<=.01?"
|
||||
"vec3(abs(v[5])):"
|
||||
"n.y>=-.21&&n.y<=-.2?"
|
||||
"vec3(abs(v[6]*1.3)):"
|
||||
"vec3(.1,.2,.3);"
|
||||
"f=vec4(a,1);"
|
||||
"vec2 m=gl_FragCoord.xy*2./vec2(1920,1080);"
|
||||
"f=vec4(s(m),1);"
|
||||
"}";
|
||||
|
||||
#endif // FRAGMENT_INL_
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
#define SU_LENGTH_IN_PATTERNS 108
|
||||
#define SU_LENGTH_IN_ROWS (SU_LENGTH_IN_PATTERNS*SU_PATTERN_SIZE)
|
||||
#define SU_SAMPLES_PER_ROW (SU_SAMPLE_RATE*60/(SU_BPM*SU_ROWS_PER_BEAT))
|
||||
#define SU_NUMSYNCS 6
|
||||
#define SU_NUMSYNCS 4
|
||||
#define SU_SYNCBUFFER_LENGTH ((SU_LENGTH_IN_SAMPLES+255)>>8)*SU_NUMSYNCS
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
Reference in New Issue
Block a user