-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathluaCBSynth.cpp
More file actions
95 lines (76 loc) · 2.27 KB
/
luaCBSynth.cpp
File metadata and controls
95 lines (76 loc) · 2.27 KB
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
// Author: Greg "fugue" Santucci, 2011
// Email: thecodewitch@gmail.com
// Web: http://createuniverses.blogspot.com/
#include "luaCB.h"
extern void StartPlayingSound();
extern void StopPlayingSound();
int luaCBPlaySound(lua_State * L)
{
StartPlayingSound();
return 0;
}
int luaCBStopSound(lua_State * L)
{
StopPlayingSound();
return 0;
}
int luaCBSoundPlaying(lua_State * L)
{
#ifdef __PRAXIS_LINUX__
extern bool g_bSDLAudioPlaying;
lua_pushboolean(L, g_bSDLAudioPlaying);
#else
bool bSoundPlaying = false;
lua_pushboolean(L, bSoundPlaying);
#endif
return 1;
}
extern const int SAMPLE_RATE;
extern const int SAMPLES_PER_REQUEST;
int luaCBGetSampleRate(lua_State * L)
{
lua_pushnumber(L, SAMPLE_RATE);
return 1;
}
int luaCBGetSamplesPerRequest(lua_State * L)
{
lua_pushnumber(L, SAMPLES_PER_REQUEST);
return 1;
}
extern short ReadLiveBufferSample();
extern void WriteLiveBufferSample(short nSample);
extern int nLiveBufferReadPosition;
extern int nLiveBufferWritePosition;
extern int nLiveBufferTotalReads;
extern int nLiveBufferTotalWrites;
int luaCBReadLiveBufferSample(lua_State * L)
{
short nSample = ReadLiveBufferSample();
lua_pushnumber(L, nSample);
return 1;
}
int luaCBWriteLiveBufferSample(lua_State * L)
{
short nSample = luaL_checknumber(L, 1);
WriteLiveBufferSample(nSample);
return 0;
}
int luaCBGetLiveBufferMarkers(lua_State * L)
{
lua_pushnumber(L, nLiveBufferReadPosition);
lua_pushnumber(L, nLiveBufferWritePosition);
lua_pushnumber(L, nLiveBufferTotalReads);
lua_pushnumber(L, nLiveBufferTotalWrites);
return 4;
}
void luaInitCallbacksSynth()
{
lua_register(g_pLuaState, "playSound", luaCBPlaySound);
lua_register(g_pLuaState, "stopSound", luaCBStopSound);
lua_register(g_pLuaState, "soundPlaying", luaCBSoundPlaying);
lua_register(g_pLuaState, "getSampleRate", luaCBGetSampleRate);
lua_register(g_pLuaState, "getSamplesPerRequest", luaCBGetSamplesPerRequest);
lua_register(g_pLuaState, "readSample", luaCBReadLiveBufferSample);
lua_register(g_pLuaState, "writeSample", luaCBWriteLiveBufferSample);
lua_register(g_pLuaState, "getSampleMarkers", luaCBGetLiveBufferMarkers);
}