Subversion Repositories eduke32

Rev

Rev 8755 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8755 Rev 8769
Line 24... Line 24...
24
24
25
#include "_multivc.h"
25
#include "_multivc.h"
26
#include "common.h"
26
#include "common.h"
27
#include "midi.h"
27
#include "midi.h"
28
28
-
 
29
int SF2_EffectSampleBlockSize = 16;
-
 
30
29
#define TSF_IMPLEMENTATION
31
#define TSF_IMPLEMENTATION
30
#define TSF_NO_STDIO
32
#define TSF_NO_STDIO
-
 
33
#define TSF_RENDER_EFFECTSAMPLEBLOCK SF2_EffectSampleBlockSize
31
#define TSF_MALLOC  Xmalloc
34
#define TSF_MALLOC  Xmalloc
32
#define TSF_REALLOC Xrealloc
35
#define TSF_REALLOC Xrealloc
33
#define TSF_FREE    Xfree
36
#define TSF_FREE    Xfree
34
#define TSF_MEMCPY Bmemcpy
37
#define TSF_MEMCPY Bmemcpy
35
#define TSF_MEMSET Bmemset
38
#define TSF_MEMSET Bmemset
Line 180... Line 183...
180
183
181
void SF2Drv_MIDI_Service(void)
184
void SF2Drv_MIDI_Service(void)
182
{
185
{
183
    int16_t *    buffer16 = (int16_t *)MV_MusicBuffer;
186
    int16_t *    buffer16 = (int16_t *)MV_MusicBuffer;
184
    static float fbuf[MV_MIXBUFFERSIZE * 2];
187
    static float fbuf[MV_MIXBUFFERSIZE * 2];
-
 
188
    float const  fvolume = SF2_Volume * (32768.f / MIDI_MaxVolume);
185
189
186
    for (int i = 0; i < MV_MIXBUFFERSIZE;)
190
    for (int i = 0; i < MV_MIXBUFFERSIZE;)
187
    {
191
    {
188
        while (MV_MIDIRenderTimer >= MV_MixRate)
192
        while (MV_MIDIRenderTimer >= MV_MixRate)
189
        {
193
        {
Line 195... Line 199...
195
        int samples = MV_MIDIRenderTempo > 0 ? (MV_MixRate - MV_MIDIRenderTimer + MV_MIDIRenderTempo - 1) / MV_MIDIRenderTempo : MV_MIXBUFFERSIZE;
199
        int samples = MV_MIDIRenderTempo > 0 ? (MV_MixRate - MV_MIDIRenderTimer + MV_MIDIRenderTempo - 1) / MV_MIDIRenderTempo : MV_MIXBUFFERSIZE;
196
        samples     = min(samples, MV_MIXBUFFERSIZE - i);
200
        samples     = min(samples, MV_MIXBUFFERSIZE - i);
197
        tsf_render_float(sf2_synth, fbuf, samples);
201
        tsf_render_float(sf2_synth, fbuf, samples);
198
202
199
        int const   nsamples = samples * MV_Channels;
203
        int const nsamples = samples * MV_Channels;
200
        float const fvolume  = SF2_Volume * (32768.f / MIDI_MaxVolume);
-
 
201
204
202
        for (int j = 0; j < nsamples; j++)
205
        for (int j = 0; j < nsamples; j++)
203
            *buffer16++ = clamp(Blrintf(fbuf[j] * fvolume), INT16_MIN, INT16_MAX);
206
            *buffer16++ = clamp(Blrintf(fbuf[j] * fvolume), INT16_MIN, INT16_MAX);
204
207
205
        if (MV_MIDIRenderTempo >= 0)
208
        if (MV_MIDIRenderTempo >= 0)