audio/internal/oboe: Add prefixes to the C functions

This commit is contained in:
Hajime Hoshi 2021-05-16 03:00:36 +09:00
parent fc8b3d70fe
commit bb4a3ce89b
3 changed files with 36 additions and 32 deletions

View File

@ -208,50 +208,52 @@ private:
extern "C" { extern "C" {
const char *Suspend() { return Player::Suspend(); } const char *ebiten_oboe_Suspend() { return Player::Suspend(); }
const char *Resume() { return Player::Resume(); } const char *ebiten_oboe_Resume() { return Player::Resume(); }
PlayerID Player_Create(int sample_rate, int channel_num, int bit_depth_in_bytes, PlayerID ebiten_oboe_Player_Create(int sample_rate, int channel_num,
double volume, uintptr_t go_player) { int bit_depth_in_bytes, double volume,
uintptr_t go_player) {
Player *p = new Player(sample_rate, channel_num, bit_depth_in_bytes, volume, Player *p = new Player(sample_rate, channel_num, bit_depth_in_bytes, volume,
go_player); go_player);
return reinterpret_cast<PlayerID>(p); return reinterpret_cast<PlayerID>(p);
} }
bool Player_IsPlaying(PlayerID audio_player) { bool ebiten_oboe_Player_IsPlaying(PlayerID audio_player) {
Player *p = reinterpret_cast<Player *>(audio_player); Player *p = reinterpret_cast<Player *>(audio_player);
return p->IsPlaying(); return p->IsPlaying();
} }
void Player_AppendBuffer(PlayerID audio_player, uint8_t *data, int length) { void ebiten_oboe_Player_AppendBuffer(PlayerID audio_player, uint8_t *data,
int length) {
Player *p = reinterpret_cast<Player *>(audio_player); Player *p = reinterpret_cast<Player *>(audio_player);
p->AppendBuffer(data, length); p->AppendBuffer(data, length);
} }
const char *Player_Play(PlayerID audio_player) { const char *ebiten_oboe_Player_Play(PlayerID audio_player) {
Player *p = reinterpret_cast<Player *>(audio_player); Player *p = reinterpret_cast<Player *>(audio_player);
return p->Play(); return p->Play();
} }
const char *Player_Pause(PlayerID audio_player) { const char *ebiten_oboe_Player_Pause(PlayerID audio_player) {
Player *p = reinterpret_cast<Player *>(audio_player); Player *p = reinterpret_cast<Player *>(audio_player);
return p->Pause(); return p->Pause();
} }
void Player_SetVolume(PlayerID audio_player, double volume) { void ebiten_oboe_Player_SetVolume(PlayerID audio_player, double volume) {
Player *p = reinterpret_cast<Player *>(audio_player); Player *p = reinterpret_cast<Player *>(audio_player);
p->SetVolume(volume); p->SetVolume(volume);
} }
const char *Player_Close(PlayerID audio_player) { const char *ebiten_oboe_Player_Close(PlayerID audio_player) {
Player *p = reinterpret_cast<Player *>(audio_player); Player *p = reinterpret_cast<Player *>(audio_player);
const char *msg = p->CloseAndRemove(); const char *msg = p->CloseAndRemove();
delete p; delete p;
return msg; return msg;
} }
int Player_UnplayedBufferSize(PlayerID audio_player) { int ebiten_oboe_Player_UnplayedBufferSize(PlayerID audio_player) {
Player *p = reinterpret_cast<Player *>(audio_player); Player *p = reinterpret_cast<Player *>(audio_player);
return p->GetUnplayedBufferSize(); return p->GetUnplayedBufferSize();
} }

View File

@ -31,14 +31,14 @@ import (
) )
func Suspend() error { func Suspend() error {
if msg := C.Suspend(); msg != nil { if msg := C.ebiten_oboe_Suspend(); msg != nil {
return fmt.Errorf("oboe: Suspend failed: %s", C.GoString(msg)) return fmt.Errorf("oboe: Suspend failed: %s", C.GoString(msg))
} }
return nil return nil
} }
func Resume() error { func Resume() error {
if msg := C.Resume(); msg != nil { if msg := C.ebiten_oboe_Resume(); msg != nil {
return fmt.Errorf("oboe: Resume failed: %s", C.GoString(msg)) return fmt.Errorf("oboe: Resume failed: %s", C.GoString(msg))
} }
return nil return nil
@ -53,7 +53,7 @@ func NewPlayer(sampleRate, channelNum, bitDepthInBytes int, volume float64, onWr
p := &Player{ p := &Player{
onWritten: onWritten, onWritten: onWritten,
} }
p.player = C.Player_Create(C.int(sampleRate), C.int(channelNum), C.int(bitDepthInBytes), C.double(volume), C.uintptr_t(uintptr(unsafe.Pointer(p)))) p.player = C.ebiten_oboe_Player_Create(C.int(sampleRate), C.int(channelNum), C.int(bitDepthInBytes), C.double(volume), C.uintptr_t(uintptr(unsafe.Pointer(p))))
runtime.SetFinalizer(p, (*Player).Close) runtime.SetFinalizer(p, (*Player).Close)
return p return p
} }
@ -65,21 +65,21 @@ func onWrittenCallback(player C.uintptr_t) {
} }
func (p *Player) IsPlaying() bool { func (p *Player) IsPlaying() bool {
return bool(C.Player_IsPlaying(p.player)) return bool(C.ebiten_oboe_Player_IsPlaying(p.player))
} }
func (p *Player) AppendBuffer(buf []byte) { func (p *Player) AppendBuffer(buf []byte) {
ptr := C.CBytes(buf) ptr := C.CBytes(buf)
defer C.free(ptr) defer C.free(ptr)
C.Player_AppendBuffer(p.player, (*C.uint8_t)(ptr), C.int(len(buf))) C.ebiten_oboe_Player_AppendBuffer(p.player, (*C.uint8_t)(ptr), C.int(len(buf)))
} }
func (p *Player) Play() error { func (p *Player) Play() error {
if p.player == 0 { if p.player == 0 {
return fmt.Errorf("oboe: player is already closed at Play") return fmt.Errorf("oboe: player is already closed at Play")
} }
if msg := C.Player_Play(p.player); msg != nil { if msg := C.ebiten_oboe_Player_Play(p.player); msg != nil {
return fmt.Errorf("oboe: Player_Play failed: %s", C.GoString(msg)) return fmt.Errorf("oboe: Player_Play failed: %s", C.GoString(msg))
} }
return nil return nil
@ -89,14 +89,14 @@ func (p *Player) Pause() error {
if p.player == 0 { if p.player == 0 {
return fmt.Errorf("oboe: player is already closed at Pause") return fmt.Errorf("oboe: player is already closed at Pause")
} }
if msg := C.Player_Pause(p.player); msg != nil { if msg := C.ebiten_oboe_Player_Pause(p.player); msg != nil {
return fmt.Errorf("oboe: Player_Pause failed: %s", C.GoString(msg)) return fmt.Errorf("oboe: Player_Pause failed: %s", C.GoString(msg))
} }
return nil return nil
} }
func (p *Player) SetVolume(volume float64) { func (p *Player) SetVolume(volume float64) {
C.Player_SetVolume(p.player, C.double(volume)) C.ebiten_oboe_Player_SetVolume(p.player, C.double(volume))
} }
func (p *Player) Close() error { func (p *Player) Close() error {
@ -104,7 +104,7 @@ func (p *Player) Close() error {
if p.player == 0 { if p.player == 0 {
return fmt.Errorf("oboe: player is already closed at Close") return fmt.Errorf("oboe: player is already closed at Close")
} }
if msg := C.Player_Close(p.player); msg != nil { if msg := C.ebiten_oboe_Player_Close(p.player); msg != nil {
return fmt.Errorf("oboe: Player_Close failed: %s", C.GoString(msg)) return fmt.Errorf("oboe: Player_Close failed: %s", C.GoString(msg))
} }
p.player = 0 p.player = 0
@ -112,5 +112,5 @@ func (p *Player) Close() error {
} }
func (p *Player) UnplayedBufferSize() int { func (p *Player) UnplayedBufferSize() int {
return int(C.Player_UnplayedBufferSize(p.player)) return int(C.ebiten_oboe_Player_UnplayedBufferSize(p.player))
} }

View File

@ -25,17 +25,19 @@ extern "C" {
typedef uintptr_t PlayerID; typedef uintptr_t PlayerID;
const char *Suspend(); const char *ebiten_oboe_Suspend();
const char *Resume(); const char *ebiten_oboe_Resume();
PlayerID Player_Create(int sample_rate, int channel_num, int bit_depth_in_bytes, PlayerID ebiten_oboe_Player_Create(int sample_rate, int channel_num,
double volume, uintptr_t go_player); int bit_depth_in_bytes, double volume,
bool Player_IsPlaying(PlayerID audio_player); uintptr_t go_player);
void Player_AppendBuffer(PlayerID audio_player, uint8_t *data, int length); bool ebiten_oboe_Player_IsPlaying(PlayerID audio_player);
const char *Player_Play(PlayerID audio_player); void ebiten_oboe_Player_AppendBuffer(PlayerID audio_player, uint8_t *data,
const char *Player_Pause(PlayerID audio_player); int length);
const char *Player_Close(PlayerID audio_player); const char *ebiten_oboe_Player_Play(PlayerID audio_player);
void Player_SetVolume(PlayerID audio_player, double volume); const char *ebiten_oboe_Player_Pause(PlayerID audio_player);
int Player_UnplayedBufferSize(PlayerID audio_player); const char *ebiten_oboe_Player_Close(PlayerID audio_player);
void ebiten_oboe_Player_SetVolume(PlayerID audio_player, double volume);
int ebiten_oboe_Player_UnplayedBufferSize(PlayerID audio_player);
#ifdef __cplusplus #ifdef __cplusplus
} }