Skip to content

Commit

Permalink
internal/cbackend: add AudioBufferSizeInSeconds
Browse files Browse the repository at this point in the history
  • Loading branch information
hajimehoshi committed Dec 22, 2021
1 parent 1799ed0 commit e613189
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 1 addition & 2 deletions audio/internal/cbackend/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,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 int(float64(c.sampleRate*c.channelNum*c.bitDepthInBytes) * cbackend.AudioBufferSizeInSeconds())
}

func (c *Context) MaxBufferSize() int {
Expand Down
6 changes: 6 additions & 0 deletions internal/cbackend/cbackend.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ package cbackend
// void EbitenGetTouches(struct Touch* touches);
//
// // Audio
// // TODO: Implement mixing on Go side and reduce the API.
// typedef void (*OnWrittenCallback)(int id);
// void EbitenOpenAudio(int sample_rate, int channel_num, int bit_depth_in_bytes);
// void EbitenCloseAudio();
Expand All @@ -62,6 +63,7 @@ package cbackend
// double EbitenAudioPlayerGetVolume(int id);
// void EbitenAudioPlayerSetVolume(int id, double volume);
// int EbitenAudioPlayerGetUnplayedBufferSize(int id);
// float EbitenAudioBufferSizeInSeconds();
//
// void EbitenAudioPlayerOnWrittenCallback(int id);
// static int EbitenCreateAudioPlayerProxy() {
Expand Down Expand Up @@ -187,6 +189,10 @@ func CreateAudioPlayer(onWritten func()) *AudioPlayer {
return p
}

func AudioBufferSizeInSeconds() float64 {
return float64(C.EbitenAudioBufferSizeInSeconds())
}

type AudioPlayer struct {
id C.int
}
Expand Down

0 comments on commit e613189

Please sign in to comment.