Skip to content

Commit fd5d416

Browse files
committed
Pushed v1.35 code
- Implemented a config entry in protracker.ini for disabling the 2x downsample dialog that shows up when attempting to load >22kHz samples (NO_DWNSMP_ON_SMP_LOAD) - Don't attempt to center window after leaving fullscreen mode. This could lead to issues on multi-monitor setups. - Further accuracy changes to the Paula emulator. Read two samples at once into the AUDxDAT buffer. This is a minor change, but it can have a very small impact on sample-changing commands (EFx/E8x).
1 parent 03d0c96 commit fd5d416

File tree

12 files changed

+124
-85
lines changed

12 files changed

+124
-85
lines changed

release/macos/protracker.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ VSYNCOFF=FALSE
8080
HWMOUSE=TRUE
8181

8282
[GENERAL SETTINGS]
83+
; Don't show downsample dialog after loading a sample whose frequency is >22kHz.
84+
; Syntax: TRUE or FALSE
85+
; Default value: FALSE
86+
;
87+
NO_DWNSMP_ON_SMP_LOAD=FALSE
88+
8389
; Hide last modification dates in Disk Op. to get longer dir/file names
8490
; Syntax: TRUE or FALSE
8591
; Default value: FALSE

release/other/protracker.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ VSYNCOFF=FALSE
8080
HWMOUSE=TRUE
8181

8282
[GENERAL SETTINGS]
83+
; Don't show downsample dialog after loading a sample whose frequency is >22kHz.
84+
; Syntax: TRUE or FALSE
85+
; Default value: FALSE
86+
;
87+
NO_DWNSMP_ON_SMP_LOAD=FALSE
88+
8389
; Hide last modification dates in Disk Op. to get longer dir/file names
8490
; Syntax: TRUE or FALSE
8591
; Default value: FALSE

release/win32/protracker.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ VSYNCOFF=FALSE
8080
HWMOUSE=TRUE
8181

8282
[GENERAL SETTINGS]
83+
; Don't show downsample dialog after loading a sample whose frequency is >22kHz.
84+
; Syntax: TRUE or FALSE
85+
; Default value: FALSE
86+
;
87+
NO_DWNSMP_ON_SMP_LOAD=FALSE
88+
8389
; Hide last modification dates in Disk Op. to get longer dir/file names
8490
; Syntax: TRUE or FALSE
8591
; Default value: FALSE

release/win64/protracker.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ VSYNCOFF=FALSE
8080
HWMOUSE=TRUE
8181

8282
[GENERAL SETTINGS]
83+
; Don't show downsample dialog after loading a sample whose frequency is >22kHz.
84+
; Syntax: TRUE or FALSE
85+
; Default value: FALSE
86+
;
87+
NO_DWNSMP_ON_SMP_LOAD=FALSE
88+
8389
; Hide last modification dates in Disk Op. to get longer dir/file names
8490
; Syntax: TRUE or FALSE
8591
; Default value: FALSE

src/pt2_audio.c

Lines changed: 62 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -277,13 +277,12 @@ void paulaSetPeriod(int32_t ch, uint16_t period)
277277
v->dOldVoiceDeltaMul = 1.0 / v->dOldVoiceDelta;
278278
}
279279

280-
v->dNewDelta = v->dOldVoiceDelta;
281-
if (v->dLastDelta == 0.0) // for BLEP
282-
v->dLastDelta = v->dNewDelta;
283-
284-
v->dNewDeltaMul = v->dOldVoiceDeltaMul;
285-
if (v->dLastDeltaMul == 0.0) // for BLEP
286-
v->dLastDeltaMul = v->dNewDeltaMul;
280+
v->AUD_PER_delta = v->dOldVoiceDelta;
281+
282+
// set BLEP stuff
283+
v->dDeltaMul = v->dOldVoiceDeltaMul;
284+
if (v->dLastDelta == 0.0)
285+
v->dLastDelta = v->AUD_PER_delta;
287286
}
288287

289288
void paulaSetVolume(int32_t ch, uint16_t vol)
@@ -299,7 +298,7 @@ void paulaSetVolume(int32_t ch, uint16_t vol)
299298
// ------------------------
300299

301300
// multiplying by this also scales the sample from -128..127 -> -1.0 .. ~0.99
302-
v->dScaledVolume = realVol * (1.0 / (128.0 * 64.0));
301+
v->AUD_VOL = realVol * (1.0 / (128.0 * 64.0));
303302

304303
if (editor.songPlaying)
305304
{
@@ -316,26 +315,12 @@ void paulaSetLength(int32_t ch, uint16_t len)
316315
{
317316
paulaVoice_t *v = &paula[ch];
318317

319-
int32_t realLength = len;
320-
if (realLength == 0)
321-
{
322-
realLength = 1+65535;
323-
/* Confirmed behavior on real Amiga. We have room for this
324-
** even at the last sample slot, so it will never overflow!
325-
**
326-
** PS: I don't really know if it's possible for ProTracker to
327-
** set a Paula length of 0, but I fully support this Paula
328-
** behavior just in case.
329-
*/
330-
}
331-
332-
realLength <<= 1; // we work with bytes, not words
318+
v->AUD_LEN = len;
333319

334-
v->newLength = realLength;
335320
if (editor.songPlaying)
336321
v->syncFlags |= SET_SCOPE_LENGTH;
337322
else
338-
scope[ch].newLength = realLength;
323+
scope[ch].newLength = len*2;
339324
}
340325

341326
void paulaSetData(int32_t ch, const int8_t *src)
@@ -345,7 +330,8 @@ void paulaSetData(int32_t ch, const int8_t *src)
345330
if (src == NULL)
346331
src = &song->sampleData[RESERVED_SAMPLE_OFFSET]; // 128K reserved sample
347332

348-
v->newData = src;
333+
v->AUD_LC = src;
334+
349335
if (editor.songPlaying)
350336
v->syncFlags |= SET_SCOPE_DATA;
351337
else
@@ -368,41 +354,40 @@ void paulaStartDMA(int32_t ch)
368354
{
369355
paulaVoice_t *v = &paula[ch];
370356

371-
const int8_t *dat = v->newData;
357+
const int8_t *dat = v->AUD_LC;
372358
if (dat == NULL)
373359
dat = &song->sampleData[RESERVED_SAMPLE_OFFSET]; // 128K reserved sample
374360

375-
int32_t length = v->newLength; // in bytes, not words
376-
if (length == 0)
377-
length = 1+65535;
361+
/* This is not really accurate to what happens on Paula
362+
** during DMA start, but it's good enough.
363+
*/
378364

379-
v->dPhase = v->dLastPhase = 0.0;
380-
v->pos = 0;
381-
v->data = dat;
382-
v->length = length;
383-
v->dDelta = v->dLastDelta = v->dNewDelta;
384-
v->dDeltaMul = v->dLastDeltaMul = v->dNewDeltaMul;
365+
v->dDelta = v->AUD_PER_delta;
366+
v->location = v->AUD_LC;
367+
v->lengthCounter = v->AUD_LEN;
385368

386-
/* Read first sample data point into cache now.
387-
**
388-
** (multiplying by dScaledVolume will also change the scale
389-
** from -128..127 to -1.0 .. ~0.99.)
390-
*/
391-
v->dCachedSamplePoint = v->data[0] * v->dScaledVolume;
369+
v->dSample = 0.0;
370+
v->sampleCounter = 0; // read new DMA data samples ASAP
371+
372+
// set BLEP stuff
373+
v->dLastPhase = 0.0;
374+
v->dLastDelta = v->dDelta;
375+
v->dBlepOffset = 0.0;
392376

377+
v->dPhase = 0.0;
393378
v->DMA_active = true;
394379

395380
if (editor.songPlaying)
396381
{
397382
v->syncTriggerData = dat;
398-
v->syncTriggerLength = length;
383+
v->syncTriggerLength = v->AUD_LEN * 2;
399384
v->syncFlags |= TRIGGER_SCOPE;
400385
}
401386
else
402387
{
403388
scope_t *s = &scope[ch];
404389
s->newData = dat;
405-
s->newLength = length;
390+
s->newLength = v->AUD_LEN * 2;
406391
scopeTrigger(ch);
407392
}
408393
}
@@ -448,20 +433,17 @@ void mixChannels(int32_t numSamples)
448433
** is temporarily forced offline, and its voice pointers are
449434
** cleared to prevent expired pointer addresses.
450435
*/
451-
if (!v->DMA_active || v->data == NULL)
436+
if (!v->DMA_active || v->location == NULL || v->AUD_LC == NULL)
452437
continue;
453438

454439
double *dMixBuf = dMixBufSelect[i]; // what output channel to mix into (L, R, R, L)
455440
for (int32_t j = 0; j < numSamples; j++)
456441
{
457-
double dSmp = v->dCachedSamplePoint;
442+
double dSmp = v->dSample;
458443
if (dSmp != bSmp->dLastValue)
459444
{
460445
if (v->dLastDelta > v->dLastPhase)
461-
{
462-
// v->dLastDeltaMul is (1.0 / v->dLastDelta) (pre-computed for speed, div -> mul)
463-
blepAdd(bSmp, v->dLastPhase * v->dLastDeltaMul, bSmp->dLastValue - dSmp);
464-
}
446+
blepAdd(bSmp, v->dBlepOffset, bSmp->dLastValue - dSmp);
465447

466448
bSmp->dLastValue = dSmp;
467449
}
@@ -476,33 +458,40 @@ void mixChannels(int32_t numSamples)
476458
{
477459
v->dPhase -= 1.0;
478460

479-
// Paula only updates period (delta) during sample fetching
480-
v->dDelta = v->dNewDelta;
481-
v->dDeltaMul = v->dNewDeltaMul;
482-
// --------------------------------------------------------
483-
484-
v->dLastPhase = v->dPhase;
485-
v->dLastDelta = v->dDelta;
486-
v->dLastDeltaMul = v->dDeltaMul;
461+
// Paula only updates period (delta) during period refetching (this stage)
462+
v->dDelta = v->AUD_PER_delta;
487463

488-
if (++v->pos >= v->length)
464+
if (v->sampleCounter == 0)
489465
{
490-
v->pos = 0;
491-
492-
// re-fetch new Paula register values now
493-
v->length = v->newLength;
494-
v->data = v->newData;
466+
// it's time to read new samples from DMA
467+
468+
if (--v->lengthCounter == 0)
469+
{
470+
v->lengthCounter = v->AUD_LEN;
471+
v->location = v->AUD_LC;
472+
}
473+
474+
// fill DMA data buffer
475+
v->AUD_DAT[0] = *v->location++;
476+
v->AUD_DAT[1] = *v->location++;
477+
v->sampleCounter = 2;
495478
}
496479

497-
/* Read sample into cache now.
498-
** Also change volume here as well. It has recently been
499-
** discovered that Paula only updates its volume during period
500-
** fetching (when it's reading the next sample point).
501-
**
502-
** (multiplying by dScaledVolume will also change the scale
503-
** from -128..127 to -1.0 .. ~0.99.)
480+
/* Pre-compute current sample point.
481+
** Output volume is only read from AUDxVOL at this stage,
482+
** and we don't emulate volume PWM anyway, so we can
483+
** pre-multiply by volume at this point.
504484
*/
505-
v->dCachedSamplePoint = v->data[v->pos] * v->dScaledVolume;
485+
v->dSample = v->AUD_DAT[0] * v->AUD_VOL; // -128..127 * 0.0 .. 1.0
486+
487+
// progress AUD_DAT buffer
488+
v->AUD_DAT[0] = v->AUD_DAT[1];
489+
v->sampleCounter--;
490+
491+
// setup BLEP stuff
492+
v->dBlepOffset = v->dPhase * v->dDeltaMul;
493+
v->dLastPhase = v->dPhase;
494+
v->dLastDelta = v->dDelta;
506495
}
507496
}
508497
}
@@ -881,7 +870,6 @@ void outputAudio(int16_t *target, int32_t numSamples)
881870
}
882871
}
883872
}
884-
885873
}
886874
}
887875

@@ -910,8 +898,8 @@ static void fillVisualsSyncBuffer(void)
910898
s->period = v->syncPeriod;
911899
s->triggerData = v->syncTriggerData;
912900
s->triggerLength = v->syncTriggerLength;
913-
s->newData = v->newData;
914-
s->newLength = v->newLength;
901+
s->newData = v->AUD_LC;
902+
s->newLength = v->AUD_LEN * 2;
915903
s->vuVolume = c->syncVuVolume;
916904
s->analyzerVolume = c->syncAnalyzerVolume;
917905
s->analyzerPeriod = c->syncAnalyzerPeriod;

src/pt2_audio.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,21 @@ typedef struct voice_t
2727
{
2828
volatile bool DMA_active;
2929

30-
const int8_t *data, *newData;
31-
int32_t length, newLength, pos;
30+
// internal values (don't modify directly!)
31+
int8_t AUD_DAT[2]; // DMA data buffer
32+
const int8_t* location; // current location
33+
uint16_t lengthCounter; // current length
34+
int32_t sampleCounter; // how many bytes left in AUD_DAT
35+
double dSample; // current sample point
3236

33-
double dDelta, dDeltaMul, dPhase, dLastDelta, dLastDeltaMul, dLastPhase;
34-
double dCachedSamplePoint, dScaledVolume, dNewDelta, dNewDeltaMul;
37+
// registers modified by Paula functions
38+
const int8_t* AUD_LC; // location
39+
uint16_t AUD_LEN; // length (in words)
40+
double AUD_PER_delta; // delta
41+
double AUD_VOL; // volume
42+
43+
double dBlepOffset, dDelta, dPhase, dLastDelta, dLastPhase;
44+
double dScaledVolume, dDeltaMul;
3545

3646
// period cache
3747
int32_t oldPeriod;

src/pt2_config.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ void loadConfig(void)
4242
FILE *f;
4343

4444
// set default config values first
45+
config.noDownsampleOnSmpLoad = false;
4546
config.disableE8xEffect = false;
4647
config.fullScreenStretch = false;
4748
config.pattDots = false;
@@ -193,6 +194,13 @@ static bool loadProTrackerDotIni(FILE *f)
193194
continue;
194195
}
195196

197+
// NO_DWNSMP_ON_SMP_LOAD (no dialog for 2x downsample after >22kHz sample load)
198+
else if (!_strnicmp(configLine, "NO_DWNSMP_ON_SMP_LOAD=", 22))
199+
{
200+
if (!_strnicmp(&configLine[22], "TRUE", 4)) config.noDownsampleOnSmpLoad = true;
201+
else if (!_strnicmp(&configLine[22], "FALSE", 5)) config.noDownsampleOnSmpLoad = false;
202+
}
203+
196204
// DISABLE_E8X (Karplus-Strong command)
197205
else if (!_strnicmp(configLine, "DISABLE_E8X=", 12))
198206
{

src/pt2_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ typedef struct config_t
1515
char *defModulesDir, *defSamplesDir;
1616
bool waveformCenterLine, pattDots, compoMode, autoCloseDiskOp, hideDiskOpDates, hwMouse;
1717
bool transDel, fullScreenStretch, vsyncOff, modDot, blankZeroFlag, realVuMeters, rememberPlayMode;
18-
bool startInFullscreen, integerScaling, disableE8xEffect;
18+
bool startInFullscreen, integerScaling, disableE8xEffect, noDownsampleOnSmpLoad;
1919
int8_t stereoSeparation, videoScaleFactor, accidental;
2020
uint8_t pixelFilter, filterModel;
2121
uint16_t quantizeValue;

src/pt2_header.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "pt2_unicode.h"
1515
#include "pt2_palette.h"
1616

17-
#define PROG_VER_STR "1.34"
17+
#define PROG_VER_STR "1.35"
1818

1919
#ifdef _WIN32
2020
#define DIR_DELIMITER '\\'

src/pt2_sample_loader.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ bool loadWAVSample(UNICHAR *fileName, char *entryName, int8_t forceDownSampling)
239239
return false;
240240
}
241241

242-
if (sampleRate > 22050)
242+
if (sampleRate > 22050 && !config.noDownsampleOnSmpLoad)
243243
{
244244
if (forceDownSampling == -1)
245245
{
@@ -884,7 +884,7 @@ bool loadIFFSample(UNICHAR *fileName, char *entryName, int8_t forceDownSampling)
884884
return false;
885885
}
886886

887-
if (sampleRate > 22050)
887+
if (sampleRate > 22050 && !config.noDownsampleOnSmpLoad)
888888
{
889889
if (forceDownSampling == -1)
890890
{
@@ -1322,7 +1322,7 @@ bool loadAIFFSample(UNICHAR *fileName, char *entryName, int8_t forceDownSampling
13221322
return false;
13231323
}
13241324

1325-
if (sampleRate > 22050)
1325+
if (sampleRate > 22050 && !config.noDownsampleOnSmpLoad)
13261326
{
13271327
if (forceDownSampling == -1)
13281328
{

src/pt2_visuals.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ void showDownsampleAskDialog(void)
342342
renderBigAskDialog();
343343

344344
textOutTight(133, 49, "THE SAMPLE'S FREQUENCY IS", video.palette[PAL_BACKGRD]);
345-
textOutTight(178, 57, "ABOVE 22KHZ.", video.palette[PAL_BACKGRD]);
345+
textOutTight(154, 57, "HIGH (ABOVE 22KHZ).", video.palette[PAL_BACKGRD]);
346346
textOutTight(133, 65, "DO YOU WANT TO DOWNSAMPLE", video.palette[PAL_BACKGRD]);
347347
textOutTight(156, 73, "BEFORE LOADING IT?", video.palette[PAL_BACKGRD]);
348348
}
@@ -2304,7 +2304,10 @@ void toggleFullScreen(void)
23042304
SDL_SetWindowFullscreen(video.window, 0);
23052305
SDL_RenderSetLogicalSize(video.renderer, SCREEN_W, SCREEN_H);
23062306
SDL_SetWindowSize(video.window, SCREEN_W * config.videoScaleFactor, SCREEN_H * config.videoScaleFactor);
2307-
SDL_SetWindowPosition(video.window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
2307+
2308+
// this is not sensible on a multi-monitor setup
2309+
//SDL_SetWindowPosition(video.window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
2310+
23082311
SDL_SetWindowGrab(video.window, SDL_FALSE);
23092312
}
23102313

0 commit comments

Comments
 (0)