31
31
#include < AK/Vector.h>
32
32
#include < AK/SharedBuffer.h>
33
33
34
+ namespace Audio {
35
+
34
36
// A single sample in an audio buffer.
35
37
// Values are floating point, and should range from -1.0 to +1.0
36
- struct ASample {
37
- ASample ()
38
+ struct Sample {
39
+ Sample ()
38
40
: left(0 )
39
41
, right(0 )
40
42
{
41
43
}
42
44
43
45
// For mono
44
- ASample (float left)
46
+ Sample (float left)
45
47
: left(left)
46
48
, right(left)
47
49
{
48
50
}
49
51
50
52
// For stereo
51
- ASample (float left, float right)
53
+ Sample (float left, float right)
52
54
: left(left)
53
55
, right(right)
54
56
{
@@ -74,7 +76,7 @@ struct ASample {
74
76
right *= pct;
75
77
}
76
78
77
- ASample & operator +=(const ASample & other)
79
+ Sample & operator +=(const Sample & other)
78
80
{
79
81
left += other.left ;
80
82
right += other.right ;
@@ -88,9 +90,9 @@ struct ASample {
88
90
// Small helper to resample from one playback rate to another
89
91
// This isn't really "smart", in that we just insert (or drop) samples.
90
92
// Should do better...
91
- class AResampleHelper {
93
+ class ResampleHelper {
92
94
public:
93
- AResampleHelper (float source, float target);
95
+ ResampleHelper (float source, float target);
94
96
95
97
void process_sample (float sample_l, float sample_r);
96
98
bool read_sample (float & next_l, float & next_r);
@@ -103,34 +105,34 @@ class AResampleHelper {
103
105
};
104
106
105
107
// A buffer of audio samples, normalized to 44100hz.
106
- class ABuffer : public RefCounted <ABuffer > {
108
+ class Buffer : public RefCounted <Buffer > {
107
109
public:
108
- static RefPtr<ABuffer > from_pcm_data (ByteBuffer& data, AResampleHelper & resampler, int num_channels, int bits_per_sample);
109
- static NonnullRefPtr<ABuffer > create_with_samples (Vector<ASample >&& samples)
110
+ static RefPtr<Buffer > from_pcm_data (ByteBuffer& data, ResampleHelper & resampler, int num_channels, int bits_per_sample);
111
+ static NonnullRefPtr<Buffer > create_with_samples (Vector<Sample >&& samples)
110
112
{
111
- return adopt (*new ABuffer (move (samples)));
113
+ return adopt (*new Buffer (move (samples)));
112
114
}
113
- static NonnullRefPtr<ABuffer > create_with_shared_buffer (NonnullRefPtr<SharedBuffer>&& buffer, int sample_count)
115
+ static NonnullRefPtr<Buffer > create_with_shared_buffer (NonnullRefPtr<SharedBuffer>&& buffer, int sample_count)
114
116
{
115
- return adopt (*new ABuffer (move (buffer), sample_count));
117
+ return adopt (*new Buffer (move (buffer), sample_count));
116
118
}
117
119
118
- const ASample * samples () const { return (const ASample *)data (); }
120
+ const Sample * samples () const { return (const Sample *)data (); }
119
121
int sample_count () const { return m_sample_count; }
120
122
const void * data () const { return m_buffer->data (); }
121
- int size_in_bytes () const { return m_sample_count * (int )sizeof (ASample ); }
123
+ int size_in_bytes () const { return m_sample_count * (int )sizeof (Sample ); }
122
124
int shared_buffer_id () const { return m_buffer->shared_buffer_id (); }
123
125
SharedBuffer& shared_buffer () { return *m_buffer; }
124
126
125
127
private:
126
- explicit ABuffer (Vector<ASample >&& samples)
127
- : m_buffer(*SharedBuffer::create_with_size (samples.size() * sizeof(ASample ))),
128
+ explicit Buffer (Vector<Sample >&& samples)
129
+ : m_buffer(*SharedBuffer::create_with_size (samples.size() * sizeof(Sample ))),
128
130
m_sample_count(samples.size())
129
131
{
130
- memcpy (m_buffer->data (), samples.data (), samples.size () * sizeof (ASample ));
132
+ memcpy (m_buffer->data (), samples.data (), samples.size () * sizeof (Sample ));
131
133
}
132
134
133
- explicit ABuffer (NonnullRefPtr<SharedBuffer>&& buffer, int sample_count)
135
+ explicit Buffer (NonnullRefPtr<SharedBuffer>&& buffer, int sample_count)
134
136
: m_buffer(move(buffer)),
135
137
m_sample_count(sample_count)
136
138
{
@@ -139,3 +141,5 @@ class ABuffer : public RefCounted<ABuffer> {
139
141
NonnullRefPtr<SharedBuffer> m_buffer;
140
142
const int m_sample_count;
141
143
};
144
+
145
+ }
0 commit comments