Skip to content

Commit

Permalink
fix #48246: End of exported audio heard at start
Browse files Browse the repository at this point in the history
  • Loading branch information
lasconic committed Feb 21, 2015
1 parent d25a3d6 commit da1a230
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
14 changes: 10 additions & 4 deletions mscore/exportaudio.cpp
Expand Up @@ -90,6 +90,7 @@ bool MuseScore::saveAudio(Score* score, const QString& name)
for (int pass = 0; pass < 2; ++pass) {
EventMap::const_iterator playPos;
playPos = events.cbegin();
synti->allSoundsOff(-1);

//
// init instruments
Expand Down Expand Up @@ -119,6 +120,7 @@ bool MuseScore::saveAudio(Score* score, const QString& name)
//
// collect events for one segment
//
float max = 0.0;
memset(buffer, 0, sizeof(float) * FRAMES * 2);
int endTime = playTime + frames;
float* p = buffer;
Expand Down Expand Up @@ -148,18 +150,22 @@ bool MuseScore::saveAudio(Score* score, const QString& name)
playTime += frames;
}
if (pass == 1) {
for (unsigned i = 0; i < FRAMES * 2; ++i)
for (unsigned i = 0; i < FRAMES * 2; ++i) {
max = qMax(max, qAbs(buffer[i]));
buffer[i] *= gain;
}
sf_writef_float(sf, buffer, FRAMES);
}
else {
for (unsigned i = 0; i < FRAMES * 2; ++i)
for (unsigned i = 0; i < FRAMES * 2; ++i) {
max = qMax(max, qAbs(buffer[i]));
peak = qMax(peak, qAbs(buffer[i]));
}
}
playTime = endTime;
pBar->setValue((pass * et + playTime) / 2);

if (playTime >= et)
// create sound until the sound decays
if (playTime >= et && max*peak < 0.000001)
break;
}
if (pass == 0 && peak == 0.0) {
Expand Down
10 changes: 9 additions & 1 deletion mscore/exportmp3.cpp
Expand Up @@ -711,6 +711,8 @@ bool MuseScore::saveMp3(Score* score, const QString& name)
for (int pass = 0; pass < 2; ++pass) {
EventMap::const_iterator playPos;
playPos = events.cbegin();
synti->allSoundsOff(-1);

//
// init instruments
//
Expand All @@ -734,6 +736,7 @@ bool MuseScore::saveMp3(Score* score, const QString& name)

for (;;) {
unsigned frames = FRAMES;
float max = 0;
//
// collect events for one segment
//
Expand Down Expand Up @@ -785,6 +788,8 @@ bool MuseScore::saveMp3(Score* score, const QString& name)

if (pass == 1) {
for (int i = 0; i < FRAMES; ++i) {
max = qMax(max, qAbs(bufferL[i]));
max = qMax(max, qAbs(bufferR[i]));
bufferL[i] *= gain;
bufferR[i] *= gain;
}
Expand All @@ -808,13 +813,16 @@ bool MuseScore::saveMp3(Score* score, const QString& name)
}
else {
for (int i = 0; i < FRAMES; ++i) {
max = qMax(max, qAbs(bufferL[i]));
max = qMax(max, qAbs(bufferR[i]));
peak = qMax(peak, qAbs(bufferL[i]));
peak = qMax(peak, qAbs(bufferR[i]));
}
}
playTime = endTime;
pBar->setValue((pass * et + playTime) / 2);
if (playTime >= et)
// create sound until the sound decays
if (playTime >= et && max * peak < 0.000001)
break;
}
if (pass == 0 && peak == 0.0) {
Expand Down

0 comments on commit da1a230

Please sign in to comment.