|
| 1 | +# Porting Guide |
| 2 | + |
| 3 | +## Status of Ports |
| 4 | +The status of ports is kept in the main module [README](README.md). |
| 5 | + |
| 6 | +## Overview |
| 7 | +ZikiChombo sio code has a porting process that is unconventional due to the |
| 8 | +nature of sound support on host systems. Usually, to port a system, one takes some |
| 9 | +desired cross-host functionality, such as a filesystem, and implements it with |
| 10 | +the OS or OS/hardware combination of interest and that's that (to make a long |
| 11 | +story short). |
| 12 | + |
| 13 | +For sound, the problem is that hosts usually have multiple different software |
| 14 | +components as entry points to playing and capturing sound, and moreover these |
| 15 | +entry points have some mutually exclusive properties, such as lower bounds on |
| 16 | +latency, availability of duplex synchronised by hardware audio clock, ability |
| 17 | +to be shared accross many users or applications, etc. |
| 18 | + |
| 19 | +Although the main CPU hardware architectures can certainly be a concern, it has |
| 20 | +not been so far in our experience. So we focus on organizing around host, |
| 21 | +which is taken to be the value of runtime.GOOS in a Go program. |
| 22 | + |
| 23 | +# Hosts |
| 24 | +A host often has a hardware abstraction layer, hardware drivers, and some |
| 25 | +levels of interacting with these layers to coordinate and make secure demands |
| 26 | +related to playing and capturing sound on a device. |
| 27 | + |
| 28 | +To simplify the end use case, we want to make all this transparent to the |
| 29 | +consumer of sio, and let them simply work with sound.{Source,Sink,Duplex}. |
| 30 | + |
| 31 | +For each Host, ZikiChombo defines a default entry point to accomplish this. |
| 32 | + |
| 33 | +All entry points are available both to the consumer of ZikiChombo and either |
| 34 | +with ZikiChombo or as 3rd party implementations. So if you're working with |
| 35 | +VoIP and have precise duplex echo cancellation needs, or a music app that |
| 36 | +listens and plays in real time with feedback, or writing a PulseAudio |
| 37 | +replacement, you're more likely to be interested in using a specialized entry |
| 38 | +point than the default. |
| 39 | + |
| 40 | +There is a directory ZikiChombo/sio/ports/{runtime.GOOS} for each host. |
| 41 | + |
| 42 | +# Entry Points |
| 43 | +An entry point defines a subset of the functionality listed in the main |
| 44 | +[README](README.md). ZikiChombo defines for each host (runtime.GOOS) a list of |
| 45 | +entry points which refer to the software layer with which the go program will |
| 46 | +communicate. These are named after the respective entry points in the main |
| 47 | +[README](README.md). |
| 48 | + |
| 49 | +Each entry point defines a base set of functionality related to what the entry |
| 50 | +point supports: device scanning, device change notifications, playback, |
| 51 | +capture, duplex. Note the README excludes some functionality from some |
| 52 | +entry points and entry points may be incomplete. |
| 53 | + |
| 54 | +The functionality is slightly more rich than implementing |
| 55 | +sio.{Capture,Play,Player,Duplex} to allow callers to achieve latency or other |
| 56 | +requirements. Package sio automatically uses the Entry point to apply defaults |
| 57 | +so that the caller may simply call sio.{Play,Player,Capture,Duplex}. Package |
| 58 | +sio also enforces that only one entry point may be in use at a time in one Go |
| 59 | +program. |
| 60 | + |
| 61 | +Entry points can then be registered by a package implementing them in |
| 62 | +their init() function. Consumers of ZikiChombo may optionaly control which |
| 63 | +package implements a given entry point. The default is chosen by |
| 64 | +package initialisation order. |
| 65 | + |
| 66 | +See [host](http://godoc.org/zikichombo.org/sio/host) for details. |
| 67 | + |
| 68 | +The list of entry names for each host is defined in host/entry_{host}.go |
| 69 | +under the function host.Names(). |
| 70 | + |
| 71 | + |
| 72 | +# Supporting concepts Devices, Inputs, Outputs, Duplex, Packets |
| 73 | +To implement an Entry Point, ZikiChombo provides some support code in |
| 74 | +[libsio](http://godoc.org/zikichombo.org/sio/libsio). The only required part |
| 75 | +of this code to reference is libsio/Dev to implement an Entry. |
| 76 | + |
| 77 | +Other parts of this code, libsio.{Input,Output,Duplex,Packet,DuplexPacket} |
| 78 | +provide interfaces for synchronising with the host via Go channels and |
| 79 | +implementations to adapt these structures to sound.{Source,Sink,Duplex}. |
| 80 | + |
| 81 | +## Import directions |
| 82 | +Package zikichombo.org/sio imports the package implementing entry points |
| 83 | +for registration side effects |
| 84 | + |
| 85 | +``` |
| 86 | +import _ "zikichombo.org/sio/ports/{runtime.GOOS}" |
| 87 | +``` |
| 88 | + |
| 89 | +Packages implementing the entries should import "zikichombo.org/sio/host" and |
| 90 | +call |
| 91 | +``` |
| 92 | +host.RegisterEntry(mySuperReliableEntry) |
| 93 | +``` |
| 94 | + |
| 95 | +These packages may also import zikichombo.org/libsio. |
| 96 | + |
| 97 | + |
| 98 | + |
| 99 | +# Duplex |
| 100 | + |
| 101 | +Duplex support is intended for synchronized input/output. Systems which simply |
| 102 | +buffer underlying independent I+O and loosely synchronize with the slack that |
| 103 | +results from the buffering should consider not implementing Duplex and just |
| 104 | +letting the caller use sound.{Source,Sink} synchronously. Ideally, duplex |
| 105 | +should be audio hardware clock synchronized as in Apple's Aggregate devices. |
| 106 | +Duplexing I+O ringbuffers which are independently clocked to the same sample |
| 107 | +rate are acceptable but less reliable especially for long sessions. PortAudio |
| 108 | +actually supports duplex connections which have different sample rates. We |
| 109 | +recommend that this not be done to preserve the reliability of latency in |
| 110 | +Duplex implementations. |
| 111 | + |
| 112 | +# Build tags |
| 113 | + |
| 114 | +Submitted ports and tests which produce or capture sound should use the build |
| 115 | +tag "listen" so that they do not run by default but are easily invokable with |
| 116 | + |
| 117 | +``` |
| 118 | +go test zikichombo.org/sio/... -tags listen |
| 119 | +``` |
| 120 | + |
| 121 | + |
| 122 | +# 3rd Party Ports |
| 123 | +To have an independently distributed port listed here, please file an issue. |
| 124 | +We only list the most recent zc version/port version pairs here. |
| 125 | + |
| 126 | +| Port | zc version | Port version | |
| 127 | +-------|------------|--------------| |
| 128 | +| - | v0.0.1-alpha.2 | vX.Y.Z | |
| 129 | + |
| 130 | + |
| 131 | +# References |
| 132 | +The following may be useful references for those considering sio ports. |
| 133 | +* [Plan9 Audio](http://man.cat-v.org/plan_9/3/audio) |
| 134 | +* [PortAudio](http://portaudio.com) |
| 135 | +* [FreeBSD](https://www.freebsd.org/doc/handbook/sound-setup.html) |
| 136 | +* [ALSA](https://www.alsa-project.org/main/index.php/Main_Page) |
| 137 | +* [RtAudio](http://www.music.mcgill.ca/~gary/rtaudio/) |
| 138 | +* [Web Audio](https://www.w3.org/TR/webaudio/) |
| 139 | +* [Audio Units](https://developer.apple.com/documentation/audiounit?language=objc) |
| 140 | +* [VST](https://www.steinberg.net/en/company/technologies/vst3.html) |
| 141 | +* [Pulse Audio](https://en.wikipedia.org/wiki/PulseAudio) |
| 142 | +* [Android Audio](https://source.android.com/devices/audio/terminology) |
| 143 | +* [AudioFlinger](https://android.googlesource.com/platform/frameworks/av/+/109347d421413303eb1678dd9e2aa9d40acf89d2/services/audioflinger/AudioFlinger.cpp) |
| 144 | + |
0 commit comments