Changeset 21221
- Timestamp:
- 05/23/07 15:40:57 (18 months ago)
- Location:
- haiku/trunk/src/kits/game
- Files:
-
- 3 modified
-
FileGameSound.cpp (modified) (5 diffs)
-
GSUtility.h (modified) (1 diff)
-
GameSoundDevice.cpp (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
haiku/trunk/src/kits/game/FileGameSound.cpp
r20682 r21221 199 199 status_t error = BStreamingGameSound::StopPlaying(); 200 200 201 if (!fAudioStream || !fAudioStream->stream) 202 return B_OK; 203 201 204 // start reading next time from the start of the file 202 205 int64 frame = 0; … … 231 234 Load(); 232 235 } 233 236 237 if (fPlayPosition + bytes > fBufferSize) 238 bytes = fBufferSize - fPlayPosition; 239 240 if (bytes == 0) 241 return; 242 234 243 if (fPausing) { 235 244 Lock(); … … 350 359 // is this is an audio file? 351 360 media_format playFormat; 352 fAudioStream->stream->EncodedFormat(&playFormat); 361 if ((error = fAudioStream->stream->EncodedFormat(&playFormat)) != B_OK) 362 return error; 363 353 364 if (!playFormat.IsAudio()) 354 365 return B_MEDIA_BAD_FORMAT; … … 395 406 396 407 if (fPlayPosition != 0) { 397 memcpy(fBuffer, fBuffer + fPlayPosition, fBufferSize - fPlayPosition); 408 if (fBufferSize > fPlayPosition) 409 memcpy(fBuffer, fBuffer + fPlayPosition, fBufferSize - fPlayPosition); 398 410 fPlayPosition = fBufferSize - fPlayPosition; 399 411 } … … 404 416 fBufferSize = fPlayPosition + frames * fFrameSize; 405 417 fPlayPosition = 0; 418 419 if (fBufferSize == 0) { 420 if (fLooping) { 421 // start reading next time from the start of the file 422 int64 frame = 0; 423 fAudioStream->stream->SeekToFrame(&frame); 424 } else { 425 StopPlaying(); 426 } 427 } 406 428 407 429 return true; -
haiku/trunk/src/kits/game/GSUtility.h
r1401 r21221 34 34 // Project Includes ------------------------------------------------------------ 35 35 #include <GameSoundDefs.h> 36 #include <MediaDefs.h> 36 37 37 38 // Local Includes -------------------------------------------------------------- -
haiku/trunk/src/kits/game/GameSoundDevice.cpp
r3854 r21221 191 191 BGameSoundDevice::ReleaseBuffer(gs_id sound) 192 192 { 193 if (sound <= 0) 194 return; 195 193 196 if (fSounds[sound-1]) 194 197 { … … 208 211 void * data) 209 212 { 210 if (!format) return B_BAD_VALUE; 213 if (!format || sound <= 0) 214 return B_BAD_VALUE; 211 215 212 216 memcpy(format, &fSounds[sound-1]->Format(), sizeof(gs_audio_format)); 213 217 214 if (fSounds[sound-1]->Data()) 215 { 218 if (fSounds[sound-1]->Data()) { 216 219 data = malloc(format->buffer_size); 217 220 memcpy(data, fSounds[sound-1]->Data(), format->buffer_size); … … 225 228 BGameSoundDevice::StartPlaying(gs_id sound) 226 229 { 227 status_t error = EALREADY;228 229 if (!fSounds[sound-1]->IsPlaying())230 {230 if (sound <= 0) 231 return B_BAD_VALUE; 232 233 if (!fSounds[sound-1]->IsPlaying()) { 231 234 // tell the producer to start playing the sound 232 error =fSounds[sound-1]->StartPlaying();233 } 234 else fSounds[sound-1]->Reset();235 236 return error;235 return fSounds[sound-1]->StartPlaying(); 236 } 237 238 fSounds[sound-1]->Reset(); 239 return EALREADY; 237 240 } 238 241 … … 241 244 BGameSoundDevice::StopPlaying(gs_id sound) 242 245 { 243 status_t error = EALREADY;244 245 if (fSounds[sound-1]->IsPlaying())246 {246 if (sound <= 0) 247 return B_BAD_VALUE; 248 249 if (fSounds[sound-1]->IsPlaying()) { 247 250 // Tell the producer to stop play this sound 248 251 fSounds[sound-1]->Reset(); 249 error =fSounds[sound-1]->StopPlaying();250 } 251 252 return error;252 return fSounds[sound-1]->StopPlaying(); 253 } 254 255 return EALREADY; 253 256 } 254 257 … … 257 260 BGameSoundDevice::IsPlaying(gs_id sound) 258 261 { 262 if (sound <= 0) 263 return false; 259 264 return fSounds[sound-1]->IsPlaying(); 260 265 }
