Skip to content

Commit a9a798c

Browse files
committed
use a bigger buffer size for macOS
1 parent 3f14867 commit a9a798c

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

driver_darwin.go

+7
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ type context struct {
8888
var theContext *context
8989

9090
func newContext(sampleRate int, channelCount int, format mux.Format, bufferSizeInBytes int) (*context, chan struct{}, error) {
91+
// defaultOneBufferSizeInBytes is the default buffer size in bytes.
92+
//
93+
// 12288 seems necessary at least on iPod touch (7th) and MacBook Pro 2020.
94+
// With 48000[Hz] stereo, the maximum delay is (12288*4[buffers] / 4 / 2)[samples] / 48000 [Hz] = 100[ms].
95+
// '4' is float32 size in bytes. '2' is a number of channels for stereo.
96+
const defaultOneBufferSizeInBytes = 12288
97+
9198
var oneBufferSizeInBytes int
9299
if bufferSizeInBytes != 0 {
93100
oneBufferSizeInBytes = bufferSizeInBytes / bufferCount

driver_ios.go

-6
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@
1616

1717
package oto
1818

19-
// 12288 seems necessary at least on iPod touch (7th).
20-
// With 48000[Hz] stereo, the maximum delay is (12288*4[buffers] / 4 / 2)[samples] / 48000 [Hz] = 100[ms].
21-
// '4' is float32 size in bytes. '2' is a number of channels for stereo.
22-
23-
const defaultOneBufferSizeInBytes = 12288
24-
2519
func setNotificationHandler() error {
2620
// AVAudioSessionInterruptionNotification is not reliable on iOS. Rely on
2721
// applicationWillResignActive and applicationDidBecomeActive instead. See

driver_macos.go

-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ import (
2323
"github.com/ebitengine/purego/objc"
2424
)
2525

26-
const defaultOneBufferSizeInBytes = 8192
27-
2826
// setNotificationHandler sets a handler for sleep/wake notifications.
2927
func setNotificationHandler() error {
3028
appkit, err := purego.Dlopen("/System/Library/Frameworks/AppKit.framework/Versions/Current/AppKit", purego.RTLD_GLOBAL)

0 commit comments

Comments
 (0)