-
Notifications
You must be signed in to change notification settings - Fork 542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add vela alsa lib interface #2553
base: master
Are you sure you want to change the base?
Conversation
I will review the change in this weekend. |
283612d
to
4456cb9
Compare
Signed-off-by: yangyalei <[email protected]>
4456cb9
to
a188981
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good and very nice porting effort that opens door for existing audio applications with ALSA interface.. but I did not have chance to test in practice :-)
# | ||
|
||
config AUDIOUTILS_ALSA_LIB | ||
tristate "Enable ALSA lib" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tristate "Enable ALSA lib" | |
bool "Enable ALSA lib" |
|
||
CSRCS += $(wildcard *.c) | ||
|
||
EXPORT_FILES := include |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove
errnum = -errnum; | ||
} | ||
|
||
return (FAR const char *)strerror(errnum); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return (FAR const char *)strerror(errnum); | |
return strerror(errnum); |
|
||
/* PCM handle */ | ||
|
||
typedef struct _snd_pcm snd_pcm_t; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typedef struct _snd_pcm snd_pcm_t; | |
typedef struct snd_pcm_s snd_pcm_t; |
|
||
/* PCM stream (direction) */ | ||
|
||
typedef enum _snd_pcm_stream |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typedef enum _snd_pcm_stream | |
typedef enum snd_pcm_stream_e |
uint32_t mask; | ||
}; | ||
|
||
typedef struct snd_pcm_hw_params |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typedef struct snd_pcm_hw_params | |
typedef struct snd_pcm_hw_params_s |
SND_PCM_HW_PARAM_FIRST_INTERVAL + 1]; | ||
} snd_pcm_hw_params_t; | ||
|
||
typedef struct snd_pcm_sw_params |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typedef struct snd_pcm_sw_params | |
typedef struct snd_pcm_sw_params_s |
SND_PCM_STATE_PRIVATE1 = 1024 | ||
} snd_pcm_state_t; | ||
|
||
union snd_interval |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
union snd_interval | |
union snd_interval_u |
|
||
/* hw & sw define */ | ||
|
||
#define __snd_alloca(ptr, type) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#define __snd_alloca(ptr, type) \ | |
#define snd_pcm_alloca(ptr, type) \ |
|
||
#define __snd_alloca(ptr, type) \ | ||
do { \ | ||
*ptr = (FAR type*)alloca(sizeof(type)); \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*ptr = (FAR type*)alloca(sizeof(type)); \ | |
*ptr = (FAR type *)alloca(sizeof(type)); \ |
#define DEFAULT_AUDIO_PERIODS 4 | ||
#define DEFAULT_AUDIO_PERIOD_TIME 10 * 1000 | ||
|
||
#define FFMIN(a, b) ((a) > (b) ? (b) : (a)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use MIN macro directly
* Private Data | ||
****************************************************************************/ | ||
|
||
struct _snd_pcm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
struct _snd_pcm | |
struct snd_pcm_s |
} | ||
|
||
pcm->state = SND_PCM_STATE_OPEN; | ||
pcm->volume = 50; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why 50
return -errno; | ||
} | ||
|
||
if (nonblock && !stat.mq_curmsgs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
call mq_time_receive instead
struct audio_buf_desc_s buf_desc; | ||
int now; | ||
int old = dq_count(&pcm->bufferq); | ||
bool nonblock = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add blank line
int snd_pcm_close(FAR snd_pcm_t *pcm) | ||
{ | ||
struct audio_buf_desc_s buf_desc; | ||
int dc = dq_count(&pcm->bufferq); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add blank line
{ | ||
snd_pcm_ioctl(pcm->fd, AUDIOIOC_STOP, 0); | ||
pcm->running = false; | ||
pcm->stopping = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove stoping use state instead
} | ||
|
||
pcm->state = SND_PCM_STATE_SUSPENDED; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove
|
||
int snd_pcm_delay(FAR snd_pcm_t *pcm, FAR snd_pcm_sframes_t *delayp) | ||
{ | ||
int ret; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add blank line
return size - snd_pcm_bytes_to_frames(pcm, left); | ||
} | ||
|
||
int snd_pcm_set_volume(FAR snd_pcm_t *pcm, int volume) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it alsa standard api?
|
||
int snd_pcm_hw_params(FAR snd_pcm_t *pcm, FAR snd_pcm_hw_params_t *params) | ||
{ | ||
int err; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int err; | |
int ret; | |
|
||
#define FORMAT(v) [SND_PCM_FORMAT_##v] = #v | ||
|
||
FAR static const char *const snd_pcm_format_names[] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FAR static const char *const snd_pcm_format_names[] = | |
FAR static const char *const g_snd_pcm_format_names[] = |
move to private data section
* Hw Functions | ||
****************************************************************************/ | ||
|
||
static inline int hw_is_mask(int var) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move all static functions to private function section
* Hw Functions | ||
****************************************************************************/ | ||
|
||
static inline int hw_is_mask(int var) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make all function prefix with snd_pcm_
var <= SND_PCM_HW_PARAM_LAST_RANGE; | ||
} | ||
|
||
static int _snd_pcm_hw_param_set(FAR snd_pcm_hw_params_t *params, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static int _snd_pcm_hw_param_set(FAR snd_pcm_hw_params_t *params, | |
static int snd_pcm_hw_param_set(FAR snd_pcm_hw_params_t *params, |
return 0; | ||
} | ||
|
||
static int _snd_pcm_hw_param_get(FAR const snd_pcm_hw_params_t *params, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static int _snd_pcm_hw_param_get(FAR const snd_pcm_hw_params_t *params, | |
static int snd_pcm_hw_param_get(FAR const snd_pcm_hw_params_t *params, |
#define _snd_pcm_hw_param_get(params, var, val) \ | ||
_snd_pcm_hw_param_get(params, var, (FAR unsigned int *)(val)) | ||
|
||
static int _snd_pcm_hw_params_internal(FAR snd_pcm_t *pcm, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static int _snd_pcm_hw_params_internal(FAR snd_pcm_t *pcm, | |
static int snd_pcm_hw_params_internal(FAR snd_pcm_t *pcm, |
if (period_size && buffer_size) | ||
{ | ||
pcm->periods = buffer_size / period_size; | ||
pcm->period_time = period_size * 1000 * 1000 / pcm->sample_rate; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we save period_size, not period_time internally to avoid the conversion in multiple places
* Pre-processor Prototypes | ||
****************************************************************************/ | ||
|
||
#define DEFAULT_AUDIO_PERIODS 4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add SND_PCM_ prefix to ALL macros
* Private Data | ||
****************************************************************************/ | ||
|
||
struct _snd_pcm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
struct _snd_pcm | |
struct snd_pcm_s |
ping @yangyalei |
I am preparing a better patch with dmix feature. When I'm ready, I'll replace this patch |
Summary
Add vela alsa lib interface
Impact
nop
Testing
Use alsa lib interface play music in allwinnertech platform