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 #2970

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions audioutils/alsa-lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# ##############################################################################
# apps/audioutils/alsa-lib/CMakeLists.txt
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for
# additional information regarding copyright ownership. The ASF licenses this
# file to you under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
# ##############################################################################

if(CONFIG_AUDIOUTILS_ALSA_LIB)
target_sources(
apps
PRIVATE bits_covert.c
channels_map.c
error.c
pcm_dmix_generic.c
pcm_dmix.c
pcm_hw.c
pcm_params.c
pcm_softvol.c
pcm.c)

add_definitions(-DOUTSIDE_SPEEX)
add_definitions(-DRANDOM_PREFIX=nuttx)
endif()
66 changes: 66 additions & 0 deletions audioutils/alsa-lib/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#

config AUDIOUTILS_ALSA_LIB
bool "Enable ALSA lib"
default n

if AUDIOUTILS_ALSA_LIB

config AUDIOUTILS_ALSA_LIB_DEV_PATH
string "play/recored device path"
default "/dev/audio"

config AUDIOUTILS_ALSA_LIB_DUMP_FLAG
string "play pcm dump flag"
default "/data/alsa_pcm_dump"

config AUDIOUTILS_ALSA_LIB_DUMP_PATH
string "play pcm dump path"
default "/data"

choice
prompt "Alsa Device to be used"
default AUDIOUTILS_ALSA_LIB_DEVICE_DMIX

config AUDIOUTILS_ALSA_LIB_DEVICE_DMIX
bool "Use Dmix device(support mix)"

config AUDIOUTILS_ALSA_LIB_DEVICE_HW
bool "Use hardware device(not support mix, more faster)"

endchoice # Alsa lib Device

config AUDIOUTILS_ALSA_LIB_OUTPUT_FORMAT
int "Dmix output format 0/16/32 (16: S16, 32: S32, 0: use input format)"
default 0

config AUDIOUTILS_ALSA_LIB_OUTPUT_CHANNELS
int "Dmix output channels 0/1/2 (1: 1ch, 2: 2ch, 0: use input channels)"
default 0

config AUDIOUTILS_ALSA_LIB_OUTPUT_RATE
int "Dmix output rate 0/8000/16000/32000/44100/48000/96000 (0: use input rate)"
default 0

choice
prompt "Alsa LOG Output Controls"
default AUDIOUTILS_ALSA_LIB_LOG_INFO

config AUDIOUTILS_ALSA_LIB_LOG_DEBUG
bool "Output DEBUG+ log"

config AUDIOUTILS_ALSA_LIB_LOG_INFO
bool "Output INFO+ log"

config AUDIOUTILS_ALSA_LIB_LOG_WARN
bool "Output WARN+ log"

config AUDIOUTILS_ALSA_LIB_LOG_ERR
bool "Output ERROR+ log"

endchoice # Alsa LOG Output Controls

endif # AUDIOUTILS_ALSA_LIB
28 changes: 28 additions & 0 deletions audioutils/alsa-lib/Make.defs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
############################################################################
# apps/audioutils/alsa-lib/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################

ifneq ($(CONFIG_AUDIOUTILS_ALSA_LIB),)

CONFIGURED_APPS += $(APPDIR)/audioutils/alsa-lib

CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/audioutils/alsa-lib/include
CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/audioutils/alsa-lib/include

endif
27 changes: 27 additions & 0 deletions audioutils/alsa-lib/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
############################################################################
# apps/audioutils/alsa-lib/Makefile
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################

include $(APPDIR)/Make.defs

CSRCS += $(wildcard *.c)

CFLAGS += -DOUTSIDE_SPEEX -DRANDOM_PREFIX=nuttx

include $(APPDIR)/Application.mk
172 changes: 172 additions & 0 deletions audioutils/alsa-lib/bits_convert.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
/****************************************************************************
* apps/audioutils/alsa-lib/bits_convert.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/

/****************************************************************************
* Included Files
****************************************************************************/

#include <stdio.h>

#include "bits_convert.h"
#include "pcm_local.h"

/****************************************************************************
* Public Functions
****************************************************************************/

int bitsconv_init(FAR struct bitsconv_data **bc, int channels,
snd_pcm_format_t src_format, snd_pcm_format_t dst_format,
int buf_size)
{
if (*bc != NULL)
{
return 0;
}

/* support s16->s32, s32->s16 only */

if ((src_format != SND_PCM_FORMAT_S16_LE &&
src_format != SND_PCM_FORMAT_S32_LE) ||
(dst_format != SND_PCM_FORMAT_S16_LE &&
dst_format != SND_PCM_FORMAT_S32_LE))
{
SND_ERR("format not supported! src: %d, dst: %d", src_format,
dst_format);
return -ENOTSUP;
}

*bc = malloc(sizeof(struct bitsconv_data));
if (*bc == NULL)
{
SND_ERR("bitsconv_init failed");
return -ENOMEM;
}

(*bc)->bitsconv_buf = malloc(buf_size);
if ((*bc)->bitsconv_buf == NULL)
{
free(*bc);
*bc = NULL;
SND_ERR("malloc bitsconv_buf failed");
return -ENOMEM;
}

(*bc)->channels = channels;
(*bc)->src_format = src_format;
(*bc)->dst_format = dst_format;
(*bc)->buf_size = buf_size;

return 0;
}

int bitsconv_process(FAR struct bitsconv_data *bc, FAR const void *in_data,
int in_size, FAR void **out_data, FAR int *out_size)
{
int out_len;
int frames;
int ch;

if (!bc)
{
SND_ERR("bitsconv_init not run");
return -EPERM;
}

if (bc->src_format == SND_PCM_FORMAT_S16_LE &&
bc->dst_format == SND_PCM_FORMAT_S32_LE)
{
const int16_t *src;
int32_t *dst;
Comment on lines +95 to +96
Copy link
Member

Choose a reason for hiding this comment

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

FAR


out_len = in_size * bc->channels * sizeof(int32_t);
if (out_len > bc->buf_size)
{
SND_ERR("bitsconv out_buf too small");
return -EPERM;
}

for (ch = 0; ch < bc->channels; ch++)
{
frames = in_size;
src = (const int16_t *)in_data;
dst = (int32_t *)bc->bitsconv_buf;
Comment on lines +108 to +109
Copy link
Member

Choose a reason for hiding this comment

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

FAR

while (frames-- > 0)
{
*(dst + ch) = (int32_t)((*(src + ch)) << 16);
src += bc->channels;
dst += bc->channels;
}
}
}
else if (bc->src_format == SND_PCM_FORMAT_S32_LE &&
bc->dst_format == SND_PCM_FORMAT_S16_LE)
{
int32_t *src;
int16_t *dst;
Comment on lines +121 to +122
Copy link
Member

Choose a reason for hiding this comment

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

FAR


out_len = in_size * bc->channels * sizeof(int16_t);
if (out_len > bc->buf_size)
{
SND_ERR("bitsconv out_buf too small");
return -EPERM;
}

for (ch = 0; ch < bc->channels; ch++)
{
frames = in_size;
src = (int32_t *)in_data;
dst = (int16_t *)bc->bitsconv_buf;
Comment on lines +134 to +135
Copy link
Member

Choose a reason for hiding this comment

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

FAR

while (frames-- > 0)
{
*(dst + ch) = (int16_t)((*(src + ch)) >> 16);
src += bc->channels;
dst += bc->channels;
}
}
}
else
{
SND_ERR("unknown format");
return -ENOTSUP;
}

*out_data = bc->bitsconv_buf;
*out_size = in_size;

return 0;
}

int bitsconv_release(FAR struct bitsconv_data *bc)
{
if (!bc)
{
return 0;
}

if (bc->bitsconv_buf)
{
free(bc->bitsconv_buf);
bc->bitsconv_buf = NULL;
}

free(bc);

return 0;
}
57 changes: 57 additions & 0 deletions audioutils/alsa-lib/bits_convert.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/****************************************************************************
* apps/audioutils/alsa-lib/bits_convert.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/

#ifndef __BITS_CONVERT_H
#define __BITS_CONVERT_H

/****************************************************************************
* Included Files
****************************************************************************/

#include <alsa_pcm.h>

/****************************************************************************
* Public Types
****************************************************************************/

struct bitsconv_data
{
FAR void *bitsconv_buf;
int buf_size;

snd_pcm_format_t src_format;
snd_pcm_format_t dst_format;
int channels;
};

/****************************************************************************
* Public Function Prototypes
****************************************************************************/

int bitsconv_init(FAR struct bitsconv_data **bc, int channels,
snd_pcm_format_t src_format, snd_pcm_format_t dst_format,
int buf_size);

int bitsconv_process(FAR struct bitsconv_data *bc, FAR const void *in_data,
int in_size, FAR void **out_data, FAR int *out_size);

int bitsconv_release(FAR struct bitsconv_data *bc);

#endif /* __BITS_CONVERT_H */
Loading
Loading