Repository navigation
GraphiteSound: channels, queued commands and the mixer - #26
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The second part of
GraphiteSound: the channels that play sounds and the mixer that renders them. Part one (#25) was the sounds and their codecs.SoundCommand: a typed enum of the commands a channel takes (null, quiet, flush, reInit, wait, pause and resume, callBack, sync, buffer, amplitude, volume, frequency, rate and rateMultiplier), withSoundCommand(code:param1:param2:)for the command words that carry no sound.SoundInitandSoundSynthare the init bits and synthesizers.SoundChannel(SndNewChannel,SndDoCommand,SndDoImmediate,SndChannelStatus,SndDisposeChannel) andSoundMixer:waitCmdholds it for its time (exact to the frame), andcallBackCmdcalls the channel's callback with the channel and the command, after the mixer's lock is released, so a callback can send more commands.syncCmdholds a channel until the named number of channels reach a sync of the same identifier; they then go on together, at the next 64-frame boundary.queueFull.volumeCmd,ampCmd, with the gain capped at 2.5), pitch from a MIDI note or a rate, linear interpolation (off withinitNoInterp), sustain loops, and a completion closure for a sound that plays to its end.play(_:completion:)forSndStartFilePlayandSndPlay.GetDefaultOutputVolumeandSetDefaultOutputVolumeas a word a side).AudioOutputis the protocol a host implements, andSoundMixer(output:)plays through it.SampledSoundisHashable. The README and the package header describe the channels and mixer.Notes for review
ChannelState.swiftandSoundMixer.swiftare adapted from rxi's cmixer through Pomme; both carry the two MIT notices. The queue, waits, callbacks and syncs are new: Pomme runs every command at once, and itsSndDoCommanddoes nothing.try mixer.newChannel().play(sound)is natural Swift.)SndPlayDoubleBuffer), waiting for room in a full queue (doCommandthrowsqueueFull),initChanLeftandinitChanRight, and an SDL3 device (that is phase 5'sGraphiteCacao).ChannelState,SoundMixerandSoundChannelrefer to one another, so7d002b1andfb278acneed the one after them (08eafe8).Testing
queueFull, sounds that can't be played, the command-word mapping, a device, and commands from other threads during rendering.swift test --sanitize=thread.FreeTypetrait, and built the project and its tests in Xcode. Linux and the 32-bit targets are left to CI.