Skip to content

Commit

Permalink
potential fix for #33
Browse files Browse the repository at this point in the history
  • Loading branch information
derselbst committed Aug 22, 2016
1 parent 66bb70e commit db4ddb8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
42 changes: 27 additions & 15 deletions src/PlayerLogic/Player.cpp
Expand Up @@ -394,6 +394,11 @@ void Player::resetPlayhead ()
this->_seekTo(0);
}

/**
* within a given loop "l": get that loop that starts just right after playhead
*
* @return a subloop of "l"
*/
core::tree<loop_t>* Player::getNextLoop(core::tree<loop_t>& l)
{
loop_t compareLoop;
Expand All @@ -414,7 +419,11 @@ core::tree<loop_t>* Player::getNextLoop(core::tree<loop_t>& l)
}



/**
* THAT method which recursively walks through a loop tree, playing all the loops, subloops and subsubsubloops given by "loop" recursively
*
* @note this method might be called recursively :P
*/
void Player::playLoop (core::tree<loop_t>& loop)
{
USERS_ARE_STUPID
Expand All @@ -435,7 +444,7 @@ void Player::playLoop (core::tree<loop_t>& loop)
continue;
}

this->playFrames(playhead, (*(*subloop)).start);
this->playFrames((*loop).start, (*(*subloop)).start);
// at this point: playhead==subloop.start

uint32_t mycount = Config::overridingGlobalLoopCount!=-1 ? Config::overridingGlobalLoopCount : (*(*subloop)).count;
Expand All @@ -454,27 +463,24 @@ void Player::playLoop (core::tree<loop_t>& loop)
}

// play rest of file
this->playFrames(playhead, (*loop).stop);
this->playFrames((*loop).start, (*loop).stop);
}


/**
* make sure you called seekTo(startFrame) before calling this!
* @param startFrame intended: the frame with which we want to start the playback
* actually: does nothing, just for debug purposes, the actual start is determined
* by playhead
* @param stopFrame play until we've reached stopFrame, although this frame will
* not be played
* plays a loop with the bounds specified by startFrame and stopFrame.
* starts playing at whereever playhead stands.
* returns as soon as playhead leaves the bounds, i.e. exceeding stopFrame or underceeding startFrame.
*
* @param startFrame zero-based array index == the lower bound this->playhead shall be in
* @param stopFrame zero-based array index == the upper bound this->playhead shall be in, i.e. play until we've reached stopFrame, although the frame at "stopFrame" will not be played.
*
* @todo really ensure and test that this last frame is not being played
*/
void Player::playFrames (frame_t startFrame, frame_t stopFrame)
{
USERS_ARE_STUPID

if(startFrame!=this->playhead)
{
cout << "Oops: Expected Playhead to be equal " << startFrame << ", but playhead is " << this->playhead << endl;
}

// the user may request to seek while we are playing, thus check whether playhead is
// still in range
while(this->isPlaying && this->playhead>=startFrame && this->playhead<stopFrame)
Expand All @@ -498,7 +504,13 @@ void Player::playFrames (frame_t startFrame, frame_t stopFrame)
}
}


/**
* play "framesToPlay" frames from the current position (indicated by this->playhead)
*
* it ought to start playing that frame, which is currently pointed to by this->playhead
*
* @param framesToPlay no. of frames to play from the current position
*/
void Player::playFrames (frame_t framesToPlay)
{
USERS_ARE_STUPID
Expand Down
2 changes: 1 addition & 1 deletion src/PlayerLogic/Player.h
Expand Up @@ -98,7 +98,7 @@ class Player
// we dont own this playlist, we dont care about destruction
IPlaylist* playlist = nullptr;

// frame offset; (song.pcm + playhead*song.channels) points to the frame(s) that will be played on subsequent call to playSample
// frame offset; (currentSong.data + playhead*currentSong.Format.Channels) points to the frame(s) that will be played on subsequent call to playFrames(frame_t)
frame_t playhead = 0;

// pointer to the audioDriver, we currently use
Expand Down

0 comments on commit db4ddb8

Please sign in to comment.