MCPcopy Create free account
hub / github.com/danoon2/Boxedwine / writeAudio

Method writeAudio

platform/sdl/kdspaudio.cpp:287–319  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

285}
286
287U32 KDspAudioSdl::writeAudio(U8* data, U32 len) {
288 U32 bytesPerSecond = want.freq * want.channels * bytesPerSampleWant();
289 U32 delay = bytesPerSecond / 8;
290
291 if (!KSystem::soundEnabled) {
292 static U32 timeSinceLastWrite;
293
294 U32 elapsedTime = KSystem::getMilliesSinceStart() - timeSinceLastWrite;
295 U32 bytesToRemove = bytesPerSecond * elapsedTime / 1000;
296
297 bytesToRemove = std::min((U32)this->audioBuffer.size(), bytesToRemove);
298 this->audioBuffer.erase(this->audioBuffer.begin(), this->audioBuffer.begin() + bytesToRemove);
299
300 if (this->audioBuffer.size() > delay) {
301 return -K_EWOULDBLOCK;
302 }
303 U32 blockSize = bytesPerSampleWant() * want.channels;
304 len = std::min(len, ((delay - (U32)this->audioBuffer.size()) & ~(blockSize - 1)));
305 audioBuffer.insert(this->audioBuffer.end(), data, data + len);
306 timeSinceLastWrite = KSystem::getMilliesSinceStart();
307 return len;
308 }
309 SDL_LockAudio();
310 if (this->audioBuffer.size() > delay) {
311 SDL_UnlockAudio();
312 return -K_EWOULDBLOCK;
313 }
314 U32 blockSize = bytesPerSampleWant() * want.channels;
315 len = std::min(len, ((delay - (U32)this->audioBuffer.size()) & ~(blockSize - 1)));
316 audioBuffer.insert(this->audioBuffer.end(), data, data + len);
317 SDL_UnlockAudio();
318 return len;
319}
320
321static U32 nextId = 0;
322BOXEDWINE_MUTEX KDspAudio::mutex;

Callers 1

writeNativeMethod · 0.80

Calls 8

minFunction · 0.85
SDL_LockAudioFunction · 0.85
SDL_UnlockAudioFunction · 0.85
sizeMethod · 0.45
eraseMethod · 0.45
beginMethod · 0.45
insertMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected