Skip to content

Commit

Permalink
YsSoundPlayer::StreamPlayerReadyToAcceptNextSegment returns error if …
Browse files Browse the repository at this point in the history
…the given segment is longer than the half of the requested ring-buffer length.
  • Loading branch information
captainys committed Nov 9, 2023
1 parent 93e8b49 commit b10faa9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/yssimplesound/src/yssimplesound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ void YsSoundPlayer::PlayBackground(SoundData &dat)

YSRESULT YsSoundPlayer::StartStreaming(Stream &streamPlayer,StreamingOption opt)
{
streamPlayer.requestedRingBufferLengthMillisec=opt.ringBufferLengthMillisec;
return StartStreamingAPISpecific(streamPlayer,opt);
}

Expand All @@ -197,6 +198,18 @@ YSBOOL YsSoundPlayer::StreamPlayerReadyToAcceptNextSegment(const Stream &streamP
{
return YSFALSE;
}

uint32_t millisec=dat.GetNumSamplePerChannel()*1000/dat.PlayBackRate();
if(streamPlayer.requestedRingBufferLengthMillisec<millisec*2)
{
// This output is added because one of my MMLPlayer sample was trying to send 1000 millisec at a time.
// It was fine in Linux and macOSX since the implementation was using double-buffering.
// It caused some trouble in Windows since the implementation was really using a ring-buffer.
printf("Number of Samples given to the stream player (%u) must be less than or equal\n",millisec);
printf("to the half of the requested ring-buffer size (%u)\n",streamPlayer.requestedRingBufferLengthMillisec);
return YSFALSE;
}

return StreamPlayerReadyToAcceptNextNumSample(streamPlayer,dat.GetNumSamplePerChannel());
}

Expand Down
1 change: 1 addition & 0 deletions src/yssimplesound/src/yssimplesound.h
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ friend class YsSoundPlayer;

class APISpecificData;

uint32_t requestedRingBufferLengthMillisec=0;
APISpecificData *api=nullptr;

// Written in API-specific code
Expand Down

0 comments on commit b10faa9

Please sign in to comment.