@@ -885,7 +885,7 @@ void DMD::SerumThread()
885885
886886 while (true )
887887 {
888- if (nextRotation == 0 && sceneCurrentFrame > sceneFrameCount)
888+ if (nextRotation == 0 && sceneCurrentFrame >= sceneFrameCount)
889889 {
890890 std::shared_lock<std::shared_mutex> sl (m_dmdSharedMutex);
891891 m_dmdCV.wait (
@@ -912,11 +912,32 @@ void DMD::SerumThread()
912912 std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now ().time_since_epoch ())
913913 .count ();
914914
915- if (!m_stopFlag.load (std::memory_order_relaxed) && sceneCurrentFrame <= sceneFrameCount && nextSceneFrame <= now)
915+ if (!m_stopFlag.load (std::memory_order_relaxed) && sceneCurrentFrame < sceneFrameCount && nextSceneFrame <= now)
916916 {
917+ Update* sceneUpdate = new Update ();
918+ sceneUpdate->mode = Mode::Data;
919+ sceneUpdate->depth = 2 ;
920+ sceneUpdate->width = 128 ;
921+ sceneUpdate->height = 32 ;
922+ sceneUpdate->hasData = true ;
923+ sceneUpdate->r = 0 ;
924+ sceneUpdate->g = 0 ;
925+ sceneUpdate->b = 0 ;
926+ if (generator.generateFrame (prevTriggerId, sceneCurrentFrame++, sceneUpdate->data ))
927+ {
928+ uint32_t result = Serum_Colorize (sceneUpdate->data );
929+
930+ if (result != IDENTIFY_NO_FRAME)
931+ {
932+ QueueSerumFrames (sceneUpdate);
933+ }
934+ }
935+ nextSceneFrame = nextSceneFrame + sceneDurationPerFrame;
936+ delete sceneUpdate;
937+
938+ // If the scene is finished.
917939 if (sceneCurrentFrame >= sceneFrameCount)
918940 {
919- // The scene is finished.
920941 if (sceneRepeatCount > 1 )
921942 {
922943 sceneCurrentFrame = 0 ;
@@ -942,34 +963,17 @@ void DMD::SerumThread()
942963 if (m_pSerum->width32 > 0 ) memset (m_pSerum->frame32 , 0 , m_pSerum->width32 * 32 * sizeof (uint16_t ));
943964 if (m_pSerum->width64 > 0 ) memset (m_pSerum->frame64 , 0 , m_pSerum->width64 * 64 * sizeof (uint16_t ));
944965 }
966+ while (std::chrono::duration_cast<std::chrono::milliseconds>(
967+ std::chrono::system_clock::now ().time_since_epoch ())
968+ .count () < nextSceneFrame)
969+ {
970+ std::this_thread::sleep_for (std::chrono::milliseconds (1 ));
971+ }
945972 QueueSerumFrames (lastDmdUpdate);
946973 }
947974 }
948975 }
949976 }
950- else
951- {
952- Update* sceneUpdate = new Update ();
953- sceneUpdate->mode = Mode::Data;
954- sceneUpdate->depth = 2 ;
955- sceneUpdate->width = 128 ;
956- sceneUpdate->height = 32 ;
957- sceneUpdate->hasData = true ;
958- sceneUpdate->r = 0 ;
959- sceneUpdate->g = 0 ;
960- sceneUpdate->b = 0 ;
961- if (generator.generateFrame (prevTriggerId, sceneCurrentFrame++, sceneUpdate->data ))
962- {
963- uint32_t result = Serum_Colorize (sceneUpdate->data );
964-
965- if (result != IDENTIFY_NO_FRAME)
966- {
967- QueueSerumFrames (sceneUpdate);
968- }
969- }
970- nextSceneFrame = nextSceneFrame + sceneDurationPerFrame;
971- delete sceneUpdate;
972- }
973977 }
974978
975979 const uint8_t updateBufferQueuePosition = m_updateBufferQueuePosition.load (std::memory_order_acquire);
0 commit comments