mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 23:27:35 +00:00
Everywhere: rename 'Sample' type to 'Frame'
Because it's what it really is. A frame is composed of 1 or more samples, in the case of SerenityOS 2 (stereo). This will make it less confusing for future mantainability.
This commit is contained in:
parent
f4bd095aa3
commit
0d5e1e9df1
7 changed files with 36 additions and 36 deletions
|
@ -36,7 +36,7 @@ i32 Buffer::allocate_id()
|
|||
}
|
||||
|
||||
template<typename SampleReader>
|
||||
static void read_samples_from_stream(InputMemoryStream& stream, SampleReader read_sample, Vector<Sample>& samples, ResampleHelper& resampler, int num_channels)
|
||||
static void read_samples_from_stream(InputMemoryStream& stream, SampleReader read_sample, Vector<Frame>& samples, ResampleHelper& resampler, int num_channels)
|
||||
{
|
||||
double norm_l = 0;
|
||||
double norm_r = 0;
|
||||
|
@ -45,7 +45,7 @@ static void read_samples_from_stream(InputMemoryStream& stream, SampleReader rea
|
|||
case 1:
|
||||
for (;;) {
|
||||
while (resampler.read_sample(norm_l, norm_r)) {
|
||||
samples.append(Sample(norm_l));
|
||||
samples.append(Frame(norm_l));
|
||||
}
|
||||
norm_l = read_sample(stream);
|
||||
|
||||
|
@ -58,7 +58,7 @@ static void read_samples_from_stream(InputMemoryStream& stream, SampleReader rea
|
|||
case 2:
|
||||
for (;;) {
|
||||
while (resampler.read_sample(norm_l, norm_r)) {
|
||||
samples.append(Sample(norm_l, norm_r));
|
||||
samples.append(Frame(norm_l, norm_r));
|
||||
}
|
||||
norm_l = read_sample(stream);
|
||||
norm_r = read_sample(stream);
|
||||
|
@ -113,7 +113,7 @@ RefPtr<Buffer> Buffer::from_pcm_data(ReadonlyBytes data, ResampleHelper& resampl
|
|||
|
||||
RefPtr<Buffer> Buffer::from_pcm_stream(InputMemoryStream& stream, ResampleHelper& resampler, int num_channels, int bits_per_sample, int num_samples)
|
||||
{
|
||||
Vector<Sample> fdata;
|
||||
Vector<Frame> fdata;
|
||||
fdata.ensure_capacity(num_samples);
|
||||
|
||||
switch (bits_per_sample) {
|
||||
|
|
|
@ -37,22 +37,22 @@ namespace Audio {
|
|||
|
||||
// A single sample in an audio buffer.
|
||||
// Values are floating point, and should range from -1.0 to +1.0
|
||||
struct Sample {
|
||||
Sample()
|
||||
struct Frame {
|
||||
Frame()
|
||||
: left(0)
|
||||
, right(0)
|
||||
{
|
||||
}
|
||||
|
||||
// For mono
|
||||
Sample(double left)
|
||||
Frame(double left)
|
||||
: left(left)
|
||||
, right(left)
|
||||
{
|
||||
}
|
||||
|
||||
// For stereo
|
||||
Sample(double left, double right)
|
||||
Frame(double left, double right)
|
||||
: left(left)
|
||||
, right(right)
|
||||
{
|
||||
|
@ -78,7 +78,7 @@ struct Sample {
|
|||
right *= pct;
|
||||
}
|
||||
|
||||
Sample& operator+=(const Sample& other)
|
||||
Frame& operator+=(const Frame& other)
|
||||
{
|
||||
left += other.left;
|
||||
right += other.right;
|
||||
|
@ -111,7 +111,7 @@ class Buffer : public RefCounted<Buffer> {
|
|||
public:
|
||||
static RefPtr<Buffer> from_pcm_data(ReadonlyBytes data, ResampleHelper& resampler, int num_channels, int bits_per_sample);
|
||||
static RefPtr<Buffer> from_pcm_stream(InputMemoryStream& stream, ResampleHelper& resampler, int num_channels, int bits_per_sample, int num_samples);
|
||||
static NonnullRefPtr<Buffer> create_with_samples(Vector<Sample>&& samples)
|
||||
static NonnullRefPtr<Buffer> create_with_samples(Vector<Frame>&& samples)
|
||||
{
|
||||
return adopt(*new Buffer(move(samples)));
|
||||
}
|
||||
|
@ -120,20 +120,20 @@ public:
|
|||
return adopt(*new Buffer(move(buffer), buffer_id, sample_count));
|
||||
}
|
||||
|
||||
const Sample* samples() const { return (const Sample*)data(); }
|
||||
const Frame* samples() const { return (const Frame*)data(); }
|
||||
int sample_count() const { return m_sample_count; }
|
||||
const void* data() const { return m_buffer.data<void>(); }
|
||||
int size_in_bytes() const { return m_sample_count * (int)sizeof(Sample); }
|
||||
int size_in_bytes() const { return m_sample_count * (int)sizeof(Frame); }
|
||||
int id() const { return m_id; }
|
||||
const Core::AnonymousBuffer& anonymous_buffer() const { return m_buffer; }
|
||||
|
||||
private:
|
||||
explicit Buffer(const Vector<Sample> samples)
|
||||
: m_buffer(Core::AnonymousBuffer::create_with_size(samples.size() * sizeof(Sample)))
|
||||
explicit Buffer(const Vector<Frame> samples)
|
||||
: m_buffer(Core::AnonymousBuffer::create_with_size(samples.size() * sizeof(Frame)))
|
||||
, m_id(allocate_id())
|
||||
, m_sample_count(samples.size())
|
||||
{
|
||||
memcpy(m_buffer.data<void>(), samples.data(), samples.size() * sizeof(Sample));
|
||||
memcpy(m_buffer.data<void>(), samples.data(), samples.size() * sizeof(Frame));
|
||||
}
|
||||
|
||||
explicit Buffer(Core::AnonymousBuffer buffer, i32 buffer_id, int sample_count)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue