Skip to content

Commit

Permalink
Mega-commit (unfortunately) for v1.87
Browse files Browse the repository at this point in the history
  • Loading branch information
8bitbubsy committed Nov 3, 2024
1 parent 7f215f8 commit 544e74e
Show file tree
Hide file tree
Showing 31 changed files with 958 additions and 252 deletions.
33 changes: 21 additions & 12 deletions src/ft2_audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ void setMixerBPM(int32_t bpm)

audio.samplesPerTickInt = audio.samplesPerTickIntTab[i];
audio.samplesPerTickFrac = audio.samplesPerTickFracTab[i];
audio.fSamplesPerTickIntMul = (float)(1.0 / (double)audio.samplesPerTickInt);

// for audio/video sync timestamp
tickTimeLenInt = audio.tickTimeIntTab[i];
Expand Down Expand Up @@ -261,10 +262,8 @@ static void voiceUpdateVolumes(int32_t i, uint8_t status)
const float fVolumeRDiff = 0.0f - f->fCurrVolumeR;

f->volumeRampLength = audio.quickVolRampSamples; // 5ms
const float fVolumeRampLength = (float)(int32_t)f->volumeRampLength;

f->fVolumeLDelta = fVolumeLDiff / fVolumeRampLength;
f->fVolumeRDelta = fVolumeRDiff / fVolumeRampLength;
f->fVolumeLDelta = fVolumeLDiff * audio.fQuickVolRampSamplesMul;
f->fVolumeRDelta = fVolumeRDiff * audio.fQuickVolRampSamplesMul;

f->isFadeOutVoice = true;
}
Expand All @@ -282,12 +281,20 @@ static void voiceUpdateVolumes(int32_t i, uint8_t status)
const float fVolumeLDiff = v->fTargetVolumeL - v->fCurrVolumeL;
const float fVolumeRDiff = v->fTargetVolumeR - v->fCurrVolumeR;

// IS_QuickVol = 5ms, otherwise the duration of a tick
v->volumeRampLength = (status & IS_QuickVol) ? audio.quickVolRampSamples : audio.samplesPerTickInt;
const float fVolumeRampLength = (float)(int32_t)v->volumeRampLength;
float fRampLengthMul;
if (status & IS_QuickVol) // duration of 5ms
{
v->volumeRampLength = audio.quickVolRampSamples;
fRampLengthMul = audio.fQuickVolRampSamplesMul;
}
else // duration of a tick
{
v->volumeRampLength = audio.samplesPerTickInt;
fRampLengthMul = audio.fSamplesPerTickIntMul;
}

v->fVolumeLDelta = fVolumeLDiff / fVolumeRampLength;
v->fVolumeRDelta = fVolumeRDiff / fVolumeRampLength;
v->fVolumeLDelta = fVolumeLDiff * fRampLengthMul;
v->fVolumeRDelta = fVolumeRDiff * fRampLengthMul;
}
}

Expand Down Expand Up @@ -340,7 +347,7 @@ static void voiceTrigger(int32_t ch, sample_t *s, int32_t position)
return;
}

v->mixFuncOffset = ((int32_t)sample16Bit * 15) + (audio.interpolationType * 3) + loopType;
v->mixFuncOffset = ((int32_t)sample16Bit * 18) + (audio.interpolationType * 3) + loopType;
v->active = true;
}

Expand Down Expand Up @@ -462,6 +469,8 @@ static void doChannelMixing(int32_t bufferPosition, int32_t samplesToMix)
voice_t *v = voice; // normal voices
voice_t *r = &voice[MAX_CHANNELS]; // volume ramp fadeout-voices

const int32_t mixOffsetBias = 3 * NUM_INTERPOLATORS * 2; // 3 = loop types (off/fwd/bidi), 2 = bit depths (8-bit/16-bit)

for (int32_t i = 0; i < song.numChannels; i++, v++, r++)
{
if (v->active)
Expand All @@ -470,11 +479,11 @@ static void doChannelMixing(int32_t bufferPosition, int32_t samplesToMix)
if (!volRampFlag && v->fCurrVolumeL == 0.0f && v->fCurrVolumeR == 0.0f)
silenceMixRoutine(v, samplesToMix);
else
mixFuncTab[((int32_t)volRampFlag * (3*5*2)) + v->mixFuncOffset](v, bufferPosition, samplesToMix);
mixFuncTab[((int32_t)volRampFlag * mixOffsetBias) + v->mixFuncOffset](v, bufferPosition, samplesToMix);
}

if (r->active) // volume ramp fadeout-voice
mixFuncTab[(3*5*2) + r->mixFuncOffset](r, bufferPosition, samplesToMix);
mixFuncTab[mixOffsetBias + r->mixFuncOffset](r, bufferPosition, samplesToMix);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ft2_audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ typedef struct audio_t

uint64_t tickTime64, tickTime64Frac;

float *fMixBufferL, *fMixBufferR;
float *fMixBufferL, *fMixBufferR, fQuickVolRampSamplesMul, fSamplesPerTickIntMul;
double dHz2MixDeltaMul;

SDL_AudioDeviceID dev;
Expand Down
2 changes: 1 addition & 1 deletion src/ft2_checkboxes.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ checkBox_t checkBoxes[NUM_CHECKBOXES] =
// ------ CONFIG CHECKBOXES ------
//x, y, w, h, funcOnUp
{ 3, 91, 77, 12, cbToggleAutoSaveConfig },
{ 508, 158, 107, 12, cbConfigVolRamp },
{ 512, 158, 107, 12, cbConfigVolRamp },
{ 113, 14, 108, 12, cbConfigPattStretch },
{ 113, 27, 117, 12, cbConfigHexCount },
{ 113, 40, 81, 12, cbConfigAccidential },
Expand Down
72 changes: 41 additions & 31 deletions src/ft2_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ static void loadConfigFromBuffer(bool defaults)
config.recMIDIVolSens = CLAMP(config.recMIDIVolSens, 0, 200);
config.recMIDIChn = CLAMP(config.recMIDIChn, 1, 16);

if (config.interpolation > 4)
if (config.interpolation >= NUM_INTERPOLATORS)
config.interpolation = INTERPOLATION_SINC8; // default (sinc, 8 point)

if (config.recTrueInsert > 1)
Expand Down Expand Up @@ -837,6 +837,8 @@ void setConfigAudioRadioButtonStates(void) // accessed by other .c files
tmpID = RB_CONFIG_AUDIO_INTRP_SINC16;
else if (config.interpolation == INTERPOLATION_CUBIC)
tmpID = RB_CONFIG_AUDIO_INTRP_CUBIC;
else if (config.interpolation == INTERPOLATION_GAUSSIAN)
tmpID = RB_CONFIG_AUDIO_INTRP_GAUSSIAN;
else
tmpID = RB_CONFIG_AUDIO_INTRP_SINC8; // default case

Expand Down Expand Up @@ -1126,13 +1128,13 @@ void showConfigScreen(void)
drawFramework(110, 0, 276, 87, FRAMEWORK_TYPE1);
drawFramework(110, 87, 276, 86, FRAMEWORK_TYPE1);

drawFramework(386, 0, 119, 58, FRAMEWORK_TYPE1);
drawFramework(386, 58, 119, 44, FRAMEWORK_TYPE1);
drawFramework(386, 102, 119, 71, FRAMEWORK_TYPE1);
drawFramework(386, 0, 123, 58, FRAMEWORK_TYPE1);
drawFramework(386, 58, 123, 29, FRAMEWORK_TYPE1);
drawFramework(386, 87, 123, 86, FRAMEWORK_TYPE1);

drawFramework(505, 0, 127, 58, FRAMEWORK_TYPE1);
drawFramework(505, 102, 127, 71, FRAMEWORK_TYPE1);
drawFramework(505, 58, 127, 44, FRAMEWORK_TYPE1);
drawFramework(509, 0, 123, 58, FRAMEWORK_TYPE1);
drawFramework(509, 102, 123, 71, FRAMEWORK_TYPE1);
drawFramework(509, 58, 123, 44, FRAMEWORK_TYPE1);

drawFramework(112, 16, AUDIO_SELECTORS_BOX_WIDTH+4, 69, FRAMEWORK_TYPE2);
drawFramework(112, 103, AUDIO_SELECTORS_BOX_WIDTH+4, 47, FRAMEWORK_TYPE2);
Expand Down Expand Up @@ -1161,33 +1163,34 @@ void showConfigScreen(void)
textOutShadow(336, 157, PAL_FORGRND, PAL_DSKTOP2, "96.0kHz");

textOutShadow(390, 3, PAL_FORGRND, PAL_DSKTOP2, "Audio buffer size:");
textOutShadow(406, 17, PAL_FORGRND, PAL_DSKTOP2, "Small");
textOutShadow(406, 31, PAL_FORGRND, PAL_DSKTOP2, "Medium (default)");
textOutShadow(406, 45, PAL_FORGRND, PAL_DSKTOP2, "Large");
textOutShadow(405, 17, PAL_FORGRND, PAL_DSKTOP2, "Small");
textOutShadow(405, 31, PAL_FORGRND, PAL_DSKTOP2, "Medium (default)");
textOutShadow(405, 45, PAL_FORGRND, PAL_DSKTOP2, "Large");

textOutShadow(390, 61, PAL_FORGRND, PAL_DSKTOP2, "Audio bit depth:");
textOutShadow(406, 75, PAL_FORGRND, PAL_DSKTOP2, "16-bit");
textOutShadow(406, 89, PAL_FORGRND, PAL_DSKTOP2, "32-bit (float)");

textOutShadow(406, 105, PAL_FORGRND, PAL_DSKTOP2, "No interpolation");
textOutShadow(406, 119, PAL_FORGRND, PAL_DSKTOP2, "Linear (FT2)");
textOutShadow(406, 133, PAL_FORGRND, PAL_DSKTOP2, "Cubic spline");
textOutShadow(406, 147, PAL_FORGRND, PAL_DSKTOP2, "Sinc (8 point)");
textOutShadow(406, 161, PAL_FORGRND, PAL_DSKTOP2, "Sinc (16 point)");

textOutShadow(509, 3, PAL_FORGRND, PAL_DSKTOP2, "Audio output rate:");
textOutShadow(525, 17, PAL_FORGRND, PAL_DSKTOP2, "44100Hz");
textOutShadow(525, 31, PAL_FORGRND, PAL_DSKTOP2, "48000Hz");
textOutShadow(525, 45, PAL_FORGRND, PAL_DSKTOP2, "96000Hz");

textOutShadow(509, 61, PAL_FORGRND, PAL_DSKTOP2, "Frequency slides:");
textOutShadow(525, 75, PAL_FORGRND, PAL_DSKTOP2, "Amiga");
textOutShadow(525, 89, PAL_FORGRND, PAL_DSKTOP2, "Linear (default)");

textOutShadow(509, 105, PAL_FORGRND, PAL_DSKTOP2, "Amplification:");
textOutShadow(405, 74, PAL_FORGRND, PAL_DSKTOP2, "16-bit");
textOutShadow(468, 74, PAL_FORGRND, PAL_DSKTOP2, "32-bit");

textOutShadow(405, 91, PAL_FORGRND, PAL_DSKTOP2, "No interpolation");
textOutShadow(405, 105, PAL_FORGRND, PAL_DSKTOP2, "Linear (FT2)");
textOutShadow(405, 119, PAL_FORGRND, PAL_DSKTOP2, "Gaussian (SNES)");
textOutShadow(405, 133, PAL_FORGRND, PAL_DSKTOP2, "Cubic Hermite");
textOutShadow(405, 147, PAL_FORGRND, PAL_DSKTOP2, "Sinc (8 point)");
textOutShadow(405, 161, PAL_FORGRND, PAL_DSKTOP2, "Sinc (16 point)");

textOutShadow(513, 3, PAL_FORGRND, PAL_DSKTOP2, "Audio output rate:");
textOutShadow(528, 17, PAL_FORGRND, PAL_DSKTOP2, "44100Hz");
textOutShadow(528, 31, PAL_FORGRND, PAL_DSKTOP2, "48000Hz");
textOutShadow(528, 45, PAL_FORGRND, PAL_DSKTOP2, "96000Hz");

textOutShadow(513, 61, PAL_FORGRND, PAL_DSKTOP2, "Frequency slides:");
textOutShadow(528, 75, PAL_FORGRND, PAL_DSKTOP2, "Amiga");
textOutShadow(528, 89, PAL_FORGRND, PAL_DSKTOP2, "Linear (default)");

textOutShadow(513, 105, PAL_FORGRND, PAL_DSKTOP2, "Amplification:");
charOutShadow(621, 105, PAL_FORGRND, PAL_DSKTOP2, 'x');
textOutShadow(509, 133, PAL_FORGRND, PAL_DSKTOP2, "Master volume:");
textOutShadow(525, 160, PAL_FORGRND, PAL_DSKTOP2, "Volume ramping");
textOutShadow(513, 133, PAL_FORGRND, PAL_DSKTOP2, "Master volume:");
textOutShadow(529, 160, PAL_FORGRND, PAL_DSKTOP2, "Volume ramping");

setConfigAudioRadioButtonStates();
setConfigAudioCheckButtonStates();
Expand Down Expand Up @@ -1625,6 +1628,13 @@ void rbConfigAudioIntrpLinear(void)
checkRadioButton(RB_CONFIG_AUDIO_INTRP_LINEAR);
}

void rbConfigAudioIntrpGaussian(void)
{
config.interpolation = INTERPOLATION_GAUSSIAN;
audioSetInterpolationType(config.interpolation);
checkRadioButton(RB_CONFIG_AUDIO_INTRP_GAUSSIAN);
}

void rbConfigAudioIntrpCubic(void)
{
config.interpolation = INTERPOLATION_CUBIC;
Expand Down
21 changes: 3 additions & 18 deletions src/ft2_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@ enum
CONFIG_HIDE_ERRORS = 0,
CONFIG_SHOW_ERRORS = 1,

// don't change the order of these! (yes, it looks off)
INTERPOLATION_DISABLED = 0,
INTERPOLATION_SINC8 = 1,
INTERPOLATION_LINEAR = 2,
INTERPOLATION_SINC16 = 3,
INTERPOLATION_CUBIC = 4,
// ------

MOUSE_IDLE_SHAPE_NICE = 0,
MOUSE_IDLE_SHAPE_UGLY = 1,
MOUSE_IDLE_SHAPE_AWFUL = 2,
Expand Down Expand Up @@ -55,22 +47,14 @@ enum
PAL_JUNGLE = 5,
PAL_LITHE_DARK = 6,
PAL_ROSE = 7,
PAL_DARK_MODE = 8,
PAL_DARK_MODE = 8, // default
PAL_VIOLENT = 9,
PAL_WHY_COLORS = 10, // default
PAL_WHY_COLORS = 10,
PAL_USER_DEFINED = 11,

FILESORT_EXT = 0,
FILESORT_NAME = 1,

ONE_PLAYER = 0,
TWO_PLAYERS = 1,

DIFFICULTY_NOVICE = 0,
DIFFICULTY_AVERAGE = 1,
DIFFICULTY_PRO = 2,
DIFFICULTY_MANIAC = 3,

DONT_SHOW_IMPORT_WARNING_FLAG = 64,
DONT_SHOW_NOT_YET_APPLIED_WARNING_FLAG = 32,

Expand Down Expand Up @@ -221,6 +205,7 @@ void rbConfigAudio16Bit(void);
void rbConfigAudio32BitFloat(void);
void rbConfigAudioIntrpDisabled(void);
void rbConfigAudioIntrpLinear(void);
void rbConfigAudioIntrpGaussian(void);
void rbConfigAudioIntrpCubic(void);
void rbConfigAudioIntrp8PointSinc(void);
void rbConfigAudioIntrp16PointSinc(void);
Expand Down
2 changes: 1 addition & 1 deletion src/ft2_header.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#endif
#include "ft2_replayer.h"

#define PROG_VER_STR "1.86"
#define PROG_VER_STR "1.87"

// do NOT change these! It will only mess things up...

Expand Down
44 changes: 23 additions & 21 deletions src/ft2_inst_ed.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ typedef struct patWaveHdr_t
uint8_t fractions;
int32_t sampleLength, loopStart, loopEnd;
uint16_t sampleRate;
int32_t lowFrq, highFreq, rootFrq;
int16_t finetune;
uint8_t panning, envRate[6], envOfs[6], tremSweep, tremRate;
int32_t lowFreq, highFreq, rootFreq;
int16_t tune; // -512 to +512, EXCLUDING 0 cause it is a multiplier. 512 is one octave off, and 1 is a neutral value
uint8_t balance, envRate[6], envOfs[6], tremSweep, tremRate;
uint8_t tremDepth, vibSweep, vibRate, vibDepth, flags;
int16_t junk1;
uint16_t junk2;
char junk3[36];
int16_t scaleFreq;
uint16_t scaleFactor;
char reserved[36];
}
#ifdef __GNUC__
__attribute__ ((packed))
Expand Down Expand Up @@ -3092,12 +3092,10 @@ void saveInstr(UNICHAR *filenameU, int16_t insNum)
SDL_DetachThread(thread);
}

static int16_t getPATNote(int32_t freq)
static int16_t getPATNote(uint32_t freq)
{
const double dNote = (log2(freq / 440000.0) * 12.0) + 57.0;
const int32_t note = (const int32_t)(dNote + 0.5); // rounded

return (int16_t)note;
const double dNote = (log2((freq / 1000.0) / 440.0) * 12.0) + 9.0;
return (int16_t)round(NOTE_C4 + dNote);
}

static int32_t SDLCALL loadInstrThread(void *ptr)
Expand Down Expand Up @@ -3314,8 +3312,8 @@ static int32_t SDLCALL loadInstrThread(void *ptr)
{
// PAT - Gravis Ultrasound patch

if (pat_h.numSamples == 0)
pat_h.numSamples = 1; // to some patch makers, 0 means 1
if (pat_h.numSamples == 0) // 0 samples really means 1 (for quirky .PAT files)
pat_h.numSamples = 1;

if (pat_h.layers > 1 || pat_h.numSamples > MAX_SMP_PER_INST)
{
Expand Down Expand Up @@ -3375,8 +3373,8 @@ static int32_t SDLCALL loadInstrThread(void *ptr)
if (i == 0)
{
ins->autoVibSweep = patWave_h.vibSweep;
ins->autoVibRate = (patWave_h.vibRate + 2) >> 2; // rounded
ins->autoVibDepth = (patWave_h.vibDepth + 1) >> 1; // rounded
ins->autoVibRate = (patWave_h.vibRate + 1) >> 2;
ins->autoVibDepth = (patWave_h.vibDepth+1) >> 1;
}

s = &instr[editor.curInstr]->smp[i];
Expand All @@ -3392,7 +3390,7 @@ static int32_t SDLCALL loadInstrThread(void *ptr)
s->flags |= LOOP_FWD;
}

s->panning = ((patWave_h.panning << 4) & 0xF0) | (patWave_h.panning & 0xF);
s->panning = ((patWave_h.balance << 4) & 0xF0) | (patWave_h.balance & 0xF); // 0..15 -> 0..255
s->loopStart = patWave_h.loopStart;
s->loopLength = patWave_h.loopEnd - patWave_h.loopStart;

Expand All @@ -3402,13 +3400,17 @@ static int32_t SDLCALL loadInstrThread(void *ptr)
s->loopLength >>= 1;
}

const double dFreq = (1.0 + (patWave_h.finetune / 512.0)) * patWave_h.sampleRate;
tuneSample(s, (int32_t)(dFreq + 0.5), audio.linearPeriodsFlag);
double dC4Freq = patWave_h.sampleRate;
if (patWave_h.scaleFactor > 0)
{
const double dMidiC4Freq = 261.6255653005986347; // 440*2^(-9/12)
const double dRatio = dMidiC4Freq / (patWave_h.rootFreq / 1000.0);
dC4Freq *= dRatio;
}

a = getPATNote(patWave_h.rootFrq) - (12 * 3);
s->relativeNote -= (uint8_t)a;
setSampleC4Hz(s, dC4Freq);

a = getPATNote(patWave_h.lowFrq);
a = getPATNote(patWave_h.lowFreq);
b = getPATNote(patWave_h.highFreq);

a = CLAMP(a, 0, 95);
Expand Down
2 changes: 1 addition & 1 deletion src/ft2_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ int main(int argc, char *argv[])
#ifdef __APPLE__
osxSetDirToProgramDirFromArgs(argv);
#endif
if (!setupExecutablePath() || !loadBMPs() || !calcCubicSplineTable() || !calcWindowedSincTables())
if (!setupExecutablePath() || !loadBMPs() || !calcGaussianTable() || !calcCubicSplineTable() || !calcWindowedSincTables())
{
cleanUpAndExit();
return 1;
Expand Down
4 changes: 2 additions & 2 deletions src/ft2_pushbuttons.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,9 @@ pushButton_t pushButtons[NUM_PUSHBUTTONS] =
{ 365, 72, 18, 13, 1, 4, ARROW_DOWN_STRING, NULL, scrollAudOutputDevListDown, NULL },
{ 365, 103, 18, 13, 1, 4, ARROW_UP_STRING, NULL, scrollAudInputDevListUp, NULL },
{ 365, 137, 18, 13, 1, 4, ARROW_DOWN_STRING, NULL, scrollAudInputDevListDown, NULL },
{ 508, 117, 21, 13, 1, 4, ARROW_LEFT_STRING, NULL, configAmpDown, NULL },
{ 512, 117, 21, 13, 1, 4, ARROW_LEFT_STRING, NULL, configAmpDown, NULL },
{ 608, 117, 21, 13, 1, 4, ARROW_RIGHT_STRING, NULL, configAmpUp, NULL },
{ 508, 143, 21, 13, 1, 0, ARROW_LEFT_STRING, NULL, configMasterVolDown, NULL },
{ 512, 143, 21, 13, 1, 0, ARROW_LEFT_STRING, NULL, configMasterVolDown, NULL },
{ 608, 143, 21, 13, 1, 0, ARROW_RIGHT_STRING, NULL, configMasterVolUp, NULL },

// ------ CONFIG LAYOUT PUSHBUTTONS ------
Expand Down
Loading

0 comments on commit 544e74e

Please sign in to comment.