MCPcopy Create free account
hub / github.com/Warzone2100/warzone2100 / audio_write

Function audio_write

lib/sequence/sequence.cpp:509–562  ·  view source on GitHub ↗

FIXME: perhaps we should use wz's routine for audio? loads up the audio buffers, and calculates audio sync time.

Source from the content-addressed store, hash-verified

507// FIXME: perhaps we should use wz's routine for audio?
508// loads up the audio buffers, and calculates audio sync time.
509static void audio_write(void)
510{
511 ALint processed = 0;
512 ALint queued = 0;
513
514 alGetSourcei(audiodata.source, AL_BUFFERS_PROCESSED, &processed);
515 alGetSourcei(audiodata.source, AL_BUFFERS_QUEUED, &queued);
516 if ((audiodata.totbufstarted < 2 || processed) && audiodata.audiobuf_fill > 0)
517 {
518 // we have audiobuf_fill bytes of data
519 ALuint oldbuffer = 0;
520
521 if (audiodata.totbufstarted == 0)
522 {
523 oldbuffer = audiodata.buffer1;
524 }
525 else if (audiodata.totbufstarted == 1)
526 {
527 oldbuffer = audiodata.buffer2;
528 }
529 else
530 {
531 ALint buffer_size = 0;
532 ogg_int64_t current_sample = 0;
533
534 alSourceUnqueueBuffers(audiodata.source, 1, &oldbuffer);
535 alGetBufferi(oldbuffer, AL_SIZE, &buffer_size);
536 // audio time sync
537 audioTime += (double) buffer_size / (videodata.vi.rate * videodata.vi.channels);
538 debug(LOG_VIDEO, "Audio sync");
539 current_sample = audiobuf_granulepos - audiodata.audiobuf_fill / 2 / videodata.vi.channels;
540 sampletimeOffset -= getTimeNow() - 1000 * current_sample / videodata.vi.rate;
541 }
542
543 alBufferData(oldbuffer, (videodata.vi.channels == 1 ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16),
544 audiobuf, audiodata.audiobuf_fill, static_cast<ALsizei>(videodata.vi.rate));
545
546 alSourceQueueBuffers(audiodata.source, 1, &oldbuffer);
547 audiodata.totbufstarted++;
548 if (audiodata.totbufstarted > 2)
549 {
550 audiodata.totbufstarted = 2;
551 }
552
553 if (sourcestate != AL_PLAYING)
554 {
555 debug(LOG_VIDEO, "starting source\n");
556 alSourcePlay(audiodata.source);
557 }
558
559 audiobuf_ready = false;
560 audiodata.audiobuf_fill = 0;
561 }
562}
563
564static void seq_InitOgg(void)
565{

Callers 1

seq_UpdateFunction · 0.85

Calls 1

getTimeNowFunction · 0.85

Tested by

no test coverage detected