summaryrefslogtreecommitdiff
path: root/drivers/alsa
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2017-03-05 16:44:50 +0100
committerRémi Verschelde <rverschelde@gmail.com>2017-03-05 16:44:50 +0100
commit5dbf1809c6e3e905b94b8764e99491e608122261 (patch)
tree5e5a5360db15d86d59ec8c6e4f7eb511388c5a9a /drivers/alsa
parent45438e9918d421b244bfd7776a30e67dc7f2d3e3 (diff)
A Whole New World (clang-format edition)
I can show you the code Pretty, with proper whitespace Tell me, coder, now when did You last write readable code? I can open your eyes Make you see your bad indent Force you to respect the style The core devs agreed upon A whole new world A new fantastic code format A de facto standard With some sugar Enforced with clang-format A whole new world A dazzling style we all dreamed of And when we read it through It's crystal clear That now we're in a whole new world of code
Diffstat (limited to 'drivers/alsa')
-rw-r--r--drivers/alsa/audio_driver_alsa.cpp100
-rw-r--r--drivers/alsa/audio_driver_alsa.h17
2 files changed, 56 insertions, 61 deletions
diff --git a/drivers/alsa/audio_driver_alsa.cpp b/drivers/alsa/audio_driver_alsa.cpp
index f2616b11b8..7e445c7c10 100644
--- a/drivers/alsa/audio_driver_alsa.cpp
+++ b/drivers/alsa/audio_driver_alsa.cpp
@@ -36,27 +36,26 @@
Error AudioDriverALSA::init() {
- active=false;
- thread_exited=false;
- exit_thread=false;
+ active = false;
+ thread_exited = false;
+ exit_thread = false;
pcm_open = false;
samples_in = NULL;
samples_out = NULL;
- mix_rate = GLOBAL_DEF("audio/mix_rate",44100);
+ mix_rate = GLOBAL_DEF("audio/mix_rate", 44100);
speaker_mode = SPEAKER_MODE_STEREO;
channels = 2;
-
- int status;
+ int status;
snd_pcm_hw_params_t *hwparams;
snd_pcm_sw_params_t *swparams;
-#define CHECK_FAIL(m_cond)\
- if (m_cond) {\
- fprintf(stderr,"ALSA ERR: %s\n",snd_strerror(status));\
- snd_pcm_close(pcm_handle);\
- ERR_FAIL_COND_V(m_cond,ERR_CANT_OPEN);\
+#define CHECK_FAIL(m_cond) \
+ if (m_cond) { \
+ fprintf(stderr, "ALSA ERR: %s\n", snd_strerror(status)); \
+ snd_pcm_close(pcm_handle); \
+ ERR_FAIL_COND_V(m_cond, ERR_CANT_OPEN); \
}
//todo, add
@@ -65,81 +64,80 @@ Error AudioDriverALSA::init() {
status = snd_pcm_open(&pcm_handle, "default", SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
- ERR_FAIL_COND_V( status<0, ERR_CANT_OPEN );
+ ERR_FAIL_COND_V(status < 0, ERR_CANT_OPEN);
snd_pcm_hw_params_alloca(&hwparams);
status = snd_pcm_hw_params_any(pcm_handle, hwparams);
- CHECK_FAIL( status<0 );
+ CHECK_FAIL(status < 0);
status = snd_pcm_hw_params_set_access(pcm_handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED);
- CHECK_FAIL( status<0 );
+ CHECK_FAIL(status < 0);
//not interested in anything else
status = snd_pcm_hw_params_set_format(pcm_handle, hwparams, SND_PCM_FORMAT_S16_LE);
- CHECK_FAIL( status<0 );
+ CHECK_FAIL(status < 0);
//todo: support 4 and 6
status = snd_pcm_hw_params_set_channels(pcm_handle, hwparams, 2);
- CHECK_FAIL( status<0 );
+ CHECK_FAIL(status < 0);
status = snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams, &mix_rate, NULL);
- CHECK_FAIL( status<0 );
+ CHECK_FAIL(status < 0);
- int latency = GLOBAL_DEF("audio/output_latency",25);
- buffer_size = nearest_power_of_2( latency * mix_rate / 1000 );
+ int latency = GLOBAL_DEF("audio/output_latency", 25);
+ buffer_size = nearest_power_of_2(latency * mix_rate / 1000);
// set buffer size from project settings
status = snd_pcm_hw_params_set_buffer_size_near(pcm_handle, hwparams, &buffer_size);
- CHECK_FAIL( status<0 );
+ CHECK_FAIL(status < 0);
- // make period size 1/8
+ // make period size 1/8
period_size = buffer_size >> 3;
status = snd_pcm_hw_params_set_period_size_near(pcm_handle, hwparams, &period_size, NULL);
- CHECK_FAIL( status<0 );
+ CHECK_FAIL(status < 0);
- unsigned int periods=2;
+ unsigned int periods = 2;
status = snd_pcm_hw_params_set_periods_near(pcm_handle, hwparams, &periods, NULL);
- CHECK_FAIL( status<0 );
+ CHECK_FAIL(status < 0);
- status = snd_pcm_hw_params(pcm_handle,hwparams);
- CHECK_FAIL( status<0 );
+ status = snd_pcm_hw_params(pcm_handle, hwparams);
+ CHECK_FAIL(status < 0);
//snd_pcm_hw_params_free(&hwparams);
-
snd_pcm_sw_params_alloca(&swparams);
status = snd_pcm_sw_params_current(pcm_handle, swparams);
- CHECK_FAIL( status<0 );
+ CHECK_FAIL(status < 0);
status = snd_pcm_sw_params_set_avail_min(pcm_handle, swparams, period_size);
- CHECK_FAIL( status<0 );
+ CHECK_FAIL(status < 0);
status = snd_pcm_sw_params_set_start_threshold(pcm_handle, swparams, 1);
- CHECK_FAIL( status<0 );
+ CHECK_FAIL(status < 0);
status = snd_pcm_sw_params(pcm_handle, swparams);
- CHECK_FAIL( status<0 );
+ CHECK_FAIL(status < 0);
- samples_in = memnew_arr(int32_t, period_size*channels);
- samples_out = memnew_arr(int16_t, period_size*channels);
+ samples_in = memnew_arr(int32_t, period_size * channels);
+ samples_out = memnew_arr(int16_t, period_size * channels);
snd_pcm_nonblock(pcm_handle, 0);
- mutex=Mutex::create();
+ mutex = Mutex::create();
thread = Thread::create(AudioDriverALSA::thread_func, this);
return OK;
};
-void AudioDriverALSA::thread_func(void* p_udata) {
+void AudioDriverALSA::thread_func(void *p_udata) {
- AudioDriverALSA* ad = (AudioDriverALSA*)p_udata;
+ AudioDriverALSA *ad = (AudioDriverALSA *)p_udata;
while (!ad->exit_thread) {
if (!ad->active) {
- for (unsigned int i=0; i < ad->period_size*ad->channels; i++) {
+ for (unsigned int i = 0; i < ad->period_size * ad->channels; i++) {
ad->samples_out[i] = 0;
};
} else {
@@ -149,36 +147,35 @@ void AudioDriverALSA::thread_func(void* p_udata) {
ad->unlock();
- for(unsigned int i=0;i<ad->period_size*ad->channels;i++) {
- ad->samples_out[i]=ad->samples_in[i]>>16;
+ for (unsigned int i = 0; i < ad->period_size * ad->channels; i++) {
+ ad->samples_out[i] = ad->samples_in[i] >> 16;
}
};
-
int todo = ad->period_size;
int total = 0;
while (todo) {
if (ad->exit_thread)
break;
- uint8_t* src = (uint8_t*)ad->samples_out;
- int wrote = snd_pcm_writei(ad->pcm_handle, (void*)(src + (total*ad->channels)), todo);
+ uint8_t *src = (uint8_t *)ad->samples_out;
+ int wrote = snd_pcm_writei(ad->pcm_handle, (void *)(src + (total * ad->channels)), todo);
if (wrote < 0) {
if (ad->exit_thread)
break;
- if ( wrote == -EAGAIN ) {
+ if (wrote == -EAGAIN) {
//can't write yet (though this is blocking..)
- usleep(1000);
+ usleep(1000);
continue;
}
wrote = snd_pcm_recover(ad->pcm_handle, wrote, 0);
- if ( wrote < 0 ) {
+ if (wrote < 0) {
//absolute fail
fprintf(stderr, "ALSA failed and can't recover: %s\n", snd_strerror(wrote));
- ad->active=false;
- ad->exit_thread=true;
+ ad->active = false;
+ ad->exit_thread = true;
break;
}
continue;
@@ -189,8 +186,7 @@ void AudioDriverALSA::thread_func(void* p_udata) {
};
};
- ad->thread_exited=true;
-
+ ad->thread_exited = true;
};
void AudioDriverALSA::start() {
@@ -247,11 +243,11 @@ void AudioDriverALSA::finish() {
AudioDriverALSA::AudioDriverALSA() {
mutex = NULL;
- thread=NULL;
- pcm_handle=NULL;
+ thread = NULL;
+ pcm_handle = NULL;
};
-AudioDriverALSA::~AudioDriverALSA() {
+AudioDriverALSA::~AudioDriverALSA(){
};
diff --git a/drivers/alsa/audio_driver_alsa.h b/drivers/alsa/audio_driver_alsa.h
index 6ab98312b2..e545b7a511 100644
--- a/drivers/alsa/audio_driver_alsa.h
+++ b/drivers/alsa/audio_driver_alsa.h
@@ -30,22 +30,22 @@
#ifdef ALSA_ENABLED
-#include "core/os/thread.h"
#include "core/os/mutex.h"
+#include "core/os/thread.h"
#include <alsa/asoundlib.h>
class AudioDriverALSA : public AudioDriver {
- Thread* thread;
- Mutex* mutex;
+ Thread *thread;
+ Mutex *mutex;
- snd_pcm_t* pcm_handle;
+ snd_pcm_t *pcm_handle;
- int32_t* samples_in;
- int16_t* samples_out;
+ int32_t *samples_in;
+ int16_t *samples_out;
- static void thread_func(void* p_udata);
+ static void thread_func(void *p_udata);
unsigned int mix_rate;
SpeakerMode speaker_mode;
@@ -60,8 +60,7 @@ class AudioDriverALSA : public AudioDriver {
bool pcm_open;
public:
-
- const char* get_name() const {
+ const char *get_name() const {
return "ALSA";
};