mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 14:57:35 +00:00
AudioServer: Put the m_zero_filled_buffer variable into the .bss segment
This way we don't have to allocate this at runtime. I'm intentionally not using static constexpr here because that would put the variable into the .rodata segment and would therefore increase the binary by 4kB. The old code also failed to free() the buffer in the destructor, however that wasn't much of an issue because the Mixer object exists throughout the program's entire lifetime.
This commit is contained in:
parent
129a0fcfb5
commit
f589acaac9
2 changed files with 4 additions and 4 deletions
|
@ -14,6 +14,8 @@
|
||||||
|
|
||||||
namespace AudioServer {
|
namespace AudioServer {
|
||||||
|
|
||||||
|
u8 Mixer::m_zero_filled_buffer[4096];
|
||||||
|
|
||||||
Mixer::Mixer()
|
Mixer::Mixer()
|
||||||
: m_device(Core::File::construct("/dev/audio", this))
|
: m_device(Core::File::construct("/dev/audio", this))
|
||||||
, m_sound_thread(Threading::Thread::construct(
|
, m_sound_thread(Threading::Thread::construct(
|
||||||
|
@ -31,8 +33,6 @@ Mixer::Mixer()
|
||||||
pthread_mutex_init(&m_pending_mutex, nullptr);
|
pthread_mutex_init(&m_pending_mutex, nullptr);
|
||||||
pthread_cond_init(&m_pending_cond, nullptr);
|
pthread_cond_init(&m_pending_cond, nullptr);
|
||||||
|
|
||||||
m_zero_filled_buffer = (u8*)malloc(4096);
|
|
||||||
bzero(m_zero_filled_buffer, 4096);
|
|
||||||
m_sound_thread->start();
|
m_sound_thread->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ void Mixer::mix()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_muted) {
|
if (m_muted) {
|
||||||
m_device->write(m_zero_filled_buffer, 4096);
|
m_device->write(m_zero_filled_buffer, sizeof(m_zero_filled_buffer));
|
||||||
} else {
|
} else {
|
||||||
Array<u8, 4096> buffer;
|
Array<u8, 4096> buffer;
|
||||||
OutputMemoryStream stream { buffer };
|
OutputMemoryStream stream { buffer };
|
||||||
|
|
|
@ -117,7 +117,7 @@ private:
|
||||||
bool m_muted { false };
|
bool m_muted { false };
|
||||||
int m_main_volume { 100 };
|
int m_main_volume { 100 };
|
||||||
|
|
||||||
u8* m_zero_filled_buffer { nullptr };
|
static u8 m_zero_filled_buffer[4096];
|
||||||
|
|
||||||
void mix();
|
void mix();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue