-
Notifications
You must be signed in to change notification settings - Fork 3
/
OPL3.bi
36 lines (30 loc) · 1.69 KB
/
OPL3.bi
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
'-----------------------------------------------------------------------------------------------------------------------
' OPL3 emulation for QB64-PE using ymfm (https://github.com/aaronsgiles/ymfm)
' Copyright (c) 2024 Samuel Gomes
'-----------------------------------------------------------------------------------------------------------------------
$INCLUDEONCE
'$INCLUDE:'Common.bi'
'$INCLUDE:'Types.bi'
'$INCLUDE:'Math/Math.bi'
'$INCLUDE:'PointerOps.bi'
CONST OPL3_SOUND_BUFFER_CHANNELS = 2 ' 2 channels (stereo)
CONST OPL3_SOUND_BUFFER_SAMPLE_SIZE = 4 ' 4 bytes (32-bits floating point)
CONST OPL3_SOUND_BUFFER_FRAME_SIZE = OPL3_SOUND_BUFFER_SAMPLE_SIZE * OPL3_SOUND_BUFFER_CHANNELS
CONST OPL3_SOUND_BUFFER_TIME_DEFAULT = 0.2 ' we will check that we have this amount of time left in the QB64 sound pipe
' QB64 specific stuff
TYPE __OPL3Type
soundBufferFrames AS _UNSIGNED LONG ' size of the render buffer in frames
soundBufferSamples AS _UNSIGNED LONG ' size of the rendered buffer in samples
soundBufferBytes AS _UNSIGNED LONG ' size of the render buffer in bytes
soundHandle AS LONG ' the sound pipe that we wll use to play the rendered samples
END TYPE
DECLARE LIBRARY "OPL3"
FUNCTION __OPL3_Initialize%% (BYVAL sampleRate AS _UNSIGNED LONG)
SUB __OPL3_Finalize
FUNCTION OPL3_IsInitialized%%
SUB OPL3_Reset
SUB OPL3_WriteRegister (BYVAL address AS _UNSIGNED INTEGER, BYVAL value AS _UNSIGNED _BYTE)
SUB __OPL3_GenerateSamples (buffer AS SINGLE, BYVAL frames AS _UNSIGNED LONG)
END DECLARE
DIM __OPL3 AS __OPL3Type ' this is used to track the library state as such
REDIM __OPL3_SoundBuffer(0 TO 0) AS SINGLE ' this is the buffer that holds the rendered samples from the library