Skip to content

Commit 0510166

Browse files
committed
Fixed incorrect sound edge at the start of attack
1 parent 550404c commit 0510166

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/grandorgue/sound/GOSoundFader.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ void GOSoundFader::Process(
3232
unsigned nFrames, float *buffer, float externalVolume) {
3333
// setup process
3434

35-
// Consider the velocity volume as part of the external volume
36-
externalVolume *= m_VelocityVolume;
37-
3835
float startTargetVolumePoint = m_LastTargetVolumePoint;
3936

4037
// Calculate new m_LastTargetVolumePoint
@@ -82,12 +79,19 @@ void GOSoundFader::Process(
8279
}
8380
}
8481

82+
// Calculate the external volume
83+
float newExternalVolume = m_VelocityVolume * externalVolume;
84+
85+
if (m_LastExternalVolumePoint < 0.0f)
86+
m_LastExternalVolumePoint = newExternalVolume;
87+
8588
float startExternalVolumePoint = m_LastExternalVolumePoint;
89+
8690
// Calculate new m_LastExternalVolumePoint
8791
// the target volume will be changed from startExternalVolumePoint to
8892
// m_LastExternalVolumePoint during the nFrames period
89-
if (externalVolume != startExternalVolumePoint)
90-
m_LastExternalVolumePoint += (externalVolume - startExternalVolumePoint)
93+
if (newExternalVolume != startExternalVolumePoint)
94+
m_LastExternalVolumePoint += (newExternalVolume - startExternalVolumePoint)
9195
// Assume that external volume is to be reached in MAX_FRAME_SIZE frames
9296
* std::max(nFrames, EXTERNAL_VOLUME_CHANGE_FRAMES)
9397
/ EXTERNAL_VOLUME_CHANGE_FRAMES;

0 commit comments

Comments
 (0)