23
AudioBuffer::AudioBuffer()
28
void AudioBuffer::Reset()
36
void AudioBuffer::Play(Sample *smpl, int vol, int pan, bool loop)
54
streaming = sample->getStreaming();
59
// if not streaming sample - preload & premix the whole thing
63
length = sample->getLength();
65
if (sample->getNumChannels() == 1)
71
buff = (Sint16*)malloc(length * 4);
80
uint AudioBuffer::PanAndMix(uint req_lenth)
83
Sint16 *tb = sample->getSampleData(req_lenth, rl);
85
double v1 = (double)vol / 100;
86
double v2 = (double)vol / 100;
91
v1 = ((double)(vol - pan)) / 100;
97
v2 = ((double)(vol + pan)) / 100;
104
bool mixasis = false;
106
if ((vol == 100) && (pan == 0))
23
AudioBuffer::AudioBuffer()
32
void AudioBuffer::Play(Sample *smpl, int vol, int pan, bool loop)
50
streaming = sample->getStreaming();
55
// if not streaming sample - preload & premix the whole thing
59
length = sample->getLength();
113
61
if (sample->getNumChannels() == 1)
120
for (uint f = 0; f < rl; f+=2)
124
buff[f] = (Sint16)(((double)*lc) * v1);
125
buff[f + 1] = (Sint16)(((double)*rc) * v2);
140
AudioBuffer::~AudioBuffer()
146
Sint16 *AudioBuffer::getMix(uint requested_length, uint &returned_length)
150
uint oldoffs = offset;
152
if ((offset + requested_length) < length)
154
returned_length = requested_length;
158
returned_length = length - offset;
170
offset += returned_length;
171
return buff + oldoffs;
175
if (requested_length != bufflen)
180
buff = (Sint16*)malloc(requested_length * 4);
181
bufflen = requested_length;
184
returned_length = PanAndMix(requested_length);
185
if (returned_length < requested_length)
67
buff = (Sint16*)malloc(length * 4);
76
uint AudioBuffer::PanAndMix(uint req_lenth)
79
Sint16 *tb = sample->getSampleData(req_lenth, rl);
81
double v1 = (double)vol / 100;
82
double v2 = (double)vol / 100;
87
v1 = ((double)(vol - pan)) / 100;
93
v2 = ((double)(vol + pan)) / 100;
100
bool mixasis = false;
102
if ((vol == 100) && (pan == 0))
109
if (sample->getNumChannels() == 1)
116
for (uint f = 0; f < rl; f+=2)
120
buff[f] = (Sint16)(((double)*lc) * v1);
121
buff[f + 1] = (Sint16)(((double)*rc) * v2);
136
AudioBuffer::~AudioBuffer()
142
Sint16 *AudioBuffer::getMix(uint requested_length, uint &returned_length)
146
uint oldoffs = offset;
148
if ((offset + requested_length) < length)
150
returned_length = requested_length;
154
returned_length = length - offset;
166
offset += returned_length;
167
return buff + oldoffs;
200
void AudioBuffer::Stop()
171
if (requested_length != bufflen)
176
buff = (Sint16*)malloc(requested_length * 4);
177
bufflen = requested_length;
180
returned_length = PanAndMix(requested_length);
181
if (returned_length < requested_length)
196
void AudioBuffer::Stop()