|  |  | @ -15,7 +15,6 @@ | 
			
		
	
		
		
			
				
					
					|  |  |  | struct SLSound::Player { |  |  |  | struct SLSound::Player { | 
			
		
	
		
		
			
				
					
					|  |  |  |   SLObjectItf player; |  |  |  |   SLObjectItf player; | 
			
		
	
		
		
			
				
					
					|  |  |  |   SLPlayItf playItf; |  |  |  |   SLPlayItf playItf; | 
			
		
	
		
		
			
				
					
					|  |  |  |   // slplay_callback runs on a background thread,use atomic to ensure thread safe.
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |   std::atomic<int> repeat; |  |  |  |   std::atomic<int> repeat; | 
			
		
	
		
		
			
				
					
					|  |  |  | }; |  |  |  | }; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  |  | @ -57,8 +56,8 @@ bool SLSound::init() { | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | void SLAPIENTRY slplay_callback(SLPlayItf playItf, void *context, SLuint32 event) { |  |  |  | void SLAPIENTRY slplay_callback(SLPlayItf playItf, void *context, SLuint32 event) { | 
			
		
	
		
		
			
				
					
					|  |  |  |   SLSound::Player *s = reinterpret_cast<SLSound::Player *>(context); |  |  |  |   SLSound::Player *s = reinterpret_cast<SLSound::Player *>(context); | 
			
		
	
		
		
			
				
					
					|  |  |  |   if (event == SL_PLAYEVENT_HEADATEND && s->repeat > 1) { |  |  |  |   if (event == SL_PLAYEVENT_HEADATEND && s->repeat != 0) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     --s->repeat; |  |  |  |     if (s->repeat > 0) --s->repeat; | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_STOPPED); |  |  |  |     (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_STOPPED); | 
			
		
	
		
		
			
				
					
					|  |  |  |     (*playItf)->SetMarkerPosition(playItf, 0); |  |  |  |     (*playItf)->SetMarkerPosition(playItf, 0); | 
			
		
	
		
		
			
				
					
					|  |  |  |     (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_PLAYING); |  |  |  |     (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_PLAYING); | 
			
		
	
	
		
		
			
				
					|  |  | @ -69,10 +68,13 @@ bool SLSound::play(AudibleAlert alert) { | 
			
		
	
		
		
			
				
					
					|  |  |  |   if (currentSound_ != AudibleAlert::NONE) { |  |  |  |   if (currentSound_ != AudibleAlert::NONE) { | 
			
		
	
		
		
			
				
					
					|  |  |  |     stop(); |  |  |  |     stop(); | 
			
		
	
		
		
			
				
					
					|  |  |  |   } |  |  |  |   } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   auto player = player_.at(alert); |  |  |  |   auto player = player_.at(alert); | 
			
		
	
		
		
			
				
					
					|  |  |  |   SLPlayItf playItf = player->playItf; |  |  |  |   SLPlayItf playItf = player->playItf; | 
			
		
	
		
		
			
				
					
					|  |  |  |   player->repeat = sound_map[alert].second; |  |  |  | 
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |   if (player->repeat > 0) { |  |  |  |   int loops = sound_map[alert].second; | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   player->repeat = loops > 0 ? loops - 1 : loops; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   if (player->repeat != 0) { | 
			
		
	
		
		
			
				
					
					|  |  |  |     ReturnOnError((*playItf)->RegisterCallback(playItf, slplay_callback, player), "Failed to register callback"); |  |  |  |     ReturnOnError((*playItf)->RegisterCallback(playItf, slplay_callback, player), "Failed to register callback"); | 
			
		
	
		
		
			
				
					
					|  |  |  |     ReturnOnError((*playItf)->SetCallbackEventsMask(playItf, SL_PLAYEVENT_HEADATEND), "Failed to set callback event mask"); |  |  |  |     ReturnOnError((*playItf)->SetCallbackEventsMask(playItf, SL_PLAYEVENT_HEADATEND), "Failed to set callback event mask"); | 
			
		
	
		
		
			
				
					
					|  |  |  |   } |  |  |  |   } | 
			
		
	
	
		
		
			
				
					|  |  | 
 |