Pārlūkot izejas kodu

Apply suggestions from code review

Co-authored-by: Ivan Savenko <[email protected]>
Laserlicht 1 gadu atpakaļ
vecāks
revīzija
c426382687
2 mainītis faili ar 4 papildinājumiem un 4 dzēšanām
  1. 3 3
      client/CMusicHandler.cpp
  2. 1 1
      client/CMusicHandler.h

+ 3 - 3
client/CMusicHandler.cpp

@@ -193,7 +193,7 @@ double CSoundHandler::getSoundDuration(const AudioPath & sound)
 	SDL_AudioSpec spec;
 	uint32_t audioLen;
 	uint8_t *audioBuf;
-	double seconds = 0.0;
+	uint32_t miliseconds = 0;
 
 	if(SDL_LoadWAV_RW(SDL_RWFromMem(data.first.get(), (int)data.second), 1, &spec, &audioBuf, &audioLen) != nullptr)
 	{
@@ -201,10 +201,10 @@ double CSoundHandler::getSoundDuration(const AudioPath & sound)
 		uint32_t sampleSize = SDL_AUDIO_BITSIZE(spec.format) / 8;
 		uint32_t sampleCount = audioLen / sampleSize;
 		uint32_t sampleLen = sampleCount / spec.channels;
-		seconds = (double)sampleLen / (double)spec.freq;
+		miliseconds = 1000 * sampleLen / spec.freq;
 	}
 
-	return seconds;
+	return miliseconds ;
 }
 
 // Plays a sound, and return its channel so we can fade it out later

+ 1 - 1
client/CMusicHandler.h

@@ -77,7 +77,7 @@ public:
 	void setChannelVolume(int channel, ui32 percent);
 
 	// Sounds
-	double getSoundDuration(const AudioPath & sound);
+	uint32_t getSoundDurationMilliseconds(const AudioPath & sound);
 	int playSound(soundBase::soundID soundID, int repeats=0);
 	int playSound(const AudioPath & sound, int repeats=0, bool cache=false);
 	int playSound(std::pair<std::unique_ptr<ui8 []>, si64> & data, int repeats=0, bool cache=false);