Skip to content

Commit da1a230

Browse files
committed
fix #48246: End of exported audio heard at start
1 parent d25a3d6 commit da1a230

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

mscore/exportaudio.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ bool MuseScore::saveAudio(Score* score, const QString& name)
9090
for (int pass = 0; pass < 2; ++pass) {
9191
EventMap::const_iterator playPos;
9292
playPos = events.cbegin();
93+
synti->allSoundsOff(-1);
9394

9495
//
9596
// init instruments
@@ -119,6 +120,7 @@ bool MuseScore::saveAudio(Score* score, const QString& name)
119120
//
120121
// collect events for one segment
121122
//
123+
float max = 0.0;
122124
memset(buffer, 0, sizeof(float) * FRAMES * 2);
123125
int endTime = playTime + frames;
124126
float* p = buffer;
@@ -148,18 +150,22 @@ bool MuseScore::saveAudio(Score* score, const QString& name)
148150
playTime += frames;
149151
}
150152
if (pass == 1) {
151-
for (unsigned i = 0; i < FRAMES * 2; ++i)
153+
for (unsigned i = 0; i < FRAMES * 2; ++i) {
154+
max = qMax(max, qAbs(buffer[i]));
152155
buffer[i] *= gain;
156+
}
153157
sf_writef_float(sf, buffer, FRAMES);
154158
}
155159
else {
156-
for (unsigned i = 0; i < FRAMES * 2; ++i)
160+
for (unsigned i = 0; i < FRAMES * 2; ++i) {
161+
max = qMax(max, qAbs(buffer[i]));
157162
peak = qMax(peak, qAbs(buffer[i]));
163+
}
158164
}
159165
playTime = endTime;
160166
pBar->setValue((pass * et + playTime) / 2);
161-
162-
if (playTime >= et)
167+
// create sound until the sound decays
168+
if (playTime >= et && max*peak < 0.000001)
163169
break;
164170
}
165171
if (pass == 0 && peak == 0.0) {

mscore/exportmp3.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,8 @@ bool MuseScore::saveMp3(Score* score, const QString& name)
711711
for (int pass = 0; pass < 2; ++pass) {
712712
EventMap::const_iterator playPos;
713713
playPos = events.cbegin();
714+
synti->allSoundsOff(-1);
715+
714716
//
715717
// init instruments
716718
//
@@ -734,6 +736,7 @@ bool MuseScore::saveMp3(Score* score, const QString& name)
734736

735737
for (;;) {
736738
unsigned frames = FRAMES;
739+
float max = 0;
737740
//
738741
// collect events for one segment
739742
//
@@ -785,6 +788,8 @@ bool MuseScore::saveMp3(Score* score, const QString& name)
785788

786789
if (pass == 1) {
787790
for (int i = 0; i < FRAMES; ++i) {
791+
max = qMax(max, qAbs(bufferL[i]));
792+
max = qMax(max, qAbs(bufferR[i]));
788793
bufferL[i] *= gain;
789794
bufferR[i] *= gain;
790795
}
@@ -808,13 +813,16 @@ bool MuseScore::saveMp3(Score* score, const QString& name)
808813
}
809814
else {
810815
for (int i = 0; i < FRAMES; ++i) {
816+
max = qMax(max, qAbs(bufferL[i]));
817+
max = qMax(max, qAbs(bufferR[i]));
811818
peak = qMax(peak, qAbs(bufferL[i]));
812819
peak = qMax(peak, qAbs(bufferR[i]));
813820
}
814821
}
815822
playTime = endTime;
816823
pBar->setValue((pass * et + playTime) / 2);
817-
if (playTime >= et)
824+
// create sound until the sound decays
825+
if (playTime >= et && max * peak < 0.000001)
818826
break;
819827
}
820828
if (pass == 0 && peak == 0.0) {

0 commit comments

Comments
 (0)