Mercurial > games > semicongine
comparison semiconginev2/audio/mixer.nim @ 1234:841e12f33c47
add: text & font rendering, not tested yet
author | sam <sam@basx.dev> |
---|---|
date | Sat, 20 Jul 2024 00:03:57 +0700 |
parents | a3fa15c25026 |
children |
comparison
equal
deleted
inserted
replaced
1233:1cf698973dca | 1234:841e12f33c47 |
---|---|
1 | |
2 const NBUFFERS = 32 | 1 const NBUFFERS = 32 |
3 const BUFFERSAMPLECOUNT = 256 | 2 const BUFFERSAMPLECOUNT = 256 |
4 const AUDIO_SAMPLE_RATE* = 44100 | 3 const AUDIO_SAMPLE_RATE* = 44100 |
5 | 4 |
6 type | 5 type |
196 clip(int32(a[1]) + int32(b[1])), | 195 clip(int32(a[1]) + int32(b[1])), |
197 ] | 196 ] |
198 | 197 |
199 proc updateSoundBuffer(mixer: var Mixer) = | 198 proc updateSoundBuffer(mixer: var Mixer) = |
200 let t = getMonoTime() | 199 let t = getMonoTime() |
201 | |
202 let tDebug = getTime() | |
203 # echo "" | |
204 # echo tDebug | |
205 | 200 |
206 let dt = (t - mixer.lastUpdate).inNanoseconds.float64 / 1_000_000_000'f64 | 201 let dt = (t - mixer.lastUpdate).inNanoseconds.float64 / 1_000_000_000'f64 |
207 mixer.lastUpdate = t | 202 mixer.lastUpdate = t |
208 | 203 |
209 # update fadings | 204 # update fadings |
236 stoppedSounds.add id | 231 stoppedSounds.add id |
237 for id in stoppedSounds: | 232 for id in stoppedSounds: |
238 track.playing.del(id) | 233 track.playing.del(id) |
239 mixer.buffers[mixer.currentBuffer][i] = mixedSample | 234 mixer.buffers[mixer.currentBuffer][i] = mixedSample |
240 # send data to sound device | 235 # send data to sound device |
241 # echo getTime() - tDebug | |
242 mixer.device.WriteSoundData(mixer.currentBuffer) | 236 mixer.device.WriteSoundData(mixer.currentBuffer) |
243 # echo getTime() - tDebug | |
244 mixer.currentBuffer = (mixer.currentBuffer + 1) mod mixer.buffers.len | 237 mixer.currentBuffer = (mixer.currentBuffer + 1) mod mixer.buffers.len |
245 | 238 |
246 # DSP functions | 239 # DSP functions |
247 # TODO: finish implementation, one day | 240 # TODO: finish implementation, one day |
248 | 241 |