# HG changeset patch # User Sam # Date 1683049292 -25200 # Node ID 6faef9195f3af6a77fa78c27c49d1e203609eae9 # Parent fc85ed0abfcff9e21bf22bfc6135cb10a24c35e7 fix: linux code use new API diff -r fc85ed0abfcf -r 6faef9195f3a 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 fc85ed0abfcf -r 6faef9195f3a 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)