Commit c42b7219 authored by Tristan Matthews's avatar Tristan Matthews

* #7131: cleanup in audiolayer

parent 35dae9e9
......@@ -44,7 +44,7 @@ class AlsaThread : public ost::Thread {
terminate();
}
virtual void run(void);
virtual void run();
private:
AlsaThread(const AlsaThread& at);
......@@ -62,7 +62,7 @@ AlsaThread::AlsaThread(AlsaLayer *alsa)
/**
* Reimplementation of run()
*/
void AlsaThread::run(void)
void AlsaThread::run()
{
while (!testCancel()) {
alsa_->audioCallback();
......@@ -91,7 +91,7 @@ AlsaLayer::AlsaLayer()
}
// Destructor
AlsaLayer::~AlsaLayer(void)
AlsaLayer::~AlsaLayer()
{
delete audioThread_;
......@@ -127,7 +127,7 @@ bool AlsaLayer::openDevice(snd_pcm_t **pcm, const std::string &dev, snd_pcm_stre
}
void
AlsaLayer::startStream(void)
AlsaLayer::startStream()
{
dcblocker_.reset();
......@@ -184,7 +184,7 @@ AlsaLayer::startStream(void)
}
void
AlsaLayer::stopStream(void)
AlsaLayer::stopStream()
{
isStarted_ = false;
......@@ -222,7 +222,7 @@ AlsaLayer::stopStream(void)
err_code; \
})
void AlsaLayer::stopCaptureStream(void)
void AlsaLayer::stopCaptureStream()
{
if (captureHandle_ && ALSA_CALL(snd_pcm_drop(captureHandle_), "couldn't stop capture") >= 0) {
is_capture_running_ = false;
......@@ -230,7 +230,7 @@ void AlsaLayer::stopCaptureStream(void)
}
}
void AlsaLayer::closeCaptureStream(void)
void AlsaLayer::closeCaptureStream()
{
if (is_capture_prepared_ and is_capture_running_)
stopCaptureStream();
......@@ -239,14 +239,14 @@ void AlsaLayer::closeCaptureStream(void)
is_capture_open_ = false;
}
void AlsaLayer::startCaptureStream(void)
void AlsaLayer::startCaptureStream()
{
if (captureHandle_ and not is_capture_running_)
if (ALSA_CALL(snd_pcm_start(captureHandle_), "Couldn't start capture") >= 0)
is_capture_running_ = true;
}
void AlsaLayer::stopPlaybackStream(void)
void AlsaLayer::stopPlaybackStream()
{
if (ringtoneHandle_ and is_playback_running_)
ALSA_CALL(snd_pcm_drop(ringtoneHandle_), "Couldn't stop ringtone");
......@@ -260,7 +260,7 @@ void AlsaLayer::stopPlaybackStream(void)
}
void AlsaLayer::closePlaybackStream(void)
void AlsaLayer::closePlaybackStream()
{
if (is_playback_prepared_ and is_playback_running_)
stopPlaybackStream();
......@@ -275,21 +275,21 @@ void AlsaLayer::closePlaybackStream(void)
}
void AlsaLayer::startPlaybackStream(void)
void AlsaLayer::startPlaybackStream()
{
if (playbackHandle_ and not is_playback_running_)
if (ALSA_CALL(snd_pcm_start(playbackHandle_), "Couldn't start playback") >= 0)
is_playback_running_ = true;
}
void AlsaLayer::prepareCaptureStream(void)
void AlsaLayer::prepareCaptureStream()
{
if (is_capture_open_ and not is_capture_prepared_)
if (ALSA_CALL(snd_pcm_prepare(captureHandle_), "Couldn't prepare capture") >= 0)
is_capture_prepared_ = true;
}
void AlsaLayer::preparePlaybackStream(void)
void AlsaLayer::preparePlaybackStream()
{
if (is_playback_open_ and not is_playback_prepared_)
if (ALSA_CALL(snd_pcm_prepare(playbackHandle_), "Couldn't prepare playback") >= 0)
......@@ -523,7 +523,7 @@ void adjustVolume(SFLDataFormat *src , int samples, int volumePercentage)
}
}
void AlsaLayer::capture(void)
void AlsaLayer::capture()
{
unsigned int mainBufferSampleRate = Manager::instance().getMainBuffer()->getInternalSamplingRate();
bool resample = audioSampleRate_ != mainBufferSampleRate;
......@@ -628,7 +628,7 @@ void AlsaLayer::playback(int maxSamples)
free(out);
}
void AlsaLayer::audioCallback(void)
void AlsaLayer::audioCallback()
{
if (!playbackHandle_ or !captureHandle_)
return;
......
......@@ -52,14 +52,14 @@ AudioLayer::~AudioLayer()
delete converter_;
}
void AudioLayer::flushMain(void)
void AudioLayer::flushMain()
{
ost::MutexLock guard(mutex_);
// should pass call id
Manager::instance().getMainBuffer()->flushAllBuffers();
}
void AudioLayer::flushUrgent(void)
void AudioLayer::flushUrgent()
{
ost::MutexLock guard(mutex_);
urgentRingBuffer_.flushAll();
......
......@@ -30,56 +30,45 @@
#include "audiorecorder.h"
#include "mainbuffer.h"
#include <assert.h>
#include <cassert>
int AudioRecorder::count = 0;
int AudioRecorder::count_ = 0;
AudioRecorder::AudioRecorder(AudioRecord *arec, MainBuffer *mb) : Thread()
AudioRecorder::AudioRecorder(AudioRecord *arec, MainBuffer *mb) : Thread(), mbuffer_(mb), arecord_(arec)
{
assert(mb);
setCancel(cancelDeferred);
++count;
++count_;
std::string id("processid_");
// convert count into string
std::string s;
std::stringstream out;
out << count;
out << count_;
s = out.str();
recorderId = id.append(s);
arecord = arec;
mbuffer = mb;
recorderId_ = id.append(s);
}
/**
* Reimplementation of run()
*/
void AudioRecorder::run()
{
int bufferLength = 10000;
SFLDataFormat buffer[bufferLength];
while (true) {
int availBytes = mbuffer->availForGet(recorderId);
int availBytes = mbuffer_->availForGet(recorderId_);
int toGet = (availBytes < bufferLength) ? availBytes : bufferLength;
mbuffer->getData(buffer, toGet, recorderId);
if (availBytes > 0) {
mbuffer_->getData(buffer, toGet, recorderId_);
arecord->recData(buffer, availBytes/sizeof(SFLDataFormat));
}
if (availBytes > 0)
arecord_->recData(buffer, availBytes / sizeof(SFLDataFormat));
sleep(20);
}
}
......@@ -42,14 +42,14 @@ class AudioRecorder : public ost::Thread {
public:
AudioRecorder(AudioRecord *arec, MainBuffer *mb);
~AudioRecorder(void) {
~AudioRecorder() {
terminate();
}
static int count;
static int count_;
std::string getRecorderID() {
return recorderId;
std::string getRecorderID() const {
return recorderId_;
}
virtual void run();
......@@ -58,11 +58,11 @@ class AudioRecorder : public ost::Thread {
AudioRecorder(const AudioRecorder& ar);
AudioRecorder& operator= (const AudioRecorder& ar);
std::string recorderId;
std::string recorderId_;
MainBuffer *mbuffer;
MainBuffer *mbuffer_;
AudioRecord *arecord;
AudioRecord *arecord_;
};
#endif
......@@ -83,7 +83,7 @@ class G722 : public sfl::AudioCodec {
}
void g722_encode_init(void) {
void g722_encode_init() {
encode_s->itu_test_mode = FALSE;
// 8 => 64 kbps; 7 => 56 kbps; 6 => 48 kbps
......@@ -108,7 +108,7 @@ class G722 : public sfl::AudioCodec {
decode_s->out_bits = 0;
}
void g722_decode_init(void) {
void g722_decode_init() {
decode_s->itu_test_mode = FALSE;
......
......@@ -64,7 +64,7 @@ class Gsm : public sfl::AudioCodec {
Gsm& operator= (const Gsm&);
virtual ~Gsm(void) {
virtual ~Gsm() {
gsm_destroy(decode_gsmhandle_);
gsm_destroy(encode_gsmhandle_);
}
......
......@@ -32,37 +32,37 @@
#include "noisesuppress.h"
NoiseSuppress::NoiseSuppress(int smplPerFrame, int samplingRate)
: _smplPerFrame(smplPerFrame)
: smplPerFrame_(smplPerFrame)
{
_noiseState = speex_preprocess_state_init(_smplPerFrame, samplingRate);
noiseState_ = speex_preprocess_state_init(smplPerFrame_, samplingRate);
int i=1;
speex_preprocess_ctl(_noiseState, SPEEX_PREPROCESS_SET_DENOISE, &i);
speex_preprocess_ctl(noiseState_, SPEEX_PREPROCESS_SET_DENOISE, &i);
i=-20;
speex_preprocess_ctl(_noiseState, SPEEX_PREPROCESS_SET_NOISE_SUPPRESS, &i);
speex_preprocess_ctl(noiseState_, SPEEX_PREPROCESS_SET_NOISE_SUPPRESS, &i);
i=0;
speex_preprocess_ctl(_noiseState, SPEEX_PREPROCESS_SET_AGC, &i);
speex_preprocess_ctl(noiseState_, SPEEX_PREPROCESS_SET_AGC, &i);
i=8000;
speex_preprocess_ctl(_noiseState, SPEEX_PREPROCESS_SET_AGC_TARGET, &i);
speex_preprocess_ctl(noiseState_, SPEEX_PREPROCESS_SET_AGC_TARGET, &i);
i=16000;
speex_preprocess_ctl(_noiseState, SPEEX_PREPROCESS_SET_AGC_LEVEL, &i);
speex_preprocess_ctl(noiseState_, SPEEX_PREPROCESS_SET_AGC_LEVEL, &i);
i=0;
speex_preprocess_ctl(_noiseState, SPEEX_PREPROCESS_SET_DEREVERB, &i);
speex_preprocess_ctl(noiseState_, SPEEX_PREPROCESS_SET_DEREVERB, &i);
float f=0.0;
speex_preprocess_ctl(_noiseState, SPEEX_PREPROCESS_SET_DEREVERB_DECAY, &f);
speex_preprocess_ctl(noiseState_, SPEEX_PREPROCESS_SET_DEREVERB_DECAY, &f);
f=0.0;
speex_preprocess_ctl(_noiseState, SPEEX_PREPROCESS_SET_DEREVERB_LEVEL, &f);
speex_preprocess_ctl(noiseState_, SPEEX_PREPROCESS_SET_DEREVERB_LEVEL, &f);
i = 0;
speex_preprocess_ctl(_noiseState, SPEEX_PREPROCESS_SET_VAD, &i);
speex_preprocess_ctl(noiseState_, SPEEX_PREPROCESS_SET_VAD, &i);
}
NoiseSuppress::~NoiseSuppress()
{
speex_preprocess_state_destroy(_noiseState);
speex_preprocess_state_destroy(noiseState_);
}
void NoiseSuppress::process(SFLDataFormat *data, int samples)
{
assert(_smplPerFrame == samples);
speex_preprocess_run(_noiseState, data);
assert(smplPerFrame_ == samples);
speex_preprocess_run(noiseState_, data);
}
......@@ -36,18 +36,14 @@
class NoiseSuppress {
public:
NoiseSuppress(int smplPerFrame, int samplingRate);
~NoiseSuppress(void);
~NoiseSuppress();
void process(SFLDataFormat *data, int samples);
private:
SpeexPreprocessState *_noiseState;
int _smplPerFrame;
SpeexPreprocessState *noiseState_;
int smplPerFrame_;
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment