Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ jobs:
env GOOS=darwin GOARCH=amd64 go build -v ./...
env GOOS=darwin GOARCH=arm64 go build -v ./...

# Check cross-compiling Linux binaries.
Comment thread
hajimehoshi marked this conversation as resolved.
env GOOS=linux GOARCH=amd64 go build -v ./...
env GOOS=linux GOARCH=arm64 go build -v ./...
- name: go mod vendor
run: |
mkdir /tmp/vendoring
Expand Down
41 changes: 14 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ A low-level library to play sound.
- [Prerequisite](#prerequisite)
- [macOS](#macos)
- [iOS](#ios)
- [Linux](#linux)
- [FreeBSD, OpenBSD](#freebsd-openbsd)
- [Linux, FreeBSD, OpenBSD](#linux-freebsd-openbsd)
- [Usage](#usage)
- [Playing sounds from memory](#playing-sounds-from-memory)
- [Playing sounds by file streaming](#playing-sounds-by-file-streaming)
Expand All @@ -20,14 +19,14 @@ A low-level library to play sound.

## Platforms

- Windows (no Cgo required!)
- macOS (no Cgo required!)
- Linux
- FreeBSD
- OpenBSD
- Windows (no Cgo required)
- macOS (no Cgo required)
- Linux (no Cgo required)
- FreeBSD (no Cgo required)
- OpenBSD (no Cgo required)
- Android
- iOS
- WebAssembly
- WebAssembly (no Cgo required)
- Nintendo Switch
- Xbox

Expand All @@ -37,7 +36,7 @@ On some platforms you will need a C/C++ compiler in your path that Go can use.

- iOS: On newer macOS versions type `clang` on your terminal and a dialog with installation instructions will appear if you don't have it
- If you get an error with clang use xcode instead `xcode-select --install`
- Linux and other Unix systems: Should be installed by default, but if not try [GCC](https://gcc.gnu.org/) or [Clang](https://releases.llvm.org/download.html)
- Console targets may still need a working C/C++ toolchain; if not installed, try [GCC](https://gcc.gnu.org/) or [Clang](https://releases.llvm.org/download.html)

### macOS

Expand All @@ -52,25 +51,12 @@ Oto requires these frameworks:

Add them to "Linked Frameworks and Libraries" on your Xcode project.

### Linux
### Linux, FreeBSD, OpenBSD

ALSA is required. On Ubuntu or Debian, run this command:
Oto uses PulseAudio on Linux and BSD systems via the pure-Go package `github.com/jfreymuth/pulse`,
though BSD systems are not tested well.

```sh
apt install libasound2-dev
```

On RedHat-based linux distributions, run:

```sh
dnf install alsa-lib-devel
```

In most cases this command must be run by root user or through `sudo` command.

### FreeBSD, OpenBSD

BSD systems are not tested well. If ALSA works, Oto should work.
If the PulseAudio server is not discoverable automatically, set `PULSE_SERVER`.

## Usage

Expand Down Expand Up @@ -222,7 +208,8 @@ This works because players implement a `Player` interface and a `BufferSizeSette

## Crosscompiling

Crosscompiling to macOS or Windows is as easy as setting `GOOS=darwin` or `GOOS=windows`, respectively.
Crosscompiling to macOS, Windows, Linux or BSD is as easy as setting `GOOS=darwin`, `GOOS=windows`,
`GOOS=linux` or `GOOS=freebsd` (or your particular BSD flavor) respectively.

To crosscompile for other platforms, make sure the libraries for the target architecture are installed, and set
`CGO_ENABLED=1` as Go disables [Cgo](https://golang.org/cmd/cgo/#hdr-Using_cgo_with_the_go_command) on crosscompiles by default.
6 changes: 5 additions & 1 deletion context.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ type NewContextOptions struct {
// Too big buffer size can increase the latency time.
// On the other hand, too small buffer size can cause glitch noises due to buffer shortage.
BufferSize time.Duration

// ApplicationName specifies the name of the client application.
// It is used for PulseAudio's volume control UI and so on.
ApplicationName string
}

// NewContext creates a new context with given options.
Expand All @@ -97,7 +101,7 @@ func NewContext(options *NewContextOptions) (*Context, chan struct{}, error) {
bufferSizeInBytes = int(int64(options.BufferSize) * int64(bytesPerSecond) / int64(time.Second))
bufferSizeInBytes = bufferSizeInBytes / bytesPerSample * bytesPerSample
}
ctx, ready, err := newContext(options.SampleRate, options.ChannelCount, mux.Format(options.Format), bufferSizeInBytes)
ctx, ready, err := newContext(options.SampleRate, options.ChannelCount, mux.Format(options.Format), bufferSizeInBytes, options.ApplicationName)
if err != nil {
return nil, nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion driver_android.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type context struct {
mux *mux.Mux
}

func newContext(sampleRate int, channelCount int, format mux.Format, bufferSizeInBytes int) (*context, chan struct{}, error) {
func newContext(sampleRate int, channelCount int, format mux.Format, bufferSizeInBytes int, _ string) (*context, chan struct{}, error) {
ready := make(chan struct{})
close(ready)

Expand Down
2 changes: 1 addition & 1 deletion driver_console.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type context struct {

var theContext *context

func newContext(sampleRate int, channelCount int, format mux.Format, bufferSizeInBytes int) (*context, chan struct{}, error) {
func newContext(sampleRate int, channelCount int, format mux.Format, bufferSizeInBytes int, _ string) (*context, chan struct{}, error) {
ready := make(chan struct{})
close(ready)

Expand Down
2 changes: 1 addition & 1 deletion driver_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ type context struct {

var theContext *context

func newContext(sampleRate int, channelCount int, format mux.Format, bufferSizeInBytes int) (*context, chan struct{}, error) {
func newContext(sampleRate int, channelCount int, format mux.Format, bufferSizeInBytes int, _ string) (*context, chan struct{}, error) {
// defaultOneBufferSizeInBytes is the default buffer size in bytes.
//
// 12288 seems necessary at least on iPod touch (7th) and MacBook Pro 2020.
Expand Down
2 changes: 1 addition & 1 deletion driver_js.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type context struct {
mux *mux.Mux
}

func newContext(sampleRate int, channelCount int, format mux.Format, bufferSizeInBytes int) (*context, chan struct{}, error) {
func newContext(sampleRate int, channelCount int, format mux.Format, bufferSizeInBytes int, _ string) (*context, chan struct{}, error) {
ready := make(chan struct{})

class := js.Global().Get("AudioContext")
Expand Down
Loading
Loading