From 921aeb4ea71bd0c4e0d826bb26b3dbbdd87e4da5 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Wed, 13 Jul 2022 02:08:38 +0900 Subject: [PATCH] audio: rename channelNum -> channelCount --- audio/audio.go | 4 ++-- audio/export_test.go | 2 +- audio/internal/cbackend/context.go | 10 +++++----- audio/internal/go2cpp/player_js.go | 10 +++++----- audio/player.go | 2 +- audio/player_cbackend.go | 4 ++-- audio/player_js.go | 6 +++--- audio/player_notjs.go | 4 ++-- audio/vorbis/vorbis.go | 16 ++++++++-------- audio/wav/decode.go | 6 +++--- internal/cbackend/cbackend.go | 4 ++-- 11 files changed, 34 insertions(+), 34 deletions(-) diff --git a/audio/audio.go b/audio/audio.go index ff8feae8e..f6d87f205 100644 --- a/audio/audio.go +++ b/audio/audio.go @@ -44,9 +44,9 @@ import ( ) const ( - channelNum = 2 + channelCount = 2 bitDepthInBytes = 2 - bytesPerSample = bitDepthInBytes * channelNum + bytesPerSample = bitDepthInBytes * channelCount ) // A Context represents a current state of audio. diff --git a/audio/export_test.go b/audio/export_test.go index ba316f8b3..0453b6b1a 100644 --- a/audio/export_test.go +++ b/audio/export_test.go @@ -38,7 +38,7 @@ func (c *dummyContext) NewPlayer(r io.Reader) player { } func (c *dummyContext) MaxBufferSize() int { - return 48000 * channelNum * bitDepthInBytes / 4 + return 48000 * channelCount * bitDepthInBytes / 4 } func (c *dummyContext) Suspend() error { diff --git a/audio/internal/cbackend/context.go b/audio/internal/cbackend/context.go index e3618c0a4..c0cb780b3 100644 --- a/audio/internal/cbackend/context.go +++ b/audio/internal/cbackend/context.go @@ -25,20 +25,20 @@ import ( type Context struct { sampleRate int - channelNum int + channelCount int bitDepthInBytes int players *players } -func NewContext(sampleRate, channelNum, bitDepthInBytes int) (*Context, chan struct{}, error) { +func NewContext(sampleRate, channelCount, bitDepthInBytes int) (*Context, chan struct{}, error) { c := &Context{ sampleRate: sampleRate, - channelNum: channelNum, + channelCount: channelCount, bitDepthInBytes: bitDepthInBytes, players: newPlayers(), } - cbackend.OpenAudio(sampleRate, channelNum, c.players.read) + cbackend.OpenAudio(sampleRate, channelCount, c.players.read) ready := make(chan struct{}) close(ready) return c, ready, nil @@ -63,5 +63,5 @@ func (c *Context) Err() error { } func (c *Context) defaultBufferSize() int { - return c.sampleRate * c.channelNum * c.bitDepthInBytes / 2 // 0.5[s] + return c.sampleRate * c.channelCount * c.bitDepthInBytes / 2 // 0.5[s] } diff --git a/audio/internal/go2cpp/player_js.go b/audio/internal/go2cpp/player_js.go index ca962f255..f5e9edee2 100644 --- a/audio/internal/go2cpp/player_js.go +++ b/audio/internal/go2cpp/player_js.go @@ -26,16 +26,16 @@ import ( type Context struct { v js.Value sampleRate int - channelNum int + channelCount int bitDepthInBytes int } -func NewContext(sampleRate int, channelNum, bitDepthInBytes int) *Context { - v := js.Global().Get("go2cpp").Call("createAudio", sampleRate, channelNum, bitDepthInBytes) +func NewContext(sampleRate int, channelCount, bitDepthInBytes int) *Context { + v := js.Global().Get("go2cpp").Call("createAudio", sampleRate, channelCount, bitDepthInBytes) return &Context{ v: v, sampleRate: sampleRate, - channelNum: channelNum, + channelCount: channelCount, bitDepthInBytes: bitDepthInBytes, } } @@ -73,7 +73,7 @@ func (c *Context) Err() error { func (c *Context) oneBufferSize() int { // TODO: This must be audio.oneBufferSize(p.context.sampleRate). Avoid the duplication. - return c.sampleRate * c.channelNum * c.bitDepthInBytes / 4 + return c.sampleRate * c.channelCount * c.bitDepthInBytes / 4 } func (c *Context) MaxBufferSize() int { diff --git a/audio/player.go b/audio/player.go index 070bded28..4612e9c6f 100644 --- a/audio/player.go +++ b/audio/player.go @@ -124,7 +124,7 @@ func (f *playerFactory) initContextIfNeeded() (<-chan struct{}, error) { return nil, nil } - c, ready, err := newContext(f.sampleRate, channelNum, bitDepthInBytes) + c, ready, err := newContext(f.sampleRate, channelCount, bitDepthInBytes) if err != nil { return nil, err } diff --git a/audio/player_cbackend.go b/audio/player_cbackend.go index d84f7d9db..e05274166 100644 --- a/audio/player_cbackend.go +++ b/audio/player_cbackend.go @@ -23,8 +23,8 @@ import ( "github.com/hajimehoshi/ebiten/v2/audio/internal/cbackend" ) -func newContext(sampleRate, channelNum, bitDepthInBytes int) (context, chan struct{}, error) { - ctx, ready, err := cbackend.NewContext(sampleRate, channelNum, bitDepthInBytes) +func newContext(sampleRate, channelCount, bitDepthInBytes int) (context, chan struct{}, error) { + ctx, ready, err := cbackend.NewContext(sampleRate, channelCount, bitDepthInBytes) return &contextProxy{ctx}, ready, err } diff --git a/audio/player_js.go b/audio/player_js.go index 93c13fa78..03a8f6dce 100644 --- a/audio/player_js.go +++ b/audio/player_js.go @@ -25,13 +25,13 @@ import ( "github.com/hajimehoshi/ebiten/v2/audio/internal/go2cpp" ) -func newContext(sampleRate, channelNum, bitDepthInBytes int) (context, chan struct{}, error) { +func newContext(sampleRate, channelCount, bitDepthInBytes int) (context, chan struct{}, error) { if js.Global().Get("go2cpp").Truthy() { ready := make(chan struct{}) close(ready) - return otoContextToContext(go2cpp.NewContext(sampleRate, channelNum, bitDepthInBytes)), ready, nil + return otoContextToContext(go2cpp.NewContext(sampleRate, channelCount, bitDepthInBytes)), ready, nil } - ctx, ready, err := oto.NewContext(sampleRate, channelNum, bitDepthInBytes) + ctx, ready, err := oto.NewContext(sampleRate, channelCount, bitDepthInBytes) return otoContextToContext(ctx), ready, err } diff --git a/audio/player_notjs.go b/audio/player_notjs.go index 2b9dbb44b..8bd1a1611 100644 --- a/audio/player_notjs.go +++ b/audio/player_notjs.go @@ -21,7 +21,7 @@ import ( "github.com/hajimehoshi/oto/v2" ) -func newContext(sampleRate, channelNum, bitDepthInBytes int) (context, chan struct{}, error) { - ctx, ready, err := oto.NewContext(sampleRate, channelNum, bitDepthInBytes) +func newContext(sampleRate, channelCount, bitDepthInBytes int) (context, chan struct{}, error) { + ctx, ready, err := oto.NewContext(sampleRate, channelCount, bitDepthInBytes) return otoContextToContext(ctx), ready, err } diff --git a/audio/vorbis/vorbis.go b/audio/vorbis/vorbis.go index 148b21874..7364914c5 100644 --- a/audio/vorbis/vorbis.go +++ b/audio/vorbis/vorbis.go @@ -148,16 +148,16 @@ func decode(in io.Reader) (*decoded, int, int, error) { // A Stream doesn't close src even if src implements io.Closer. // Closing the source is src owner's responsibility. func DecodeWithoutResampling(src io.Reader) (*Stream, error) { - decoded, channelNum, _, err := decode(src) + decoded, channelCount, _, err := decode(src) if err != nil { return nil, err } - if channelNum != 1 && channelNum != 2 { - return nil, fmt.Errorf("vorbis: number of channels must be 1 or 2 but was %d", channelNum) + if channelCount != 1 && channelCount != 2 { + return nil, fmt.Errorf("vorbis: number of channels must be 1 or 2 but was %d", channelCount) } var s io.ReadSeeker = decoded size := decoded.Length() - if channelNum == 1 { + if channelCount == 1 { s = convert.NewStereo16(s, true, false) size *= 2 } @@ -179,16 +179,16 @@ func DecodeWithoutResampling(src io.Reader) (*Stream, error) { // A Stream doesn't close src even if src implements io.Closer. // Closing the source is src owner's responsibility. func DecodeWithSampleRate(sampleRate int, src io.Reader) (*Stream, error) { - decoded, channelNum, origSampleRate, err := decode(src) + decoded, channelCount, origSampleRate, err := decode(src) if err != nil { return nil, err } - if channelNum != 1 && channelNum != 2 { - return nil, fmt.Errorf("vorbis: number of channels must be 1 or 2 but was %d", channelNum) + if channelCount != 1 && channelCount != 2 { + return nil, fmt.Errorf("vorbis: number of channels must be 1 or 2 but was %d", channelCount) } var s io.ReadSeeker = decoded size := decoded.Length() - if channelNum == 1 { + if channelCount == 1 { s = convert.NewStereo16(s, true, false) size *= 2 } diff --git a/audio/wav/decode.go b/audio/wav/decode.go index 188c982a0..1a70e9d36 100644 --- a/audio/wav/decode.go +++ b/audio/wav/decode.go @@ -187,14 +187,14 @@ chunks: if format != 1 { return nil, fmt.Errorf("wav: format must be linear PCM") } - channelNum := int(buf[2]) | int(buf[3])<<8 - switch channelNum { + channelCount := int(buf[2]) | int(buf[3])<<8 + switch channelCount { case 1: mono = true case 2: mono = false default: - return nil, fmt.Errorf("wav: channel num must be 1 or 2 but was %d", channelNum) + return nil, fmt.Errorf("wav: number of channels must be 1 or 2 but was %d", channelCount) } bitsPerSample = int(buf[14]) | int(buf[15])<<8 if bitsPerSample != 8 && bitsPerSample != 16 { diff --git a/internal/cbackend/cbackend.go b/internal/cbackend/cbackend.go index 68a1387a6..647cf0428 100644 --- a/internal/cbackend/cbackend.go +++ b/internal/cbackend/cbackend.go @@ -165,8 +165,8 @@ func VibrateGamepad(id int, duration time.Duration, strongMagnitude float64, wea var onReadCallback func(buf []float32) -func OpenAudio(sampleRate, channelNum int, onRead func(buf []float32)) { - C.EbitenOpenAudioProxy(C.int(sampleRate), C.int(channelNum)) +func OpenAudio(sampleRate, channelCount int, onRead func(buf []float32)) { + C.EbitenOpenAudioProxy(C.int(sampleRate), C.int(channelCount)) onReadCallback = onRead }