mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-13 20:42:07 +01:00
audio/internal/oboe: clang-format
This commit is contained in:
parent
2edb286ec4
commit
fc8b3d70fe
45
audio/internal/oboe/binding_android.cpp
vendored
45
audio/internal/oboe/binding_android.cpp
vendored
@ -52,11 +52,10 @@ public:
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player(int sample_rate, int channel_num, int bit_depth_in_bytes, double volume, uintptr_t go_player)
|
Player(int sample_rate, int channel_num, int bit_depth_in_bytes,
|
||||||
: sample_rate_{sample_rate},
|
double volume, uintptr_t go_player)
|
||||||
channel_num_{channel_num},
|
: sample_rate_{sample_rate}, channel_num_{channel_num},
|
||||||
bit_depth_in_bytes_{bit_depth_in_bytes},
|
bit_depth_in_bytes_{bit_depth_in_bytes}, go_player_{go_player} {
|
||||||
go_player_{go_player} {
|
|
||||||
std::atomic_store(&volume_, volume);
|
std::atomic_store(&volume_, volume);
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(PlayersMutex());
|
std::lock_guard<std::mutex> lock(PlayersMutex());
|
||||||
@ -64,18 +63,16 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetVolume(double volume) {
|
void SetVolume(double volume) { std::atomic_store(&volume_, volume); }
|
||||||
std::atomic_store(&volume_, volume);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsPlaying() {
|
bool IsPlaying() { return stream_->getState() == oboe::StreamState::Started; }
|
||||||
return stream_->getState() == oboe::StreamState::Started;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AppendBuffer(uint8_t *data, int length) {
|
void AppendBuffer(uint8_t *data, int length) {
|
||||||
// Sync this constants with internal/readerdriver/driver.go
|
// Sync this constants with internal/readerdriver/driver.go
|
||||||
const size_t bytes_per_sample = channel_num_ * bit_depth_in_bytes_;
|
const size_t bytes_per_sample = channel_num_ * bit_depth_in_bytes_;
|
||||||
const size_t one_buffer_size = sample_rate_ * channel_num_ * bit_depth_in_bytes_ / 4 / bytes_per_sample * bytes_per_sample;
|
const size_t one_buffer_size = sample_rate_ * channel_num_ *
|
||||||
|
bit_depth_in_bytes_ / 4 / bytes_per_sample *
|
||||||
|
bytes_per_sample;
|
||||||
const size_t max_buffer_size = one_buffer_size * 2;
|
const size_t max_buffer_size = one_buffer_size * 2;
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(mutex_);
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
@ -89,7 +86,8 @@ public:
|
|||||||
|
|
||||||
if (!stream_) {
|
if (!stream_) {
|
||||||
oboe::AudioStreamBuilder builder;
|
oboe::AudioStreamBuilder builder;
|
||||||
oboe::Result result = builder.setDirection(oboe::Direction::Output)
|
oboe::Result result =
|
||||||
|
builder.setDirection(oboe::Direction::Output)
|
||||||
->setPerformanceMode(oboe::PerformanceMode::LowLatency)
|
->setPerformanceMode(oboe::PerformanceMode::LowLatency)
|
||||||
->setSharingMode(oboe::SharingMode::Shared)
|
->setSharingMode(oboe::SharingMode::Shared)
|
||||||
->setFormat(oboe::AudioFormat::I16)
|
->setFormat(oboe::AudioFormat::I16)
|
||||||
@ -150,7 +148,9 @@ public:
|
|||||||
return buf_.size();
|
return buf_.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
oboe::DataCallbackResult onAudioReady(oboe::AudioStream *oboe_stream, void *audio_data, int32_t num_frames) override {
|
oboe::DataCallbackResult onAudioReady(oboe::AudioStream *oboe_stream,
|
||||||
|
void *audio_data,
|
||||||
|
int32_t num_frames) override {
|
||||||
size_t num_bytes = num_frames * channel_num_ * bit_depth_in_bytes_;
|
size_t num_bytes = num_frames * channel_num_ * bit_depth_in_bytes_;
|
||||||
std::vector<uint8_t> buf(num_bytes);
|
std::vector<uint8_t> buf(num_bytes);
|
||||||
{
|
{
|
||||||
@ -165,7 +165,8 @@ public:
|
|||||||
|
|
||||||
if (const double volume = std::atomic_load(&volume_); volume < 1) {
|
if (const double volume = std::atomic_load(&volume_); volume < 1) {
|
||||||
for (int i = 0; i < buf.size() / 2; i++) {
|
for (int i = 0; i < buf.size() / 2; i++) {
|
||||||
int16_t v = static_cast<int16_t>(buf[2*i]) | (static_cast<int16_t>(buf[2*i+1]) << 8);
|
int16_t v = static_cast<int16_t>(buf[2 * i]) |
|
||||||
|
(static_cast<int16_t>(buf[2 * i + 1]) << 8);
|
||||||
v = static_cast<int16_t>(static_cast<double>(v) * volume);
|
v = static_cast<int16_t>(static_cast<double>(v) * volume);
|
||||||
buf[2 * i] = static_cast<uint8_t>(v);
|
buf[2 * i] = static_cast<uint8_t>(v);
|
||||||
buf[2 * i + 1] = static_cast<uint8_t>(v >> 8);
|
buf[2 * i + 1] = static_cast<uint8_t>(v >> 8);
|
||||||
@ -207,16 +208,14 @@ private:
|
|||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
const char* Suspend() {
|
const char *Suspend() { return Player::Suspend(); }
|
||||||
return Player::Suspend();
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* Resume() {
|
const char *Resume() { return Player::Resume(); }
|
||||||
return Player::Resume();
|
|
||||||
}
|
|
||||||
|
|
||||||
PlayerID Player_Create(int sample_rate, int channel_num, int bit_depth_in_bytes, double volume, uintptr_t go_player) {
|
PlayerID Player_Create(int sample_rate, int channel_num, int bit_depth_in_bytes,
|
||||||
Player* p = new Player(sample_rate, channel_num, bit_depth_in_bytes, volume, go_player);
|
double volume, uintptr_t go_player) {
|
||||||
|
Player *p = new Player(sample_rate, channel_num, bit_depth_in_bytes, volume,
|
||||||
|
go_player);
|
||||||
return reinterpret_cast<PlayerID>(p);
|
return reinterpret_cast<PlayerID>(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
3
audio/internal/oboe/binding_android.h
vendored
3
audio/internal/oboe/binding_android.h
vendored
@ -27,7 +27,8 @@ typedef uintptr_t PlayerID;
|
|||||||
|
|
||||||
const char *Suspend();
|
const char *Suspend();
|
||||||
const char *Resume();
|
const char *Resume();
|
||||||
PlayerID Player_Create(int sample_rate, int channel_num, int bit_depth_in_bytes, double volume, uintptr_t go_player);
|
PlayerID Player_Create(int sample_rate, int channel_num, int bit_depth_in_bytes,
|
||||||
|
double volume, uintptr_t go_player);
|
||||||
bool Player_IsPlaying(PlayerID audio_player);
|
bool Player_IsPlaying(PlayerID audio_player);
|
||||||
void Player_AppendBuffer(PlayerID audio_player, uint8_t *data, int length);
|
void Player_AppendBuffer(PlayerID audio_player, uint8_t *data, int length);
|
||||||
const char *Player_Play(PlayerID audio_player);
|
const char *Player_Play(PlayerID audio_player);
|
||||||
|
Loading…
Reference in New Issue
Block a user