Commit c42b7219 authored by Tristan Matthews's avatar Tristan Matthews
Browse files

* #7131: cleanup in audiolayer

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