13
0

ALSA backend: code cleanup and scoping and indent

This is combination of clang-format and manual edits.
The latter mainly to add braces and reduce scope of variables.
This commit is contained in:
Robin Gareus 2021-05-16 00:08:03 +02:00
parent 6801c2cac2
commit 14961e6bc7
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
4 changed files with 1171 additions and 1104 deletions

File diff suppressed because it is too large Load Diff

View File

@ -20,13 +20,13 @@
#ifndef __libbackend_alsa_audiobackend_h__ #ifndef __libbackend_alsa_audiobackend_h__
#define __libbackend_alsa_audiobackend_h__ #define __libbackend_alsa_audiobackend_h__
#include <string>
#include <vector>
#include <map> #include <map>
#include <set> #include <set>
#include <string>
#include <vector>
#include <stdint.h>
#include <pthread.h> #include <pthread.h>
#include <stdint.h>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
@ -41,10 +41,10 @@
#include "ardouralsautil/deviceinfo.h" #include "ardouralsautil/deviceinfo.h"
#include "zita-alsa-pcmi.h"
#include "alsa_rawmidi.h" #include "alsa_rawmidi.h"
#include "alsa_sequencer.h" #include "alsa_sequencer.h"
#include "alsa_slave.h" #include "alsa_slave.h"
#include "zita-alsa-pcmi.h"
namespace ARDOUR { namespace ARDOUR {

File diff suppressed because it is too large Load Diff

View File

@ -1,23 +1,20 @@
// ---------------------------------------------------------------------------- /*
// * Copyright (C) 2006-2012 Fons Adriaensen <fons@linuxaudio.org>
// Copyright (C) 2006-2012 Fons Adriaensen <fons@linuxaudio.org> * Copyright (C) 2014-2021 Robin Gareus <robin@gareus.org>
// Copyright (C) 2014-2021 Robin Gareus <robin@gareus.org> *
// * This program is free software; you can redistribute it and/or modify
// This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
// it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or
// the Free Software Foundation; either version 3 of the License, or * (at your option) any later version.
// (at your option) any later version. *
// * This program is distributed in the hope that it will be useful,
// This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of
// but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details.
// GNU General Public License for more details. *
// * You should have received a copy of the GNU General Public License
// You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>.
// along with this program. If not, see <http://www.gnu.org/licenses/>. */
//
// ----------------------------------------------------------------------------
#ifndef _ZITA_ALSA_PCMI_H_ #ifndef _ZITA_ALSA_PCMI_H_
#define _ZITA_ALSA_PCMI_H_ #define _ZITA_ALSA_PCMI_H_
@ -31,21 +28,19 @@
class Alsa_pcmi class Alsa_pcmi
{ {
public: public:
Alsa_pcmi ( Alsa_pcmi (
const char *play_name, const char* play_name,
const char *capt_name, const char* capt_name,
const char *ctrl_name, const char* ctrl_name,
unsigned int rate, unsigned int rate,
unsigned int frsize, unsigned int frsize,
unsigned int play_nfrags, unsigned int play_nfrags,
unsigned int capt_nfrags, unsigned int capt_nfrags,
unsigned int debug = 0); unsigned int debug = 0);
~Alsa_pcmi (void); ~Alsa_pcmi (void);
enum enum {
{
DEBUG_INIT = 0x001, DEBUG_INIT = 0x001,
DEBUG_STAT = 0x002, DEBUG_STAT = 0x002,
DEBUG_WAIT = 0x004, DEBUG_WAIT = 0x004,
@ -60,17 +55,18 @@ public:
int pcm_start (void); int pcm_start (void);
int pcm_stop (void); int pcm_stop (void);
snd_pcm_sframes_t pcm_wait (void);
int pcm_idle (int len); int pcm_idle (int len);
int play_init (snd_pcm_uframes_t len); snd_pcm_sframes_t pcm_wait (void);
void clear_chan (int chan, int len);
void play_chan (int chan, const float *src, int len, int step = 1);
int play_done (int len);
int capt_init (snd_pcm_uframes_t len); int play_init (snd_pcm_uframes_t len);
void capt_chan (int chan, float *dst, int len, int step = 1); void clear_chan (int chan, int len);
int capt_done (int len); void play_chan (int chan, const float* src, int len, int step = 1);
int play_done (int len);
int capt_init (snd_pcm_uframes_t len);
void capt_chan (int chan, float* dst, int len, int step = 1);
int capt_done (int len);
int play_avail (void) int play_avail (void)
{ {
@ -102,84 +98,86 @@ public:
int state (void) const { return _state; } int state (void) const { return _state; }
size_t fsize (void) const { return _fsize; } size_t fsize (void) const { return _fsize; }
uint32_t fsamp (void) const { return _fsamp; } uint32_t fsamp (void) const { return _fsamp; }
uint32_t play_nfrag (void) const { return _play_nfrag; } uint32_t play_nfrag (void) const { return _play_nfrag; }
uint32_t capt_nfrag (void) const { return _capt_nfrag; } uint32_t capt_nfrag (void) const { return _capt_nfrag; }
uint32_t nplay (void) const { return _play_nchan; } uint32_t nplay (void) const { return _play_nchan; }
uint32_t ncapt (void) const { return _capt_nchan; } uint32_t ncapt (void) const { return _capt_nchan; }
snd_pcm_t *play_handle (void) const { return _play_handle; }
snd_pcm_t *capt_handle (void) const { return _capt_handle; }
snd_pcm_t* play_handle (void) const { return _play_handle; }
snd_pcm_t* capt_handle (void) const { return _capt_handle; }
private: private:
typedef char* (Alsa_pcmi::*clear_function) (char*, int);
typedef char* (Alsa_pcmi::*play_function) (const float*, char*, int, int);
typedef const char* (Alsa_pcmi::*capt_function) (const char*, float*, int, int);
typedef char *(Alsa_pcmi::*clear_function)(char *, int); enum { MAXPFD = 16,
typedef char *(Alsa_pcmi::*play_function)(const float *, char *, int, int); MAXCHAN = 128 };
typedef const char *(Alsa_pcmi::*capt_function) (const char *, float *, int, int);
enum { MAXPFD = 16, MAXCHAN = 128 }; void initialise (const char* play_name, const char* capt_name, const char* ctrl_name);
int set_hwpar (snd_pcm_t* handle, snd_pcm_hw_params_t* hwpar, const char* sname, unsigned int nfrag, unsigned int* nchan);
int set_swpar (snd_pcm_t* handle, snd_pcm_sw_params_t* swpar, const char* sname);
int recover (void);
float xruncheck (snd_pcm_status_t* stat);
void initialise (const char *play_name, const char *capt_name, const char *ctrl_name); char* clear_32 (char* dst, int nfrm);
int set_hwpar (snd_pcm_t *handle, snd_pcm_hw_params_t *hwpar, const char *sname, unsigned int nfrag, unsigned int *nchan); char* clear_24 (char* dst, int nfrm);
int set_swpar (snd_pcm_t *handle, snd_pcm_sw_params_t *swpar, const char *sname); char* clear_16 (char* dst, int nfrm);
int recover (void);
float xruncheck (snd_pcm_status_t *stat);
char *clear_32 (char *dst, int nfrm); char* play_float (const float* src, char* dst, int nfrm, int step);
char *clear_24 (char *dst, int nfrm); char* play_32 (const float* src, char* dst, int nfrm, int step);
char *clear_16 (char *dst, int nfrm); char* play_24 (const float* src, char* dst, int nfrm, int step);
char* play_16 (const float* src, char* dst, int nfrm, int step);
char* play_32swap (const float* src, char* dst, int nfrm, int step);
char* play_24swap (const float* src, char* dst, int nfrm, int step);
char* play_16swap (const float* src, char* dst, int nfrm, int step);
char *play_float (const float *src, char *dst, int nfrm, int step); const char* capt_float (const char* src, float* dst, int nfrm, int step);
char *play_32 (const float *src, char *dst, int nfrm, int step); const char* capt_32 (const char* src, float* dst, int nfrm, int step);
char *play_24 (const float *src, char *dst, int nfrm, int step); const char* capt_24 (const char* src, float* dst, int nfrm, int step);
char *play_16 (const float *src, char *dst, int nfrm, int step); const char* capt_16 (const char* src, float* dst, int nfrm, int step);
char *play_32swap (const float *src, char *dst, int nfrm, int step); const char* capt_32swap (const char* src, float* dst, int nfrm, int step);
char *play_24swap (const float *src, char *dst, int nfrm, int step); const char* capt_24swap (const char* src, float* dst, int nfrm, int step);
char *play_16swap (const float *src, char *dst, int nfrm, int step); const char* capt_16swap (const char* src, float* dst, int nfrm, int step);
const char *capt_float (const char *src, float *dst, int nfrm, int step); unsigned int _fsamp;
const char *capt_32 (const char *src, float *dst, int nfrm, int step); snd_pcm_uframes_t _fsize;
const char *capt_24 (const char *src, float *dst, int nfrm, int step); unsigned int _play_nfrag;
const char *capt_16 (const char *src, float *dst, int nfrm, int step); unsigned int _real_nfrag;
const char *capt_32swap (const char *src, float *dst, int nfrm, int step); unsigned int _capt_nfrag;
const char *capt_24swap (const char *src, float *dst, int nfrm, int step); unsigned int _debug;
const char *capt_16swap (const char *src, float *dst, int nfrm, int step); int _state;
snd_pcm_t* _play_handle;
unsigned int _fsamp; snd_pcm_t* _capt_handle;
snd_pcm_uframes_t _fsize; snd_ctl_t* _ctrl_handle;
unsigned int _play_nfrag; snd_pcm_hw_params_t* _play_hwpar;
unsigned int _real_nfrag; snd_pcm_sw_params_t* _play_swpar;
unsigned int _capt_nfrag; snd_pcm_hw_params_t* _capt_hwpar;
unsigned int _debug; snd_pcm_sw_params_t* _capt_swpar;
int _state; snd_pcm_format_t _play_format;
snd_pcm_t *_play_handle; snd_pcm_format_t _capt_format;
snd_pcm_t *_capt_handle; snd_pcm_access_t _play_access;
snd_ctl_t *_ctrl_handle; snd_pcm_access_t _capt_access;
snd_pcm_hw_params_t *_play_hwpar; unsigned int _play_nchan;
snd_pcm_sw_params_t *_play_swpar; unsigned int _capt_nchan;
snd_pcm_hw_params_t *_capt_hwpar; float _play_xrun;
snd_pcm_sw_params_t *_capt_swpar; float _capt_xrun;
snd_pcm_format_t _play_format; bool _synced;
snd_pcm_format_t _capt_format; int _play_npfd;
snd_pcm_access_t _play_access; int _capt_npfd;
snd_pcm_access_t _capt_access; struct pollfd _poll_fd[MAXPFD];
unsigned int _play_nchan; snd_pcm_uframes_t _capt_offs;
unsigned int _capt_nchan; snd_pcm_uframes_t _play_offs;
float _play_xrun; int _play_step;
float _capt_xrun; int _capt_step;
bool _synced; char* _play_ptr[MAXCHAN];
int _play_npfd; const char* _capt_ptr[MAXCHAN];
int _capt_npfd; clear_function _clear_func;
struct pollfd _poll_fd [MAXPFD]; play_function _play_func;
snd_pcm_uframes_t _capt_offs; capt_function _capt_func;
snd_pcm_uframes_t _play_offs; void* _dummy[16];
int _play_step;
int _capt_step;
char *_play_ptr [MAXCHAN];
const char *_capt_ptr [MAXCHAN];
clear_function _clear_func;
play_function _play_func;
capt_function _capt_func;
void *_dummy [16];
}; };
#endif #endif