Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yangyalei
Copy link

Summary

Add vela alsa lib interface

Impact

nop

Testing

Use alsa lib interface play music in allwinnertech platform

@yangyalei yangyalei changed the title Alsa-lib: Add vela alsa lib interface Add vela alsa lib interface Sep 5, 2024
@yangyalei
Copy link
Author

@xiaoxiang781216 @acassis

@xiaoxiang781216
Copy link
Contributor

I will review the change in this weekend.

@yangyalei yangyalei force-pushed the feature-add-vela-alsa-lib branch from 283612d to 4456cb9 Compare September 6, 2024 12:50
audioutils/alsa-lib/Kconfig Outdated Show resolved Hide resolved
@yangyalei yangyalei force-pushed the feature-add-vela-alsa-lib branch from 4456cb9 to a188981 Compare September 9, 2024 02:53
Copy link

@cederom cederom left a 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 :-)

@xiaoxiang781216 xiaoxiang781216 self-requested a review September 13, 2024 05:20
#

config AUDIOUTILS_ALSA_LIB
tristate "Enable ALSA lib"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tristate "Enable ALSA lib"
bool "Enable ALSA lib"


CSRCS += $(wildcard *.c)

EXPORT_FILES := include
Copy link
Contributor

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return (FAR const char *)strerror(errnum);
return strerror(errnum);


/* PCM handle */

typedef struct _snd_pcm snd_pcm_t;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
typedef struct _snd_pcm snd_pcm_t;
typedef struct snd_pcm_s snd_pcm_t;


/* PCM stream (direction) */

typedef enum _snd_pcm_stream
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
typedef enum _snd_pcm_stream
typedef enum snd_pcm_stream_e

uint32_t mask;
};

typedef struct snd_pcm_hw_params
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
union snd_interval
union snd_interval_u


/* hw & sw define */

#define __snd_alloca(ptr, type) \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#define __snd_alloca(ptr, type) \
#define snd_pcm_alloca(ptr, type) \


#define __snd_alloca(ptr, type) \
do { \
*ptr = (FAR type*)alloca(sizeof(type)); \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
*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))
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
struct _snd_pcm
struct snd_pcm_s

}

pcm->state = SND_PCM_STATE_OPEN;
pcm->volume = 50;
Copy link
Contributor

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)
Copy link
Contributor

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;
Copy link
Contributor

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);
Copy link
Contributor

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;
Copy link
Contributor

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;

Copy link
Contributor

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;
Copy link
Contributor

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)
Copy link
Contributor

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int err;
int ret;


#define FORMAT(v) [SND_PCM_FORMAT_##v] = #v

FAR static const char *const snd_pcm_format_names[] =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)
Copy link
Contributor

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)
Copy link
Contributor

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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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;
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
struct _snd_pcm
struct snd_pcm_s

@acassis
Copy link
Contributor

acassis commented Nov 11, 2024

ping @yangyalei

@yangyalei
Copy link
Author

ping @yangyalei

I am preparing a better patch with dmix feature. When I'm ready, I'll replace this patch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants