Skip to content

Commit e1ba980

Browse files
committed
Apply tempo state separately from channel state
Fixes #384. Fixes #382.
1 parent 12cb934 commit e1ba980

File tree

2 files changed

+39
-19
lines changed

2 files changed

+39
-19
lines changed

Source/SoundGen.cpp

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#include "FamiTracker.h"
3333
#include "FamiTrackerTypes.h"
3434
#include "FTMComponentInterface.h" // // //
35-
#include "ChannelState.h" // // //
3635
#include "FamiTrackerDoc.h"
3736
#include "FamiTrackerView.h"
3837
#include "VisualizerWnd.h"
@@ -1527,32 +1526,41 @@ void CSoundGen::ApplyGlobalState() // // //
15271526
int Frame = IsPlaying() ? GetPlayerFrame() : m_pTrackerView->GetSelectedFrame();
15281527
int Row = IsPlaying() ? GetPlayerRow() : m_pTrackerView->GetSelectedRow();
15291528
if (stFullState *State = m_pDocument->RetrieveSoundState(GetPlayerTrack(), Frame, Row, -1)) {
1530-
if (State->Tempo != -1)
1531-
m_iTempo = State->Tempo;
1532-
if (State->GroovePos >= 0) {
1533-
m_iGroovePosition = State->GroovePos;
1534-
if (State->Speed >= 0)
1535-
m_iGrooveIndex = State->Speed;
1536-
if (m_pDocument->GetGroove(m_iGrooveIndex) != NULL)
1537-
m_iSpeed = m_pDocument->GetGroove(m_iGrooveIndex)->GetEntry(m_iGroovePosition);
1538-
}
1539-
else {
1540-
if (State->Speed >= 0)
1541-
m_iSpeed = State->Speed;
1542-
m_iGrooveIndex = -1;
1543-
}
1529+
ApplyGlobalTempoState(State);
15441530
m_iLastHighlight = m_pDocument->GetHighlightAt(GetPlayerTrack(), Frame, Row).First;
1545-
SetupSpeed();
1531+
15461532
for (int i = 0; i < m_pDocument->GetChannelCount(); i++) {
15471533
for (int j = 0; j < sizeof(m_pTrackerChannels) / sizeof(CTrackerChannel*); ++j) // // // pick this out later
15481534
if (m_pChannels[j] && m_pTrackerChannels[j]->GetID() == State->State[i].ChannelIndex) {
15491535
m_pChannels[j]->ApplyChannelState(&State->State[i]); break;
15501536
}
15511537
}
1538+
15521539
delete State;
15531540
}
15541541
}
15551542

1543+
// Separate updating groove, tempo and speed
1544+
// to allow ResetTempo() to get the most recent state without updating the channel state
1545+
void CSoundGen::ApplyGlobalTempoState(stFullState *pState)
1546+
{
1547+
if (pState->Tempo != -1)
1548+
m_iTempo = pState->Tempo;
1549+
if (pState->GroovePos >= 0) {
1550+
m_iGroovePosition = pState->GroovePos;
1551+
if (pState->Speed >= 0)
1552+
m_iGrooveIndex = pState->Speed;
1553+
if (m_pDocument->GetGroove(m_iGrooveIndex) != NULL)
1554+
m_iSpeed = m_pDocument->GetGroove(m_iGrooveIndex)->GetEntry(m_iGroovePosition);
1555+
}
1556+
else {
1557+
if (pState->Speed >= 0)
1558+
m_iSpeed = pState->Speed;
1559+
m_iGrooveIndex = -1;
1560+
}
1561+
SetupSpeed();
1562+
}
1563+
15561564
/*! \brief Obtains a human-readable form of a channel state object.
15571565
\warning The output of this method is neither guaranteed nor required to match that of
15581566
CChannelHandler::GetStateString.
@@ -1858,10 +1866,20 @@ void CSoundGen::ResetTempo()
18581866

18591867
m_iTempoAccum = 0;
18601868

1861-
if (theApp.GetSettings()->General.bRetrieveChanState) // // //
1862-
ApplyGlobalState();
1863-
// Legacy behavior
1869+
if (theApp.GetSettings()->General.bRetrieveChanState) { // !! !!
1870+
// Calling on ApplyGlobalState() causes crackly audio on FDS
1871+
// May have something to do with conflicting stFullState pointers? haven't investigated
1872+
// So we do a reduced version here where we don't update the channel handlers.
1873+
int Frame = IsPlaying() ? GetPlayerFrame() : m_pTrackerView->GetSelectedFrame();
1874+
int Row = IsPlaying() ? GetPlayerRow() : m_pTrackerView->GetSelectedRow();
1875+
if (stFullState *State = m_pDocument->RetrieveSoundState(GetPlayerTrack(), Frame, Row, -1)) {
1876+
ApplyGlobalTempoState(State);
1877+
m_iLastHighlight = m_pDocument->GetHighlightAt(GetPlayerTrack(), Frame, Row).First;
1878+
delete State;
1879+
}
1880+
}
18641881
else {
1882+
// Legacy behavior
18651883
if (m_pDocument->GetSongGroove(m_iPlayTrack) && m_pDocument->GetGroove(m_iSpeed) != NULL) { // // //
18661884
m_iGrooveIndex = m_iSpeed;
18671885
m_iGroovePosition = 0;

Source/SoundGen.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <queue> // // //
3333
#include "Common.h"
3434
#include "FamiTrackerTypes.h"
35+
#include "ChannelState.h" // // //
3536

3637
#include <atomic>
3738
#include <cstdint>
@@ -321,6 +322,7 @@ class CSoundGen : IAudioCallback
321322
void PlayerSkipTo(int Row);
322323

323324
void ApplyGlobalState(); // // //
325+
void ApplyGlobalTempoState(stFullState *pState);
324326

325327
public:
326328
static const double NEW_VIBRATO_DEPTH[];

0 commit comments

Comments
 (0)