Skip to content
This repository was archived by the owner on May 11, 2022. It is now read-only.

Commit b04d480

Browse files
committed
A very rare issue seems to be fixed, due to which after 20-30 minutes of listening to a large amount of music, the sound may disappear, and the text of the current position of the track will not move.
1 parent 3e97a48 commit b04d480

File tree

4 files changed

+70
-62
lines changed

4 files changed

+70
-62
lines changed

ide/BloodyPlayer.pro.user

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE QtCreatorProject>
3-
<!-- Written by QtCreator 4.9.2, 2019-08-19T15:14:23. -->
3+
<!-- Written by QtCreator 4.9.2, 2019-08-30T12:23:04. -->
44
<qtcreator>
55
<data>
66
<variable>EnvironmentId</variable>

src/Model/AudioService/audioservice.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,11 @@ void AudioService::addTrack(const wchar_t *pFilePath)
247247
monitor.detach();
248248
}
249249

250+
FMOD_RESULT result = pSystem->update();
251+
if (result)
252+
{
253+
pMainWindow->showMessageBox( true, std::string("AudioService::addTrack::FMOD::System::update() failed. Error: ") + std::string(FMOD_ErrorString(result)) );
254+
}
250255

251256
mtxThreadLoadAddTrack.unlock();
252257
}
@@ -429,6 +434,12 @@ void AudioService::playTrack(size_t iTrackIndex, bool bDontLockMutex)
429434
pMainWindow->showMessageBox(false, "Something went wrong and we could not play the track.");
430435
}
431436

437+
FMOD_RESULT result = pSystem->update();
438+
if (result)
439+
{
440+
pMainWindow->showMessageBox( true, std::string("AudioService::playTrack::FMOD::System::update() failed. Error: ") + std::string(FMOD_ErrorString(result)) );
441+
}
442+
432443
pMainWindow->setPlayingOnTrack(iCurrentlyPlayingTrackIndex);
433444
}
434445
else
@@ -458,6 +469,13 @@ void AudioService::setTrackPos(unsigned int graphPos)
458469
}
459470
}
460471

472+
FMOD_RESULT result;
473+
result = pSystem->update();
474+
if (result)
475+
{
476+
pMainWindow->showMessageBox( true, std::string("AudioService::setTrackPos::FMOD::System::update() failed. Error: ") + std::string(FMOD_ErrorString(result)) );
477+
}
478+
461479
mtxTracksVec.unlock();
462480
}
463481

@@ -483,6 +501,13 @@ void AudioService::pauseTrack()
483501
}
484502
}
485503

504+
FMOD_RESULT result;
505+
result = pSystem->update();
506+
if (result)
507+
{
508+
pMainWindow->showMessageBox( true, std::string("AudioService::pauseTrack::FMOD::System::update() failed. Error: ") + std::string(FMOD_ErrorString(result)) );
509+
}
510+
486511
mtxTracksVec.unlock();
487512
}
488513

@@ -619,6 +644,13 @@ void AudioService::removeTrack(size_t iTrackIndex)
619644
delete tracks[iTrackIndex];
620645
tracks.erase( tracks.begin() + iTrackIndex );
621646

647+
FMOD_RESULT result;
648+
result = pSystem->update();
649+
if (result)
650+
{
651+
pMainWindow->showMessageBox( true, std::string("AudioService::removeTrack::FMOD::System::update() failed. Error: ") + std::string(FMOD_ErrorString(result)) );
652+
}
653+
622654
mtxGetCurrentDrawingIndex.unlock();
623655
}
624656
else
@@ -1076,6 +1108,12 @@ void AudioService::monitorTrack()
10761108
// The track is ended, play next
10771109
tracks[iCurrentlyPlayingTrackIndex]->reCreateTrack(fCurrentVolume);
10781110

1111+
FMOD_RESULT result = pSystem->update();
1112+
if (result)
1113+
{
1114+
pMainWindow->showMessageBox(true, std::string("AudioService::monitorTrack::FMOD::System::update() failed. Error: ") + FMOD_ErrorString(result));
1115+
}
1116+
10791117
if (bRepeatTrack)
10801118
{
10811119
// Or not
@@ -1104,6 +1142,8 @@ void AudioService::monitorTrack()
11041142
}
11051143
}
11061144

1145+
pSystem->update();
1146+
11071147
mtxTracksVec.unlock();
11081148

11091149
std::this_thread::sleep_for(std::chrono::milliseconds(MONITOR_TRACK_INTERVAL_MS));
@@ -1116,6 +1156,16 @@ void AudioService::drawGraph(size_t* iTrackIndex)
11161156
bDrawing = true;
11171157

11181158

1159+
// default: 16384
1160+
// "If FMOD_TIMEUNIT_RAWBYTES is used, the memory allocated is two times the size passed in, because fmod allocates a double buffer."
1161+
// 131072 * 2 = 256 kB (x8 times bigger than default) to speed up our graph draw (to speed up our readData() calls)
1162+
FMOD_RESULT fresult = pSystem->setStreamBufferSize(131072, FMOD_TIMEUNIT_RAWBYTES);
1163+
if (fresult)
1164+
{
1165+
pMainWindow->showMessageBox( true, std::string("AudioService::AudioService::FMOD::System::setStreamBufferSize() failed. Error: ") + std::string(FMOD_ErrorString(fresult)) );
1166+
}
1167+
1168+
11191169
pMainWindow->clearGraph();
11201170

11211171
// this value combines 'iSamplesInOne' samples in one to store less points for graph in memory
@@ -1185,6 +1235,16 @@ void AudioService::drawGraph(size_t* iTrackIndex)
11851235

11861236
mtxGetCurrentDrawingIndex.unlock();
11871237

1238+
1239+
1240+
// set to default: 16384
1241+
fresult = pSystem->setStreamBufferSize(16384, FMOD_TIMEUNIT_RAWBYTES);
1242+
if (fresult)
1243+
{
1244+
pMainWindow->showMessageBox( true, std::string("AudioService::AudioService::FMOD::System::setStreamBufferSize() failed. Error: ") + std::string(FMOD_ErrorString(fresult)) );
1245+
}
1246+
1247+
11881248
bDrawing = false;
11891249
mtxDrawGraph.unlock();
11901250
}

src/Model/Track/track.cpp

Lines changed: 8 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -285,72 +285,20 @@ bool Track::playTrack(float fVolume)
285285
return false;
286286
}
287287

288-
// Is track paused?
289-
bool bPausedTrack;
290-
result = pChannel->getPaused(&bPausedTrack);
288+
289+
// Check if it's actually playing
290+
bool bIsPlaying;
291+
result = pChannel->isPlaying(&bIsPlaying);
291292
if (result)
292293
{
293-
pMainWindow->showMessageBox( true, std::string("Track::playTrack::FMOD::Channel::getPaused() failed. Error: ") + std::string(FMOD_ErrorString(result)) );
294+
pMainWindow->showMessageBox( true, std::string("Track::playTrack::FMOD::Channel::setPaused() failed. Error: ") + std::string(FMOD_ErrorString(result)) );
294295
return false;
295296
}
296297

297-
if (bPausedTrack)
298-
{
299-
// Unpause track is it's paused
300-
// 'bPaused = false' in the end of this function
301-
result = pChannel->setPaused(false);
302-
if (result)
303-
{
304-
pMainWindow->showMessageBox( true, std::string("Track::playTrack::FMOD::Channel::setPaused() failed. Error: ") + std::string(FMOD_ErrorString(result)) );
305-
return false;
306-
}
307-
}
308-
else
298+
if (bIsPlaying)
309299
{
310-
// The track is not paused, maybe it's stopped?
311-
312-
bool bIsPlaying;
313-
result = pChannel->isPlaying(&bIsPlaying);
314-
if (result)
315-
{
316-
pMainWindow->showMessageBox( true, std::string("Track::playTrack::FMOD::Channel::setPaused() failed. Error: ") + std::string(FMOD_ErrorString(result)) );
317-
return false;
318-
}
319-
320-
if (bIsPlaying)
321-
{
322-
// The track is plaing and user pressed Play so now we just need to start track from the beginning.
323-
setPositionInMS(0);
324-
pChannel->setPaused(true);
325-
}
326-
else
327-
{
328-
// The track is stopped (probably it was playing and ended).
329-
// Now every operation with 'pChannel' will return error because sound is ended.
330-
// We will recreate the track:
331-
332-
result = pChannel->stop();
333-
if (result)
334-
{
335-
pMainWindow->showMessageBox( true, std::string("Track::playTrack::FMOD::Channel::stop() failed. Error: ") + std::string(FMOD_ErrorString(result)) );
336-
return false;
337-
}
338-
339-
// And play it again.
340-
result = pSystem->playSound(pSound, nullptr, true, &pChannel);
341-
if (result)
342-
{
343-
pMainWindow->showMessageBox( true, std::string("Track::playTrack::FMOD::System::playSound() failed. Error: ") + std::string(FMOD_ErrorString(result)) );
344-
return false;
345-
}
346-
347-
result = pChannel->setVolume(fVolume);
348-
if (result)
349-
{
350-
pMainWindow->showMessageBox( true, std::string("Track::playTrack::FMOD::Channel::setVolume() failed. Error: ") + std::string(FMOD_ErrorString(result)) );
351-
return false;
352-
}
353-
}
300+
// The track is plaing and user pressed Play so now we just need to start track from the beginning.
301+
setPositionInMS(0);
354302
}
355303

356304
if ( (fSpeedByFreq == 1.0f) && (fSpeedByTime == 1.0f) )

src/globalparams.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#define MAX_CHANNELS 2000
44
#define DEFAULT_VOLUME 0.75f
5-
#define MONITOR_TRACK_INTERVAL_MS 400
5+
#define MONITOR_TRACK_INTERVAL_MS 200
66
#define MAX_TIME_ERROR_MS 50
77

88
// graph

0 commit comments

Comments
 (0)