Skip to content

Commit

Permalink
Mostly fix non deterministic timer
Browse files Browse the repository at this point in the history
  • Loading branch information
clementgallet committed Apr 16, 2016
1 parent fc18baa commit dfb24f8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
5 changes: 3 additions & 2 deletions src/libTAS/NonDeterministicTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ struct timespec NonDeterministicTimer::getTicks(void)
* do not count the normal frame boundary duration,
* as it would delay more and more the timer
*/
if(frameBoundaryDur.tv_sec > 0 || frameBoundaryDur.tv_nsec > 50000000)
if(frameBoundaryDur.tv_sec > 0 || ((frameBoundaryDur.tv_sec >= 0) && (frameBoundaryDur.tv_nsec > 50000000)))
{
/* Remove the duration of the frame boundary from the elapsed time */
delta -= frameBoundaryDur;
Expand All @@ -89,7 +89,8 @@ void NonDeterministicTimer::enterFrameBoundary()
/* Doing the audio mixing here */
getTicks();
TimeHolder elapsedTicks = ticks - lastEnterTicks;
//audiocontext.mixAllSources(*(struct timespec*)&elapsedTicks);
audiocontext.mixAllSources(*(struct timespec*)&elapsedTicks);

lastEnterTicks = ticks;
}

Expand Down
14 changes: 10 additions & 4 deletions src/libTAS/audio/AudioContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,17 @@ void AudioContext::mixAllSources(struct timespec ticks)
{
//std::lock_guard<std::mutex> lock(mutex);

/* Check that ticks is positive! */
if (ticks.tv_sec < 0) {
debuglog(LCF_SOUND | LCF_FRAME | LCF_ERROR, "Negative number of ticks for audio mixing!");
return;
}

outBytes = ticksToBytes(ticks, outAlignSize, outFrequency);
debuglog(LCF_SOUND | LCF_FRAME, "Start mixing about ", outBytes, " of buffers");
/* Save the actual number of samples and size */
outNbSamples = outBytes / outAlignSize;

debuglog(LCF_SOUND | LCF_FRAME, "Start mixing about ", outNbSamples, " samples");

/* Silent the output buffer */
if (outBitDepth == 8) // Unsigned 8-bit samples
Expand All @@ -181,9 +190,6 @@ void AudioContext::mixAllSources(struct timespec ticks)
source->mixWith(ticks, &outSamples[0], outBytes, outBitDepth, outNbChannels, outFrequency, outVolume);
}

/* Save the actual number of samples and size */
outNbSamples = outBytes / outAlignSize;

#ifdef LIBTAS_ENABLE_SOUNDPLAYBACK
/* Play the music */
audioplayer.play(*this);
Expand Down
11 changes: 5 additions & 6 deletions src/libTAS/audio/AudioPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,11 @@ bool AudioPlayer::init(snd_pcm_format_t format, int nbChannels, unsigned int fre
return false;
}

if (tasflags.framerate != 0) {
snd_pcm_uframes_t buffer_size = frequency / tasflags.framerate;
if (snd_pcm_hw_params_set_buffer_size_near(phandle, hw_params, &buffer_size) < 0) {
debuglog(LCF_SOUND | LCF_ERROR, " snd_pcm_hw_params_set_rate_near failed");
return false;
}
snd_pcm_uframes_t buffer_size = 2 * frequency / ((tasflags.framerate>0)?tasflags.framerate:30);
debuglog(LCF_SOUND, " Buffer size is ", buffer_size);
if (snd_pcm_hw_params_set_buffer_size_near(phandle, hw_params, &buffer_size) < 0) {
debuglog(LCF_SOUND | LCF_ERROR, " snd_pcm_hw_params_set_rate_near failed");
return false;
}

if (snd_pcm_hw_params_set_channels(phandle, hw_params, nbChannels) < 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/shared/tasflags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ struct TasFlags tasflags = {
recording : -1,
fastforward : 0,
//includeFlags : LCF_FRAME,
includeFlags : LCF_DUMP,
includeFlags : LCF_SOUND,
excludeFlags : LCF_NONE,
av_dumping : 0,
framerate : 60,
framerate : 0,
numControllers : 1
};

0 comments on commit dfb24f8

Please sign in to comment.