internal/cbackend: add AudioBufferSizeInSeconds

This commit is contained in:
Hajime Hoshi 2021-12-23 02:55:54 +09:00
parent 1799ed0b28
commit e6131894a7
2 changed files with 7 additions and 2 deletions

View File

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

View File

@ -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();
@ -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() {
@ -187,6 +189,10 @@ func CreateAudioPlayer(onWritten func()) *AudioPlayer {
return p
}
func AudioBufferSizeInSeconds() float64 {
return float64(C.EbitenAudioBufferSizeInSeconds())
}
type AudioPlayer struct {
id C.int
}