-
Notifications
You must be signed in to change notification settings - Fork 571
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
yangyalei
wants to merge
2
commits into
apache:master
Choose a base branch
from
yangyalei:feature-add-alsa
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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