Commit dd69d700 authored by Adrien Béraud's avatar Adrien Béraud

use references instead of pointers to AudioBuffer

parent 70292c55
......@@ -711,12 +711,12 @@ void AlsaLayer::capture()
if (resample) {
int outSamples = toGetSamples * (static_cast<double>(sampleRate_) / mainBufferSampleRate);
AudioBuffer rsmpl_out(outSamples, 1, mainBufferSampleRate);
converter_.resample(&in, &rsmpl_out);
dcblocker_.process(&rsmpl_out);
Manager::instance().getMainBuffer().putData(&rsmpl_out, MainBuffer::DEFAULT_ID);
converter_.resample(in, rsmpl_out);
dcblocker_.process(rsmpl_out);
Manager::instance().getMainBuffer().putData(rsmpl_out, MainBuffer::DEFAULT_ID);
} else {
dcblocker_.process(&in);
Manager::instance().getMainBuffer().putData(&in, MainBuffer::DEFAULT_ID);
dcblocker_.process(in);
Manager::instance().getMainBuffer().putData(in, MainBuffer::DEFAULT_ID);
}
}
......@@ -734,9 +734,9 @@ void AlsaLayer::playback(int maxSamples)
AudioBuffer out(maxSamples, 1, sampleRate_);
if (tone)
tone->getNext(&out, getPlaybackGain());
tone->getNext(out, getPlaybackGain());
else if (file_tone && !ringtoneHandle_)
file_tone->getNext(&out, getPlaybackGain());
file_tone->getNext(out, getPlaybackGain());
write(out.getChannel()->data(), bytesToPut, playbackHandle_);
} else {
......@@ -759,7 +759,7 @@ void AlsaLayer::playback(int maxSamples)
AudioBuffer out(samplesToGet, 1, mainBufferSampleRate);
//SFLAudioSample * const out_ptr = &(*out.getChannel()->begin());
Manager::instance().getMainBuffer().getData(&out, MainBuffer::DEFAULT_ID);
Manager::instance().getMainBuffer().getData(out, MainBuffer::DEFAULT_ID);
//AudioLayer::applyGain(out_ptr, samplesToGet, getPlaybackGain());
out.applyGain(getPlaybackGain());
......@@ -770,7 +770,7 @@ void AlsaLayer::playback(int maxSamples)
//std::vector<SFLAudioSample> rsmpl_out(outSamples);
//SFLAudioSample * const rsmpl_out_ptr = &(*rsmpl_out.begin());
//converter_.resample(out_ptr, rsmpl_out_ptr, rsmpl_out.size(), mainBufferSampleRate, sampleRate_, samplesToGet);
converter_.resample(&out, &rsmpl_out);
converter_.resample(out, rsmpl_out);
write(rsmpl_out.getChannel()->data(), outBytes, playbackHandle_);
} else {
write(out.getChannel()->data(), bytesToGet, playbackHandle_);
......@@ -797,7 +797,7 @@ void AlsaLayer::audioCallback()
// Urgent data (dtmf, incoming call signal) come first.
samplesToGet = std::min(samplesToGet, (unsigned)playbackAvailSmpl);
AudioBuffer out(samplesToGet);
urgentRingBuffer_.get(&out, MainBuffer::DEFAULT_ID);
urgentRingBuffer_.get(out, MainBuffer::DEFAULT_ID);
out.applyGain(getPlaybackGain());
write(out.getChannel()->data(), samplesToGet*sizeof(SFLAudioSample), playbackHandle_);
......@@ -819,7 +819,7 @@ void AlsaLayer::audioCallback()
if (file_tone) {
DEBUG("playback gain %d", getPlaybackGain());
file_tone->getNext(&out, getPlaybackGain());
file_tone->getNext(out, getPlaybackGain());
}
write(out.getChannel()->data(), ringtoneAvailBytes, ringtoneHandle_);
......
......@@ -172,25 +172,25 @@ size_t AudioBuffer::mix(const AudioBuffer& other)
return samp_num;
}
size_t AudioBuffer::copy(AudioBuffer* in, int sample_num /* = -1 */, size_t pos_in /* = 0 */, size_t pos_out /* = 0 */)
size_t AudioBuffer::copy(AudioBuffer& in, int sample_num /* = -1 */, size_t pos_in /* = 0 */, size_t pos_out /* = 0 */)
{
if(sample_num == -1)
sample_num = in->samples();
sample_num = in.samples();
int to_copy = std::min((int)in->samples()-(int)pos_in, sample_num);
int to_copy = std::min((int)in.samples()-(int)pos_in, sample_num);
if(to_copy <= 0) return 0;
const size_t chan_num = std::min(in->channels_, channels_);
const size_t chan_num = std::min(in.channels_, channels_);
if(pos_out+to_copy > sampleNum_)
resize(pos_out+to_copy);
sampleRate_ = in->sampleRate_;
sampleRate_ = in.sampleRate_;
//setChannelNum(chan_num);
unsigned i;
for(i=0; i<chan_num; i++) {
std::copy(in->samples_[i].begin()+pos_in, in->samples_[i].begin()+pos_in+to_copy, samples_[i].begin()+pos_out);
std::copy(in.samples_[i].begin()+pos_in, in.samples_[i].begin()+pos_in+to_copy, samples_[i].begin()+pos_out);
}
return to_copy;
......@@ -198,6 +198,7 @@ size_t AudioBuffer::copy(AudioBuffer* in, int sample_num /* = -1 */, size_t pos_
size_t AudioBuffer::copy(SFLAudioSample* in, size_t sample_num, size_t pos_out /* = 0 */)
{
if(in == NULL) return 0;
if(pos_out+sample_num > sampleNum_)
resize(pos_out+sample_num);
......@@ -206,4 +207,5 @@ size_t AudioBuffer::copy(SFLAudioSample* in, size_t sample_num, size_t pos_out /
for(i=0; i<chan_num; i++) {
std::copy(in, in+sample_num, samples_[i].begin()+pos_out);
}
return sample_num;
}
......@@ -152,7 +152,7 @@ class AudioBuffer {
* The number of channels is changed to match the in channel number.
* Buffer sample number is also increased if required to hold the new requested samples.
*/
size_t copy(AudioBuffer* in, int sample_num=-1, size_t pos_in=0, size_t pos_out=0);
size_t copy(AudioBuffer& in, int sample_num=-1, size_t pos_in=0, size_t pos_out=0);
/**
* Copy sample_num samples from in to this (at sample pos_out).
......
......@@ -70,7 +70,7 @@ void AudioLayer::flushUrgent()
urgentRingBuffer_.flushAll();
}
void AudioLayer::putUrgent(AudioBuffer* buffer)
void AudioLayer::putUrgent(AudioBuffer& buffer)
{
sfl::ScopedLock guard(mutex_);
urgentRingBuffer_.put(buffer);
......@@ -97,10 +97,10 @@ void AudioLayer::notifyIncomingCall()
Tone tone("440/160", getSampleRate());
unsigned int nbSample = tone.getSize();
AudioBuffer buf(nbSample);
tone.getNext(&buf);
tone.getNext(buf);
/* Put the data in the urgent ring buffer */
flushUrgent();
putUrgent(&buf);
putUrgent(buf);
}
......@@ -122,7 +122,7 @@ class AudioLayer {
* Copy data in the urgent buffer.
* @param buffer The buffer containing the data to be played ( ringtones )
*/
void putUrgent(AudioBuffer* buffer);
void putUrgent(AudioBuffer& buffer);
/**
* Flush main buffer
......
......@@ -65,7 +65,7 @@ static unsigned int updatePlaybackScale = 0;
void
//AudioLoop::getNext(SFLAudioSample* output, size_t total_samples, short volume)
AudioLoop::getNext(AudioBuffer* output, unsigned int volume)
AudioLoop::getNext(AudioBuffer& output, unsigned int volume)
{
if(!buffer_) {
ERROR("AudioLoop::buffer_ is not set (NULL pointer)");
......@@ -74,7 +74,7 @@ AudioLoop::getNext(AudioBuffer* output, unsigned int volume)
const size_t buf_samples = buffer_->samples();
size_t pos = pos_;
size_t total_samples = output->samples();
size_t total_samples = output.samples();
size_t output_pos = 0;
if (buf_samples == 0) {
......@@ -94,7 +94,7 @@ AudioLoop::getNext(AudioBuffer* output, unsigned int volume)
// short->char conversion
//memcpy(output, buffer_ + pos, samples * sizeof(SFLAudioSample));
//buffer_.copy(output, pos, samples);
output->copy(buffer_, samples, pos, output_pos);
output.copy(*buffer_, samples, pos, output_pos);
// Scaling needed
/*if (volume != 100) {
......@@ -111,7 +111,7 @@ AudioLoop::getNext(AudioBuffer* output, unsigned int volume)
total_samples -= samples;
}
output->applyGain(volume); // apply volume
output.applyGain(volume); // apply volume
pos_ = pos;
......
......@@ -57,7 +57,7 @@ class AudioLoop {
* @param volume The volume
*/
//void getNext(SFLAudioSample* output, size_t samples, short volume=100);
void getNext(AudioBuffer* output, unsigned int volume=100);
void getNext(AudioBuffer& output, unsigned int volume=100);
void seek(double relative_position);
......
......@@ -417,7 +417,7 @@ void AudioRecord::closeWavFile()
}
//void AudioRecord::recData(SFLDataFormat* buffer, size_t nSamples)
void AudioRecord::recData(AudioBuffer* buffer)
void AudioRecord::recData(AudioBuffer& buffer)
{
if (recordingEnabled_) {
if (fileHandle_ == 0) {
......@@ -425,9 +425,9 @@ void AudioRecord::recData(AudioBuffer* buffer)
return;
}
size_t nSamples = buffer->samples();
size_t nSamples = buffer.samples();
if (fwrite(buffer->getChannel(), sizeof(SFLAudioSample), nSamples, fileHandle_) != nSamples)
if (fwrite(buffer.getChannel(), sizeof(SFLAudioSample), nSamples, fileHandle_) != nSamples)
WARN("Could not record data! ");
else {
fflush(fileHandle_);
......
......@@ -104,7 +104,7 @@ class AudioRecord {
* @param nSamples Number of samples (number of bytes) to be recorded
*/
//void recData(SFLDataFormat* buffer, size_t nSamples);
void recData(AudioBuffer* buffer);
void recData(AudioBuffer& buffer);
protected:
......
......@@ -89,10 +89,10 @@ void AudioRecorder::run()
while (running_) {
const size_t availableBytes = mbuffer_->availableForGet(recorderId_);
buffer.resize(std::min(availableBytes, BUFFER_LENGTH));
mbuffer_->getData(&buffer, recorderId_);
mbuffer_->getData(buffer, recorderId_);
if (availableBytes > 0)
arecord_->recData(&buffer);
arecord_->recData(buffer);
usleep(20000); // 20 ms
}
......
......@@ -295,7 +295,7 @@ int AudioRtpRecordHandler::processDataEncode()
SFLAudioSample *micData = audioRtpRecord_.decData_.data();
const size_t bytes = Manager::instance().getMainBuffer().getData(micData, bytesToGet, id_);*/
AudioBuffer micData(samplesToGet);
const size_t samps = Manager::instance().getMainBuffer().getData(&micData, id_);
const size_t samps = Manager::instance().getMainBuffer().getData(micData, id_);
#ifdef RECTODISK
rtpNotResampled.write((const char *)micData, bytes);
......@@ -326,7 +326,7 @@ int AudioRtpRecordHandler::processDataEncode()
*/
audioRtpRecord_.resampledData_.setSampleRate(codecSampleRate);
audioRtpRecord_.converterEncode_->resample(&micData, &(audioRtpRecord_.resampledData_));
audioRtpRecord_.converterEncode_->resample(micData, audioRtpRecord_.resampledData_);
#ifdef RECTODISK
rtpResampled.write((const char *)audioRtpRecord_.resampledData_.data(), samplesToGet*sizeof(SFLAudioSample)/2 );
......@@ -339,7 +339,7 @@ int AudioRtpRecordHandler::processDataEncode()
if (Manager::instance().audioPreference.getNoiseReduce()) {
ScopedLock lock(audioRtpRecord_.audioProcessMutex_);
RETURN_IF_NULL(audioRtpRecord_.noiseSuppressEncode_, 0, "Noise suppressor already destroyed");
audioRtpRecord_.noiseSuppressEncode_->process(&micData, getCodecFrameSize());
audioRtpRecord_.noiseSuppressEncode_->process(micData, getCodecFrameSize());
}
#endif
......@@ -347,7 +347,7 @@ int AudioRtpRecordHandler::processDataEncode()
ScopedLock lock(audioRtpRecord_.audioCodecMutex_);
RETURN_IF_NULL(audioRtpRecord_.getCurrentCodec(), 0, "Audio codec already destroyed");
unsigned char *micDataEncoded = audioRtpRecord_.encodedData_.data();
return audioRtpRecord_.getCurrentCodec()->encode(micDataEncoded, out, getCodecFrameSize());
return audioRtpRecord_.getCurrentCodec()->encode(micDataEncoded, *out, getCodecFrameSize());
}
}
#undef RETURN_IF_NULL
......@@ -373,29 +373,29 @@ void AudioRtpRecordHandler::processDataDecode(unsigned char *spkrData, size_t si
int inSamples = 0;
size = std::min(size, audioRtpRecord_.decData_.samples());
//SFLAudioSample *spkrDataDecoded = audioRtpRecord_.decData_.data();
AudioBuffer *spkrDataDecoded = &(audioRtpRecord_.decData_);
//AudioBuffer *spkrDataDecoded = &(audioRtpRecord_.decData_);
{
ScopedLock lock(audioRtpRecord_.audioCodecMutex_);
RETURN_IF_NULL(audioRtpRecord_.getCurrentCodec(), "Audio codecs already destroyed");
// Return the size of data in samples
inSamples = audioRtpRecord_.getCurrentCodec()->decode(spkrDataDecoded, spkrData, size);
inSamples = audioRtpRecord_.getCurrentCodec()->decode(audioRtpRecord_.decData_, spkrData, size);
}
#if HAVE_SPEEXDSP
if (Manager::instance().audioPreference.getNoiseReduce()) {
ScopedLock lock(audioRtpRecord_.audioProcessMutex_);
RETURN_IF_NULL(audioRtpRecord_.noiseSuppressDecode_, "Noise suppressor already destroyed");
audioRtpRecord_.noiseSuppressDecode_->process(spkrDataDecoded, getCodecFrameSize());
audioRtpRecord_.noiseSuppressDecode_->process(audioRtpRecord_.decData_, getCodecFrameSize());
}
#endif
audioRtpRecord_.fadeInDecodedData();//(inSamples);
// Normalize incomming signal
gainController.process(spkrDataDecoded);
gainController.process(audioRtpRecord_.decData_);
AudioBuffer *out = spkrDataDecoded;
AudioBuffer *out = &(audioRtpRecord_.decData_);
int outSamples = inSamples;
int codecSampleRate = out->getSampleRate();//getCodecSampleRate();
......@@ -407,14 +407,14 @@ void AudioRtpRecordHandler::processDataDecode(unsigned char *spkrData, size_t si
out = &(audioRtpRecord_.resampledData_);
// Do sample rate conversion
//outSamples = ((float) inSamples * ((float) mainBufferSampleRate / (float) codecSampleRate));
audioRtpRecord_.converterDecode_->resample(spkrDataDecoded, out);
audioRtpRecord_.converterDecode_->resample(audioRtpRecord_.decData_, audioRtpRecord_.resampledData_);
/*audioRtpRecord_.converterDecode_->resample(spkrDataDecoded, out,
audioRtpRecord_.resampledData_.size(), codecSampleRate,
mainBufferSampleRate, inSamples);*/
}
//Manager::instance().getMainBuffer().putData(out, outSamples * sizeof(SFLAudioSample), id_);
Manager::instance().getMainBuffer().putData(out, id_);
Manager::instance().getMainBuffer().putData(*out, id_);
}
#undef RETURN_IF_NULL
......
......@@ -59,15 +59,15 @@ AudioCodec::AudioCodec(const AudioCodec& c) :
hasDynamicPayload_(c.hasDynamicPayload_)
{}
int AudioCodec::decode(AudioBuffer* dst, unsigned char *buf, size_t buffer_size, size_t dst_offset /* = 0 */)
int AudioCodec::decode(AudioBuffer& dst, unsigned char *buf, size_t buffer_size, size_t dst_offset /* = 0 */)
{
dst->setSampleRate(clockRate_);
return decode(&(*(dst->getChannel()->begin()+dst_offset)), buf, buffer_size);
dst.setSampleRate(clockRate_);
return decode(&(*(dst.getChannel()->begin()+dst_offset)), buf, buffer_size);
}
int AudioCodec::encode(unsigned char *dst, AudioBuffer* src, size_t buffer_size)
int AudioCodec::encode(unsigned char *dst, AudioBuffer& src, size_t buffer_size)
{
return encode(dst, src->getChannel()->data(), buffer_size);
return encode(dst, src.getChannel()->data(), buffer_size);
}
std::string AudioCodec::getMimeSubtype() const
......
......@@ -81,13 +81,13 @@ class AudioCodec {
* Multichannel version of decode().
* Default implementation decode(short *, unsigned char *, size_t) to the first channel (assume 1 channel).
*/
int decode(AudioBuffer* dst, unsigned char *buf, size_t buffer_size, size_t dst_offset=0);
int decode(AudioBuffer& dst, unsigned char *buf, size_t buffer_size, size_t dst_offset=0);
/**
* Multichannel version of encode().
* Default implementation calls encode() on the first channel (assume 1 channel).
*/
int encode(unsigned char *dst, AudioBuffer* src, size_t buffer_size);
int encode(unsigned char *dst, AudioBuffer& src, size_t buffer_size);
uint8 getPayloadType() const;
......
......@@ -41,7 +41,7 @@ void DcBlocker::reset()
void DcBlocker::doProcess(SFLAudioSample *out, SFLAudioSample *in, int samples, struct StreamState * state)
{
for (int i = 0; i < samples; ++i) {
for (unsigned i = 0; i < samples; ++i) {
state->x_ = in[i];
state->y_ = (SFLAudioSample) ((float) state->x_ - (float) state->xm1_ + 0.9999 * (float) state->y_);
......@@ -50,24 +50,24 @@ void DcBlocker::doProcess(SFLAudioSample *out, SFLAudioSample *in, int samples,
out[i] = state->y_;
}
}
void DcBlocker::process(SFLAudioSample *out, SFLAudioSample *in, int samples)
{
if(out == NULL or in == NULL or samples == 0) return;
doProcess(out, in, samples, &states[0]);
}
void DcBlocker::process(AudioBuffer *buf)
void DcBlocker::process(AudioBuffer& buf)
{
const size_t chans = buf->channels();
const size_t samples = buf->samples();
const size_t chans = buf.channels();
const size_t samples = buf.samples();
if(chans > states.size())
states.resize(buf->channels(), (struct StreamState){0, 0, 0, 0});
states.resize(buf.channels(), (struct StreamState){0, 0, 0, 0});
unsigned i;
for(i=0; i<chans; i++) {
SFLAudioSample *chan = buf->getChannel(i)->data();
SFLAudioSample *chan = buf.getChannel(i)->data();
doProcess(chan, chan, samples, &states[i]);
}
}
......
......@@ -45,7 +45,7 @@ class DcBlocker {
/**
* In-place processing of all samples in buf (each channel treated independently)
*/
void process(AudioBuffer *buf);
void process(AudioBuffer& buf);
private:
struct StreamState {
......
......@@ -56,9 +56,9 @@ GainControl::GainControl(double sr, double target) : averager_(sr, SFL_GAIN_ATTA
DEBUG("Target gain %f dB (%f linear)", targetLeveldB_, targetLevelLinear_);
}
void GainControl::process(AudioBuffer * buf)
void GainControl::process(AudioBuffer& buf)
{
process(buf->getChannel()->data(), buf->samples());
process(buf.getChannel()->data(), buf.samples());
}
void GainControl::process(SFLAudioSample *buf, int samples)
......
......@@ -50,7 +50,7 @@ class GainControl {
* /param Input samples
*/
void process(SFLAudioSample *, int samples);
void process(AudioBuffer * buf);
void process(AudioBuffer& buf);
private:
class DetectionAverage {
......
......@@ -236,7 +236,7 @@ void MainBuffer::unBindAll(const std::string & call_id)
}
//void MainBuffer::putData(void *buffer, size_t toCopy, const std::string &call_id)
void MainBuffer::putData(AudioBuffer* buffer, const std::string &call_id)
void MainBuffer::putData(AudioBuffer& buffer, const std::string &call_id)
{
sfl::ScopedLock guard(mutex_);
......@@ -247,7 +247,7 @@ void MainBuffer::putData(AudioBuffer* buffer, const std::string &call_id)
}
//size_t MainBuffer::getData(void *buffer, size_t toCopy, const std::string &call_id)
size_t MainBuffer::getData(AudioBuffer* buffer, const std::string &call_id)
size_t MainBuffer::getData(AudioBuffer& buffer, const std::string &call_id)
{
sfl::ScopedLock guard(mutex_);
......@@ -265,11 +265,11 @@ size_t MainBuffer::getData(AudioBuffer* buffer, const std::string &call_id)
else
return 0;
} else {
buffer->clear();//memset(buffer, 0, toCopy);
buffer->setSampleRate(internalSamplingRate_);
buffer.clear();//memset(buffer, 0, toCopy);
buffer.setSampleRate(internalSamplingRate_);
size_t size = 0;
AudioBuffer mixBuffer(*buffer);
AudioBuffer mixBuffer(buffer);
for (CallIDSet::iterator iter_id = callid_set->begin();
iter_id != callid_set->end(); ++iter_id) {
......@@ -277,13 +277,13 @@ size_t MainBuffer::getData(AudioBuffer* buffer, const std::string &call_id)
SFLDataFormat mixBuffer[nbSmplToCopy];
memset(mixBuffer, 0, toCopy);
size = getDataByID(mixBuffer, toCopy, *iter_id, call_id);*/
size = getDataByID(&mixBuffer, *iter_id, call_id);
size = getDataByID(mixBuffer, *iter_id, call_id);
if (size > 0) {
/*SFLDataFormat *dest = static_cast<SFLDataFormat*>(buffer);
for (size_t k = 0; k < nbSmplToCopy; ++k)
dest[k] += mixBuffer[k];*/
buffer->mix(mixBuffer);
buffer.mix(mixBuffer);
}
}
......@@ -291,7 +291,7 @@ size_t MainBuffer::getData(AudioBuffer* buffer, const std::string &call_id)
}
}
size_t MainBuffer::getDataByID(AudioBuffer *buffer, const std::string & call_id, const std::string & reader_id)
size_t MainBuffer::getDataByID(AudioBuffer& buffer, const std::string & call_id, const std::string & reader_id)
{
RingBuffer* ring_buffer = getRingBuffer(call_id);
return ring_buffer ? ring_buffer->get(buffer, reader_id) : 0;
......
......@@ -83,10 +83,10 @@ class MainBuffer {
void unBindAll(const std::string &call_id);
//void putData(void *buffer, size_t toCopy, const std::string &call_id);
void putData(AudioBuffer* buffer, const std::string &call_id);
void putData(AudioBuffer& buffer, const std::string &call_id);
//size_t getData(void *buffer, size_t toCopy, const std::string &call_id);
size_t getData(AudioBuffer* buffer, const std::string &call_id);
size_t getData(AudioBuffer& buffer, const std::string &call_id);
size_t availableForGet(const std::string &call_id);
......@@ -124,7 +124,7 @@ class MainBuffer {
const RingBuffer* getRingBuffer(const std::string & call_id) const;
//size_t getDataByID(void *buffer, size_t toCopy, const std::string &call_id, const std::string &reader_id);
size_t getDataByID(AudioBuffer *buffer, const std::string &call_id, const std::string &reader_id);
size_t getDataByID(AudioBuffer& buffer, const std::string &call_id, const std::string &reader_id);
size_t availableForGetByID(const std::string &call_id, const std::string &reader_id) const;
......
......@@ -62,9 +62,9 @@ NoiseSuppress::~NoiseSuppress()
noiseState_ = 0;
}
void NoiseSuppress::process(AudioBuffer *buff, int samples)
void NoiseSuppress::process(AudioBuffer& buff, int samples)
{
SFLAudioSample* data = buff->getChannel()->data();
SFLAudioSample* data = buff.getChannel()->data();
if (noiseState_) {
assert(smplPerFrame_ == samples);
speex_preprocess_run(noiseState_, data);
......
......@@ -40,7 +40,7 @@ class NoiseSuppress {
NoiseSuppress(int smplPerFrame, int samplingRate);
~NoiseSuppress();
//void process(SFLAudioSample *data, int samples);
void process(AudioBuffer *buf, int samples);
void process(AudioBuffer& buf, int samples);
private:
NON_COPYABLE(NoiseSuppress);
......
......@@ -386,7 +386,7 @@ void PulseLayer::writeToSpeaker()
if (urgentBytes) {
AudioBuffer linearbuff(urgentSamples, n_channels);
pa_stream_begin_write(s, (void**)&data, &urgentBytes);
urgentRingBuffer_.get(&linearbuff, MainBuffer::DEFAULT_ID); // retrive only the first sample_spec->channels channels
urgentRingBuffer_.get(linearbuff, MainBuffer::DEFAULT_ID); // retrive only the first sample_spec->channels channels
linearbuff.applyGain(getPlaybackGain());
linearbuff.interleave(data);
pa_stream_write(s, data, urgentBytes, NULL, 0, PA_SEEK_RELATIVE);
......@@ -403,7 +403,7 @@ void PulseLayer::writeToSpeaker()
if (playback_->isReady()) {
pa_stream_begin_write(s, (void**)&data, &writableBytes);
AudioBuffer linearbuff(writableSamples, n_channels);
toneToPlay->getNext(&linearbuff, getPlaybackGain()); // retrive only n_channels
toneToPlay->getNext(linearbuff, getPlaybackGain()); // retrive only n_channels
linearbuff.interleave(data);
pa_stream_write(s, data, writableBytes, NULL, 0, PA_SEEK_RELATIVE);
}
......@@ -441,11 +441,11 @@ void PulseLayer::writeToSpeaker()
pa_stream_begin_write(s, (void**)&data, &resampledBytes);
AudioBuffer linearbuff(readableSamples, n_channels);
Manager::instance().getMainBuffer().getData(&linearbuff, MainBuffer::DEFAULT_ID);
Manager::instance().getMainBuffer().getData(linearbuff, MainBuffer::DEFAULT_ID);
if (resample) {
AudioBuffer rsmpl_out(nResampled, 1, sampleRate_);
converter_.resample(&linearbuff, &rsmpl_out);
converter_.resample(linearbuff, rsmpl_out);
rsmpl_out.applyGain(getPlaybackGain());
rsmpl_out.interleave(data);
pa_stream_write(s, data, resampledBytes, NULL, 0, PA_SEEK_RELATIVE);
......@@ -499,14 +499,14 @@ void PulseLayer::readFromMic()
if (resample) {
mic_buffer_.setSampleRate(mainBufferSampleRate);
//converter_.resample((SFLAudioSample*)data, mic_buffer_, samples, mainBufferSampleRate, sampleRate_, samples);
converter_.resample(&in, &mic_buffer_);
converter_.resample(in, mic_buffer_);
out = &mic_buffer_;
}
dcblocker_.process(out);
dcblocker_.process(*out);
out->applyGain(getCaptureGain());
//applyGain(mic_buffer_, bytes / sizeof(SFLAudioSample), getCaptureGain());
Manager::instance().getMainBuffer().putData(out, MainBuffer::DEFAULT_ID);
Manager::instance().getMainBuffer().putData(*out, MainBuffer::DEFAULT_ID);