Skip to content

Commit

Permalink
use a bigger buffer size for macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
hajimehoshi committed Jan 3, 2024
1 parent 3f14867 commit a9a798c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
7 changes: 7 additions & 0 deletions driver_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ type context struct {
var theContext *context

func newContext(sampleRate int, channelCount int, format mux.Format, bufferSizeInBytes int) (*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.
// With 48000[Hz] stereo, the maximum delay is (12288*4[buffers] / 4 / 2)[samples] / 48000 [Hz] = 100[ms].
// '4' is float32 size in bytes. '2' is a number of channels for stereo.
const defaultOneBufferSizeInBytes = 12288

var oneBufferSizeInBytes int
if bufferSizeInBytes != 0 {
oneBufferSizeInBytes = bufferSizeInBytes / bufferCount
Expand Down
6 changes: 0 additions & 6 deletions driver_ios.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@

package oto

// 12288 seems necessary at least on iPod touch (7th).
// With 48000[Hz] stereo, the maximum delay is (12288*4[buffers] / 4 / 2)[samples] / 48000 [Hz] = 100[ms].
// '4' is float32 size in bytes. '2' is a number of channels for stereo.

const defaultOneBufferSizeInBytes = 12288

func setNotificationHandler() error {
// AVAudioSessionInterruptionNotification is not reliable on iOS. Rely on
// applicationWillResignActive and applicationDidBecomeActive instead. See
Expand Down
2 changes: 0 additions & 2 deletions driver_macos.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (
"github.com/ebitengine/purego/objc"
)

const defaultOneBufferSizeInBytes = 8192

// setNotificationHandler sets a handler for sleep/wake notifications.
func setNotificationHandler() error {
appkit, err := purego.Dlopen("/System/Library/Frameworks/AppKit.framework/Versions/Current/AppKit", purego.RTLD_GLOBAL)
Expand Down

0 comments on commit a9a798c

Please sign in to comment.