ft2-clone

Fasttracker 2 clone
Log | Files | Refs | README | LICENSE

commit 01075c7508d8356a7fe77110daa76d0e87264c38
parent c8ca07133c9fcb92cc2d9242538764f0f4bbc386
Author: Olav Sørensen <olav.sorensen@live.no>
Date:   Sun,  1 Nov 2020 19:37:34 +0100

Pushed v1.38 code

- Fixed two possible pattern length bugs while switching to a new, shorter pattern while the song is playing
- Mixer code cleanup (generates smaller code now)

Diffstat:
Msrc/ft2_audio.c | 8+++++---
Msrc/ft2_audio.h | 7++++++-
Msrc/ft2_header.h | 2+-
Msrc/ft2_pattern_ed.c | 106+++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/ft2_replayer.c | 2+-
Msrc/ft2_replayer.h | 8++++++--
Msrc/ft2_sample_ed.c | 16++++++++--------
Msrc/mixer/ft2_center_mix.c | 8++++++++
Msrc/mixer/ft2_mix.c | 8++++++++
Msrc/mixer/ft2_mix_macros.h | 44++++++++------------------------------------
10 files changed, 103 insertions(+), 106 deletions(-)

diff --git a/src/ft2_audio.c b/src/ft2_audio.c @@ -324,16 +324,18 @@ static void voiceTrigger(int32_t ch, sampleTyp *s, int32_t position) { v->base16 = (const int16_t *)s->pek; v->revBase16 = &v->base16[loopStart + loopEnd]; // for pingpong loops + + v->leftEdgeTaps16 = s->leftEdgeTapSamples16 + 3; } else { v->base8 = s->pek; v->revBase8 = &v->base8[loopStart + loopEnd]; // for pingpong loops + v->leftEdgeTaps8 = s->leftEdgeTapSamples8 + 3; + } - v->dLeftEdgeTaps = s->dLeftEdgeTapSamples + 3; v->hasLooped = false; // for sinc interpolation special case - v->backwards = false; v->loopType = loopType; v->end = (loopType > 0) ? loopEnd : length; @@ -801,7 +803,7 @@ void unlockAudio(void) audio.locked = false; } -static void resetSyncQueues(void) +void resetSyncQueues(void) { pattSync.data[0].timestamp = 0; pattSync.readPos = 0; diff --git a/src/ft2_audio.h b/src/ft2_audio.h @@ -50,8 +50,12 @@ typedef struct int32_t pos, end, loopStart, loopLength; uint32_t volRampSamples, revDelta, oldRevDelta; uint64_t posFrac, delta, oldDelta; + + // if (loopStart > 0 && pos <= loopStart+3) useTheseTaps(); + const int8_t *leftEdgeTaps8; + const int16_t *leftEdgeTaps16; + const double *dSincLUT; - double *dLeftEdgeTaps; // if (loopStart > 0 && pos <= loopStart+3) useTheseTaps(); double dVol, dDestVolL, dDestVolR, dVolL, dVolR, dVolDeltaL, dVolDeltaR; } voice_t; @@ -94,6 +98,7 @@ bool chQueuePush(chSyncData_t t); bool chQueuePop(void); chSyncData_t *chQueuePeek(void); uint64_t getChQueueTimestamp(void); +void resetSyncQueues(void); void calcPanningTable(void); void setAudioAmp(int16_t amp, int16_t masterVol, bool bitDepth32Flag); diff --git a/src/ft2_header.h b/src/ft2_header.h @@ -12,7 +12,7 @@ #endif #include "ft2_replayer.h" -#define PROG_VER_STR "1.37" +#define PROG_VER_STR "1.38" // do NOT change these! It will only mess things up... diff --git a/src/ft2_pattern_ed.c b/src/ft2_pattern_ed.c @@ -1614,11 +1614,22 @@ void pbPosEdPattUp(void) { song.songTab[song.songPos]++; song.pattNr = song.songTab[song.songPos]; - editor.editPattern = (uint8_t)song.pattNr; - song.pattLen = pattLens[editor.editPattern]; + song.pattLen = pattLens[song.pattNr]; + if (song.pattPos >= song.pattLen) + { + song.pattPos = song.pattLen-1; + if (!songPlaying) + editor.pattPos = song.pattPos; + } + + if (!songPlaying) + editor.editPattern = (uint8_t)song.pattNr; + + checkMarkLimits(); ui.updatePatternEditor = true; ui.updatePosSections = true; + setSongModifiedFlag(); } unlockMixerCallback(); @@ -1634,11 +1645,22 @@ void pbPosEdPattDown(void) { song.songTab[song.songPos]--; song.pattNr = song.songTab[song.songPos]; - editor.editPattern = (uint8_t)song.pattNr; - song.pattLen = pattLens[editor.editPattern]; + song.pattLen = pattLens[song.pattNr]; + if (song.pattPos >= song.pattLen) + { + song.pattPos = song.pattLen-1; + if (!songPlaying) + editor.pattPos = song.pattPos; + } + + if (!songPlaying) + editor.editPattern = (uint8_t)song.pattNr; + + checkMarkLimits(); ui.updatePatternEditor = true; ui.updatePosSections = true; + setSongModifiedFlag(); } unlockMixerCallback(); @@ -1888,49 +1910,30 @@ void pbSubChan(void) unlockMixerCallback(); } -static void updatePtnLen(void) -{ - uint16_t len = pattLens[editor.editPattern]; - - song.pattLen = len; - if (song.pattPos >= len) - { - song.pattPos = len - 1; - editor.pattPos = song.pattPos; - } - - checkMarkLimits(); -} - void pbEditPattUp(void) { const bool audioWasntLocked = !audio.locked; if (audioWasntLocked) lockAudio(); - if (songPlaying) + if (song.pattNr < 255) { - if (song.pattNr < 255) - { - song.pattNr++; - updatePtnLen(); + song.pattNr++; - ui.updatePatternEditor = true; - ui.updatePosSections = true; - } - } - else - { - if (editor.editPattern < 255) + song.pattLen = pattLens[song.pattNr]; + if (song.pattPos >= song.pattLen) { - editor.editPattern++; + song.pattPos = song.pattLen-1; + if (!songPlaying) + editor.pattPos = song.pattPos; + } - song.pattNr = editor.editPattern; - updatePtnLen(); + if (!songPlaying) + editor.editPattern = (uint8_t)song.pattNr; - ui.updatePatternEditor = true; - ui.updatePosSections = true; - } + checkMarkLimits(); + ui.updatePatternEditor = true; + ui.updatePosSections = true; } if (audioWasntLocked) @@ -1943,29 +1946,24 @@ void pbEditPattDown(void) if (audioWasntLocked) lockAudio(); - if (songPlaying) + if (song.pattNr > 0) { - if (song.pattNr > 0) - { - song.pattNr--; - updatePtnLen(); + song.pattNr--; - ui.updatePatternEditor = true; - ui.updatePosSections = true; - } - } - else - { - if (editor.editPattern > 0) + song.pattLen = pattLens[song.pattNr]; + if (song.pattPos >= song.pattLen) { - editor.editPattern--; + song.pattPos = song.pattLen-1; + if (!songPlaying) + editor.pattPos = song.pattPos; + } - song.pattNr = editor.editPattern; - updatePtnLen(); + if (!songPlaying) + editor.editPattern = (uint8_t)song.pattNr; - ui.updatePatternEditor = true; - ui.updatePosSections = true; - } + checkMarkLimits(); + ui.updatePatternEditor = true; + ui.updatePosSections = true; } if (audioWasntLocked) diff --git a/src/ft2_replayer.c b/src/ft2_replayer.c @@ -2294,7 +2294,7 @@ void setPos(int16_t songPos, int16_t pattPos, bool resetTimer) { song.pattPos = pattPos; if (song.pattPos >= song.pattLen) - song.pattPos = song.pattLen - 1; + song.pattPos = song.pattLen-1; } // if not playing, update local position variables diff --git a/src/ft2_replayer.h b/src/ft2_replayer.h @@ -173,9 +173,13 @@ typedef struct sampleTyp_t bool fixed; int8_t fine, relTon, *pek, *origPek; uint8_t vol, typ, pan; - double dLeftEdgeTapSamples[8+3]; + int32_t len, repS, repL; + + // fix for resampling interpolation taps + int8_t leftEdgeTapSamples8[SINC_TAPS+SINC_LEFT_TAPS]; + int16_t leftEdgeTapSamples16[SINC_TAPS+SINC_LEFT_TAPS]; int16_t fixedSmp[SINC_RIGHT_TAPS]; - int32_t fixedPos, len, repS, repL; + int32_t fixedPos; } sampleTyp; typedef struct instrTyp_t diff --git a/src/ft2_sample_ed.c b/src/ft2_sample_ed.c @@ -148,7 +148,7 @@ void fixSample(sampleTyp *s) if (sample16Bit) { for (int32_t i = 0; i < SINC_TAPS+SINC_LEFT_TAPS; i++) - s->dLeftEdgeTapSamples[i] = ptr16[loopStart]; + s->leftEdgeTapSamples16[i] = ptr16[loopStart]; for (int32_t i = 0; i < SINC_RIGHT_TAPS; i++) { @@ -159,7 +159,7 @@ void fixSample(sampleTyp *s) else { for (int32_t i = 0; i < SINC_TAPS+SINC_LEFT_TAPS; i++) - s->dLeftEdgeTapSamples[i] = s->pek[loopStart]; + s->leftEdgeTapSamples8[i] = s->pek[loopStart]; for (int32_t i = 0; i < SINC_RIGHT_TAPS; i++) { @@ -190,7 +190,7 @@ void fixSample(sampleTyp *s) pos = loopStart + ((i-SINC_LEFT_TAPS) % loopLen); } - s->dLeftEdgeTapSamples[i] = ptr16[pos]; + s->leftEdgeTapSamples16[i] = ptr16[pos]; } // right edge (change actual sample data since data after loop is never used) @@ -216,7 +216,7 @@ void fixSample(sampleTyp *s) pos = loopStart + ((i-SINC_LEFT_TAPS) % loopLen); } - s->dLeftEdgeTapSamples[i] = s->pek[pos]; + s->leftEdgeTapSamples8[i] = s->pek[pos]; } // right edge (change actual sample data since data after loop is never used) @@ -254,7 +254,7 @@ void fixSample(sampleTyp *s) } } - s->dLeftEdgeTapSamples[3-i] = ptr16[pos]; + s->leftEdgeTapSamples16[3-i] = ptr16[pos]; } pos = loopStart; @@ -278,7 +278,7 @@ void fixSample(sampleTyp *s) } } - s->dLeftEdgeTapSamples[i] = ptr16[pos]; + s->leftEdgeTapSamples16[i] = ptr16[pos]; } // right edge (change actual sample data since data after loop is never used) @@ -331,7 +331,7 @@ void fixSample(sampleTyp *s) } } - s->dLeftEdgeTapSamples[3-i] = s->pek[pos]; + s->leftEdgeTapSamples8[3-i] = s->pek[pos]; } pos = loopStart; @@ -355,7 +355,7 @@ void fixSample(sampleTyp *s) } } - s->dLeftEdgeTapSamples[i] = s->pek[pos]; + s->leftEdgeTapSamples8[i] = s->pek[pos]; } // right edge (change actual sample data since data after loop is never used) diff --git a/src/mixer/ft2_center_mix.c b/src/mixer/ft2_center_mix.c @@ -183,6 +183,7 @@ void centerMix8bNoLoopSIntrp(voice_t *v, uint32_t numSamples) void centerMix8bLoopSIntrp(voice_t *v, uint32_t numSamples) { const int8_t *base, *smpPtr; + int8_t *smpTapPtr; double dSample, *dMixBufferL, *dMixBufferR; int32_t pos; uint32_t i, samplesToMix, samplesLeft; @@ -249,6 +250,7 @@ void centerMix8bLoopSIntrp(voice_t *v, uint32_t numSamples) void centerMix8bBidiLoopSIntrp(voice_t *v, uint32_t numSamples) { const int8_t *base, *revBase, *smpPtr; + int8_t *smpTapPtr; double dSample, *dMixBufferL, *dMixBufferR; int32_t pos; uint32_t i, samplesToMix, samplesLeft; @@ -648,6 +650,7 @@ void centerMix8bRampNoLoopSIntrp(voice_t *v, uint32_t numSamples) void centerMix8bRampLoopSIntrp(voice_t *v, uint32_t numSamples) { const int8_t *base, *smpPtr; + int8_t *smpTapPtr; double dSample, *dMixBufferL, *dMixBufferR; int32_t pos; double dVolLDelta, dVolL; @@ -727,6 +730,7 @@ void centerMix8bRampLoopSIntrp(voice_t *v, uint32_t numSamples) void centerMix8bRampBidiLoopSIntrp(voice_t *v, uint32_t numSamples) { const int8_t *base, *revBase, *smpPtr; + int8_t *smpTapPtr; double dSample, *dMixBufferL, *dMixBufferR; int32_t pos; double dVolLDelta, dVolL; @@ -1134,6 +1138,7 @@ void centerMix16bNoLoopSIntrp(voice_t *v, uint32_t numSamples) void centerMix16bLoopSIntrp(voice_t *v, uint32_t numSamples) { const int16_t *base, *smpPtr; + int16_t *smpTapPtr; double dSample, *dMixBufferL, *dMixBufferR; int32_t pos; uint32_t i, samplesToMix, samplesLeft; @@ -1200,6 +1205,7 @@ void centerMix16bLoopSIntrp(voice_t *v, uint32_t numSamples) void centerMix16bBidiLoopSIntrp(voice_t *v, uint32_t numSamples) { const int16_t *base, *revBase, *smpPtr; + int16_t *smpTapPtr; double dSample, *dMixBufferL, *dMixBufferR; int32_t pos; uint32_t i, samplesToMix, samplesLeft; @@ -1599,6 +1605,7 @@ void centerMix16bRampNoLoopSIntrp(voice_t *v, uint32_t numSamples) void centerMix16bRampLoopSIntrp(voice_t *v, uint32_t numSamples) { const int16_t *base, *smpPtr; + int16_t *smpTapPtr; double dSample, *dMixBufferL, *dMixBufferR; int32_t pos; double dVolLDelta, dVolL; @@ -1678,6 +1685,7 @@ void centerMix16bRampLoopSIntrp(voice_t *v, uint32_t numSamples) void centerMix16bRampBidiLoopSIntrp(voice_t *v, uint32_t numSamples) { const int16_t *base, *revBase, *smpPtr; + int16_t *smpTapPtr; double dSample, *dMixBufferL, *dMixBufferR; int32_t pos; double dVolLDelta, dVolL; diff --git a/src/mixer/ft2_mix.c b/src/mixer/ft2_mix.c @@ -203,6 +203,7 @@ static void mix8bNoLoopSIntrp(voice_t *v, uint32_t numSamples) static void mix8bLoopSIntrp(voice_t *v, uint32_t numSamples) { const int8_t *base, *smpPtr; + int8_t *smpTapPtr; double dSample, *dMixBufferL, *dMixBufferR; int32_t pos; uint32_t i, samplesToMix, samplesLeft; @@ -269,6 +270,7 @@ static void mix8bLoopSIntrp(voice_t *v, uint32_t numSamples) static void mix8bBidiLoopSIntrp(voice_t *v, uint32_t numSamples) { const int8_t *base, *revBase, *smpPtr; + int8_t *smpTapPtr; double dSample, *dMixBufferL, *dMixBufferR; int32_t pos; uint32_t i, samplesToMix, samplesLeft; @@ -667,6 +669,7 @@ static void mix8bRampNoLoopSIntrp(voice_t *v, uint32_t numSamples) static void mix8bRampLoopSIntrp(voice_t *v, uint32_t numSamples) { const int8_t *base, *smpPtr; + int8_t *smpTapPtr; double dSample, *dMixBufferL, *dMixBufferR; int32_t pos; double dVolLDelta, dVolRDelta, dVolL, dVolR; @@ -746,6 +749,7 @@ static void mix8bRampLoopSIntrp(voice_t *v, uint32_t numSamples) static void mix8bRampBidiLoopSIntrp(voice_t *v, uint32_t numSamples) { const int8_t *base, *revBase, *smpPtr; + int8_t *smpTapPtr; double dSample, *dMixBufferL, *dMixBufferR; int32_t pos; double dVolLDelta, dVolRDelta, dVolL, dVolR; @@ -1153,6 +1157,7 @@ static void mix16bNoLoopSIntrp(voice_t *v, uint32_t numSamples) static void mix16bLoopSIntrp(voice_t *v, uint32_t numSamples) { const int16_t *base, *smpPtr; + int16_t *smpTapPtr; double dSample, *dMixBufferL, *dMixBufferR; int32_t pos; uint32_t i, samplesToMix, samplesLeft; @@ -1219,6 +1224,7 @@ static void mix16bLoopSIntrp(voice_t *v, uint32_t numSamples) static void mix16bBidiLoopSIntrp(voice_t *v, uint32_t numSamples) { const int16_t *base, *revBase, *smpPtr; + int16_t *smpTapPtr; double dSample, *dMixBufferL, *dMixBufferR; int32_t pos; uint32_t i, samplesToMix, samplesLeft; @@ -1617,6 +1623,7 @@ static void mix16bRampNoLoopSIntrp(voice_t *v, uint32_t numSamples) static void mix16bRampLoopSIntrp(voice_t *v, uint32_t numSamples) { const int16_t *base, *smpPtr; + int16_t *smpTapPtr; double dSample, *dMixBufferL, *dMixBufferR; int32_t pos; double dVolLDelta, dVolRDelta, dVolL, dVolR; @@ -1696,6 +1703,7 @@ static void mix16bRampLoopSIntrp(voice_t *v, uint32_t numSamples) static void mix16bRampBidiLoopSIntrp(voice_t *v, uint32_t numSamples) { const int16_t *base, *revBase, *smpPtr; + int16_t *smpTapPtr; double dSample, *dMixBufferL, *dMixBufferR; int32_t pos; double dVolLDelta, dVolRDelta, dVolL, dVolR; diff --git a/src/mixer/ft2_mix_macros.h b/src/mixer/ft2_mix_macros.h @@ -235,58 +235,30 @@ #define RENDER_8BIT_SMP_SINTRP_TAP_FIX \ assert(smpPtr >= base && smpPtr < base+v->end); \ - if (smpPtr <= leftEdgePtr) \ - { \ - const double *tapData = &v->dLeftEdgeTaps[(int32_t)(smpPtr - loopStartPtr)]; \ - WINDOWED_SINC_INTERPOLATION8(tapData, posFrac) \ - } \ - else \ - { \ - WINDOWED_SINC_INTERPOLATION8(smpPtr, posFrac) \ - } \ + smpTapPtr = (smpPtr <= leftEdgePtr) ? (int8_t *)&v->leftEdgeTaps8[(int32_t)(smpPtr-loopStartPtr)] : (int8_t *)smpPtr; \ + WINDOWED_SINC_INTERPOLATION8(smpTapPtr, posFrac) \ *dMixBufferL++ += dSample * dVolL; \ *dMixBufferR++ += dSample * dVolR; \ #define RENDER_8BIT_SMP_MONO_SINTRP_TAP_FIX \ assert(smpPtr >= base && smpPtr < base+v->end); \ - if (smpPtr <= leftEdgePtr) \ - { \ - const double *tapData = &v->dLeftEdgeTaps[(int32_t)(smpPtr - loopStartPtr)]; \ - WINDOWED_SINC_INTERPOLATION8(tapData, posFrac) \ - } \ - else \ - { \ - WINDOWED_SINC_INTERPOLATION8(smpPtr, posFrac) \ - } \ + smpTapPtr = (smpPtr <= leftEdgePtr) ? (int8_t *)&v->leftEdgeTaps8[(int32_t)(smpPtr-loopStartPtr)] : (int8_t *)smpPtr; \ + WINDOWED_SINC_INTERPOLATION8(smpTapPtr, posFrac) \ dSample *= dVolL; \ *dMixBufferL++ += dSample; \ *dMixBufferR++ += dSample; \ #define RENDER_16BIT_SMP_SINTRP_TAP_FIX \ assert(smpPtr >= base && smpPtr < base+v->end); \ - if (smpPtr <= leftEdgePtr) \ - { \ - const double *tapData = &v->dLeftEdgeTaps[(int32_t)(smpPtr - loopStartPtr)]; \ - WINDOWED_SINC_INTERPOLATION16(tapData, posFrac) \ - } \ - else \ - { \ - WINDOWED_SINC_INTERPOLATION16(smpPtr, posFrac) \ - } \ + smpTapPtr = (smpPtr <= leftEdgePtr) ? (int16_t *)&v->leftEdgeTaps16[(int32_t)(smpPtr-loopStartPtr)] : (int16_t *)smpPtr; \ + WINDOWED_SINC_INTERPOLATION16(smpTapPtr, posFrac) \ *dMixBufferL++ += dSample * dVolL; \ *dMixBufferR++ += dSample * dVolR; \ #define RENDER_16BIT_SMP_MONO_SINTRP_TAP_FIX \ assert(smpPtr >= base && smpPtr < base+v->end); \ - if (smpPtr <= leftEdgePtr) \ - { \ - const double *tapData = &v->dLeftEdgeTaps[(int32_t)(smpPtr - loopStartPtr)]; \ - WINDOWED_SINC_INTERPOLATION16(tapData, posFrac) \ - } \ - else \ - { \ - WINDOWED_SINC_INTERPOLATION16(smpPtr, posFrac) \ - } \ + smpTapPtr = (smpPtr <= leftEdgePtr) ? (int16_t *)&v->leftEdgeTaps16[(int32_t)(smpPtr-loopStartPtr)] : (int16_t *)smpPtr; \ + WINDOWED_SINC_INTERPOLATION16(smpTapPtr, posFrac) \ dSample *= dVolL; \ *dMixBufferL++ += dSample; \ *dMixBufferR++ += dSample; \