# HG changeset patch # User Sam # Date 1683049292 -25200 # Node ID 596eb3a84a011c16f658db253a9d7a9ca8b5a587 # Parent 886de16ffdc49ab59a8f0beb4eb033658c14a7e2 fix: linux code use new API diff -r 886de16ffdc4 -r 596eb3a84a01 src/semicongine/audio.nim --- a/src/semicongine/audio.nim Tue May 02 10:37:26 2023 -0700 +++ b/src/semicongine/audio.nim Wed May 03 00:41:32 2023 +0700 @@ -183,7 +183,7 @@ proc audioWorker() {.thread.} = when defined(linux): - nice(-20) + discard nice(-20) onThreadDestruction(proc() = mixer[].lock.withLock(mixer[].destroy()); freeShared(mixer)) mixer[].setupDevice() while true: diff -r 886de16ffdc4 -r 596eb3a84a01 src/semicongine/platform/linux/audio.nim --- a/src/semicongine/platform/linux/audio.nim Tue May 02 10:37:26 2023 -0700 +++ b/src/semicongine/platform/linux/audio.nim Wed May 03 00:41:32 2023 +0700 @@ -41,9 +41,9 @@ type NativeSoundDevice* = object handle: snd_pcm_p - buffer: ptr SoundData + buffers: seq[ptr SoundData] -proc openSoundDevice*(sampleRate: uint32, buffer: ptr SoundData): NativeSoundDevice = +proc openSoundDevice*(sampleRate: uint32, buffers: seq[ptr SoundData]): NativeSoundDevice = var hw_params: snd_pcm_hw_params_p = nil checkAlsaResult snd_pcm_open(addr result.handle, "default", SND_PCM_STREAM_PLAYBACK, SND_PCM_BLOCK) @@ -54,13 +54,13 @@ checkAlsaResult snd_pcm_hw_params_set_format(result.handle, hw_params, SND_PCM_FORMAT_S16_LE) checkAlsaResult snd_pcm_hw_params_set_rate(result.handle, hw_params, sampleRate, 0) checkAlsaResult snd_pcm_hw_params_set_channels(result.handle, hw_params, 2) - checkAlsaResult snd_pcm_hw_params_set_buffer_size(result.handle, hw_params, snd_pcm_uframes_t(buffer[].len)) + checkAlsaResult snd_pcm_hw_params_set_buffer_size(result.handle, hw_params, snd_pcm_uframes_t(buffers[0][].len)) checkAlsaResult snd_pcm_hw_params(result.handle, hw_params) snd_pcm_hw_params_free(hw_params) - result.buffer = buffer + result.buffers = buffers -proc writeSoundData*(soundDevice: NativeSoundDevice) = - var ret = snd_pcm_writei(soundDevice.handle, addr soundDevice.buffer[][0], snd_pcm_uframes_t(soundDevice.buffer[].len)) +proc writeSoundData*(soundDevice: NativeSoundDevice, buffer: int) = + var ret = snd_pcm_writei(soundDevice.handle, addr soundDevice.buffers[buffer][][0], snd_pcm_uframes_t(soundDevice.buffers[buffer][].len)) if ret < 0: checkAlsaResult snd_pcm_recover(soundDevice.handle, cint(ret), 0)