comparison src/dmengine.c @ 1263:4e9deb14e67f

Fix audio sync with nosound.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 22 May 2015 20:41:53 +0300
parents 2bf7cb1e662f
children 5e5f75b45f8d
comparison
equal deleted inserted replaced
1262:dc9b20d77bc9 1263:4e9deb14e67f
420 else 420 else
421 return 1; 421 return 1;
422 } 422 }
423 423
424 424
425 void enginePauseAudio(int status) 425 void enginePauseAudio(DMEngineData *engine, int status)
426 { 426 {
427 if (status) 427 if (status)
428 engine.audioStatus = SDL_AUDIO_PAUSED; 428 engine->audioStatus = SDL_AUDIO_PAUSED;
429 else 429 else
430 engine.audioStatus = SDL_AUDIO_PLAYING; 430 engine->audioStatus = SDL_AUDIO_PLAYING;
431 431
432 SDL_PauseAudio(status); 432 SDL_PauseAudio(status);
433 } 433 }
434 434
435 435
495 static int engineAudioThreadFunc(void *userdata) 495 static int engineAudioThreadFunc(void *userdata)
496 { 496 {
497 DMEngineData *engine = (DMEngineData *) userdata; 497 DMEngineData *engine = (DMEngineData *) userdata;
498 if (engine == NULL) 498 if (engine == NULL)
499 return 0; 499 return 0;
500
501 do 500 do
502 { 501 {
503 dmMutexLock(engine->audioStreamMutex); 502 dmMutexLock(engine->audioStreamMutex);
504 if (engine->audioStatus == SDL_AUDIO_PLAYING) 503 if (engine->audioStatus == SDL_AUDIO_PLAYING)
505 { 504 {
541 // Set up simulated audio thread 540 // Set up simulated audio thread
542 engine->audioSimDelay = 1000 / 45; 541 engine->audioSimDelay = 1000 / 45;
543 engine->audioSimBufSize = (engine->optAfmt.freq / 45) * engine->audioSampleSize; 542 engine->audioSimBufSize = (engine->optAfmt.freq / 45) * engine->audioSampleSize;
544 engine->audioSimBuf = dmMalloc(engine->audioSimBufSize); 543 engine->audioSimBuf = dmMalloc(engine->audioSimBufSize);
545 engine->audioSimDone = FALSE; 544 engine->audioSimDone = FALSE;
546 engine->audioSimThread = SDL_CreateThread(engineAudioThreadFunc, NULL); 545 engine->audioSimThread = SDL_CreateThread(engineAudioThreadFunc, engine);
547 if (engine->audioSimThread == NULL) 546 if (engine->audioSimThread == NULL)
548 return DMERR_INIT_FAIL; 547 return DMERR_INIT_FAIL;
549 } 548 }
550 549
551 return DMERR_OK; 550 return DMERR_OK;