audio: rename channelNum -> channelCount

This commit is contained in:
Hajime Hoshi 2022-07-13 02:08:38 +09:00
parent 36b7b85477
commit 921aeb4ea7
11 changed files with 34 additions and 34 deletions

View File

@ -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.

View File

@ -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 {

View File

@ -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]
}

View File

@ -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 {

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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 {

View File

@ -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
}