mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 15:47:34 +00:00
LibAudio: Rename Audio::Frame -> Audio::Sample
"Frame" is an MPEG term, which is not only unintuitive but also overloaded with different meaning by other codecs (e.g. FLAC). Therefore, use the standard term Sample for the central audio structure. The class is also extracted to its own file, because it's becoming quite large. Bundling these two changes means not distributing similar modifications (changing names and paths) across commits. Co-authored-by: kleines Filmröllchen <malu.bertsch@gmail.com>
This commit is contained in:
parent
fa4255bcf1
commit
b6d075bb01
11 changed files with 179 additions and 165 deletions
|
@ -12,10 +12,10 @@
|
|||
// Converts Piano-internal data to an Audio::Buffer that AudioServer receives
|
||||
static NonnullRefPtr<Audio::Buffer> music_samples_to_buffer(Array<Sample, sample_count> samples)
|
||||
{
|
||||
Vector<Audio::Frame, sample_count> frames;
|
||||
Vector<Audio::Sample, sample_count> frames;
|
||||
frames.ensure_capacity(sample_count);
|
||||
for (auto sample : samples) {
|
||||
Audio::Frame frame = { sample.left / (double)NumericLimits<i16>::max(), sample.right / (double)NumericLimits<i16>::max() };
|
||||
Audio::Sample frame = { sample.left / (double)NumericLimits<i16>::max(), sample.right / (double)NumericLimits<i16>::max() };
|
||||
frames.unchecked_append(frame);
|
||||
}
|
||||
return Audio::Buffer::create_with_samples(frames);
|
||||
|
|
|
@ -31,7 +31,7 @@ Track::~Track()
|
|||
|
||||
void Track::fill_sample(Sample& sample)
|
||||
{
|
||||
Audio::Frame new_sample;
|
||||
Audio::Sample new_sample;
|
||||
|
||||
for (size_t note = 0; note < note_count; ++note) {
|
||||
if (!m_roll_iterators[note].is_end()) {
|
||||
|
@ -72,7 +72,7 @@ void Track::fill_sample(Sample& sample)
|
|||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
Audio::Frame note_sample;
|
||||
Audio::Sample note_sample;
|
||||
switch (m_wave) {
|
||||
case Wave::Sine:
|
||||
note_sample = sine(note);
|
||||
|
@ -161,7 +161,7 @@ String Track::set_recorded_sample(const StringView& path)
|
|||
|
||||
// All of the information for these waves is on Wikipedia.
|
||||
|
||||
Audio::Frame Track::sine(size_t note)
|
||||
Audio::Sample Track::sine(size_t note)
|
||||
{
|
||||
double pos = note_frequencies[note] / sample_rate;
|
||||
double sin_step = pos * 2 * M_PI;
|
||||
|
@ -170,7 +170,7 @@ Audio::Frame Track::sine(size_t note)
|
|||
return w;
|
||||
}
|
||||
|
||||
Audio::Frame Track::saw(size_t note)
|
||||
Audio::Sample Track::saw(size_t note)
|
||||
{
|
||||
double saw_step = note_frequencies[note] / sample_rate;
|
||||
double t = m_pos[note];
|
||||
|
@ -179,7 +179,7 @@ Audio::Frame Track::saw(size_t note)
|
|||
return w;
|
||||
}
|
||||
|
||||
Audio::Frame Track::square(size_t note)
|
||||
Audio::Sample Track::square(size_t note)
|
||||
{
|
||||
double pos = note_frequencies[note] / sample_rate;
|
||||
double square_step = pos * 2 * M_PI;
|
||||
|
@ -188,7 +188,7 @@ Audio::Frame Track::square(size_t note)
|
|||
return w;
|
||||
}
|
||||
|
||||
Audio::Frame Track::triangle(size_t note)
|
||||
Audio::Sample Track::triangle(size_t note)
|
||||
{
|
||||
double triangle_step = note_frequencies[note] / sample_rate;
|
||||
double t = m_pos[note];
|
||||
|
@ -197,7 +197,7 @@ Audio::Frame Track::triangle(size_t note)
|
|||
return w;
|
||||
}
|
||||
|
||||
Audio::Frame Track::noise(size_t note)
|
||||
Audio::Sample Track::noise(size_t note)
|
||||
{
|
||||
double step = note_frequencies[note] / sample_rate;
|
||||
// m_pos keeps track of the time since the last random sample
|
||||
|
@ -210,7 +210,7 @@ Audio::Frame Track::noise(size_t note)
|
|||
return m_last_w[note];
|
||||
}
|
||||
|
||||
Audio::Frame Track::recorded_sample(size_t note)
|
||||
Audio::Sample Track::recorded_sample(size_t note)
|
||||
{
|
||||
int t = m_pos[note];
|
||||
if (t >= static_cast<int>(m_recorded_sample.size()))
|
||||
|
|
|
@ -24,7 +24,7 @@ public:
|
|||
explicit Track(const u32& time);
|
||||
~Track();
|
||||
|
||||
const Vector<Audio::Frame>& recorded_sample() const { return m_recorded_sample; }
|
||||
const Vector<Audio::Sample>& recorded_sample() const { return m_recorded_sample; }
|
||||
const SinglyLinkedList<RollNote>& roll_notes(int note) const { return m_roll_notes[note]; }
|
||||
int wave() const { return m_wave; }
|
||||
int volume() const { return m_volume; }
|
||||
|
@ -48,17 +48,17 @@ public:
|
|||
void set_release(int release);
|
||||
|
||||
private:
|
||||
Audio::Frame sine(size_t note);
|
||||
Audio::Frame saw(size_t note);
|
||||
Audio::Frame square(size_t note);
|
||||
Audio::Frame triangle(size_t note);
|
||||
Audio::Frame noise(size_t note);
|
||||
Audio::Frame recorded_sample(size_t note);
|
||||
Audio::Sample sine(size_t note);
|
||||
Audio::Sample saw(size_t note);
|
||||
Audio::Sample square(size_t note);
|
||||
Audio::Sample triangle(size_t note);
|
||||
Audio::Sample noise(size_t note);
|
||||
Audio::Sample recorded_sample(size_t note);
|
||||
|
||||
void sync_roll(int note);
|
||||
void set_sustain_impl(int sustain);
|
||||
|
||||
Vector<Audio::Frame> m_recorded_sample;
|
||||
Vector<Audio::Sample> m_recorded_sample;
|
||||
|
||||
u8 m_note_on[note_count] { 0 };
|
||||
double m_power[note_count] { 0 };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue