Compare commits
No commits in common. "7facfe997caefbe0612ca18ce2be11892fd65c66" and "56d75943a198bee6f888f7afd16a13f4e89bc1a0" have entirely different histories.
7facfe997c
...
56d75943a1
|
@ -1 +0,0 @@
|
||||||
BasedOnStyle: LLVM
|
|
|
@ -1,16 +0,0 @@
|
||||||
{
|
|
||||||
"name": "Open PineBuds Pro - VS Code Development Environment",
|
|
||||||
"build": {
|
|
||||||
"dockerfile": "../Dockerfile",
|
|
||||||
"context": ".."
|
|
||||||
},
|
|
||||||
"extensions": [
|
|
||||||
"ms-vscode.cmake-tools",
|
|
||||||
"ms-vscode.cpptools"
|
|
||||||
],
|
|
||||||
"runArgs": [
|
|
||||||
"--privileged"
|
|
||||||
],
|
|
||||||
"userEnvProbe": "loginInteractiveShell",
|
|
||||||
"remoteUser": "root"
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
version: 2
|
|
||||||
updates:
|
|
||||||
- package-ecosystem: "docker"
|
|
||||||
directory: "/"
|
|
||||||
schedule:
|
|
||||||
interval: "weekly"
|
|
||||||
commit-message:
|
|
||||||
prefix: "chore(deps)"
|
|
||||||
|
|
||||||
- package-ecosystem: "github-actions"
|
|
||||||
directory: "/"
|
|
||||||
schedule:
|
|
||||||
interval: "weekly"
|
|
||||||
commit-message:
|
|
||||||
prefix: "chore(ci)"
|
|
|
@ -1,36 +0,0 @@
|
||||||
name: Container image builder workflow
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [main]
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
concurrency:
|
|
||||||
group: gh-ref-${{ github.ref }}
|
|
||||||
cancel-in-progress: true
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build-and-push-images:
|
|
||||||
if: ${{ github.repository == 'pine64/OpenPineBuds' }}
|
|
||||||
name: Build and push container image for PineBuds Pro SDK to GHCR.io
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout sources
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Build images
|
|
||||||
id: build
|
|
||||||
uses: redhat-actions/buildah-build@v2
|
|
||||||
with:
|
|
||||||
image: ${{ github.repository }}
|
|
||||||
context: /
|
|
||||||
tags: ${{ contains(github.ref_name, 'main') && 'latest' || github.ref_name }}-sdk
|
|
||||||
containerfiles: /Dockerfile
|
|
||||||
|
|
||||||
- name: Push container
|
|
||||||
uses: redhat-actions/push-to-registry@v2
|
|
||||||
with:
|
|
||||||
image: ${{ steps.build.outputs.image }}
|
|
||||||
tags: ${{ steps.build.outputs.tags }}
|
|
||||||
registry: ghcr.io
|
|
||||||
username: ${{ github.repository_owner }}
|
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
@ -1,17 +0,0 @@
|
||||||
name: CI
|
|
||||||
|
|
||||||
on: [push, pull_request]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build-firmware:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
container:
|
|
||||||
image: ghcr.io/pine64/openpinebuds:latest-sdk
|
|
||||||
steps:
|
|
||||||
- name: Build the main firmware
|
|
||||||
run: cd /usr/src/ && ./build.sh || cat /usr/src/log.txt
|
|
||||||
|
|
||||||
- name: Archive produced firmware
|
|
||||||
uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
path: /usr/src/out/open_source/open_source.bin
|
|
|
@ -18,8 +18,6 @@
|
||||||
!.gitignore
|
!.gitignore
|
||||||
!.gitattributes
|
!.gitattributes
|
||||||
!.mailmap
|
!.mailmap
|
||||||
!.github
|
|
||||||
!.devcontainer
|
|
||||||
|
|
||||||
# Backup files
|
# Backup files
|
||||||
*~
|
*~
|
||||||
|
@ -27,7 +25,6 @@
|
||||||
*.BAK
|
*.BAK
|
||||||
*.orig
|
*.orig
|
||||||
\#*#
|
\#*#
|
||||||
firmware-backups/
|
|
||||||
|
|
||||||
# Tag files
|
# Tag files
|
||||||
/tags
|
/tags
|
||||||
|
|
55
Dockerfile
55
Dockerfile
|
@ -1,48 +1,23 @@
|
||||||
FROM debian:bullseye-slim AS base
|
FROM rust:1-slim-buster as programmer_build
|
||||||
|
LABEL maintainer="Ben V. Brown <ralim@ralimtek.com>"
|
||||||
FROM base AS rust_build
|
|
||||||
|
|
||||||
LABEL org.opencontainers.image.authors = "Ben V. Brown <ralim@ralimtek.com>, Dom Rodriguez <shymega@shymega.org.uk>"
|
|
||||||
|
|
||||||
WORKDIR /usr/src
|
WORKDIR /usr/src
|
||||||
ENV PATH="/root/.cargo/bin:$PATH"
|
RUN apt-get update && apt-get install -y git pkg-config libudev-dev bc
|
||||||
|
RUN git clone https://github.com/Ralim/bestool.git
|
||||||
|
RUN cd /usr/src/bestool/bestool/ && cargo build --release
|
||||||
|
|
||||||
RUN apt-get update \
|
FROM debian:buster
|
||||||
&& apt-get install -y \
|
LABEL maintainer="Ben V. Brown <ralim@ralimtek.com>"
|
||||||
bc \
|
|
||||||
build-essential \
|
|
||||||
curl \
|
|
||||||
git \
|
|
||||||
libudev-dev \
|
|
||||||
pkg-config \
|
|
||||||
&& curl https://sh.rustup.rs -sSf | bash -s -- -y \
|
|
||||||
&& git clone https://github.com/Ralim/bestool.git \
|
|
||||||
&& cd /usr/src/bestool/bestool/ \
|
|
||||||
&& cargo build --release
|
|
||||||
|
|
||||||
FROM base as dev_env
|
|
||||||
|
|
||||||
WORKDIR /usr/src
|
RUN apt update && apt-get install -y make git bash curl tar bzip2 bc xxd ffmpeg
|
||||||
|
|
||||||
RUN apt-get update \
|
WORKDIR /src
|
||||||
&& apt-get install -y \
|
# Git trust
|
||||||
bash \
|
RUN git config --global --add safe.directory /src
|
||||||
bc \
|
# Grab arm compiler; we have to use this ancient one or else we get boot failures. Probably subtle link issues.
|
||||||
bzip2 \
|
|
||||||
curl \
|
|
||||||
ffmpeg \
|
|
||||||
clang-format \
|
|
||||||
git \
|
|
||||||
make \
|
|
||||||
tar \
|
|
||||||
xxd \
|
|
||||||
&& git config --global --add safe.directory /src \
|
|
||||||
&& mkdir -pv /src \
|
|
||||||
&& curl \
|
|
||||||
https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/9-2019q4/gcc-arm-none-eabi-9-2019-q4-major-$(arch)-linux.tar.bz2 | tar -xj -C /src/
|
|
||||||
|
|
||||||
|
RUN curl https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/9-2019q4/gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2 | tar -xj
|
||||||
ENV PATH="${PATH}:/src/gcc-arm-none-eabi-9-2019-q4-major/bin"
|
ENV PATH="${PATH}:/src/gcc-arm-none-eabi-9-2019-q4-major/bin"
|
||||||
COPY --from=rust_build /usr/src/bestool/bestool/target/release/bestool /usr/local/bin/bestool
|
WORKDIR /usr/src
|
||||||
|
COPY --from=programmer_build /usr/src/bestool/bestool/target/release/bestool /usr/local/bin/bestool
|
||||||
COPY . /usr/src
|
COPY . /usr/src
|
||||||
|
|
||||||
ENTRYPOINT ["/bin/bash"]
|
|
||||||
|
|
40
Makefile
40
Makefile
|
@ -195,19 +195,6 @@ $(error Invalid target: T=$(T))
|
||||||
endif
|
endif
|
||||||
export T
|
export T
|
||||||
|
|
||||||
# Default audio source: en (English, config/_default_cfg_src_/res/en)
|
|
||||||
AUDIO ?= en
|
|
||||||
AUDIO := $(strip $(AUDIO))
|
|
||||||
# Select audio source
|
|
||||||
AUDIO_FOLDER = config/_default_cfg_src_/res/$(AUDIO)
|
|
||||||
ifeq ($(AUDIO),)
|
|
||||||
$(error Please specify the sound language in the command line: AUDIO=<audioName>)
|
|
||||||
endif
|
|
||||||
ifeq ($(wildcard $(AUDIO_FOLDER)),)
|
|
||||||
$(error Invalid target: AUDIO=$(AUDIO))
|
|
||||||
endif
|
|
||||||
export AUDIO
|
|
||||||
|
|
||||||
KBUILD_OUTPUT := $(KBUILD_OUTPUT)/$(T)
|
KBUILD_OUTPUT := $(KBUILD_OUTPUT)/$(T)
|
||||||
|
|
||||||
# That's our default target when none is given on the command line
|
# That's our default target when none is given on the command line
|
||||||
|
@ -228,7 +215,7 @@ KBUILD_OUTPUT := $(shell ( if not exist $(KBUILD_OUTPUT)\ mkdir $(KBUILD_OUTPUT)
|
||||||
KBUILD_OUTPUT := $(subst \,/,$(KBUILD_OUTPUT))
|
KBUILD_OUTPUT := $(subst \,/,$(KBUILD_OUTPUT))
|
||||||
else
|
else
|
||||||
KBUILD_OUTPUT := $(shell mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) \
|
KBUILD_OUTPUT := $(shell mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) \
|
||||||
&& pwd)
|
&& /bin/pwd)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
$(if $(KBUILD_OUTPUT),, \
|
$(if $(KBUILD_OUTPUT),, \
|
||||||
|
@ -1050,32 +1037,7 @@ endif
|
||||||
|
|
||||||
PHONY += FORCE
|
PHONY += FORCE
|
||||||
FORCE: ;
|
FORCE: ;
|
||||||
### Formatting
|
|
||||||
ALL_SOURCE = $(shell find . \( -type f \( -name '*.c' -o -name '*.cpp' \) \) )
|
|
||||||
|
|
||||||
|
|
||||||
style:
|
|
||||||
@for src in $(ALL_SOURCE) $(ALL_INCLUDES); do \
|
|
||||||
echo "Formatting $$src..." ; \
|
|
||||||
clang-format -i "$$src" ; \
|
|
||||||
done
|
|
||||||
@echo "Done"
|
|
||||||
|
|
||||||
check-style:
|
|
||||||
@for src in $(ALL_SOURCE) $(ALL_INCLUDES) ; do \
|
|
||||||
var=`clang-format "$$src" | diff "$$src" - | wc -l` ; \
|
|
||||||
if [ $$var -ne 0 ] ; then \
|
|
||||||
echo "$$src does not respect the coding style (diff: $$var lines)" ; \
|
|
||||||
clang-format "$$src" | diff "$$src" -; \
|
|
||||||
exit 1 ; \
|
|
||||||
fi ; \
|
|
||||||
done
|
|
||||||
@echo "Style check passed"
|
|
||||||
|
|
||||||
|
|
||||||
PHONY += style check-style
|
|
||||||
|
|
||||||
# Declare the contents of the .PHONY variable as phony. We keep that
|
# Declare the contents of the .PHONY variable as phony. We keep that
|
||||||
# information in a variable so we can use it in if_changed and friends.
|
# information in a variable so we can use it in if_changed and friends.
|
||||||
.PHONY: $(PHONY)
|
.PHONY: $(PHONY)
|
||||||
|
|
||||||
|
|
38
README.md
38
README.md
|
@ -1,13 +1,11 @@
|
||||||
# PineBuds SDK
|
# PineBuds Open Source SDK
|
||||||
|
|
||||||
This is just the SDK from the wiki (so far), with dockerfile setup to make building easier, and my reverse engineered bestool integrated.
|
This is just the SDK from the wiki (so far), with dockerfile setup to make building easier, and my reverse engineered bestool integrated.
|
||||||
The docker image will build bestool for you first, then drop you into the dev container for building and flashing the buds.
|
The docker image will build bestool for you first, then drop you into the dev container for building and flashing the buds.
|
||||||
|
|
||||||
NOTE: Currently, the SDK is not licensed under an 'open source' license. We are working to resolve this issue, and will be reaching out to contributors and other parties soon. For now, consider this SDK as 'All Rights Reserved'/'shared source'.
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
To use this setup to build & flash your PineBuds you will need a system with docker setup at the minimum.
|
To use this setup to build & flash your pine buds you will need a system with docker setup at the minimum.
|
||||||
Docker is used to (1) make this all much more reprodicible and easier to debug and (2) so that we dont mess with your host system at all.
|
Docker is used to (1) make this all much more reprodicible and easier to debug and (2) so that we dont mess with your host system at all.
|
||||||
In order to program the buds from inside of the docker container; privileged mode is used. So do be a tad more careful than usual.
|
In order to program the buds from inside of the docker container; privileged mode is used. So do be a tad more careful than usual.
|
||||||
|
|
||||||
|
@ -20,10 +18,6 @@ In order to program the buds from inside of the docker container; privileged mod
|
||||||
./build.sh # This will run make and build the output program. If you have weird build errors try running clean.sh or rm -rf'ing the out folder first
|
./build.sh # This will run make and build the output program. If you have weird build errors try running clean.sh or rm -rf'ing the out folder first
|
||||||
|
|
||||||
# Now that the firmware has finished building; if there are no errors you can load it to your buds
|
# Now that the firmware has finished building; if there are no errors you can load it to your buds
|
||||||
|
|
||||||
# You may want to back up the firmware currently on the buds - it will be deleted when the new firmware is loaded on:
|
|
||||||
./backup.sh
|
|
||||||
|
|
||||||
# You may need to take the buds out of the case, wait three seconds, place them back. This wakes them up and the programmer needs to catch this reboot.
|
# You may need to take the buds out of the case, wait three seconds, place them back. This wakes them up and the programmer needs to catch this reboot.
|
||||||
|
|
||||||
# You can try the helper script by running
|
# You can try the helper script by running
|
||||||
|
@ -36,12 +30,12 @@ bestool write-image out/open_source/open_source.bin --port /dev/ttyACM0
|
||||||
bestool write-image out/open_source/open_source.bin --port /dev/ttyACM1
|
bestool write-image out/open_source/open_source.bin --port /dev/ttyACM1
|
||||||
```
|
```
|
||||||
|
|
||||||
## Changelist from stock open source SDK
|
## Changelist from stock opeen source SDK
|
||||||
|
|
||||||
- Long hold (5 ish seconds) the button on the back when buds are in the case to force a device reboot (so it can be programmed)
|
- Long hold (5 ish seconds) the button on the back when buds are in the case to force a device reboot (so it can be programmed)
|
||||||
- Use the resistor in the buds to pick Left/Right rather than TWS master/slave pairing
|
- Use the resistor in the buds to pick Left/Right rather than TWS master/slave pairing
|
||||||
- Pressing the button on the back while in the case no longer triggers DFU mode
|
- Pressing the button on the back while in the case no longer triggers DFU mode
|
||||||
- Debugging baud rate raised to 2000000 to match stock firmware
|
- Debugging baud rate raised to 200000 to match stock firmware
|
||||||
- Fixed TWS operation such that putting either bud into the case correctly switches to the other bud
|
- Fixed TWS operation such that putting either bud into the case correctly switches to the other bud
|
||||||
- Working (mostly) audio controls using the touch button on the buds
|
- Working (mostly) audio controls using the touch button on the buds
|
||||||
- Turned off showing up as a HID keyboard, as not sure _why_ you would; but it stops android nagging me about a new keyboard
|
- Turned off showing up as a HID keyboard, as not sure _why_ you would; but it stops android nagging me about a new keyboard
|
||||||
|
@ -73,27 +67,9 @@ bestool write-image out/open_source/open_source.bin --port /dev/ttyACM1
|
||||||
- Quad tap : Volume Down
|
- Quad tap : Volume Down
|
||||||
|
|
||||||
## Changing audio alerts
|
## Changing audio alerts
|
||||||
|
The audio alerts are stored in:
|
||||||
The default audio alerts are stored in:
|
|
||||||
|
|
||||||
`config/_default_cfg_src_/res/en/`
|
`config/_default_cfg_src_/res/en/`
|
||||||
|
|
||||||
If you want to change the alert to a custom sound, just replace the sound file you'd like to change
|
You can convert these .txt files to .wav files by using the script `convert.sh` with the -T flag, the resulting file will be named `output.wav`.
|
||||||
(ie `config/_default_cfg_src_/res/en/SOUND_POWER_ON.opus`) with your own audio file with the same base
|
If you want to change the alert to a custom sound use the -W flag on your wav file and then move the resulting `SOUND.txt` file to the place you want to replace (eg. `config/_default_cfg_src_/res/en/SOUND_POWER_ON.txt`)
|
||||||
name (ie `config/_default_cfg_src_/res/en/SOUND_POWER_ON.mp3`) and recompile with `./build.sh`!
|
|
||||||
|
|
||||||
### Language support
|
|
||||||
|
|
||||||
The `AUDIO` environment variable can be set when running the `build.sh` script to load sound files
|
|
||||||
for languages other than the default English. For example, running `AUDIO=cn ./build.sh` will load sounds files from
|
|
||||||
`config/_default_cfg_src_/res/cn/` instead of the default `en/` folder.
|
|
||||||
|
|
||||||
The current languages supported with sound files are English (`en`) and Chinese (`cn`). Other languages
|
|
||||||
(or other sets of custom sounds) may be added by adding all the correct sound files into a
|
|
||||||
`config/_default_cfg_src_/res/<custom_sounds>/` directory and building with `AUDIO=<custom_sounds> ./build.sh`.
|
|
||||||
|
|
||||||
### Blue light when connected
|
|
||||||
|
|
||||||
The firmware can be configured to either have a blinking blue light when connected or not.
|
|
||||||
Build with `CONNECTED_BLUE_LIGHT=1 ./build.sh` to enable blinking when connected,
|
|
||||||
or `CONNECTED_BLUE_LIGHT=0 ./build.sh` (or just the default `./build.sh`) to keep the LEDs off when connected.
|
|
||||||
|
|
|
@ -12,6 +12,9 @@ obj-y += btusbaudio/
|
||||||
obj-y += usbaudio/
|
obj-y += usbaudio/
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(APP_TEST_SDMMC),1)
|
||||||
|
obj-y += sdmmc/
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(ANC_APP),1)
|
ifeq ($(ANC_APP),1)
|
||||||
obj-y += anc/
|
obj-y += anc/
|
||||||
|
@ -32,6 +35,7 @@ endif
|
||||||
subdir-ccflags-y += -Iapps/apptester \
|
subdir-ccflags-y += -Iapps/apptester \
|
||||||
-Iapps/audioplayers \
|
-Iapps/audioplayers \
|
||||||
-Iapps/common \
|
-Iapps/common \
|
||||||
|
-Iapps/sdmmc \
|
||||||
-Iapps/main \
|
-Iapps/main \
|
||||||
-Iapps/cmd \
|
-Iapps/cmd \
|
||||||
-Iapps/key \
|
-Iapps/key \
|
||||||
|
|
|
@ -17,13 +17,13 @@
|
||||||
#define __ANC_WNR_H__
|
#define __ANC_WNR_H__
|
||||||
|
|
||||||
// #include "plat_types.h"
|
// #include "plat_types.h"
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
ANC_WNR_OPEN_MODE_STANDALONE = 0,
|
ANC_WNR_OPEN_MODE_STANDALONE = 0,
|
||||||
ANC_WNR_OPEN_MODE_CONFIGURE,
|
ANC_WNR_OPEN_MODE_CONFIGURE,
|
||||||
|
|
||||||
|
@ -32,7 +32,8 @@ typedef enum {
|
||||||
|
|
||||||
void anc_release_gain(void);
|
void anc_release_gain(void);
|
||||||
|
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
APP_WNR_NOTIFY_DETECT_RESULT,
|
APP_WNR_NOTIFY_DETECT_RESULT,
|
||||||
APP_WNR_REQUEST_DETECT_RESULT,
|
APP_WNR_REQUEST_DETECT_RESULT,
|
||||||
APP_WNR_RESPONSE_DETECT_RESULT,
|
APP_WNR_RESPONSE_DETECT_RESULT,
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
*
|
*
|
||||||
* Copyright 2015-2019 BES.
|
* Copyright 2015-2019 BES.
|
||||||
|
@ -16,26 +17,32 @@
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include "anc_assist.h"
|
#include "anc_assist.h"
|
||||||
#include "anc_assist_algo.h"
|
#include "hal_trace.h"
|
||||||
#include "anc_process.h"
|
|
||||||
#include "arm_math.h"
|
#include "arm_math.h"
|
||||||
#include "audio_dump.h"
|
#include "audio_dump.h"
|
||||||
#include "audioflinger.h"
|
|
||||||
#include "hal_aud.h"
|
|
||||||
#include "hal_codec.h"
|
|
||||||
#include "hal_timer.h"
|
|
||||||
#include "hal_trace.h"
|
|
||||||
#include "speech_cfg.h"
|
#include "speech_cfg.h"
|
||||||
#include "speech_memory.h"
|
#include "anc_process.h"
|
||||||
#include "speech_ssat.h"
|
#include "audioflinger.h"
|
||||||
|
#include "anc_assist_algo.h"
|
||||||
|
#include "hal_codec.h"
|
||||||
|
#include "audioflinger.h"
|
||||||
|
#include "hal_timer.h"
|
||||||
|
#include "hal_aud.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include "hal_aud.h"
|
||||||
|
#include "anc_process.h"
|
||||||
|
#include "anc_assist_algo.h"
|
||||||
|
#include "speech_memory.h"
|
||||||
|
#include "speech_ssat.h"
|
||||||
|
|
||||||
|
|
||||||
#if defined(ANC_ASSIST_NOISE_ADAPTIVE_ENABLED)
|
#if defined(ANC_ASSIST_NOISE_ADAPTIVE_ENABLED)
|
||||||
#include "main_classify.h"
|
#include "main_classify.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
static void _close_mic_anc_assist();
|
static void _close_mic_anc_assist();
|
||||||
static void _open_mic_anc_assist();
|
static void _open_mic_anc_assist();
|
||||||
#define _SAMPLE_RATE (16000)
|
#define _SAMPLE_RATE (16000)
|
||||||
|
@ -65,19 +72,14 @@ int MIC_MAP = 0;
|
||||||
#define _PLAY_SAMPLE_RATE (8000)
|
#define _PLAY_SAMPLE_RATE (8000)
|
||||||
#define _PLAY_FRAME_LEN (80)
|
#define _PLAY_FRAME_LEN (80)
|
||||||
#define AF_PLAY_STREAM_BUFF_SIZE (_PLAY_FRAME_LEN * SAMPLE_BYTES * 1 * 2)
|
#define AF_PLAY_STREAM_BUFF_SIZE (_PLAY_FRAME_LEN * SAMPLE_BYTES * 1 * 2)
|
||||||
static uint8_t __attribute__((aligned(4)))
|
static uint8_t __attribute__((aligned(4))) af_play_stream_buff[AF_PLAY_STREAM_BUFF_SIZE];
|
||||||
af_play_stream_buff[AF_PLAY_STREAM_BUFF_SIZE];
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ANC_ASSIST_NOISE_ADAPTIVE_ENABLED)
|
#if defined(ANC_ASSIST_NOISE_ADAPTIVE_ENABLED)
|
||||||
ClassifyState * NoiseClassify_st = NULL;
|
ClassifyState * NoiseClassify_st = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ANC_ASSIST_PILOT_ENABLED) || defined(ANC_ASSIST_HESS_ENABLED) || \
|
#if defined(ANC_ASSIST_PILOT_ENABLED) || defined(ANC_ASSIST_HESS_ENABLED) || defined(ANC_ASSIST_PNC_ENABLED) || defined(ANC_ASSIST_DEHOWLING_ENABLED) || defined(ANC_ASSIST_WNR_ENABLED) || defined(ANC_ASSIST_NOISE_ADAPTIVE_ENABLED)
|
||||||
defined(ANC_ASSIST_PNC_ENABLED) || \
|
|
||||||
defined(ANC_ASSIST_DEHOWLING_ENABLED) || \
|
|
||||||
defined(ANC_ASSIST_WNR_ENABLED) || \
|
|
||||||
defined(ANC_ASSIST_NOISE_ADAPTIVE_ENABLED)
|
|
||||||
|
|
||||||
extern const struct_anc_cfg * anc_coef_list_48k[1];
|
extern const struct_anc_cfg * anc_coef_list_48k[1];
|
||||||
void anc_assist_change_curve(int curve_id){
|
void anc_assist_change_curve(int curve_id){
|
||||||
|
@ -85,11 +87,14 @@ void anc_assist_change_curve(int curve_id) {
|
||||||
anc_set_cfg(anc_coef_list_48k[0],ANC_FEEDFORWARD,ANC_GAIN_NO_DELAY);
|
anc_set_cfg(anc_coef_list_48k[0],ANC_FEEDFORWARD,ANC_GAIN_NO_DELAY);
|
||||||
anc_set_cfg(anc_coef_list_48k[0],ANC_FEEDBACK,ANC_GAIN_NO_DELAY);
|
anc_set_cfg(anc_coef_list_48k[0],ANC_FEEDBACK,ANC_GAIN_NO_DELAY);
|
||||||
}
|
}
|
||||||
bool audio_engine_tt_is_on() { return 1; }
|
bool audio_engine_tt_is_on(){
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define _tgt_ff_gain (512)
|
#define _tgt_ff_gain (512)
|
||||||
void anc_assist_set_anc_gain(float gain_ch_l, float gain_ch_r,
|
void anc_assist_set_anc_gain(float gain_ch_l, float gain_ch_r,enum ANC_TYPE_T anc_type){
|
||||||
enum ANC_TYPE_T anc_type) {
|
|
||||||
|
|
||||||
TRACE(2,"[%s] set anc gain %d",__func__,(int)(100*gain_ch_l));
|
TRACE(2,"[%s] set anc gain %d",__func__,(int)(100*gain_ch_l));
|
||||||
uint32_t tgt_ff_gain_l,tgt_ff_gain_r;
|
uint32_t tgt_ff_gain_l,tgt_ff_gain_r;
|
||||||
|
@ -104,22 +109,24 @@ static LeakageDetectionState *pilot_st = NULL;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ANC_ASSIST_HESS_ENABLED) || defined(ANC_ASSIST_PNC_ENABLED) || \
|
|
||||||
defined(ANC_ASSIST_DEHOWLING_ENABLED) || defined(ANC_ASSIST_WNR_ENABLED)
|
#if defined(ANC_ASSIST_HESS_ENABLED) || defined(ANC_ASSIST_PNC_ENABLED) || defined(ANC_ASSIST_DEHOWLING_ENABLED) || defined(ANC_ASSIST_WNR_ENABLED)
|
||||||
static ANCAssistMultiState * anc_assist_multi_st = NULL;
|
static ANCAssistMultiState * anc_assist_multi_st = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ANC_ASSIST_MODE_T g_anc_assist_mode = ANC_ASSIST_MODE_QTY;
|
ANC_ASSIST_MODE_T g_anc_assist_mode = ANC_ASSIST_MODE_QTY;
|
||||||
void anc_assist_open(ANC_ASSIST_MODE_T mode){
|
void anc_assist_open(ANC_ASSIST_MODE_T mode){
|
||||||
g_anc_assist_mode = mode;
|
g_anc_assist_mode = mode;
|
||||||
|
|
||||||
|
|
||||||
//normal init
|
//normal init
|
||||||
#if defined(ANC_ASSIST_PILOT_ENABLED)
|
#if defined(ANC_ASSIST_PILOT_ENABLED)
|
||||||
pilot_st = LeakageDetection_create(160,0);
|
pilot_st = LeakageDetection_create(160,0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ANC_ASSIST_HESS_ENABLED) || defined(ANC_ASSIST_PNC_ENABLED) || \
|
#if defined(ANC_ASSIST_HESS_ENABLED) || defined(ANC_ASSIST_PNC_ENABLED) || defined(ANC_ASSIST_DEHOWLING_ENABLED) || defined(ANC_ASSIST_WNR_ENABLED)
|
||||||
defined(ANC_ASSIST_DEHOWLING_ENABLED) || defined(ANC_ASSIST_WNR_ENABLED)
|
|
||||||
anc_assist_multi_st = ANCAssistMulti_create(_SAMPLE_RATE,_FRAME_LEN,128);
|
anc_assist_multi_st = ANCAssistMulti_create(_SAMPLE_RATE,_FRAME_LEN,128);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -129,27 +136,36 @@ void anc_assist_open(ANC_ASSIST_MODE_T mode) {
|
||||||
|
|
||||||
// audio_dump_init(160,sizeof(short),3);
|
// audio_dump_init(160,sizeof(short),3);
|
||||||
|
|
||||||
|
|
||||||
if( mode == ANC_ASSIST_MODE_QTY){
|
if( mode == ANC_ASSIST_MODE_QTY){
|
||||||
return;
|
return;
|
||||||
} else {
|
}
|
||||||
|
else{
|
||||||
if(mode == ANC_ASSIST_STANDALONE || mode == ANC_ASSIST_MUSIC ){
|
if(mode == ANC_ASSIST_STANDALONE || mode == ANC_ASSIST_MUSIC ){
|
||||||
_open_mic_anc_assist();
|
_open_mic_anc_assist();
|
||||||
}
|
}
|
||||||
if(mode == ANC_ASSIST_PHONE_8K){
|
if(mode == ANC_ASSIST_PHONE_8K){
|
||||||
// normal init 8k
|
// normal init 8k
|
||||||
} else if (mode == ANC_ASSIST_PHONE_16K) {
|
}
|
||||||
|
else if(mode == ANC_ASSIST_PHONE_16K){
|
||||||
// normal init 16k
|
// normal init 16k
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void anc_assist_close(){
|
void anc_assist_close(){
|
||||||
|
|
||||||
#if defined(ANC_ASSIST_PILOT_ENABLED)
|
#if defined(ANC_ASSIST_PILOT_ENABLED)
|
||||||
LeakageDetection_destroy(pilot_st);
|
LeakageDetection_destroy(pilot_st);
|
||||||
#endif
|
#endif
|
||||||
#if defined(ANC_ASSIST_HESS_ENABLED) || defined(ANC_ASSIST_PNC_ENABLED) || \
|
#if defined(ANC_ASSIST_HESS_ENABLED) || defined(ANC_ASSIST_PNC_ENABLED) || defined(ANC_ASSIST_DEHOWLING_ENABLED) || defined(ANC_ASSIST_WNR_ENABLED)
|
||||||
defined(ANC_ASSIST_DEHOWLING_ENABLED) || defined(ANC_ASSIST_WNR_ENABLED)
|
|
||||||
ANCAssistMulti_destroy(anc_assist_multi_st);
|
ANCAssistMulti_destroy(anc_assist_multi_st);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -161,25 +177,29 @@ void anc_assist_close() {
|
||||||
|
|
||||||
if( g_anc_assist_mode == ANC_ASSIST_MODE_QTY){
|
if( g_anc_assist_mode == ANC_ASSIST_MODE_QTY){
|
||||||
return;
|
return;
|
||||||
} else {
|
}
|
||||||
if (g_anc_assist_mode == ANC_ASSIST_STANDALONE ||
|
else{
|
||||||
g_anc_assist_mode == ANC_ASSIST_MUSIC) {
|
if(g_anc_assist_mode == ANC_ASSIST_STANDALONE || g_anc_assist_mode == ANC_ASSIST_MUSIC ){
|
||||||
_close_mic_anc_assist();
|
_close_mic_anc_assist();
|
||||||
}
|
}
|
||||||
if(g_anc_assist_mode == ANC_ASSIST_PHONE_8K){
|
if(g_anc_assist_mode == ANC_ASSIST_PHONE_8K){
|
||||||
// normal init 8k
|
// normal init 8k
|
||||||
} else if (g_anc_assist_mode == ANC_ASSIST_PHONE_16K) {
|
}
|
||||||
|
else if(g_anc_assist_mode == ANC_ASSIST_PHONE_16K){
|
||||||
// normal init 16k
|
// normal init 16k
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
extern ASSIST_PCM_T ref_buf_data[80];
|
extern ASSIST_PCM_T ref_buf_data[80];
|
||||||
void anc_assist_process(uint8_t * buf, int len){
|
void anc_assist_process(uint8_t * buf, int len){
|
||||||
|
|
||||||
|
|
||||||
int32_t frame_len = len / SAMPLE_BYTES / MIC_NUM;
|
int32_t frame_len = len / SAMPLE_BYTES / MIC_NUM;
|
||||||
ASSERT(frame_len == _FRAME_LEN, "[%s] frame len(%d) is invalid.", __func__,
|
ASSERT(frame_len == _FRAME_LEN, "[%s] frame len(%d) is invalid.", __func__, frame_len);
|
||||||
frame_len);
|
|
||||||
ASSIST_PCM_T *pcm_buf = (ASSIST_PCM_T *)buf;
|
ASSIST_PCM_T *pcm_buf = (ASSIST_PCM_T *)buf;
|
||||||
|
|
||||||
ASSIST_PCM_T *mic1 = (ASSIST_PCM_T *)af_stream_mic1;
|
ASSIST_PCM_T *mic1 = (ASSIST_PCM_T *)af_stream_mic1;
|
||||||
|
@ -201,8 +221,7 @@ void anc_assist_process(uint8_t *buf, int len) {
|
||||||
LeakageDetection_process(pilot_st,AF_ANC_OFF,mic3,ref_buf_data,frame_len);
|
LeakageDetection_process(pilot_st,AF_ANC_OFF,mic3,ref_buf_data,frame_len);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ANC_ASSIST_HESS_ENABLED) || defined(ANC_ASSIST_PNC_ENABLED) || \
|
#if defined(ANC_ASSIST_HESS_ENABLED) || defined(ANC_ASSIST_PNC_ENABLED) || defined(ANC_ASSIST_DEHOWLING_ENABLED) || defined(ANC_ASSIST_WNR_ENABLED)
|
||||||
defined(ANC_ASSIST_DEHOWLING_ENABLED) || defined(ANC_ASSIST_WNR_ENABLED)
|
|
||||||
ANCAssistMulti_process(anc_assist_multi_st,mic1,mic2,mic3,frame_len);
|
ANCAssistMulti_process(anc_assist_multi_st,mic1,mic2,mic3,frame_len);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -219,13 +238,35 @@ void anc_assist_process(uint8_t *buf, int len) {
|
||||||
|
|
||||||
// wnr
|
// wnr
|
||||||
|
|
||||||
|
|
||||||
// pnc
|
// pnc
|
||||||
|
|
||||||
|
|
||||||
// hess
|
// hess
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// pilot adpt
|
// pilot adpt
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static uint32_t anc_assist_callback(uint8_t *buf, uint32_t len){
|
static uint32_t anc_assist_callback(uint8_t *buf, uint32_t len){
|
||||||
#ifdef TEST_MIPS
|
#ifdef TEST_MIPS
|
||||||
start_ticks = hal_fast_sys_timer_get();
|
start_ticks = hal_fast_sys_timer_get();
|
||||||
|
@ -237,22 +278,25 @@ static uint32_t anc_assist_callback(uint8_t *buf, uint32_t len) {
|
||||||
used_mips = (end_ticks - start_ticks) * 1000 / (start_ticks - pre_ticks);
|
used_mips = (end_ticks - start_ticks) * 1000 / (start_ticks - pre_ticks);
|
||||||
TRACE(2,"[%s] Usage: %d in a thousand (MIPS).", __func__, used_mips);
|
TRACE(2,"[%s] Usage: %d in a thousand (MIPS).", __func__, used_mips);
|
||||||
//wnr_ticks = start_ticks;
|
//wnr_ticks = start_ticks;
|
||||||
// TRACE(2,"[%s] WNR frame takes %d ms.", __func__,
|
//TRACE(2,"[%s] WNR frame takes %d ms.", __func__, FAST_TICKS_TO_MS((start_ticks - pre_ticks)*100));
|
||||||
// FAST_TICKS_TO_MS((start_ticks - pre_ticks)*100));
|
|
||||||
pre_ticks = start_ticks;
|
pre_ticks = start_ticks;
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if defined(ANC_ASSIST_PILOT_ENABLED)
|
#if defined(ANC_ASSIST_PILOT_ENABLED)
|
||||||
static uint32_t anc_assist_playback_callback(uint8_t *buf, uint32_t len){
|
static uint32_t anc_assist_playback_callback(uint8_t *buf, uint32_t len){
|
||||||
get_pilot_data(buf,len);
|
get_pilot_data(buf,len);
|
||||||
// TRACE(2,"playing data %d",len);
|
// TRACE(2,"playing data %d",len);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void _open_mic_anc_assist(void) {
|
|
||||||
|
static void _open_mic_anc_assist(void)
|
||||||
|
{
|
||||||
|
|
||||||
int anc_assist_mic_num = 0;
|
int anc_assist_mic_num = 0;
|
||||||
|
|
||||||
|
@ -260,65 +304,76 @@ static void _open_mic_anc_assist(void) {
|
||||||
anc_assist_mic_num = anc_assist_mic_num | ANC_ASSIST_FB_MIC;
|
anc_assist_mic_num = anc_assist_mic_num | ANC_ASSIST_FB_MIC;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ANC_ASSIST_HESS_ENABLED) || \
|
#if defined(ANC_ASSIST_HESS_ENABLED) || defined(ANC_ASSIST_NOISE_ADAPTIVE_ENABLED)
|
||||||
defined(ANC_ASSIST_NOISE_ADAPTIVE_ENABLED)
|
|
||||||
anc_assist_mic_num = anc_assist_mic_num | ANC_ASSIST_FF1_MIC;
|
anc_assist_mic_num = anc_assist_mic_num | ANC_ASSIST_FF1_MIC;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ANC_ASSIST_PNC_ENABLED)
|
#if defined(ANC_ASSIST_PNC_ENABLED)
|
||||||
anc_assist_mic_num =
|
anc_assist_mic_num = anc_assist_mic_num | ANC_ASSIST_FF1_MIC | ANC_ASSIST_FB_MIC;
|
||||||
anc_assist_mic_num | ANC_ASSIST_FF1_MIC | ANC_ASSIST_FB_MIC;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ANC_ASSIST_DEHOWLING_ENABLED)
|
#if defined(ANC_ASSIST_DEHOWLING_ENABLED)
|
||||||
anc_assist_mic_num =
|
anc_assist_mic_num = anc_assist_mic_num | ANC_ASSIST_FF1_MIC | ANC_ASSIST_FB_MIC;
|
||||||
anc_assist_mic_num | ANC_ASSIST_FF1_MIC | ANC_ASSIST_FB_MIC;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ANC_ASSIST_WNR_ENABLED)
|
#if defined(ANC_ASSIST_WNR_ENABLED)
|
||||||
anc_assist_mic_num =
|
anc_assist_mic_num = anc_assist_mic_num | ANC_ASSIST_FF1_MIC | ANC_ASSIST_FF2_MIC;
|
||||||
anc_assist_mic_num | ANC_ASSIST_FF1_MIC | ANC_ASSIST_FF2_MIC;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
switch(anc_assist_mic_num){
|
switch(anc_assist_mic_num){
|
||||||
case (0): {
|
case(0):
|
||||||
|
{
|
||||||
TRACE(2,"[%s] no mic is used",__func__);
|
TRACE(2,"[%s] no mic is used",__func__);
|
||||||
return;
|
return;
|
||||||
} break;
|
}
|
||||||
case (1): {
|
break;
|
||||||
|
case(1):
|
||||||
|
{
|
||||||
TRACE(2,"[%s] use fb mic only",__func__);
|
TRACE(2,"[%s] use fb mic only",__func__);
|
||||||
MIC_NUM = 3;
|
MIC_NUM = 3;
|
||||||
MIC_MAP = AUD_INPUT_PATH_AF_ANC;
|
MIC_MAP = AUD_INPUT_PATH_AF_ANC;
|
||||||
|
|
||||||
} break;
|
}
|
||||||
case (4): {
|
break;
|
||||||
|
case(4):
|
||||||
|
{
|
||||||
TRACE(2,"[%s] use ff mic only",__func__);
|
TRACE(2,"[%s] use ff mic only",__func__);
|
||||||
MIC_NUM = 3;
|
MIC_NUM = 3;
|
||||||
MIC_MAP = AUD_INPUT_PATH_ANC_WNR;
|
MIC_MAP = AUD_INPUT_PATH_ANC_WNR;
|
||||||
|
|
||||||
} break;
|
}
|
||||||
case (5): {
|
break;
|
||||||
|
case(5):
|
||||||
|
{
|
||||||
TRACE(2,"[%s] use ff mic and fb mic",__func__);
|
TRACE(2,"[%s] use ff mic and fb mic",__func__);
|
||||||
MIC_NUM = 3;
|
MIC_NUM = 3;
|
||||||
MIC_MAP = AUD_INPUT_PATH_ANC_WNR;
|
MIC_MAP = AUD_INPUT_PATH_ANC_WNR;
|
||||||
|
|
||||||
} break;
|
}
|
||||||
case (6): {
|
break;
|
||||||
|
case(6):
|
||||||
|
{
|
||||||
TRACE(2,"[%s] use ff1 mic and ff2 mic",__func__);
|
TRACE(2,"[%s] use ff1 mic and ff2 mic",__func__);
|
||||||
MIC_NUM = 2;
|
MIC_NUM = 2;
|
||||||
MIC_MAP = AUD_INPUT_PATH_AF_ANC;
|
MIC_MAP = AUD_INPUT_PATH_AF_ANC;
|
||||||
|
|
||||||
} break;
|
}
|
||||||
case (7): {
|
break;
|
||||||
|
case(7):
|
||||||
|
{
|
||||||
TRACE(2,"[%s] use ff1 mic and ff2 mic and fb mic",__func__);
|
TRACE(2,"[%s] use ff1 mic and ff2 mic and fb mic",__func__);
|
||||||
MIC_NUM = 2;
|
MIC_NUM = 2;
|
||||||
MIC_MAP = AUD_INPUT_PATH_AF_ANC;
|
MIC_MAP = AUD_INPUT_PATH_AF_ANC;
|
||||||
|
|
||||||
} break;
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
default: {
|
default:
|
||||||
|
{
|
||||||
TRACE(2,"[%s] invalid mic order is used",__func__);
|
TRACE(2,"[%s] invalid mic order is used",__func__);
|
||||||
} break;
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MIC_NUM = 3;
|
MIC_NUM = 3;
|
||||||
|
@ -337,22 +392,21 @@ static void _open_mic_anc_assist(void) {
|
||||||
stream_cfg.handler = anc_assist_callback;
|
stream_cfg.handler = anc_assist_callback;
|
||||||
stream_cfg.data_size = _FRAME_LEN * SAMPLE_BYTES * 2 * MIC_NUM;
|
stream_cfg.data_size = _FRAME_LEN * SAMPLE_BYTES * 2 * MIC_NUM;
|
||||||
stream_cfg.data_ptr = af_stream_buff;
|
stream_cfg.data_ptr = af_stream_buff;
|
||||||
ASSERT(stream_cfg.channel_num == MIC_NUM,
|
ASSERT(stream_cfg.channel_num == MIC_NUM, "[%s] channel number(%d) is invalid.", __func__, stream_cfg.channel_num);
|
||||||
"[%s] channel number(%d) is invalid.", __func__,
|
TRACE(2,"[%s] sample_rate:%d, data_size:%d", __func__, stream_cfg.sample_rate, stream_cfg.data_size);
|
||||||
stream_cfg.channel_num);
|
|
||||||
TRACE(2, "[%s] sample_rate:%d, data_size:%d", __func__,
|
|
||||||
stream_cfg.sample_rate, stream_cfg.data_size);
|
|
||||||
TRACE(2,"[%s] af_stream_buff = %p", __func__, af_stream_buff);
|
TRACE(2,"[%s] af_stream_buff = %p", __func__, af_stream_buff);
|
||||||
|
|
||||||
af_stream_open(ANC_ADPT_STREAM_ID, AUD_STREAM_CAPTURE, &stream_cfg);
|
af_stream_open(ANC_ADPT_STREAM_ID, AUD_STREAM_CAPTURE, &stream_cfg);
|
||||||
af_stream_start(ANC_ADPT_STREAM_ID, AUD_STREAM_CAPTURE);
|
af_stream_start(ANC_ADPT_STREAM_ID, AUD_STREAM_CAPTURE);
|
||||||
|
|
||||||
|
|
||||||
#if defined(ANC_ASSIST_PILOT_ENABLED)
|
#if defined(ANC_ASSIST_PILOT_ENABLED)
|
||||||
// struct AF_STREAM_CONFIG_T stream_cfg;
|
// struct AF_STREAM_CONFIG_T stream_cfg;
|
||||||
TRACE(1,"[%s] set play ...", __func__);
|
TRACE(1,"[%s] set play ...", __func__);
|
||||||
|
|
||||||
memset(&stream_cfg, 0, sizeof(stream_cfg));
|
memset(&stream_cfg, 0, sizeof(stream_cfg));
|
||||||
|
|
||||||
|
|
||||||
stream_cfg.bits = (enum AUD_BITS_T)_SAMPLE_BITS;
|
stream_cfg.bits = (enum AUD_BITS_T)_SAMPLE_BITS;
|
||||||
stream_cfg.channel_num = AUD_CHANNEL_NUM_1;
|
stream_cfg.channel_num = AUD_CHANNEL_NUM_1;
|
||||||
stream_cfg.sample_rate = (enum AUD_SAMPRATE_T)_PLAY_SAMPLE_RATE;
|
stream_cfg.sample_rate = (enum AUD_SAMPRATE_T)_PLAY_SAMPLE_RATE;
|
||||||
|
@ -365,18 +419,26 @@ static void _open_mic_anc_assist(void) {
|
||||||
stream_cfg.data_ptr = af_play_stream_buff;
|
stream_cfg.data_ptr = af_play_stream_buff;
|
||||||
stream_cfg.data_size = sizeof(af_play_stream_buff);
|
stream_cfg.data_size = sizeof(af_play_stream_buff);
|
||||||
|
|
||||||
|
|
||||||
af_stream_open(ANC_ADPT_STREAM_ID, AUD_STREAM_PLAYBACK, &stream_cfg);
|
af_stream_open(ANC_ADPT_STREAM_ID, AUD_STREAM_PLAYBACK, &stream_cfg);
|
||||||
af_stream_start(ANC_ADPT_STREAM_ID, AUD_STREAM_PLAYBACK);
|
af_stream_start(ANC_ADPT_STREAM_ID, AUD_STREAM_PLAYBACK);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void _close_mic_anc_assist(){
|
static void _close_mic_anc_assist(){
|
||||||
TRACE(1,"[%s] ...", __func__);
|
TRACE(1,"[%s] ...", __func__);
|
||||||
|
|
||||||
af_stream_stop(ANC_ADPT_STREAM_ID, AUD_STREAM_CAPTURE);
|
af_stream_stop(ANC_ADPT_STREAM_ID, AUD_STREAM_CAPTURE);
|
||||||
af_stream_close(ANC_ADPT_STREAM_ID, AUD_STREAM_CAPTURE);
|
af_stream_close(ANC_ADPT_STREAM_ID, AUD_STREAM_CAPTURE);
|
||||||
if (g_anc_assist_mode == ANC_ASSIST_STANDALONE ||
|
if(g_anc_assist_mode == ANC_ASSIST_STANDALONE || g_anc_assist_mode == ANC_ASSIST_MUSIC ){
|
||||||
g_anc_assist_mode == ANC_ASSIST_MUSIC) {
|
|
||||||
// close capture
|
// close capture
|
||||||
}
|
}
|
||||||
// destroy
|
// destroy
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -13,8 +13,8 @@
|
||||||
* trademark and other intellectual property rights.
|
* trademark and other intellectual property rights.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include "peak_detector.h"
|
|
||||||
#include "math.h"
|
#include "math.h"
|
||||||
|
#include "peak_detector.h"
|
||||||
|
|
||||||
// #define PKD_FACTOR_UP (0.6)
|
// #define PKD_FACTOR_UP (0.6)
|
||||||
// #define PKD_FACTOR_DOWN (2.0)
|
// #define PKD_FACTOR_DOWN (2.0)
|
||||||
|
@ -31,47 +31,49 @@ static float pkd_reduce_rate = 1.0f;
|
||||||
#define Max(a,b) ((a)>(b) ? (a):(b))
|
#define Max(a,b) ((a)>(b) ? (a):(b))
|
||||||
|
|
||||||
// Depend on codec_dac_vol
|
// Depend on codec_dac_vol
|
||||||
// const float pkd_vol_multiple[18] = {0.089125, 0.0, 0.005623, 0.007943,
|
// const float pkd_vol_multiple[18] = {0.089125, 0.0, 0.005623, 0.007943, 0.011220, 0.015849, 0.022387, 0.031623, 0.044668, 0.063096, 0.089125, 0.125893, 0.177828, 0.251189, 0.354813, 0.501187, 0.707946, 1.000000};
|
||||||
// 0.011220, 0.015849, 0.022387, 0.031623, 0.044668, 0.063096, 0.089125,
|
|
||||||
// 0.125893, 0.177828, 0.251189, 0.354813, 0.501187, 0.707946, 1.000000};
|
|
||||||
|
|
||||||
// static uint32_t test_num = 0;
|
// static uint32_t test_num = 0;
|
||||||
|
|
||||||
// int app_bt_stream_local_volume_get(void);
|
// int app_bt_stream_local_volume_get(void);
|
||||||
|
|
||||||
// y = 20log(x)
|
// y = 20log(x)
|
||||||
static inline float convert_multiple_to_db(float multiple) {
|
static inline float convert_multiple_to_db(float multiple)
|
||||||
|
{
|
||||||
return 20*(float)log10(multiple);
|
return 20*(float)log10(multiple);
|
||||||
}
|
}
|
||||||
|
|
||||||
// x = 10^(y/20)
|
// x = 10^(y/20)
|
||||||
static inline float convert_db_to_multiple(float db) {
|
static inline float convert_db_to_multiple(float db)
|
||||||
|
{
|
||||||
return (float)pow(10, db/20);
|
return (float)pow(10, db/20);
|
||||||
}
|
}
|
||||||
|
|
||||||
void peak_detector_init(void) {
|
void peak_detector_init(void)
|
||||||
|
{
|
||||||
pkd_alphaR = 0.0f;
|
pkd_alphaR = 0.0f;
|
||||||
pkd_alphaA = 0.0f;
|
pkd_alphaA = 0.0f;
|
||||||
pkd_factor1 = 0.0f;
|
pkd_factor1 = 0.0f;
|
||||||
pkd_factor2 = 0.0f;
|
pkd_factor2 = 0.0f;
|
||||||
pkd_reduce_rate = 1.0f;
|
pkd_reduce_rate = 1.0f;
|
||||||
// TRACE(3,"[%s] pkd_alphaR = %f, pkd_alphaA = %f", __func__,
|
// TRACE(3,"[%s] pkd_alphaR = %f, pkd_alphaA = %f", __func__, (double)pkd_alphaR, (double)pkd_alphaA);
|
||||||
// (double)pkd_alphaR, (double)pkd_alphaA);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void peak_detector_setup(PEAK_DETECTOR_CFG_T *cfg) {
|
void peak_detector_setup(PEAK_DETECTOR_CFG_T *cfg)
|
||||||
|
{
|
||||||
pkd_samp_bits = cfg->bits;
|
pkd_samp_bits = cfg->bits;
|
||||||
pkd_alphaR = (float)exp(-1/(cfg->factor_down * cfg->fs));
|
pkd_alphaR = (float)exp(-1/(cfg->factor_down * cfg->fs));
|
||||||
pkd_alphaA = (float)exp(-1/(cfg->factor_up * cfg->fs));
|
pkd_alphaA = (float)exp(-1/(cfg->factor_up * cfg->fs));
|
||||||
pkd_reduce_rate = convert_db_to_multiple(cfg->reduce_dB);
|
pkd_reduce_rate = convert_db_to_multiple(cfg->reduce_dB);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void peak_detector_run_16bits(int16_t *buf, uint32_t len,
|
static void peak_detector_run_16bits(int16_t *buf, uint32_t len, float vol_multiple)
|
||||||
float vol_multiple) {
|
{
|
||||||
float normal_rate = 1.0;
|
float normal_rate = 1.0;
|
||||||
float tgt_rate = 1.0;
|
float tgt_rate = 1.0;
|
||||||
|
|
||||||
for (uint32_t i = 0; i < len; i++) {
|
for(uint32_t i = 0; i < len; i++)
|
||||||
|
{
|
||||||
pkd_factor1 = Max(buf[i], pkd_alphaR * pkd_factor1);
|
pkd_factor1 = Max(buf[i], pkd_alphaR * pkd_factor1);
|
||||||
pkd_factor2 = pkd_alphaA * pkd_factor2 + (1 - pkd_alphaA) * pkd_factor1;
|
pkd_factor2 = pkd_alphaA * pkd_factor2 + (1 - pkd_alphaA) * pkd_factor1;
|
||||||
|
|
||||||
|
@ -79,7 +81,8 @@ static void peak_detector_run_16bits(int16_t *buf, uint32_t len,
|
||||||
|
|
||||||
tgt_rate = pkd_reduce_rate / normal_rate / vol_multiple;
|
tgt_rate = pkd_reduce_rate / normal_rate / vol_multiple;
|
||||||
|
|
||||||
if (tgt_rate > 1.0) {
|
if(tgt_rate > 1.0)
|
||||||
|
{
|
||||||
tgt_rate = 1.0;
|
tgt_rate = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,14 +108,11 @@ static void peak_detector_run_16bits(int16_t *buf, uint32_t len,
|
||||||
// {
|
// {
|
||||||
// test_num = 0;
|
// test_num = 0;
|
||||||
// TRACE(0,"START>>>");
|
// TRACE(0,"START>>>");
|
||||||
// TRACE(2,"vol_level = %d, pkd_vol_multiple = %f", vol_level,
|
// TRACE(2,"vol_level = %d, pkd_vol_multiple = %f", vol_level, pkd_vol_multiple[vol_level]);
|
||||||
// pkd_vol_multiple[vol_level]); TRACE(3,"buf = %d, pkd_alphaR = %f,
|
// TRACE(3,"buf = %d, pkd_alphaR = %f, pkd_alphaA = %f", buf[len-1], pkd_alphaR, pkd_alphaA);
|
||||||
// pkd_alphaA = %f", buf[len-1], pkd_alphaR, pkd_alphaA);
|
// TRACE(4,"pkd_factor1 = %f, pkd_factor2 = %f, normal_rate = %f, tgt_rate = %f", pkd_factor1, pkd_factor2, normal_rate, tgt_rate);
|
||||||
// TRACE(4,"pkd_factor1 = %f, pkd_factor2 = %f, normal_rate = %f, tgt_rate =
|
// TRACE(0,"END<<<");
|
||||||
// %f", pkd_factor1, pkd_factor2, normal_rate, tgt_rate); TRACE(0,"END<<<");
|
// // TRACE(7,"[%s] buf = %d, pkd_alphaR = %f, pkd_alphaA = %f, pkd_factor1 = %f, pkd_factor2 = %f, normal_rate = %f", __func__, buf[len-1], pkd_alphaR, pkd_alphaA, pkd_factor1, pkd_factor2, (1.0 - pkd_factor2/32768));
|
||||||
// // TRACE(7,"[%s] buf = %d, pkd_alphaR = %f, pkd_alphaA = %f, pkd_factor1 =
|
|
||||||
// %f, pkd_factor2 = %f, normal_rate = %f", __func__, buf[len-1], pkd_alphaR,
|
|
||||||
// pkd_alphaA, pkd_factor1, pkd_factor2, (1.0 - pkd_factor2/32768));
|
|
||||||
// }
|
// }
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
@ -139,12 +139,13 @@ static void peak_detector_run_16bits(int16_t *buf, uint32_t len,
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void peak_detector_run_24bits(int32_t *buf, uint32_t len,
|
static void peak_detector_run_24bits(int32_t *buf, uint32_t len, float vol_multiple)
|
||||||
float vol_multiple) {
|
{
|
||||||
float normal_rate = 1.0;
|
float normal_rate = 1.0;
|
||||||
float tgt_rate = 1.0;
|
float tgt_rate = 1.0;
|
||||||
|
|
||||||
for (uint32_t i = 0; i < len; i++) {
|
for(uint32_t i = 0; i < len; i++)
|
||||||
|
{
|
||||||
pkd_factor1 = Max(buf[i], pkd_alphaR * pkd_factor1);
|
pkd_factor1 = Max(buf[i], pkd_alphaR * pkd_factor1);
|
||||||
pkd_factor2 = pkd_alphaA * pkd_factor2 + (1 - pkd_alphaA) * pkd_factor1;
|
pkd_factor2 = pkd_alphaA * pkd_factor2 + (1 - pkd_alphaA) * pkd_factor1;
|
||||||
|
|
||||||
|
@ -152,7 +153,8 @@ static void peak_detector_run_24bits(int32_t *buf, uint32_t len,
|
||||||
|
|
||||||
tgt_rate = pkd_reduce_rate / normal_rate / vol_multiple;
|
tgt_rate = pkd_reduce_rate / normal_rate / vol_multiple;
|
||||||
|
|
||||||
if (tgt_rate > 1.0) {
|
if(tgt_rate > 1.0)
|
||||||
|
{
|
||||||
tgt_rate = 1.0;
|
tgt_rate = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,7 +177,8 @@ static void peak_detector_run_24bits(int32_t *buf, uint32_t len,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void peak_detector_run(uint8_t *buf, uint32_t len, float vol_multiple) {
|
void peak_detector_run(uint8_t *buf, uint32_t len, float vol_multiple)
|
||||||
|
{
|
||||||
// int vol_level = 0;
|
// int vol_level = 0;
|
||||||
|
|
||||||
if (pkd_samp_bits <= AUD_BITS_16) {
|
if (pkd_samp_bits <= AUD_BITS_16) {
|
||||||
|
@ -190,3 +193,4 @@ void peak_detector_run(uint8_t *buf, uint32_t len, float vol_multiple) {
|
||||||
|
|
||||||
// vol_level = app_bt_stream_local_volume_get();
|
// vol_level = app_bt_stream_local_volume_get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,8 @@ subdir-ccflags-y += \
|
||||||
-Iservices/multimedia/speech/inc \
|
-Iservices/multimedia/speech/inc \
|
||||||
-Iservices/nv_section/include \
|
-Iservices/nv_section/include \
|
||||||
-Iservices/nv_section/aud_section \
|
-Iservices/nv_section/aud_section \
|
||||||
|
-Iplatform/drivers/usb/usb_dev/inc \
|
||||||
|
-Itests/anc_usb \
|
||||||
-Iutils/hwtimer_list
|
-Iutils/hwtimer_list
|
||||||
|
|
||||||
CFLAGS_usb_audio_app.o += -DAUDIO_OUTPUT_VOLUME_DEFAULT=$(AUDIO_OUTPUT_VOLUME_DEFAULT)
|
CFLAGS_usb_audio_app.o += -DAUDIO_OUTPUT_VOLUME_DEFAULT=$(AUDIO_OUTPUT_VOLUME_DEFAULT)
|
||||||
|
@ -56,6 +58,9 @@ ifeq ($(ADC_CH_SEP_BUFF),1)
|
||||||
ANC_USB_CFG_FLAGS += -DADC_CH_SEP_BUFF
|
ANC_USB_CFG_FLAGS += -DADC_CH_SEP_BUFF
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
include platform/drivers/usb/usb_dev/uaud_cfg_flags.mk
|
||||||
|
|
||||||
|
platform/drivers/usb/usb_dev/uaud_cfg_flags.mk: ;
|
||||||
|
|
||||||
ANC_USB_CFG_FLAGS += $(UAUD_CFG_FLAGS)
|
ANC_USB_CFG_FLAGS += $(UAUD_CFG_FLAGS)
|
||||||
|
|
||||||
|
|
|
@ -13,20 +13,20 @@
|
||||||
* trademark and other intellectual property rights.
|
* trademark and other intellectual property rights.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include "app_thread.h"
|
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
#include "hal_trace.h"
|
#include "hal_trace.h"
|
||||||
|
#include "app_thread.h"
|
||||||
|
|
||||||
#include "app_audtest_pattern.h"
|
|
||||||
#include "hal_timer.h"
|
#include "hal_timer.h"
|
||||||
|
#include "app_audtest_pattern.h"
|
||||||
|
|
||||||
#include "app_utils.h"
|
|
||||||
#include "audiobuffer.h"
|
|
||||||
#include "audioflinger.h"
|
|
||||||
#include "eq_export.h"
|
|
||||||
#include "hal_aud.h"
|
#include "hal_aud.h"
|
||||||
|
#include "audioflinger.h"
|
||||||
|
#include "audiobuffer.h"
|
||||||
#include "stdbool.h"
|
#include "stdbool.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "eq_export.h"
|
||||||
|
#include "app_utils.h"
|
||||||
|
|
||||||
#if defined(APP_TEST_AUDIO) && defined(ANC_APP)
|
#if defined(APP_TEST_AUDIO) && defined(ANC_APP)
|
||||||
#include "anc_usb_app.h"
|
#include "anc_usb_app.h"
|
||||||
|
@ -66,42 +66,53 @@ static uint8_t ALIGNED4 app_test_recv_buff[USB_AUDIO_RECV_BUFF_SIZE];
|
||||||
static uint8_t ALIGNED4 app_test_send_buff[USB_AUDIO_SEND_BUFF_SIZE];
|
static uint8_t ALIGNED4 app_test_send_buff[USB_AUDIO_SEND_BUFF_SIZE];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint32_t pcm_1ksin_more_data(uint8_t *buf, uint32_t len) {
|
uint32_t pcm_1ksin_more_data(uint8_t *buf, uint32_t len)
|
||||||
|
{
|
||||||
static uint32_t nextPbufIdx = 0;
|
static uint32_t nextPbufIdx = 0;
|
||||||
uint32_t remain_size = len;
|
uint32_t remain_size = len;
|
||||||
uint32_t curr_size = 0;
|
uint32_t curr_size = 0;
|
||||||
static uint32_t pcm_preIrqTime = 0;
|
static uint32_t pcm_preIrqTime = 0;;
|
||||||
;
|
|
||||||
uint32_t stime = 0;
|
uint32_t stime = 0;
|
||||||
|
|
||||||
|
|
||||||
stime = hal_sys_timer_get();
|
stime = hal_sys_timer_get();
|
||||||
TRACE(3, "pcm_1ksin_more_data irqDur:%d readbuff:0x%08x %d\n ",
|
TRACE(3,"pcm_1ksin_more_data irqDur:%d readbuff:0x%08x %d\n ", TICKS_TO_MS(stime - pcm_preIrqTime), buf, len);
|
||||||
TICKS_TO_MS(stime - pcm_preIrqTime), buf, len);
|
|
||||||
pcm_preIrqTime = stime;
|
pcm_preIrqTime = stime;
|
||||||
|
|
||||||
// TRACE(2,"[pcm_1ksin_more_data] len=%d nextBuf:%d\n", len, nextPbufIdx);
|
// TRACE(2,"[pcm_1ksin_more_data] len=%d nextBuf:%d\n", len, nextPbufIdx);
|
||||||
if (remain_size > sizeof(sinwave)) {
|
if (remain_size > sizeof(sinwave))
|
||||||
|
{
|
||||||
do{
|
do{
|
||||||
if (nextPbufIdx) {
|
if (nextPbufIdx)
|
||||||
|
{
|
||||||
curr_size = sizeof(sinwave)-nextPbufIdx;
|
curr_size = sizeof(sinwave)-nextPbufIdx;
|
||||||
memcpy(buf,&sinwave[nextPbufIdx/2], curr_size);
|
memcpy(buf,&sinwave[nextPbufIdx/2], curr_size);
|
||||||
remain_size -= curr_size;
|
remain_size -= curr_size;
|
||||||
nextPbufIdx = 0;
|
nextPbufIdx = 0;
|
||||||
} else if (remain_size > sizeof(sinwave)) {
|
}
|
||||||
|
else if (remain_size>sizeof(sinwave))
|
||||||
|
{
|
||||||
memcpy(buf+curr_size,sinwave,sizeof(sinwave));
|
memcpy(buf+curr_size,sinwave,sizeof(sinwave));
|
||||||
curr_size += sizeof(sinwave);
|
curr_size += sizeof(sinwave);
|
||||||
remain_size -= sizeof(sinwave);
|
remain_size -= sizeof(sinwave);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
memcpy(buf+curr_size,sinwave,remain_size);
|
memcpy(buf+curr_size,sinwave,remain_size);
|
||||||
nextPbufIdx = remain_size;
|
nextPbufIdx = remain_size;
|
||||||
remain_size = 0;
|
remain_size = 0;
|
||||||
}
|
}
|
||||||
}while(remain_size);
|
}while(remain_size);
|
||||||
} else {
|
}
|
||||||
if ((sizeof(sinwave) - nextPbufIdx) >= len) {
|
else
|
||||||
|
{
|
||||||
|
if ((sizeof(sinwave) - nextPbufIdx) >= len)
|
||||||
|
{
|
||||||
memcpy(buf, &sinwave[nextPbufIdx/2],len);
|
memcpy(buf, &sinwave[nextPbufIdx/2],len);
|
||||||
nextPbufIdx += len;
|
nextPbufIdx += len;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
curr_size = sizeof(sinwave)-nextPbufIdx;
|
curr_size = sizeof(sinwave)-nextPbufIdx;
|
||||||
memcpy(buf, &sinwave[nextPbufIdx/2],curr_size);
|
memcpy(buf, &sinwave[nextPbufIdx/2],curr_size);
|
||||||
nextPbufIdx = len - curr_size;
|
nextPbufIdx = len - curr_size;
|
||||||
|
@ -112,12 +123,14 @@ uint32_t pcm_1ksin_more_data(uint8_t *buf, uint32_t len) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t pcm_mute_more_data(uint8_t *buf, uint32_t len) {
|
uint32_t pcm_mute_more_data(uint8_t *buf, uint32_t len)
|
||||||
|
{
|
||||||
memset(buf, 0 , len);
|
memset(buf, 0 , len);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void da_output_sin1k(bool on) {
|
void da_output_sin1k(bool on)
|
||||||
|
{
|
||||||
static bool isRun = false;
|
static bool isRun = false;
|
||||||
struct AF_STREAM_CONFIG_T stream_cfg;
|
struct AF_STREAM_CONFIG_T stream_cfg;
|
||||||
memset(&stream_cfg, 0, sizeof(stream_cfg));
|
memset(&stream_cfg, 0, sizeof(stream_cfg));
|
||||||
|
@ -147,16 +160,21 @@ void da_output_sin1k(bool on) {
|
||||||
af_stream_stop(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK);
|
af_stream_stop(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK);
|
||||||
af_stream_close(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK);
|
af_stream_close(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void da_tester(uint8_t on) { da_output_sin1k(on); }
|
void da_tester(uint8_t on)
|
||||||
|
{
|
||||||
|
da_output_sin1k(on);
|
||||||
|
}
|
||||||
|
|
||||||
extern int voicecvsd_audio_init(void);
|
extern int voicecvsd_audio_init(void);
|
||||||
extern uint32_t voicecvsd_audio_more_data(uint8_t *buf, uint32_t len);
|
extern uint32_t voicecvsd_audio_more_data(uint8_t *buf, uint32_t len);
|
||||||
extern int get_voicecvsd_buffer_size(void);
|
extern int get_voicecvsd_buffer_size(void);
|
||||||
extern int store_voice_pcm2cvsd(unsigned char *buf, unsigned int len);
|
extern int store_voice_pcm2cvsd(unsigned char *buf, unsigned int len);
|
||||||
|
|
||||||
static uint32_t pcm_data_capture(uint8_t *buf, uint32_t len) {
|
static uint32_t pcm_data_capture(uint8_t *buf, uint32_t len)
|
||||||
|
{
|
||||||
uint32_t stime, etime;
|
uint32_t stime, etime;
|
||||||
static uint32_t preIrqTime = 0;
|
static uint32_t preIrqTime = 0;
|
||||||
|
|
||||||
|
@ -164,26 +182,26 @@ static uint32_t pcm_data_capture(uint8_t *buf, uint32_t len) {
|
||||||
// audio_buffer_set_stereo2mono_16bits(buf, len, 1);
|
// audio_buffer_set_stereo2mono_16bits(buf, len, 1);
|
||||||
audio_buffer_set(buf, len);
|
audio_buffer_set(buf, len);
|
||||||
etime = hal_sys_timer_get();
|
etime = hal_sys_timer_get();
|
||||||
TRACE(4, "%s irqDur:%d fsSpend:%d, Len:%d", __func__,
|
TRACE(4,"%s irqDur:%d fsSpend:%d, Len:%d", __func__, TICKS_TO_MS(stime - preIrqTime), TICKS_TO_MS(etime - stime), len);
|
||||||
TICKS_TO_MS(stime - preIrqTime), TICKS_TO_MS(etime - stime), len);
|
|
||||||
preIrqTime = stime;
|
preIrqTime = stime;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t pcm_data_playback(uint8_t *buf, uint32_t len) {
|
static uint32_t pcm_data_playback(uint8_t *buf, uint32_t len)
|
||||||
|
{
|
||||||
uint32_t stime, etime;
|
uint32_t stime, etime;
|
||||||
static uint32_t preIrqTime = 0;
|
static uint32_t preIrqTime = 0;
|
||||||
stime = hal_sys_timer_get();
|
stime = hal_sys_timer_get();
|
||||||
// audio_buffer_get_mono2stereo_16bits(buf, len);
|
// audio_buffer_get_mono2stereo_16bits(buf, len);
|
||||||
audio_buffer_get(buf, len);
|
audio_buffer_get(buf, len);
|
||||||
etime = hal_sys_timer_get();
|
etime = hal_sys_timer_get();
|
||||||
TRACE(4, "%s irqDur:%d fsSpend:%d, Len:%d", __func__,
|
TRACE(4,"%s irqDur:%d fsSpend:%d, Len:%d", __func__, TICKS_TO_MS(stime - preIrqTime), TICKS_TO_MS(etime - stime), len);
|
||||||
TICKS_TO_MS(stime - preIrqTime), TICKS_TO_MS(etime - stime), len);
|
|
||||||
preIrqTime = stime;
|
preIrqTime = stime;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t pcm_cvsd_data_capture(uint8_t *buf, uint32_t len) {
|
uint32_t pcm_cvsd_data_capture(uint8_t *buf, uint32_t len)
|
||||||
|
{
|
||||||
uint32_t stime, etime;
|
uint32_t stime, etime;
|
||||||
static uint32_t preIrqTime = 0;
|
static uint32_t preIrqTime = 0;
|
||||||
|
|
||||||
|
@ -193,13 +211,13 @@ uint32_t pcm_cvsd_data_capture(uint8_t *buf, uint32_t len) {
|
||||||
audio_stereo2mono_16bits(0, (uint16_t *)buf, (uint16_t *)buf, len);
|
audio_stereo2mono_16bits(0, (uint16_t *)buf, (uint16_t *)buf, len);
|
||||||
store_voice_pcm2cvsd(buf, len);
|
store_voice_pcm2cvsd(buf, len);
|
||||||
etime = hal_sys_timer_get();
|
etime = hal_sys_timer_get();
|
||||||
TRACE(4, "%s exit irqDur:%d fsSpend:%d, add:%d", __func__,
|
TRACE(4,"%s exit irqDur:%d fsSpend:%d, add:%d", __func__, TICKS_TO_MS(stime - preIrqTime), TICKS_TO_MS(etime - stime), len);
|
||||||
TICKS_TO_MS(stime - preIrqTime), TICKS_TO_MS(etime - stime), len);
|
|
||||||
preIrqTime = stime;
|
preIrqTime = stime;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t pcm_cvsd_data_playback(uint8_t *buf, uint32_t len) {
|
uint32_t pcm_cvsd_data_playback(uint8_t *buf, uint32_t len)
|
||||||
|
{
|
||||||
int n;
|
int n;
|
||||||
uint32_t stime, etime;
|
uint32_t stime, etime;
|
||||||
static uint32_t preIrqTime = 0;
|
static uint32_t preIrqTime = 0;
|
||||||
|
@ -210,14 +228,13 @@ uint32_t pcm_cvsd_data_playback(uint8_t *buf, uint32_t len) {
|
||||||
voicecvsd_audio_more_data(buf, len);
|
voicecvsd_audio_more_data(buf, len);
|
||||||
n = get_voicecvsd_buffer_size();
|
n = get_voicecvsd_buffer_size();
|
||||||
etime = hal_sys_timer_get();
|
etime = hal_sys_timer_get();
|
||||||
TRACE(5, "%s exit irqDur:%d fsSpend:%d, get:%d remain:%d", __func__,
|
TRACE(5,"%s exit irqDur:%d fsSpend:%d, get:%d remain:%d", __func__, TICKS_TO_MS(stime - preIrqTime), TICKS_TO_MS(etime - stime), len, n);
|
||||||
TICKS_TO_MS(stime - preIrqTime), TICKS_TO_MS(etime - stime), len, n);
|
|
||||||
preIrqTime = stime;
|
preIrqTime = stime;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void adc_looptester(bool on, enum AUD_IO_PATH_T input_path,
|
void adc_looptester(bool on, enum AUD_IO_PATH_T input_path, enum AUD_SAMPRATE_T sample_rate)
|
||||||
enum AUD_SAMPRATE_T sample_rate) {
|
{
|
||||||
struct AF_STREAM_CONFIG_T stream_cfg;
|
struct AF_STREAM_CONFIG_T stream_cfg;
|
||||||
|
|
||||||
static bool isRun = false;
|
static bool isRun = false;
|
||||||
|
@ -263,11 +280,11 @@ void adc_looptester(bool on, enum AUD_IO_PATH_T input_path,
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(APP_TEST_AUDIO) && defined(ANC_APP)
|
#if defined(APP_TEST_AUDIO) && defined(ANC_APP)
|
||||||
void app_anc_usb_init(void) {
|
void app_anc_usb_init(void)
|
||||||
|
{
|
||||||
app_sysfreq_req(APP_SYSFREQ_USER_APP_0, APP_SYSFREQ_52M);
|
app_sysfreq_req(APP_SYSFREQ_USER_APP_0, APP_SYSFREQ_52M);
|
||||||
|
|
||||||
anc_usb_app_init(AUD_INPUT_PATH_MAINMIC, AUD_SAMPRATE_96000,
|
anc_usb_app_init(AUD_INPUT_PATH_MAINMIC, AUD_SAMPRATE_96000, AUD_SAMPRATE_192000);
|
||||||
AUD_SAMPRATE_192000);
|
|
||||||
|
|
||||||
struct USB_AUDIO_BUF_CFG cfg;
|
struct USB_AUDIO_BUF_CFG cfg;
|
||||||
|
|
||||||
|
@ -283,8 +300,8 @@ void app_anc_usb_init(void) {
|
||||||
|
|
||||||
usb_audio_app_init(&cfg);
|
usb_audio_app_init(&cfg);
|
||||||
|
|
||||||
// dualadc_audio_app_init(app_test_playback_buff,
|
//dualadc_audio_app_init(app_test_playback_buff, USB_AUDIO_PLAYBACK_BUFF_SIZE,
|
||||||
// USB_AUDIO_PLAYBACK_BUFF_SIZE, app_test_capture_buff,
|
//app_test_capture_buff, USB_AUDIO_CAPTURE_BUFF_SIZE);
|
||||||
// USB_AUDIO_CAPTURE_BUFF_SIZE);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -13,10 +13,11 @@
|
||||||
* trademark and other intellectual property rights.
|
* trademark and other intellectual property rights.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include "audiobuffer.h"
|
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
#include "cqueue.h"
|
#include "cqueue.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
#include "audiobuffer.h"
|
||||||
|
|
||||||
|
|
||||||
#ifndef _AUDIO_NO_THREAD_
|
#ifndef _AUDIO_NO_THREAD_
|
||||||
static osMutexId g_audio_queue_mutex_id = NULL;
|
static osMutexId g_audio_queue_mutex_id = NULL;
|
||||||
|
@ -24,36 +25,36 @@ osMutexDef(g_audio_queue_mutex);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static CQueue audio_queue;
|
static CQueue audio_queue;
|
||||||
static unsigned char
|
static unsigned char audio_queue_buf[AUDIO_BUFFER_FRAME_SIZE*AUDIO_BUFFER_FRAME_NUM];
|
||||||
audio_queue_buf[AUDIO_BUFFER_FRAME_SIZE * AUDIO_BUFFER_FRAME_NUM];
|
|
||||||
|
|
||||||
void audio_mono2stereo_16bits(uint16_t *dst_buf, uint16_t *src_buf,
|
void audio_mono2stereo_16bits(uint16_t *dst_buf, uint16_t *src_buf, uint32_t src_len)
|
||||||
uint32_t src_len) {
|
{
|
||||||
uint32_t i = 0;
|
uint32_t i = 0;
|
||||||
for (i = 0; i < src_len; ++i) {
|
for (i = 0; i < src_len; ++i) {
|
||||||
dst_buf[i*2 + 0] = dst_buf[i*2 + 1] = src_buf[i];
|
dst_buf[i*2 + 0] = dst_buf[i*2 + 1] = src_buf[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void audio_stereo2mono_16bits(uint8_t chnlsel, uint16_t *dst_buf,
|
void audio_stereo2mono_16bits(uint8_t chnlsel, uint16_t *dst_buf, uint16_t *src_buf, uint32_t src_len)
|
||||||
uint16_t *src_buf, uint32_t src_len) {
|
{
|
||||||
uint32_t i = 0;
|
uint32_t i = 0;
|
||||||
for (i = 0; i < src_len; i+=2) {
|
for (i = 0; i < src_len; i+=2) {
|
||||||
dst_buf[i/2] = src_buf[i + chnlsel];
|
dst_buf[i/2] = src_buf[i + chnlsel];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void audio_buffer_init(void) {
|
void audio_buffer_init(void)
|
||||||
|
{
|
||||||
#ifndef _AUDIO_NO_THREAD_
|
#ifndef _AUDIO_NO_THREAD_
|
||||||
if (g_audio_queue_mutex_id == NULL)
|
if (g_audio_queue_mutex_id == NULL)
|
||||||
g_audio_queue_mutex_id = osMutexCreate((osMutex(g_audio_queue_mutex)));
|
g_audio_queue_mutex_id = osMutexCreate((osMutex(g_audio_queue_mutex)));
|
||||||
#endif
|
#endif
|
||||||
InitCQueue(&audio_queue, sizeof(audio_queue_buf),
|
InitCQueue(&audio_queue, sizeof(audio_queue_buf), (unsigned char *)&audio_queue_buf);
|
||||||
(unsigned char *)&audio_queue_buf);
|
|
||||||
memset(&audio_queue_buf, 0x00, sizeof(audio_queue_buf));
|
memset(&audio_queue_buf, 0x00, sizeof(audio_queue_buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
int audio_buffer_length(void) {
|
int audio_buffer_length(void)
|
||||||
|
{
|
||||||
int len;
|
int len;
|
||||||
#ifndef _AUDIO_NO_THREAD_
|
#ifndef _AUDIO_NO_THREAD_
|
||||||
osMutexWait(g_audio_queue_mutex_id, osWaitForever);
|
osMutexWait(g_audio_queue_mutex_id, osWaitForever);
|
||||||
|
@ -65,7 +66,8 @@ int audio_buffer_length(void) {
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
int audio_buffer_set(uint8_t *buff, uint16_t len) {
|
int audio_buffer_set(uint8_t *buff, uint16_t len)
|
||||||
|
{
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
#ifndef _AUDIO_NO_THREAD_
|
#ifndef _AUDIO_NO_THREAD_
|
||||||
|
@ -78,7 +80,8 @@ int audio_buffer_set(uint8_t *buff, uint16_t len) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
int audio_buffer_get(uint8_t *buff, uint16_t len) {
|
int audio_buffer_get(uint8_t *buff, uint16_t len)
|
||||||
|
{
|
||||||
uint8_t *e1 = NULL, *e2 = NULL;
|
uint8_t *e1 = NULL, *e2 = NULL;
|
||||||
unsigned int len1 = 0, len2 = 0;
|
unsigned int len1 = 0, len2 = 0;
|
||||||
int status;
|
int status;
|
||||||
|
@ -101,15 +104,14 @@ int audio_buffer_get(uint8_t *buff, uint16_t len) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
int audio_buffer_set_stereo2mono_16bits(uint8_t *buff, uint16_t len,
|
int audio_buffer_set_stereo2mono_16bits(uint8_t *buff, uint16_t len, uint8_t chnlsel)
|
||||||
uint8_t chnlsel) {
|
{
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
#ifndef _AUDIO_NO_THREAD_
|
#ifndef _AUDIO_NO_THREAD_
|
||||||
osMutexWait(g_audio_queue_mutex_id, osWaitForever);
|
osMutexWait(g_audio_queue_mutex_id, osWaitForever);
|
||||||
#endif
|
#endif
|
||||||
audio_stereo2mono_16bits(chnlsel, (uint16_t *)buff, (uint16_t *)buff,
|
audio_stereo2mono_16bits(chnlsel, (uint16_t *)buff, (uint16_t *)buff, len>>1);
|
||||||
len >> 1);
|
|
||||||
status = EnCQueue(&audio_queue, buff, len>>1);
|
status = EnCQueue(&audio_queue, buff, len>>1);
|
||||||
#ifndef _AUDIO_NO_THREAD_
|
#ifndef _AUDIO_NO_THREAD_
|
||||||
osMutexRelease(g_audio_queue_mutex_id);
|
osMutexRelease(g_audio_queue_mutex_id);
|
||||||
|
@ -117,7 +119,8 @@ int audio_buffer_set_stereo2mono_16bits(uint8_t *buff, uint16_t len,
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
int audio_buffer_get_mono2stereo_16bits(uint8_t *buff, uint16_t len) {
|
int audio_buffer_get_mono2stereo_16bits(uint8_t *buff, uint16_t len)
|
||||||
|
{
|
||||||
uint8_t *e1 = NULL, *e2 = NULL;
|
uint8_t *e1 = NULL, *e2 = NULL;
|
||||||
unsigned int len1 = 0, len2 = 0;
|
unsigned int len1 = 0, len2 = 0;
|
||||||
int status;
|
int status;
|
||||||
|
@ -128,8 +131,7 @@ int audio_buffer_get_mono2stereo_16bits(uint8_t *buff, uint16_t len) {
|
||||||
status = PeekCQueue(&audio_queue, len>>1, &e1, &len1, &e2, &len2);
|
status = PeekCQueue(&audio_queue, len>>1, &e1, &len1, &e2, &len2);
|
||||||
if (len>>1== len1+len2){
|
if (len>>1== len1+len2){
|
||||||
audio_mono2stereo_16bits((uint16_t *)buff, (uint16_t *)e1, len1>>1);
|
audio_mono2stereo_16bits((uint16_t *)buff, (uint16_t *)e1, len1>>1);
|
||||||
audio_mono2stereo_16bits((uint16_t *)(buff + (len1 << 1)), (uint16_t *)e2,
|
audio_mono2stereo_16bits((uint16_t *)(buff+(len1<<1)), (uint16_t *)e2, len2>>1);
|
||||||
len2 >> 1);
|
|
||||||
DeCQueue(&audio_queue, 0, len1);
|
DeCQueue(&audio_queue, 0, len1);
|
||||||
DeCQueue(&audio_queue, 0, len2);
|
DeCQueue(&audio_queue, 0, len2);
|
||||||
status = len;
|
status = len;
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -14,19 +14,19 @@
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
// Standard C Included Files
|
// Standard C Included Files
|
||||||
#include "a2dp_decoder_internal.h"
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "cmsis_os.h"
|
|
||||||
#include "hal_location.h"
|
|
||||||
#include "hal_timer.h"
|
|
||||||
#include "heap_api.h"
|
|
||||||
#include "plat_types.h"
|
#include "plat_types.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "heap_api.h"
|
||||||
|
#include "hal_location.h"
|
||||||
|
#include "hal_timer.h"
|
||||||
|
#include "a2dp_decoder_internal.h"
|
||||||
|
#include "cmsis_os.h"
|
||||||
|
|
||||||
#if defined(A2DP_AAC_ON)
|
#if defined(A2DP_AAC_ON)
|
||||||
|
#include "heap_api.h"
|
||||||
#include "aacdecoder_lib.h"
|
#include "aacdecoder_lib.h"
|
||||||
#include "aacenc_lib.h"
|
#include "aacenc_lib.h"
|
||||||
#include "heap_api.h"
|
|
||||||
|
|
||||||
#ifndef AAC_MTU_LIMITER
|
#ifndef AAC_MTU_LIMITER
|
||||||
#define AAC_MTU_LIMITER (32) /*must <= 23*/
|
#define AAC_MTU_LIMITER (32) /*must <= 23*/
|
||||||
|
@ -59,32 +59,30 @@ static A2DP_AUDIO_DECODER_LASTFRAME_INFO_T a2dp_audio_aac_lastframe_info;
|
||||||
static uint16_t aac_mtu_limiter = AAC_MTU_LIMITER;
|
static uint16_t aac_mtu_limiter = AAC_MTU_LIMITER;
|
||||||
|
|
||||||
static a2dp_audio_aac_decoder_frame_t *aac_decoder_frame_reorder_p = NULL;
|
static a2dp_audio_aac_decoder_frame_t *aac_decoder_frame_reorder_p = NULL;
|
||||||
static a2dp_audio_aac_decoder_frame_t aac_decoder_last_valid_frame = {
|
static a2dp_audio_aac_decoder_frame_t aac_decoder_last_valid_frame = {0,};
|
||||||
0,
|
|
||||||
};
|
|
||||||
static bool aac_decoder_last_valid_frame_ready = false;
|
static bool aac_decoder_last_valid_frame_ready = false;
|
||||||
|
|
||||||
static void *a2dp_audio_aac_lc_frame_malloc(uint32_t packet_len) {
|
static void *a2dp_audio_aac_lc_frame_malloc(uint32_t packet_len)
|
||||||
|
{
|
||||||
a2dp_audio_aac_decoder_frame_t *aac_decoder_frame_p = NULL;
|
a2dp_audio_aac_decoder_frame_t *aac_decoder_frame_p = NULL;
|
||||||
uint8_t *aac_buffer = NULL;
|
uint8_t *aac_buffer = NULL;
|
||||||
|
|
||||||
aac_buffer = (uint8_t *)a2dp_audio_heap_malloc(AAC_READBUF_SIZE);
|
aac_buffer = (uint8_t *)a2dp_audio_heap_malloc(AAC_READBUF_SIZE);
|
||||||
aac_decoder_frame_p =
|
aac_decoder_frame_p = (a2dp_audio_aac_decoder_frame_t *)a2dp_audio_heap_malloc(sizeof(a2dp_audio_aac_decoder_frame_t));
|
||||||
(a2dp_audio_aac_decoder_frame_t *)a2dp_audio_heap_malloc(
|
|
||||||
sizeof(a2dp_audio_aac_decoder_frame_t));
|
|
||||||
aac_decoder_frame_p->aac_buffer = aac_buffer;
|
aac_decoder_frame_p->aac_buffer = aac_buffer;
|
||||||
aac_decoder_frame_p->aac_buffer_len = packet_len;
|
aac_decoder_frame_p->aac_buffer_len = packet_len;
|
||||||
return (void *)aac_decoder_frame_p;
|
return (void *)aac_decoder_frame_p;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void a2dp_audio_aac_lc_free(void *packet) {
|
static void a2dp_audio_aac_lc_free(void *packet)
|
||||||
a2dp_audio_aac_decoder_frame_t *aac_decoder_frame_p =
|
{
|
||||||
(a2dp_audio_aac_decoder_frame_t *)packet;
|
a2dp_audio_aac_decoder_frame_t *aac_decoder_frame_p = (a2dp_audio_aac_decoder_frame_t *)packet;
|
||||||
a2dp_audio_heap_free(aac_decoder_frame_p->aac_buffer);
|
a2dp_audio_heap_free(aac_decoder_frame_p->aac_buffer);
|
||||||
a2dp_audio_heap_free(aac_decoder_frame_p);
|
a2dp_audio_heap_free(aac_decoder_frame_p);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void a2dp_audio_aac_lc_decoder_init(void) {
|
static void a2dp_audio_aac_lc_decoder_init(void)
|
||||||
|
{
|
||||||
if (aacDec_handle == NULL){
|
if (aacDec_handle == NULL){
|
||||||
TRANSPORT_TYPE transportFmt = TT_MP4_LATM_MCP1;
|
TRANSPORT_TYPE transportFmt = TT_MP4_LATM_MCP1;
|
||||||
|
|
||||||
|
@ -97,14 +95,16 @@ static void a2dp_audio_aac_lc_decoder_init(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void a2dp_audio_aac_lc_decoder_deinit(void) {
|
static void a2dp_audio_aac_lc_decoder_deinit(void)
|
||||||
|
{
|
||||||
if (aacDec_handle){
|
if (aacDec_handle){
|
||||||
aacDecoder_Close(aacDec_handle);
|
aacDecoder_Close(aacDec_handle);
|
||||||
aacDec_handle = NULL;
|
aacDec_handle = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void a2dp_audio_aac_lc_decoder_reinit(void) {
|
static void a2dp_audio_aac_lc_decoder_reinit(void)
|
||||||
|
{
|
||||||
if (aacDec_handle){
|
if (aacDec_handle){
|
||||||
a2dp_audio_aac_lc_decoder_deinit();
|
a2dp_audio_aac_lc_decoder_deinit();
|
||||||
}
|
}
|
||||||
|
@ -133,14 +133,16 @@ extern uint32_t app_bt_stream_get_dma_buffer_samples(void);
|
||||||
|
|
||||||
int a2dp_cp_aac_lc_cp_decode(void);
|
int a2dp_cp_aac_lc_cp_decode(void);
|
||||||
|
|
||||||
static int TEXT_AAC_LOC a2dp_cp_aac_lc_after_cache_underflow(void) {
|
static int TEXT_AAC_LOC a2dp_cp_aac_lc_after_cache_underflow(void)
|
||||||
|
{
|
||||||
#ifdef A2DP_CP_ACCEL
|
#ifdef A2DP_CP_ACCEL
|
||||||
cp_codec_reset = true;
|
cp_codec_reset = true;
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int a2dp_cp_aac_lc_mcu_decode(uint8_t *buffer, uint32_t buffer_bytes) {
|
static int a2dp_cp_aac_lc_mcu_decode(uint8_t *buffer, uint32_t buffer_bytes)
|
||||||
|
{
|
||||||
a2dp_audio_aac_decoder_frame_t *aac_decoder_frame_p = NULL;
|
a2dp_audio_aac_decoder_frame_t *aac_decoder_frame_p = NULL;
|
||||||
list_node_t *node = NULL;
|
list_node_t *node = NULL;
|
||||||
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
||||||
|
@ -152,15 +154,13 @@ static int a2dp_cp_aac_lc_mcu_decode(uint8_t *buffer, uint32_t buffer_bytes) {
|
||||||
uint32_t out_frame_len;
|
uint32_t out_frame_len;
|
||||||
uint32_t check_sum = 0;
|
uint32_t check_sum = 0;
|
||||||
|
|
||||||
|
|
||||||
uint32_t cp_buffer_frames_max = 0;
|
uint32_t cp_buffer_frames_max = 0;
|
||||||
cp_buffer_frames_max = app_bt_stream_get_dma_buffer_samples()/2;
|
cp_buffer_frames_max = app_bt_stream_get_dma_buffer_samples()/2;
|
||||||
if (cp_buffer_frames_max %(a2dp_audio_aac_lastframe_info.frame_samples) ){
|
if (cp_buffer_frames_max %(a2dp_audio_aac_lastframe_info.frame_samples) ){
|
||||||
cp_buffer_frames_max =
|
cp_buffer_frames_max = cp_buffer_frames_max /(a2dp_audio_aac_lastframe_info.frame_samples) +1 ;
|
||||||
cp_buffer_frames_max / (a2dp_audio_aac_lastframe_info.frame_samples) +
|
|
||||||
1;
|
|
||||||
}else{
|
}else{
|
||||||
cp_buffer_frames_max =
|
cp_buffer_frames_max = cp_buffer_frames_max /(a2dp_audio_aac_lastframe_info.frame_samples) ;
|
||||||
cp_buffer_frames_max / (a2dp_audio_aac_lastframe_info.frame_samples);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
out_frame_len = sizeof(*p_out_info) + buffer_bytes;
|
out_frame_len = sizeof(*p_out_info) + buffer_bytes;
|
||||||
|
@ -172,28 +172,23 @@ static int a2dp_cp_aac_lc_mcu_decode(uint8_t *buffer, uint32_t buffer_bytes) {
|
||||||
return A2DP_DECODER_DECODE_ERROR;
|
return A2DP_DECODER_DECODE_ERROR;
|
||||||
}
|
}
|
||||||
while ((node = a2dp_audio_list_begin(list)) != NULL) {
|
while ((node = a2dp_audio_list_begin(list)) != NULL) {
|
||||||
aac_decoder_frame_p =
|
aac_decoder_frame_p = (a2dp_audio_aac_decoder_frame_t *)a2dp_audio_list_node(node);
|
||||||
(a2dp_audio_aac_decoder_frame_t *)a2dp_audio_list_node(node);
|
|
||||||
|
|
||||||
in_info.sequenceNumber = aac_decoder_frame_p->sequenceNumber;
|
in_info.sequenceNumber = aac_decoder_frame_p->sequenceNumber;
|
||||||
in_info.timestamp = aac_decoder_frame_p->timestamp;
|
in_info.timestamp = aac_decoder_frame_p->timestamp;
|
||||||
|
|
||||||
ret = a2dp_cp_put_in_frame(&in_info, sizeof(in_info),
|
ret = a2dp_cp_put_in_frame(&in_info, sizeof(in_info), aac_decoder_frame_p->aac_buffer, aac_decoder_frame_p->aac_buffer_len);
|
||||||
aac_decoder_frame_p->aac_buffer,
|
|
||||||
aac_decoder_frame_p->aac_buffer_len);
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
TRACE_A2DP_DECODER_D("[MCU][AAC] piff !!!!!!ret: %d ", ret);
|
TRACE_A2DP_DECODER_D("[MCU][AAC] piff !!!!!!ret: %d ", ret);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
check_sum = a2dp_audio_decoder_internal_check_sum_generate(
|
check_sum = a2dp_audio_decoder_internal_check_sum_generate(aac_decoder_frame_p->aac_buffer, aac_decoder_frame_p->aac_buffer_len);
|
||||||
aac_decoder_frame_p->aac_buffer, aac_decoder_frame_p->aac_buffer_len);
|
|
||||||
a2dp_audio_list_remove(list, aac_decoder_frame_p);
|
a2dp_audio_list_remove(list, aac_decoder_frame_p);
|
||||||
}
|
}
|
||||||
ret = a2dp_cp_get_full_out_frame((void **)&out, &out_len);
|
ret = a2dp_cp_get_full_out_frame((void **)&out, &out_len);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
if (!get_in_cp_frame_cnt()){
|
if (!get_in_cp_frame_cnt()){
|
||||||
TRACE_A2DP_DECODER_I("[MCU][AAC] cp cache underflow list:%d in_cp:%d",
|
TRACE_A2DP_DECODER_I("[MCU][AAC] cp cache underflow list:%d in_cp:%d",a2dp_audio_list_length(list), get_in_cp_frame_cnt());
|
||||||
a2dp_audio_list_length(list), get_in_cp_frame_cnt());
|
|
||||||
return A2DP_DECODER_CACHE_UNDERFLOW_ERROR;
|
return A2DP_DECODER_CACHE_UNDERFLOW_ERROR;
|
||||||
}
|
}
|
||||||
if (!a2dp_audio_sysfreq_boost_running()){
|
if (!a2dp_audio_sysfreq_boost_running()){
|
||||||
|
@ -202,8 +197,7 @@ static int a2dp_cp_aac_lc_mcu_decode(uint8_t *buffer, uint32_t buffer_bytes) {
|
||||||
osDelay(12);
|
osDelay(12);
|
||||||
ret = a2dp_cp_get_full_out_frame((void **)&out, &out_len);
|
ret = a2dp_cp_get_full_out_frame((void **)&out, &out_len);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
TRACE_A2DP_DECODER_I("[MCU][AAC] cp cache underflow list:%d in_cp:%d",
|
TRACE_A2DP_DECODER_I("[MCU][AAC] cp cache underflow list:%d in_cp:%d",a2dp_audio_list_length(list), get_in_cp_frame_cnt());
|
||||||
a2dp_audio_list_length(list), get_in_cp_frame_cnt());
|
|
||||||
a2dp_cp_aac_lc_after_cache_underflow();
|
a2dp_cp_aac_lc_after_cache_underflow();
|
||||||
return A2DP_DECODER_CACHE_UNDERFLOW_ERROR;
|
return A2DP_DECODER_CACHE_UNDERFLOW_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -216,27 +210,22 @@ static int a2dp_cp_aac_lc_mcu_decode(uint8_t *buffer, uint32_t buffer_bytes) {
|
||||||
return A2DP_DECODER_NO_ERROR;
|
return A2DP_DECODER_NO_ERROR;
|
||||||
}
|
}
|
||||||
if (out_len != out_frame_len){
|
if (out_len != out_frame_len){
|
||||||
TRACE_A2DP_DECODER_I("[MCU][AAC] Bad out len %u (should be %u)", out_len,
|
TRACE_A2DP_DECODER_I("[MCU][AAC] Bad out len %u (should be %u)", out_len, out_frame_len);
|
||||||
out_frame_len);
|
|
||||||
set_cp_reset_flag(true);
|
set_cp_reset_flag(true);
|
||||||
return A2DP_DECODER_DECODE_ERROR;
|
return A2DP_DECODER_DECODE_ERROR;
|
||||||
}
|
}
|
||||||
p_out_info = (struct A2DP_CP_AAC_LC_OUT_FRM_INFO_T *)out;
|
p_out_info = (struct A2DP_CP_AAC_LC_OUT_FRM_INFO_T *)out;
|
||||||
if (p_out_info->pcm_len) {
|
if (p_out_info->pcm_len) {
|
||||||
a2dp_audio_aac_lastframe_info.sequenceNumber =
|
a2dp_audio_aac_lastframe_info.sequenceNumber = p_out_info->in_info.sequenceNumber;
|
||||||
p_out_info->in_info.sequenceNumber;
|
|
||||||
a2dp_audio_aac_lastframe_info.timestamp = p_out_info->in_info.timestamp;
|
a2dp_audio_aac_lastframe_info.timestamp = p_out_info->in_info.timestamp;
|
||||||
a2dp_audio_aac_lastframe_info.curSubSequenceNumber = 0;
|
a2dp_audio_aac_lastframe_info.curSubSequenceNumber = 0;
|
||||||
a2dp_audio_aac_lastframe_info.totalSubSequenceNumber = 0;
|
a2dp_audio_aac_lastframe_info.totalSubSequenceNumber = 0;
|
||||||
a2dp_audio_aac_lastframe_info.frame_samples = p_out_info->frame_samples;
|
a2dp_audio_aac_lastframe_info.frame_samples = p_out_info->frame_samples;
|
||||||
a2dp_audio_aac_lastframe_info.decoded_frames += p_out_info->decoded_frames;
|
a2dp_audio_aac_lastframe_info.decoded_frames += p_out_info->decoded_frames;
|
||||||
a2dp_audio_aac_lastframe_info.undecode_frames =
|
a2dp_audio_aac_lastframe_info.undecode_frames =
|
||||||
a2dp_audio_list_length(list) +
|
a2dp_audio_list_length(list) + a2dp_cp_get_in_frame_cnt_by_index(p_out_info->frame_idx) - 1;
|
||||||
a2dp_cp_get_in_frame_cnt_by_index(p_out_info->frame_idx) - 1;
|
a2dp_audio_aac_lastframe_info.check_sum= check_sum?check_sum:a2dp_audio_aac_lastframe_info.check_sum;
|
||||||
a2dp_audio_aac_lastframe_info.check_sum =
|
a2dp_audio_decoder_internal_lastframe_info_set(&a2dp_audio_aac_lastframe_info);
|
||||||
check_sum ? check_sum : a2dp_audio_aac_lastframe_info.check_sum;
|
|
||||||
a2dp_audio_decoder_internal_lastframe_info_set(
|
|
||||||
&a2dp_audio_aac_lastframe_info);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p_out_info->pcm_len == buffer_bytes) {
|
if (p_out_info->pcm_len == buffer_bytes) {
|
||||||
|
@ -251,24 +240,26 @@ static int a2dp_cp_aac_lc_mcu_decode(uint8_t *buffer, uint32_t buffer_bytes) {
|
||||||
ret = a2dp_cp_consume_full_out_frame();
|
ret = a2dp_cp_consume_full_out_frame();
|
||||||
if (ret){
|
if (ret){
|
||||||
|
|
||||||
TRACE_A2DP_DECODER_I(
|
TRACE_A2DP_DECODER_I("[MCU][AAC] cp consume_full_out_frame() failed: ret=%d", ret);
|
||||||
"[MCU][AAC] cp consume_full_out_frame() failed: ret=%d", ret);
|
|
||||||
set_cp_reset_flag(true);
|
set_cp_reset_flag(true);
|
||||||
return A2DP_DECODER_DECODE_ERROR;
|
return A2DP_DECODER_DECODE_ERROR;
|
||||||
}
|
}
|
||||||
return dec_ret;
|
return dec_ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef __CP_EXCEPTION_TEST__
|
#ifdef __CP_EXCEPTION_TEST__
|
||||||
static bool _cp_assert = false;
|
static bool _cp_assert = false;
|
||||||
int cp_assert(void) {
|
int cp_assert(void)
|
||||||
|
{
|
||||||
_cp_assert = true;
|
_cp_assert = true;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TEXT_AAC_LOC
|
TEXT_AAC_LOC
|
||||||
int a2dp_cp_aac_lc_cp_decode(void) {
|
int a2dp_cp_aac_lc_cp_decode(void)
|
||||||
|
{
|
||||||
int ret;
|
int ret;
|
||||||
enum CP_EMPTY_OUT_FRM_T out_frm_st;
|
enum CP_EMPTY_OUT_FRM_T out_frm_st;
|
||||||
uint8_t *out;
|
uint8_t *out;
|
||||||
|
@ -299,22 +290,17 @@ int a2dp_cp_aac_lc_cp_decode(void) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
out_frm_st = a2dp_cp_get_emtpy_out_frame((void **)&out, &out_len);
|
out_frm_st = a2dp_cp_get_emtpy_out_frame((void **)&out, &out_len);
|
||||||
if (out_frm_st != CP_EMPTY_OUT_FRM_OK &&
|
if (out_frm_st != CP_EMPTY_OUT_FRM_OK && out_frm_st != CP_EMPTY_OUT_FRM_WORKING) {
|
||||||
out_frm_st != CP_EMPTY_OUT_FRM_WORKING) {
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
ASSERT_A2DP_DECODER(out_len > sizeof(*p_out_info),
|
ASSERT_A2DP_DECODER(out_len > sizeof(*p_out_info), "%s: Bad out_len %u (should > %u)", __func__, out_len, sizeof(*p_out_info));
|
||||||
"%s: Bad out_len %u (should > %u)", __func__, out_len,
|
|
||||||
sizeof(*p_out_info));
|
|
||||||
|
|
||||||
p_out_info = (struct A2DP_CP_AAC_LC_OUT_FRM_INFO_T *)out;
|
p_out_info = (struct A2DP_CP_AAC_LC_OUT_FRM_INFO_T *)out;
|
||||||
if (out_frm_st == CP_EMPTY_OUT_FRM_OK) {
|
if (out_frm_st == CP_EMPTY_OUT_FRM_OK) {
|
||||||
p_out_info->pcm_len = 0;
|
p_out_info->pcm_len = 0;
|
||||||
p_out_info->decoded_frames = 0;
|
p_out_info->decoded_frames = 0;
|
||||||
}
|
}
|
||||||
ASSERT_A2DP_DECODER(out_len > sizeof(*p_out_info) + p_out_info->pcm_len,
|
ASSERT_A2DP_DECODER(out_len > sizeof(*p_out_info) + p_out_info->pcm_len, "%s: Bad out_len %u (should > %u + %u)", __func__, out_len, sizeof(*p_out_info), p_out_info->pcm_len);
|
||||||
"%s: Bad out_len %u (should > %u + %u)", __func__,
|
|
||||||
out_len, sizeof(*p_out_info), p_out_info->pcm_len);
|
|
||||||
|
|
||||||
dec_start = (uint8_t *)(p_out_info + 1) + p_out_info->pcm_len;
|
dec_start = (uint8_t *)(p_out_info + 1) + p_out_info->pcm_len;
|
||||||
dec_len = out_len - (dec_start - (uint8_t *)out);
|
dec_len = out_len - (dec_start - (uint8_t *)out);
|
||||||
|
@ -336,9 +322,7 @@ int a2dp_cp_aac_lc_cp_decode(void) {
|
||||||
if (ret) {
|
if (ret) {
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
ASSERT_A2DP_DECODER(in_len > sizeof(*p_in_info),
|
ASSERT_A2DP_DECODER(in_len > sizeof(*p_in_info), "[CP][AAC] Bad in_len %u (should > %u)", in_len, sizeof(*p_in_info));
|
||||||
"[CP][AAC] Bad in_len %u (should > %u)", in_len,
|
|
||||||
sizeof(*p_in_info));
|
|
||||||
|
|
||||||
p_in_info = (struct A2DP_CP_AAC_LC_IN_FRM_INFO_T *)in_buf;
|
p_in_info = (struct A2DP_CP_AAC_LC_IN_FRM_INFO_T *)in_buf;
|
||||||
if (need_refill){
|
if (need_refill){
|
||||||
|
@ -360,8 +344,7 @@ int a2dp_cp_aac_lc_cp_decode(void) {
|
||||||
|
|
||||||
bufferSize = aac_maxreadBytes;
|
bufferSize = aac_maxreadBytes;
|
||||||
bytesValid = aac_maxreadBytes;
|
bytesValid = aac_maxreadBytes;
|
||||||
decoder_err =
|
decoder_err = aacDecoder_Fill(aacDec_handle, &in_buf, &bufferSize, &bytesValid);
|
||||||
aacDecoder_Fill(aacDec_handle, &in_buf, &bufferSize, &bytesValid);
|
|
||||||
if (decoder_err != AAC_DEC_OK) {
|
if (decoder_err != AAC_DEC_OK) {
|
||||||
TRACE_A2DP_DECODER_W("[CP][AAC] decoder_Fill failed:0x%x", decoder_err);
|
TRACE_A2DP_DECODER_W("[CP][AAC] decoder_Fill failed:0x%x", decoder_err);
|
||||||
//if aac failed reopen it again
|
//if aac failed reopen it again
|
||||||
|
@ -374,23 +357,19 @@ int a2dp_cp_aac_lc_cp_decode(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* decode one AAC frame */
|
/* decode one AAC frame */
|
||||||
decoder_err =
|
decoder_err = aacDecoder_DecodeFrame(aacDec_handle, (short *)(dec_start + dec_sum), (dec_len - dec_sum) / 2, 0 /* flags */);
|
||||||
aacDecoder_DecodeFrame(aacDec_handle, (short *)(dec_start + dec_sum),
|
TRACE_A2DP_DECODER_D("[CP][AAC] decoder seq:%d len:%d err:%x", p_in_info->sequenceNumber,
|
||||||
(dec_len - dec_sum) / 2, 0 /* flags */);
|
(dec_len - dec_sum),
|
||||||
TRACE_A2DP_DECODER_D("[CP][AAC] decoder seq:%d len:%d err:%x",
|
|
||||||
p_in_info->sequenceNumber, (dec_len - dec_sum),
|
|
||||||
decoder_err);
|
decoder_err);
|
||||||
if (decoder_err != AAC_DEC_OK){
|
if (decoder_err != AAC_DEC_OK){
|
||||||
TRACE_A2DP_DECODER_W("[CP][AAC] aac_lc_decode failed:0x%x seq:%d",
|
TRACE_A2DP_DECODER_W("[CP][AAC] aac_lc_decode failed:0x%x seq:%d", decoder_err, p_in_info->sequenceNumber);
|
||||||
decoder_err, p_in_info->sequenceNumber);
|
|
||||||
//if aac failed reopen it again
|
//if aac failed reopen it again
|
||||||
a2dp_audio_aac_lc_decoder_reinit();
|
a2dp_audio_aac_lc_decoder_reinit();
|
||||||
TRACE_A2DP_DECODER_I("[CP][AAC]aac_lc_decode reinin codec \n");
|
TRACE_A2DP_DECODER_I("[CP][AAC]aac_lc_decode reinin codec \n");
|
||||||
if(!need_refill){
|
if(!need_refill){
|
||||||
need_refill = true;
|
need_refill = true;
|
||||||
ret = a2dp_cp_consume_in_frame();
|
ret = a2dp_cp_consume_in_frame();
|
||||||
ASSERT(ret == 0, "%s: a2dp_cp_consume_in_frame() failed: ret=%d",
|
ASSERT(ret == 0, "%s: a2dp_cp_consume_in_frame() failed: ret=%d", __func__, ret);
|
||||||
__func__, ret);
|
|
||||||
continue;
|
continue;
|
||||||
}else{
|
}else{
|
||||||
need_refill = false;
|
need_refill = false;
|
||||||
|
@ -406,11 +385,8 @@ int a2dp_cp_aac_lc_cp_decode(void) {
|
||||||
goto end_decode;
|
goto end_decode;
|
||||||
}
|
}
|
||||||
|
|
||||||
bufferSize = stream_info->frameSize * stream_info->numChannels *
|
bufferSize = stream_info->frameSize * stream_info->numChannels * 2;//sizeof(pcm_buffer[0]);
|
||||||
2; // sizeof(pcm_buffer[0]);
|
ASSERT_A2DP_DECODER(AAC_OUTPUT_FRAME_SAMPLES == bufferSize/4, "aac_lc_decode output mismatch samples:%d", bufferSize/4);
|
||||||
ASSERT_A2DP_DECODER(AAC_OUTPUT_FRAME_SAMPLES == bufferSize / 4,
|
|
||||||
"aac_lc_decode output mismatch samples:%d",
|
|
||||||
bufferSize / 4);
|
|
||||||
|
|
||||||
dec_sum += bufferSize;
|
dec_sum += bufferSize;
|
||||||
|
|
||||||
|
@ -420,12 +396,10 @@ int a2dp_cp_aac_lc_cp_decode(void) {
|
||||||
p_out_info->frame_samples = AAC_OUTPUT_FRAME_SAMPLES;
|
p_out_info->frame_samples = AAC_OUTPUT_FRAME_SAMPLES;
|
||||||
p_out_info->frame_idx = a2dp_cp_get_in_frame_index();
|
p_out_info->frame_idx = a2dp_cp_get_in_frame_index();
|
||||||
if (need_refill){
|
if (need_refill){
|
||||||
TRACE_A2DP_DECODER_W("[CP][AAC] resume refill seq:%d",
|
TRACE_A2DP_DECODER_W("[CP][AAC] resume refill seq:%d", p_in_info->sequenceNumber);
|
||||||
p_in_info->sequenceNumber);
|
|
||||||
}else{
|
}else{
|
||||||
ret = a2dp_cp_consume_in_frame();
|
ret = a2dp_cp_consume_in_frame();
|
||||||
ASSERT_A2DP_DECODER(
|
ASSERT_A2DP_DECODER(ret == 0, "[CP][AAC] a2dp_cp_consume_in_frame() failed: ret=%d", ret);
|
||||||
ret == 0, "[CP][AAC] a2dp_cp_consume_in_frame() failed: ret=%d", ret);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -433,24 +407,22 @@ int a2dp_cp_aac_lc_cp_decode(void) {
|
||||||
|
|
||||||
if (error || out_len <= sizeof(*p_out_info) + p_out_info->pcm_len) {
|
if (error || out_len <= sizeof(*p_out_info) + p_out_info->pcm_len) {
|
||||||
ret = a2dp_cp_consume_emtpy_out_frame();
|
ret = a2dp_cp_consume_emtpy_out_frame();
|
||||||
ASSERT_A2DP_DECODER(
|
ASSERT_A2DP_DECODER(ret == 0, "[CP][AAC] a2dp_cp_consume_emtpy_out_frame() failed: ret=%d", ret);
|
||||||
ret == 0, "[CP][AAC] a2dp_cp_consume_emtpy_out_frame() failed: ret=%d",
|
|
||||||
ret);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int a2dp_audio_aac_lc_list_checker(void) {
|
static int a2dp_audio_aac_lc_list_checker(void)
|
||||||
|
{
|
||||||
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
||||||
list_node_t *node = NULL;
|
list_node_t *node = NULL;
|
||||||
a2dp_audio_aac_decoder_frame_t *aac_decoder_frame_p = NULL;
|
a2dp_audio_aac_decoder_frame_t *aac_decoder_frame_p = NULL;
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
aac_decoder_frame_p =
|
aac_decoder_frame_p = (a2dp_audio_aac_decoder_frame_t *)a2dp_audio_aac_lc_frame_malloc(0);
|
||||||
(a2dp_audio_aac_decoder_frame_t *)a2dp_audio_aac_lc_frame_malloc(0);
|
|
||||||
if (aac_decoder_frame_p){
|
if (aac_decoder_frame_p){
|
||||||
a2dp_audio_list_append(list, aac_decoder_frame_p);
|
a2dp_audio_list_append(list, aac_decoder_frame_p);
|
||||||
}
|
}
|
||||||
|
@ -459,22 +431,21 @@ static int a2dp_audio_aac_lc_list_checker(void) {
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if ((node = a2dp_audio_list_begin(list)) != NULL){
|
if ((node = a2dp_audio_list_begin(list)) != NULL){
|
||||||
aac_decoder_frame_p =
|
aac_decoder_frame_p = (a2dp_audio_aac_decoder_frame_t *)a2dp_audio_list_node(node);
|
||||||
(a2dp_audio_aac_decoder_frame_t *)a2dp_audio_list_node(node);
|
|
||||||
a2dp_audio_list_remove(list, aac_decoder_frame_p);
|
a2dp_audio_list_remove(list, aac_decoder_frame_p);
|
||||||
}
|
}
|
||||||
}while(node);
|
}while(node);
|
||||||
|
|
||||||
TRACE_A2DP_DECODER_I("[AAC][INIT] cnt:%d list:%d", cnt,
|
TRACE_A2DP_DECODER_I("[AAC][INIT] cnt:%d list:%d", cnt, a2dp_audio_list_length(list));
|
||||||
a2dp_audio_list_length(list));
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2dp_audio_aac_lc_channel_select(A2DP_AUDIO_CHANNEL_SELECT_E chnl_sel) {
|
int a2dp_audio_aac_lc_channel_select(A2DP_AUDIO_CHANNEL_SELECT_E chnl_sel)
|
||||||
AAC_DECODER_CHANNEL_SELECT_E aac_decoder_channel_select =
|
{
|
||||||
AAC_DECODER_CHANNEL_SELECT_SELECT_STEREO;
|
AAC_DECODER_CHANNEL_SELECT_E aac_decoder_channel_select = AAC_DECODER_CHANNEL_SELECT_SELECT_STEREO;
|
||||||
switch (chnl_sel) {
|
switch(chnl_sel)
|
||||||
|
{
|
||||||
case A2DP_AUDIO_CHANNEL_SELECT_STEREO:
|
case A2DP_AUDIO_CHANNEL_SELECT_STEREO:
|
||||||
aac_decoder_channel_select = AAC_DECODER_CHANNEL_SELECT_SELECT_STEREO;
|
aac_decoder_channel_select = AAC_DECODER_CHANNEL_SELECT_SELECT_STEREO;
|
||||||
break;
|
break;
|
||||||
|
@ -494,22 +465,19 @@ int a2dp_audio_aac_lc_channel_select(A2DP_AUDIO_CHANNEL_SELECT_E chnl_sel) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2dp_audio_aac_lc_init(A2DP_AUDIO_OUTPUT_CONFIG_T *config, void *context) {
|
int a2dp_audio_aac_lc_init(A2DP_AUDIO_OUTPUT_CONFIG_T *config, void *context)
|
||||||
|
{
|
||||||
TRACE_A2DP_DECODER_I("[AAC] init");
|
TRACE_A2DP_DECODER_I("[AAC] init");
|
||||||
|
|
||||||
a2dp_audio_context_p = (A2DP_AUDIO_CONTEXT_T *)context;
|
a2dp_audio_context_p = (A2DP_AUDIO_CONTEXT_T *)context;
|
||||||
|
|
||||||
memset(&a2dp_audio_aac_lastframe_info, 0,
|
memset(&a2dp_audio_aac_lastframe_info, 0, sizeof(A2DP_AUDIO_DECODER_LASTFRAME_INFO_T));
|
||||||
sizeof(A2DP_AUDIO_DECODER_LASTFRAME_INFO_T));
|
|
||||||
a2dp_audio_aac_lastframe_info.stream_info = *config;
|
a2dp_audio_aac_lastframe_info.stream_info = *config;
|
||||||
a2dp_audio_aac_lastframe_info.frame_samples = AAC_OUTPUT_FRAME_SAMPLES;
|
a2dp_audio_aac_lastframe_info.frame_samples = AAC_OUTPUT_FRAME_SAMPLES;
|
||||||
a2dp_audio_aac_lastframe_info.list_samples = AAC_OUTPUT_FRAME_SAMPLES;
|
a2dp_audio_aac_lastframe_info.list_samples = AAC_OUTPUT_FRAME_SAMPLES;
|
||||||
a2dp_audio_decoder_internal_lastframe_info_set(
|
a2dp_audio_decoder_internal_lastframe_info_set(&a2dp_audio_aac_lastframe_info);
|
||||||
&a2dp_audio_aac_lastframe_info);
|
|
||||||
|
|
||||||
ASSERT_A2DP_DECODER(a2dp_audio_context_p->dest_packet_mut < AAC_MTU_LIMITER,
|
ASSERT_A2DP_DECODER(a2dp_audio_context_p->dest_packet_mut < AAC_MTU_LIMITER, "%s MTU OVERFLOW:%u/%u", __func__, a2dp_audio_context_p->dest_packet_mut, AAC_MTU_LIMITER);
|
||||||
"%s MTU OVERFLOW:%u/%u", __func__,
|
|
||||||
a2dp_audio_context_p->dest_packet_mut, AAC_MTU_LIMITER);
|
|
||||||
|
|
||||||
aac_mempoll = (uint8_t *)a2dp_audio_heap_malloc(AAC_MEMPOOL_SIZE);
|
aac_mempoll = (uint8_t *)a2dp_audio_heap_malloc(AAC_MEMPOOL_SIZE);
|
||||||
ASSERT_A2DP_DECODER(aac_mempoll, "aac_mempoll = NULL");
|
ASSERT_A2DP_DECODER(aac_mempoll, "aac_mempoll = NULL");
|
||||||
|
@ -520,8 +488,7 @@ int a2dp_audio_aac_lc_init(A2DP_AUDIO_OUTPUT_CONFIG_T *config, void *context) {
|
||||||
|
|
||||||
cp_codec_reset = true;
|
cp_codec_reset = true;
|
||||||
ret = a2dp_cp_init(a2dp_cp_aac_lc_cp_decode, CP_PROC_DELAY_2_FRAMES);
|
ret = a2dp_cp_init(a2dp_cp_aac_lc_cp_decode, CP_PROC_DELAY_2_FRAMES);
|
||||||
ASSERT_A2DP_DECODER(ret == 0, "%s: a2dp_cp_init() failed: ret=%d", __func__,
|
ASSERT_A2DP_DECODER(ret == 0, "%s: a2dp_cp_init() failed: ret=%d", __func__, ret);
|
||||||
ret);
|
|
||||||
#else
|
#else
|
||||||
a2dp_audio_aac_lc_decoder_init();
|
a2dp_audio_aac_lc_decoder_init();
|
||||||
#endif
|
#endif
|
||||||
|
@ -533,7 +500,9 @@ int a2dp_audio_aac_lc_init(A2DP_AUDIO_OUTPUT_CONFIG_T *config, void *context) {
|
||||||
return A2DP_DECODER_NO_ERROR;
|
return A2DP_DECODER_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2dp_audio_aac_lc_deinit(void) {
|
|
||||||
|
int a2dp_audio_aac_lc_deinit(void)
|
||||||
|
{
|
||||||
#ifdef A2DP_CP_ACCEL
|
#ifdef A2DP_CP_ACCEL
|
||||||
a2dp_cp_deinit();
|
a2dp_cp_deinit();
|
||||||
#endif
|
#endif
|
||||||
|
@ -542,14 +511,14 @@ int a2dp_audio_aac_lc_deinit(void) {
|
||||||
size_t total = 0, used = 0, max_used = 0;
|
size_t total = 0, used = 0, max_used = 0;
|
||||||
heap_memory_info(aac_memhandle, &total, &used, &max_used);
|
heap_memory_info(aac_memhandle, &total, &used, &max_used);
|
||||||
a2dp_audio_heap_free(aac_mempoll);
|
a2dp_audio_heap_free(aac_mempoll);
|
||||||
TRACE_A2DP_DECODER_I(
|
TRACE_A2DP_DECODER_I("[AAC] deinit MEM: total - %d, used - %d, max_used - %d.",
|
||||||
"[AAC] deinit MEM: total - %d, used - %d, max_used - %d.", total, used,
|
total, used, max_used);
|
||||||
max_used);
|
|
||||||
|
|
||||||
return A2DP_DECODER_NO_ERROR;
|
return A2DP_DECODER_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2dp_audio_aac_lc_mcu_decode_frame(uint8_t *buffer, uint32_t buffer_bytes) {
|
int a2dp_audio_aac_lc_mcu_decode_frame(uint8_t *buffer, uint32_t buffer_bytes)
|
||||||
|
{
|
||||||
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
||||||
list_node_t *node = NULL;
|
list_node_t *node = NULL;
|
||||||
a2dp_audio_aac_decoder_frame_t *aac_decoder_frame_p = NULL;
|
a2dp_audio_aac_decoder_frame_t *aac_decoder_frame_p = NULL;
|
||||||
|
@ -577,8 +546,7 @@ int a2dp_audio_aac_lc_mcu_decode_frame(uint8_t *buffer, uint32_t buffer_bytes) {
|
||||||
cache_underflow = true;
|
cache_underflow = true;
|
||||||
goto exit;
|
goto exit;
|
||||||
}else{
|
}else{
|
||||||
aac_decoder_frame_p =
|
aac_decoder_frame_p = (a2dp_audio_aac_decoder_frame_t *)a2dp_audio_list_node(node);
|
||||||
(a2dp_audio_aac_decoder_frame_t *)a2dp_audio_list_node(node);
|
|
||||||
|
|
||||||
if (aac_decoder_frame_p->aac_buffer_len < 64)
|
if (aac_decoder_frame_p->aac_buffer_len < 64)
|
||||||
aac_maxreadBytes = 64;
|
aac_maxreadBytes = 64;
|
||||||
|
@ -593,12 +561,9 @@ int a2dp_audio_aac_lc_mcu_decode_frame(uint8_t *buffer, uint32_t buffer_bytes) {
|
||||||
|
|
||||||
bufferSize = aac_maxreadBytes;
|
bufferSize = aac_maxreadBytes;
|
||||||
bytesValid = aac_maxreadBytes;
|
bytesValid = aac_maxreadBytes;
|
||||||
decoder_err =
|
decoder_err = aacDecoder_Fill(aacDec_handle, &(aac_decoder_frame_p->aac_buffer), &bufferSize, &bytesValid);
|
||||||
aacDecoder_Fill(aacDec_handle, &(aac_decoder_frame_p->aac_buffer),
|
|
||||||
&bufferSize, &bytesValid);
|
|
||||||
if (decoder_err != AAC_DEC_OK) {
|
if (decoder_err != AAC_DEC_OK) {
|
||||||
TRACE_A2DP_DECODER_W("[MCU][AAC] aacDecoder_Fill failed:0x%x",
|
TRACE_A2DP_DECODER_W("[MCU][AAC] aacDecoder_Fill failed:0x%x", decoder_err);
|
||||||
decoder_err);
|
|
||||||
//if aac failed reopen it again
|
//if aac failed reopen it again
|
||||||
if(is_aacDecoder_Close(aacDec_handle)){
|
if(is_aacDecoder_Close(aacDec_handle)){
|
||||||
a2dp_audio_aac_lc_decoder_reinit();
|
a2dp_audio_aac_lc_decoder_reinit();
|
||||||
|
@ -608,11 +573,10 @@ int a2dp_audio_aac_lc_mcu_decode_frame(uint8_t *buffer, uint32_t buffer_bytes) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* decode one AAC frame */
|
/* decode one AAC frame */
|
||||||
decoder_err = aacDecoder_DecodeFrame(aacDec_handle, (short *)buffer,
|
decoder_err = aacDecoder_DecodeFrame(aacDec_handle, (short *)buffer, buffer_bytes/2, 0 /* flags */);
|
||||||
buffer_bytes / 2, 0 /* flags */);
|
TRACE_A2DP_DECODER_D("[MCU][AAC] decoder seq:%d len:%d err:%x", aac_decoder_frame_p->sequenceNumber,
|
||||||
TRACE_A2DP_DECODER_D("[MCU][AAC] decoder seq:%d len:%d err:%x",
|
aac_decoder_frame_p->aac_buffer_len,
|
||||||
aac_decoder_frame_p->sequenceNumber,
|
decoder_err);
|
||||||
aac_decoder_frame_p->aac_buffer_len, decoder_err);
|
|
||||||
if (decoder_err != AAC_DEC_OK){
|
if (decoder_err != AAC_DEC_OK){
|
||||||
TRACE_A2DP_DECODER_W("[MCU][AAC]aac_lc_decode failed:0x%x", decoder_err);
|
TRACE_A2DP_DECODER_W("[MCU][AAC]aac_lc_decode failed:0x%x", decoder_err);
|
||||||
//if aac failed reopen it again
|
//if aac failed reopen it again
|
||||||
|
@ -629,41 +593,32 @@ int a2dp_audio_aac_lc_mcu_decode_frame(uint8_t *buffer, uint32_t buffer_bytes) {
|
||||||
goto end_decode;
|
goto end_decode;
|
||||||
}
|
}
|
||||||
|
|
||||||
output_byte = stream_info->frameSize * stream_info->numChannels *
|
output_byte = stream_info->frameSize * stream_info->numChannels * 2;//sizeof(pcm_buffer[0]);
|
||||||
2; // sizeof(pcm_buffer[0]);
|
ASSERT_A2DP_DECODER(AAC_OUTPUT_FRAME_SAMPLES == output_byte/4, "aac_lc_decode output mismatch samples:%d", output_byte/4);
|
||||||
ASSERT_A2DP_DECODER(AAC_OUTPUT_FRAME_SAMPLES == output_byte / 4,
|
|
||||||
"aac_lc_decode output mismatch samples:%d",
|
|
||||||
output_byte / 4);
|
|
||||||
end_decode:
|
end_decode:
|
||||||
a2dp_audio_aac_lastframe_info.sequenceNumber =
|
a2dp_audio_aac_lastframe_info.sequenceNumber = aac_decoder_frame_p->sequenceNumber;
|
||||||
aac_decoder_frame_p->sequenceNumber;
|
|
||||||
a2dp_audio_aac_lastframe_info.timestamp = aac_decoder_frame_p->timestamp;
|
a2dp_audio_aac_lastframe_info.timestamp = aac_decoder_frame_p->timestamp;
|
||||||
a2dp_audio_aac_lastframe_info.curSubSequenceNumber = 0;
|
a2dp_audio_aac_lastframe_info.curSubSequenceNumber = 0;
|
||||||
a2dp_audio_aac_lastframe_info.totalSubSequenceNumber = 0;
|
a2dp_audio_aac_lastframe_info.totalSubSequenceNumber = 0;
|
||||||
a2dp_audio_aac_lastframe_info.frame_samples = AAC_OUTPUT_FRAME_SAMPLES;
|
a2dp_audio_aac_lastframe_info.frame_samples = AAC_OUTPUT_FRAME_SAMPLES;
|
||||||
a2dp_audio_aac_lastframe_info.decoded_frames++;
|
a2dp_audio_aac_lastframe_info.decoded_frames++;
|
||||||
a2dp_audio_aac_lastframe_info.undecode_frames =
|
a2dp_audio_aac_lastframe_info.undecode_frames = a2dp_audio_list_length(list)-1;
|
||||||
a2dp_audio_list_length(list) - 1;
|
a2dp_audio_aac_lastframe_info.check_sum= a2dp_audio_decoder_internal_check_sum_generate(aac_decoder_frame_p->aac_buffer, aac_decoder_frame_p->aac_buffer_len);
|
||||||
a2dp_audio_aac_lastframe_info.check_sum =
|
a2dp_audio_decoder_internal_lastframe_info_set(&a2dp_audio_aac_lastframe_info);
|
||||||
a2dp_audio_decoder_internal_check_sum_generate(
|
|
||||||
aac_decoder_frame_p->aac_buffer,
|
|
||||||
aac_decoder_frame_p->aac_buffer_len);
|
|
||||||
a2dp_audio_decoder_internal_lastframe_info_set(
|
|
||||||
&a2dp_audio_aac_lastframe_info);
|
|
||||||
a2dp_audio_list_remove(list, aac_decoder_frame_p);
|
a2dp_audio_list_remove(list, aac_decoder_frame_p);
|
||||||
}
|
}
|
||||||
exit:
|
exit:
|
||||||
if(cache_underflow){
|
if(cache_underflow){
|
||||||
a2dp_audio_aac_lastframe_info.undecode_frames = 0;
|
a2dp_audio_aac_lastframe_info.undecode_frames = 0;
|
||||||
a2dp_audio_aac_lastframe_info.check_sum = 0;
|
a2dp_audio_aac_lastframe_info.check_sum = 0;
|
||||||
a2dp_audio_decoder_internal_lastframe_info_set(
|
a2dp_audio_decoder_internal_lastframe_info_set(&a2dp_audio_aac_lastframe_info);
|
||||||
&a2dp_audio_aac_lastframe_info);
|
|
||||||
output_byte = A2DP_DECODER_CACHE_UNDERFLOW_ERROR;
|
output_byte = A2DP_DECODER_CACHE_UNDERFLOW_ERROR;
|
||||||
}
|
}
|
||||||
return output_byte;
|
return output_byte;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2dp_audio_aac_lc_decode_frame(uint8_t *buffer, uint32_t buffer_bytes) {
|
int a2dp_audio_aac_lc_decode_frame(uint8_t *buffer, uint32_t buffer_bytes)
|
||||||
|
{
|
||||||
#ifdef A2DP_CP_ACCEL
|
#ifdef A2DP_CP_ACCEL
|
||||||
return a2dp_cp_aac_lc_mcu_decode(buffer, buffer_bytes);
|
return a2dp_cp_aac_lc_mcu_decode(buffer, buffer_bytes);
|
||||||
#else
|
#else
|
||||||
|
@ -671,8 +626,8 @@ int a2dp_audio_aac_lc_decode_frame(uint8_t *buffer, uint32_t buffer_bytes) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2dp_audio_aac_lc_preparse_packet(btif_media_header_t *header,
|
int a2dp_audio_aac_lc_preparse_packet(btif_media_header_t * header, uint8_t *buffer, uint32_t buffer_bytes)
|
||||||
uint8_t *buffer, uint32_t buffer_bytes) {
|
{
|
||||||
a2dp_audio_aac_lastframe_info.sequenceNumber = header->sequenceNumber;
|
a2dp_audio_aac_lastframe_info.sequenceNumber = header->sequenceNumber;
|
||||||
a2dp_audio_aac_lastframe_info.timestamp = header->timestamp;
|
a2dp_audio_aac_lastframe_info.timestamp = header->timestamp;
|
||||||
a2dp_audio_aac_lastframe_info.curSubSequenceNumber = 0;
|
a2dp_audio_aac_lastframe_info.curSubSequenceNumber = 0;
|
||||||
|
@ -682,16 +637,15 @@ int a2dp_audio_aac_lc_preparse_packet(btif_media_header_t *header,
|
||||||
a2dp_audio_aac_lastframe_info.decoded_frames = 0;
|
a2dp_audio_aac_lastframe_info.decoded_frames = 0;
|
||||||
a2dp_audio_aac_lastframe_info.undecode_frames = 0;
|
a2dp_audio_aac_lastframe_info.undecode_frames = 0;
|
||||||
a2dp_audio_aac_lastframe_info.check_sum = 0;
|
a2dp_audio_aac_lastframe_info.check_sum = 0;
|
||||||
a2dp_audio_decoder_internal_lastframe_info_set(
|
a2dp_audio_decoder_internal_lastframe_info_set(&a2dp_audio_aac_lastframe_info);
|
||||||
&a2dp_audio_aac_lastframe_info);
|
|
||||||
|
|
||||||
TRACE_A2DP_DECODER_I("[AAC][PRE] seq:%d timestamp:%08x",
|
TRACE_A2DP_DECODER_I("[AAC][PRE] seq:%d timestamp:%08x", header->sequenceNumber, header->timestamp);
|
||||||
header->sequenceNumber, header->timestamp);
|
|
||||||
|
|
||||||
return A2DP_DECODER_NO_ERROR;
|
return A2DP_DECODER_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2dp_audio_aac_lc_reorder_init(void) {
|
int a2dp_audio_aac_lc_reorder_init(void)
|
||||||
|
{
|
||||||
aac_decoder_frame_reorder_p = NULL;
|
aac_decoder_frame_reorder_p = NULL;
|
||||||
aac_decoder_last_valid_frame_ready = false;
|
aac_decoder_last_valid_frame_ready = false;
|
||||||
aac_decoder_last_valid_frame.sequenceNumber = 0;
|
aac_decoder_last_valid_frame.sequenceNumber = 0;
|
||||||
|
@ -702,7 +656,8 @@ int a2dp_audio_aac_lc_reorder_init(void) {
|
||||||
return A2DP_DECODER_NO_ERROR;
|
return A2DP_DECODER_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2dp_audio_aac_lc_reorder_deinit(void) {
|
int a2dp_audio_aac_lc_reorder_deinit(void)
|
||||||
|
{
|
||||||
aac_decoder_frame_reorder_p = NULL;
|
aac_decoder_frame_reorder_p = NULL;
|
||||||
aac_decoder_last_valid_frame_ready = false;
|
aac_decoder_last_valid_frame_ready = false;
|
||||||
aac_decoder_last_valid_frame.sequenceNumber = 0;
|
aac_decoder_last_valid_frame.sequenceNumber = 0;
|
||||||
|
@ -712,9 +667,9 @@ int a2dp_audio_aac_lc_reorder_deinit(void) {
|
||||||
return A2DP_DECODER_NO_ERROR;
|
return A2DP_DECODER_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2dp_audio_aac_lc_reorder_store_packet(
|
int a2dp_audio_aac_lc_reorder_store_packet(a2dp_audio_aac_decoder_frame_t *aac_decoder_frame_p,
|
||||||
a2dp_audio_aac_decoder_frame_t *aac_decoder_frame_p,
|
btif_media_header_t * header, uint8_t *buffer, uint32_t buffer_bytes)
|
||||||
btif_media_header_t *header, uint8_t *buffer, uint32_t buffer_bytes) {
|
{
|
||||||
aac_decoder_frame_p->sequenceNumber = header->sequenceNumber;
|
aac_decoder_frame_p->sequenceNumber = header->sequenceNumber;
|
||||||
aac_decoder_frame_p->timestamp = header->timestamp;
|
aac_decoder_frame_p->timestamp = header->timestamp;
|
||||||
memcpy(aac_decoder_frame_p->aac_buffer, buffer, buffer_bytes);
|
memcpy(aac_decoder_frame_p->aac_buffer, buffer, buffer_bytes);
|
||||||
|
@ -722,38 +677,32 @@ int a2dp_audio_aac_lc_reorder_store_packet(
|
||||||
return A2DP_DECODER_NO_ERROR;
|
return A2DP_DECODER_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2dp_audio_aac_lc_reorder_proc(
|
int a2dp_audio_aac_lc_reorder_proc(a2dp_audio_aac_decoder_frame_t *aac_decoder_frame_p,
|
||||||
a2dp_audio_aac_decoder_frame_t *aac_decoder_frame_p,
|
btif_media_header_t * header, uint8_t *buffer, uint32_t buffer_bytes)
|
||||||
btif_media_header_t *header, uint8_t *buffer, uint32_t buffer_bytes) {
|
{
|
||||||
uint8_t *dest_buf = NULL;
|
uint8_t *dest_buf = NULL;
|
||||||
if ((aac_decoder_frame_p->aac_buffer_len + buffer_bytes) > AAC_READBUF_SIZE){
|
if ((aac_decoder_frame_p->aac_buffer_len + buffer_bytes) > AAC_READBUF_SIZE){
|
||||||
return A2DP_DECODER_NO_ERROR;
|
return A2DP_DECODER_NO_ERROR;
|
||||||
}
|
}
|
||||||
TRACE_A2DP_DECODER_W("[AAC][INPUT][REORDER] proc enter seq:%d len:%d",
|
TRACE_A2DP_DECODER_W("[AAC][INPUT][REORDER] proc enter seq:%d len:%d", aac_decoder_frame_p->sequenceNumber, aac_decoder_frame_p->aac_buffer_len);
|
||||||
aac_decoder_frame_p->sequenceNumber,
|
dest_buf = &aac_decoder_frame_p->aac_buffer[aac_decoder_frame_p->aac_buffer_len];
|
||||||
aac_decoder_frame_p->aac_buffer_len);
|
|
||||||
dest_buf =
|
|
||||||
&aac_decoder_frame_p->aac_buffer[aac_decoder_frame_p->aac_buffer_len];
|
|
||||||
memcpy(dest_buf, buffer, buffer_bytes);
|
memcpy(dest_buf, buffer, buffer_bytes);
|
||||||
aac_decoder_frame_p->aac_buffer_len += buffer_bytes;
|
aac_decoder_frame_p->aac_buffer_len += buffer_bytes;
|
||||||
TRACE_A2DP_DECODER_W("[AAC][INPUT][REORDER] proc exit seq:%d len:%d",
|
TRACE_A2DP_DECODER_W("[AAC][INPUT][REORDER] proc exit seq:%d len:%d", aac_decoder_frame_p->sequenceNumber, aac_decoder_frame_p->aac_buffer_len);
|
||||||
aac_decoder_frame_p->sequenceNumber,
|
|
||||||
aac_decoder_frame_p->aac_buffer_len);
|
|
||||||
|
|
||||||
return A2DP_DECODER_NO_ERROR;
|
return A2DP_DECODER_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2dp_audio_aac_lc_packet_recover_save_last(
|
int a2dp_audio_aac_lc_packet_recover_save_last(a2dp_audio_aac_decoder_frame_t *aac_decoder_frame)
|
||||||
a2dp_audio_aac_decoder_frame_t *aac_decoder_frame) {
|
{
|
||||||
aac_decoder_last_valid_frame_ready = true;
|
aac_decoder_last_valid_frame_ready = true;
|
||||||
aac_decoder_last_valid_frame.sequenceNumber =
|
aac_decoder_last_valid_frame.sequenceNumber = aac_decoder_frame->sequenceNumber;
|
||||||
aac_decoder_frame->sequenceNumber;
|
|
||||||
aac_decoder_last_valid_frame.timestamp = aac_decoder_frame->timestamp;
|
aac_decoder_last_valid_frame.timestamp = aac_decoder_frame->timestamp;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2dp_audio_aac_lc_packet_recover_find_missing(
|
int a2dp_audio_aac_lc_packet_recover_find_missing(a2dp_audio_aac_decoder_frame_t *aac_decoder_frame)
|
||||||
a2dp_audio_aac_decoder_frame_t *aac_decoder_frame) {
|
{
|
||||||
uint16_t diff_seq = 0;
|
uint16_t diff_seq = 0;
|
||||||
uint32_t diff_timestamp = 0;
|
uint32_t diff_timestamp = 0;
|
||||||
uint32_t diff = 0;
|
uint32_t diff = 0;
|
||||||
|
@ -764,36 +713,24 @@ int a2dp_audio_aac_lc_packet_recover_find_missing(
|
||||||
return need_recover_pkt;
|
return need_recover_pkt;
|
||||||
}
|
}
|
||||||
|
|
||||||
diff_seq = a2dp_audio_get_passed(aac_decoder_frame->sequenceNumber,
|
diff_seq = a2dp_audio_get_passed(aac_decoder_frame->sequenceNumber, aac_decoder_last_valid_frame.sequenceNumber, UINT16_MAX);
|
||||||
aac_decoder_last_valid_frame.sequenceNumber,
|
diff_timestamp = a2dp_audio_get_passed(aac_decoder_frame->timestamp, aac_decoder_last_valid_frame.timestamp, UINT32_MAX);
|
||||||
UINT16_MAX);
|
|
||||||
diff_timestamp =
|
|
||||||
a2dp_audio_get_passed(aac_decoder_frame->timestamp,
|
|
||||||
aac_decoder_last_valid_frame.timestamp, UINT32_MAX);
|
|
||||||
|
|
||||||
if (diff_seq > 1){
|
if (diff_seq > 1){
|
||||||
TRACE_A2DP_DECODER_W("[AAC][INPUT][PLC] seq:%d/%d stmp:%d/%d",
|
TRACE_A2DP_DECODER_W("[AAC][INPUT][PLC] seq:%d/%d stmp:%d/%d", aac_decoder_frame->sequenceNumber, aac_decoder_last_valid_frame.sequenceNumber,
|
||||||
aac_decoder_frame->sequenceNumber,
|
aac_decoder_frame->timestamp, aac_decoder_last_valid_frame.timestamp);
|
||||||
aac_decoder_last_valid_frame.sequenceNumber,
|
|
||||||
aac_decoder_frame->timestamp,
|
|
||||||
aac_decoder_last_valid_frame.timestamp);
|
|
||||||
diff = diff_timestamp/diff_seq;
|
diff = diff_timestamp/diff_seq;
|
||||||
if (diff%AAC_OUTPUT_FRAME_SAMPLES == 0){
|
if (diff%AAC_OUTPUT_FRAME_SAMPLES == 0){
|
||||||
tmp_pkt_cnt = diff_timestamp/AAC_OUTPUT_FRAME_SAMPLES;
|
tmp_pkt_cnt = diff_timestamp/AAC_OUTPUT_FRAME_SAMPLES;
|
||||||
}else{
|
}else{
|
||||||
tmp_pkt_cnt =
|
tmp_pkt_cnt = (float)diff_timestamp/
|
||||||
(float)diff_timestamp /
|
((1000.f/(float)a2dp_audio_context_p->output_cfg.sample_rate)*(float)AAC_OUTPUT_FRAME_SAMPLES);
|
||||||
((1000.f / (float)a2dp_audio_context_p->output_cfg.sample_rate) *
|
|
||||||
(float)AAC_OUTPUT_FRAME_SAMPLES);
|
|
||||||
}
|
}
|
||||||
need_recover_pkt = (uint32_t)(tmp_pkt_cnt+0.5f);
|
need_recover_pkt = (uint32_t)(tmp_pkt_cnt+0.5f);
|
||||||
TRACE_A2DP_DECODER_W(
|
TRACE_A2DP_DECODER_W("[AAC][INPUT][PLC] diff_seq:%d diff_stmp:%d diff:%d missing:%d", diff_seq, diff_timestamp, diff, need_recover_pkt);
|
||||||
"[AAC][INPUT][PLC] diff_seq:%d diff_stmp:%d diff:%d missing:%d",
|
|
||||||
diff_seq, diff_timestamp, diff, need_recover_pkt);
|
|
||||||
if (need_recover_pkt == diff_seq){
|
if (need_recover_pkt == diff_seq){
|
||||||
need_recover_pkt--;
|
need_recover_pkt--;
|
||||||
TRACE_A2DP_DECODER_W("[AAC][INPUT][PLC] need_recover_pkt seq:%d",
|
TRACE_A2DP_DECODER_W("[AAC][INPUT][PLC] need_recover_pkt seq:%d", need_recover_pkt);
|
||||||
need_recover_pkt);
|
|
||||||
}else{
|
}else{
|
||||||
need_recover_pkt = 0;
|
need_recover_pkt = 0;
|
||||||
}
|
}
|
||||||
|
@ -801,22 +738,17 @@ int a2dp_audio_aac_lc_packet_recover_find_missing(
|
||||||
return need_recover_pkt;
|
return need_recover_pkt;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2dp_audio_aac_lc_packet_recover_proc(
|
int a2dp_audio_aac_lc_packet_recover_proc(a2dp_audio_aac_decoder_frame_t *aac_decoder_frame)
|
||||||
a2dp_audio_aac_decoder_frame_t *aac_decoder_frame) {
|
{
|
||||||
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
||||||
int missing_pkt_cnt = 0;
|
int missing_pkt_cnt = 0;
|
||||||
missing_pkt_cnt =
|
missing_pkt_cnt = a2dp_audio_aac_lc_packet_recover_find_missing(aac_decoder_frame);
|
||||||
a2dp_audio_aac_lc_packet_recover_find_missing(aac_decoder_frame);
|
if (missing_pkt_cnt <= 4 && a2dp_audio_list_length(list) + missing_pkt_cnt < aac_mtu_limiter){
|
||||||
if (missing_pkt_cnt <= 4 &&
|
|
||||||
a2dp_audio_list_length(list) + missing_pkt_cnt < aac_mtu_limiter) {
|
|
||||||
for (uint8_t i=0; i<missing_pkt_cnt; i++){
|
for (uint8_t i=0; i<missing_pkt_cnt; i++){
|
||||||
a2dp_audio_aac_decoder_frame_t *aac_decoder_frame_p =
|
a2dp_audio_aac_decoder_frame_t *aac_decoder_frame_p = (a2dp_audio_aac_decoder_frame_t *)a2dp_audio_aac_lc_frame_malloc(aac_decoder_frame->aac_buffer_len);
|
||||||
(a2dp_audio_aac_decoder_frame_t *)a2dp_audio_aac_lc_frame_malloc(
|
|
||||||
aac_decoder_frame->aac_buffer_len);
|
|
||||||
aac_decoder_frame_p->sequenceNumber = UINT16_MAX;
|
aac_decoder_frame_p->sequenceNumber = UINT16_MAX;
|
||||||
aac_decoder_frame_p->timestamp = UINT32_MAX;
|
aac_decoder_frame_p->timestamp = UINT32_MAX;
|
||||||
memcpy(aac_decoder_frame_p->aac_buffer, aac_decoder_frame->aac_buffer,
|
memcpy(aac_decoder_frame_p->aac_buffer, aac_decoder_frame->aac_buffer, aac_decoder_frame->aac_buffer_len);
|
||||||
aac_decoder_frame->aac_buffer_len);
|
|
||||||
aac_decoder_frame_p->aac_buffer_len = aac_decoder_frame->aac_buffer_len;
|
aac_decoder_frame_p->aac_buffer_len = aac_decoder_frame->aac_buffer_len;
|
||||||
a2dp_audio_list_append(list, aac_decoder_frame_p);
|
a2dp_audio_list_append(list, aac_decoder_frame_p);
|
||||||
}
|
}
|
||||||
|
@ -825,8 +757,8 @@ int a2dp_audio_aac_lc_packet_recover_proc(
|
||||||
return A2DP_DECODER_NO_ERROR;
|
return A2DP_DECODER_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int inline a2dp_audio_aac_lc_packet_append(
|
int inline a2dp_audio_aac_lc_packet_append(a2dp_audio_aac_decoder_frame_t *aac_decoder_frame)
|
||||||
a2dp_audio_aac_decoder_frame_t *aac_decoder_frame) {
|
{
|
||||||
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
||||||
a2dp_audio_aac_lc_packet_recover_proc(aac_decoder_frame);
|
a2dp_audio_aac_lc_packet_recover_proc(aac_decoder_frame);
|
||||||
a2dp_audio_aac_lc_packet_recover_save_last(aac_decoder_frame);
|
a2dp_audio_aac_lc_packet_recover_save_last(aac_decoder_frame);
|
||||||
|
@ -835,8 +767,8 @@ int inline a2dp_audio_aac_lc_packet_append(
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
int a2dp_audio_aac_lc_store_packet(btif_media_header_t *header, uint8_t *buffer,
|
int a2dp_audio_aac_lc_store_packet(btif_media_header_t * header, uint8_t *buffer, uint32_t buffer_bytes)
|
||||||
uint32_t buffer_bytes) {
|
{
|
||||||
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
||||||
int nRet = A2DP_DECODER_NO_ERROR;
|
int nRet = A2DP_DECODER_NO_ERROR;
|
||||||
a2dp_audio_aac_decoder_frame_t *aac_decoder_frame_p = NULL;
|
a2dp_audio_aac_decoder_frame_t *aac_decoder_frame_p = NULL;
|
||||||
|
@ -844,45 +776,35 @@ int a2dp_audio_aac_lc_store_packet(btif_media_header_t *header, uint8_t *buffer,
|
||||||
if (a2dp_audio_list_length(list) < aac_mtu_limiter &&
|
if (a2dp_audio_list_length(list) < aac_mtu_limiter &&
|
||||||
buffer_bytes <= AAC_READBUF_SIZE){
|
buffer_bytes <= AAC_READBUF_SIZE){
|
||||||
if (aac_decoder_frame_reorder_p == NULL){
|
if (aac_decoder_frame_reorder_p == NULL){
|
||||||
aac_decoder_frame_p =
|
aac_decoder_frame_p = (a2dp_audio_aac_decoder_frame_t *)a2dp_audio_aac_lc_frame_malloc(buffer_bytes);
|
||||||
(a2dp_audio_aac_decoder_frame_t *)a2dp_audio_aac_lc_frame_malloc(
|
|
||||||
buffer_bytes);
|
|
||||||
aac_decoder_frame_reorder_p = aac_decoder_frame_p;
|
aac_decoder_frame_reorder_p = aac_decoder_frame_p;
|
||||||
TRACE_A2DP_DECODER_W("[AAC][INPUT][REORDER] start seq:%d len:%d",
|
TRACE_A2DP_DECODER_W("[AAC][INPUT][REORDER] start seq:%d len:%d", header->sequenceNumber, buffer_bytes);
|
||||||
header->sequenceNumber, buffer_bytes);
|
a2dp_audio_aac_lc_reorder_store_packet(aac_decoder_frame_p, header, buffer, buffer_bytes);
|
||||||
a2dp_audio_aac_lc_reorder_store_packet(aac_decoder_frame_p, header,
|
|
||||||
buffer, buffer_bytes);
|
|
||||||
}else{
|
}else{
|
||||||
if (aac_decoder_frame_reorder_p->aac_buffer[0] == buffer[0] &&
|
if (aac_decoder_frame_reorder_p->aac_buffer[0] == buffer[0] &&
|
||||||
aac_decoder_frame_reorder_p->aac_buffer[1] == buffer[1]){
|
aac_decoder_frame_reorder_p->aac_buffer[1] == buffer[1]){
|
||||||
a2dp_audio_aac_lc_packet_append(aac_decoder_frame_reorder_p);
|
a2dp_audio_aac_lc_packet_append(aac_decoder_frame_reorder_p);
|
||||||
aac_decoder_frame_p =
|
aac_decoder_frame_p = (a2dp_audio_aac_decoder_frame_t *)a2dp_audio_aac_lc_frame_malloc(buffer_bytes);
|
||||||
(a2dp_audio_aac_decoder_frame_t *)a2dp_audio_aac_lc_frame_malloc(
|
|
||||||
buffer_bytes);
|
|
||||||
aac_decoder_frame_reorder_p = aac_decoder_frame_p;
|
aac_decoder_frame_reorder_p = aac_decoder_frame_p;
|
||||||
a2dp_audio_aac_lc_reorder_store_packet(aac_decoder_frame_p, header,
|
a2dp_audio_aac_lc_reorder_store_packet(aac_decoder_frame_p, header, buffer, buffer_bytes);
|
||||||
buffer, buffer_bytes);
|
|
||||||
}else{
|
}else{
|
||||||
aac_decoder_frame_p = aac_decoder_frame_reorder_p;
|
aac_decoder_frame_p = aac_decoder_frame_reorder_p;
|
||||||
a2dp_audio_aac_lc_reorder_proc(aac_decoder_frame_p, header, buffer,
|
a2dp_audio_aac_lc_reorder_proc(aac_decoder_frame_p, header, buffer, buffer_bytes);
|
||||||
buffer_bytes);
|
|
||||||
a2dp_audio_aac_lc_packet_append(aac_decoder_frame_p);
|
a2dp_audio_aac_lc_packet_append(aac_decoder_frame_p);
|
||||||
aac_decoder_frame_reorder_p = NULL;
|
aac_decoder_frame_reorder_p = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nRet = A2DP_DECODER_NO_ERROR;
|
nRet = A2DP_DECODER_NO_ERROR;
|
||||||
}else{
|
}else{
|
||||||
TRACE_A2DP_DECODER_W(
|
TRACE_A2DP_DECODER_W("[AAC][INPUT] list full current list_len:%d buff_len:%d", a2dp_audio_list_length(list), buffer_bytes);
|
||||||
"[AAC][INPUT] list full current list_len:%d buff_len:%d",
|
|
||||||
a2dp_audio_list_length(list), buffer_bytes);
|
|
||||||
nRet = A2DP_DECODER_MTU_LIMTER_ERROR;
|
nRet = A2DP_DECODER_MTU_LIMTER_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return nRet;
|
return nRet;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
int a2dp_audio_aac_lc_store_packet(btif_media_header_t *header, uint8_t *buffer,
|
int a2dp_audio_aac_lc_store_packet(btif_media_header_t * header, uint8_t *buffer, uint32_t buffer_bytes)
|
||||||
uint32_t buffer_bytes) {
|
{
|
||||||
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
||||||
int nRet = A2DP_DECODER_NO_ERROR;
|
int nRet = A2DP_DECODER_NO_ERROR;
|
||||||
|
|
||||||
|
@ -892,11 +814,8 @@ int a2dp_audio_aac_lc_store_packet(btif_media_header_t *header, uint8_t *buffer,
|
||||||
|
|
||||||
if (a2dp_audio_list_length(list) < aac_mtu_limiter &&
|
if (a2dp_audio_list_length(list) < aac_mtu_limiter &&
|
||||||
buffer_bytes <= AAC_READBUF_SIZE){
|
buffer_bytes <= AAC_READBUF_SIZE){
|
||||||
a2dp_audio_aac_decoder_frame_t *aac_decoder_frame_p =
|
a2dp_audio_aac_decoder_frame_t *aac_decoder_frame_p = (a2dp_audio_aac_decoder_frame_t *)a2dp_audio_aac_lc_frame_malloc(buffer_bytes);
|
||||||
(a2dp_audio_aac_decoder_frame_t *)a2dp_audio_aac_lc_frame_malloc(
|
TRACE_A2DP_DECODER_D("[AAC][INPUT]seq:%d len:%d", header->sequenceNumber, buffer_bytes);
|
||||||
buffer_bytes);
|
|
||||||
TRACE_A2DP_DECODER_D("[AAC][INPUT]seq:%d len:%d", header->sequenceNumber,
|
|
||||||
buffer_bytes);
|
|
||||||
aac_decoder_frame_p->sequenceNumber = header->sequenceNumber;
|
aac_decoder_frame_p->sequenceNumber = header->sequenceNumber;
|
||||||
aac_decoder_frame_p->timestamp = header->timestamp;
|
aac_decoder_frame_p->timestamp = header->timestamp;
|
||||||
memcpy(aac_decoder_frame_p->aac_buffer, buffer, buffer_bytes);
|
memcpy(aac_decoder_frame_p->aac_buffer, buffer, buffer_bytes);
|
||||||
|
@ -905,9 +824,7 @@ int a2dp_audio_aac_lc_store_packet(btif_media_header_t *header, uint8_t *buffer,
|
||||||
a2dp_audio_list_append(list, aac_decoder_frame_p);
|
a2dp_audio_list_append(list, aac_decoder_frame_p);
|
||||||
nRet = A2DP_DECODER_NO_ERROR;
|
nRet = A2DP_DECODER_NO_ERROR;
|
||||||
}else{
|
}else{
|
||||||
TRACE_A2DP_DECODER_I(
|
TRACE_A2DP_DECODER_I("[AAC][INPUT] list full current list_len:%d buff_len:%d", a2dp_audio_list_length(list), buffer_bytes);
|
||||||
"[AAC][INPUT] list full current list_len:%d buff_len:%d",
|
|
||||||
a2dp_audio_list_length(list), buffer_bytes);
|
|
||||||
nRet = A2DP_DECODER_MTU_LIMTER_ERROR;
|
nRet = A2DP_DECODER_MTU_LIMTER_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -915,7 +832,8 @@ int a2dp_audio_aac_lc_store_packet(btif_media_header_t *header, uint8_t *buffer,
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int a2dp_audio_aac_lc_discards_packet(uint32_t packets) {
|
int a2dp_audio_aac_lc_discards_packet(uint32_t packets)
|
||||||
|
{
|
||||||
int nRet = A2DP_DECODER_MEMORY_ERROR;
|
int nRet = A2DP_DECODER_MEMORY_ERROR;
|
||||||
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
||||||
list_node_t *node = NULL;
|
list_node_t *node = NULL;
|
||||||
|
@ -928,8 +846,7 @@ int a2dp_audio_aac_lc_discards_packet(uint32_t packets) {
|
||||||
if (packets <= a2dp_audio_list_length(list)){
|
if (packets <= a2dp_audio_list_length(list)){
|
||||||
for (uint8_t i=0; i<packets; i++){
|
for (uint8_t i=0; i<packets; i++){
|
||||||
if ((node = a2dp_audio_list_begin(list)) != NULL){
|
if ((node = a2dp_audio_list_begin(list)) != NULL){
|
||||||
aac_decoder_frame_p =
|
aac_decoder_frame_p = (a2dp_audio_aac_decoder_frame_t *)a2dp_audio_list_node(node);
|
||||||
(a2dp_audio_aac_decoder_frame_t *)a2dp_audio_list_node(node);
|
|
||||||
a2dp_audio_list_remove(list, aac_decoder_frame_p);
|
a2dp_audio_list_remove(list, aac_decoder_frame_p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -940,16 +857,14 @@ int a2dp_audio_aac_lc_discards_packet(uint32_t packets) {
|
||||||
return nRet;
|
return nRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2dp_audio_aac_lc_headframe_info_get(
|
int a2dp_audio_aac_lc_headframe_info_get(A2DP_AUDIO_HEADFRAME_INFO_T* headframe_info)
|
||||||
A2DP_AUDIO_HEADFRAME_INFO_T *headframe_info) {
|
{
|
||||||
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
||||||
list_node_t *node = NULL;
|
list_node_t *node = NULL;
|
||||||
a2dp_audio_aac_decoder_frame_t *aac_decoder_frame = NULL;
|
a2dp_audio_aac_decoder_frame_t *aac_decoder_frame = NULL;
|
||||||
|
|
||||||
if (a2dp_audio_list_length(list) &&
|
if (a2dp_audio_list_length(list) && ((node = a2dp_audio_list_begin(list)) != NULL)){
|
||||||
((node = a2dp_audio_list_begin(list)) != NULL)) {
|
aac_decoder_frame = (a2dp_audio_aac_decoder_frame_t *)a2dp_audio_list_node(node);
|
||||||
aac_decoder_frame =
|
|
||||||
(a2dp_audio_aac_decoder_frame_t *)a2dp_audio_list_node(node);
|
|
||||||
headframe_info->sequenceNumber = aac_decoder_frame->sequenceNumber;
|
headframe_info->sequenceNumber = aac_decoder_frame->sequenceNumber;
|
||||||
headframe_info->timestamp = aac_decoder_frame->timestamp;
|
headframe_info->timestamp = aac_decoder_frame->timestamp;
|
||||||
headframe_info->curSubSequenceNumber = 0;
|
headframe_info->curSubSequenceNumber = 0;
|
||||||
|
@ -961,10 +876,13 @@ int a2dp_audio_aac_lc_headframe_info_get(
|
||||||
return A2DP_DECODER_NO_ERROR;
|
return A2DP_DECODER_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2dp_audio_aac_lc_info_get(void *info) { return A2DP_DECODER_NO_ERROR; }
|
int a2dp_audio_aac_lc_info_get(void *info)
|
||||||
|
{
|
||||||
|
return A2DP_DECODER_NO_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
int a2dp_audio_aac_lc_synchronize_packet(A2DP_AUDIO_SYNCFRAME_INFO_T *sync_info,
|
int a2dp_audio_aac_lc_synchronize_packet(A2DP_AUDIO_SYNCFRAME_INFO_T *sync_info, uint32_t mask)
|
||||||
uint32_t mask) {
|
{
|
||||||
int nRet = A2DP_DECODER_SYNC_ERROR;
|
int nRet = A2DP_DECODER_SYNC_ERROR;
|
||||||
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
||||||
list_node_t *node = NULL;
|
list_node_t *node = NULL;
|
||||||
|
@ -980,18 +898,11 @@ int a2dp_audio_aac_lc_synchronize_packet(A2DP_AUDIO_SYNCFRAME_INFO_T *sync_info,
|
||||||
for (uint16_t i=0; i<list_len; i++){
|
for (uint16_t i=0; i<list_len; i++){
|
||||||
node = a2dp_audio_list_begin(list);
|
node = a2dp_audio_list_begin(list);
|
||||||
if (node){
|
if (node){
|
||||||
aac_decoder_frame_p =
|
aac_decoder_frame_p = (a2dp_audio_aac_decoder_frame_t *)a2dp_audio_list_node(node);
|
||||||
(a2dp_audio_aac_decoder_frame_t *)a2dp_audio_list_node(node);
|
TRACE_A2DP_DECODER_D("[synchronize_packet]%d/%d %x/%x", aac_decoder_frame_p->sequenceNumber, sync_info->sequenceNumber,
|
||||||
TRACE_A2DP_DECODER_D(
|
|
||||||
"[synchronize_packet]%d/%d %x/%x",
|
|
||||||
aac_decoder_frame_p->sequenceNumber, sync_info->sequenceNumber,
|
|
||||||
aac_decoder_frame_p->timestamp, sync_info->timestamp);
|
aac_decoder_frame_p->timestamp, sync_info->timestamp);
|
||||||
if (A2DP_AUDIO_SYNCFRAME_CHK(aac_decoder_frame_p->sequenceNumber ==
|
if (A2DP_AUDIO_SYNCFRAME_CHK(aac_decoder_frame_p->sequenceNumber == sync_info->sequenceNumber, A2DP_AUDIO_SYNCFRAME_MASK_SEQ, mask)&&
|
||||||
sync_info->sequenceNumber,
|
A2DP_AUDIO_SYNCFRAME_CHK(aac_decoder_frame_p->timestamp == sync_info->timestamp, A2DP_AUDIO_SYNCFRAME_MASK_TIMESTAMP, mask)){
|
||||||
A2DP_AUDIO_SYNCFRAME_MASK_SEQ, mask) &&
|
|
||||||
A2DP_AUDIO_SYNCFRAME_CHK(aac_decoder_frame_p->timestamp ==
|
|
||||||
sync_info->timestamp,
|
|
||||||
A2DP_AUDIO_SYNCFRAME_MASK_TIMESTAMP, mask)) {
|
|
||||||
nRet = A2DP_DECODER_NO_ERROR;
|
nRet = A2DP_DECODER_NO_ERROR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1001,11 +912,8 @@ int a2dp_audio_aac_lc_synchronize_packet(A2DP_AUDIO_SYNCFRAME_INFO_T *sync_info,
|
||||||
|
|
||||||
node = a2dp_audio_list_begin(list);
|
node = a2dp_audio_list_begin(list);
|
||||||
if (node){
|
if (node){
|
||||||
aac_decoder_frame_p =
|
aac_decoder_frame_p = (a2dp_audio_aac_decoder_frame_t *)a2dp_audio_list_node(node);
|
||||||
(a2dp_audio_aac_decoder_frame_t *)a2dp_audio_list_node(node);
|
TRACE_A2DP_DECODER_I("[MCU][SYNC][AAC] sync pkt nRet:%d SEQ:%d timestamp:%d", nRet, aac_decoder_frame_p->sequenceNumber, aac_decoder_frame_p->timestamp);
|
||||||
TRACE_A2DP_DECODER_I(
|
|
||||||
"[MCU][SYNC][AAC] sync pkt nRet:%d SEQ:%d timestamp:%d", nRet,
|
|
||||||
aac_decoder_frame_p->sequenceNumber, aac_decoder_frame_p->timestamp);
|
|
||||||
}else{
|
}else{
|
||||||
TRACE_A2DP_DECODER_I("[MCU][SYNC][AAC] sync pkt nRet:%d", nRet);
|
TRACE_A2DP_DECODER_I("[MCU][SYNC][AAC] sync pkt nRet:%d", nRet);
|
||||||
}
|
}
|
||||||
|
@ -1013,7 +921,8 @@ int a2dp_audio_aac_lc_synchronize_packet(A2DP_AUDIO_SYNCFRAME_INFO_T *sync_info,
|
||||||
return nRet;
|
return nRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2dp_audio_aac_lc_synchronize_dest_packet_mut(uint16_t packet_mut) {
|
int a2dp_audio_aac_lc_synchronize_dest_packet_mut(uint16_t packet_mut)
|
||||||
|
{
|
||||||
list_node_t *node = NULL;
|
list_node_t *node = NULL;
|
||||||
uint32_t list_len = 0;
|
uint32_t list_len = 0;
|
||||||
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
||||||
|
@ -1024,8 +933,7 @@ int a2dp_audio_aac_lc_synchronize_dest_packet_mut(uint16_t packet_mut) {
|
||||||
do{
|
do{
|
||||||
node = a2dp_audio_list_begin(list);
|
node = a2dp_audio_list_begin(list);
|
||||||
if (node){
|
if (node){
|
||||||
aac_decoder_frame_p =
|
aac_decoder_frame_p = (a2dp_audio_aac_decoder_frame_t *)a2dp_audio_list_node(node);
|
||||||
(a2dp_audio_aac_decoder_frame_t *)a2dp_audio_list_node(node);
|
|
||||||
a2dp_audio_list_remove(list, aac_decoder_frame_p);
|
a2dp_audio_list_remove(list, aac_decoder_frame_p);
|
||||||
}
|
}
|
||||||
}while(a2dp_audio_list_length(list) > packet_mut);
|
}while(a2dp_audio_list_length(list) > packet_mut);
|
||||||
|
@ -1038,33 +946,32 @@ int a2dp_audio_aac_lc_synchronize_dest_packet_mut(uint16_t packet_mut) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TRACE_A2DP_DECODER_I("[MCU][SYNC][AAC] dest pkt list:%d",
|
TRACE_A2DP_DECODER_I("[MCU][SYNC][AAC] dest pkt list:%d", a2dp_audio_list_length(list));
|
||||||
a2dp_audio_list_length(list));
|
|
||||||
return A2DP_DECODER_NO_ERROR;
|
return A2DP_DECODER_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2dp_audio_aac_lc_convert_list_to_samples(uint32_t *samples) {
|
int a2dp_audio_aac_lc_convert_list_to_samples(uint32_t *samples)
|
||||||
|
{
|
||||||
uint32_t list_len = 0;
|
uint32_t list_len = 0;
|
||||||
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
||||||
|
|
||||||
list_len = a2dp_audio_list_length(list);
|
list_len = a2dp_audio_list_length(list);
|
||||||
*samples = AAC_OUTPUT_FRAME_SAMPLES*list_len;
|
*samples = AAC_OUTPUT_FRAME_SAMPLES*list_len;
|
||||||
|
|
||||||
TRACE_A2DP_DECODER_I("AUD][DECODER][MCU][AAC] list:%d samples:%d", list_len,
|
TRACE_A2DP_DECODER_I("AUD][DECODER][MCU][AAC] list:%d samples:%d", list_len, *samples);
|
||||||
*samples);
|
|
||||||
|
|
||||||
return A2DP_DECODER_NO_ERROR;
|
return A2DP_DECODER_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2dp_audio_aac_lc_discards_samples(uint32_t samples) {
|
int a2dp_audio_aac_lc_discards_samples(uint32_t samples)
|
||||||
|
{
|
||||||
int nRet = A2DP_DECODER_SYNC_ERROR;
|
int nRet = A2DP_DECODER_SYNC_ERROR;
|
||||||
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
||||||
a2dp_audio_aac_decoder_frame_t *aac_decoder_frame_p = NULL;
|
a2dp_audio_aac_decoder_frame_t *aac_decoder_frame_p = NULL;
|
||||||
list_node_t *node = NULL;
|
list_node_t *node = NULL;
|
||||||
int need_remove_list = 0;
|
int need_remove_list = 0;
|
||||||
uint32_t list_samples = 0;
|
uint32_t list_samples = 0;
|
||||||
ASSERT_A2DP_DECODER(!(samples % AAC_OUTPUT_FRAME_SAMPLES),
|
ASSERT_A2DP_DECODER(!(samples%AAC_OUTPUT_FRAME_SAMPLES), "%s samples err:%d", __func__, samples);
|
||||||
"%s samples err:%d", __func__, samples);
|
|
||||||
|
|
||||||
a2dp_audio_aac_lc_convert_list_to_samples(&list_samples);
|
a2dp_audio_aac_lc_convert_list_to_samples(&list_samples);
|
||||||
if (list_samples >= samples){
|
if (list_samples >= samples){
|
||||||
|
@ -1072,8 +979,7 @@ int a2dp_audio_aac_lc_discards_samples(uint32_t samples) {
|
||||||
for (int i=0; i<need_remove_list; i++){
|
for (int i=0; i<need_remove_list; i++){
|
||||||
node = a2dp_audio_list_begin(list);
|
node = a2dp_audio_list_begin(list);
|
||||||
if (node){
|
if (node){
|
||||||
aac_decoder_frame_p =
|
aac_decoder_frame_p = (a2dp_audio_aac_decoder_frame_t *)a2dp_audio_list_node(node);
|
||||||
(a2dp_audio_aac_decoder_frame_t *)a2dp_audio_list_node(node);
|
|
||||||
a2dp_audio_list_remove(list, aac_decoder_frame_p);
|
a2dp_audio_list_remove(list, aac_decoder_frame_p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1102,7 +1008,5 @@ A2DP_AUDIO_DECODER_T a2dp_audio_aac_lc_decoder_config = {
|
||||||
a2dp_audio_aac_lc_channel_select,
|
a2dp_audio_aac_lc_channel_select,
|
||||||
} ;
|
} ;
|
||||||
#else
|
#else
|
||||||
A2DP_AUDIO_DECODER_T a2dp_audio_aac_lc_decoder_config = {
|
A2DP_AUDIO_DECODER_T a2dp_audio_aac_lc_decoder_config = {0,} ;
|
||||||
0,
|
|
||||||
};
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#ifdef A2DP_CP_ACCEL
|
#ifdef A2DP_CP_ACCEL
|
||||||
|
|
||||||
#include "a2dp_decoder_cp.h"
|
|
||||||
#include "a2dp_decoder_internal.h"
|
#include "a2dp_decoder_internal.h"
|
||||||
|
#include "a2dp_decoder_cp.h"
|
||||||
#include "cp_accel.h"
|
#include "cp_accel.h"
|
||||||
#include "hal_location.h"
|
#include "hal_location.h"
|
||||||
#include "hal_timer.h"
|
#include "hal_timer.h"
|
||||||
|
@ -82,21 +82,28 @@ static enum CP_PROC_DELAY_T proc_delay;
|
||||||
static bool cp_need_reset;
|
static bool cp_need_reset;
|
||||||
|
|
||||||
CP_TEXT_SRAM_LOC
|
CP_TEXT_SRAM_LOC
|
||||||
unsigned int set_cp_reset_flag(uint8_t evt) {
|
unsigned int set_cp_reset_flag(uint8_t evt)
|
||||||
|
{
|
||||||
cp_need_reset = true;
|
cp_need_reset = true;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_cp_need_reset(void) {
|
bool is_cp_need_reset(void)
|
||||||
|
{
|
||||||
bool ret = cp_need_reset;
|
bool ret = cp_need_reset;
|
||||||
cp_need_reset = false;
|
cp_need_reset = false;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_cp_init_done(void) { return cp_accel_init_done(); }
|
bool is_cp_init_done(void)
|
||||||
|
{
|
||||||
|
return cp_accel_init_done();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
CP_TEXT_SRAM_LOC
|
CP_TEXT_SRAM_LOC
|
||||||
static void reset_frame_info(void) {
|
static void reset_frame_info(void)
|
||||||
|
{
|
||||||
uint32_t idle_cnt;
|
uint32_t idle_cnt;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -125,7 +132,8 @@ static void reset_frame_info(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
CP_TEXT_SRAM_LOC
|
CP_TEXT_SRAM_LOC
|
||||||
static unsigned int cp_a2dp_main(uint8_t event) {
|
static unsigned int cp_a2dp_main(uint8_t event)
|
||||||
|
{
|
||||||
int ret;
|
int ret;
|
||||||
#ifdef A2DP_TRACE_CP_DEC_TIME
|
#ifdef A2DP_TRACE_CP_DEC_TIME
|
||||||
uint32_t stime;
|
uint32_t stime;
|
||||||
|
@ -146,9 +154,7 @@ static unsigned int cp_a2dp_main(uint8_t event) {
|
||||||
|
|
||||||
#ifdef A2DP_TRACE_CP_DEC_TIME
|
#ifdef A2DP_TRACE_CP_DEC_TIME
|
||||||
etime = hal_fast_sys_timer_get();
|
etime = hal_fast_sys_timer_get();
|
||||||
TRACE_A2DP_DECODER_I("cp_decode: %5u us in %5u us",
|
TRACE_A2DP_DECODER_I("cp_decode: %5u us in %5u us", FAST_TICKS_TO_US(etime - stime), FAST_TICKS_TO_US(etime - cp_last_dec_time));
|
||||||
FAST_TICKS_TO_US(etime - stime),
|
|
||||||
FAST_TICKS_TO_US(etime - cp_last_dec_time));
|
|
||||||
cp_last_dec_time = etime;
|
cp_last_dec_time = etime;
|
||||||
#endif
|
#endif
|
||||||
} while (ret == 0);
|
} while (ret == 0);
|
||||||
|
@ -164,9 +170,9 @@ static unsigned int cp_a2dp_main(uint8_t event) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct cp_task_desc TASK_DESC_A2DP = {
|
static struct cp_task_desc TASK_DESC_A2DP = {CP_ACCEL_STATE_CLOSED, cp_a2dp_main, NULL, NULL, set_cp_reset_flag};
|
||||||
CP_ACCEL_STATE_CLOSED, cp_a2dp_main, NULL, NULL, set_cp_reset_flag};
|
int a2dp_cp_init(A2DP_CP_DECODE_T decode_func, enum CP_PROC_DELAY_T delay)
|
||||||
int a2dp_cp_init(A2DP_CP_DECODE_T decode_func, enum CP_PROC_DELAY_T delay) {
|
{
|
||||||
if (delay >= CP_PROC_DELAY_QTY) {
|
if (delay >= CP_PROC_DELAY_QTY) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -177,8 +183,7 @@ int a2dp_cp_init(A2DP_CP_DECODE_T decode_func, enum CP_PROC_DELAY_T delay) {
|
||||||
cp_last_dec_time = hal_fast_sys_timer_get();
|
cp_last_dec_time = hal_fast_sys_timer_get();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
norflash_api_flush_disable(NORFLASH_API_USER_CP,
|
norflash_api_flush_disable(NORFLASH_API_USER_CP,(uint32_t)cp_accel_init_done);
|
||||||
(uint32_t)cp_accel_init_done);
|
|
||||||
cp_accel_open(CP_TASK_A2DP_DECODE, &TASK_DESC_A2DP);
|
cp_accel_open(CP_TASK_A2DP_DECODE, &TASK_DESC_A2DP);
|
||||||
while(cp_accel_init_done() == false) {
|
while(cp_accel_init_done() == false) {
|
||||||
hal_sys_timer_delay_us(100);
|
hal_sys_timer_delay_us(100);
|
||||||
|
@ -186,14 +191,16 @@ int a2dp_cp_init(A2DP_CP_DECODE_T decode_func, enum CP_PROC_DELAY_T delay) {
|
||||||
norflash_api_flush_enable(NORFLASH_API_USER_CP);
|
norflash_api_flush_enable(NORFLASH_API_USER_CP);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int a2dp_cp_deinit(void) {
|
int a2dp_cp_deinit(void)
|
||||||
|
{
|
||||||
cp_accel_close(CP_TASK_A2DP_DECODE);
|
cp_accel_close(CP_TASK_A2DP_DECODE);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SRAM_TEXT_LOC
|
SRAM_TEXT_LOC
|
||||||
int a2dp_cp_decoder_init(uint32_t out_frame_len, uint8_t max_frames) {
|
int a2dp_cp_decoder_init(uint32_t out_frame_len, uint8_t max_frames)
|
||||||
|
{
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
max_buffer_frames = max_frames;
|
max_buffer_frames = max_frames;
|
||||||
if (!mcu_dec_inited) {
|
if (!mcu_dec_inited) {
|
||||||
|
@ -243,7 +250,8 @@ int a2dp_cp_decoder_init(uint32_t out_frame_len, uint8_t max_frames) {
|
||||||
}
|
}
|
||||||
|
|
||||||
CP_TEXT_SRAM_LOC
|
CP_TEXT_SRAM_LOC
|
||||||
static uint32_t get_in_frame_cnt(uint32_t in_widx, uint32_t in_ridx) {
|
static uint32_t get_in_frame_cnt(uint32_t in_widx, uint32_t in_ridx)
|
||||||
|
{
|
||||||
uint32_t cnt;
|
uint32_t cnt;
|
||||||
|
|
||||||
if (in_widx >= in_ridx) {
|
if (in_widx >= in_ridx) {
|
||||||
|
@ -255,14 +263,19 @@ static uint32_t get_in_frame_cnt(uint32_t in_widx, uint32_t in_ridx) {
|
||||||
return cnt;
|
return cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t get_in_cp_frame_cnt(void) {
|
uint32_t get_in_cp_frame_cnt(void)
|
||||||
|
{
|
||||||
return get_in_frame_cnt(cp_in_widx, cp_in_ridx);
|
return get_in_frame_cnt(cp_in_widx, cp_in_ridx);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t get_in_cp_frame_delay(void) { return proc_delay; }
|
uint32_t get_in_cp_frame_delay(void)
|
||||||
|
{
|
||||||
|
return proc_delay;
|
||||||
|
}
|
||||||
|
|
||||||
SRAM_TEXT_LOC
|
SRAM_TEXT_LOC
|
||||||
static uint32_t get_in_frame_free_cnt(uint32_t in_widx, uint32_t in_ridx) {
|
static uint32_t get_in_frame_free_cnt(uint32_t in_widx, uint32_t in_ridx)
|
||||||
|
{
|
||||||
uint32_t free_cnt;
|
uint32_t free_cnt;
|
||||||
|
|
||||||
if (in_widx >= in_ridx) {
|
if (in_widx >= in_ridx) {
|
||||||
|
@ -276,8 +289,8 @@ static uint32_t get_in_frame_free_cnt(uint32_t in_widx, uint32_t in_ridx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SRAM_TEXT_LOC
|
SRAM_TEXT_LOC
|
||||||
int a2dp_cp_put_in_frame(const void *buf1, uint32_t len1, const void *buf2,
|
int a2dp_cp_put_in_frame(const void *buf1, uint32_t len1, const void *buf2, uint32_t len2)
|
||||||
uint32_t len2) {
|
{
|
||||||
uint16_t free_cnt;
|
uint16_t free_cnt;
|
||||||
uint16_t in_widx;
|
uint16_t in_widx;
|
||||||
uint16_t in_ridx;
|
uint16_t in_ridx;
|
||||||
|
@ -367,7 +380,8 @@ int a2dp_cp_put_in_frame(const void *buf1, uint32_t len1, const void *buf2,
|
||||||
}
|
}
|
||||||
|
|
||||||
CP_TEXT_SRAM_LOC
|
CP_TEXT_SRAM_LOC
|
||||||
int a2dp_cp_get_in_frame(void **p_buf, uint32_t *p_len) {
|
int a2dp_cp_get_in_frame(void **p_buf, uint32_t *p_len)
|
||||||
|
{
|
||||||
uint16_t in_widx;
|
uint16_t in_widx;
|
||||||
uint16_t in_ridx;
|
uint16_t in_ridx;
|
||||||
uint32_t in_rpos;
|
uint32_t in_rpos;
|
||||||
|
@ -396,7 +410,8 @@ int a2dp_cp_get_in_frame(void **p_buf, uint32_t *p_len) {
|
||||||
}
|
}
|
||||||
|
|
||||||
CP_TEXT_SRAM_LOC
|
CP_TEXT_SRAM_LOC
|
||||||
int a2dp_cp_consume_in_frame(void) {
|
int a2dp_cp_consume_in_frame(void)
|
||||||
|
{
|
||||||
uint16_t in_widx;
|
uint16_t in_widx;
|
||||||
uint16_t in_ridx;
|
uint16_t in_ridx;
|
||||||
|
|
||||||
|
@ -421,15 +436,20 @@ int a2dp_cp_consume_in_frame(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
CP_TEXT_SRAM_LOC
|
CP_TEXT_SRAM_LOC
|
||||||
uint32_t a2dp_cp_get_in_frame_index(void) { return cp_in_ridx; }
|
uint32_t a2dp_cp_get_in_frame_index(void)
|
||||||
|
{
|
||||||
|
return cp_in_ridx;
|
||||||
|
}
|
||||||
|
|
||||||
SRAM_TEXT_LOC
|
SRAM_TEXT_LOC
|
||||||
uint32_t a2dp_cp_get_in_frame_cnt_by_index(uint32_t ridx) {
|
uint32_t a2dp_cp_get_in_frame_cnt_by_index(uint32_t ridx)
|
||||||
|
{
|
||||||
return get_in_frame_cnt(cp_in_widx, ridx);
|
return get_in_frame_cnt(cp_in_widx, ridx);
|
||||||
}
|
}
|
||||||
|
|
||||||
SRAM_TEXT_LOC
|
SRAM_TEXT_LOC
|
||||||
void a2dp_cp_reset_frame(void) {
|
void a2dp_cp_reset_frame(void)
|
||||||
|
{
|
||||||
#ifdef A2DP_TRACE_CP_ACCEL
|
#ifdef A2DP_TRACE_CP_ACCEL
|
||||||
TRACE_A2DP_DECODER_I("%s: Reset frames", __func__);
|
TRACE_A2DP_DECODER_I("%s: Reset frames", __func__);
|
||||||
#endif
|
#endif
|
||||||
|
@ -441,11 +461,14 @@ void a2dp_cp_reset_frame(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SRAM_TEXT_LOC
|
SRAM_TEXT_LOC
|
||||||
bool a2dp_cp_get_frame_reset_status(void) { return reset_frames; }
|
bool a2dp_cp_get_frame_reset_status(void)
|
||||||
|
{
|
||||||
|
return reset_frames;
|
||||||
|
}
|
||||||
|
|
||||||
CP_TEXT_SRAM_LOC
|
CP_TEXT_SRAM_LOC
|
||||||
enum CP_EMPTY_OUT_FRM_T a2dp_cp_get_emtpy_out_frame(void **p_buf,
|
enum CP_EMPTY_OUT_FRM_T a2dp_cp_get_emtpy_out_frame(void **p_buf, uint32_t *p_len)
|
||||||
uint32_t *p_len) {
|
{
|
||||||
enum CP_EMPTY_OUT_FRM_T ret;
|
enum CP_EMPTY_OUT_FRM_T ret;
|
||||||
uint8_t out_widx;
|
uint8_t out_widx;
|
||||||
uint32_t out_wpos;
|
uint32_t out_wpos;
|
||||||
|
@ -482,7 +505,8 @@ enum CP_EMPTY_OUT_FRM_T a2dp_cp_get_emtpy_out_frame(void **p_buf,
|
||||||
}
|
}
|
||||||
|
|
||||||
CP_TEXT_SRAM_LOC
|
CP_TEXT_SRAM_LOC
|
||||||
int a2dp_cp_consume_emtpy_out_frame(void) {
|
int a2dp_cp_consume_emtpy_out_frame(void)
|
||||||
|
{
|
||||||
uint8_t out_widx;
|
uint8_t out_widx;
|
||||||
|
|
||||||
if (reset_frames) {
|
if (reset_frames) {
|
||||||
|
@ -511,7 +535,8 @@ int a2dp_cp_consume_emtpy_out_frame(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SRAM_TEXT_LOC
|
SRAM_TEXT_LOC
|
||||||
int a2dp_cp_get_full_out_frame(void **p_buf, uint32_t *p_len) {
|
int a2dp_cp_get_full_out_frame(void **p_buf, uint32_t *p_len)
|
||||||
|
{
|
||||||
uint8_t out_ridx;
|
uint8_t out_ridx;
|
||||||
uint32_t out_rpos;
|
uint32_t out_rpos;
|
||||||
enum CP_DEC_STATE_T state ;
|
enum CP_DEC_STATE_T state ;
|
||||||
|
@ -525,8 +550,7 @@ int a2dp_cp_get_full_out_frame(void **p_buf, uint32_t *p_len) {
|
||||||
|
|
||||||
if (state != CP_DEC_STATE_DONE && state != CP_DEC_STATE_INIT_DONE) {
|
if (state != CP_DEC_STATE_DONE && state != CP_DEC_STATE_INIT_DONE) {
|
||||||
// Notify CP to work again
|
// Notify CP to work again
|
||||||
cp_accel_send_event_mcu2cp(
|
cp_accel_send_event_mcu2cp(CP_BUILD_ID(CP_TASK_A2DP_DECODE, CP_EVENT_A2DP_DECODE));
|
||||||
CP_BUILD_ID(CP_TASK_A2DP_DECODE, CP_EVENT_A2DP_DECODE));
|
|
||||||
if (state == CP_DEC_STATE_WORKING){
|
if (state == CP_DEC_STATE_WORKING){
|
||||||
return CP_EMPTY_OUT_FRM_WORKING;
|
return CP_EMPTY_OUT_FRM_WORKING;
|
||||||
}else{
|
}else{
|
||||||
|
@ -556,7 +580,8 @@ int a2dp_cp_get_full_out_frame(void **p_buf, uint32_t *p_len) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SRAM_TEXT_LOC
|
SRAM_TEXT_LOC
|
||||||
int a2dp_cp_consume_full_out_frame(void) {
|
int a2dp_cp_consume_full_out_frame(void)
|
||||||
|
{
|
||||||
uint8_t out_ridx;
|
uint8_t out_ridx;
|
||||||
enum CP_DEC_STATE_T state ;
|
enum CP_DEC_STATE_T state ;
|
||||||
|
|
||||||
|
@ -584,10 +609,10 @@ int a2dp_cp_consume_full_out_frame(void) {
|
||||||
cp_out_ridx = out_ridx;
|
cp_out_ridx = out_ridx;
|
||||||
|
|
||||||
// Notify CP to work again
|
// Notify CP to work again
|
||||||
cp_accel_send_event_mcu2cp(
|
cp_accel_send_event_mcu2cp(CP_BUILD_ID(CP_TASK_A2DP_DECODE, CP_EVENT_A2DP_DECODE));
|
||||||
CP_BUILD_ID(CP_TASK_A2DP_DECODE, CP_EVENT_A2DP_DECODE));
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -14,12 +14,12 @@
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
// Standard C Included Files
|
// Standard C Included Files
|
||||||
#include "a2dp_decoder_internal.h"
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "hal_location.h"
|
|
||||||
#include "heap_api.h"
|
|
||||||
#include "plat_types.h"
|
#include "plat_types.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "heap_api.h"
|
||||||
|
#include "hal_location.h"
|
||||||
|
#include "a2dp_decoder_internal.h"
|
||||||
|
|
||||||
static A2DP_AUDIO_CONTEXT_T *a2dp_audio_context_p = NULL;
|
static A2DP_AUDIO_CONTEXT_T *a2dp_audio_context_p = NULL;
|
||||||
static A2DP_AUDIO_DECODER_LASTFRAME_INFO_T a2dp_audio_ldac_example_info;
|
static A2DP_AUDIO_DECODER_LASTFRAME_INFO_T a2dp_audio_ldac_example_info;
|
||||||
|
@ -32,41 +32,41 @@ typedef struct {
|
||||||
uint32_t buffer_len;
|
uint32_t buffer_len;
|
||||||
} a2dp_audio_example_decoder_frame_t;
|
} a2dp_audio_example_decoder_frame_t;
|
||||||
|
|
||||||
int a2dp_audio_example_decode_frame(uint8_t *buffer, uint32_t buffer_bytes) {
|
|
||||||
|
int a2dp_audio_example_decode_frame(uint8_t *buffer, uint32_t buffer_bytes)
|
||||||
|
{
|
||||||
return A2DP_DECODER_NO_ERROR;
|
return A2DP_DECODER_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2dp_audio_example_preparse_packet(btif_media_header_t *header,
|
int a2dp_audio_example_preparse_packet(btif_media_header_t * header, uint8_t *buffer, uint32_t buffer_bytes)
|
||||||
uint8_t *buffer, uint32_t buffer_bytes) {
|
{
|
||||||
return A2DP_DECODER_NO_ERROR;
|
return A2DP_DECODER_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *a2dp_audio_example_frame_malloc(uint32_t packet_len) {
|
|
||||||
|
static void *a2dp_audio_example_frame_malloc(uint32_t packet_len)
|
||||||
|
{
|
||||||
a2dp_audio_example_decoder_frame_t *decoder_frame_p = NULL;
|
a2dp_audio_example_decoder_frame_t *decoder_frame_p = NULL;
|
||||||
uint8_t *buffer = NULL;
|
uint8_t *buffer = NULL;
|
||||||
|
|
||||||
buffer = (uint8_t *)a2dp_audio_heap_malloc(packet_len);
|
buffer = (uint8_t *)a2dp_audio_heap_malloc(packet_len);
|
||||||
decoder_frame_p =
|
decoder_frame_p = (a2dp_audio_example_decoder_frame_t *)a2dp_audio_heap_malloc(sizeof(a2dp_audio_example_decoder_frame_t));
|
||||||
(a2dp_audio_example_decoder_frame_t *)a2dp_audio_heap_malloc(
|
|
||||||
sizeof(a2dp_audio_example_decoder_frame_t));
|
|
||||||
decoder_frame_p->buffer = buffer;
|
decoder_frame_p->buffer = buffer;
|
||||||
decoder_frame_p->buffer_len = packet_len;
|
decoder_frame_p->buffer_len = packet_len;
|
||||||
return (void *)decoder_frame_p;
|
return (void *)decoder_frame_p;
|
||||||
}
|
}
|
||||||
|
|
||||||
void a2dp_audio_example_free(void *packet) {
|
void a2dp_audio_example_free(void *packet)
|
||||||
a2dp_audio_example_decoder_frame_t *decoder_frame_p =
|
{
|
||||||
(a2dp_audio_example_decoder_frame_t *)packet;
|
a2dp_audio_example_decoder_frame_t *decoder_frame_p = (a2dp_audio_example_decoder_frame_t *)packet;
|
||||||
a2dp_audio_heap_free(decoder_frame_p->buffer);
|
a2dp_audio_heap_free(decoder_frame_p->buffer);
|
||||||
a2dp_audio_heap_free(decoder_frame_p);
|
a2dp_audio_heap_free(decoder_frame_p);
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2dp_audio_example_store_packet(btif_media_header_t *header,
|
int a2dp_audio_example_store_packet(btif_media_header_t * header, uint8_t *buffer, uint32_t buffer_bytes)
|
||||||
uint8_t *buffer, uint32_t buffer_bytes) {
|
{
|
||||||
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
||||||
a2dp_audio_example_decoder_frame_t *decoder_frame_p =
|
a2dp_audio_example_decoder_frame_t *decoder_frame_p = (a2dp_audio_example_decoder_frame_t *)a2dp_audio_example_frame_malloc(buffer_bytes);
|
||||||
(a2dp_audio_example_decoder_frame_t *)a2dp_audio_example_frame_malloc(
|
|
||||||
buffer_bytes);
|
|
||||||
|
|
||||||
decoder_frame_p->sequenceNumber = header->sequenceNumber;
|
decoder_frame_p->sequenceNumber = header->sequenceNumber;
|
||||||
decoder_frame_p->timestamp = header->timestamp;
|
decoder_frame_p->timestamp = header->timestamp;
|
||||||
|
@ -77,38 +77,45 @@ int a2dp_audio_example_store_packet(btif_media_header_t *header,
|
||||||
return A2DP_DECODER_NO_ERROR;
|
return A2DP_DECODER_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2dp_audio_example_discards_packet(uint32_t packets) {
|
int a2dp_audio_example_discards_packet(uint32_t packets)
|
||||||
|
{
|
||||||
return A2DP_DECODER_NO_ERROR;
|
return A2DP_DECODER_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2dp_audio_example_headframe_info_get(
|
int a2dp_audio_example_headframe_info_get(A2DP_AUDIO_HEADFRAME_INFO_T* headframe_info)
|
||||||
A2DP_AUDIO_HEADFRAME_INFO_T *headframe_info) {
|
{
|
||||||
return A2DP_DECODER_NO_ERROR;
|
return A2DP_DECODER_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2dp_audio_example_info_get(void *info) { return A2DP_DECODER_NO_ERROR; }
|
int a2dp_audio_example_info_get(void *info)
|
||||||
|
{
|
||||||
|
return A2DP_DECODER_NO_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
int a2dp_audio_example_init(A2DP_AUDIO_OUTPUT_CONFIG_T *config, void *context) {
|
int a2dp_audio_example_init(A2DP_AUDIO_OUTPUT_CONFIG_T *config, void *context)
|
||||||
|
{
|
||||||
TRACE_A2DP_DECODER_D("%s", __func__);
|
TRACE_A2DP_DECODER_D("%s", __func__);
|
||||||
a2dp_audio_context_p = (A2DP_AUDIO_CONTEXT_T *)context;
|
a2dp_audio_context_p = (A2DP_AUDIO_CONTEXT_T *)context;
|
||||||
|
|
||||||
memset(&a2dp_audio_ldac_example_info, 0,
|
memset(&a2dp_audio_ldac_example_info, 0, sizeof(A2DP_AUDIO_DECODER_LASTFRAME_INFO_T));
|
||||||
sizeof(A2DP_AUDIO_DECODER_LASTFRAME_INFO_T));
|
memcpy(&a2dp_audio_example_output_config, config, sizeof(A2DP_AUDIO_OUTPUT_CONFIG_T));
|
||||||
memcpy(&a2dp_audio_example_output_config, config,
|
|
||||||
sizeof(A2DP_AUDIO_OUTPUT_CONFIG_T));
|
|
||||||
a2dp_audio_ldac_example_info.stream_info = &a2dp_audio_example_output_config;
|
a2dp_audio_ldac_example_info.stream_info = &a2dp_audio_example_output_config;
|
||||||
|
|
||||||
return A2DP_DECODER_NO_ERROR;
|
return A2DP_DECODER_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2dp_audio_example_deinit(void) { return A2DP_DECODER_NO_ERROR; }
|
int a2dp_audio_example_deinit(void)
|
||||||
|
{
|
||||||
int a2dp_audio_example_synchronize_packet(
|
|
||||||
A2DP_AUDIO_SYNCFRAME_INFO_T *sync_info, uint32_t mask) {
|
|
||||||
return A2DP_DECODER_NO_ERROR;
|
return A2DP_DECODER_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2dp_audio_example_synchronize_dest_packet_mut(uint16_t packet_mut) {
|
int a2dp_audio_example_synchronize_packet(A2DP_AUDIO_SYNCFRAME_INFO_T *sync_info, uint32_t mask)
|
||||||
|
{
|
||||||
|
return A2DP_DECODER_NO_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
int a2dp_audio_example_synchronize_dest_packet_mut(uint16_t packet_mut)
|
||||||
|
{
|
||||||
return A2DP_DECODER_NO_ERROR;
|
return A2DP_DECODER_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,3 +134,4 @@ A2DP_AUDIO_DECODER_T a2dp_audio_example_decoder_config = {
|
||||||
a2dp_audio_example_info_get,
|
a2dp_audio_example_info_get,
|
||||||
a2dp_audio_example_free,
|
a2dp_audio_example_free,
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -14,15 +14,15 @@
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
// Standard C Included Files
|
// Standard C Included Files
|
||||||
#include "a2dp_decoder_internal.h"
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "cmsis_os.h"
|
|
||||||
#include "codec_sbc.h"
|
|
||||||
#include "hal_location.h"
|
|
||||||
#include "hal_timer.h"
|
|
||||||
#include "heap_api.h"
|
|
||||||
#include "plat_types.h"
|
#include "plat_types.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "heap_api.h"
|
||||||
|
#include "hal_location.h"
|
||||||
|
#include "codec_sbc.h"
|
||||||
|
#include "a2dp_decoder_internal.h"
|
||||||
|
#include "hal_timer.h"
|
||||||
|
#include "cmsis_os.h"
|
||||||
|
|
||||||
#ifndef SBC_MTU_LIMITER
|
#ifndef SBC_MTU_LIMITER
|
||||||
#define SBC_MTU_LIMITER (250) /*must <= 332*/
|
#define SBC_MTU_LIMITER (250) /*must <= 332*/
|
||||||
|
@ -55,35 +55,33 @@ static A2DP_AUDIO_DECODER_LASTFRAME_INFO_T a2dp_audio_sbc_lastframe_info;
|
||||||
|
|
||||||
static uint16_t sbc_mtu_limiter = SBC_MTU_LIMITER;
|
static uint16_t sbc_mtu_limiter = SBC_MTU_LIMITER;
|
||||||
|
|
||||||
static btif_media_header_t sbc_decoder_last_valid_frame = {
|
static btif_media_header_t sbc_decoder_last_valid_frame = {0,};
|
||||||
0,
|
|
||||||
};
|
|
||||||
static bool sbc_decoder_last_valid_frame_ready = false;
|
static bool sbc_decoder_last_valid_frame_ready = false;
|
||||||
static bool sbc_chnl_mode_mono = false;
|
static bool sbc_chnl_mode_mono = false;
|
||||||
|
|
||||||
static int a2dp_audio_sbc_header_parser_init(void);
|
static int a2dp_audio_sbc_header_parser_init(void);
|
||||||
|
|
||||||
static void *a2dp_audio_sbc_subframe_malloc(uint32_t sbc_len) {
|
static void *a2dp_audio_sbc_subframe_malloc(uint32_t sbc_len)
|
||||||
|
{
|
||||||
a2dp_audio_sbc_decoder_frame_t *sbc_decoder_frame_p = NULL;
|
a2dp_audio_sbc_decoder_frame_t *sbc_decoder_frame_p = NULL;
|
||||||
uint8_t *sbc_buffer = NULL;
|
uint8_t *sbc_buffer = NULL;
|
||||||
|
|
||||||
sbc_buffer = (uint8_t *)a2dp_audio_heap_malloc(sbc_len);
|
sbc_buffer = (uint8_t *)a2dp_audio_heap_malloc(sbc_len);
|
||||||
sbc_decoder_frame_p =
|
sbc_decoder_frame_p = (a2dp_audio_sbc_decoder_frame_t *)a2dp_audio_heap_malloc(sizeof(a2dp_audio_sbc_decoder_frame_t));
|
||||||
(a2dp_audio_sbc_decoder_frame_t *)a2dp_audio_heap_malloc(
|
|
||||||
sizeof(a2dp_audio_sbc_decoder_frame_t));
|
|
||||||
sbc_decoder_frame_p->sbc_buffer = sbc_buffer;
|
sbc_decoder_frame_p->sbc_buffer = sbc_buffer;
|
||||||
sbc_decoder_frame_p->sbc_buffer_len = sbc_len;
|
sbc_decoder_frame_p->sbc_buffer_len = sbc_len;
|
||||||
return (void *)sbc_decoder_frame_p;
|
return (void *)sbc_decoder_frame_p;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void a2dp_audio_sbc_subframe_free(void *packet) {
|
static void a2dp_audio_sbc_subframe_free(void *packet)
|
||||||
a2dp_audio_sbc_decoder_frame_t *sbc_decoder_frame_p =
|
{
|
||||||
(a2dp_audio_sbc_decoder_frame_t *)packet;
|
a2dp_audio_sbc_decoder_frame_t *sbc_decoder_frame_p = (a2dp_audio_sbc_decoder_frame_t *)packet;
|
||||||
a2dp_audio_heap_free(sbc_decoder_frame_p->sbc_buffer);
|
a2dp_audio_heap_free(sbc_decoder_frame_p->sbc_buffer);
|
||||||
a2dp_audio_heap_free(sbc_decoder_frame_p);
|
a2dp_audio_heap_free(sbc_decoder_frame_p);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sbc_codec_init(void) {
|
static void sbc_codec_init(void)
|
||||||
|
{
|
||||||
btif_sbc_init_decoder(a2dp_audio_sbc_decoder.sbc_decoder);
|
btif_sbc_init_decoder(a2dp_audio_sbc_decoder.sbc_decoder);
|
||||||
a2dp_audio_sbc_decoder.sbc_decoder->maxPcmLen = SBC_PCMLEN_DEFAULT;
|
a2dp_audio_sbc_decoder.sbc_decoder->maxPcmLen = SBC_PCMLEN_DEFAULT;
|
||||||
a2dp_audio_sbc_decoder.pcm_data->data = NULL;
|
a2dp_audio_sbc_decoder.pcm_data->data = NULL;
|
||||||
|
@ -114,14 +112,16 @@ int a2dp_cp_sbc_cp_decode(void);
|
||||||
|
|
||||||
extern uint32_t app_bt_stream_get_dma_buffer_samples(void);
|
extern uint32_t app_bt_stream_get_dma_buffer_samples(void);
|
||||||
|
|
||||||
static int TEXT_SBC_LOC a2dp_cp_sbc_after_cache_underflow(void) {
|
static int TEXT_SBC_LOC a2dp_cp_sbc_after_cache_underflow(void)
|
||||||
|
{
|
||||||
#ifdef A2DP_CP_ACCEL
|
#ifdef A2DP_CP_ACCEL
|
||||||
cp_codec_reset = true;
|
cp_codec_reset = true;
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int a2dp_cp_sbc_mcu_decode(uint8_t *buffer, uint32_t buffer_bytes) {
|
static int a2dp_cp_sbc_mcu_decode(uint8_t *buffer, uint32_t buffer_bytes)
|
||||||
|
{
|
||||||
a2dp_audio_sbc_decoder_frame_t *sbc_decoder_frame = NULL;
|
a2dp_audio_sbc_decoder_frame_t *sbc_decoder_frame = NULL;
|
||||||
list_node_t *node = NULL;
|
list_node_t *node = NULL;
|
||||||
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
||||||
|
@ -136,12 +136,9 @@ static int a2dp_cp_sbc_mcu_decode(uint8_t *buffer, uint32_t buffer_bytes) {
|
||||||
|
|
||||||
cp_buffer_frames_max = app_bt_stream_get_dma_buffer_samples()/2;
|
cp_buffer_frames_max = app_bt_stream_get_dma_buffer_samples()/2;
|
||||||
if (cp_buffer_frames_max %(a2dp_audio_sbc_lastframe_info.frame_samples) ){
|
if (cp_buffer_frames_max %(a2dp_audio_sbc_lastframe_info.frame_samples) ){
|
||||||
cp_buffer_frames_max =
|
cp_buffer_frames_max = cp_buffer_frames_max /(a2dp_audio_sbc_lastframe_info.frame_samples) +1 ;
|
||||||
cp_buffer_frames_max / (a2dp_audio_sbc_lastframe_info.frame_samples) +
|
|
||||||
1;
|
|
||||||
}else{
|
}else{
|
||||||
cp_buffer_frames_max =
|
cp_buffer_frames_max = cp_buffer_frames_max /(a2dp_audio_sbc_lastframe_info.frame_samples) ;
|
||||||
cp_buffer_frames_max / (a2dp_audio_sbc_lastframe_info.frame_samples);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
out_frame_len = sizeof(*p_out_info) + buffer_bytes;
|
out_frame_len = sizeof(*p_out_info) + buffer_bytes;
|
||||||
|
@ -152,31 +149,26 @@ static int a2dp_cp_sbc_mcu_decode(uint8_t *buffer, uint32_t buffer_bytes) {
|
||||||
return A2DP_DECODER_DECODE_ERROR;
|
return A2DP_DECODER_DECODE_ERROR;
|
||||||
}
|
}
|
||||||
while ((node = a2dp_audio_list_begin(list)) != NULL) {
|
while ((node = a2dp_audio_list_begin(list)) != NULL) {
|
||||||
sbc_decoder_frame =
|
sbc_decoder_frame = (a2dp_audio_sbc_decoder_frame_t *)a2dp_audio_list_node(node);
|
||||||
(a2dp_audio_sbc_decoder_frame_t *)a2dp_audio_list_node(node);
|
|
||||||
|
|
||||||
in_info.sequenceNumber = sbc_decoder_frame->sequenceNumber;
|
in_info.sequenceNumber = sbc_decoder_frame->sequenceNumber;
|
||||||
in_info.timestamp = sbc_decoder_frame->timestamp;
|
in_info.timestamp = sbc_decoder_frame->timestamp;
|
||||||
in_info.curSubSequenceNumber = sbc_decoder_frame->curSubSequenceNumber;
|
in_info.curSubSequenceNumber = sbc_decoder_frame->curSubSequenceNumber;
|
||||||
in_info.totalSubSequenceNumber = sbc_decoder_frame->totalSubSequenceNumber;
|
in_info.totalSubSequenceNumber = sbc_decoder_frame->totalSubSequenceNumber;
|
||||||
|
|
||||||
ret = a2dp_cp_put_in_frame(&in_info, sizeof(in_info),
|
ret = a2dp_cp_put_in_frame(&in_info, sizeof(in_info), sbc_decoder_frame->sbc_buffer, sbc_decoder_frame->sbc_buffer_len);
|
||||||
sbc_decoder_frame->sbc_buffer,
|
|
||||||
sbc_decoder_frame->sbc_buffer_len);
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
TRACE_A2DP_DECODER_D("[MCU][SBC] piff !!!!!!ret: %d ", ret);
|
TRACE_A2DP_DECODER_D("[MCU][SBC] piff !!!!!!ret: %d ", ret);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
check_sum = a2dp_audio_decoder_internal_check_sum_generate(
|
check_sum = a2dp_audio_decoder_internal_check_sum_generate(sbc_decoder_frame->sbc_buffer, sbc_decoder_frame->sbc_buffer_len);
|
||||||
sbc_decoder_frame->sbc_buffer, sbc_decoder_frame->sbc_buffer_len);
|
|
||||||
a2dp_audio_list_remove(list, sbc_decoder_frame);
|
a2dp_audio_list_remove(list, sbc_decoder_frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = a2dp_cp_get_full_out_frame((void **)&out, &out_len);
|
ret = a2dp_cp_get_full_out_frame((void **)&out, &out_len);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
if (!get_in_cp_frame_cnt()){
|
if (!get_in_cp_frame_cnt()){
|
||||||
TRACE_A2DP_DECODER_I("[MCU][SBC] cp cache underflow list:%d in_cp:%d",
|
TRACE_A2DP_DECODER_I("[MCU][SBC] cp cache underflow list:%d in_cp:%d",a2dp_audio_list_length(list), get_in_cp_frame_cnt());
|
||||||
a2dp_audio_list_length(list), get_in_cp_frame_cnt());
|
|
||||||
return A2DP_DECODER_CACHE_UNDERFLOW_ERROR;
|
return A2DP_DECODER_CACHE_UNDERFLOW_ERROR;
|
||||||
}
|
}
|
||||||
if (!a2dp_audio_sysfreq_boost_running()){
|
if (!a2dp_audio_sysfreq_boost_running()){
|
||||||
|
@ -185,8 +177,7 @@ static int a2dp_cp_sbc_mcu_decode(uint8_t *buffer, uint32_t buffer_bytes) {
|
||||||
osDelay(8);
|
osDelay(8);
|
||||||
ret = a2dp_cp_get_full_out_frame((void **)&out, &out_len);
|
ret = a2dp_cp_get_full_out_frame((void **)&out, &out_len);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
TRACE_A2DP_DECODER_I("[MCU][SBC] cp cache underflow list:%d in_cp:%d",
|
TRACE_A2DP_DECODER_I("[MCU][SBC] cp cache underflow list:%d in_cp:%d",a2dp_audio_list_length(list), get_in_cp_frame_cnt());
|
||||||
a2dp_audio_list_length(list), get_in_cp_frame_cnt());
|
|
||||||
a2dp_cp_sbc_after_cache_underflow();
|
a2dp_cp_sbc_after_cache_underflow();
|
||||||
return A2DP_DECODER_CACHE_UNDERFLOW_ERROR;
|
return A2DP_DECODER_CACHE_UNDERFLOW_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -199,61 +190,56 @@ static int a2dp_cp_sbc_mcu_decode(uint8_t *buffer, uint32_t buffer_bytes) {
|
||||||
return A2DP_DECODER_NO_ERROR;
|
return A2DP_DECODER_NO_ERROR;
|
||||||
}
|
}
|
||||||
if(out_len != out_frame_len){
|
if(out_len != out_frame_len){
|
||||||
TRACE_A2DP_DECODER_I("[MCU][SBC] Bad out len %u (should be %u)", out_len,
|
TRACE_A2DP_DECODER_I("[MCU][SBC] Bad out len %u (should be %u)", out_len, out_frame_len);
|
||||||
out_frame_len);
|
|
||||||
set_cp_reset_flag(true);
|
set_cp_reset_flag(true);
|
||||||
return A2DP_DECODER_DECODE_ERROR;
|
return A2DP_DECODER_DECODE_ERROR;
|
||||||
}
|
}
|
||||||
p_out_info = (struct A2DP_CP_SBC_OUT_FRM_INFO_T *)out;
|
p_out_info = (struct A2DP_CP_SBC_OUT_FRM_INFO_T *)out;
|
||||||
if (p_out_info->pcm_len) {
|
if (p_out_info->pcm_len) {
|
||||||
a2dp_audio_sbc_lastframe_info.sequenceNumber =
|
a2dp_audio_sbc_lastframe_info.sequenceNumber = p_out_info->in_info.sequenceNumber;
|
||||||
p_out_info->in_info.sequenceNumber;
|
|
||||||
a2dp_audio_sbc_lastframe_info.timestamp = p_out_info->in_info.timestamp;
|
a2dp_audio_sbc_lastframe_info.timestamp = p_out_info->in_info.timestamp;
|
||||||
a2dp_audio_sbc_lastframe_info.curSubSequenceNumber =
|
a2dp_audio_sbc_lastframe_info.curSubSequenceNumber = p_out_info->in_info.curSubSequenceNumber;
|
||||||
p_out_info->in_info.curSubSequenceNumber;
|
a2dp_audio_sbc_lastframe_info.totalSubSequenceNumber = p_out_info->in_info.totalSubSequenceNumber;
|
||||||
a2dp_audio_sbc_lastframe_info.totalSubSequenceNumber =
|
|
||||||
p_out_info->in_info.totalSubSequenceNumber;
|
|
||||||
a2dp_audio_sbc_lastframe_info.frame_samples = p_out_info->frame_samples;
|
a2dp_audio_sbc_lastframe_info.frame_samples = p_out_info->frame_samples;
|
||||||
a2dp_audio_sbc_lastframe_info.decoded_frames += p_out_info->decoded_frames;
|
a2dp_audio_sbc_lastframe_info.decoded_frames += p_out_info->decoded_frames;
|
||||||
a2dp_audio_sbc_lastframe_info.undecode_frames =
|
a2dp_audio_sbc_lastframe_info.undecode_frames =
|
||||||
a2dp_audio_list_length(list) +
|
a2dp_audio_list_length(list) + a2dp_cp_get_in_frame_cnt_by_index(p_out_info->frame_idx) - 1;
|
||||||
a2dp_cp_get_in_frame_cnt_by_index(p_out_info->frame_idx) - 1;
|
a2dp_audio_sbc_lastframe_info.check_sum= check_sum?check_sum:a2dp_audio_sbc_lastframe_info.check_sum;
|
||||||
a2dp_audio_sbc_lastframe_info.check_sum =
|
a2dp_audio_decoder_internal_lastframe_info_set(&a2dp_audio_sbc_lastframe_info);
|
||||||
check_sum ? check_sum : a2dp_audio_sbc_lastframe_info.check_sum;
|
|
||||||
a2dp_audio_decoder_internal_lastframe_info_set(
|
|
||||||
&a2dp_audio_sbc_lastframe_info);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p_out_info->pcm_len == buffer_bytes) {
|
if (p_out_info->pcm_len == buffer_bytes) {
|
||||||
memcpy(buffer, p_out_info + 1, p_out_info->pcm_len);
|
memcpy(buffer, p_out_info + 1, p_out_info->pcm_len);
|
||||||
dec_ret = A2DP_DECODER_NO_ERROR;
|
dec_ret = A2DP_DECODER_NO_ERROR;
|
||||||
} else {
|
} else {
|
||||||
TRACE_A2DP_DECODER_I("[MCU][SBC] line:%d cp decoder error !!!!!!",
|
TRACE_A2DP_DECODER_I("[MCU][SBC] line:%d cp decoder error !!!!!!", __LINE__);
|
||||||
__LINE__);
|
|
||||||
set_cp_reset_flag(true);
|
set_cp_reset_flag(true);
|
||||||
return A2DP_DECODER_DECODE_ERROR;
|
return A2DP_DECODER_DECODE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = a2dp_cp_consume_full_out_frame();
|
ret = a2dp_cp_consume_full_out_frame();
|
||||||
if(ret){
|
if(ret){
|
||||||
TRACE_A2DP_DECODER_I("[MCU][SBC] cp_consume_full_out_frame failed: ret=%d",
|
TRACE_A2DP_DECODER_I("[MCU][SBC] cp_consume_full_out_frame failed: ret=%d", ret);
|
||||||
ret);
|
|
||||||
set_cp_reset_flag(true);
|
set_cp_reset_flag(true);
|
||||||
return A2DP_DECODER_DECODE_ERROR;
|
return A2DP_DECODER_DECODE_ERROR;
|
||||||
}
|
}
|
||||||
return dec_ret;
|
return dec_ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef __CP_EXCEPTION_TEST__
|
#ifdef __CP_EXCEPTION_TEST__
|
||||||
static bool _cp_assert = false;
|
static bool _cp_assert = false;
|
||||||
int cp_assert_sbc(void) {
|
int cp_assert_sbc(void)
|
||||||
|
{
|
||||||
_cp_assert = true;
|
_cp_assert = true;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
TEXT_SBC_LOC
|
TEXT_SBC_LOC
|
||||||
int a2dp_cp_sbc_cp_decode(void) {
|
int a2dp_cp_sbc_cp_decode(void)
|
||||||
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
enum CP_EMPTY_OUT_FRM_T out_frm_st;
|
enum CP_EMPTY_OUT_FRM_T out_frm_st;
|
||||||
uint8_t *out = NULL;
|
uint8_t *out = NULL;
|
||||||
|
@ -276,6 +262,7 @@ int a2dp_cp_sbc_cp_decode(void) {
|
||||||
sbc_codec_init();
|
sbc_codec_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef __CP_EXCEPTION_TEST__
|
#ifdef __CP_EXCEPTION_TEST__
|
||||||
if (_cp_assert){
|
if (_cp_assert){
|
||||||
_cp_assert = false;
|
_cp_assert = false;
|
||||||
|
@ -288,23 +275,18 @@ int a2dp_cp_sbc_cp_decode(void) {
|
||||||
pcm_data = a2dp_audio_sbc_decoder.pcm_data;
|
pcm_data = a2dp_audio_sbc_decoder.pcm_data;
|
||||||
|
|
||||||
out_frm_st = a2dp_cp_get_emtpy_out_frame((void **)&out, &out_len);
|
out_frm_st = a2dp_cp_get_emtpy_out_frame((void **)&out, &out_len);
|
||||||
if (out_frm_st != CP_EMPTY_OUT_FRM_OK &&
|
if (out_frm_st != CP_EMPTY_OUT_FRM_OK && out_frm_st != CP_EMPTY_OUT_FRM_WORKING) {
|
||||||
out_frm_st != CP_EMPTY_OUT_FRM_WORKING) {
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT_A2DP_DECODER(out_len > sizeof(*p_out_info),
|
ASSERT_A2DP_DECODER(out_len > sizeof(*p_out_info), "[CP][SBC] Bad out_len %u (should > %u)", out_len, sizeof(*p_out_info));
|
||||||
"[CP][SBC] Bad out_len %u (should > %u)", out_len,
|
|
||||||
sizeof(*p_out_info));
|
|
||||||
|
|
||||||
p_out_info = (struct A2DP_CP_SBC_OUT_FRM_INFO_T *)out;
|
p_out_info = (struct A2DP_CP_SBC_OUT_FRM_INFO_T *)out;
|
||||||
if (out_frm_st == CP_EMPTY_OUT_FRM_OK) {
|
if (out_frm_st == CP_EMPTY_OUT_FRM_OK) {
|
||||||
p_out_info->pcm_len = 0;
|
p_out_info->pcm_len = 0;
|
||||||
p_out_info->decoded_frames = 0;
|
p_out_info->decoded_frames = 0;
|
||||||
}
|
}
|
||||||
ASSERT_A2DP_DECODER(out_len > sizeof(*p_out_info) + p_out_info->pcm_len,
|
ASSERT_A2DP_DECODER(out_len > sizeof(*p_out_info) + p_out_info->pcm_len, "[CP][SBC] Bad out_len %u (should > %u + %u)", out_len, sizeof(*p_out_info), p_out_info->pcm_len);
|
||||||
"[CP][SBC] Bad out_len %u (should > %u + %u)", out_len,
|
|
||||||
sizeof(*p_out_info), p_out_info->pcm_len);
|
|
||||||
|
|
||||||
dec_start = (uint8_t *)(p_out_info + 1) + p_out_info->pcm_len;
|
dec_start = (uint8_t *)(p_out_info + 1) + p_out_info->pcm_len;
|
||||||
dec_len = out_len - (dec_start - (uint8_t *)out);
|
dec_len = out_len - (dec_start - (uint8_t *)out);
|
||||||
|
@ -319,25 +301,25 @@ int a2dp_cp_sbc_cp_decode(void) {
|
||||||
p_out_info->pcm_len += pcm_data->dataLen;
|
p_out_info->pcm_len += pcm_data->dataLen;
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
ASSERT_A2DP_DECODER(in_len > sizeof(*p_in_info),
|
ASSERT_A2DP_DECODER(in_len > sizeof(*p_in_info), "%s: Bad in_len %u (should > %u)", __func__, in_len, sizeof(*p_in_info));
|
||||||
"%s: Bad in_len %u (should > %u)", __func__, in_len,
|
|
||||||
sizeof(*p_in_info));
|
|
||||||
|
|
||||||
p_in_info = (struct A2DP_CP_SBC_IN_FRM_INFO_T *)in_buf;
|
p_in_info = (struct A2DP_CP_SBC_IN_FRM_INFO_T *)in_buf;
|
||||||
in_buf += sizeof(*p_in_info);
|
in_buf += sizeof(*p_in_info);
|
||||||
in_len -= sizeof(*p_in_info);
|
in_len -= sizeof(*p_in_info);
|
||||||
|
|
||||||
decoder_err =
|
decoder_err = btif_sbc_decode_frames(sbc_decoder, in_buf, in_len,
|
||||||
btif_sbc_decode_frames(sbc_decoder, in_buf, in_len, &bytes_parsed,
|
&bytes_parsed,
|
||||||
pcm_data, dec_len, sbc_subbands_gain);
|
pcm_data,
|
||||||
switch (decoder_err) {
|
dec_len,
|
||||||
|
sbc_subbands_gain);
|
||||||
|
switch (decoder_err)
|
||||||
|
{
|
||||||
case BT_STS_SUCCESS:
|
case BT_STS_SUCCESS:
|
||||||
case BT_STS_CONTINUE:
|
case BT_STS_CONTINUE:
|
||||||
break;
|
break;
|
||||||
case BT_STS_NO_RESOURCES:
|
case BT_STS_NO_RESOURCES:
|
||||||
error = 1;
|
error = 1;
|
||||||
ASSERT_A2DP_DECODER(0, "sbc_decode BT_STS_NO_RESOURCES pcm has no more "
|
ASSERT_A2DP_DECODER(0, "sbc_decode BT_STS_NO_RESOURCES pcm has no more buffer, i think can't reach here");
|
||||||
"buffer, i think can't reach here");
|
|
||||||
break;
|
break;
|
||||||
case BT_STS_FAILED:
|
case BT_STS_FAILED:
|
||||||
default:
|
default:
|
||||||
|
@ -352,34 +334,29 @@ int a2dp_cp_sbc_cp_decode(void) {
|
||||||
p_out_info->frame_idx = a2dp_cp_get_in_frame_index();
|
p_out_info->frame_idx = a2dp_cp_get_in_frame_index();
|
||||||
|
|
||||||
ret = a2dp_cp_consume_in_frame();
|
ret = a2dp_cp_consume_in_frame();
|
||||||
ASSERT_A2DP_DECODER(ret == 0,
|
ASSERT_A2DP_DECODER(ret == 0, "%s: a2dp_cp_consume_in_frame() failed: ret=%d", __func__, ret);
|
||||||
"%s: a2dp_cp_consume_in_frame() failed: ret=%d",
|
|
||||||
__func__, ret);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
p_out_info->pcm_len += pcm_data->dataLen;
|
p_out_info->pcm_len += pcm_data->dataLen;
|
||||||
|
|
||||||
if (error || out_len <= sizeof(*p_out_info) + p_out_info->pcm_len) {
|
if (error || out_len <= sizeof(*p_out_info) + p_out_info->pcm_len) {
|
||||||
ret = a2dp_cp_consume_emtpy_out_frame();
|
ret = a2dp_cp_consume_emtpy_out_frame();
|
||||||
ASSERT_A2DP_DECODER(ret == 0,
|
ASSERT_A2DP_DECODER(ret == 0, "%s: a2dp_cp_consume_emtpy_out_frame() failed: ret=%d", __func__, ret);
|
||||||
"%s: a2dp_cp_consume_emtpy_out_frame() failed: ret=%d",
|
|
||||||
__func__, ret);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int a2dp_audio_sbc_list_checker(void) {
|
static int a2dp_audio_sbc_list_checker(void)
|
||||||
|
{
|
||||||
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
||||||
list_node_t *node = NULL;
|
list_node_t *node = NULL;
|
||||||
a2dp_audio_sbc_decoder_frame_t *sbc_decoder_frame = NULL;
|
a2dp_audio_sbc_decoder_frame_t *sbc_decoder_frame = NULL;
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
sbc_decoder_frame =
|
sbc_decoder_frame = (a2dp_audio_sbc_decoder_frame_t *)a2dp_audio_sbc_subframe_malloc(SBC_LIST_SAMPLES);
|
||||||
(a2dp_audio_sbc_decoder_frame_t *)a2dp_audio_sbc_subframe_malloc(
|
|
||||||
SBC_LIST_SAMPLES);
|
|
||||||
if (sbc_decoder_frame){
|
if (sbc_decoder_frame){
|
||||||
a2dp_audio_list_append(list, sbc_decoder_frame);
|
a2dp_audio_list_append(list, sbc_decoder_frame);
|
||||||
}
|
}
|
||||||
|
@ -389,49 +366,39 @@ static int a2dp_audio_sbc_list_checker(void) {
|
||||||
do {
|
do {
|
||||||
node = a2dp_audio_list_begin(list);
|
node = a2dp_audio_list_begin(list);
|
||||||
if (node){
|
if (node){
|
||||||
sbc_decoder_frame =
|
sbc_decoder_frame = (a2dp_audio_sbc_decoder_frame_t *)a2dp_audio_list_node(node);
|
||||||
(a2dp_audio_sbc_decoder_frame_t *)a2dp_audio_list_node(node);
|
|
||||||
a2dp_audio_list_remove(list, sbc_decoder_frame);
|
a2dp_audio_list_remove(list, sbc_decoder_frame);
|
||||||
}
|
}
|
||||||
}while(node);
|
}while(node);
|
||||||
|
|
||||||
TRACE_A2DP_DECODER_I("[SBC][INIT] cnt:%d list:%d", cnt,
|
TRACE_A2DP_DECODER_I("[SBC][INIT] cnt:%d list:%d", cnt, a2dp_audio_list_length(list));
|
||||||
a2dp_audio_list_length(list));
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2dp_audio_sbc_init(A2DP_AUDIO_OUTPUT_CONFIG_T *config, void *context) {
|
int a2dp_audio_sbc_init(A2DP_AUDIO_OUTPUT_CONFIG_T *config, void *context)
|
||||||
|
{
|
||||||
TRACE_A2DP_DECODER_I("[SBC][INIT]");
|
TRACE_A2DP_DECODER_I("[SBC][INIT]");
|
||||||
|
|
||||||
a2dp_audio_context_p = (A2DP_AUDIO_CONTEXT_T *)context;
|
a2dp_audio_context_p = (A2DP_AUDIO_CONTEXT_T *)context;
|
||||||
|
|
||||||
a2dp_audio_sbc_header_parser_init();
|
a2dp_audio_sbc_header_parser_init();
|
||||||
memset(&a2dp_audio_sbc_lastframe_info, 0,
|
memset(&a2dp_audio_sbc_lastframe_info, 0, sizeof(A2DP_AUDIO_DECODER_LASTFRAME_INFO_T));
|
||||||
sizeof(A2DP_AUDIO_DECODER_LASTFRAME_INFO_T));
|
|
||||||
a2dp_audio_sbc_lastframe_info.stream_info = *config;
|
a2dp_audio_sbc_lastframe_info.stream_info = *config;
|
||||||
a2dp_audio_sbc_lastframe_info.frame_samples= SBC_LIST_SAMPLES;
|
a2dp_audio_sbc_lastframe_info.frame_samples= SBC_LIST_SAMPLES;
|
||||||
a2dp_audio_sbc_lastframe_info.list_samples = SBC_LIST_SAMPLES;
|
a2dp_audio_sbc_lastframe_info.list_samples = SBC_LIST_SAMPLES;
|
||||||
a2dp_audio_decoder_internal_lastframe_info_set(
|
a2dp_audio_decoder_internal_lastframe_info_set(&a2dp_audio_sbc_lastframe_info);
|
||||||
&a2dp_audio_sbc_lastframe_info);
|
|
||||||
|
|
||||||
ASSERT_A2DP_DECODER(a2dp_audio_context_p->dest_packet_mut < SBC_MTU_LIMITER,
|
ASSERT_A2DP_DECODER(a2dp_audio_context_p->dest_packet_mut < SBC_MTU_LIMITER, "%s MTU OVERFLOW:%u/%u", __func__, a2dp_audio_context_p->dest_packet_mut, SBC_MTU_LIMITER);
|
||||||
"%s MTU OVERFLOW:%u/%u", __func__,
|
|
||||||
a2dp_audio_context_p->dest_packet_mut, SBC_MTU_LIMITER);
|
|
||||||
|
|
||||||
a2dp_audio_sbc_decoder.sbc_decoder =
|
a2dp_audio_sbc_decoder.sbc_decoder = (btif_sbc_decoder_t *)a2dp_audio_heap_malloc(sizeof(btif_sbc_decoder_t));
|
||||||
(btif_sbc_decoder_t *)a2dp_audio_heap_malloc(sizeof(btif_sbc_decoder_t));
|
a2dp_audio_sbc_decoder.pcm_data = (btif_sbc_pcm_data_t *)a2dp_audio_heap_malloc(sizeof(btif_sbc_pcm_data_t));
|
||||||
a2dp_audio_sbc_decoder.pcm_data =
|
a2dp_audio_sbc_decoder_preparse = (btif_sbc_decoder_t *)a2dp_audio_heap_malloc(sizeof(btif_sbc_decoder_t));
|
||||||
(btif_sbc_pcm_data_t *)a2dp_audio_heap_malloc(
|
|
||||||
sizeof(btif_sbc_pcm_data_t));
|
|
||||||
a2dp_audio_sbc_decoder_preparse =
|
|
||||||
(btif_sbc_decoder_t *)a2dp_audio_heap_malloc(sizeof(btif_sbc_decoder_t));
|
|
||||||
#ifdef A2DP_CP_ACCEL
|
#ifdef A2DP_CP_ACCEL
|
||||||
int ret;
|
int ret;
|
||||||
cp_codec_reset = true;
|
cp_codec_reset = true;
|
||||||
ret = a2dp_cp_init(a2dp_cp_sbc_cp_decode, CP_PROC_DELAY_2_FRAMES);
|
ret = a2dp_cp_init(a2dp_cp_sbc_cp_decode, CP_PROC_DELAY_2_FRAMES);
|
||||||
ASSERT_A2DP_DECODER(ret == 0, "%s: a2dp_cp_init() failed: ret=%d", __func__,
|
ASSERT_A2DP_DECODER(ret == 0, "%s: a2dp_cp_init() failed: ret=%d", __func__, ret);
|
||||||
ret);
|
|
||||||
#else
|
#else
|
||||||
sbc_codec_init();
|
sbc_codec_init();
|
||||||
#endif
|
#endif
|
||||||
|
@ -440,7 +407,8 @@ int a2dp_audio_sbc_init(A2DP_AUDIO_OUTPUT_CONFIG_T *config, void *context) {
|
||||||
return A2DP_DECODER_NO_ERROR;
|
return A2DP_DECODER_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2dp_audio_sbc_deinit(void) {
|
int a2dp_audio_sbc_deinit(void)
|
||||||
|
{
|
||||||
#ifdef A2DP_CP_ACCEL
|
#ifdef A2DP_CP_ACCEL
|
||||||
a2dp_cp_deinit();
|
a2dp_cp_deinit();
|
||||||
#endif
|
#endif
|
||||||
|
@ -453,7 +421,8 @@ int a2dp_audio_sbc_deinit(void) {
|
||||||
return A2DP_DECODER_NO_ERROR;
|
return A2DP_DECODER_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2dp_audio_sbc_mcu_decode_frame(uint8_t *buffer, uint32_t buffer_bytes) {
|
int a2dp_audio_sbc_mcu_decode_frame(uint8_t *buffer, uint32_t buffer_bytes)
|
||||||
|
{
|
||||||
bt_status_t ret = BT_STS_SUCCESS;
|
bt_status_t ret = BT_STS_SUCCESS;
|
||||||
uint16_t bytes_parsed = 0;
|
uint16_t bytes_parsed = 0;
|
||||||
float sbc_subbands_gain[8]={1,1,1,1,1,1,1,1};
|
float sbc_subbands_gain[8]={1,1,1,1,1,1,1,1};
|
||||||
|
@ -467,6 +436,7 @@ int a2dp_audio_sbc_mcu_decode_frame(uint8_t *buffer, uint32_t buffer_bytes) {
|
||||||
pcm_data = a2dp_audio_sbc_decoder.pcm_data;
|
pcm_data = a2dp_audio_sbc_decoder.pcm_data;
|
||||||
frame_pcmbyte = sbc_decoder->maxPcmLen;
|
frame_pcmbyte = sbc_decoder->maxPcmLen;
|
||||||
|
|
||||||
|
|
||||||
a2dp_audio_sbc_decoder_frame_t *sbc_decoder_frame = NULL;
|
a2dp_audio_sbc_decoder_frame_t *sbc_decoder_frame = NULL;
|
||||||
list_node_t *node = NULL;
|
list_node_t *node = NULL;
|
||||||
|
|
||||||
|
@ -477,57 +447,48 @@ int a2dp_audio_sbc_mcu_decode_frame(uint8_t *buffer, uint32_t buffer_bytes) {
|
||||||
|
|
||||||
TRACE_A2DP_DECODER_D("[MCU][SBC] size:%d", a2dp_audio_list_length(list));
|
TRACE_A2DP_DECODER_D("[MCU][SBC] size:%d", a2dp_audio_list_length(list));
|
||||||
|
|
||||||
for (pcm_output_byte = 0; pcm_output_byte < buffer_bytes;
|
for (pcm_output_byte = 0; pcm_output_byte<buffer_bytes; pcm_output_byte += frame_pcmbyte){
|
||||||
pcm_output_byte += frame_pcmbyte) {
|
|
||||||
node = a2dp_audio_list_begin(list);
|
node = a2dp_audio_list_begin(list);
|
||||||
|
|
||||||
if (node){
|
if (node){
|
||||||
uint32_t lock;
|
uint32_t lock;
|
||||||
|
|
||||||
sbc_decoder_frame =
|
sbc_decoder_frame = (a2dp_audio_sbc_decoder_frame_t *)a2dp_audio_list_node(node);
|
||||||
(a2dp_audio_sbc_decoder_frame_t *)a2dp_audio_list_node(node);
|
|
||||||
|
|
||||||
lock = int_lock();
|
lock = int_lock();
|
||||||
ret = btif_sbc_decode_frames(sbc_decoder, sbc_decoder_frame->sbc_buffer,
|
ret = btif_sbc_decode_frames(sbc_decoder, sbc_decoder_frame->sbc_buffer, sbc_decoder_frame->sbc_buffer_len,
|
||||||
sbc_decoder_frame->sbc_buffer_len,
|
&bytes_parsed,
|
||||||
&bytes_parsed, pcm_data, buffer_bytes,
|
pcm_data,
|
||||||
|
buffer_bytes,
|
||||||
sbc_subbands_gain);
|
sbc_subbands_gain);
|
||||||
int_unlock(lock);
|
int_unlock(lock);
|
||||||
TRACE_A2DP_DECODER_D("[MCU][SBC] seq:%d/%d/%d len:%d ret:%d used:%d",
|
TRACE_A2DP_DECODER_D("[MCU][SBC] seq:%d/%d/%d len:%d ret:%d used:%d",
|
||||||
sbc_decoder_frame->curSubSequenceNumber,
|
sbc_decoder_frame->curSubSequenceNumber,
|
||||||
sbc_decoder_frame->totalSubSequenceNumber,
|
sbc_decoder_frame->totalSubSequenceNumber,
|
||||||
sbc_decoder_frame->sequenceNumber,
|
sbc_decoder_frame->sequenceNumber,
|
||||||
sbc_decoder_frame->sbc_buffer_len, ret,
|
sbc_decoder_frame->sbc_buffer_len,
|
||||||
|
ret,
|
||||||
bytes_parsed);
|
bytes_parsed);
|
||||||
|
|
||||||
a2dp_audio_sbc_lastframe_info.sequenceNumber =
|
a2dp_audio_sbc_lastframe_info.sequenceNumber = sbc_decoder_frame->sequenceNumber;
|
||||||
sbc_decoder_frame->sequenceNumber;
|
|
||||||
a2dp_audio_sbc_lastframe_info.timestamp = sbc_decoder_frame->timestamp;
|
a2dp_audio_sbc_lastframe_info.timestamp = sbc_decoder_frame->timestamp;
|
||||||
a2dp_audio_sbc_lastframe_info.curSubSequenceNumber =
|
a2dp_audio_sbc_lastframe_info.curSubSequenceNumber = sbc_decoder_frame->curSubSequenceNumber;
|
||||||
sbc_decoder_frame->curSubSequenceNumber;
|
a2dp_audio_sbc_lastframe_info.totalSubSequenceNumber = sbc_decoder_frame->totalSubSequenceNumber;
|
||||||
a2dp_audio_sbc_lastframe_info.totalSubSequenceNumber =
|
|
||||||
sbc_decoder_frame->totalSubSequenceNumber;
|
|
||||||
a2dp_audio_sbc_lastframe_info.frame_samples = sbc_decoder->maxPcmLen/4;
|
a2dp_audio_sbc_lastframe_info.frame_samples = sbc_decoder->maxPcmLen/4;
|
||||||
a2dp_audio_sbc_lastframe_info.decoded_frames++;
|
a2dp_audio_sbc_lastframe_info.decoded_frames++;
|
||||||
a2dp_audio_sbc_lastframe_info.undecode_frames =
|
a2dp_audio_sbc_lastframe_info.undecode_frames = a2dp_audio_list_length(list)-1;
|
||||||
a2dp_audio_list_length(list) - 1;
|
a2dp_audio_sbc_lastframe_info.check_sum = a2dp_audio_decoder_internal_check_sum_generate(sbc_decoder_frame->sbc_buffer, sbc_decoder_frame->sbc_buffer_len);
|
||||||
a2dp_audio_sbc_lastframe_info.check_sum =
|
a2dp_audio_decoder_internal_lastframe_info_set(&a2dp_audio_sbc_lastframe_info);
|
||||||
a2dp_audio_decoder_internal_check_sum_generate(
|
|
||||||
sbc_decoder_frame->sbc_buffer, sbc_decoder_frame->sbc_buffer_len);
|
|
||||||
a2dp_audio_decoder_internal_lastframe_info_set(
|
|
||||||
&a2dp_audio_sbc_lastframe_info);
|
|
||||||
a2dp_audio_list_remove(list, sbc_decoder_frame);
|
a2dp_audio_list_remove(list, sbc_decoder_frame);
|
||||||
switch (ret) {
|
switch (ret)
|
||||||
|
{
|
||||||
case BT_STS_SUCCESS:
|
case BT_STS_SUCCESS:
|
||||||
if (pcm_data->dataLen != buffer_bytes){
|
if (pcm_data->dataLen != buffer_bytes){
|
||||||
TRACE_A2DP_DECODER_W("[MCU][SBC] WARNING pcm buff mismatch %d/%d",
|
TRACE_A2DP_DECODER_W("[MCU][SBC] WARNING pcm buff mismatch %d/%d", pcm_data->dataLen, buffer_bytes);
|
||||||
pcm_data->dataLen, buffer_bytes);
|
|
||||||
}
|
}
|
||||||
if (pcm_data->dataLen == buffer_bytes){
|
if (pcm_data->dataLen == buffer_bytes){
|
||||||
if (pcm_output_byte+frame_pcmbyte != buffer_bytes){
|
if (pcm_output_byte+frame_pcmbyte != buffer_bytes){
|
||||||
TRACE_A2DP_DECODER_W(
|
TRACE_A2DP_DECODER_W("[MCU][SBC]WARNING loop not break %d/%d frame_pcm:%d", pcm_output_byte, buffer_bytes, frame_pcmbyte);
|
||||||
"[MCU][SBC]WARNING loop not break %d/%d frame_pcm:%d",
|
|
||||||
pcm_output_byte, buffer_bytes, frame_pcmbyte);
|
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -536,8 +497,7 @@ int a2dp_audio_sbc_mcu_decode_frame(uint8_t *buffer, uint32_t buffer_bytes) {
|
||||||
continue;
|
continue;
|
||||||
break;
|
break;
|
||||||
case BT_STS_NO_RESOURCES:
|
case BT_STS_NO_RESOURCES:
|
||||||
ASSERT_A2DP_DECODER(0, "sbc_decode BT_STS_NO_RESOURCES pcm has no more "
|
ASSERT_A2DP_DECODER(0, "sbc_decode BT_STS_NO_RESOURCES pcm has no more buffer, i think can't reach here");
|
||||||
"buffer, i think can't reach here");
|
|
||||||
break;
|
break;
|
||||||
case BT_STS_FAILED:
|
case BT_STS_FAILED:
|
||||||
default:
|
default:
|
||||||
|
@ -550,21 +510,21 @@ int a2dp_audio_sbc_mcu_decode_frame(uint8_t *buffer, uint32_t buffer_bytes) {
|
||||||
cache_underflow = true;
|
cache_underflow = true;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
exit:
|
exit:
|
||||||
if (cache_underflow){
|
if (cache_underflow){
|
||||||
TRACE_A2DP_DECODER_W(
|
TRACE_A2DP_DECODER_W("[MCU][SBC] A2DP PACKET CACHE UNDERFLOW need add some process");
|
||||||
"[MCU][SBC] A2DP PACKET CACHE UNDERFLOW need add some process");
|
|
||||||
a2dp_audio_sbc_lastframe_info.undecode_frames = 0;
|
a2dp_audio_sbc_lastframe_info.undecode_frames = 0;
|
||||||
a2dp_audio_sbc_lastframe_info.check_sum = 0;
|
a2dp_audio_sbc_lastframe_info.check_sum = 0;
|
||||||
a2dp_audio_decoder_internal_lastframe_info_set(
|
a2dp_audio_decoder_internal_lastframe_info_set(&a2dp_audio_sbc_lastframe_info);
|
||||||
&a2dp_audio_sbc_lastframe_info);
|
|
||||||
ret = A2DP_DECODER_CACHE_UNDERFLOW_ERROR;
|
ret = A2DP_DECODER_CACHE_UNDERFLOW_ERROR;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2dp_audio_sbc_decode_frame(uint8_t *buffer, uint32_t buffer_bytes) {
|
int a2dp_audio_sbc_decode_frame(uint8_t *buffer, uint32_t buffer_bytes)
|
||||||
|
{
|
||||||
int nRet = 0;
|
int nRet = 0;
|
||||||
if (sbc_chnl_mode_mono){
|
if (sbc_chnl_mode_mono){
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
@ -595,8 +555,8 @@ int a2dp_audio_sbc_decode_frame(uint8_t *buffer, uint32_t buffer_bytes) {
|
||||||
return nRet;
|
return nRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2dp_audio_sbc_preparse_packet(btif_media_header_t *header, uint8_t *buffer,
|
int a2dp_audio_sbc_preparse_packet(btif_media_header_t * header, uint8_t *buffer, uint32_t buffer_bytes)
|
||||||
uint32_t buffer_bytes) {
|
{
|
||||||
uint16_t bytes_parsed = 0;
|
uint16_t bytes_parsed = 0;
|
||||||
uint32_t frame_num = 0;
|
uint32_t frame_num = 0;
|
||||||
uint8_t *parser_p = buffer;
|
uint8_t *parser_p = buffer;
|
||||||
|
@ -605,63 +565,57 @@ int a2dp_audio_sbc_preparse_packet(btif_media_header_t *header, uint8_t *buffer,
|
||||||
parser_p++;
|
parser_p++;
|
||||||
buffer_bytes--;
|
buffer_bytes--;
|
||||||
|
|
||||||
// TODO: Remove the following sbc init and decode codes. They might conflict
|
// TODO: Remove the following sbc init and decode codes. They might conflict with the calls
|
||||||
// with the calls
|
// during CP process. CP process is triggered by audioflinger PCM callback.
|
||||||
// during CP process. CP process is triggered by audioflinger PCM
|
|
||||||
// callback.
|
|
||||||
|
|
||||||
if (*parser_p != 0x9c){
|
if (*parser_p != 0x9c){
|
||||||
TRACE_A2DP_DECODER_I("[SBC][PRE] ERROR SBC FRAME !!! frame_num:%d",
|
TRACE_A2DP_DECODER_I("[SBC][PRE] ERROR SBC FRAME !!! frame_num:%d", frame_num);
|
||||||
frame_num);
|
|
||||||
DUMP8("%02x ", parser_p, 12);
|
DUMP8("%02x ", parser_p, 12);
|
||||||
}else{
|
}else{
|
||||||
btif_sbc_decode_frames_parser(a2dp_audio_sbc_decoder_preparse, parser_p,
|
btif_sbc_decode_frames_parser(a2dp_audio_sbc_decoder_preparse,parser_p, buffer_bytes, &bytes_parsed);
|
||||||
buffer_bytes, &bytes_parsed);
|
TRACE_A2DP_DECODER_I("[SBC][PRE] seq:%d tStmp:%08x smpR:%d ch:%d len:%d",
|
||||||
TRACE_A2DP_DECODER_I(
|
header->sequenceNumber,
|
||||||
"[SBC][PRE] seq:%d tStmp:%08x smpR:%d ch:%d len:%d",
|
header->timestamp,
|
||||||
header->sequenceNumber, header->timestamp,
|
|
||||||
a2dp_audio_sbc_decoder_preparse->streamInfo.sampleFreq,
|
a2dp_audio_sbc_decoder_preparse->streamInfo.sampleFreq,
|
||||||
a2dp_audio_sbc_decoder_preparse->streamInfo.channelMode,
|
a2dp_audio_sbc_decoder_preparse->streamInfo.channelMode,
|
||||||
a2dp_audio_sbc_decoder_preparse->maxPcmLen);
|
a2dp_audio_sbc_decoder_preparse->maxPcmLen);
|
||||||
TRACE_A2DP_DECODER_I("[SBC][PRE] frmN:%d par:%d/%d", frame_num,
|
TRACE_A2DP_DECODER_I("[SBC][PRE] frmN:%d par:%d/%d", frame_num, buffer_bytes, bytes_parsed);
|
||||||
buffer_bytes, bytes_parsed);
|
|
||||||
|
|
||||||
a2dp_audio_sbc_lastframe_info.sequenceNumber = header->sequenceNumber;
|
a2dp_audio_sbc_lastframe_info.sequenceNumber = header->sequenceNumber;
|
||||||
a2dp_audio_sbc_lastframe_info.timestamp = header->timestamp;
|
a2dp_audio_sbc_lastframe_info.timestamp = header->timestamp;
|
||||||
a2dp_audio_sbc_lastframe_info.curSubSequenceNumber = 0;
|
a2dp_audio_sbc_lastframe_info.curSubSequenceNumber = 0;
|
||||||
a2dp_audio_sbc_lastframe_info.totalSubSequenceNumber = frame_num;
|
a2dp_audio_sbc_lastframe_info.totalSubSequenceNumber = frame_num;
|
||||||
a2dp_audio_sbc_lastframe_info.frame_samples =
|
a2dp_audio_sbc_lastframe_info.frame_samples = a2dp_audio_sbc_decoder_preparse->maxPcmLen/4;
|
||||||
a2dp_audio_sbc_decoder_preparse->maxPcmLen / 4;
|
|
||||||
a2dp_audio_sbc_lastframe_info.list_samples = SBC_LIST_SAMPLES;
|
a2dp_audio_sbc_lastframe_info.list_samples = SBC_LIST_SAMPLES;
|
||||||
a2dp_audio_sbc_lastframe_info.decoded_frames = 0;
|
a2dp_audio_sbc_lastframe_info.decoded_frames = 0;
|
||||||
a2dp_audio_sbc_lastframe_info.undecode_frames = 0;
|
a2dp_audio_sbc_lastframe_info.undecode_frames = 0;
|
||||||
a2dp_audio_decoder_internal_lastframe_info_set(
|
a2dp_audio_decoder_internal_lastframe_info_set(&a2dp_audio_sbc_lastframe_info);
|
||||||
&a2dp_audio_sbc_lastframe_info);
|
|
||||||
}
|
}
|
||||||
if (a2dp_audio_sbc_decoder_preparse->streamInfo.channelMode ==
|
if (a2dp_audio_sbc_decoder_preparse->streamInfo.channelMode == BTIF_SBC_CHNL_MODE_MONO){
|
||||||
BTIF_SBC_CHNL_MODE_MONO) {
|
|
||||||
sbc_chnl_mode_mono = true;
|
sbc_chnl_mode_mono = true;
|
||||||
}
|
}
|
||||||
return A2DP_DECODER_NO_ERROR;
|
return A2DP_DECODER_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int a2dp_audio_sbc_header_parser_init(void) {
|
|
||||||
|
static int a2dp_audio_sbc_header_parser_init(void)
|
||||||
|
{
|
||||||
a2dp_audio_sbc_decoder_config.auto_synchronize_support = true;
|
a2dp_audio_sbc_decoder_config.auto_synchronize_support = true;
|
||||||
sbc_decoder_last_valid_frame_ready = false;
|
sbc_decoder_last_valid_frame_ready = false;
|
||||||
memset(&sbc_decoder_last_valid_frame, 0,
|
memset(&sbc_decoder_last_valid_frame, 0, sizeof(sbc_decoder_last_valid_frame));
|
||||||
sizeof(sbc_decoder_last_valid_frame));
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int a2dp_audio_sbc_packet_recover_save_last(
|
static int a2dp_audio_sbc_packet_recover_save_last(btif_media_header_t *sbc_decoder_frame)
|
||||||
btif_media_header_t *sbc_decoder_frame) {
|
{
|
||||||
sbc_decoder_last_valid_frame = *sbc_decoder_frame;
|
sbc_decoder_last_valid_frame = *sbc_decoder_frame;
|
||||||
sbc_decoder_last_valid_frame_ready = true;
|
sbc_decoder_last_valid_frame_ready = true;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int a2dp_audio_sbc_packet_recover_find_missing(
|
static int a2dp_audio_sbc_packet_recover_find_missing(btif_media_header_t *sbc_decoder_frame, uint8_t frame_cnt)
|
||||||
btif_media_header_t *sbc_decoder_frame, uint8_t frame_cnt) {
|
{
|
||||||
uint16_t diff_seq = 0;
|
uint16_t diff_seq = 0;
|
||||||
uint32_t diff_timestamp = 0;
|
uint32_t diff_timestamp = 0;
|
||||||
uint32_t diff = 0;
|
uint32_t diff = 0;
|
||||||
|
@ -671,12 +625,8 @@ static int a2dp_audio_sbc_packet_recover_find_missing(
|
||||||
return need_recover_pkt;
|
return need_recover_pkt;
|
||||||
}
|
}
|
||||||
|
|
||||||
diff_seq = a2dp_audio_get_passed(sbc_decoder_frame->sequenceNumber,
|
diff_seq = a2dp_audio_get_passed(sbc_decoder_frame->sequenceNumber, sbc_decoder_last_valid_frame.sequenceNumber, UINT16_MAX);
|
||||||
sbc_decoder_last_valid_frame.sequenceNumber,
|
diff_timestamp = a2dp_audio_get_passed(sbc_decoder_frame->timestamp, sbc_decoder_last_valid_frame.timestamp, UINT32_MAX);
|
||||||
UINT16_MAX);
|
|
||||||
diff_timestamp =
|
|
||||||
a2dp_audio_get_passed(sbc_decoder_frame->timestamp,
|
|
||||||
sbc_decoder_last_valid_frame.timestamp, UINT32_MAX);
|
|
||||||
if (diff_seq > 1){
|
if (diff_seq > 1){
|
||||||
diff = diff_timestamp/diff_seq;
|
diff = diff_timestamp/diff_seq;
|
||||||
if (diff%SBC_LIST_SAMPLES == 0){
|
if (diff%SBC_LIST_SAMPLES == 0){
|
||||||
|
@ -688,41 +638,31 @@ static int a2dp_audio_sbc_packet_recover_find_missing(
|
||||||
diff_seq--;
|
diff_seq--;
|
||||||
need_recover_pkt = diff_seq * frame_cnt;
|
need_recover_pkt = diff_seq * frame_cnt;
|
||||||
}
|
}
|
||||||
TRACE_A2DP_DECODER_W("[SBC][INPUT][PLC] seq:%d/%d stmp:%d/%d",
|
TRACE_A2DP_DECODER_W("[SBC][INPUT][PLC] seq:%d/%d stmp:%d/%d", sbc_decoder_frame->sequenceNumber, sbc_decoder_last_valid_frame.sequenceNumber,
|
||||||
sbc_decoder_frame->sequenceNumber,
|
sbc_decoder_frame->timestamp, sbc_decoder_last_valid_frame.timestamp);
|
||||||
sbc_decoder_last_valid_frame.sequenceNumber,
|
TRACE_A2DP_DECODER_W("[SBC][INPUT][PLC] diff_seq:%d diff_stmp:%d diff:%d missing:%d", diff_seq, diff_timestamp, diff, need_recover_pkt);
|
||||||
sbc_decoder_frame->timestamp,
|
|
||||||
sbc_decoder_last_valid_frame.timestamp);
|
|
||||||
TRACE_A2DP_DECODER_W(
|
|
||||||
"[SBC][INPUT][PLC] diff_seq:%d diff_stmp:%d diff:%d missing:%d",
|
|
||||||
diff_seq, diff_timestamp, diff, need_recover_pkt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return need_recover_pkt;
|
return need_recover_pkt;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int a2dp_audio_sbc_packet_recover_proc(
|
static int a2dp_audio_sbc_packet_recover_proc(btif_media_header_t *sbc_decoder_frame, a2dp_audio_sbc_decoder_frame_t *sbc_raw_frame, uint8_t frame_cnt)
|
||||||
btif_media_header_t *sbc_decoder_frame,
|
{
|
||||||
a2dp_audio_sbc_decoder_frame_t *sbc_raw_frame, uint8_t frame_cnt) {
|
|
||||||
int nRet = A2DP_DECODER_NO_ERROR;
|
int nRet = A2DP_DECODER_NO_ERROR;
|
||||||
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
||||||
int missing_pkt_cnt = 0;
|
int missing_pkt_cnt = 0;
|
||||||
missing_pkt_cnt =
|
missing_pkt_cnt = a2dp_audio_sbc_packet_recover_find_missing(sbc_decoder_frame, frame_cnt);
|
||||||
a2dp_audio_sbc_packet_recover_find_missing(sbc_decoder_frame, frame_cnt);
|
|
||||||
if (missing_pkt_cnt && sbc_raw_frame &&
|
if (missing_pkt_cnt && sbc_raw_frame &&
|
||||||
(a2dp_audio_list_length(list)+missing_pkt_cnt) < sbc_mtu_limiter){
|
(a2dp_audio_list_length(list)+missing_pkt_cnt) < sbc_mtu_limiter){
|
||||||
for (uint8_t i =0; i<missing_pkt_cnt; i++){
|
for (uint8_t i =0; i<missing_pkt_cnt; i++){
|
||||||
a2dp_audio_sbc_decoder_frame_t *frame_p =
|
a2dp_audio_sbc_decoder_frame_t *frame_p = (a2dp_audio_sbc_decoder_frame_t *)a2dp_audio_sbc_subframe_malloc(sbc_raw_frame->sbc_buffer_len);
|
||||||
(a2dp_audio_sbc_decoder_frame_t *)a2dp_audio_sbc_subframe_malloc(
|
|
||||||
sbc_raw_frame->sbc_buffer_len);
|
|
||||||
if (!frame_p){
|
if (!frame_p){
|
||||||
nRet = A2DP_DECODER_MEMORY_ERROR;
|
nRet = A2DP_DECODER_MEMORY_ERROR;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
frame_p->sequenceNumber = UINT16_MAX;
|
frame_p->sequenceNumber = UINT16_MAX;
|
||||||
frame_p->timestamp = UINT32_MAX;
|
frame_p->timestamp = UINT32_MAX;
|
||||||
memcpy(frame_p->sbc_buffer, sbc_raw_frame->sbc_buffer,
|
memcpy(frame_p->sbc_buffer, sbc_raw_frame->sbc_buffer, sbc_raw_frame->sbc_buffer_len);
|
||||||
sbc_raw_frame->sbc_buffer_len);
|
|
||||||
frame_p->sbc_buffer_len = sbc_raw_frame->sbc_buffer_len;
|
frame_p->sbc_buffer_len = sbc_raw_frame->sbc_buffer_len;
|
||||||
a2dp_audio_list_append(list, frame_p);
|
a2dp_audio_list_append(list, frame_p);
|
||||||
}
|
}
|
||||||
|
@ -732,8 +672,8 @@ exit:
|
||||||
}
|
}
|
||||||
|
|
||||||
#define FRAME_LIST_MAX (20)
|
#define FRAME_LIST_MAX (20)
|
||||||
int a2dp_audio_sbc_store_packet(btif_media_header_t *header, uint8_t *buffer,
|
int a2dp_audio_sbc_store_packet(btif_media_header_t * header, uint8_t *buffer, uint32_t buffer_bytes)
|
||||||
uint32_t buffer_bytes) {
|
{
|
||||||
int nRet = A2DP_DECODER_NO_ERROR;
|
int nRet = A2DP_DECODER_NO_ERROR;
|
||||||
|
|
||||||
uint32_t frame_cnt = 0;
|
uint32_t frame_cnt = 0;
|
||||||
|
@ -742,9 +682,7 @@ int a2dp_audio_sbc_store_packet(btif_media_header_t *header, uint8_t *buffer,
|
||||||
uint8_t *parser_p = buffer;
|
uint8_t *parser_p = buffer;
|
||||||
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
||||||
uint16_t bytes_parsed = 0;
|
uint16_t bytes_parsed = 0;
|
||||||
a2dp_audio_sbc_decoder_frame_t *frame_list[FRAME_LIST_MAX] = {
|
a2dp_audio_sbc_decoder_frame_t *frame_list[FRAME_LIST_MAX] = {0,};
|
||||||
0,
|
|
||||||
};
|
|
||||||
uint8_t frame_list_idx = 0;
|
uint8_t frame_list_idx = 0;
|
||||||
bool find_err = false;
|
bool find_err = false;
|
||||||
uint32_t i = 0;
|
uint32_t i = 0;
|
||||||
|
@ -752,8 +690,7 @@ int a2dp_audio_sbc_store_packet(btif_media_header_t *header, uint8_t *buffer,
|
||||||
frame_num = *parser_p;
|
frame_num = *parser_p;
|
||||||
|
|
||||||
if (!frame_num){
|
if (!frame_num){
|
||||||
TRACE_A2DP_DECODER_W("[SBC][INPUT] ERROR SBC FRAME !!! frame_num:%d",
|
TRACE_A2DP_DECODER_W("[SBC][INPUT] ERROR SBC FRAME !!! frame_num:%d", frame_num);
|
||||||
frame_num);
|
|
||||||
DUMP8("%02x ", parser_p, 12);
|
DUMP8("%02x ", parser_p, 12);
|
||||||
return A2DP_DECODER_DECODE_ERROR;
|
return A2DP_DECODER_DECODE_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -766,18 +703,14 @@ int a2dp_audio_sbc_store_packet(btif_media_header_t *header, uint8_t *buffer,
|
||||||
for (i=0; i<buffer_bytes; i+=bytes_parsed, frame_cnt++){
|
for (i=0; i<buffer_bytes; i+=bytes_parsed, frame_cnt++){
|
||||||
bytes_parsed = 0;
|
bytes_parsed = 0;
|
||||||
if (*(parser_p+i) == 0x9c){
|
if (*(parser_p+i) == 0x9c){
|
||||||
if (btif_sbc_decode_frames_parser(a2dp_audio_sbc_decoder_preparse,
|
if (btif_sbc_decode_frames_parser(a2dp_audio_sbc_decoder_preparse, parser_p+i, buffer_bytes, &bytes_parsed) != BT_STS_SUCCESS){
|
||||||
parser_p + i, buffer_bytes,
|
|
||||||
&bytes_parsed) != BT_STS_SUCCESS) {
|
|
||||||
bytes_parsed = frame_len;
|
bytes_parsed = frame_len;
|
||||||
TRACE_A2DP_DECODER_W("[SBC][INPUT] ERROR SBC FRAME PARSER !!!");
|
TRACE_A2DP_DECODER_W("[SBC][INPUT] ERROR SBC FRAME PARSER !!!");
|
||||||
DUMP8("%02x ", parser_p+i, 12);
|
DUMP8("%02x ", parser_p+i, 12);
|
||||||
find_err = true;
|
find_err = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
a2dp_audio_sbc_decoder_frame_t *frame_p =
|
a2dp_audio_sbc_decoder_frame_t *frame_p = (a2dp_audio_sbc_decoder_frame_t *)a2dp_audio_sbc_subframe_malloc(bytes_parsed);
|
||||||
(a2dp_audio_sbc_decoder_frame_t *)a2dp_audio_sbc_subframe_malloc(
|
|
||||||
bytes_parsed);
|
|
||||||
if (!frame_p){
|
if (!frame_p){
|
||||||
nRet = A2DP_DECODER_MEMORY_ERROR;
|
nRet = A2DP_DECODER_MEMORY_ERROR;
|
||||||
find_err = true;
|
find_err = true;
|
||||||
|
@ -816,15 +749,15 @@ int a2dp_audio_sbc_store_packet(btif_media_header_t *header, uint8_t *buffer,
|
||||||
nRet = A2DP_DECODER_NO_ERROR;
|
nRet = A2DP_DECODER_NO_ERROR;
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
TRACE_A2DP_DECODER_W("[SBC][INPUT] OVERFLOW list:%d",
|
TRACE_A2DP_DECODER_W("[SBC][INPUT] OVERFLOW list:%d", a2dp_audio_list_length(list));
|
||||||
a2dp_audio_list_length(list));
|
|
||||||
nRet = A2DP_DECODER_MTU_LIMTER_ERROR;
|
nRet = A2DP_DECODER_MTU_LIMTER_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return nRet;
|
return nRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2dp_audio_sbc_discards_packet(uint32_t packets) {
|
int a2dp_audio_sbc_discards_packet(uint32_t packets)
|
||||||
|
{
|
||||||
int nRet = A2DP_DECODER_MEMORY_ERROR;
|
int nRet = A2DP_DECODER_MEMORY_ERROR;
|
||||||
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
||||||
list_node_t *node = NULL;
|
list_node_t *node = NULL;
|
||||||
|
@ -840,16 +773,14 @@ int a2dp_audio_sbc_discards_packet(uint32_t packets) {
|
||||||
if (!node){
|
if (!node){
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
sbc_decoder_frame =
|
sbc_decoder_frame = (a2dp_audio_sbc_decoder_frame_t *)a2dp_audio_list_node(node);
|
||||||
(a2dp_audio_sbc_decoder_frame_t *)a2dp_audio_list_node(node);
|
|
||||||
|
|
||||||
for (j=0; j<a2dp_audio_list_length(list); j++){
|
for (j=0; j<a2dp_audio_list_length(list); j++){
|
||||||
node = a2dp_audio_list_begin(list);
|
node = a2dp_audio_list_begin(list);
|
||||||
if (!node){
|
if (!node){
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
sbc_decoder_frame =
|
sbc_decoder_frame = (a2dp_audio_sbc_decoder_frame_t *)a2dp_audio_list_node(node);
|
||||||
(a2dp_audio_sbc_decoder_frame_t *)a2dp_audio_list_node(node);
|
|
||||||
if (sbc_decoder_frame->curSubSequenceNumber != 0){
|
if (sbc_decoder_frame->curSubSequenceNumber != 0){
|
||||||
a2dp_audio_list_remove(list, sbc_decoder_frame);
|
a2dp_audio_list_remove(list, sbc_decoder_frame);
|
||||||
}else{
|
}else{
|
||||||
|
@ -861,10 +792,8 @@ int a2dp_audio_sbc_discards_packet(uint32_t packets) {
|
||||||
if (!node){
|
if (!node){
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
sbc_decoder_frame =
|
sbc_decoder_frame = (a2dp_audio_sbc_decoder_frame_t *)a2dp_audio_list_node(node);
|
||||||
(a2dp_audio_sbc_decoder_frame_t *)a2dp_audio_list_node(node);
|
ASSERT_A2DP_DECODER(sbc_decoder_frame->curSubSequenceNumber == 0, "sbc_discards_packet not align curSubSequenceNumber:%d",
|
||||||
ASSERT_A2DP_DECODER(sbc_decoder_frame->curSubSequenceNumber == 0,
|
|
||||||
"sbc_discards_packet not align curSubSequenceNumber:%d",
|
|
||||||
sbc_decoder_frame->curSubSequenceNumber);
|
sbc_decoder_frame->curSubSequenceNumber);
|
||||||
|
|
||||||
totalSubSequenceNumber = sbc_decoder_frame->totalSubSequenceNumber;
|
totalSubSequenceNumber = sbc_decoder_frame->totalSubSequenceNumber;
|
||||||
|
@ -876,8 +805,7 @@ int a2dp_audio_sbc_discards_packet(uint32_t packets) {
|
||||||
if (!node){
|
if (!node){
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
sbc_decoder_frame =
|
sbc_decoder_frame = (a2dp_audio_sbc_decoder_frame_t *)a2dp_audio_list_node(node);
|
||||||
(a2dp_audio_sbc_decoder_frame_t *)a2dp_audio_list_node(node);
|
|
||||||
a2dp_audio_list_remove(list, sbc_decoder_frame);
|
a2dp_audio_list_remove(list, sbc_decoder_frame);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -888,22 +816,18 @@ exit:
|
||||||
return nRet;
|
return nRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2dp_audio_sbc_headframe_info_get(
|
int a2dp_audio_sbc_headframe_info_get(A2DP_AUDIO_HEADFRAME_INFO_T *headframe_info)
|
||||||
A2DP_AUDIO_HEADFRAME_INFO_T *headframe_info) {
|
{
|
||||||
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
||||||
list_node_t *node = NULL;
|
list_node_t *node = NULL;
|
||||||
a2dp_audio_sbc_decoder_frame_t *sbc_decoder_frame = NULL;
|
a2dp_audio_sbc_decoder_frame_t *sbc_decoder_frame = NULL;
|
||||||
|
|
||||||
if (a2dp_audio_list_length(list) &&
|
if (a2dp_audio_list_length(list) && ((node = a2dp_audio_list_begin(list)) != NULL)){
|
||||||
((node = a2dp_audio_list_begin(list)) != NULL)) {
|
sbc_decoder_frame = (a2dp_audio_sbc_decoder_frame_t *)a2dp_audio_list_node(node);
|
||||||
sbc_decoder_frame =
|
|
||||||
(a2dp_audio_sbc_decoder_frame_t *)a2dp_audio_list_node(node);
|
|
||||||
headframe_info->sequenceNumber = sbc_decoder_frame->sequenceNumber;
|
headframe_info->sequenceNumber = sbc_decoder_frame->sequenceNumber;
|
||||||
headframe_info->timestamp = sbc_decoder_frame->timestamp;
|
headframe_info->timestamp = sbc_decoder_frame->timestamp;
|
||||||
headframe_info->curSubSequenceNumber =
|
headframe_info->curSubSequenceNumber = sbc_decoder_frame->curSubSequenceNumber;
|
||||||
sbc_decoder_frame->curSubSequenceNumber;
|
headframe_info->totalSubSequenceNumber = sbc_decoder_frame->totalSubSequenceNumber;
|
||||||
headframe_info->totalSubSequenceNumber =
|
|
||||||
sbc_decoder_frame->totalSubSequenceNumber;
|
|
||||||
}else{
|
}else{
|
||||||
memset(headframe_info, 0, sizeof(A2DP_AUDIO_HEADFRAME_INFO_T));
|
memset(headframe_info, 0, sizeof(A2DP_AUDIO_HEADFRAME_INFO_T));
|
||||||
}
|
}
|
||||||
|
@ -911,10 +835,13 @@ int a2dp_audio_sbc_headframe_info_get(
|
||||||
return A2DP_DECODER_NO_ERROR;
|
return A2DP_DECODER_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2dp_audio_sbc_info_get(void *info) { return A2DP_DECODER_NO_ERROR; }
|
int a2dp_audio_sbc_info_get(void *info)
|
||||||
|
{
|
||||||
|
return A2DP_DECODER_NO_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
int a2dp_audio_sbc_synchronize_packet(A2DP_AUDIO_SYNCFRAME_INFO_T *sync_info,
|
int a2dp_audio_sbc_synchronize_packet(A2DP_AUDIO_SYNCFRAME_INFO_T *sync_info, uint32_t mask)
|
||||||
uint32_t mask) {
|
{
|
||||||
int nRet = A2DP_DECODER_SYNC_ERROR;
|
int nRet = A2DP_DECODER_SYNC_ERROR;
|
||||||
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
||||||
list_node_t *node = NULL;
|
list_node_t *node = NULL;
|
||||||
|
@ -930,19 +857,10 @@ int a2dp_audio_sbc_synchronize_packet(A2DP_AUDIO_SYNCFRAME_INFO_T *sync_info,
|
||||||
for (uint16_t i=0; i<list_len; i++){
|
for (uint16_t i=0; i<list_len; i++){
|
||||||
node = a2dp_audio_list_begin(list);
|
node = a2dp_audio_list_begin(list);
|
||||||
if (node){
|
if (node){
|
||||||
sbc_decoder_frame =
|
sbc_decoder_frame = (a2dp_audio_sbc_decoder_frame_t *)a2dp_audio_list_node(node);
|
||||||
(a2dp_audio_sbc_decoder_frame_t *)a2dp_audio_list_node(node);
|
if (A2DP_AUDIO_SYNCFRAME_CHK(sbc_decoder_frame->sequenceNumber == sync_info->sequenceNumber, A2DP_AUDIO_SYNCFRAME_MASK_SEQ, mask)&&
|
||||||
if (A2DP_AUDIO_SYNCFRAME_CHK(sbc_decoder_frame->sequenceNumber ==
|
A2DP_AUDIO_SYNCFRAME_CHK(sbc_decoder_frame->curSubSequenceNumber == sync_info->curSubSequenceNumber, A2DP_AUDIO_SYNCFRAME_MASK_CURRSUBSEQ, mask)&&
|
||||||
sync_info->sequenceNumber,
|
A2DP_AUDIO_SYNCFRAME_CHK(sbc_decoder_frame->totalSubSequenceNumber == sync_info->totalSubSequenceNumber,A2DP_AUDIO_SYNCFRAME_MASK_TOTALSUBSEQ,mask)){
|
||||||
A2DP_AUDIO_SYNCFRAME_MASK_SEQ, mask) &&
|
|
||||||
A2DP_AUDIO_SYNCFRAME_CHK(sbc_decoder_frame->curSubSequenceNumber ==
|
|
||||||
sync_info->curSubSequenceNumber,
|
|
||||||
A2DP_AUDIO_SYNCFRAME_MASK_CURRSUBSEQ,
|
|
||||||
mask) &&
|
|
||||||
A2DP_AUDIO_SYNCFRAME_CHK(sbc_decoder_frame->totalSubSequenceNumber ==
|
|
||||||
sync_info->totalSubSequenceNumber,
|
|
||||||
A2DP_AUDIO_SYNCFRAME_MASK_TOTALSUBSEQ,
|
|
||||||
mask)) {
|
|
||||||
nRet = A2DP_DECODER_NO_ERROR;
|
nRet = A2DP_DECODER_NO_ERROR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -952,13 +870,10 @@ int a2dp_audio_sbc_synchronize_packet(A2DP_AUDIO_SYNCFRAME_INFO_T *sync_info,
|
||||||
|
|
||||||
node = a2dp_audio_list_begin(list);
|
node = a2dp_audio_list_begin(list);
|
||||||
if (node){
|
if (node){
|
||||||
sbc_decoder_frame =
|
sbc_decoder_frame = (a2dp_audio_sbc_decoder_frame_t *)a2dp_audio_list_node(node);
|
||||||
(a2dp_audio_sbc_decoder_frame_t *)a2dp_audio_list_node(node);
|
TRACE_A2DP_DECODER_I("[MCU][SYNC][SBC] sync pkt nRet:%d SEQ:%d timestamp:%d %d/%d",
|
||||||
TRACE_A2DP_DECODER_I(
|
nRet, sbc_decoder_frame->sequenceNumber, sbc_decoder_frame->timestamp,
|
||||||
"[MCU][SYNC][SBC] sync pkt nRet:%d SEQ:%d timestamp:%d %d/%d", nRet,
|
sbc_decoder_frame->curSubSequenceNumber, sbc_decoder_frame->totalSubSequenceNumber);
|
||||||
sbc_decoder_frame->sequenceNumber, sbc_decoder_frame->timestamp,
|
|
||||||
sbc_decoder_frame->curSubSequenceNumber,
|
|
||||||
sbc_decoder_frame->totalSubSequenceNumber);
|
|
||||||
}else{
|
}else{
|
||||||
TRACE_A2DP_DECODER_I("[MCU][SYNC][SBC] sync pkt nRet:%d", nRet);
|
TRACE_A2DP_DECODER_I("[MCU][SYNC][SBC] sync pkt nRet:%d", nRet);
|
||||||
}
|
}
|
||||||
|
@ -966,7 +881,8 @@ int a2dp_audio_sbc_synchronize_packet(A2DP_AUDIO_SYNCFRAME_INFO_T *sync_info,
|
||||||
return nRet;
|
return nRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2dp_audio_sbc_synchronize_dest_packet_mut(uint16_t packet_mut) {
|
int a2dp_audio_sbc_synchronize_dest_packet_mut(uint16_t packet_mut)
|
||||||
|
{
|
||||||
list_node_t *node = NULL;
|
list_node_t *node = NULL;
|
||||||
uint32_t list_len = 0;
|
uint32_t list_len = 0;
|
||||||
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
||||||
|
@ -977,20 +893,19 @@ int a2dp_audio_sbc_synchronize_dest_packet_mut(uint16_t packet_mut) {
|
||||||
do{
|
do{
|
||||||
node = a2dp_audio_list_begin(list);
|
node = a2dp_audio_list_begin(list);
|
||||||
if (node){
|
if (node){
|
||||||
sbc_decoder_frame =
|
sbc_decoder_frame = (a2dp_audio_sbc_decoder_frame_t *)a2dp_audio_list_node(node);
|
||||||
(a2dp_audio_sbc_decoder_frame_t *)a2dp_audio_list_node(node);
|
|
||||||
a2dp_audio_list_remove(list, sbc_decoder_frame);
|
a2dp_audio_list_remove(list, sbc_decoder_frame);
|
||||||
}
|
}
|
||||||
}while(a2dp_audio_list_length(list) > packet_mut);
|
}while(a2dp_audio_list_length(list) > packet_mut);
|
||||||
}
|
}
|
||||||
|
|
||||||
TRACE_A2DP_DECODER_I("[MCU][SYNC][SBC] dest pkt list:%d",
|
TRACE_A2DP_DECODER_I("[MCU][SYNC][SBC] dest pkt list:%d", a2dp_audio_list_length(list));
|
||||||
a2dp_audio_list_length(list));
|
|
||||||
|
|
||||||
return A2DP_DECODER_NO_ERROR;
|
return A2DP_DECODER_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2dp_audio_sbc_convert_list_to_samples(uint32_t *samples) {
|
int a2dp_audio_sbc_convert_list_to_samples(uint32_t *samples)
|
||||||
|
{
|
||||||
uint32_t list_len = 0;
|
uint32_t list_len = 0;
|
||||||
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
||||||
|
|
||||||
|
@ -1002,15 +917,15 @@ int a2dp_audio_sbc_convert_list_to_samples(uint32_t *samples) {
|
||||||
return A2DP_DECODER_NO_ERROR;
|
return A2DP_DECODER_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2dp_audio_sbc_discards_samples(uint32_t samples) {
|
int a2dp_audio_sbc_discards_samples(uint32_t samples)
|
||||||
|
{
|
||||||
int nRet = A2DP_DECODER_SYNC_ERROR;
|
int nRet = A2DP_DECODER_SYNC_ERROR;
|
||||||
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
||||||
a2dp_audio_sbc_decoder_frame_t *sbc_decoder_frame = NULL;
|
a2dp_audio_sbc_decoder_frame_t *sbc_decoder_frame = NULL;
|
||||||
list_node_t *node = NULL;
|
list_node_t *node = NULL;
|
||||||
int need_remove_list = 0;
|
int need_remove_list = 0;
|
||||||
uint32_t list_samples = 0;
|
uint32_t list_samples = 0;
|
||||||
ASSERT_A2DP_DECODER(!(samples % SBC_LIST_SAMPLES), "%s samples err:%d",
|
ASSERT_A2DP_DECODER(!(samples%SBC_LIST_SAMPLES), "%s samples err:%d", __func__, samples);
|
||||||
__func__, samples);
|
|
||||||
|
|
||||||
a2dp_audio_sbc_convert_list_to_samples(&list_samples);
|
a2dp_audio_sbc_convert_list_to_samples(&list_samples);
|
||||||
if (list_samples >= samples){
|
if (list_samples >= samples){
|
||||||
|
@ -1018,8 +933,7 @@ int a2dp_audio_sbc_discards_samples(uint32_t samples) {
|
||||||
for (int i=0; i<need_remove_list; i++){
|
for (int i=0; i<need_remove_list; i++){
|
||||||
node = a2dp_audio_list_begin(list);
|
node = a2dp_audio_list_begin(list);
|
||||||
if (node){
|
if (node){
|
||||||
sbc_decoder_frame =
|
sbc_decoder_frame = (a2dp_audio_sbc_decoder_frame_t *)a2dp_audio_list_node(node);
|
||||||
(a2dp_audio_sbc_decoder_frame_t *)a2dp_audio_list_node(node);
|
|
||||||
a2dp_audio_list_remove(list, sbc_decoder_frame);
|
a2dp_audio_list_remove(list, sbc_decoder_frame);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1029,7 +943,8 @@ int a2dp_audio_sbc_discards_samples(uint32_t samples) {
|
||||||
return nRet;
|
return nRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2dp_audio_sbc_channel_select(A2DP_AUDIO_CHANNEL_SELECT_E chnl_sel) {
|
int a2dp_audio_sbc_channel_select(A2DP_AUDIO_CHANNEL_SELECT_E chnl_sel)
|
||||||
|
{
|
||||||
return A2DP_DECODER_NO_ERROR;
|
return A2DP_DECODER_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1051,3 +966,4 @@ A2DP_AUDIO_DECODER_T a2dp_audio_sbc_decoder_config = {
|
||||||
a2dp_audio_sbc_subframe_free,
|
a2dp_audio_sbc_subframe_free,
|
||||||
a2dp_audio_sbc_channel_select,
|
a2dp_audio_sbc_channel_select,
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
|
@ -14,13 +14,13 @@
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
// Standard C Included Files
|
// Standard C Included Files
|
||||||
#include "a2dp_decoder_internal.h"
|
|
||||||
#include "app_audio.h"
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "hal_location.h"
|
|
||||||
#include "heap_api.h"
|
|
||||||
#include "plat_types.h"
|
#include "plat_types.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "heap_api.h"
|
||||||
|
#include "hal_location.h"
|
||||||
|
#include "a2dp_decoder_internal.h"
|
||||||
|
#include "app_audio.h"
|
||||||
#if defined(A2DP_SCALABLE_ON)
|
#if defined(A2DP_SCALABLE_ON)
|
||||||
#include "heap_api.h"
|
#include "heap_api.h"
|
||||||
#include "ssc.h"
|
#include "ssc.h"
|
||||||
|
@ -43,6 +43,7 @@ static HANDLE_DECODER scalableDec_handle = NULL;
|
||||||
|
|
||||||
static A2DP_AUDIO_DECODER_LASTFRAME_INFO_T lastframe_info;
|
static A2DP_AUDIO_DECODER_LASTFRAME_INFO_T lastframe_info;
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint16_t sequenceNumber;
|
uint16_t sequenceNumber;
|
||||||
uint32_t timestamp;
|
uint32_t timestamp;
|
||||||
|
@ -50,22 +51,26 @@ typedef struct {
|
||||||
int buffer_len;
|
int buffer_len;
|
||||||
} a2dp_audio_scalable_decoder_frame_t;
|
} a2dp_audio_scalable_decoder_frame_t;
|
||||||
|
|
||||||
static void ss_to_24bit_buf(int32_t *out, int32_t *in, int size) {
|
static void ss_to_24bit_buf(int32_t * out, int32_t * in, int size)
|
||||||
|
{
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
out[i] = in[i];
|
out[i] = in[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void a2dp_audio_scalable_decoder_init(void) {
|
static void a2dp_audio_scalable_decoder_init(void)
|
||||||
|
{
|
||||||
if (scalableDec_handle == NULL) {
|
if (scalableDec_handle == NULL) {
|
||||||
scalableDec_handle = scalable_decoder_place;
|
scalableDec_handle = scalable_decoder_place;
|
||||||
|
|
||||||
ssc_decoder_init(scalableDec_handle, output_config.num_channels,
|
|
||||||
output_config.sample_rate);
|
ssc_decoder_init(scalableDec_handle, output_config.num_channels, output_config.sample_rate);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int scalableDecoder_Close(HANDLE_DECODER handle) {
|
static int scalableDecoder_Close(HANDLE_DECODER handle)
|
||||||
|
{
|
||||||
if (handle) {
|
if (handle) {
|
||||||
a2dp_audio_heap_free(handle);
|
a2dp_audio_heap_free(handle);
|
||||||
a2dp_audio_heap_free(scalable_decoder_temp_buf);
|
a2dp_audio_heap_free(scalable_decoder_temp_buf);
|
||||||
|
@ -74,29 +79,30 @@ static int scalableDecoder_Close(HANDLE_DECODER handle) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void a2dp_audio_scalable_decoder_deinit(void) {
|
static void a2dp_audio_scalable_decoder_deinit(void)
|
||||||
|
{
|
||||||
if (scalableDec_handle) {
|
if (scalableDec_handle) {
|
||||||
scalableDecoder_Close(scalableDec_handle);
|
scalableDecoder_Close(scalableDec_handle);
|
||||||
scalableDec_handle = NULL;
|
scalableDec_handle = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void a2dp_audio_scalable_decoder_reinit(void) {
|
static void a2dp_audio_scalable_decoder_reinit(void)
|
||||||
|
{
|
||||||
if (scalableDec_handle) {
|
if (scalableDec_handle) {
|
||||||
a2dp_audio_scalable_decoder_deinit();
|
a2dp_audio_scalable_decoder_deinit();
|
||||||
}
|
}
|
||||||
a2dp_audio_scalable_decoder_init();
|
a2dp_audio_scalable_decoder_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool is_valid_frame(a2dp_audio_scalable_decoder_frame_t * decoder_frame_p)
|
||||||
is_valid_frame(a2dp_audio_scalable_decoder_frame_t *decoder_frame_p) {
|
{
|
||||||
int hw_tmp, len, bitrate_bps, frame_len, frame_size;
|
int hw_tmp, len, bitrate_bps, frame_len, frame_size;
|
||||||
|
|
||||||
int sampling_rate = 44100;
|
int sampling_rate = 44100;
|
||||||
unsigned char *input_buf = decoder_frame_p->buffer;
|
unsigned char *input_buf = decoder_frame_p->buffer;
|
||||||
if (decoder_frame_p->buffer_len < SCALABLE_HEAD_SIZE) {
|
if (decoder_frame_p->buffer_len < SCALABLE_HEAD_SIZE) {
|
||||||
TRACE_A2DP_DECODER_E(
|
TRACE_A2DP_DECODER_E("invalid scalable a2dp frame, length < SCALABLE_HEAD_SIZE !!!!!!!");
|
||||||
"invalid scalable a2dp frame, length < SCALABLE_HEAD_SIZE !!!!!!!");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,20 +144,21 @@ is_valid_frame(a2dp_audio_scalable_decoder_frame_t *decoder_frame_p) {
|
||||||
} else {
|
} else {
|
||||||
len = 369; //744/2-4+1
|
len = 369; //744/2-4+1
|
||||||
}
|
}
|
||||||
TRACE_A2DP_DECODER_D(
|
TRACE_A2DP_DECODER_D
|
||||||
"scalable a2dp frame, length:%d bitrate:%d sampling_rate:%d",
|
("scalable a2dp frame, length:%d bitrate:%d sampling_rate:%d",
|
||||||
decoder_frame_p->buffer_len, bitrate_bps, sampling_rate);
|
decoder_frame_p->buffer_len, bitrate_bps, sampling_rate);
|
||||||
frame_len = SCALABLE_HEAD_SIZE + len - 1;
|
frame_len = SCALABLE_HEAD_SIZE + len - 1;
|
||||||
|
|
||||||
if (decoder_frame_p->buffer_len < frame_len) {
|
if (decoder_frame_p->buffer_len < frame_len) {
|
||||||
TRACE_A2DP_DECODER_E(
|
TRACE_A2DP_DECODER_E
|
||||||
"invalid scalable a2dp frame, length:%d < %d !!!!!!!",
|
("invalid scalable a2dp frame, length:%d < %d !!!!!!!", decoder_frame_p->buffer_len, frame_len);
|
||||||
decoder_frame_p->buffer_len, frame_len);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef A2DP_CP_ACCEL
|
#ifdef A2DP_CP_ACCEL
|
||||||
struct A2DP_CP_scalable_IN_FRM_INFO_T {
|
struct A2DP_CP_scalable_IN_FRM_INFO_T {
|
||||||
uint16_t sequenceNumber;
|
uint16_t sequenceNumber;
|
||||||
|
@ -169,8 +176,8 @@ struct A2DP_CP_scalable_OUT_FRM_INFO_T {
|
||||||
static bool cp_codec_reset;
|
static bool cp_codec_reset;
|
||||||
extern uint32_t app_bt_stream_get_dma_buffer_samples(void);
|
extern uint32_t app_bt_stream_get_dma_buffer_samples(void);
|
||||||
|
|
||||||
TEXT_SSC_LOC static int a2dp_cp_scalable_mcu_decode(uint8_t *buffer,
|
TEXT_SSC_LOC static int a2dp_cp_scalable_mcu_decode(uint8_t * buffer, uint32_t buffer_bytes)
|
||||||
uint32_t buffer_bytes) {
|
{
|
||||||
a2dp_audio_scalable_decoder_frame_t *decoder_frame_p = NULL;
|
a2dp_audio_scalable_decoder_frame_t *decoder_frame_p = NULL;
|
||||||
list_node_t *node = NULL;
|
list_node_t *node = NULL;
|
||||||
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
||||||
|
@ -184,11 +191,9 @@ TEXT_SSC_LOC static int a2dp_cp_scalable_mcu_decode(uint8_t *buffer,
|
||||||
|
|
||||||
cp_buffer_frames_max = app_bt_stream_get_dma_buffer_samples()/2;
|
cp_buffer_frames_max = app_bt_stream_get_dma_buffer_samples()/2;
|
||||||
if (cp_buffer_frames_max %(lastframe_info.frame_samples) ){
|
if (cp_buffer_frames_max %(lastframe_info.frame_samples) ){
|
||||||
cp_buffer_frames_max =
|
cp_buffer_frames_max = cp_buffer_frames_max /(lastframe_info.frame_samples) +1;
|
||||||
cp_buffer_frames_max / (lastframe_info.frame_samples) + 1;
|
|
||||||
}else{
|
}else{
|
||||||
cp_buffer_frames_max =
|
cp_buffer_frames_max = cp_buffer_frames_max /(lastframe_info.frame_samples);
|
||||||
cp_buffer_frames_max / (lastframe_info.frame_samples);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
out_frame_len = sizeof(*p_out_info) + buffer_bytes;
|
out_frame_len = sizeof(*p_out_info) + buffer_bytes;
|
||||||
|
@ -197,8 +202,8 @@ TEXT_SSC_LOC static int a2dp_cp_scalable_mcu_decode(uint8_t *buffer,
|
||||||
ASSERT(ret == 0, "%s: a2dp_cp_decoder_init() failed: ret=%d", __func__, ret);
|
ASSERT(ret == 0, "%s: a2dp_cp_decoder_init() failed: ret=%d", __func__, ret);
|
||||||
|
|
||||||
while ((node = a2dp_audio_list_begin(list)) != NULL) {
|
while ((node = a2dp_audio_list_begin(list)) != NULL) {
|
||||||
decoder_frame_p =
|
decoder_frame_p = (a2dp_audio_scalable_decoder_frame_t *)
|
||||||
(a2dp_audio_scalable_decoder_frame_t *)a2dp_audio_list_node(node);
|
a2dp_audio_list_node(node);
|
||||||
|
|
||||||
if (false == is_valid_frame(decoder_frame_p)) {
|
if (false == is_valid_frame(decoder_frame_p)) {
|
||||||
return A2DP_DECODER_DECODE_ERROR;
|
return A2DP_DECODER_DECODE_ERROR;
|
||||||
|
@ -207,9 +212,7 @@ TEXT_SSC_LOC static int a2dp_cp_scalable_mcu_decode(uint8_t *buffer,
|
||||||
in_info.sequenceNumber = decoder_frame_p->sequenceNumber;
|
in_info.sequenceNumber = decoder_frame_p->sequenceNumber;
|
||||||
in_info.timestamp = decoder_frame_p->timestamp;
|
in_info.timestamp = decoder_frame_p->timestamp;
|
||||||
|
|
||||||
ret =
|
ret = a2dp_cp_put_in_frame(&in_info, sizeof(in_info), decoder_frame_p->buffer, decoder_frame_p->buffer_len);
|
||||||
a2dp_cp_put_in_frame(&in_info, sizeof(in_info), decoder_frame_p->buffer,
|
|
||||||
decoder_frame_p->buffer_len);
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -226,8 +229,7 @@ TEXT_SSC_LOC static int a2dp_cp_scalable_mcu_decode(uint8_t *buffer,
|
||||||
a2dp_cp_consume_full_out_frame();
|
a2dp_cp_consume_full_out_frame();
|
||||||
return A2DP_DECODER_NO_ERROR;
|
return A2DP_DECODER_NO_ERROR;
|
||||||
}
|
}
|
||||||
ASSERT(out_len == out_frame_len, "%s: Bad out len %u (should be %u)",
|
ASSERT(out_len == out_frame_len, "%s: Bad out len %u (should be %u)", __func__, out_len, out_frame_len);
|
||||||
__func__, out_len, out_frame_len);
|
|
||||||
|
|
||||||
p_out_info = (struct A2DP_CP_scalable_OUT_FRM_INFO_T *)out;
|
p_out_info = (struct A2DP_CP_scalable_OUT_FRM_INFO_T *)out;
|
||||||
if (p_out_info->pcm_len) {
|
if (p_out_info->pcm_len) {
|
||||||
|
@ -238,8 +240,7 @@ TEXT_SSC_LOC static int a2dp_cp_scalable_mcu_decode(uint8_t *buffer,
|
||||||
lastframe_info.frame_samples = p_out_info->frame_samples;
|
lastframe_info.frame_samples = p_out_info->frame_samples;
|
||||||
lastframe_info.decoded_frames += p_out_info->decoded_frames;
|
lastframe_info.decoded_frames += p_out_info->decoded_frames;
|
||||||
lastframe_info.undecode_frames =
|
lastframe_info.undecode_frames =
|
||||||
a2dp_audio_list_length(list) +
|
a2dp_audio_list_length(list) + a2dp_cp_get_in_frame_cnt_by_index(p_out_info->frame_idx) - 1;
|
||||||
a2dp_cp_get_in_frame_cnt_by_index(p_out_info->frame_idx) - 1;
|
|
||||||
a2dp_audio_decoder_internal_lastframe_info_set(&lastframe_info);
|
a2dp_audio_decoder_internal_lastframe_info_set(&lastframe_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,13 +252,13 @@ TEXT_SSC_LOC static int a2dp_cp_scalable_mcu_decode(uint8_t *buffer,
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = a2dp_cp_consume_full_out_frame();
|
ret = a2dp_cp_consume_full_out_frame();
|
||||||
ASSERT(ret == 0, "%s: a2dp_cp_consume_full_out_frame() failed: ret=%d",
|
ASSERT(ret == 0, "%s: a2dp_cp_consume_full_out_frame() failed: ret=%d", __func__, ret);
|
||||||
__func__, ret);
|
|
||||||
|
|
||||||
return dec_ret;
|
return dec_ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEXT_SSC_LOC int a2dp_cp_scalable_cp_decode(void) {
|
TEXT_SSC_LOC int a2dp_cp_scalable_cp_decode(void)
|
||||||
|
{
|
||||||
int ret;
|
int ret;
|
||||||
enum CP_EMPTY_OUT_FRM_T out_frm_st;
|
enum CP_EMPTY_OUT_FRM_T out_frm_st;
|
||||||
uint8_t *out;
|
uint8_t *out;
|
||||||
|
@ -271,30 +272,30 @@ TEXT_SSC_LOC int a2dp_cp_scalable_cp_decode(void) {
|
||||||
uint32_t dec_sum;
|
uint32_t dec_sum;
|
||||||
int error, output_samples = 0,output_byte = 0;
|
int error, output_samples = 0,output_byte = 0;
|
||||||
|
|
||||||
if (cp_codec_reset) {
|
if (cp_codec_reset)
|
||||||
|
{
|
||||||
cp_codec_reset = false;
|
cp_codec_reset = false;
|
||||||
a2dp_audio_scalable_decoder_init();
|
a2dp_audio_scalable_decoder_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
out_frm_st = a2dp_cp_get_emtpy_out_frame((void **)&out, &out_len);
|
out_frm_st = a2dp_cp_get_emtpy_out_frame((void **)&out, &out_len);
|
||||||
|
|
||||||
if (out_frm_st != CP_EMPTY_OUT_FRM_OK &&
|
if (out_frm_st != CP_EMPTY_OUT_FRM_OK && out_frm_st != CP_EMPTY_OUT_FRM_WORKING)
|
||||||
out_frm_st != CP_EMPTY_OUT_FRM_WORKING) {
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(out_len > sizeof(*p_out_info), "%s: Bad out_len %u (should > %u)",
|
ASSERT(out_len > sizeof(*p_out_info), "%s: Bad out_len %u (should > %u)", __func__, out_len, sizeof(*p_out_info));
|
||||||
__func__, out_len, sizeof(*p_out_info));
|
|
||||||
|
|
||||||
p_out_info = (struct A2DP_CP_scalable_OUT_FRM_INFO_T *)out;
|
p_out_info = (struct A2DP_CP_scalable_OUT_FRM_INFO_T *)out;
|
||||||
if (out_frm_st == CP_EMPTY_OUT_FRM_OK) {
|
if (out_frm_st == CP_EMPTY_OUT_FRM_OK)
|
||||||
|
{
|
||||||
p_out_info->pcm_len = 0;
|
p_out_info->pcm_len = 0;
|
||||||
p_out_info->decoded_frames = 0;
|
p_out_info->decoded_frames = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(out_len > sizeof(*p_out_info) + p_out_info->pcm_len,
|
ASSERT(out_len > sizeof(*p_out_info) + p_out_info->pcm_len,
|
||||||
"%s: Bad out_len %u (should > %u + %u)", __func__, out_len,
|
"%s: Bad out_len %u (should > %u + %u)", __func__, out_len, sizeof(*p_out_info), p_out_info->pcm_len);
|
||||||
sizeof(*p_out_info), p_out_info->pcm_len);
|
|
||||||
|
|
||||||
dec_start = (uint8_t *) (p_out_info + 1) + p_out_info->pcm_len;
|
dec_start = (uint8_t *) (p_out_info + 1) + p_out_info->pcm_len;
|
||||||
dec_len = out_len - (dec_start - (uint8_t *) out);
|
dec_len = out_len - (dec_start - (uint8_t *) out);
|
||||||
|
@ -306,31 +307,30 @@ TEXT_SSC_LOC int a2dp_cp_scalable_cp_decode(void) {
|
||||||
dec_sum = 0;
|
dec_sum = 0;
|
||||||
error = 0;
|
error = 0;
|
||||||
|
|
||||||
while (dec_sum < dec_len && error == 0) {
|
while (dec_sum < dec_len && error == 0)
|
||||||
|
{
|
||||||
ret = a2dp_cp_get_in_frame((void * *) &in_buf, &in_len);
|
ret = a2dp_cp_get_in_frame((void * *) &in_buf, &in_len);
|
||||||
|
|
||||||
if (ret) {
|
if (ret)
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(in_len > sizeof(*p_in_info), "%s: Bad in_len %u (should > %u)",
|
ASSERT(in_len > sizeof(*p_in_info), "%s: Bad in_len %u (should > %u)", __func__, in_len, sizeof(*p_in_info));
|
||||||
__func__, in_len, sizeof(*p_in_info));
|
|
||||||
p_in_info = (struct A2DP_CP_scalable_IN_FRM_INFO_T *)in_buf;
|
p_in_info = (struct A2DP_CP_scalable_IN_FRM_INFO_T *)in_buf;
|
||||||
in_buf += sizeof(*p_in_info);
|
in_buf += sizeof(*p_in_info);
|
||||||
in_len -= sizeof(*p_in_info);
|
in_len -= sizeof(*p_in_info);
|
||||||
/* decode one SSC frame */
|
/* decode one SSC frame */
|
||||||
output_samples =
|
output_samples = ssc_decode(scalableDec_handle,(const unsigned char*)in_buf, ss_pcm_buff, SCALABLE_FRAME_SIZE, 0, 2);
|
||||||
ssc_decode(scalableDec_handle, (const unsigned char *)in_buf,
|
if (0 == output_samples)
|
||||||
ss_pcm_buff, SCALABLE_FRAME_SIZE, 0, 2);
|
{
|
||||||
if (0 == output_samples) {
|
|
||||||
a2dp_audio_scalable_decoder_reinit();
|
a2dp_audio_scalable_decoder_reinit();
|
||||||
TRACE(0, "scalable_decode reinin codec \n");
|
TRACE(0, "scalable_decode reinin codec \n");
|
||||||
error = A2DP_DECODER_DECODE_ERROR;
|
error = A2DP_DECODER_DECODE_ERROR;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
ss_to_24bit_buf((int32_t *)(dec_start + dec_sum), (int32_t *)ss_pcm_buff,
|
ss_to_24bit_buf((int32_t *) (dec_start+dec_sum), (int32_t *) ss_pcm_buff, output_samples);
|
||||||
output_samples);
|
|
||||||
output_byte = output_samples * 4;
|
output_byte = output_samples * 4;
|
||||||
dec_sum += output_byte;
|
dec_sum += output_byte;
|
||||||
exit:
|
exit:
|
||||||
|
@ -340,24 +340,22 @@ TEXT_SSC_LOC int a2dp_cp_scalable_cp_decode(void) {
|
||||||
p_out_info->frame_idx = a2dp_cp_get_in_frame_index();
|
p_out_info->frame_idx = a2dp_cp_get_in_frame_index();
|
||||||
|
|
||||||
ret = a2dp_cp_consume_in_frame();
|
ret = a2dp_cp_consume_in_frame();
|
||||||
ASSERT(ret == 0, "%s: a2dp_cp_consume_in_frame() failed: ret=%d", __func__,
|
ASSERT(ret == 0, "%s: a2dp_cp_consume_in_frame() failed: ret=%d", __func__, ret);
|
||||||
ret);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
p_out_info->pcm_len += dec_sum;
|
p_out_info->pcm_len += dec_sum;
|
||||||
|
|
||||||
if (error || out_len <= sizeof(*p_out_info) + p_out_info->pcm_len) {
|
if (error || out_len <= sizeof(*p_out_info) + p_out_info->pcm_len) {
|
||||||
ret = a2dp_cp_consume_emtpy_out_frame();
|
ret = a2dp_cp_consume_emtpy_out_frame();
|
||||||
ASSERT(ret == 0, "%s: a2dp_cp_consume_emtpy_out_frame() failed: ret=%d",
|
ASSERT(ret == 0, "%s: a2dp_cp_consume_emtpy_out_frame() failed: ret=%d", __func__, ret);
|
||||||
__func__, ret);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int a2dp_audio_scalable_init(A2DP_AUDIO_OUTPUT_CONFIG_T *config,
|
static int a2dp_audio_scalable_init(A2DP_AUDIO_OUTPUT_CONFIG_T * config, void *context)
|
||||||
void *context) {
|
{
|
||||||
TRACE_A2DP_DECODER_D("%s", __func__);
|
TRACE_A2DP_DECODER_D("%s", __func__);
|
||||||
|
|
||||||
TRACE(0,"\n\nA2DP SSC-LC INIT\n");
|
TRACE(0,"\n\nA2DP SSC-LC INIT\n");
|
||||||
|
@ -373,25 +371,19 @@ static int a2dp_audio_scalable_init(A2DP_AUDIO_OUTPUT_CONFIG_T *config,
|
||||||
a2dp_audio_decoder_internal_lastframe_info_set(&lastframe_info);
|
a2dp_audio_decoder_internal_lastframe_info_set(&lastframe_info);
|
||||||
|
|
||||||
ASSERT(a2dp_audio_context_p->dest_packet_mut < SCALABLE_MTU_LIMITER,
|
ASSERT(a2dp_audio_context_p->dest_packet_mut < SCALABLE_MTU_LIMITER,
|
||||||
"%s MTU OVERFLOW:%u/%u", __func__,
|
"%s MTU OVERFLOW:%u/%u", __func__, a2dp_audio_context_p->dest_packet_mut, SCALABLE_MTU_LIMITER);
|
||||||
a2dp_audio_context_p->dest_packet_mut, SCALABLE_MTU_LIMITER);
|
|
||||||
|
|
||||||
int decoder_size;
|
int decoder_size;
|
||||||
|
|
||||||
decoder_size = ssc_decoder_get_size(
|
decoder_size = ssc_decoder_get_size(output_config.num_channels); //todo: get size with codec capability
|
||||||
output_config.num_channels); // todo: get size with codec capability
|
|
||||||
|
|
||||||
TRACE(0, "decoder size %d", decoder_size);
|
TRACE(0, "decoder size %d", decoder_size);
|
||||||
|
|
||||||
scalable_decoder_place =
|
scalable_decoder_place = (unsigned char *)a2dp_audio_heap_malloc(decoder_size);
|
||||||
(unsigned char *)a2dp_audio_heap_malloc(decoder_size);
|
ASSERT_A2DP_DECODER(scalable_decoder_place, "no memory resource for scalable_decoder_place");
|
||||||
ASSERT_A2DP_DECODER(scalable_decoder_place,
|
|
||||||
"no memory resource for scalable_decoder_place");
|
|
||||||
|
|
||||||
scalable_decoder_temp_buf =
|
scalable_decoder_temp_buf = (unsigned char *)a2dp_audio_heap_malloc(SCALABLE_FRAME_SIZE * 16);
|
||||||
(unsigned char *)a2dp_audio_heap_malloc(SCALABLE_FRAME_SIZE * 16);
|
ASSERT_A2DP_DECODER(scalable_decoder_temp_buf, "no memory resource for scalable_decoder_temp_buf");
|
||||||
ASSERT_A2DP_DECODER(scalable_decoder_temp_buf,
|
|
||||||
"no memory resource for scalable_decoder_temp_buf");
|
|
||||||
|
|
||||||
#ifdef A2DP_CP_ACCEL
|
#ifdef A2DP_CP_ACCEL
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -405,7 +397,8 @@ static int a2dp_audio_scalable_init(A2DP_AUDIO_OUTPUT_CONFIG_T *config,
|
||||||
return A2DP_DECODER_NO_ERROR;
|
return A2DP_DECODER_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int a2dp_audio_scalable_deinit(void) {
|
static int a2dp_audio_scalable_deinit(void)
|
||||||
|
{
|
||||||
#ifdef A2DP_CP_ACCEL
|
#ifdef A2DP_CP_ACCEL
|
||||||
a2dp_cp_deinit();
|
a2dp_cp_deinit();
|
||||||
#endif
|
#endif
|
||||||
|
@ -417,8 +410,8 @@ static int a2dp_audio_scalable_deinit(void) {
|
||||||
return A2DP_DECODER_NO_ERROR;
|
return A2DP_DECODER_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2dp_audio_scalable_mcu_decode_frame(uint8_t *buffer,
|
int a2dp_audio_scalable_mcu_decode_frame(uint8_t * buffer, uint32_t buffer_bytes)
|
||||||
uint32_t buffer_bytes) {
|
{
|
||||||
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
||||||
list_node_t *node = NULL;
|
list_node_t *node = NULL;
|
||||||
a2dp_audio_scalable_decoder_frame_t *decoder_frame_p = NULL;
|
a2dp_audio_scalable_decoder_frame_t *decoder_frame_p = NULL;
|
||||||
|
@ -428,8 +421,7 @@ int a2dp_audio_scalable_mcu_decode_frame(uint8_t *buffer,
|
||||||
int output_byte = 0, output_samples = 0;
|
int output_byte = 0, output_samples = 0;
|
||||||
uint8_t *output = buffer;
|
uint8_t *output = buffer;
|
||||||
// TRACE(1,"bbd %d",buffer_bytes );
|
// TRACE(1,"bbd %d",buffer_bytes );
|
||||||
if (buffer_bytes < (SCALABLE_FRAME_SIZE * output_config.num_channels *
|
if (buffer_bytes < (SCALABLE_FRAME_SIZE * output_config.num_channels * output_config.bits_depth / 8)) {
|
||||||
output_config.bits_depth / 8)) {
|
|
||||||
TRACE(1,"scalable_decode pcm_len = %d \n", buffer_bytes);
|
TRACE(1,"scalable_decode pcm_len = %d \n", buffer_bytes);
|
||||||
return A2DP_DECODER_NO_ERROR;
|
return A2DP_DECODER_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -445,8 +437,8 @@ int a2dp_audio_scalable_mcu_decode_frame(uint8_t *buffer,
|
||||||
cache_underflow = true;
|
cache_underflow = true;
|
||||||
goto exit;
|
goto exit;
|
||||||
} else {
|
} else {
|
||||||
decoder_frame_p =
|
decoder_frame_p = (a2dp_audio_scalable_decoder_frame_t *)
|
||||||
(a2dp_audio_scalable_decoder_frame_t *)a2dp_audio_list_node(node);
|
a2dp_audio_list_node(node);
|
||||||
|
|
||||||
if (false == is_valid_frame(decoder_frame_p)) {
|
if (false == is_valid_frame(decoder_frame_p)) {
|
||||||
TRACE_A2DP_DECODER_E("%s %d invalid a2dp frame", __func__, __LINE__);
|
TRACE_A2DP_DECODER_E("%s %d invalid a2dp frame", __func__, __LINE__);
|
||||||
|
@ -455,12 +447,13 @@ int a2dp_audio_scalable_mcu_decode_frame(uint8_t *buffer,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* decode one SSC frame */
|
/* decode one SSC frame */
|
||||||
output_samples = ssc_decode(scalableDec_handle, decoder_frame_p->buffer,
|
output_samples =
|
||||||
ss_pcm_buff, SCALABLE_FRAME_SIZE, 0, 2);
|
ssc_decode(scalableDec_handle,
|
||||||
|
decoder_frame_p->buffer, ss_pcm_buff, SCALABLE_FRAME_SIZE,0,2);
|
||||||
|
|
||||||
TRACE_A2DP_DECODER_D("scalable_decode seq:%d len:%d output_samples:%d",
|
TRACE_A2DP_DECODER_D
|
||||||
decoder_frame_p->sequenceNumber,
|
("scalable_decode seq:%d len:%d output_samples:%d",
|
||||||
decoder_frame_p->buffer_len, output_samples);
|
decoder_frame_p->sequenceNumber, decoder_frame_p->buffer_len, output_samples);
|
||||||
|
|
||||||
if (0 == output_samples) {
|
if (0 == output_samples) {
|
||||||
TRACE(0,"scalable_decode failed !!!!!!");
|
TRACE(0,"scalable_decode failed !!!!!!");
|
||||||
|
@ -470,13 +463,12 @@ int a2dp_audio_scalable_mcu_decode_frame(uint8_t *buffer,
|
||||||
ret = A2DP_DECODER_DECODE_ERROR;
|
ret = A2DP_DECODER_DECODE_ERROR;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
ss_to_24bit_buf((int32_t *)output, (int32_t *)ss_pcm_buff,
|
ss_to_24bit_buf((int32_t *) output, (int32_t *) ss_pcm_buff, output_samples * 2);
|
||||||
output_samples * 2);
|
|
||||||
output_byte = output_samples * 8;
|
output_byte = output_samples * 8;
|
||||||
|
|
||||||
|
|
||||||
output += output_byte;
|
output += output_byte;
|
||||||
ASSERT(SCALABLE_FRAME_SIZE == output_samples,
|
ASSERT(SCALABLE_FRAME_SIZE == output_samples, "scalable_decode output mismatch samples:%d", output_samples);
|
||||||
"scalable_decode output mismatch samples:%d", output_samples);
|
|
||||||
lastframe_info.sequenceNumber = decoder_frame_p->sequenceNumber;
|
lastframe_info.sequenceNumber = decoder_frame_p->sequenceNumber;
|
||||||
lastframe_info.timestamp = decoder_frame_p->timestamp;
|
lastframe_info.timestamp = decoder_frame_p->timestamp;
|
||||||
lastframe_info.curSubSequenceNumber = 0;
|
lastframe_info.curSubSequenceNumber = 0;
|
||||||
|
@ -486,7 +478,9 @@ int a2dp_audio_scalable_mcu_decode_frame(uint8_t *buffer,
|
||||||
lastframe_info.undecode_frames = a2dp_audio_list_length(list) - 1;
|
lastframe_info.undecode_frames = a2dp_audio_list_length(list) - 1;
|
||||||
a2dp_audio_decoder_internal_lastframe_info_set(&lastframe_info);
|
a2dp_audio_decoder_internal_lastframe_info_set(&lastframe_info);
|
||||||
a2dp_audio_list_remove(list, decoder_frame_p);
|
a2dp_audio_list_remove(list, decoder_frame_p);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
@ -499,8 +493,8 @@ exit:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int a2dp_audio_scalable_decode_frame(uint8_t *buffer,
|
static int a2dp_audio_scalable_decode_frame(uint8_t * buffer, uint32_t buffer_bytes)
|
||||||
uint32_t buffer_bytes) {
|
{
|
||||||
#ifdef A2DP_CP_ACCEL
|
#ifdef A2DP_CP_ACCEL
|
||||||
return a2dp_cp_scalable_mcu_decode(buffer, buffer_bytes);
|
return a2dp_cp_scalable_mcu_decode(buffer, buffer_bytes);
|
||||||
#else
|
#else
|
||||||
|
@ -508,9 +502,8 @@ static int a2dp_audio_scalable_decode_frame(uint8_t *buffer,
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static int a2dp_audio_scalable_preparse_packet(btif_media_header_t *header,
|
static int a2dp_audio_scalable_preparse_packet(btif_media_header_t * header, uint8_t * buffer, uint32_t buffer_bytes)
|
||||||
uint8_t *buffer,
|
{
|
||||||
uint32_t buffer_bytes) {
|
|
||||||
lastframe_info.sequenceNumber = header->sequenceNumber;
|
lastframe_info.sequenceNumber = header->sequenceNumber;
|
||||||
lastframe_info.timestamp = header->timestamp;
|
lastframe_info.timestamp = header->timestamp;
|
||||||
lastframe_info.curSubSequenceNumber = 0;
|
lastframe_info.curSubSequenceNumber = 0;
|
||||||
|
@ -521,43 +514,39 @@ static int a2dp_audio_scalable_preparse_packet(btif_media_header_t *header,
|
||||||
lastframe_info.undecode_frames = 0;
|
lastframe_info.undecode_frames = 0;
|
||||||
a2dp_audio_decoder_internal_lastframe_info_set(&lastframe_info);
|
a2dp_audio_decoder_internal_lastframe_info_set(&lastframe_info);
|
||||||
|
|
||||||
TRACE(3, "%s seq:%d timestamp:%08x", __func__, header->sequenceNumber,
|
TRACE(3,"%s seq:%d timestamp:%08x", __func__, header->sequenceNumber, header->timestamp);
|
||||||
header->timestamp);
|
|
||||||
|
|
||||||
return A2DP_DECODER_NO_ERROR;
|
return A2DP_DECODER_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *a2dp_audio_scalable_frame_malloc(uint32_t packet_len) {
|
static void *a2dp_audio_scalable_frame_malloc(uint32_t packet_len)
|
||||||
|
{
|
||||||
a2dp_audio_scalable_decoder_frame_t *decoder_frame_p = NULL;
|
a2dp_audio_scalable_decoder_frame_t *decoder_frame_p = NULL;
|
||||||
uint8_t *buffer = NULL;
|
uint8_t *buffer = NULL;
|
||||||
|
|
||||||
buffer = (uint8_t *) a2dp_audio_heap_malloc(SCALABLE_READBUF_SIZE);
|
buffer = (uint8_t *) a2dp_audio_heap_malloc(SCALABLE_READBUF_SIZE);
|
||||||
decoder_frame_p =
|
decoder_frame_p = (a2dp_audio_scalable_decoder_frame_t *)
|
||||||
(a2dp_audio_scalable_decoder_frame_t *)a2dp_audio_heap_malloc(
|
a2dp_audio_heap_malloc(sizeof(a2dp_audio_scalable_decoder_frame_t));
|
||||||
sizeof(a2dp_audio_scalable_decoder_frame_t));
|
|
||||||
decoder_frame_p->buffer = buffer;
|
decoder_frame_p->buffer = buffer;
|
||||||
decoder_frame_p->buffer_len = packet_len;
|
decoder_frame_p->buffer_len = packet_len;
|
||||||
return (void *)decoder_frame_p;
|
return (void *)decoder_frame_p;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void a2dp_audio_scalable_free(void *packet) {
|
static void a2dp_audio_scalable_free(void *packet)
|
||||||
a2dp_audio_scalable_decoder_frame_t *decoder_frame_p =
|
{
|
||||||
(a2dp_audio_scalable_decoder_frame_t *)packet;
|
a2dp_audio_scalable_decoder_frame_t *decoder_frame_p = (a2dp_audio_scalable_decoder_frame_t *) packet;
|
||||||
a2dp_audio_heap_free(decoder_frame_p->buffer);
|
a2dp_audio_heap_free(decoder_frame_p->buffer);
|
||||||
a2dp_audio_heap_free(decoder_frame_p);
|
a2dp_audio_heap_free(decoder_frame_p);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int a2dp_audio_scalable_store_packet(btif_media_header_t *header,
|
static int a2dp_audio_scalable_store_packet(btif_media_header_t * header, uint8_t * buffer, uint32_t buffer_bytes)
|
||||||
uint8_t *buffer,
|
{
|
||||||
uint32_t buffer_bytes) {
|
|
||||||
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
||||||
int nRet = A2DP_DECODER_NO_ERROR;
|
int nRet = A2DP_DECODER_NO_ERROR;
|
||||||
if (a2dp_audio_list_length(list) < SCALABLE_MTU_LIMITER) {
|
if (a2dp_audio_list_length(list) < SCALABLE_MTU_LIMITER) {
|
||||||
a2dp_audio_scalable_decoder_frame_t *decoder_frame_p =
|
a2dp_audio_scalable_decoder_frame_t *decoder_frame_p = (a2dp_audio_scalable_decoder_frame_t *)
|
||||||
(a2dp_audio_scalable_decoder_frame_t *)a2dp_audio_scalable_frame_malloc(
|
a2dp_audio_scalable_frame_malloc(buffer_bytes);
|
||||||
buffer_bytes);
|
TRACE_A2DP_DECODER_D("%s seq:%d len:%d", __func__, header->sequenceNumber, buffer_bytes);
|
||||||
TRACE_A2DP_DECODER_D("%s seq:%d len:%d", __func__, header->sequenceNumber,
|
|
||||||
buffer_bytes);
|
|
||||||
decoder_frame_p->sequenceNumber = header->sequenceNumber;
|
decoder_frame_p->sequenceNumber = header->sequenceNumber;
|
||||||
decoder_frame_p->timestamp = header->timestamp;
|
decoder_frame_p->timestamp = header->timestamp;
|
||||||
memcpy(decoder_frame_p->buffer, buffer, buffer_bytes);
|
memcpy(decoder_frame_p->buffer, buffer, buffer_bytes);
|
||||||
|
@ -565,15 +554,15 @@ static int a2dp_audio_scalable_store_packet(btif_media_header_t *header,
|
||||||
a2dp_audio_list_append(list, decoder_frame_p);
|
a2dp_audio_list_append(list, decoder_frame_p);
|
||||||
nRet = A2DP_DECODER_NO_ERROR;
|
nRet = A2DP_DECODER_NO_ERROR;
|
||||||
} else {
|
} else {
|
||||||
TRACE(2, "%s list full current len:%d", __func__,
|
TRACE(2,"%s list full current len:%d", __func__, a2dp_audio_list_length(list));
|
||||||
a2dp_audio_list_length(list));
|
|
||||||
nRet = A2DP_DECODER_MTU_LIMTER_ERROR;
|
nRet = A2DP_DECODER_MTU_LIMTER_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return nRet;
|
return nRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int a2dp_audio_scalable_discards_packet(uint32_t packets) {
|
static int a2dp_audio_scalable_discards_packet(uint32_t packets)
|
||||||
|
{
|
||||||
int nRet = A2DP_DECODER_MEMORY_ERROR;
|
int nRet = A2DP_DECODER_MEMORY_ERROR;
|
||||||
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
||||||
list_node_t *node = NULL;
|
list_node_t *node = NULL;
|
||||||
|
@ -586,8 +575,8 @@ static int a2dp_audio_scalable_discards_packet(uint32_t packets) {
|
||||||
if (packets <= a2dp_audio_list_length(list)) {
|
if (packets <= a2dp_audio_list_length(list)) {
|
||||||
for (uint8_t i = 0; i < packets; i++) {
|
for (uint8_t i = 0; i < packets; i++) {
|
||||||
if ((node = a2dp_audio_list_begin(list)) != NULL){
|
if ((node = a2dp_audio_list_begin(list)) != NULL){
|
||||||
decoder_frame_p =
|
decoder_frame_p = (a2dp_audio_scalable_decoder_frame_t *)
|
||||||
(a2dp_audio_scalable_decoder_frame_t *)a2dp_audio_list_node(node);
|
a2dp_audio_list_node(node);
|
||||||
a2dp_audio_list_remove(list, decoder_frame_p);
|
a2dp_audio_list_remove(list, decoder_frame_p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -598,16 +587,15 @@ static int a2dp_audio_scalable_discards_packet(uint32_t packets) {
|
||||||
return nRet;
|
return nRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int a2dp_audio_scalable_headframe_info_get(
|
static int a2dp_audio_scalable_headframe_info_get(A2DP_AUDIO_HEADFRAME_INFO_T* headframe_info)
|
||||||
A2DP_AUDIO_HEADFRAME_INFO_T *headframe_info) {
|
{
|
||||||
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
||||||
list_node_t *node = NULL;
|
list_node_t *node = NULL;
|
||||||
a2dp_audio_scalable_decoder_frame_t *decoder_frame_p = NULL;
|
a2dp_audio_scalable_decoder_frame_t *decoder_frame_p = NULL;
|
||||||
|
|
||||||
if (a2dp_audio_list_length(list)){
|
if (a2dp_audio_list_length(list)){
|
||||||
if ((node = a2dp_audio_list_begin(list)) != NULL){
|
if ((node = a2dp_audio_list_begin(list)) != NULL){
|
||||||
decoder_frame_p =
|
decoder_frame_p = (a2dp_audio_scalable_decoder_frame_t *)a2dp_audio_list_node(node);
|
||||||
(a2dp_audio_scalable_decoder_frame_t *)a2dp_audio_list_node(node);
|
|
||||||
headframe_info->sequenceNumber = decoder_frame_p->sequenceNumber;
|
headframe_info->sequenceNumber = decoder_frame_p->sequenceNumber;
|
||||||
headframe_info->timestamp = decoder_frame_p->timestamp;
|
headframe_info->timestamp = decoder_frame_p->timestamp;
|
||||||
headframe_info->curSubSequenceNumber = 0;
|
headframe_info->curSubSequenceNumber = 0;
|
||||||
|
@ -620,13 +608,13 @@ static int a2dp_audio_scalable_headframe_info_get(
|
||||||
return A2DP_DECODER_NO_ERROR;
|
return A2DP_DECODER_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int a2dp_audio_scalable_info_get(void *info) {
|
static int a2dp_audio_scalable_info_get(void *info)
|
||||||
|
{
|
||||||
return A2DP_DECODER_NO_ERROR;
|
return A2DP_DECODER_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int a2dp_audio_scalable_synchronize_packet(A2DP_AUDIO_SYNCFRAME_INFO_T * sync_info, uint32_t mask)
|
||||||
a2dp_audio_scalable_synchronize_packet(A2DP_AUDIO_SYNCFRAME_INFO_T *sync_info,
|
{
|
||||||
uint32_t mask) {
|
|
||||||
int nRet = A2DP_DECODER_SYNC_ERROR;
|
int nRet = A2DP_DECODER_SYNC_ERROR;
|
||||||
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
||||||
list_node_t *node = NULL;
|
list_node_t *node = NULL;
|
||||||
|
@ -641,14 +629,10 @@ a2dp_audio_scalable_synchronize_packet(A2DP_AUDIO_SYNCFRAME_INFO_T *sync_info,
|
||||||
|
|
||||||
for (uint16_t i = 0; i < list_len; i++) {
|
for (uint16_t i = 0; i < list_len; i++) {
|
||||||
if ((node = a2dp_audio_list_begin(list)) != NULL){
|
if ((node = a2dp_audio_list_begin(list)) != NULL){
|
||||||
decoder_frame_p =
|
decoder_frame_p = (a2dp_audio_scalable_decoder_frame_t *)
|
||||||
(a2dp_audio_scalable_decoder_frame_t *)a2dp_audio_list_node(node);
|
a2dp_audio_list_node(node);
|
||||||
if (A2DP_AUDIO_SYNCFRAME_CHK(decoder_frame_p->sequenceNumber ==
|
if (A2DP_AUDIO_SYNCFRAME_CHK(decoder_frame_p->sequenceNumber == sync_info->sequenceNumber, A2DP_AUDIO_SYNCFRAME_MASK_SEQ, mask)&&
|
||||||
sync_info->sequenceNumber,
|
A2DP_AUDIO_SYNCFRAME_CHK(decoder_frame_p->timestamp == sync_info->timestamp, A2DP_AUDIO_SYNCFRAME_MASK_TIMESTAMP, mask)) {
|
||||||
A2DP_AUDIO_SYNCFRAME_MASK_SEQ, mask) &&
|
|
||||||
A2DP_AUDIO_SYNCFRAME_CHK(decoder_frame_p->timestamp ==
|
|
||||||
sync_info->timestamp,
|
|
||||||
A2DP_AUDIO_SYNCFRAME_MASK_TIMESTAMP, mask)) {
|
|
||||||
nRet = A2DP_DECODER_NO_ERROR;
|
nRet = A2DP_DECODER_NO_ERROR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -658,8 +642,8 @@ a2dp_audio_scalable_synchronize_packet(A2DP_AUDIO_SYNCFRAME_INFO_T *sync_info,
|
||||||
|
|
||||||
node = a2dp_audio_list_begin(list);
|
node = a2dp_audio_list_begin(list);
|
||||||
if (node) {
|
if (node) {
|
||||||
decoder_frame_p =
|
decoder_frame_p = (a2dp_audio_scalable_decoder_frame_t *)
|
||||||
(a2dp_audio_scalable_decoder_frame_t *)a2dp_audio_list_node(node);
|
a2dp_audio_list_node(node);
|
||||||
TRACE(4,"%s nRet:%d SEQ:%d timestamp:%d", __func__, nRet,
|
TRACE(4,"%s nRet:%d SEQ:%d timestamp:%d", __func__, nRet,
|
||||||
decoder_frame_p->sequenceNumber, decoder_frame_p->timestamp);
|
decoder_frame_p->sequenceNumber, decoder_frame_p->timestamp);
|
||||||
} else {
|
} else {
|
||||||
|
@ -669,8 +653,8 @@ a2dp_audio_scalable_synchronize_packet(A2DP_AUDIO_SYNCFRAME_INFO_T *sync_info,
|
||||||
return nRet;
|
return nRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int a2dp_audio_scalable_synchronize_dest_packet_mut(uint16_t packet_mut)
|
||||||
a2dp_audio_scalable_synchronize_dest_packet_mut(uint16_t packet_mut) {
|
{
|
||||||
list_node_t *node = NULL;
|
list_node_t *node = NULL;
|
||||||
uint32_t list_len = 0;
|
uint32_t list_len = 0;
|
||||||
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
||||||
|
@ -680,9 +664,10 @@ a2dp_audio_scalable_synchronize_dest_packet_mut(uint16_t packet_mut) {
|
||||||
if (list_len > packet_mut) {
|
if (list_len > packet_mut) {
|
||||||
do {
|
do {
|
||||||
node = a2dp_audio_list_begin(list);
|
node = a2dp_audio_list_begin(list);
|
||||||
if (node) {
|
if (node)
|
||||||
decoder_frame_p =
|
{
|
||||||
(a2dp_audio_scalable_decoder_frame_t *)a2dp_audio_list_node(node);
|
decoder_frame_p = (a2dp_audio_scalable_decoder_frame_t *)
|
||||||
|
a2dp_audio_list_node(node);
|
||||||
a2dp_audio_list_remove(list, decoder_frame_p);
|
a2dp_audio_list_remove(list, decoder_frame_p);
|
||||||
}
|
}
|
||||||
} while (a2dp_audio_list_length(list) > packet_mut);
|
} while (a2dp_audio_list_length(list) > packet_mut);
|
||||||
|
@ -693,7 +678,8 @@ a2dp_audio_scalable_synchronize_dest_packet_mut(uint16_t packet_mut) {
|
||||||
return A2DP_DECODER_NO_ERROR;
|
return A2DP_DECODER_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2dp_audio_scalable_convert_list_to_samples(uint32_t *samples) {
|
int a2dp_audio_scalable_convert_list_to_samples(uint32_t *samples)
|
||||||
|
{
|
||||||
uint32_t list_len = 0;
|
uint32_t list_len = 0;
|
||||||
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
||||||
|
|
||||||
|
@ -705,24 +691,24 @@ int a2dp_audio_scalable_convert_list_to_samples(uint32_t *samples) {
|
||||||
return A2DP_DECODER_NO_ERROR;
|
return A2DP_DECODER_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a2dp_audio_scalable_discards_samples(uint32_t samples) {
|
int a2dp_audio_scalable_discards_samples(uint32_t samples)
|
||||||
|
{
|
||||||
int nRet = A2DP_DECODER_SYNC_ERROR;
|
int nRet = A2DP_DECODER_SYNC_ERROR;
|
||||||
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
||||||
a2dp_audio_scalable_decoder_frame_t *scalable_decoder_frame = NULL;
|
a2dp_audio_scalable_decoder_frame_t *scalable_decoder_frame = NULL;
|
||||||
list_node_t *node = NULL;
|
list_node_t *node = NULL;
|
||||||
int need_remove_list = 0;
|
int need_remove_list = 0;
|
||||||
uint32_t list_samples = 0;
|
uint32_t list_samples = 0;
|
||||||
ASSERT(!(samples % SCALABLE_FRAME_SIZE), "%s samples err:%d", __func__,
|
ASSERT(!(samples%SCALABLE_FRAME_SIZE), "%s samples err:%d", __func__, samples);
|
||||||
samples);
|
|
||||||
|
|
||||||
a2dp_audio_scalable_convert_list_to_samples(&list_samples);
|
a2dp_audio_scalable_convert_list_to_samples(&list_samples);
|
||||||
if (list_samples >= samples){
|
if (list_samples >= samples){
|
||||||
need_remove_list = samples/SCALABLE_FRAME_SIZE;
|
need_remove_list = samples/SCALABLE_FRAME_SIZE;
|
||||||
for (int i=0; i<need_remove_list; i++){
|
for (int i=0; i<need_remove_list; i++){
|
||||||
node = a2dp_audio_list_begin(list);
|
node = a2dp_audio_list_begin(list);
|
||||||
if (node) {
|
if (node)
|
||||||
scalable_decoder_frame =
|
{
|
||||||
(a2dp_audio_scalable_decoder_frame_t *)a2dp_audio_list_node(node);
|
scalable_decoder_frame = (a2dp_audio_scalable_decoder_frame_t *)a2dp_audio_list_node(node);
|
||||||
a2dp_audio_list_remove(list, scalable_decoder_frame);
|
a2dp_audio_list_remove(list, scalable_decoder_frame);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -749,7 +735,5 @@ A2DP_AUDIO_DECODER_T a2dp_audio_scalable_decoder_config = {
|
||||||
a2dp_audio_scalable_free,
|
a2dp_audio_scalable_free,
|
||||||
};
|
};
|
||||||
#else
|
#else
|
||||||
A2DP_AUDIO_DECODER_T a2dp_audio_scalable_decoder_config = {
|
A2DP_AUDIO_DECODER_T a2dp_audio_scalable_decoder_config = { 0, };
|
||||||
0,
|
|
||||||
};
|
|
||||||
#endif
|
#endif
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -13,25 +13,25 @@
|
||||||
* trademark and other intellectual property rights.
|
* trademark and other intellectual property rights.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include "app_bt_trace.h"
|
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
|
#include "app_bt_trace.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
|
||||||
|
#include "cqueue.h"
|
||||||
|
#include "list.h"
|
||||||
|
#include "hal_aud.h"
|
||||||
|
#include "resources.h"
|
||||||
|
#include "app_thread.h"
|
||||||
#include "app_audio.h"
|
#include "app_audio.h"
|
||||||
#include "app_media_player.h"
|
#include "app_media_player.h"
|
||||||
#include "app_ring_merge.h"
|
#include "app_ring_merge.h"
|
||||||
#include "app_thread.h"
|
|
||||||
#include "cqueue.h"
|
|
||||||
#include "hal_aud.h"
|
|
||||||
#include "list.h"
|
|
||||||
#include "nvrecord.h"
|
#include "nvrecord.h"
|
||||||
#include "resources.h"
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include "a2dp_api.h"
|
#include "a2dp_api.h"
|
||||||
|
|
||||||
#include "app_bt_media_manager.h"
|
|
||||||
#include "btapp.h"
|
#include "btapp.h"
|
||||||
|
#include "app_bt_media_manager.h"
|
||||||
|
|
||||||
extern uint8_t __StackLimit[];
|
extern uint8_t __StackLimit[];
|
||||||
extern uint8_t __HeapLimit[];
|
extern uint8_t __HeapLimit[];
|
||||||
|
@ -41,12 +41,12 @@ static const size_t heap_size = __StackLimit - __HeapLimit - 512;
|
||||||
static bool app_audio_init = false;
|
static bool app_audio_init = false;
|
||||||
|
|
||||||
static uint32_t capture_audio_buff_size_used;
|
static uint32_t capture_audio_buff_size_used;
|
||||||
// from the bottom of the system available memory pool, size is
|
// from the bottom of the system available memory pool, size is APP_CAPTURE_AUDIO_BUFFER_SIZE
|
||||||
// APP_CAPTURE_AUDIO_BUFFER_SIZE can be overlayed with the sco used audio buffer
|
// can be overlayed with the sco used audio buffer
|
||||||
static uint8_t *capture_audio_buffer =
|
static uint8_t* capture_audio_buffer = __HeapLimit + heap_size - APP_CAPTURE_AUDIO_BUFFER_SIZE;
|
||||||
__HeapLimit + heap_size - APP_CAPTURE_AUDIO_BUFFER_SIZE;
|
|
||||||
|
|
||||||
int app_capture_audio_mempool_init(void) {
|
int app_capture_audio_mempool_init(void)
|
||||||
|
{
|
||||||
TRACE_AUD_HDL_I("[CAPMEM][INIT] size %d.", APP_CAPTURE_AUDIO_BUFFER_SIZE);
|
TRACE_AUD_HDL_I("[CAPMEM][INIT] size %d.", APP_CAPTURE_AUDIO_BUFFER_SIZE);
|
||||||
capture_audio_buff_size_used = 0;
|
capture_audio_buff_size_used = 0;
|
||||||
memset((uint8_t *)capture_audio_buffer, 0, APP_CAPTURE_AUDIO_BUFFER_SIZE);
|
memset((uint8_t *)capture_audio_buffer, 0, APP_CAPTURE_AUDIO_BUFFER_SIZE);
|
||||||
|
@ -54,11 +54,13 @@ int app_capture_audio_mempool_init(void) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t app_capture_audio_mempool_free_buff_size() {
|
uint32_t app_capture_audio_mempool_free_buff_size()
|
||||||
|
{
|
||||||
return APP_CAPTURE_AUDIO_BUFFER_SIZE - capture_audio_buff_size_used;
|
return APP_CAPTURE_AUDIO_BUFFER_SIZE - capture_audio_buff_size_used;
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_capture_audio_mempool_get_buff(uint8_t **buff, uint32_t size) {
|
int app_capture_audio_mempool_get_buff(uint8_t **buff, uint32_t size)
|
||||||
|
{
|
||||||
uint32_t buff_size_free;
|
uint32_t buff_size_free;
|
||||||
uint8_t* capture_buf_addr = (uint8_t *)capture_audio_buffer;
|
uint8_t* capture_buf_addr = (uint8_t *)capture_audio_buffer;
|
||||||
buff_size_free = app_capture_audio_mempool_free_buff_size();
|
buff_size_free = app_capture_audio_mempool_free_buff_size();
|
||||||
|
@ -67,18 +69,15 @@ int app_capture_audio_mempool_get_buff(uint8_t **buff, uint32_t size) {
|
||||||
size = size + (4 - size % 4);
|
size = size + (4 - size % 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
TRACE_AUD_HDL_I("[CAPMEM][GET] current free %d to allocate %d",
|
TRACE_AUD_HDL_I("[CAPMEM][GET] current free %d to allocate %d", buff_size_free, size);
|
||||||
buff_size_free, size);
|
|
||||||
|
|
||||||
ASSERT(size <= buff_size_free, "[%s] size = %d > free size = %d", __func__,
|
ASSERT(size <= buff_size_free, "[%s] size = %d > free size = %d", __func__, size, buff_size_free);
|
||||||
size, buff_size_free);
|
|
||||||
|
|
||||||
*buff = capture_buf_addr + capture_audio_buff_size_used;
|
*buff = capture_buf_addr + capture_audio_buff_size_used;
|
||||||
|
|
||||||
capture_audio_buff_size_used += size;
|
capture_audio_buff_size_used += size;
|
||||||
TRACE_AUD_HDL_I("[CAPMEM][GET] %d, now used %d left %d", size,
|
TRACE_AUD_HDL_I("[CAPMEM][GET] %d, now used %d left %d",
|
||||||
capture_audio_buff_size_used,
|
size, capture_audio_buff_size_used, app_capture_audio_mempool_free_buff_size());
|
||||||
app_capture_audio_mempool_free_buff_size());
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -101,48 +100,60 @@ typedef struct {
|
||||||
list_t *audio_list;
|
list_t *audio_list;
|
||||||
}APP_AUDIO_CONFIG;
|
}APP_AUDIO_CONFIG;
|
||||||
|
|
||||||
APP_AUDIO_CONFIG app_audio_conifg = {.audio_list = NULL};
|
APP_AUDIO_CONFIG app_audio_conifg = {
|
||||||
|
.audio_list = NULL
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void LOCK_APP_AUDIO_QUEUE() {
|
void LOCK_APP_AUDIO_QUEUE()
|
||||||
|
{
|
||||||
osMutexWait(g_app_audio_queue_mutex_id, osWaitForever);
|
osMutexWait(g_app_audio_queue_mutex_id, osWaitForever);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UNLOCK_APP_AUDIO_QUEUE() { osMutexRelease(g_app_audio_queue_mutex_id); }
|
void UNLOCK_APP_AUDIO_QUEUE()
|
||||||
|
{
|
||||||
|
osMutexRelease(g_app_audio_queue_mutex_id);
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t app_audio_lr_balance(uint8_t *buf, uint32_t len, int8_t balance) {
|
uint32_t app_audio_lr_balance(uint8_t *buf, uint32_t len, int8_t balance)
|
||||||
|
{
|
||||||
short *balance_buf=(short *)buf;
|
short *balance_buf=(short *)buf;
|
||||||
uint32_t balance_len = len/2;
|
uint32_t balance_len = len/2;
|
||||||
float factor;
|
float factor;
|
||||||
|
|
||||||
ASSERT((balance >= -100) && (balance <= 100), "balance = %d is invalid!",
|
ASSERT((balance >= -100) && (balance <= 100), "balance = %d is invalid!", balance);
|
||||||
balance);
|
|
||||||
|
|
||||||
if (balance > 0) {
|
if(balance > 0)
|
||||||
|
{
|
||||||
//reduce L channel
|
//reduce L channel
|
||||||
factor = 1 - 0.01 * balance;
|
factor = 1 - 0.01 * balance;
|
||||||
for (uint32_t i = 0; i < balance_len; i += 2) {
|
for(uint32_t i=0; i<balance_len;i+=2)
|
||||||
|
{
|
||||||
balance_buf[i] = (short) (factor * balance_buf[i]);
|
balance_buf[i] = (short) (factor * balance_buf[i]);
|
||||||
}
|
}
|
||||||
} else if (balance < 0) {
|
}
|
||||||
|
else if(balance < 0)
|
||||||
|
{
|
||||||
//reduce R channel
|
//reduce R channel
|
||||||
factor = 1 + 0.01 * balance;
|
factor = 1 + 0.01 * balance;
|
||||||
for (uint32_t i = 0; i < balance_len; i += 2) {
|
for(uint32_t i=0; i<balance_len;i+=2)
|
||||||
|
{
|
||||||
balance_buf[i+1] = (short) (factor * balance_buf[i+1]);
|
balance_buf[i+1] = (short) (factor * balance_buf[i+1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void app_audio_mempool_init_with_specific_size(uint32_t size) {
|
void app_audio_mempool_init_with_specific_size(uint32_t size)
|
||||||
|
{
|
||||||
syspool_init_specific_size(size);
|
syspool_init_specific_size(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_audio_pcmbuff_init(uint8_t *buff, uint16_t len) {
|
int app_audio_pcmbuff_init(uint8_t *buff, uint16_t len)
|
||||||
|
{
|
||||||
if (app_audio_pcmbuff_mutex_id == NULL)
|
if (app_audio_pcmbuff_mutex_id == NULL)
|
||||||
app_audio_pcmbuff_mutex_id =
|
app_audio_pcmbuff_mutex_id = osMutexCreate((osMutex(app_audio_pcmbuff_mutex)));
|
||||||
osMutexCreate((osMutex(app_audio_pcmbuff_mutex)));
|
|
||||||
|
|
||||||
if ((buff == NULL)||(app_audio_pcmbuff_mutex_id == NULL))
|
if ((buff == NULL)||(app_audio_pcmbuff_mutex_id == NULL))
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -155,7 +166,8 @@ int app_audio_pcmbuff_init(uint8_t *buff, uint16_t len) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_audio_pcmbuff_length(void) {
|
int app_audio_pcmbuff_length(void)
|
||||||
|
{
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
osMutexWait(app_audio_pcmbuff_mutex_id, osWaitForever);
|
osMutexWait(app_audio_pcmbuff_mutex_id, osWaitForever);
|
||||||
|
@ -165,7 +177,8 @@ int app_audio_pcmbuff_length(void) {
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_audio_pcmbuff_put(uint8_t *buff, uint16_t len) {
|
int app_audio_pcmbuff_put(uint8_t *buff, uint16_t len)
|
||||||
|
{
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
osMutexWait(app_audio_pcmbuff_mutex_id, osWaitForever);
|
osMutexWait(app_audio_pcmbuff_mutex_id, osWaitForever);
|
||||||
|
@ -175,7 +188,8 @@ int app_audio_pcmbuff_put(uint8_t *buff, uint16_t len) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_audio_pcmbuff_get(uint8_t *buff, uint16_t len) {
|
int app_audio_pcmbuff_get(uint8_t *buff, uint16_t len)
|
||||||
|
{
|
||||||
unsigned char *e1 = NULL, *e2 = NULL;
|
unsigned char *e1 = NULL, *e2 = NULL;
|
||||||
unsigned int len1 = 0, len2 = 0;
|
unsigned int len1 = 0, len2 = 0;
|
||||||
int status;
|
int status;
|
||||||
|
@ -196,7 +210,8 @@ int app_audio_pcmbuff_get(uint8_t *buff, uint16_t len) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_audio_pcmbuff_discard(uint16_t len) {
|
int app_audio_pcmbuff_discard(uint16_t len)
|
||||||
|
{
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
osMutexWait(app_audio_pcmbuff_mutex_id, osWaitForever);
|
osMutexWait(app_audio_pcmbuff_mutex_id, osWaitForever);
|
||||||
|
@ -206,25 +221,27 @@ int app_audio_pcmbuff_discard(uint16_t len) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
void __attribute__((section(".fast_text_sram")))
|
void __attribute__((section(".fast_text_sram"))) app_audio_memcpy_16bit(int16_t *des, int16_t *src, int len)
|
||||||
app_audio_memcpy_16bit(int16_t *des, int16_t *src, int len) {
|
{
|
||||||
// Check input
|
// Check input
|
||||||
for (int i = 0; i < len; i++) {
|
for(int i=0; i<len; i++)
|
||||||
|
{
|
||||||
des[i] = src[i];
|
des[i] = src[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void __attribute__((section(".fast_text_sram")))
|
void __attribute__((section(".fast_text_sram"))) app_audio_memset_16bit(int16_t *des, int16_t val, int len)
|
||||||
app_audio_memset_16bit(int16_t *des, int16_t val, int len) {
|
{
|
||||||
// Check input
|
// Check input
|
||||||
for (int i = 0; i < len; i++) {
|
for(int i=0; i<len; i++)
|
||||||
|
{
|
||||||
des[i] = val;
|
des[i] = val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __AUDIO_QUEUE_SUPPORT__
|
#ifdef __AUDIO_QUEUE_SUPPORT__
|
||||||
int app_audio_sendrequest_param(uint16_t id, uint8_t status, uint32_t ptr,
|
int app_audio_sendrequest_param(uint16_t id, uint8_t status, uint32_t ptr, uint32_t param)
|
||||||
uint32_t param) {
|
{
|
||||||
uint32_t audevt;
|
uint32_t audevt;
|
||||||
APP_MESSAGE_BLOCK msg;
|
APP_MESSAGE_BLOCK msg;
|
||||||
|
|
||||||
|
@ -241,20 +258,23 @@ int app_audio_sendrequest_param(uint16_t id, uint8_t status, uint32_t ptr,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_audio_sendrequest(uint16_t id, uint8_t status, uint32_t ptr) {
|
int app_audio_sendrequest(uint16_t id, uint8_t status, uint32_t ptr)
|
||||||
|
{
|
||||||
return app_audio_sendrequest_param(id, status, ptr, 0);
|
return app_audio_sendrequest_param(id, status, ptr, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern bool app_audio_list_playback_exist(void);
|
extern bool app_audio_list_playback_exist(void);
|
||||||
#ifdef MEDIA_PLAYER_SUPPORT
|
#ifdef MEDIA_PLAYER_SUPPORT
|
||||||
static uint8_t app_audio_get_list_playback_num(void) {
|
static uint8_t app_audio_get_list_playback_num(void)
|
||||||
|
{
|
||||||
APP_AUDIO_STATUS *audio_handle = NULL;
|
APP_AUDIO_STATUS *audio_handle = NULL;
|
||||||
list_node_t *node = NULL;
|
list_node_t *node = NULL;
|
||||||
uint8_t num=0;
|
uint8_t num=0;
|
||||||
for (node = list_begin(app_audio_conifg.audio_list);
|
for (node = list_begin(app_audio_conifg.audio_list); node != list_end(app_audio_conifg.audio_list); node = list_next(node))
|
||||||
node != list_end(app_audio_conifg.audio_list); node = list_next(node)) {
|
{
|
||||||
audio_handle = (APP_AUDIO_STATUS *)list_node(node);
|
audio_handle = (APP_AUDIO_STATUS *)list_node(node);
|
||||||
if (audio_handle == NULL) {
|
if(audio_handle == NULL)
|
||||||
|
{
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
if (audio_handle->id == APP_PLAY_BACK_AUDIO)
|
if (audio_handle->id == APP_PLAY_BACK_AUDIO)
|
||||||
|
@ -266,7 +286,8 @@ static uint8_t app_audio_get_list_playback_num(void) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static bool need_flush_flash_switch_audio = false;
|
static bool need_flush_flash_switch_audio = false;
|
||||||
void app_audio_switch_flash_flush_req(void) {
|
void app_audio_switch_flash_flush_req(void)
|
||||||
|
{
|
||||||
uint32_t lock;
|
uint32_t lock;
|
||||||
|
|
||||||
lock = int_lock();
|
lock = int_lock();
|
||||||
|
@ -274,7 +295,8 @@ void app_audio_switch_flash_flush_req(void) {
|
||||||
int_unlock(lock);
|
int_unlock(lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void app_audio_switch_flash_proc(void) {
|
static void app_audio_switch_flash_proc(void)
|
||||||
|
{
|
||||||
// no need to do this across the audio switch,
|
// no need to do this across the audio switch,
|
||||||
// will use suspend flash erase to assure that no audio
|
// will use suspend flash erase to assure that no audio
|
||||||
// irq is missing for handling caused by long time global irq disabling
|
// irq is missing for handling caused by long time global irq disabling
|
||||||
|
@ -293,25 +315,31 @@ static void app_audio_switch_flash_proc(void) {
|
||||||
int_unlock(lock);
|
int_unlock(lock);
|
||||||
|
|
||||||
if (need_flush_flash){
|
if (need_flush_flash){
|
||||||
|
#ifndef FPGA
|
||||||
nv_record_flash_flush();
|
nv_record_flash_flush();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef VOICE_DATAPATH
|
#ifdef VOICE_DATAPATH
|
||||||
static bool app_audio_handle_pre_processing(APP_MESSAGE_BODY *msg_body) {
|
static bool app_audio_handle_pre_processing(APP_MESSAGE_BODY *msg_body)
|
||||||
|
{
|
||||||
uint16_t stream_type;
|
uint16_t stream_type;
|
||||||
APP_AUDIO_GET_AUD_ID(msg_body->message_ptr, stream_type);
|
APP_AUDIO_GET_AUD_ID(msg_body->message_ptr, stream_type);
|
||||||
|
|
||||||
bool isToResetCaptureStream = false;
|
bool isToResetCaptureStream = false;
|
||||||
if ((BT_STREAM_SBC == stream_type) || (BT_STREAM_MEDIA == stream_type)) {
|
if ((BT_STREAM_SBC == stream_type) || (BT_STREAM_MEDIA == stream_type))
|
||||||
if (app_audio_manager_capture_is_active()) {
|
{
|
||||||
|
if (app_audio_manager_capture_is_active())
|
||||||
|
{
|
||||||
isToResetCaptureStream = true;
|
isToResetCaptureStream = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isToResetCaptureStream) {
|
if (isToResetCaptureStream)
|
||||||
app_audio_manager_sendrequest(APP_BT_STREAM_MANAGER_STOP, BT_STREAM_CAPTURE,
|
{
|
||||||
0, 0);
|
app_audio_manager_sendrequest(APP_BT_STREAM_MANAGER_STOP,
|
||||||
|
BT_STREAM_CAPTURE, 0, 0);
|
||||||
|
|
||||||
APP_MESSAGE_BLOCK msg;
|
APP_MESSAGE_BLOCK msg;
|
||||||
msg.msg_body = *msg_body;
|
msg.msg_body = *msg_body;
|
||||||
|
@ -321,13 +349,16 @@ static bool app_audio_handle_pre_processing(APP_MESSAGE_BODY *msg_body) {
|
||||||
BT_STREAM_CAPTURE, 0, 0);
|
BT_STREAM_CAPTURE, 0, 0);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int app_audio_handle_process(APP_MESSAGE_BODY *msg_body) {
|
static int app_audio_handle_process(APP_MESSAGE_BODY *msg_body)
|
||||||
|
{
|
||||||
int nRet = -1;
|
int nRet = -1;
|
||||||
|
|
||||||
APP_AUDIO_STATUS aud_status;
|
APP_AUDIO_STATUS aud_status;
|
||||||
|
@ -337,7 +368,8 @@ static int app_audio_handle_process(APP_MESSAGE_BODY *msg_body) {
|
||||||
|
|
||||||
#ifdef VOICE_DATAPATH
|
#ifdef VOICE_DATAPATH
|
||||||
bool isContinue = app_audio_handle_pre_processing(msg_body);
|
bool isContinue = app_audio_handle_pre_processing(msg_body);
|
||||||
if (!isContinue) {
|
if (!isContinue)
|
||||||
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -347,16 +379,23 @@ static int app_audio_handle_process(APP_MESSAGE_BODY *msg_body) {
|
||||||
APP_AUDIO_GET_AUD_ID(msg_body->message_ptr, aud_status.aud_id);
|
APP_AUDIO_GET_AUD_ID(msg_body->message_ptr, aud_status.aud_id);
|
||||||
APP_AUDIO_GET_FREQ(msg_body->message_Param0, aud_status.freq);
|
APP_AUDIO_GET_FREQ(msg_body->message_Param0, aud_status.freq);
|
||||||
|
|
||||||
switch (aud_status.status) {
|
switch (aud_status.status)
|
||||||
|
{
|
||||||
case APP_BT_SETTING_OPEN:
|
case APP_BT_SETTING_OPEN:
|
||||||
#ifdef __AUDIO_QUEUE_SUPPORT__
|
#ifdef __AUDIO_QUEUE_SUPPORT__
|
||||||
TRACE_AUD_HDL_I("[OPEN] before status_id: 0x%x%s, aud_id: %d, len = %d",
|
TRACE_AUD_HDL_I(
|
||||||
aud_status.id, player2str(aud_status.id), aud_status.aud_id,
|
"[OPEN] before status_id: 0x%x%s, aud_id: %d, len = %d",
|
||||||
|
aud_status.id,
|
||||||
|
player2str(aud_status.id),
|
||||||
|
aud_status.aud_id,
|
||||||
list_length(app_audio_conifg.audio_list));
|
list_length(app_audio_conifg.audio_list));
|
||||||
|
|
||||||
if (app_audio_list_append(&aud_status)) {
|
if (app_audio_list_append(&aud_status))
|
||||||
|
{
|
||||||
app_bt_stream_open(&aud_status);
|
app_bt_stream_open(&aud_status);
|
||||||
TRACE_AUD_HDL_I("[OPEN] after status_id: 0x%x%s, len = %d", aud_status.id,
|
TRACE_AUD_HDL_I(
|
||||||
|
"[OPEN] after status_id: 0x%x%s, len = %d",
|
||||||
|
aud_status.id,
|
||||||
player2str(aud_status.id),
|
player2str(aud_status.id),
|
||||||
list_length(app_audio_conifg.audio_list));
|
list_length(app_audio_conifg.audio_list));
|
||||||
}
|
}
|
||||||
|
@ -369,23 +408,30 @@ static int app_audio_handle_process(APP_MESSAGE_BODY *msg_body) {
|
||||||
app_audio_switch_flash_proc();
|
app_audio_switch_flash_proc();
|
||||||
#ifdef __AUDIO_QUEUE_SUPPORT__
|
#ifdef __AUDIO_QUEUE_SUPPORT__
|
||||||
APP_AUDIO_STATUS next_status;
|
APP_AUDIO_STATUS next_status;
|
||||||
TRACE_AUD_HDL_I("[CLOSE] current id: 0x%x%s", aud_status.id,
|
TRACE_AUD_HDL_I(
|
||||||
|
"[CLOSE] current id: 0x%x%s",
|
||||||
|
aud_status.id,
|
||||||
player2str(aud_status.id));
|
player2str(aud_status.id));
|
||||||
app_bt_stream_close(aud_status.id);
|
app_bt_stream_close(aud_status.id);
|
||||||
app_audio_switch_flash_proc();
|
app_audio_switch_flash_proc();
|
||||||
#ifdef MEDIA_PLAYER_SUPPORT
|
#ifdef MEDIA_PLAYER_SUPPORT
|
||||||
if (aud_status.id == APP_PLAY_BACK_AUDIO) {
|
if (aud_status.id == APP_PLAY_BACK_AUDIO)
|
||||||
|
{
|
||||||
TRACE_AUD_HDL_I("[CLOSE] list: %d", app_audio_get_list_playback_num());
|
TRACE_AUD_HDL_I("[CLOSE] list: %d", app_audio_get_list_playback_num());
|
||||||
if (app_audio_get_list_playback_num() == 1) {
|
if (app_audio_get_list_playback_num() == 1)
|
||||||
|
{
|
||||||
TRACE_AUD_HDL_I("=======>APP_BT_SETTING_CLOSE MEDIA");
|
TRACE_AUD_HDL_I("=======>APP_BT_SETTING_CLOSE MEDIA");
|
||||||
bt_media_stop(BT_STREAM_MEDIA, BT_DEVICE_ID_1);
|
bt_media_stop(BT_STREAM_MEDIA, BT_DEVICE_ID_1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (app_audio_list_rmv_callback(&aud_status, &next_status,
|
if (app_audio_list_rmv_callback(&aud_status, &next_status, APP_BT_SETTING_Q_POS_HEAD, false))
|
||||||
APP_BT_SETTING_Q_POS_HEAD, false)) {
|
{
|
||||||
TRACE_AUD_HDL_I("[CLOSE] %p, next id: 0x%x%s, status %d", &next_status,
|
TRACE_AUD_HDL_I(
|
||||||
next_status.id, player2str(next_status.id),
|
"[CLOSE] %p, next id: 0x%x%s, status %d",
|
||||||
|
&next_status,
|
||||||
|
next_status.id,
|
||||||
|
player2str(next_status.id),
|
||||||
next_status.status);
|
next_status.status);
|
||||||
app_bt_stream_open(&next_status);
|
app_bt_stream_open(&next_status);
|
||||||
}
|
}
|
||||||
|
@ -415,33 +461,37 @@ static int app_audio_handle_process(APP_MESSAGE_BODY *msg_body) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __AUDIO_QUEUE_SUPPORT__
|
#ifdef __AUDIO_QUEUE_SUPPORT__
|
||||||
static void app_audio_handle_free(void *data) {
|
static void app_audio_handle_free(void* data)
|
||||||
|
{
|
||||||
#ifdef MEDIA_PLAYER_SUPPORT
|
#ifdef MEDIA_PLAYER_SUPPORT
|
||||||
APP_AUDIO_STATUS * status = (APP_AUDIO_STATUS * )data;
|
APP_AUDIO_STATUS * status = (APP_AUDIO_STATUS * )data;
|
||||||
|
|
||||||
if (status->id == APP_PLAY_BACK_AUDIO) {
|
if(status->id == APP_PLAY_BACK_AUDIO)
|
||||||
TRACE_AUD_HDL_I("[HANDLE_FREE] , aud_id: 0x%x, type = 0x%x", status->aud_id,
|
{
|
||||||
status->aud_type);
|
TRACE_AUD_HDL_I("[HANDLE_FREE] , aud_id: 0x%x, type = 0x%x", status->aud_id, status->aud_type);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
osPoolFree (app_audio_status_mempool, data);
|
osPoolFree (app_audio_status_mempool, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void app_audio_list_create() {
|
void app_audio_list_create()
|
||||||
if (app_audio_conifg.audio_list == NULL) {
|
{
|
||||||
|
if (app_audio_conifg.audio_list == NULL)
|
||||||
|
{
|
||||||
app_audio_conifg.audio_list = list_new(app_audio_handle_free, NULL, NULL);
|
app_audio_conifg.audio_list = list_new(app_audio_handle_free, NULL, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool app_audio_list_stream_exist() {
|
bool app_audio_list_stream_exist()
|
||||||
|
{
|
||||||
APP_AUDIO_STATUS *audio_handle = NULL;
|
APP_AUDIO_STATUS *audio_handle = NULL;
|
||||||
list_node_t *node = NULL;
|
list_node_t *node = NULL;
|
||||||
|
|
||||||
for (node = list_begin(app_audio_conifg.audio_list);
|
for (node = list_begin(app_audio_conifg.audio_list); node != list_end(app_audio_conifg.audio_list); node = list_next(node)) {
|
||||||
node != list_end(app_audio_conifg.audio_list); node = list_next(node)) {
|
|
||||||
|
|
||||||
audio_handle = (APP_AUDIO_STATUS *)list_node(node);
|
audio_handle = (APP_AUDIO_STATUS *)list_node(node);
|
||||||
if (audio_handle == NULL) {
|
if(audio_handle == NULL)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (audio_handle->id == APP_BT_STREAM_HFP_PCM ||
|
if (audio_handle->id == APP_BT_STREAM_HFP_PCM ||
|
||||||
|
@ -458,7 +508,8 @@ bool app_audio_list_stream_exist() {
|
||||||
#ifdef __THIRDPARTY
|
#ifdef __THIRDPARTY
|
||||||
audio_handle->id == APP_BT_STREAM_THIRDPARTY_VOICE ||
|
audio_handle->id == APP_BT_STREAM_THIRDPARTY_VOICE ||
|
||||||
#endif
|
#endif
|
||||||
audio_handle->id == APP_BT_STREAM_A2DP_VENDOR) {
|
audio_handle->id == APP_BT_STREAM_A2DP_VENDOR
|
||||||
|
) {
|
||||||
TRACE_AUD_HDL_I("[STREAM_LIST][EXIST] id 0x%x", audio_handle->id);
|
TRACE_AUD_HDL_I("[STREAM_LIST][EXIST] id 0x%x", audio_handle->id);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -467,7 +518,8 @@ bool app_audio_list_stream_exist() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool app_audio_list_filter_exist(APP_AUDIO_STATUS *aud_status) {
|
bool app_audio_list_filter_exist(APP_AUDIO_STATUS* aud_status)
|
||||||
|
{
|
||||||
#ifdef MEDIA_PLAYER_SUPPORT
|
#ifdef MEDIA_PLAYER_SUPPORT
|
||||||
APP_AUDIO_STATUS *audio_handle = NULL;
|
APP_AUDIO_STATUS *audio_handle = NULL;
|
||||||
list_node_t *node = NULL;
|
list_node_t *node = NULL;
|
||||||
|
@ -475,23 +527,19 @@ bool app_audio_list_filter_exist(APP_AUDIO_STATUS *aud_status) {
|
||||||
|
|
||||||
if (aud_status->id == APP_PLAY_BACK_AUDIO){
|
if (aud_status->id == APP_PLAY_BACK_AUDIO){
|
||||||
if(aud_status->aud_id == AUD_ID_BT_CALL_INCOMING_CALL) {
|
if(aud_status->aud_id == AUD_ID_BT_CALL_INCOMING_CALL) {
|
||||||
for (node = list_begin(app_audio_conifg.audio_list);
|
for (node = list_begin(app_audio_conifg.audio_list); node != list_end(app_audio_conifg.audio_list); node = list_next(node)) {
|
||||||
node != list_end(app_audio_conifg.audio_list);
|
|
||||||
node = list_next(node)) {
|
|
||||||
audio_handle = (APP_AUDIO_STATUS *)list_node(node);
|
audio_handle = (APP_AUDIO_STATUS *)list_node(node);
|
||||||
if (audio_handle == NULL) {
|
if(audio_handle == NULL)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (audio_handle->id == APP_PLAY_BACK_AUDIO &&
|
if (audio_handle->id == APP_PLAY_BACK_AUDIO && audio_handle->aud_id == AUD_ID_BT_CALL_INCOMING_CALL) {
|
||||||
audio_handle->aud_id == AUD_ID_BT_CALL_INCOMING_CALL) {
|
|
||||||
TRACE_AUD_HDL_I("[STREAM_LIST][FILTER] id 0x%x", audio_handle->id);
|
TRACE_AUD_HDL_I("[STREAM_LIST][FILTER] id 0x%x", audio_handle->id);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (node = list_begin(app_audio_conifg.audio_list);
|
for (node = list_begin(app_audio_conifg.audio_list); node != list_end(app_audio_conifg.audio_list); node = list_next(node)) {
|
||||||
node != list_end(app_audio_conifg.audio_list);
|
|
||||||
node = list_next(node)) {
|
|
||||||
audio_handle = (APP_AUDIO_STATUS *)list_node(node);
|
audio_handle = (APP_AUDIO_STATUS *)list_node(node);
|
||||||
if (cnt++ > 1) {
|
if (cnt++ > 1) {
|
||||||
TRACE_AUD_HDL_I("[STREAM_LIST][FILTER] cnt %d", cnt);
|
TRACE_AUD_HDL_I("[STREAM_LIST][FILTER] cnt %d", cnt);
|
||||||
|
@ -504,15 +552,16 @@ bool app_audio_list_filter_exist(APP_AUDIO_STATUS *aud_status) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool app_audio_list_playback_exist(void) {
|
bool app_audio_list_playback_exist(void)
|
||||||
|
{
|
||||||
#ifdef MEDIA_PLAYER_SUPPORT
|
#ifdef MEDIA_PLAYER_SUPPORT
|
||||||
APP_AUDIO_STATUS *audio_handle = NULL;
|
APP_AUDIO_STATUS *audio_handle = NULL;
|
||||||
list_node_t *node = NULL;
|
list_node_t *node = NULL;
|
||||||
|
|
||||||
for (node = list_begin(app_audio_conifg.audio_list);
|
for (node = list_begin(app_audio_conifg.audio_list); node != list_end(app_audio_conifg.audio_list); node = list_next(node)) {
|
||||||
node != list_end(app_audio_conifg.audio_list); node = list_next(node)) {
|
|
||||||
audio_handle = (APP_AUDIO_STATUS *)list_node(node);
|
audio_handle = (APP_AUDIO_STATUS *)list_node(node);
|
||||||
if (audio_handle == NULL) {
|
if(audio_handle == NULL)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (audio_handle->id == APP_PLAY_BACK_AUDIO) {
|
if (audio_handle->id == APP_PLAY_BACK_AUDIO) {
|
||||||
|
@ -524,15 +573,16 @@ bool app_audio_list_playback_exist(void) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void app_audio_list_playback_clear(void) {
|
void app_audio_list_playback_clear(void)
|
||||||
|
{
|
||||||
#ifdef MEDIA_PLAYER_SUPPORT
|
#ifdef MEDIA_PLAYER_SUPPORT
|
||||||
APP_AUDIO_STATUS *audio_handle = NULL;
|
APP_AUDIO_STATUS *audio_handle = NULL;
|
||||||
list_node_t *node = NULL;
|
list_node_t *node = NULL;
|
||||||
|
|
||||||
for (node = list_begin(app_audio_conifg.audio_list);
|
for (node = list_begin(app_audio_conifg.audio_list); node != list_end(app_audio_conifg.audio_list); node = list_next(node)) {
|
||||||
node != list_end(app_audio_conifg.audio_list); node = list_next(node)) {
|
|
||||||
audio_handle = (APP_AUDIO_STATUS *)list_node(node);
|
audio_handle = (APP_AUDIO_STATUS *)list_node(node);
|
||||||
if (audio_handle == NULL) {
|
if(audio_handle == NULL)
|
||||||
|
{
|
||||||
TRACE_AUD_HDL_I("[STREAM_LIST][CLR] find null\n ");
|
TRACE_AUD_HDL_I("[STREAM_LIST][CLR] find null\n ");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -543,162 +593,182 @@ void app_audio_list_playback_clear(void) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool app_audio_list_append(APP_AUDIO_STATUS *aud_status) {
|
bool app_audio_list_append(APP_AUDIO_STATUS* aud_status)
|
||||||
|
{
|
||||||
APP_AUDIO_STATUS *data_to_append = NULL;
|
APP_AUDIO_STATUS *data_to_append = NULL;
|
||||||
bool add_data_to_head_of_list = false;
|
bool add_data_to_head_of_list = false;
|
||||||
bool ret = true;
|
bool ret = true;
|
||||||
TRACE_AUD_HDL_I("[STREAM_LIST][APPEND] id 0x%x%s", aud_status->id,
|
TRACE_AUD_HDL_I("[STREAM_LIST][APPEND] id 0x%x%s", aud_status->id, player2str(aud_status->id));
|
||||||
player2str(aud_status->id));
|
|
||||||
#ifdef MEDIA_PLAYER_SUPPORT
|
#ifdef MEDIA_PLAYER_SUPPORT
|
||||||
if (aud_status->id == APP_PLAY_BACK_AUDIO) {
|
if (aud_status->id == APP_PLAY_BACK_AUDIO)
|
||||||
|
{
|
||||||
//ignore redundant ring ind from hfp...
|
//ignore redundant ring ind from hfp...
|
||||||
if (app_audio_list_filter_exist(aud_status)) {
|
if (app_audio_list_filter_exist(aud_status))
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (app_audio_list_playback_exist()) {
|
if (app_audio_list_playback_exist())
|
||||||
if (list_length(app_audio_conifg.audio_list) >= MAX_AUDIO_BUF_LIST) {
|
{
|
||||||
if (app_audio_list_stream_exist()) {
|
if (list_length(app_audio_conifg.audio_list) >= MAX_AUDIO_BUF_LIST)
|
||||||
data_to_append =
|
{
|
||||||
(APP_AUDIO_STATUS *)osPoolCAlloc(app_audio_status_mempool);
|
if (app_audio_list_stream_exist())
|
||||||
if (data_to_append == NULL) {
|
{
|
||||||
|
data_to_append = (APP_AUDIO_STATUS *)osPoolCAlloc (app_audio_status_mempool);
|
||||||
|
if(data_to_append == NULL)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
memcpy(data_to_append,
|
memcpy(data_to_append, (const void *)list_front(app_audio_conifg.audio_list), sizeof(APP_AUDIO_STATUS));
|
||||||
(const void *)list_front(app_audio_conifg.audio_list),
|
|
||||||
sizeof(APP_AUDIO_STATUS));
|
|
||||||
add_data_to_head_of_list = true;
|
add_data_to_head_of_list = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
app_audio_list_clear();
|
app_audio_list_clear();
|
||||||
TRACE_AUD_HDL_E("[STREAM_LIST][APPEND] FIXME!!!!\n ");
|
TRACE_AUD_HDL_E("[STREAM_LIST][APPEND] FIXME!!!!\n ");
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
ret = false;
|
ret = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
add_data_to_head_of_list = true;
|
add_data_to_head_of_list = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data_to_append == NULL) {
|
if (data_to_append == NULL)
|
||||||
|
{
|
||||||
data_to_append = (APP_AUDIO_STATUS *)osPoolCAlloc (app_audio_status_mempool);
|
data_to_append = (APP_AUDIO_STATUS *)osPoolCAlloc (app_audio_status_mempool);
|
||||||
if (data_to_append == NULL) {
|
if(data_to_append == NULL)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
memcpy(data_to_append, aud_status, sizeof(APP_AUDIO_STATUS));
|
memcpy(data_to_append, aud_status, sizeof(APP_AUDIO_STATUS));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (add_data_to_head_of_list) {
|
if (add_data_to_head_of_list)
|
||||||
|
{
|
||||||
list_prepend(app_audio_conifg.audio_list, (void*)data_to_append);
|
list_prepend(app_audio_conifg.audio_list, (void*)data_to_append);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
list_append(app_audio_conifg.audio_list, (void*)data_to_append);
|
list_append(app_audio_conifg.audio_list, (void*)data_to_append);
|
||||||
}
|
}
|
||||||
|
|
||||||
TRACE_AUD_HDL_I("[STREAM_LIST][APPEND] id 0x%x%s status %d len %d ret %d",
|
TRACE_AUD_HDL_I("[STREAM_LIST][APPEND] id 0x%x%s status %d len %d ret %d", data_to_append->id, player2str(data_to_append->id), \
|
||||||
data_to_append->id, player2str(data_to_append->id),
|
data_to_append->status, list_length(app_audio_conifg.audio_list), ret);
|
||||||
data_to_append->status,
|
|
||||||
list_length(app_audio_conifg.audio_list), ret);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool app_audio_list_rmv_callback(APP_AUDIO_STATUS *status_close,
|
bool app_audio_list_rmv_callback(APP_AUDIO_STATUS *status_close, APP_AUDIO_STATUS *status_next, enum APP_BT_AUDIO_Q_POS pos, bool pop_next)
|
||||||
APP_AUDIO_STATUS *status_next,
|
{
|
||||||
enum APP_BT_AUDIO_Q_POS pos, bool pop_next) {
|
|
||||||
void *data_to_remove = NULL;
|
void *data_to_remove = NULL;
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
|
||||||
// for status: first bt_a2dp->APP_BT_SETTING_CLOSE,then ring->
|
//for status: first bt_a2dp->APP_BT_SETTING_CLOSE,then ring-> APP_BT_SETTING_CLOSE
|
||||||
// APP_BT_SETTING_CLOSE
|
TRACE_AUD_HDL_I("[STREAM_LIST][RMV] audio list len %d close_id 0x%x%s", list_length(app_audio_conifg.audio_list), \
|
||||||
TRACE_AUD_HDL_I("[STREAM_LIST][RMV] audio list len %d close_id 0x%x%s",
|
status_close->id, player2str(status_close->id));
|
||||||
list_length(app_audio_conifg.audio_list), status_close->id,
|
if(list_length(app_audio_conifg.audio_list) == 0)
|
||||||
player2str(status_close->id));
|
{
|
||||||
if (list_length(app_audio_conifg.audio_list) == 0) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MEDIA_PLAYER_SUPPORT
|
#ifdef MEDIA_PLAYER_SUPPORT
|
||||||
APP_AUDIO_STATUS *audio_handle = NULL;
|
APP_AUDIO_STATUS *audio_handle = NULL;
|
||||||
list_node_t *node = NULL;
|
list_node_t *node = NULL;
|
||||||
if (status_close->id == APP_PLAY_BACK_AUDIO) {
|
if (status_close->id == APP_PLAY_BACK_AUDIO)
|
||||||
for (node = list_begin(app_audio_conifg.audio_list);
|
{
|
||||||
node != list_end(app_audio_conifg.audio_list);
|
for (node = list_begin(app_audio_conifg.audio_list); node != list_end(app_audio_conifg.audio_list); node = list_next(node))
|
||||||
node = list_next(node)) {
|
{
|
||||||
audio_handle = (APP_AUDIO_STATUS *)list_node(node);
|
audio_handle = (APP_AUDIO_STATUS *)list_node(node);
|
||||||
if (audio_handle == NULL) {
|
if(audio_handle == NULL)
|
||||||
|
{
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
if (audio_handle->id == APP_PLAY_BACK_AUDIO) {
|
if (audio_handle->id == APP_PLAY_BACK_AUDIO)
|
||||||
|
{
|
||||||
list_node_t *nod_next = list_next(node);
|
list_node_t *nod_next = list_next(node);
|
||||||
data_to_remove = list_node(node);
|
data_to_remove = list_node(node);
|
||||||
|
|
||||||
if (pop_next) {
|
if (pop_next)
|
||||||
|
{
|
||||||
memcpy(status_next, list_node(node), sizeof(APP_AUDIO_STATUS));
|
memcpy(status_next, list_node(node), sizeof(APP_AUDIO_STATUS));
|
||||||
ret = true;
|
ret = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (nod_next != NULL) {
|
if (nod_next != NULL)
|
||||||
|
{
|
||||||
memcpy(status_next, list_node(nod_next), sizeof(APP_AUDIO_STATUS));
|
memcpy(status_next, list_node(nod_next), sizeof(APP_AUDIO_STATUS));
|
||||||
ASSERT(status_next->id == APP_PLAY_BACK_AUDIO,
|
ASSERT(status_next->id == APP_PLAY_BACK_AUDIO, "[%s] 111ERROR: status_next->id != APP_PLAY_BACK_AUDIO", __func__);
|
||||||
"[%s] 111ERROR: status_next->id != APP_PLAY_BACK_AUDIO",
|
|
||||||
__func__);
|
|
||||||
|
|
||||||
ret = true;
|
ret = true;
|
||||||
} else if (app_audio_list_stream_exist()) {
|
}
|
||||||
|
else if (app_audio_list_stream_exist())
|
||||||
|
{
|
||||||
void *indata = list_front(app_audio_conifg.audio_list);
|
void *indata = list_front(app_audio_conifg.audio_list);
|
||||||
if (indata == NULL) {
|
if(indata == NULL)
|
||||||
|
{
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
memcpy(status_next, indata, sizeof(APP_AUDIO_STATUS));
|
memcpy(status_next, indata, sizeof(APP_AUDIO_STATUS));
|
||||||
ASSERT(status_next->id != APP_PLAY_BACK_AUDIO,
|
ASSERT(status_next->id != APP_PLAY_BACK_AUDIO, "[%s] 222ERROR: status_next->id != APP_PLAY_BACK_AUDIO", __func__);
|
||||||
"[%s] 222ERROR: status_next->id != APP_PLAY_BACK_AUDIO",
|
|
||||||
__func__);
|
|
||||||
|
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else // maybe...a2dp send >> APP_BT_SETTING_CLOSE, when ring
|
}
|
||||||
|
else //maybe...a2dp send >> APP_BT_SETTING_CLOSE, when ring
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
if (app_audio_list_stream_exist()) {
|
if (app_audio_list_stream_exist())
|
||||||
if (pos == APP_BT_SETTING_Q_POS_HEAD) {
|
{
|
||||||
|
if(pos == APP_BT_SETTING_Q_POS_HEAD)
|
||||||
|
{
|
||||||
data_to_remove = list_front(app_audio_conifg.audio_list);
|
data_to_remove = list_front(app_audio_conifg.audio_list);
|
||||||
} else if (pos == APP_BT_SETTING_Q_POS_TAIL) {
|
}
|
||||||
|
else if (pos == APP_BT_SETTING_Q_POS_TAIL)
|
||||||
|
{
|
||||||
data_to_remove = list_back(app_audio_conifg.audio_list);
|
data_to_remove = list_back(app_audio_conifg.audio_list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data_to_remove) {
|
if (data_to_remove)
|
||||||
|
{
|
||||||
list_remove(app_audio_conifg.audio_list, data_to_remove);
|
list_remove(app_audio_conifg.audio_list, data_to_remove);
|
||||||
}
|
}
|
||||||
TRACE_AUD_HDL_I("[STREAM_LIST][RMV] end len:%d ret %d data %p",
|
TRACE_AUD_HDL_I("[STREAM_LIST][RMV] end len:%d ret %d data %p", list_length(app_audio_conifg.audio_list), ret, data_to_remove);
|
||||||
list_length(app_audio_conifg.audio_list), ret,
|
|
||||||
data_to_remove);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void app_audio_list_clear() { list_clear(app_audio_conifg.audio_list); }
|
void app_audio_list_clear()
|
||||||
|
{
|
||||||
|
list_clear(app_audio_conifg.audio_list);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void app_audio_open(void) {
|
void app_audio_open(void)
|
||||||
if (app_audio_init) {
|
{
|
||||||
|
if(app_audio_init)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (g_app_audio_queue_mutex_id == NULL) {
|
if (g_app_audio_queue_mutex_id == NULL)
|
||||||
g_app_audio_queue_mutex_id =
|
{
|
||||||
osMutexCreate((osMutex(g_app_audio_queue_mutex)));
|
g_app_audio_queue_mutex_id = osMutexCreate((osMutex(g_app_audio_queue_mutex)));
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
ASSERT(0, "[%s] ERROR: g_app_audio_queue_mutex_id != NULL", __func__);
|
ASSERT(0, "[%s] ERROR: g_app_audio_queue_mutex_id != NULL", __func__);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (app_audio_status_mempool == NULL)
|
if (app_audio_status_mempool == NULL)
|
||||||
app_audio_status_mempool = osPoolCreate(osPool(app_audio_status_mempool));
|
app_audio_status_mempool = osPoolCreate(osPool(app_audio_status_mempool));
|
||||||
ASSERT(app_audio_status_mempool,
|
ASSERT(app_audio_status_mempool, "[%s] ERROR: app_audio_status_mempool != NULL", __func__);
|
||||||
"[%s] ERROR: app_audio_status_mempool != NULL", __func__);
|
|
||||||
|
|
||||||
#ifdef __AUDIO_QUEUE_SUPPORT__
|
#ifdef __AUDIO_QUEUE_SUPPORT__
|
||||||
app_audio_list_create();
|
app_audio_list_create();
|
||||||
|
@ -712,7 +782,10 @@ void app_audio_open(void) {
|
||||||
app_audio_init = true;
|
app_audio_init = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void app_audio_close(void) {
|
void app_audio_close(void)
|
||||||
|
{
|
||||||
app_set_threadhandle(APP_MODUAL_AUDIO, NULL);
|
app_set_threadhandle(APP_MODUAL_AUDIO, NULL);
|
||||||
app_audio_init = false;
|
app_audio_init = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -19,88 +19,69 @@
|
||||||
// RX: Receive process
|
// RX: Receive process
|
||||||
// 16k: base 25M/208M(1300,1302) base 28M/104M(1400,1402)
|
// 16k: base 25M/208M(1300,1302) base 28M/104M(1400,1402)
|
||||||
|-------|--------------------|-----------------------------------|----------------------------------|-----------|----------------------|
|
|-------|--------------------|-----------------------------------|----------------------------------|-----------|----------------------|
|
||||||
| TX/RX | New | Old | description
|
| TX/RX | New | Old | description | MIPS(M) | Note |
|
||||||
| MIPS(M) | Note | | | | | | 16k 8k |
|
| | | | | 16k 8k | |
|
||||||
|
|
|
||||||
|-------|--------------------|-----------------------------------|----------------------------------|-----------|----------------------|
|
|-------|--------------------|-----------------------------------|----------------------------------|-----------|----------------------|
|
||||||
| | SPEECH_TX_DC_FILTER| | Direct
|
| | SPEECH_TX_DC_FILTER| | Direct Current filter | 1~2 \ | |
|
||||||
Current filter | 1~2 \ | | | |
|
| | SPEECH_TX_AEC | SPEECH_ECHO_CANCEL | Acoustic Echo Cancellation(old) | 40 \ | HWFFT: 37 |
|
||||||
SPEECH_TX_AEC | SPEECH_ECHO_CANCEL | Acoustic Echo
|
| | SPEECH_TX_AEC2 | SPEECH_AEC_FIX | Acoustic Echo Cancellation(new) | 39 \ | enable NLP |
|
||||||
Cancellation(old) | 40 \ | HWFFT: 37 | | | SPEECH_TX_AEC2
|
| | SPEECH_TX_AEC3 | | Acoustic Echo Cancellation(new) | 14/18 \ | 2 filters/4 filters |
|
||||||
| SPEECH_AEC_FIX | Acoustic Echo Cancellation(new) | 39 \ |
|
| | SPEECH_TX_AEC2FLOAT| | Acoustic Echo Cancellation(new) | 23/22 \ | nlp/af(blocks=1) |
|
||||||
enable NLP | | | SPEECH_TX_AEC3 | | Acoustic Echo
|
| | SPEECH_TX_AEC2FLOAT| | Acoustic Echo Cancellation(ns) | 14/10 \ | banks=256/banks=128 |
|
||||||
Cancellation(new) | 14/18 \ | 2 filters/4 filters | | |
|
| | (ns_enabled) | | | 8/6 \ | banks=64/banks=32 |
|
||||||
SPEECH_TX_AEC2FLOAT| | Acoustic Echo
|
| | SPEECH_TX_NS | SPEECH_NOISE_SUPPRESS | 1 mic noise suppress(old) | 30 \ | HWFFT: 19 |
|
||||||
Cancellation(new) | 23/22 \ | nlp/af(blocks=1) | | |
|
| | SPEECH_TX_NS2 | LC_MMSE_NOISE_SUPPRESS | 1 mic noise suppress(new) | 16 \ | HWFFT: 12 |
|
||||||
SPEECH_TX_AEC2FLOAT| | Acoustic Echo
|
| | SPEECH_TX_NS3 | | 1 mic noise suppress(new) | 26 \ | |
|
||||||
Cancellation(ns) | 14/10 \ | banks=256/banks=128 | | | (ns_enabled)
|
| | SPEECH_TX_NS2FLOAT | LC_MMSE_NOISE_SUPPRESS_FLOAT | 1 mic noise suppress(new float) | 12.5 \ | banks=64 |
|
||||||
| | | 8/6 \
|
| TX | SPEECH_TX_2MIC_NS | DUAL_MIC_DENOISE | 2 mic noise suppres(long space) | \ | |
|
||||||
| banks=64/banks=32 | | | SPEECH_TX_NS | SPEECH_NOISE_SUPPRESS |
|
| | SPEECH_TX_2MIC_NS2 | 2MIC_DENOISE | 2 mic noise suppres(short space) | 22 | delay_taps 5M |
|
||||||
1 mic noise suppress(old) | 30 \ | HWFFT: 19 | | |
|
| | freq_smooth_enable 1.5M | |
|
||||||
SPEECH_TX_NS2 | LC_MMSE_NOISE_SUPPRESS | 1 mic noise
|
| | wnr_enable 1.5M |
|
||||||
suppress(new) | 16 \ | HWFFT: 12 | | |
|
| | SPEECH_TX_2MIC_NS4 | SENSORMIC_DENOISE | sensor mic noise suppress | 31.5 | |
|
||||||
SPEECH_TX_NS3 | | 1 mic noise
|
| | SPEECH_TX_2MIC_NS3 | FAR_FIELD_SPEECH_ENHANCEMENT | 2 mic noise suppres(far field) | \ | |
|
||||||
suppress(new) | 26 \ | | | |
|
| | SPEECH_TX_2MIC_NS5 | LEFTRIGHT_DENOISE | 2 mic noise suppr(left right end)| \ | |
|
||||||
SPEECH_TX_NS2FLOAT | LC_MMSE_NOISE_SUPPRESS_FLOAT | 1 mic noise
|
| | SPEECH_TX_2MIC_NS6 | FF_2MIC_DENOISE | 2 mic noise suppr(far field) | 70 | |
|
||||||
suppress(new float) | 12.5 \ | banks=64 | | TX |
|
| | SPEECH_TX_AGC | SPEECH_AGC | Automatic Gain Control | 3 | |
|
||||||
SPEECH_TX_2MIC_NS | DUAL_MIC_DENOISE | 2 mic noise
|
| | SPEECH_TX_COMPEXP | | Compressor and expander | 4 | |
|
||||||
suppres(long space) | \ | | | |
|
| | SPEECH_TX_EQ | SPEECH_WEIGHTING_FILTER_SUPPRESS | Default EQ | 0.5 \ | each section |
|
||||||
SPEECH_TX_2MIC_NS2 | 2MIC_DENOISE | 2 mic noise
|
|
||||||
suppres(short space) | 22 | delay_taps 5M | | |
|
|
||||||
freq_smooth_enable 1.5M | | | | wnr_enable 1.5M | |
|
|
||||||
| SPEECH_TX_2MIC_NS4 | SENSORMIC_DENOISE | sensor mic noise
|
|
||||||
suppress | 31.5 | | | |
|
|
||||||
SPEECH_TX_2MIC_NS3 | FAR_FIELD_SPEECH_ENHANCEMENT | 2 mic noise suppres(far
|
|
||||||
field) | \ | | | | SPEECH_TX_2MIC_NS5 |
|
|
||||||
LEFTRIGHT_DENOISE | 2 mic noise suppr(left right end)| \ | | |
|
|
||||||
| SPEECH_TX_2MIC_NS6 | FF_2MIC_DENOISE | 2 mic noise suppr(far
|
|
||||||
field) | 70 | | | | SPEECH_TX_AGC |
|
|
||||||
SPEECH_AGC | Automatic Gain Control | 3 | | |
|
|
||||||
| SPEECH_TX_COMPEXP | | Compressor and
|
|
||||||
expander | 4 | | | | SPEECH_TX_EQ |
|
|
||||||
SPEECH_WEIGHTING_FILTER_SUPPRESS | Default EQ | 0.5 \
|
|
||||||
| each section |
|
|
||||||
|-------|--------------------|-----------------------------------|----------------------------------|-----------|----------------------|
|
|-------|--------------------|-----------------------------------|----------------------------------|-----------|----------------------|
|
||||||
| | SPEECH_RX_NS | SPEAKER_NOISE_SUPPRESS | 1 mic noise
|
| | SPEECH_RX_NS | SPEAKER_NOISE_SUPPRESS | 1 mic noise suppress(old) | 30 \ | |
|
||||||
suppress(old) | 30 \ | | | RX |
|
| RX | SPEECH_RX_NS2 | LC_MMSE_NOISE_SUPPRESS_SPK | 1 mic noise suppress(new) | 16 \ | |
|
||||||
SPEECH_RX_NS2 | LC_MMSE_NOISE_SUPPRESS_SPK | 1 mic noise
|
| | SPEECH_RX_AGC | SPEECH_AGC_SPK | Automatic Gain Control | 3 | |
|
||||||
suppress(new) | 16 \ | | | |
|
| | SPEECH_RX_EQ | SPEAKER_WEIGHTING_FILTER_SUPPRESS | Default EQ | 0.5 \ | each section |
|
||||||
SPEECH_RX_AGC | SPEECH_AGC_SPK | Automatic Gain Control
|
|
||||||
| 3 | | | | SPEECH_RX_EQ |
|
|
||||||
SPEAKER_WEIGHTING_FILTER_SUPPRESS | Default EQ | 0.5 \
|
|
||||||
| each section |
|
|
||||||
|-------|--------------------|-----------------------------------|----------------------------------|-----------|----------------------|
|
|-------|--------------------|-----------------------------------|----------------------------------|-----------|----------------------|
|
||||||
**/
|
**/
|
||||||
|
|
||||||
#include "bt_sco_chain.h"
|
#include "plat_types.h"
|
||||||
|
#include "hal_trace.h"
|
||||||
|
#include "hal_timer.h"
|
||||||
#include "audio_dump.h"
|
#include "audio_dump.h"
|
||||||
|
#include "speech_cfg.h"
|
||||||
|
#include "bt_sco_chain.h"
|
||||||
#include "bt_sco_chain_cfg.h"
|
#include "bt_sco_chain_cfg.h"
|
||||||
#include "bt_sco_chain_tuning.h"
|
#include "bt_sco_chain_tuning.h"
|
||||||
#include "hal_timer.h"
|
|
||||||
#include "hal_trace.h"
|
|
||||||
#include "plat_types.h"
|
|
||||||
#include "speech_cfg.h"
|
|
||||||
#if defined(SPEECH_TX_2MIC_NS4)
|
#if defined(SPEECH_TX_2MIC_NS4)
|
||||||
#include "app_anc.h"
|
#include "app_anc.h"
|
||||||
#endif
|
#endif
|
||||||
#include "app_utils.h"
|
#include "app_utils.h"
|
||||||
|
|
||||||
#if defined(SCO_CP_ACCEL)
|
#if defined(SCO_CP_ACCEL)
|
||||||
#include "bt_sco_chain_cp.h"
|
|
||||||
#include "hal_location.h"
|
#include "hal_location.h"
|
||||||
|
#include "bt_sco_chain_cp.h"
|
||||||
|
|
||||||
#define SCO_CP_ACCEL_ALGO_START() \
|
#define SCO_CP_ACCEL_ALGO_START() \
|
||||||
*_pcm_len = pcm_len; \
|
*_pcm_len = pcm_len; \
|
||||||
} \
|
} \
|
||||||
CP_TEXT_SRAM_LOC \
|
CP_TEXT_SRAM_LOC \
|
||||||
void _speech_tx_process_mid(short *pcm_buf, short *ref_buf, int *_pcm_len) { \
|
void _speech_tx_process_mid(short *pcm_buf, short *ref_buf, int *_pcm_len) \
|
||||||
|
{ \
|
||||||
int pcm_len = *_pcm_len;
|
int pcm_len = *_pcm_len;
|
||||||
|
|
||||||
#define SCO_CP_ACCEL_ALGO_END() \
|
#define SCO_CP_ACCEL_ALGO_END() \
|
||||||
*_pcm_len = pcm_len; \
|
*_pcm_len = pcm_len; \
|
||||||
} \
|
} \
|
||||||
void _speech_tx_process_post(short *pcm_buf, short *ref_buf, \
|
void _speech_tx_process_post(short *pcm_buf, short *ref_buf, int *_pcm_len) \
|
||||||
int *_pcm_len) { \
|
{ \
|
||||||
int pcm_len = *_pcm_len;
|
int pcm_len = *_pcm_len;
|
||||||
|
|
||||||
#define SPEECH_TX_AEC2FLOAT_CORE 1
|
#define SPEECH_TX_AEC2FLOAT_CORE 1
|
||||||
|
@ -144,8 +125,7 @@ static int32_t *tx_pcmbuf32 = NULL;
|
||||||
short *aec_echo_buf = NULL;
|
short *aec_echo_buf = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SPEECH_TX_AEC) || defined(SPEECH_TX_AEC2) || \
|
#if defined(SPEECH_TX_AEC) || defined(SPEECH_TX_AEC2) || defined(SPEECH_TX_AEC3) || defined(SPEECH_TX_AEC2FLOAT)
|
||||||
defined(SPEECH_TX_AEC3) || defined(SPEECH_TX_AEC2FLOAT)
|
|
||||||
// Use to free buffer
|
// Use to free buffer
|
||||||
#if defined(SPEECH_TX_24BIT)
|
#if defined(SPEECH_TX_24BIT)
|
||||||
static int32_t *aec_echo_buf_ptr;
|
static int32_t *aec_echo_buf_ptr;
|
||||||
|
@ -172,6 +152,7 @@ SpeechFirCalibState *speech_tx_mic_fir_calib_st = NULL;
|
||||||
extern const SpeechFirCalibConfig speech_tx_mic_fir_calib_cfg;
|
extern const SpeechFirCalibConfig speech_tx_mic_fir_calib_cfg;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// AEC
|
// AEC
|
||||||
#if defined(SPEECH_TX_AEC)
|
#if defined(SPEECH_TX_AEC)
|
||||||
SpeechAecState *speech_tx_aec_st = NULL;
|
SpeechAecState *speech_tx_aec_st = NULL;
|
||||||
|
@ -186,10 +167,15 @@ SpeechAec2State *speech_tx_aec2_st = NULL;
|
||||||
short delay = 70;
|
short delay = 70;
|
||||||
short bufferstate[356];
|
short bufferstate[356];
|
||||||
short buf_out[256];
|
short buf_out[256];
|
||||||
void CODEC_OpVecCpy(short *pshwDes, short *pshwSrc, short swLen) {
|
void CODEC_OpVecCpy(
|
||||||
|
short *pshwDes,
|
||||||
|
short *pshwSrc,
|
||||||
|
short swLen)
|
||||||
|
{
|
||||||
short i = 0;
|
short i = 0;
|
||||||
|
|
||||||
for (i = 0; i < swLen; i++) {
|
for (i = 0; i < swLen; i++)
|
||||||
|
{
|
||||||
pshwDes[i] = pshwSrc[i];
|
pshwDes[i] = pshwSrc[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -203,8 +189,7 @@ static Ec2FloatState *speech_tx_aec2float_st = NULL;
|
||||||
|
|
||||||
// 2MIC NS
|
// 2MIC NS
|
||||||
#if defined(SPEECH_TX_2MIC_NS)
|
#if defined(SPEECH_TX_2MIC_NS)
|
||||||
// float mic2_ft_caliration[] =
|
// float mic2_ft_caliration[] = {0.395000,0.809000,0.939000,1.748000,1.904000,1.957000,1.944000,1.906000,1.935000,1.940000,1.937000,1.931000,1.929000,1.911000,1.887000,1.871000,1.846000,1.779000,1.748000,2.086000,2.055000,2.002000,1.903000,1.885000,1.854000,1.848000,1.848000,1.844000,1.852000,1.870000,1.866000,1.843000,1.838000,1.824000,1.861000,1.871000,1.866000,1.833000,1.800000,1.769000,1.749000,1.690000,1.664000,1.573000,1.602000,1.692000,1.759000,1.758000,1.698000,1.628000,1.525000,1.509000,1.492000,1.515000,1.530000,1.644000,1.653000,1.617000,1.667000,1.746000,1.663000,1.606000,1.560000,1.500000,1.579000,1.632000,1.623000,1.549000,1.524000,1.512000,1.493000,1.476000,1.421000,1.396000,1.386000,1.459000,1.463000,1.496000,1.568000,1.544000,1.555000,1.547000,1.619000,1.630000,1.574000,1.491000,1.414000,1.383000,1.352000,1.464000,1.474000,1.450000,1.419000,1.425000,1.411000,1.479000,1.517000,1.486000,1.428000,1.389000,1.330000,1.284000,1.267000,1.249000,1.256000,1.215000,1.250000,1.402000,1.386000,1.334000,1.287000,1.329000,1.337000,1.292000,1.226000,1.212000,1.142000,1.087000,1.086000,1.112000,1.145000,1.194000,1.163000,1.131000,1.162000,1.166000,1.259000,1.218000,1.218000,1.322000,1.347000,1.436000,1.890000,1.693000,1.591000,1.518000,1.422000,1.345000,1.331000,1.308000,1.330000,1.305000,1.218000,1.286000,1.340000,1.399000,1.406000,1.353000,1.280000,1.246000,1.185000,1.129000,1.014000,0.985000,0.981000,1.189000,1.533000,1.694000,1.613000,1.464000,1.419000,1.448000,1.449000,1.442000,1.367000,1.283000,1.232000,1.381000,1.484000,1.497000,1.554000,1.438000,1.365000,1.326000,1.332000,1.335000,1.367000,1.301000,1.288000,1.168000,1.103000,1.067000,1.026000,1.076000,1.126000,1.068000,1.045000,0.978000,0.926000,0.939000,0.854000,0.772000,0.902000,0.742000,1.073000,1.220000,1.177000,1.762000,1.573000,1.390000,1.406000,1.148000,1.054000,1.210000,1.344000,1.849000,2.078000,1.756000,1.646000,1.597000,1.447000,1.322000,1.279000,1.007000,0.921000,0.871000,0.864000,1.067000,1.129000,1.128000,1.027000,0.983000,0.889000,0.774000,0.759000,0.724000,0.949000,1.237000,1.499000,1.658000,1.837000,1.492000,1.452000,1.151000,1.100000,0.996000,0.986000,1.023000,1.071000,1.252000,1.295000,1.309000,1.343000,1.220000,1.161000,1.142000,1.041000,0.974000,0.885000,0.799000,0.669000,0.732000,0.953000,0.861000,0.881000,0.988000,0.891000};
|
||||||
// {0.395000,0.809000,0.939000,1.748000,1.904000,1.957000,1.944000,1.906000,1.935000,1.940000,1.937000,1.931000,1.929000,1.911000,1.887000,1.871000,1.846000,1.779000,1.748000,2.086000,2.055000,2.002000,1.903000,1.885000,1.854000,1.848000,1.848000,1.844000,1.852000,1.870000,1.866000,1.843000,1.838000,1.824000,1.861000,1.871000,1.866000,1.833000,1.800000,1.769000,1.749000,1.690000,1.664000,1.573000,1.602000,1.692000,1.759000,1.758000,1.698000,1.628000,1.525000,1.509000,1.492000,1.515000,1.530000,1.644000,1.653000,1.617000,1.667000,1.746000,1.663000,1.606000,1.560000,1.500000,1.579000,1.632000,1.623000,1.549000,1.524000,1.512000,1.493000,1.476000,1.421000,1.396000,1.386000,1.459000,1.463000,1.496000,1.568000,1.544000,1.555000,1.547000,1.619000,1.630000,1.574000,1.491000,1.414000,1.383000,1.352000,1.464000,1.474000,1.450000,1.419000,1.425000,1.411000,1.479000,1.517000,1.486000,1.428000,1.389000,1.330000,1.284000,1.267000,1.249000,1.256000,1.215000,1.250000,1.402000,1.386000,1.334000,1.287000,1.329000,1.337000,1.292000,1.226000,1.212000,1.142000,1.087000,1.086000,1.112000,1.145000,1.194000,1.163000,1.131000,1.162000,1.166000,1.259000,1.218000,1.218000,1.322000,1.347000,1.436000,1.890000,1.693000,1.591000,1.518000,1.422000,1.345000,1.331000,1.308000,1.330000,1.305000,1.218000,1.286000,1.340000,1.399000,1.406000,1.353000,1.280000,1.246000,1.185000,1.129000,1.014000,0.985000,0.981000,1.189000,1.533000,1.694000,1.613000,1.464000,1.419000,1.448000,1.449000,1.442000,1.367000,1.283000,1.232000,1.381000,1.484000,1.497000,1.554000,1.438000,1.365000,1.326000,1.332000,1.335000,1.367000,1.301000,1.288000,1.168000,1.103000,1.067000,1.026000,1.076000,1.126000,1.068000,1.045000,0.978000,0.926000,0.939000,0.854000,0.772000,0.902000,0.742000,1.073000,1.220000,1.177000,1.762000,1.573000,1.390000,1.406000,1.148000,1.054000,1.210000,1.344000,1.849000,2.078000,1.756000,1.646000,1.597000,1.447000,1.322000,1.279000,1.007000,0.921000,0.871000,0.864000,1.067000,1.129000,1.128000,1.027000,0.983000,0.889000,0.774000,0.759000,0.724000,0.949000,1.237000,1.499000,1.658000,1.837000,1.492000,1.452000,1.151000,1.100000,0.996000,0.986000,1.023000,1.071000,1.252000,1.295000,1.309000,1.343000,1.220000,1.161000,1.142000,1.041000,0.974000,0.885000,0.799000,0.669000,0.732000,0.953000,0.861000,0.881000,0.988000,0.891000};
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SPEECH_TX_2MIC_NS2)
|
#if defined(SPEECH_TX_2MIC_NS2)
|
||||||
|
@ -320,9 +305,9 @@ SpeechGainState *speech_rx_post_gain_st = NULL;
|
||||||
|
|
||||||
static bool dualmic_enable = true;
|
static bool dualmic_enable = true;
|
||||||
|
|
||||||
void switch_dualmic_status(void) {
|
void switch_dualmic_status(void)
|
||||||
TRACE(3, "[%s] dualmic status: %d -> %d", __FUNCTION__, dualmic_enable,
|
{
|
||||||
!dualmic_enable);
|
TRACE(3,"[%s] dualmic status: %d -> %d", __FUNCTION__, dualmic_enable, !dualmic_enable);
|
||||||
dualmic_enable ^= true;
|
dualmic_enable ^= true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,14 +318,16 @@ static int speech_rx_frame_len = 256;
|
||||||
static bool speech_tx_frame_resizer_enable = false;
|
static bool speech_tx_frame_resizer_enable = false;
|
||||||
static bool speech_rx_frame_resizer_enable = false;
|
static bool speech_rx_frame_resizer_enable = false;
|
||||||
|
|
||||||
static int32_t _speech_tx_process_(void *pcm_buf, void *ref_buf,
|
static int32_t _speech_tx_process_(void *pcm_buf, void *ref_buf, int32_t *pcm_len);
|
||||||
int32_t *pcm_len);
|
|
||||||
static int32_t _speech_rx_process_(void *pcm_buf, int32_t *pcm_len);
|
static int32_t _speech_rx_process_(void *pcm_buf, int32_t *pcm_len);
|
||||||
enum APP_SYSFREQ_FREQ_T speech_get_proper_sysfreq(int *needed_mips);
|
enum APP_SYSFREQ_FREQ_T speech_get_proper_sysfreq(int *needed_mips);
|
||||||
|
|
||||||
void *speech_get_ext_buff(int size) {
|
|
||||||
|
void *speech_get_ext_buff(int size)
|
||||||
|
{
|
||||||
void *pBuff = NULL;
|
void *pBuff = NULL;
|
||||||
if (size % 4) {
|
if (size % 4)
|
||||||
|
{
|
||||||
size = size + (4 - size % 4);
|
size = size + (4 - size % 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -350,44 +337,42 @@ void *speech_get_ext_buff(int size) {
|
||||||
return pBuff;
|
return pBuff;
|
||||||
}
|
}
|
||||||
|
|
||||||
int speech_store_config(const SpeechConfig *cfg) {
|
int speech_store_config(const SpeechConfig *cfg)
|
||||||
if (speech_cfg) {
|
{
|
||||||
|
if (speech_cfg)
|
||||||
|
{
|
||||||
memcpy(speech_cfg, cfg, sizeof(SpeechConfig));
|
memcpy(speech_cfg, cfg, sizeof(SpeechConfig));
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
TRACE(1,"[%s] WARNING: Please phone call...", __func__);
|
TRACE(1,"[%s] WARNING: Please phone call...", __func__);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int speech_tx_init(int sample_rate, int frame_len) {
|
int speech_tx_init(int sample_rate, int frame_len)
|
||||||
TRACE(3, "[%s] Start, sample_rate: %d, frame_len: %d", __func__, sample_rate,
|
{
|
||||||
frame_len);
|
TRACE(3,"[%s] Start, sample_rate: %d, frame_len: %d", __func__, sample_rate, frame_len);
|
||||||
|
|
||||||
#if defined(SPEECH_TX_DC_FILTER)
|
#if defined(SPEECH_TX_DC_FILTER)
|
||||||
int channel_num = SPEECH_TX_CHANNEL_NUM;
|
int channel_num = SPEECH_TX_CHANNEL_NUM;
|
||||||
int data_separation = 0;
|
int data_separation = 0;
|
||||||
|
|
||||||
speech_tx_dc_filter_st =
|
speech_tx_dc_filter_st = speech_dc_filter_create(sample_rate, &speech_cfg->tx_dc_filter);
|
||||||
speech_dc_filter_create(sample_rate, &speech_cfg->tx_dc_filter);
|
speech_dc_filter_ctl(speech_tx_dc_filter_st, SPEECH_DC_FILTER_SET_CHANNEL_NUM, &channel_num);
|
||||||
speech_dc_filter_ctl(speech_tx_dc_filter_st, SPEECH_DC_FILTER_SET_CHANNEL_NUM,
|
speech_dc_filter_ctl(speech_tx_dc_filter_st, SPEECH_DC_FILTER_SET_DATA_SEPARATION, &data_separation);
|
||||||
&channel_num);
|
|
||||||
speech_dc_filter_ctl(speech_tx_dc_filter_st,
|
|
||||||
SPEECH_DC_FILTER_SET_DATA_SEPARATION, &data_separation);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SPEECH_TX_MIC_CALIBRATION)
|
#if defined(SPEECH_TX_MIC_CALIBRATION)
|
||||||
speech_tx_mic_calib_st =
|
speech_tx_mic_calib_st = speech_iir_calib_init(sample_rate, frame_len, &speech_tx_mic_calib_cfg);
|
||||||
speech_iir_calib_init(sample_rate, frame_len, &speech_tx_mic_calib_cfg);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SPEECH_TX_MIC_FIR_CALIBRATION)
|
#if defined(SPEECH_TX_MIC_FIR_CALIBRATION)
|
||||||
speech_tx_mic_fir_calib_st = speech_fir_calib_init(
|
speech_tx_mic_fir_calib_st = speech_fir_calib_init(sample_rate, frame_len, &speech_tx_mic_fir_calib_cfg);
|
||||||
sample_rate, frame_len, &speech_tx_mic_fir_calib_cfg);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SPEECH_TX_AEC) || defined(SPEECH_TX_AEC2) || \
|
#if defined(SPEECH_TX_AEC) || defined(SPEECH_TX_AEC2) || defined(SPEECH_TX_AEC3) || defined(SPEECH_TX_AEC2FLOAT)
|
||||||
defined(SPEECH_TX_AEC3) || defined(SPEECH_TX_AEC2FLOAT)
|
|
||||||
// #if !(defined(__AUDIO_RESAMPLE__) && defined(SW_SCO_RESAMPLE))
|
// #if !(defined(__AUDIO_RESAMPLE__) && defined(SW_SCO_RESAMPLE))
|
||||||
aec_out_buf = (short *)speech_calloc(frame_len, sizeof(short));
|
aec_out_buf = (short *)speech_calloc(frame_len, sizeof(short));
|
||||||
#if defined(SPEECH_TX_24BIT)
|
#if defined(SPEECH_TX_24BIT)
|
||||||
|
@ -400,41 +385,32 @@ int speech_tx_init(int sample_rate, int frame_len) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SPEECH_TX_AEC)
|
#if defined(SPEECH_TX_AEC)
|
||||||
speech_tx_aec_st =
|
speech_tx_aec_st = speech_aec_create(sample_rate, frame_len, &speech_cfg->tx_aec);
|
||||||
speech_aec_create(sample_rate, frame_len, &speech_cfg->tx_aec);
|
speech_aec_ctl(speech_tx_aec_st, SPEECH_AEC_GET_LIB_ST, &speech_tx_aec_lib_st);
|
||||||
speech_aec_ctl(speech_tx_aec_st, SPEECH_AEC_GET_LIB_ST,
|
|
||||||
&speech_tx_aec_lib_st);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SPEECH_TX_AEC2)
|
#if defined(SPEECH_TX_AEC2)
|
||||||
speech_tx_aec2_st =
|
speech_tx_aec2_st = speech_aec2_create(sample_rate, frame_len, &speech_cfg->tx_aec2);
|
||||||
speech_aec2_create(sample_rate, frame_len, &speech_cfg->tx_aec2);
|
|
||||||
#endif
|
#endif
|
||||||
#if defined(SPEECH_TX_AEC3)
|
#if defined(SPEECH_TX_AEC3)
|
||||||
speech_tx_aec3_st =
|
speech_tx_aec3_st = SubBandAec_init(sample_rate, frame_len, &speech_cfg->tx_aec3);
|
||||||
SubBandAec_init(sample_rate, frame_len, &speech_cfg->tx_aec3);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SPEECH_TX_AEC2FLOAT)
|
#if defined(SPEECH_TX_AEC2FLOAT)
|
||||||
speech_tx_aec2float_st =
|
speech_tx_aec2float_st = ec2float_create(sample_rate, frame_len, SPEECH_TX_AEC2FLOAT_CORE, &speech_cfg->tx_aec2float);
|
||||||
ec2float_create(sample_rate, frame_len, SPEECH_TX_AEC2FLOAT_CORE,
|
|
||||||
&speech_cfg->tx_aec2float);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SPEECH_TX_2MIC_NS)
|
#if defined(SPEECH_TX_2MIC_NS)
|
||||||
dual_mic_denoise_init(sample_rate, frame_len, &speech_cfg->tx_2mic_ns, NULL);
|
dual_mic_denoise_init(sample_rate, frame_len, &speech_cfg->tx_2mic_ns, NULL);
|
||||||
// dual_mic_denoise_ctl(DUAL_MIC_DENOISE_SET_CALIBRATION_COEF,
|
// dual_mic_denoise_ctl(DUAL_MIC_DENOISE_SET_CALIBRATION_COEF, mic2_ft_caliration);
|
||||||
// mic2_ft_caliration);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SPEECH_TX_2MIC_NS2)
|
#if defined(SPEECH_TX_2MIC_NS2)
|
||||||
speech_tx_2mic_ns2_st =
|
speech_tx_2mic_ns2_st = speech_2mic_ns2_create(sample_rate, frame_len, &speech_cfg->tx_2mic_ns2);
|
||||||
speech_2mic_ns2_create(sample_rate, frame_len, &speech_cfg->tx_2mic_ns2);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// #if defined(SPEECH_CS_VAD)
|
// #if defined(SPEECH_CS_VAD)
|
||||||
// speech_cs_vad_st = VAD_process_state_init(sample_rate, 64,
|
// speech_cs_vad_st = VAD_process_state_init(sample_rate, 64, &speech_cfg->cs_vad);
|
||||||
// &speech_cfg->cs_vad);
|
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
#if defined(SPEECH_TX_2MIC_NS3)
|
#if defined(SPEECH_TX_2MIC_NS3)
|
||||||
|
@ -443,8 +419,7 @@ int speech_tx_init(int sample_rate, int frame_len) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SPEECH_TX_2MIC_NS5)
|
#if defined(SPEECH_TX_2MIC_NS5)
|
||||||
speech_tx_2mic_ns5_st =
|
speech_tx_2mic_ns5_st = leftright_denoise_create(sample_rate, 64, &speech_cfg->tx_2mic_ns5);
|
||||||
leftright_denoise_create(sample_rate, 64, &speech_cfg->tx_2mic_ns5);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SPEECH_TX_2MIC_NS6)
|
#if defined(SPEECH_TX_2MIC_NS6)
|
||||||
|
@ -452,25 +427,20 @@ int speech_tx_init(int sample_rate, int frame_len) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SPEECH_TX_2MIC_NS4)
|
#if defined(SPEECH_TX_2MIC_NS4)
|
||||||
// speech_tx_2mic_ns4_st = sensormic_denoise_create(sample_rate, 64,
|
//speech_tx_2mic_ns4_st = sensormic_denoise_create(sample_rate, 64, &speech_cfg->tx_2mic_ns4);
|
||||||
// &speech_cfg->tx_2mic_ns4);
|
speech_tx_2mic_ns4_st = sensormic_denoise_create(sample_rate, 128, 256, 31, &speech_cfg->tx_2mic_ns4);
|
||||||
speech_tx_2mic_ns4_st = sensormic_denoise_create(sample_rate, 128, 256, 31,
|
|
||||||
&speech_cfg->tx_2mic_ns4);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SPEECH_TX_3MIC_NS)
|
#if defined(SPEECH_TX_3MIC_NS)
|
||||||
speech_tx_3mic_ns_st =
|
speech_tx_3mic_ns_st = speech_3mic_ns_create(sample_rate, 64, &speech_cfg->tx_3mic_ns);
|
||||||
speech_3mic_ns_create(sample_rate, 64, &speech_cfg->tx_3mic_ns);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SPEECH_TX_3MIC_NS3)
|
#if defined(SPEECH_TX_3MIC_NS3)
|
||||||
speech_tx_3mic_ns3_st = triple_mic_denoise3_init(sample_rate, frame_len,
|
speech_tx_3mic_ns3_st = triple_mic_denoise3_init(sample_rate, frame_len, &speech_cfg->tx_3mic_ns3);
|
||||||
&speech_cfg->tx_3mic_ns3);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SPEECH_TX_NS)
|
#if defined(SPEECH_TX_NS)
|
||||||
speech_tx_ns_st =
|
speech_tx_ns_st = speech_ns_create(sample_rate, frame_len, &speech_cfg->tx_ns);
|
||||||
speech_ns_create(sample_rate, frame_len, &speech_cfg->tx_ns);
|
|
||||||
#if defined(SPEECH_TX_AEC)
|
#if defined(SPEECH_TX_AEC)
|
||||||
speech_ns_ctl(speech_tx_ns_st, SPEECH_NS_SET_AEC_STATE, speech_tx_aec_lib_st);
|
speech_ns_ctl(speech_tx_ns_st, SPEECH_NS_SET_AEC_STATE, speech_tx_aec_lib_st);
|
||||||
int32_t echo_supress = -39;
|
int32_t echo_supress = -39;
|
||||||
|
@ -479,8 +449,7 @@ int speech_tx_init(int sample_rate, int frame_len) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SPEECH_TX_NS2)
|
#if defined(SPEECH_TX_NS2)
|
||||||
speech_tx_ns2_st =
|
speech_tx_ns2_st = speech_ns2_create(sample_rate, frame_len, &speech_cfg->tx_ns2);
|
||||||
speech_ns2_create(sample_rate, frame_len, &speech_cfg->tx_ns2);
|
|
||||||
#if defined(SPEECH_TX_AEC)
|
#if defined(SPEECH_TX_AEC)
|
||||||
speech_ns2_set_echo_state(speech_tx_ns2_st, speech_tx_aec_lib_st);
|
speech_ns2_set_echo_state(speech_tx_ns2_st, speech_tx_aec_lib_st);
|
||||||
speech_ns2_set_echo_suppress(speech_tx_ns2_st, -40);
|
speech_ns2_set_echo_suppress(speech_tx_ns2_st, -40);
|
||||||
|
@ -488,9 +457,7 @@ int speech_tx_init(int sample_rate, int frame_len) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SPEECH_TX_NS2FLOAT)
|
#if defined(SPEECH_TX_NS2FLOAT)
|
||||||
speech_tx_ns2float_st =
|
speech_tx_ns2float_st = speech_ns2float_create(sample_rate, frame_len, SPEECH_TX_NS2FLOAT_CORE, &speech_cfg->tx_ns2float);
|
||||||
speech_ns2float_create(sample_rate, frame_len, SPEECH_TX_NS2FLOAT_CORE,
|
|
||||||
&speech_cfg->tx_ns2float);
|
|
||||||
#if defined(SPEECH_TX_AEC)
|
#if defined(SPEECH_TX_AEC)
|
||||||
speech_ns2float_set_echo_state(speech_tx_ns2float_st, speech_tx_aec_lib_st);
|
speech_ns2float_set_echo_state(speech_tx_ns2float_st, speech_tx_aec_lib_st);
|
||||||
speech_ns2float_set_echo_suppress(speech_tx_ns2float_st, -40);
|
speech_ns2float_set_echo_suppress(speech_tx_ns2float_st, -40);
|
||||||
|
@ -506,18 +473,15 @@ int speech_tx_init(int sample_rate, int frame_len) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SPEECH_TX_NOISE_GATE)
|
#if defined(SPEECH_TX_NOISE_GATE)
|
||||||
speech_tx_noise_gate_st = speech_noise_gate_create(
|
speech_tx_noise_gate_st = speech_noise_gate_create(sample_rate, frame_len, &speech_cfg->tx_noise_gate);
|
||||||
sample_rate, frame_len, &speech_cfg->tx_noise_gate);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SPEECH_TX_COMPEXP)
|
#if defined(SPEECH_TX_COMPEXP)
|
||||||
speech_tx_compexp_st =
|
speech_tx_compexp_st = compexp_create(sample_rate, frame_len, &speech_cfg->tx_compexp);
|
||||||
compexp_create(sample_rate, frame_len, &speech_cfg->tx_compexp);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SPEECH_TX_AGC)
|
#if defined(SPEECH_TX_AGC)
|
||||||
speech_tx_agc_st =
|
speech_tx_agc_st = agc_state_create(sample_rate, frame_len, &speech_cfg->tx_agc);
|
||||||
agc_state_create(sample_rate, frame_len, &speech_cfg->tx_agc);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SPEECH_TX_EQ)
|
#if defined(SPEECH_TX_EQ)
|
||||||
|
@ -525,8 +489,7 @@ int speech_tx_init(int sample_rate, int frame_len) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SPEECH_TX_POST_GAIN)
|
#if defined(SPEECH_TX_POST_GAIN)
|
||||||
speech_tx_post_gain_st =
|
speech_tx_post_gain_st = speech_gain_create(sample_rate, frame_len, &speech_cfg->tx_post_gain);
|
||||||
speech_gain_create(sample_rate, frame_len, &speech_cfg->tx_post_gain);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TRACE(1,"[%s] End", __func__);
|
TRACE(1,"[%s] End", __func__);
|
||||||
|
@ -534,24 +497,20 @@ int speech_tx_init(int sample_rate, int frame_len) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int speech_rx_init(int sample_rate, int frame_len) {
|
int speech_rx_init(int sample_rate, int frame_len)
|
||||||
TRACE(3, "[%s] Start, sample_rate: %d, frame_len: %d", __func__, sample_rate,
|
{
|
||||||
frame_len);
|
TRACE(3,"[%s] Start, sample_rate: %d, frame_len: %d", __func__, sample_rate, frame_len);
|
||||||
|
|
||||||
#if defined (SPEECH_RX_NS)
|
#if defined (SPEECH_RX_NS)
|
||||||
speech_rx_ns_st =
|
speech_rx_ns_st = speech_ns_create(sample_rate, frame_len, &speech_cfg->rx_ns);
|
||||||
speech_ns_create(sample_rate, frame_len, &speech_cfg->rx_ns);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SPEECH_RX_NS2)
|
#if defined(SPEECH_RX_NS2)
|
||||||
speech_rx_ns2_st =
|
speech_rx_ns2_st = speech_ns2_create(sample_rate, frame_len, &speech_cfg->rx_ns2);
|
||||||
speech_ns2_create(sample_rate, frame_len, &speech_cfg->rx_ns2);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SPEECH_RX_NS2FLOAT)
|
#if defined(SPEECH_RX_NS2FLOAT)
|
||||||
speech_rx_ns2float_st =
|
speech_rx_ns2float_st = speech_ns2float_create(sample_rate, frame_len, SPEECH_RX_NS2FLOAT_CORE, &speech_cfg->rx_ns2float);
|
||||||
speech_ns2float_create(sample_rate, frame_len, SPEECH_RX_NS2FLOAT_CORE,
|
|
||||||
&speech_cfg->rx_ns2float);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SPEECH_RX_NS3)
|
#if defined(SPEECH_RX_NS3)
|
||||||
|
@ -559,8 +518,7 @@ int speech_rx_init(int sample_rate, int frame_len) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SPEECH_RX_AGC)
|
#if defined(SPEECH_RX_AGC)
|
||||||
speech_rx_agc_st =
|
speech_rx_agc_st = agc_state_create(sample_rate, frame_len, &speech_cfg->rx_agc);
|
||||||
agc_state_create(sample_rate, frame_len, &speech_cfg->rx_agc);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SPEECH_RX_EQ)
|
#if defined(SPEECH_RX_EQ)
|
||||||
|
@ -568,8 +526,7 @@ int speech_rx_init(int sample_rate, int frame_len) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SPEECH_RX_POST_GAIN)
|
#if defined(SPEECH_RX_POST_GAIN)
|
||||||
speech_rx_post_gain_st =
|
speech_rx_post_gain_st = speech_gain_create(sample_rate, frame_len, &speech_cfg->rx_post_gain);
|
||||||
speech_gain_create(sample_rate, frame_len, &speech_cfg->rx_post_gain);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TRACE(1,"[%s] End", __func__);
|
TRACE(1,"[%s] End", __func__);
|
||||||
|
@ -577,12 +534,14 @@ int speech_rx_init(int sample_rate, int frame_len) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int speech_init(int tx_sample_rate, int rx_sample_rate, int tx_frame_ms,
|
int speech_init(int tx_sample_rate, int rx_sample_rate,
|
||||||
int rx_frame_ms, int sco_frame_ms, uint8_t *buf, int len) {
|
int tx_frame_ms, int rx_frame_ms,
|
||||||
|
int sco_frame_ms,
|
||||||
|
uint8_t *buf, int len)
|
||||||
|
{
|
||||||
TRACE(1,"[%s] Start...", __func__);
|
TRACE(1,"[%s] Start...", __func__);
|
||||||
|
|
||||||
// ASSERT(frame_ms == SPEECH_PROCESS_FRAME_MS, "[%s] frame_ms(%d) !=
|
//ASSERT(frame_ms == SPEECH_PROCESS_FRAME_MS, "[%s] frame_ms(%d) != SPEECH_PROCESS_FRAME_MS(%d)", __func__,
|
||||||
// SPEECH_PROCESS_FRAME_MS(%d)", __func__,
|
|
||||||
// frame_ms,
|
// frame_ms,
|
||||||
// SPEECH_PROCESS_FRAME_MS);
|
// SPEECH_PROCESS_FRAME_MS);
|
||||||
|
|
||||||
|
@ -594,9 +553,9 @@ int speech_init(int tx_sample_rate, int rx_sample_rate, int tx_frame_ms,
|
||||||
speech_heap_init(buf, len);
|
speech_heap_init(buf, len);
|
||||||
|
|
||||||
#if defined(SCO_OPTIMIZE_FOR_RAM)
|
#if defined(SCO_OPTIMIZE_FOR_RAM)
|
||||||
TRACE(2, "[%s] sco_overlay_ram_buf_len = %d", __func__,
|
TRACE(2,"[%s] sco_overlay_ram_buf_len = %d", __func__, sco_overlay_ram_buf_len);
|
||||||
sco_overlay_ram_buf_len);
|
if (sco_overlay_ram_buf_len >= 1024)
|
||||||
if (sco_overlay_ram_buf_len >= 1024) {
|
{
|
||||||
speech_heap_add_block(sco_overlay_ram_buf, sco_overlay_ram_buf_len);
|
speech_heap_add_block(sco_overlay_ram_buf, sco_overlay_ram_buf_len);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -616,13 +575,11 @@ int speech_init(int tx_sample_rate, int rx_sample_rate, int tx_frame_ms,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int aec_enable = 0;
|
int aec_enable = 0;
|
||||||
#if defined(SPEECH_TX_AEC) || defined(SPEECH_TX_AEC2) || \
|
#if defined(SPEECH_TX_AEC) || defined(SPEECH_TX_AEC2) || defined(SPEECH_TX_AEC3) || defined(SPEECH_TX_AEC2FLOAT)
|
||||||
defined(SPEECH_TX_AEC3) || defined(SPEECH_TX_AEC2FLOAT)
|
|
||||||
aec_enable = 1;
|
aec_enable = 1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int capture_sample_size = sizeof(int16_t),
|
int capture_sample_size = sizeof(int16_t), playback_sample_size = sizeof(int16_t);
|
||||||
playback_sample_size = sizeof(int16_t);
|
|
||||||
#if defined(SPEECH_TX_24BIT)
|
#if defined(SPEECH_TX_24BIT)
|
||||||
capture_sample_size = sizeof(int32_t);
|
capture_sample_size = sizeof(int32_t);
|
||||||
#endif
|
#endif
|
||||||
|
@ -630,19 +587,22 @@ int speech_init(int tx_sample_rate, int rx_sample_rate, int tx_frame_ms,
|
||||||
playback_sample_size = sizeof(int32_t);
|
playback_sample_size = sizeof(int32_t);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
CAPTURE_HANDLER_T tx_handler =
|
CAPTURE_HANDLER_T tx_handler = (tx_frame_ms == sco_frame_ms) ? NULL : _speech_tx_process_;
|
||||||
(tx_frame_ms == sco_frame_ms) ? NULL : _speech_tx_process_;
|
PLAYBACK_HANDLER_T rx_handler = (rx_frame_ms == sco_frame_ms) ? NULL : _speech_rx_process_;
|
||||||
PLAYBACK_HANDLER_T rx_handler =
|
|
||||||
(rx_frame_ms == sco_frame_ms) ? NULL : _speech_rx_process_;
|
|
||||||
|
|
||||||
speech_tx_frame_resizer_enable = (tx_handler != NULL);
|
speech_tx_frame_resizer_enable = (tx_handler != NULL);
|
||||||
speech_rx_frame_resizer_enable = (rx_handler != NULL);
|
speech_rx_frame_resizer_enable = (rx_handler != NULL);
|
||||||
|
|
||||||
if (speech_tx_frame_resizer_enable || speech_rx_frame_resizer_enable) {
|
if (speech_tx_frame_resizer_enable || speech_rx_frame_resizer_enable) {
|
||||||
speech_frame_resize_st = frame_resize_create(
|
speech_frame_resize_st = frame_resize_create(SPEECH_FRAME_MS_TO_LEN(tx_sample_rate, sco_frame_ms),
|
||||||
SPEECH_FRAME_MS_TO_LEN(tx_sample_rate, sco_frame_ms),
|
SPEECH_TX_CHANNEL_NUM,
|
||||||
SPEECH_TX_CHANNEL_NUM, speech_tx_frame_len, capture_sample_size,
|
speech_tx_frame_len,
|
||||||
playback_sample_size, aec_enable, tx_handler, rx_handler);
|
capture_sample_size,
|
||||||
|
playback_sample_size,
|
||||||
|
aec_enable,
|
||||||
|
tx_handler,
|
||||||
|
rx_handler
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(SCO_CP_ACCEL)
|
#if defined(SCO_CP_ACCEL)
|
||||||
|
@ -655,8 +615,7 @@ int speech_init(int tx_sample_rate, int rx_sample_rate, int tx_frame_ms,
|
||||||
|
|
||||||
#if !defined(SCO_CP_ACCEL)
|
#if !defined(SCO_CP_ACCEL)
|
||||||
int needed_freq = 0;
|
int needed_freq = 0;
|
||||||
enum APP_SYSFREQ_FREQ_T min_system_freq =
|
enum APP_SYSFREQ_FREQ_T min_system_freq = speech_get_proper_sysfreq(&needed_freq);
|
||||||
speech_get_proper_sysfreq(&needed_freq);
|
|
||||||
enum APP_SYSFREQ_FREQ_T freq = hal_sysfreq_get();
|
enum APP_SYSFREQ_FREQ_T freq = hal_sysfreq_get();
|
||||||
|
|
||||||
if (freq < min_system_freq) {
|
if (freq < min_system_freq) {
|
||||||
|
@ -669,9 +628,7 @@ int speech_init(int tx_sample_rate, int rx_sample_rate, int tx_frame_ms,
|
||||||
TRACE(2,"[%s]: sys freq calc : %d\n", __FUNCTION__, system_freq);
|
TRACE(2,"[%s]: sys freq calc : %d\n", __FUNCTION__, system_freq);
|
||||||
|
|
||||||
if (system_freq <= needed_freq * 1000 * 1000) {
|
if (system_freq <= needed_freq * 1000 * 1000) {
|
||||||
TRACE(3,
|
TRACE(3,"[%s] WARNING: system freq(%d) seems to be lower than needed(%d).", __FUNCTION__, system_freq/1000000, needed_freq);
|
||||||
"[%s] WARNING: system freq(%d) seems to be lower than needed(%d).",
|
|
||||||
__FUNCTION__, system_freq / 1000000, needed_freq);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -681,7 +638,8 @@ int speech_init(int tx_sample_rate, int rx_sample_rate, int tx_frame_ms,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int speech_tx_deinit(void) {
|
int speech_tx_deinit(void)
|
||||||
|
{
|
||||||
TRACE(1,"[%s] Start...", __func__);
|
TRACE(1,"[%s] Start...", __func__);
|
||||||
|
|
||||||
#if defined(SPEECH_TX_POST_GAIN)
|
#if defined(SPEECH_TX_POST_GAIN)
|
||||||
|
@ -776,8 +734,7 @@ int speech_tx_deinit(void) {
|
||||||
ec2float_destroy(speech_tx_aec2float_st);
|
ec2float_destroy(speech_tx_aec2float_st);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SPEECH_TX_AEC) || defined(SPEECH_TX_AEC2) || \
|
#if defined(SPEECH_TX_AEC) || defined(SPEECH_TX_AEC2) || defined(SPEECH_TX_AEC3) || defined(SPEECH_TX_AEC2FLOAT)
|
||||||
defined(SPEECH_TX_AEC3) || defined(SPEECH_TX_AEC2FLOAT)
|
|
||||||
speech_free(aec_echo_buf_ptr);
|
speech_free(aec_echo_buf_ptr);
|
||||||
speech_free(aec_out_buf);
|
speech_free(aec_out_buf);
|
||||||
#endif
|
#endif
|
||||||
|
@ -799,7 +756,8 @@ int speech_tx_deinit(void) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int speech_rx_deinit(void) {
|
int speech_rx_deinit(void)
|
||||||
|
{
|
||||||
TRACE(1,"[%s] Start...", __func__);
|
TRACE(1,"[%s] Start...", __func__);
|
||||||
|
|
||||||
#if defined(SPEECH_RX_POST_GAIN)
|
#if defined(SPEECH_RX_POST_GAIN)
|
||||||
|
@ -835,7 +793,8 @@ int speech_rx_deinit(void) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int speech_deinit(void) {
|
int speech_deinit(void)
|
||||||
|
{
|
||||||
TRACE(1,"[%s] Start...", __func__);
|
TRACE(1,"[%s] Start...", __func__);
|
||||||
|
|
||||||
speech_rx_deinit();
|
speech_rx_deinit();
|
||||||
|
@ -864,8 +823,7 @@ int speech_deinit(void) {
|
||||||
|
|
||||||
size_t total = 0, used = 0, max_used = 0;
|
size_t total = 0, used = 0, max_used = 0;
|
||||||
speech_memory_info(&total, &used, &max_used);
|
speech_memory_info(&total, &used, &max_used);
|
||||||
TRACE(3, "SPEECH MALLOC MEM: total - %d, used - %d, max_used - %d.", total,
|
TRACE(3,"SPEECH MALLOC MEM: total - %d, used - %d, max_used - %d.", total, used, max_used);
|
||||||
used, max_used);
|
|
||||||
ASSERT(used == 0, "[%s] used != 0", __func__);
|
ASSERT(used == 0, "[%s] used != 0", __func__);
|
||||||
|
|
||||||
TRACE(1,"[%s] End", __func__);
|
TRACE(1,"[%s] End", __func__);
|
||||||
|
@ -873,7 +831,8 @@ int speech_deinit(void) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
float speech_tx_get_required_mips(void) {
|
float speech_tx_get_required_mips(void)
|
||||||
|
{
|
||||||
float mips = 0;
|
float mips = 0;
|
||||||
|
|
||||||
#if defined(SPEECH_TX_DC_FILTER)
|
#if defined(SPEECH_TX_DC_FILTER)
|
||||||
|
@ -983,7 +942,8 @@ float speech_tx_get_required_mips(void) {
|
||||||
return mips;
|
return mips;
|
||||||
}
|
}
|
||||||
|
|
||||||
float speech_rx_get_required_mips(void) {
|
float speech_rx_get_required_mips(void)
|
||||||
|
{
|
||||||
float mips = 0;
|
float mips = 0;
|
||||||
|
|
||||||
#if defined (SPEECH_RX_NS)
|
#if defined (SPEECH_RX_NS)
|
||||||
|
@ -1017,13 +977,15 @@ float speech_rx_get_required_mips(void) {
|
||||||
return mips;
|
return mips;
|
||||||
}
|
}
|
||||||
|
|
||||||
float speech_get_required_mips(void) {
|
float speech_get_required_mips(void)
|
||||||
|
{
|
||||||
return speech_tx_get_required_mips() + speech_rx_get_required_mips();
|
return speech_tx_get_required_mips() + speech_rx_get_required_mips();
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SYSTEM_BASE_MIPS (18)
|
#define SYSTEM_BASE_MIPS (18)
|
||||||
|
|
||||||
enum APP_SYSFREQ_FREQ_T speech_get_proper_sysfreq(int *needed_mips) {
|
enum APP_SYSFREQ_FREQ_T speech_get_proper_sysfreq(int *needed_mips)
|
||||||
|
{
|
||||||
enum APP_SYSFREQ_FREQ_T freq = APP_SYSFREQ_32K;
|
enum APP_SYSFREQ_FREQ_T freq = APP_SYSFREQ_32K;
|
||||||
int required_mips = (int)ceilf(speech_get_required_mips() + SYSTEM_BASE_MIPS);
|
int required_mips = (int)ceilf(speech_get_required_mips() + SYSTEM_BASE_MIPS);
|
||||||
|
|
||||||
|
@ -1043,7 +1005,8 @@ enum APP_SYSFREQ_FREQ_T speech_get_proper_sysfreq(int *needed_mips) {
|
||||||
return freq;
|
return freq;
|
||||||
}
|
}
|
||||||
|
|
||||||
int speech_set_config(const SpeechConfig *cfg) {
|
int speech_set_config(const SpeechConfig *cfg)
|
||||||
|
{
|
||||||
#if defined(SPEECH_TX_DC_FILTER)
|
#if defined(SPEECH_TX_DC_FILTER)
|
||||||
speech_dc_filter_set_config(speech_tx_dc_filter_st, &cfg->tx_dc_filter);
|
speech_dc_filter_set_config(speech_tx_dc_filter_st, &cfg->tx_dc_filter);
|
||||||
#endif
|
#endif
|
||||||
|
@ -1054,8 +1017,7 @@ int speech_set_config(const SpeechConfig *cfg) {
|
||||||
speech_aec2_set_config(speech_tx_aec2_st, &cfg->tx_aec2);
|
speech_aec2_set_config(speech_tx_aec2_st, &cfg->tx_aec2);
|
||||||
#endif
|
#endif
|
||||||
#if defined(SPEECH_TX_AEC2FLOAT)
|
#if defined(SPEECH_TX_AEC2FLOAT)
|
||||||
ec2float_set_config(speech_tx_aec2float_st, &cfg->tx_aec2float,
|
ec2float_set_config(speech_tx_aec2float_st, &cfg->tx_aec2float, SPEECH_TX_AEC2FLOAT_CORE);
|
||||||
SPEECH_TX_AEC2FLOAT_CORE);
|
|
||||||
#endif
|
#endif
|
||||||
#if defined(SPEECH_TX_2MIC_NS)
|
#if defined(SPEECH_TX_2MIC_NS)
|
||||||
TRACE(1,"[%s] WARNING: Can not support tuning SPEECH_TX_2MIC_NS", __func__);
|
TRACE(1,"[%s] WARNING: Can not support tuning SPEECH_TX_2MIC_NS", __func__);
|
||||||
|
@ -1109,8 +1071,7 @@ int speech_set_config(const SpeechConfig *cfg) {
|
||||||
speech_ns2_set_config(speech_rx_ns2_st, &cfg->rx_ns2);
|
speech_ns2_set_config(speech_rx_ns2_st, &cfg->rx_ns2);
|
||||||
#endif
|
#endif
|
||||||
#if defined(SPEECH_RX_NS2FLOAT)
|
#if defined(SPEECH_RX_NS2FLOAT)
|
||||||
speech_ns2float_set_config(speech_rx_ns2float_st, &cfg->rx_ns2float,
|
speech_ns2float_set_config(speech_rx_ns2float_st, &cfg->rx_ns2float, SPEECH_RX_NS2FLOAT_CORE);
|
||||||
SPEECH_RX_NS2FLOAT_CORE);
|
|
||||||
#endif
|
#endif
|
||||||
#if defined(SPEECH_RX_NS3)
|
#if defined(SPEECH_RX_NS3)
|
||||||
ns3_set_config(speech_rx_ns3_st, &cfg->rx_ns3);
|
ns3_set_config(speech_rx_ns3_st, &cfg->rx_ns3);
|
||||||
|
@ -1135,7 +1096,8 @@ int speech_set_config(const SpeechConfig *cfg) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _speech_tx_process_pre(short *pcm_buf, short *ref_buf, int *_pcm_len) {
|
void _speech_tx_process_pre(short *pcm_buf, short *ref_buf, int *_pcm_len)
|
||||||
|
{
|
||||||
int pcm_len = *_pcm_len;
|
int pcm_len = *_pcm_len;
|
||||||
|
|
||||||
#if defined(BT_SCO_CHAIN_PROFILE)
|
#if defined(BT_SCO_CHAIN_PROFILE)
|
||||||
|
@ -1145,19 +1107,19 @@ void _speech_tx_process_pre(short *pcm_buf, short *ref_buf, int *_pcm_len) {
|
||||||
// TRACE(2,"[%s] pcm_len = %d", __func__, pcm_len);
|
// TRACE(2,"[%s] pcm_len = %d", __func__, pcm_len);
|
||||||
|
|
||||||
#ifdef AUDIO_DEBUG_V0_1_0
|
#ifdef AUDIO_DEBUG_V0_1_0
|
||||||
if (speech_tuning_get_status()) {
|
if (speech_tuning_get_status())
|
||||||
|
{
|
||||||
speech_set_config(speech_cfg);
|
speech_set_config(speech_cfg);
|
||||||
|
|
||||||
speech_tuning_set_status(false);
|
speech_tuning_set_status(false);
|
||||||
|
|
||||||
// If has MIPS problem, can move this block code into speech_rx_process or
|
// If has MIPS problem, can move this block code into speech_rx_process or return directly
|
||||||
// return directly return 0
|
// return 0
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SPEECH_TX_24BIT)
|
#if defined(SPEECH_TX_24BIT)
|
||||||
#if defined(SPEECH_TX_AEC) || defined(SPEECH_TX_AEC2) || \
|
#if defined(SPEECH_TX_AEC) || defined(SPEECH_TX_AEC2) || defined(SPEECH_TX_AEC3) || defined(SPEECH_TX_AEC2FLOAT)
|
||||||
defined(SPEECH_TX_AEC3) || defined(SPEECH_TX_AEC2FLOAT)
|
|
||||||
tx_refbuf16 = (int16_t *)ref_buf;
|
tx_refbuf16 = (int16_t *)ref_buf;
|
||||||
tx_refbuf32 = (int32_t *)ref_buf;
|
tx_refbuf32 = (int32_t *)ref_buf;
|
||||||
for (int i = 0; i < pcm_len / SPEECH_CODEC_CAPTURE_CHANNEL_NUM; i++) {
|
for (int i = 0; i < pcm_len / SPEECH_CODEC_CAPTURE_CHANNEL_NUM; i++) {
|
||||||
|
@ -1192,12 +1154,9 @@ void _speech_tx_process_pre(short *pcm_buf, short *ref_buf, int *_pcm_len) {
|
||||||
speech_dc_filter_process(speech_tx_dc_filter_st, pcm_buf, pcm_len);
|
speech_dc_filter_process(speech_tx_dc_filter_st, pcm_buf, pcm_len);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (SPEECH_CODEC_CAPTURE_CHANNEL_NUM == 2) && defined(AUDIO_DUMP) && \
|
#if (SPEECH_CODEC_CAPTURE_CHANNEL_NUM == 2) && defined(AUDIO_DUMP) && defined(BT_SCO_CHAIN_AUDIO_DUMP)
|
||||||
defined(BT_SCO_CHAIN_AUDIO_DUMP)
|
audio_dump_add_channel_data_from_multi_channels(0, pcm_buf, pcm_len / 2, 2, 0);
|
||||||
audio_dump_add_channel_data_from_multi_channels(0, pcm_buf, pcm_len / 2, 2,
|
audio_dump_add_channel_data_from_multi_channels(1, pcm_buf, pcm_len / 2, 2, 1);
|
||||||
0);
|
|
||||||
audio_dump_add_channel_data_from_multi_channels(1, pcm_buf, pcm_len / 2, 2,
|
|
||||||
1);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SPEECH_TX_MIC_CALIBRATION)
|
#if defined(SPEECH_TX_MIC_CALIBRATION)
|
||||||
|
@ -1208,12 +1167,9 @@ void _speech_tx_process_pre(short *pcm_buf, short *ref_buf, int *_pcm_len) {
|
||||||
speech_fir_calib_process(speech_tx_mic_fir_calib_st, pcm_buf, pcm_len);
|
speech_fir_calib_process(speech_tx_mic_fir_calib_st, pcm_buf, pcm_len);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (SPEECH_CODEC_CAPTURE_CHANNEL_NUM == 2) && defined(AUDIO_DUMP) && \
|
#if (SPEECH_CODEC_CAPTURE_CHANNEL_NUM == 2) && defined(AUDIO_DUMP) && defined(BT_SCO_CHAIN_AUDIO_DUMP)
|
||||||
defined(BT_SCO_CHAIN_AUDIO_DUMP)
|
audio_dump_add_channel_data_from_multi_channels(2, pcm_buf, pcm_len / 2, 2, 0);
|
||||||
audio_dump_add_channel_data_from_multi_channels(2, pcm_buf, pcm_len / 2, 2,
|
audio_dump_add_channel_data_from_multi_channels(3, pcm_buf, pcm_len / 2, 2, 1);
|
||||||
0);
|
|
||||||
audio_dump_add_channel_data_from_multi_channels(3, pcm_buf, pcm_len / 2, 2,
|
|
||||||
1);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SPEECH_TX_2MIC_NS)
|
#if defined(SPEECH_TX_2MIC_NS)
|
||||||
|
@ -1231,8 +1187,7 @@ void _speech_tx_process_pre(short *pcm_buf, short *ref_buf, int *_pcm_len) {
|
||||||
#if defined(SPEECH_TX_2MIC_NS4)
|
#if defined(SPEECH_TX_2MIC_NS4)
|
||||||
if (dualmic_enable == true) {
|
if (dualmic_enable == true) {
|
||||||
#if defined(ANC_APP)
|
#if defined(ANC_APP)
|
||||||
sensormic_denoise_set_anc_status(speech_tx_2mic_ns4_st,
|
sensormic_denoise_set_anc_status(speech_tx_2mic_ns4_st, app_anc_work_status());
|
||||||
app_anc_work_status());
|
|
||||||
#endif
|
#endif
|
||||||
sensormic_denoise_process(speech_tx_2mic_ns4_st, pcm_buf, pcm_len, pcm_buf);
|
sensormic_denoise_process(speech_tx_2mic_ns4_st, pcm_buf, pcm_len, pcm_buf);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1271,8 +1226,7 @@ void _speech_tx_process_pre(short *pcm_buf, short *ref_buf, int *_pcm_len) {
|
||||||
|
|
||||||
#if defined(BT_SCO_CHAIN_AUDIO_DUMP)
|
#if defined(BT_SCO_CHAIN_AUDIO_DUMP)
|
||||||
audio_dump_add_channel_data(0, pcm_buf, pcm_len);
|
audio_dump_add_channel_data(0, pcm_buf, pcm_len);
|
||||||
#if defined(SPEECH_TX_AEC) || defined(SPEECH_TX_AEC2) || \
|
#if defined(SPEECH_TX_AEC) || defined(SPEECH_TX_AEC2) || defined(SPEECH_TX_AEC3) || defined(SPEECH_TX_AEC2FLOAT)
|
||||||
defined(SPEECH_TX_AEC3) || defined(SPEECH_TX_AEC2FLOAT)
|
|
||||||
audio_dump_add_channel_data(1, ref_buf, pcm_len);
|
audio_dump_add_channel_data(1, ref_buf, pcm_len);
|
||||||
#else
|
#else
|
||||||
audio_dump_add_channel_data(1, pcm_buf, pcm_len);
|
audio_dump_add_channel_data(1, pcm_buf, pcm_len);
|
||||||
|
@ -1301,13 +1255,10 @@ void _speech_tx_process_pre(short *pcm_buf, short *ref_buf, int *_pcm_len) {
|
||||||
#if defined(SPEECH_TX_AEC2FLOAT)
|
#if defined(SPEECH_TX_AEC2FLOAT)
|
||||||
#if defined(SPEECH_TX_2MIC_NS4)
|
#if defined(SPEECH_TX_2MIC_NS4)
|
||||||
if (dualmic_enable == true)
|
if (dualmic_enable == true)
|
||||||
TRACE(2, "[%s] vad: %d", __FUNCTION__,
|
TRACE(2,"[%s] vad: %d", __FUNCTION__, sensormic_denoise_get_vad(speech_tx_2mic_ns4_st));
|
||||||
sensormic_denoise_get_vad(speech_tx_2mic_ns4_st));
|
ec2float_set_external_vad(speech_tx_aec2float_st, sensormic_denoise_get_vad(speech_tx_2mic_ns4_st));
|
||||||
ec2float_set_external_vad(speech_tx_aec2float_st,
|
|
||||||
sensormic_denoise_get_vad(speech_tx_2mic_ns4_st));
|
|
||||||
#endif
|
#endif
|
||||||
ec2float_process(speech_tx_aec2float_st, pcm_buf, ref_buf, pcm_len,
|
ec2float_process(speech_tx_aec2float_st, pcm_buf, ref_buf, pcm_len, aec_out_buf);
|
||||||
aec_out_buf);
|
|
||||||
speech_copy_int16(pcm_buf, aec_out_buf, pcm_len);
|
speech_copy_int16(pcm_buf, aec_out_buf, pcm_len);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1328,9 +1279,7 @@ void _speech_tx_process_pre(short *pcm_buf, short *ref_buf, int *_pcm_len) {
|
||||||
#if defined(SPEECH_TX_NS2FLOAT)
|
#if defined(SPEECH_TX_NS2FLOAT)
|
||||||
#if defined(SPEECH_TX_2MIC_NS4)
|
#if defined(SPEECH_TX_2MIC_NS4)
|
||||||
if (dualmic_enable == true)
|
if (dualmic_enable == true)
|
||||||
speech_ns2float_set_external_vad(
|
speech_ns2float_set_external_vad(speech_tx_ns2float_st, sensormic_denoise_get_vad(speech_tx_2mic_ns4_st));
|
||||||
speech_tx_ns2float_st,
|
|
||||||
sensormic_denoise_get_vad(speech_tx_2mic_ns4_st));
|
|
||||||
#endif
|
#endif
|
||||||
speech_ns2float_process(speech_tx_ns2float_st, pcm_buf, pcm_len);
|
speech_ns2float_process(speech_tx_ns2float_st, pcm_buf, pcm_len);
|
||||||
#endif
|
#endif
|
||||||
|
@ -1401,7 +1350,8 @@ void _speech_tx_process_pre(short *pcm_buf, short *ref_buf, int *_pcm_len) {
|
||||||
|
|
||||||
#if defined(SCO_CP_ACCEL)
|
#if defined(SCO_CP_ACCEL)
|
||||||
CP_TEXT_SRAM_LOC
|
CP_TEXT_SRAM_LOC
|
||||||
int sco_cp_algo(short *pcm_buf, short *ref_buf, int *_pcm_len) {
|
int sco_cp_algo(short *pcm_buf, short *ref_buf, int *_pcm_len)
|
||||||
|
{
|
||||||
#if defined(SCO_TRACE_CP_ACCEL)
|
#if defined(SCO_TRACE_CP_ACCEL)
|
||||||
TRACE(1,"[%s] ...", __func__);
|
TRACE(1,"[%s] ...", __func__);
|
||||||
#endif
|
#endif
|
||||||
|
@ -1412,7 +1362,8 @@ int sco_cp_algo(short *pcm_buf, short *ref_buf, int *_pcm_len) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int32_t _speech_tx_process_(void *pcm_buf, void *ref_buf, int32_t *_pcm_len) {
|
int32_t _speech_tx_process_(void *pcm_buf, void *ref_buf, int32_t *_pcm_len)
|
||||||
|
{
|
||||||
_speech_tx_process_pre(pcm_buf, ref_buf, (int *)_pcm_len);
|
_speech_tx_process_pre(pcm_buf, ref_buf, (int *)_pcm_len);
|
||||||
#if defined(SCO_CP_ACCEL)
|
#if defined(SCO_CP_ACCEL)
|
||||||
sco_cp_process(pcm_buf, ref_buf, (int *)_pcm_len);
|
sco_cp_process(pcm_buf, ref_buf, (int *)_pcm_len);
|
||||||
|
@ -1422,7 +1373,8 @@ int32_t _speech_tx_process_(void *pcm_buf, void *ref_buf, int32_t *_pcm_len) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t _speech_rx_process_(void *pcm_buf, int32_t *_pcm_len) {
|
int32_t _speech_rx_process_(void *pcm_buf, int32_t *_pcm_len)
|
||||||
|
{
|
||||||
int32_t pcm_len = *_pcm_len;
|
int32_t pcm_len = *_pcm_len;
|
||||||
|
|
||||||
#if defined(BT_SCO_CHAIN_PROFILE)
|
#if defined(BT_SCO_CHAIN_PROFILE)
|
||||||
|
@ -1448,7 +1400,8 @@ int32_t _speech_rx_process_(void *pcm_buf, int32_t *_pcm_len) {
|
||||||
#if defined(SPEECH_RX_NS2)
|
#if defined(SPEECH_RX_NS2)
|
||||||
// fix 0dB signal
|
// fix 0dB signal
|
||||||
int16_t *pcm_buf16 = (int16_t *)pcm_buf;
|
int16_t *pcm_buf16 = (int16_t *)pcm_buf;
|
||||||
for (int i = 0; i < pcm_len; i++) {
|
for(int i=0; i<pcm_len; i++)
|
||||||
|
{
|
||||||
pcm_buf16[i] = (int16_t)(pcm_buf16[i] * 0.94);
|
pcm_buf16[i] = (int16_t)(pcm_buf16[i] * 0.94);
|
||||||
}
|
}
|
||||||
speech_ns2_process(speech_rx_ns2_st, pcm_buf, pcm_len);
|
speech_ns2_process(speech_rx_ns2_st, pcm_buf, pcm_len);
|
||||||
|
@ -1457,7 +1410,8 @@ int32_t _speech_rx_process_(void *pcm_buf, int32_t *_pcm_len) {
|
||||||
#if defined(SPEECH_RX_NS2FLOAT)
|
#if defined(SPEECH_RX_NS2FLOAT)
|
||||||
// FIXME
|
// FIXME
|
||||||
int16_t *pcm_buf16 = (int16_t *)pcm_buf;
|
int16_t *pcm_buf16 = (int16_t *)pcm_buf;
|
||||||
for (int i = 0; i < pcm_len; i++) {
|
for(int i=0; i<pcm_len; i++)
|
||||||
|
{
|
||||||
pcm_buf16[i] = (int16_t)(pcm_buf16[i] * 0.94);
|
pcm_buf16[i] = (int16_t)(pcm_buf16[i] * 0.94);
|
||||||
}
|
}
|
||||||
speech_ns2float_process(speech_rx_ns2float_st, pcm_buf, pcm_len);
|
speech_ns2float_process(speech_rx_ns2float_st, pcm_buf, pcm_len);
|
||||||
|
@ -1505,24 +1459,24 @@ int32_t _speech_rx_process_(void *pcm_buf, int32_t *_pcm_len) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int speech_tx_process(void *pcm_buf, void *ref_buf, int *pcm_len) {
|
int speech_tx_process(void *pcm_buf, void *ref_buf, int *pcm_len)
|
||||||
|
{
|
||||||
if (speech_tx_frame_resizer_enable == false) {
|
if (speech_tx_frame_resizer_enable == false) {
|
||||||
_speech_tx_process_(pcm_buf, ref_buf, (int32_t *)pcm_len);
|
_speech_tx_process_(pcm_buf, ref_buf, (int32_t *)pcm_len);
|
||||||
} else {
|
} else {
|
||||||
// MUST use (int32_t *)??????
|
// MUST use (int32_t *)??????
|
||||||
frame_resize_process_capture(speech_frame_resize_st, pcm_buf, ref_buf,
|
frame_resize_process_capture(speech_frame_resize_st, pcm_buf, ref_buf, (int32_t *)pcm_len);
|
||||||
(int32_t *)pcm_len);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int speech_rx_process(void *pcm_buf, int *pcm_len) {
|
int speech_rx_process(void *pcm_buf, int *pcm_len)
|
||||||
|
{
|
||||||
if (speech_rx_frame_resizer_enable == false) {
|
if (speech_rx_frame_resizer_enable == false) {
|
||||||
_speech_rx_process_(pcm_buf, (int32_t *)pcm_len);
|
_speech_rx_process_(pcm_buf, (int32_t *)pcm_len);
|
||||||
} else {
|
} else {
|
||||||
frame_resize_process_playback(speech_frame_resize_st, pcm_buf,
|
frame_resize_process_playback(speech_frame_resize_st, pcm_buf, (int32_t *)pcm_len);
|
||||||
(int32_t *)pcm_len);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -13,13 +13,11 @@
|
||||||
* trademark and other intellectual property rights.
|
* trademark and other intellectual property rights.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include "bt_sco_chain_cfg.h"
|
|
||||||
#include "plat_types.h"
|
#include "plat_types.h"
|
||||||
|
#include "bt_sco_chain_cfg.h"
|
||||||
|
|
||||||
#if defined(SPEECH_TX_2MIC_NS4)
|
#if defined(SPEECH_TX_2MIC_NS4)
|
||||||
static float ff_fb_h[256] = {
|
static float ff_fb_h[256] = {1.f, };
|
||||||
1.f,
|
|
||||||
};
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SPEECH_TX_MIC_CALIBRATION)
|
#if defined(SPEECH_TX_MIC_CALIBRATION)
|
||||||
|
@ -29,22 +27,28 @@ static float ff_fb_h[256] = {
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* bypass(0/1): bypass enable or disable.
|
* bypass(0/1): bypass enable or disable.
|
||||||
* mic_num(1~4): the number of microphones. The filter num is (mic_num - 1)
|
* mic_num(1~4): the number of microphones. The filter num is (mic_num - 1)
|
||||||
* calib: {bypass, gain, num, {type, frequency, gain, q}}. Please refer to
|
* calib: {bypass, gain, num, {type, frequency, gain, q}}. Please refer to SPEECH_TX_EQ section
|
||||||
*SPEECH_TX_EQ section in this file Resource consumption: RAM: None FLASE:
|
* in this file
|
||||||
*None MIPS: fs = 16kHz, 0.5M/section; Note: None
|
* Resource consumption:
|
||||||
|
* RAM: None
|
||||||
|
* FLASE: None
|
||||||
|
* MIPS: fs = 16kHz, 0.5M/section;
|
||||||
|
* Note:
|
||||||
|
* None
|
||||||
****************************************************************************************************/
|
****************************************************************************************************/
|
||||||
const SpeechIirCalibConfig WEAK speech_tx_mic_calib_cfg = {
|
const SpeechIirCalibConfig WEAK speech_tx_mic_calib_cfg =
|
||||||
|
{
|
||||||
.bypass = 0,
|
.bypass = 0,
|
||||||
.mic_num = 2,
|
.mic_num = 2,
|
||||||
.calib =
|
.calib = {
|
||||||
{
|
{
|
||||||
{.bypass = 0,
|
.bypass = 0,
|
||||||
.gain = 0.f,
|
.gain = 0.f,
|
||||||
.num = 0,
|
.num = 0,
|
||||||
.params =
|
.params = {
|
||||||
{
|
|
||||||
{IIR_BIQUARD_LOWSHELF, 150, -2.5, 0.707},
|
{IIR_BIQUARD_LOWSHELF, 150, -2.5, 0.707},
|
||||||
}},
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@ -64,15 +68,13 @@ const SpeechIirCalibConfig WEAK speech_tx_mic_calib_cfg = {
|
||||||
* Note:
|
* Note:
|
||||||
* None
|
* None
|
||||||
****************************************************************************************************/
|
****************************************************************************************************/
|
||||||
float mic2_ft_caliration[256] = {
|
float mic2_ft_caliration[256] = {1.f, };
|
||||||
1.f,
|
const SpeechFirCalibConfig WEAK speech_tx_mic_fir_calib_cfg =
|
||||||
};
|
{
|
||||||
const SpeechFirCalibConfig WEAK speech_tx_mic_fir_calib_cfg = {
|
|
||||||
.bypass = 0,
|
.bypass = 0,
|
||||||
.mic_num = SPEECH_CODEC_CAPTURE_CHANNEL_NUM,
|
.mic_num = SPEECH_CODEC_CAPTURE_CHANNEL_NUM,
|
||||||
.delay = 0,
|
.delay = 0,
|
||||||
.calib =
|
.calib = {
|
||||||
{
|
|
||||||
{
|
{
|
||||||
.filter = mic2_ft_caliration,
|
.filter = mic2_ft_caliration,
|
||||||
.filter_length = ARRAY_SIZE(mic2_ft_caliration),
|
.filter_length = ARRAY_SIZE(mic2_ft_caliration),
|
||||||
|
@ -84,8 +86,7 @@ const SpeechFirCalibConfig WEAK speech_tx_mic_fir_calib_cfg = {
|
||||||
const SpeechConfig WEAK speech_cfg_default = {
|
const SpeechConfig WEAK speech_cfg_default = {
|
||||||
|
|
||||||
#if defined(SPEECH_TX_DC_FILTER)
|
#if defined(SPEECH_TX_DC_FILTER)
|
||||||
.tx_dc_filter =
|
.tx_dc_filter = {
|
||||||
{
|
|
||||||
.bypass = 0,
|
.bypass = 0,
|
||||||
.gain = 0,
|
.gain = 0,
|
||||||
},
|
},
|
||||||
|
@ -98,16 +99,19 @@ const SpeechConfig WEAK speech_cfg_default = {
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* bypass(0/1): bypass enable or disable.
|
* bypass(0/1): bypass enable or disable.
|
||||||
* delay(>0): delay samples from mic to speak, unit(sample).
|
* delay(>0): delay samples from mic to speak, unit(sample).
|
||||||
* leak_estimate(0~32767): echo supression value. This is a fixed mode.
|
* leak_estimate(0~32767): echo supression value. This is a fixed mode. It has relatively large
|
||||||
*It has relatively large echo supression and large damage to speech signal.
|
* echo supression and large damage to speech signal.
|
||||||
* leak_estimate_shift(0~8): echo supression value. if leak_estimate ==
|
* leak_estimate_shift(0~8): echo supression value. if leak_estimate == 0, then leak_estimate_shift
|
||||||
*0, then leak_estimate_shift can take effect. This is a adaptive mode. It
|
* can take effect. This is a adaptive mode. It has relatively small echo supression and also
|
||||||
*has relatively small echo supression and also small damage to speech
|
* small damage to speech signal.
|
||||||
*signal. Resource consumption: RAM: None FLASE: None MIPS: fs =
|
* Resource consumption:
|
||||||
*16kHz, 40M; Note: If possible, use SPEECH_TX_AEC2FLOAT
|
* RAM: None
|
||||||
|
* FLASE: None
|
||||||
|
* MIPS: fs = 16kHz, 40M;
|
||||||
|
* Note:
|
||||||
|
* If possible, use SPEECH_TX_AEC2FLOAT
|
||||||
****************************************************************************************************/
|
****************************************************************************************************/
|
||||||
.tx_aec =
|
.tx_aec = {
|
||||||
{
|
|
||||||
.bypass = 0,
|
.bypass = 0,
|
||||||
.delay = 60,
|
.delay = 60,
|
||||||
.leak_estimate = 16383,
|
.leak_estimate = 16383,
|
||||||
|
@ -131,8 +135,7 @@ const SpeechConfig WEAK speech_cfg_default = {
|
||||||
* Note:
|
* Note:
|
||||||
* If possible, use SPEECH_TX_AEC2FLOAT
|
* If possible, use SPEECH_TX_AEC2FLOAT
|
||||||
****************************************************************************************************/
|
****************************************************************************************************/
|
||||||
.tx_aec2 =
|
.tx_aec2 = {
|
||||||
{
|
|
||||||
.bypass = 0,
|
.bypass = 0,
|
||||||
.enEAecEnable = 1,
|
.enEAecEnable = 1,
|
||||||
.enHpfEnable = 1,
|
.enHpfEnable = 1,
|
||||||
|
@ -154,23 +157,26 @@ const SpeechConfig WEAK speech_cfg_default = {
|
||||||
* Acoustic Echo Cancellation
|
* Acoustic Echo Cancellation
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* bypass(0/1): bypass enable or disable.
|
* bypass(0/1): bypass enable or disable.
|
||||||
* hpf_enabled(0/1): high pass filter enable or disable. Used to remove
|
* hpf_enabled(0/1): high pass filter enable or disable. Used to remove DC for Near and Ref signals.
|
||||||
*DC for Near and Ref signals. af_enabled(0/1): adaptive filter enable or
|
* af_enabled(0/1): adaptive filter enable or disable. If the echo signal is very large, enable this
|
||||||
*disable. If the echo signal is very large, enable this nlp_enabled(0/1):
|
* nlp_enabled(0/1): non-linear process enable or disable. Enable this by default.
|
||||||
*non-linear process enable or disable. Enable this by default.
|
* ns_enabled(0/1): noise supression enable or disable. Enable this by default.
|
||||||
* ns_enabled(0/1): noise supression enable or disable. Enable this by
|
* cng_enabled(0/1): comfort noise generator enable or disable.
|
||||||
*default. cng_enabled(0/1): comfort noise generator enable or disable.
|
|
||||||
* blocks(1~8): the length of adaptive filter = blocks * frame length
|
* blocks(1~8): the length of adaptive filter = blocks * frame length
|
||||||
* delay(>0): delay samples from mic to speak, unit(sample).
|
* delay(>0): delay samples from mic to speak, unit(sample).
|
||||||
* min_ovrd(1~6): supression factor, min_ovrd becomes larger and echo
|
* min_ovrd(1~6): supression factor, min_ovrd becomes larger and echo suppression becomes larger.
|
||||||
*suppression becomes larger. target_supp(<0): target echo suppression,
|
* target_supp(<0): target echo suppression, unit(dB)
|
||||||
*unit(dB) noise_supp(-30~0): noise suppression, unit(dB) cng_type(0/1):
|
* noise_supp(-30~0): noise suppression, unit(dB)
|
||||||
*noise type(0: White noise; 1: Pink noise) cng_level(<0): noise gain,
|
* cng_type(0/1): noise type(0: White noise; 1: Pink noise)
|
||||||
*unit(dB) Resource consumption: RAM: None FLASE: None MIPS: fs =
|
* cng_level(<0): noise gain, unit(dB)
|
||||||
*16kHz; Note: This is the recommended AEC
|
* Resource consumption:
|
||||||
|
* RAM: None
|
||||||
|
* FLASE: None
|
||||||
|
* MIPS: fs = 16kHz;
|
||||||
|
* Note:
|
||||||
|
* This is the recommended AEC
|
||||||
****************************************************************************************************/
|
****************************************************************************************************/
|
||||||
.tx_aec2float =
|
.tx_aec2float = {
|
||||||
{
|
|
||||||
.bypass = 0,
|
.bypass = 0,
|
||||||
.hpf_enabled = false,
|
.hpf_enabled = false,
|
||||||
.af_enabled = false,
|
.af_enabled = false,
|
||||||
|
@ -192,8 +198,7 @@ const SpeechConfig WEAK speech_cfg_default = {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SPEECH_TX_AEC3)
|
#if defined(SPEECH_TX_AEC3)
|
||||||
.tx_aec3 =
|
.tx_aec3 = {
|
||||||
{
|
|
||||||
.bypass = 0,
|
.bypass = 0,
|
||||||
.filter_size = 16,
|
.filter_size = 16,
|
||||||
},
|
},
|
||||||
|
@ -212,8 +217,7 @@ const SpeechConfig WEAK speech_cfg_default = {
|
||||||
* Note:
|
* Note:
|
||||||
* None
|
* None
|
||||||
****************************************************************************************************/
|
****************************************************************************************************/
|
||||||
.tx_2mic_ns =
|
.tx_2mic_ns = {
|
||||||
{
|
|
||||||
.bypass = 0,
|
.bypass = 0,
|
||||||
.alpha_h = 0.8,
|
.alpha_h = 0.8,
|
||||||
.alpha_slow = 0.9,
|
.alpha_slow = 0.9,
|
||||||
|
@ -235,16 +239,20 @@ const SpeechConfig WEAK speech_cfg_default = {
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* bypass(0/1): bypass enable or disable.
|
* bypass(0/1): bypass enable or disable.
|
||||||
* delay_taps(0~4): ceil{[d(MIC1~mouth) - d(MIC2~mouth)] / 2}.
|
* delay_taps(0~4): ceil{[d(MIC1~mouth) - d(MIC2~mouth)] / 2}.
|
||||||
* ceil: Returns the largest integer less than or equal to the
|
* ceil: Returns the largest integer less than or equal to the specified data
|
||||||
*specified data d(MIC~mouth): The dinstance from MIC to mouth e.g. 0:
|
* d(MIC~mouth): The dinstance from MIC to mouth
|
||||||
*0~2cm; 1: 2~4; 2: 5~6... freq_smooth_enable(1): Must enable
|
* e.g. 0: 0~2cm; 1: 2~4; 2: 5~6...
|
||||||
* wnr_enable(0/1): wind noise reduction enable or disable. This is also
|
* freq_smooth_enable(1): Must enable
|
||||||
*useful for improving noise suppression, but it also has some damage to
|
* wnr_enable(0/1): wind noise reduction enable or disable. This is also useful for improving
|
||||||
*speech signal. Resource consumption: RAM: None FLASE: None MIPS: fs
|
* noise suppression, but it also has some damage to speech signal.
|
||||||
*= 16kHz, 32M; Note: None
|
* Resource consumption:
|
||||||
|
* RAM: None
|
||||||
|
* FLASE: None
|
||||||
|
* MIPS: fs = 16kHz, 32M;
|
||||||
|
* Note:
|
||||||
|
* None
|
||||||
****************************************************************************************************/
|
****************************************************************************************************/
|
||||||
.tx_2mic_ns2 =
|
.tx_2mic_ns2 = {
|
||||||
{
|
|
||||||
.bypass = 0,
|
.bypass = 0,
|
||||||
.delay_taps = 0.f,
|
.delay_taps = 0.f,
|
||||||
.freq_smooth_enable = 1,
|
.freq_smooth_enable = 1,
|
||||||
|
@ -258,19 +266,23 @@ const SpeechConfig WEAK speech_cfg_default = {
|
||||||
* 2 MICs Noise Suppression
|
* 2 MICs Noise Suppression
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* bypass(0/1): bypass enable or disable.
|
* bypass(0/1): bypass enable or disable.
|
||||||
* delay_taps(0~4): ceil{[d(MIC1~mouth) - d(MIC2~mouth)] / 2}. Default
|
* delay_taps(0~4): ceil{[d(MIC1~mouth) - d(MIC2~mouth)] / 2}. Default as 0
|
||||||
*as 0 ceil: Returns the largest integer less than or equal to the specified
|
* ceil: Returns the largest integer less than or equal to the specified data
|
||||||
*data d(MIC~mouth): The dinstance from MIC to mouth e.g. 0: 0~2cm; 1: 2~4;
|
* d(MIC~mouth): The dinstance from MIC to mouth
|
||||||
*2: 5~6... freq_smooth_enable(1): Must enable wnr_enable(0/1): wind noise
|
* e.g. 0: 0~2cm; 1: 2~4; 2: 5~6...
|
||||||
*reduction enable or disable. This is also useful for improving noise
|
* freq_smooth_enable(1): Must enable
|
||||||
*suppression, but it also has some damage to speech signal.
|
* wnr_enable(0/1): wind noise reduction enable or disable. This is also useful for improving
|
||||||
* delay_enable(0/1): enable the delay_taps or not. Ideally, never need
|
* noise suppression, but it also has some damage to speech signal.
|
||||||
*to enable the delay and delay_taps will be a useless parameter. Resource
|
* delay_enable(0/1): enable the delay_taps or not. Ideally, never need to enable the delay and
|
||||||
*consumption: RAM: None FLASE: None MIPS: fs = 16kHz, 32M; Note:
|
* delay_taps will be a useless parameter.
|
||||||
|
* Resource consumption:
|
||||||
|
* RAM: None
|
||||||
|
* FLASE: None
|
||||||
|
* MIPS: fs = 16kHz, 32M;
|
||||||
|
* Note:
|
||||||
* None
|
* None
|
||||||
****************************************************************************************************/
|
****************************************************************************************************/
|
||||||
.tx_2mic_ns5 =
|
.tx_2mic_ns5 = {
|
||||||
{
|
|
||||||
.bypass = 0,
|
.bypass = 0,
|
||||||
.delay_taps = 0.0f,
|
.delay_taps = 0.0f,
|
||||||
.freq_smooth_enable = 1,
|
.freq_smooth_enable = 1,
|
||||||
|
@ -292,8 +304,7 @@ const SpeechConfig WEAK speech_cfg_default = {
|
||||||
* Note:
|
* Note:
|
||||||
* None
|
* None
|
||||||
****************************************************************************************************/
|
****************************************************************************************************/
|
||||||
.tx_2mic_ns4 =
|
.tx_2mic_ns4 = {
|
||||||
{
|
|
||||||
.bypass = 0,
|
.bypass = 0,
|
||||||
.blend_en = 1,
|
.blend_en = 1,
|
||||||
// .left_gain = 1.0f,
|
// .left_gain = 1.0f,
|
||||||
|
@ -302,14 +313,10 @@ const SpeechConfig WEAK speech_cfg_default = {
|
||||||
.delay_tapsS = 0,
|
.delay_tapsS = 0,
|
||||||
// .delay_tapsC = 32,
|
// .delay_tapsC = 32,
|
||||||
//////////////////////////{{a0,a1,a2,a3,a4},{b0,b1,b2,b3,b4}}///////////////////////////
|
//////////////////////////{{a0,a1,a2,a3,a4},{b0,b1,b2,b3,b4}}///////////////////////////
|
||||||
// .coefH[0] = {1.0, -1.88561808316413, 1.55555555555556,
|
// .coefH[0] = {1.0, -1.88561808316413, 1.55555555555556, -0.628539361054709, 0.111111111111111},
|
||||||
// -0.628539361054709, 0.111111111111111}, .coefH[1] =
|
// .coefH[1] = {0.323801506930344, -1.29520602772138, 1.94280904158206, -1.29520602772138, 0.323801506930344},
|
||||||
// {0.323801506930344, -1.29520602772138, 1.94280904158206,
|
// .coefL[0] = {1.0, -1.88561808316413, 1.55555555555556, -0.628539361054709, 0.111111111111111},
|
||||||
// -1.29520602772138, 0.323801506930344}, .coefL[0] =
|
// .coefL[1] = {0.00953182640298944, 0.0381273056119578, 0.0571909584179366, 0.0381273056119578, 0.00953182640298944},
|
||||||
// {1.0, -1.88561808316413, 1.55555555555556, -0.628539361054709,
|
|
||||||
// 0.111111111111111}, .coefL[1] = {0.00953182640298944,
|
|
||||||
// 0.0381273056119578, 0.0571909584179366, 0.0381273056119578,
|
|
||||||
// 0.00953182640298944},
|
|
||||||
.crossover_freq = 1000,
|
.crossover_freq = 1000,
|
||||||
.ff_fb_coeff = ff_fb_h,
|
.ff_fb_coeff = ff_fb_h,
|
||||||
.ff_fb_coeff_len = ARRAY_SIZE(ff_fb_h),
|
.ff_fb_coeff_len = ARRAY_SIZE(ff_fb_h),
|
||||||
|
@ -322,16 +329,19 @@ const SpeechConfig WEAK speech_cfg_default = {
|
||||||
* 3 MICs Noise Suppression
|
* 3 MICs Noise Suppression
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* bypass(0/1): bypass enable or disable.
|
* bypass(0/1): bypass enable or disable.
|
||||||
* delay_tapsM(0~4): MIC L/R delay samples. Refer to SPEECH_TX_2MIC_NS2
|
* delay_tapsM(0~4): MIC L/R delay samples. Refer to SPEECH_TX_2MIC_NS2 delay_taps
|
||||||
*delay_taps delay_tapsS(0~4): MIC L/S delay samples. Refer to
|
* delay_tapsS(0~4): MIC L/S delay samples. Refer to SPEECH_TX_2MIC_NS2 delay_taps
|
||||||
*SPEECH_TX_2MIC_NS2 delay_taps freq_smooth_enable(1): Must enable
|
* freq_smooth_enable(1): Must enable
|
||||||
* wnr_enable(0/1): wind noise reduction enable or disable. This is also
|
* wnr_enable(0/1): wind noise reduction enable or disable. This is also useful for improving
|
||||||
*useful for improving noise suppression, but it also has some damage to
|
* noise suppression, but it also has some damage to speech signal.
|
||||||
*speech signal. Resource consumption: RAM: None FLASE: None MIPS: fs
|
* Resource consumption:
|
||||||
*= 16kHz; Note: None
|
* RAM: None
|
||||||
|
* FLASE: None
|
||||||
|
* MIPS: fs = 16kHz;
|
||||||
|
* Note:
|
||||||
|
* None
|
||||||
****************************************************************************************************/
|
****************************************************************************************************/
|
||||||
.tx_3mic_ns =
|
.tx_3mic_ns = {
|
||||||
{
|
|
||||||
.bypass = 0,
|
.bypass = 0,
|
||||||
.blend_en = 1,
|
.blend_en = 1,
|
||||||
.authen_en = 1,
|
.authen_en = 1,
|
||||||
|
@ -355,16 +365,20 @@ const SpeechConfig WEAK speech_cfg_default = {
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* bypass(0/1): bypass enable or disable.
|
* bypass(0/1): bypass enable or disable.
|
||||||
* delay_taps(0~4): ceil{[d(MIC1~mouth) - d(MIC2~mouth)] / 2}.
|
* delay_taps(0~4): ceil{[d(MIC1~mouth) - d(MIC2~mouth)] / 2}.
|
||||||
* ceil: Returns the largest integer less than or equal to the
|
* ceil: Returns the largest integer less than or equal to the specified data
|
||||||
*specified data d(MIC~mouth): The dinstance from MIC to mouth e.g. 0:
|
* d(MIC~mouth): The dinstance from MIC to mouth
|
||||||
*0~2cm; 1: 2~4; 2: 5~6... freq_smooth_enable(1): Must enable
|
* e.g. 0: 0~2cm; 1: 2~4; 2: 5~6...
|
||||||
* wnr_enable(0/1): wind noise reduction enable or disable. This is also
|
* freq_smooth_enable(1): Must enable
|
||||||
*useful for improving noise suppression, but it also has some damage to
|
* wnr_enable(0/1): wind noise reduction enable or disable. This is also useful for improving
|
||||||
*speech signal. Resource consumption: RAM: None FLASE: None MIPS: fs
|
* noise suppression, but it also has some damage to speech signal.
|
||||||
*= 16kHz, 32M; Note: None
|
* Resource consumption:
|
||||||
|
* RAM: None
|
||||||
|
* FLASE: None
|
||||||
|
* MIPS: fs = 16kHz, 32M;
|
||||||
|
* Note:
|
||||||
|
* None
|
||||||
****************************************************************************************************/
|
****************************************************************************************************/
|
||||||
.tx_3mic_ns3 =
|
.tx_3mic_ns3 = {
|
||||||
{
|
|
||||||
.bypass = 0,
|
.bypass = 0,
|
||||||
.endfire_enable = 1,
|
.endfire_enable = 1,
|
||||||
.broadside_enable = 1,
|
.broadside_enable = 1,
|
||||||
|
@ -387,8 +401,7 @@ const SpeechConfig WEAK speech_cfg_default = {
|
||||||
* Note:
|
* Note:
|
||||||
* If possible, use SPEECH_TX_NS2 or SPEECH_TX_NS2FLOAT
|
* If possible, use SPEECH_TX_NS2 or SPEECH_TX_NS2FLOAT
|
||||||
****************************************************************************************************/
|
****************************************************************************************************/
|
||||||
.tx_ns =
|
.tx_ns = {
|
||||||
{
|
|
||||||
.bypass = 0,
|
.bypass = 0,
|
||||||
.denoise_dB = -12,
|
.denoise_dB = -12,
|
||||||
},
|
},
|
||||||
|
@ -411,8 +424,7 @@ const SpeechConfig WEAK speech_cfg_default = {
|
||||||
* Note:
|
* Note:
|
||||||
* None
|
* None
|
||||||
****************************************************************************************************/
|
****************************************************************************************************/
|
||||||
.tx_ns2 =
|
.tx_ns2 = {
|
||||||
{
|
|
||||||
.bypass = 0,
|
.bypass = 0,
|
||||||
.denoise_dB = -15,
|
.denoise_dB = -15,
|
||||||
},
|
},
|
||||||
|
@ -434,8 +446,7 @@ const SpeechConfig WEAK speech_cfg_default = {
|
||||||
* This is a 'float' version for SPEECH_TX_NS2.
|
* This is a 'float' version for SPEECH_TX_NS2.
|
||||||
* It needs more MIPS and RAM, but can redece quantization noise.
|
* It needs more MIPS and RAM, but can redece quantization noise.
|
||||||
****************************************************************************************************/
|
****************************************************************************************************/
|
||||||
.tx_ns2float =
|
.tx_ns2float = {
|
||||||
{
|
|
||||||
.bypass = 0,
|
.bypass = 0,
|
||||||
.denoise_dB = -15,
|
.denoise_dB = -15,
|
||||||
.banks = 64,
|
.banks = 64,
|
||||||
|
@ -456,8 +467,7 @@ const SpeechConfig WEAK speech_cfg_default = {
|
||||||
* Note:
|
* Note:
|
||||||
* None
|
* None
|
||||||
****************************************************************************************************/
|
****************************************************************************************************/
|
||||||
.tx_ns3 =
|
.tx_ns3 = {
|
||||||
{
|
|
||||||
.bypass = 0,
|
.bypass = 0,
|
||||||
.mode = NS3_SUPPRESSION_HIGH,
|
.mode = NS3_SUPPRESSION_HIGH,
|
||||||
},
|
},
|
||||||
|
@ -471,8 +481,8 @@ const SpeechConfig WEAK speech_cfg_default = {
|
||||||
* bypass(0/1): bypass enable or disable.
|
* bypass(0/1): bypass enable or disable.
|
||||||
* lpf_cutoff: lowpass filter for wind noise detection
|
* lpf_cutoff: lowpass filter for wind noise detection
|
||||||
* hpf_cutoff: highpass filter for wind noise suppression
|
* hpf_cutoff: highpass filter for wind noise suppression
|
||||||
* power_ratio_thr: ratio of the power spectrum of the lower frequencies
|
* power_ratio_thr: ratio of the power spectrum of the lower frequencies over the total power
|
||||||
over the total power spectrum for all frequencies
|
spectrum for all frequencies
|
||||||
* power_thr: normalized power of the low frequencies
|
* power_thr: normalized power of the low frequencies
|
||||||
* Resource consumption:
|
* Resource consumption:
|
||||||
* RAM: None
|
* RAM: None
|
||||||
|
@ -481,8 +491,7 @@ const SpeechConfig WEAK speech_cfg_default = {
|
||||||
* Note:
|
* Note:
|
||||||
* None
|
* None
|
||||||
****************************************************************************************************/
|
****************************************************************************************************/
|
||||||
.tx_wnr =
|
.tx_wnr = {
|
||||||
{
|
|
||||||
.bypass = 0,
|
.bypass = 0,
|
||||||
.lpf_cutoff = 1000,
|
.lpf_cutoff = 1000,
|
||||||
.hpf_cutoff = 400,
|
.hpf_cutoff = 400,
|
||||||
|
@ -497,8 +506,8 @@ const SpeechConfig WEAK speech_cfg_default = {
|
||||||
* Noise Gate
|
* Noise Gate
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* bypass(0/1): bypass enable or disable.
|
* bypass(0/1): bypass enable or disable.
|
||||||
* data_threshold(0~32767): distinguish between noise and speech,
|
* data_threshold(0~32767): distinguish between noise and speech, unit(sample).
|
||||||
*unit(sample). data_shift(1~3): 1: -6dB; 2: -12dB; 3: -18dB
|
* data_shift(1~3): 1: -6dB; 2: -12dB; 3: -18dB
|
||||||
* factor_up(float): attack time, unit(s)
|
* factor_up(float): attack time, unit(s)
|
||||||
* factor_down(float): release time, unit(s)
|
* factor_down(float): release time, unit(s)
|
||||||
* Resource consumption:
|
* Resource consumption:
|
||||||
|
@ -508,8 +517,7 @@ const SpeechConfig WEAK speech_cfg_default = {
|
||||||
* Note:
|
* Note:
|
||||||
* None
|
* None
|
||||||
****************************************************************************************************/
|
****************************************************************************************************/
|
||||||
.tx_noise_gate =
|
.tx_noise_gate = {
|
||||||
{
|
|
||||||
.bypass = 0,
|
.bypass = 0,
|
||||||
.data_threshold = 640,
|
.data_threshold = 640,
|
||||||
.data_shift = 1,
|
.data_shift = 1,
|
||||||
|
@ -532,8 +540,7 @@ const SpeechConfig WEAK speech_cfg_default = {
|
||||||
* Note:
|
* Note:
|
||||||
* None
|
* None
|
||||||
****************************************************************************************************/
|
****************************************************************************************************/
|
||||||
.tx_compexp =
|
.tx_compexp = {
|
||||||
{
|
|
||||||
.bypass = 0,
|
.bypass = 0,
|
||||||
.comp_threshold = -10.f,
|
.comp_threshold = -10.f,
|
||||||
.comp_ratio = 2.f,
|
.comp_ratio = 2.f,
|
||||||
|
@ -554,14 +561,15 @@ const SpeechConfig WEAK speech_cfg_default = {
|
||||||
* bypass(0/1): bypass enable or disable.
|
* bypass(0/1): bypass enable or disable.
|
||||||
* target_level(>0): signal can not exceed (-1 * target_level)dB.
|
* target_level(>0): signal can not exceed (-1 * target_level)dB.
|
||||||
* compression_gain(>0): excepted gain.
|
* compression_gain(>0): excepted gain.
|
||||||
* limiter_enable(0/1): 0: target_level does not take effect; 1:
|
* limiter_enable(0/1): 0: target_level does not take effect; 1: target_level takes effect.
|
||||||
*target_level takes effect. Resource consumption: RAM: None FLASE: None
|
* Resource consumption:
|
||||||
|
* RAM: None
|
||||||
|
* FLASE: None
|
||||||
* MIPS: fs = 16kHz, 3M;
|
* MIPS: fs = 16kHz, 3M;
|
||||||
* Note:
|
* Note:
|
||||||
* None
|
* None
|
||||||
****************************************************************************************************/
|
****************************************************************************************************/
|
||||||
.tx_agc =
|
.tx_agc = {
|
||||||
{
|
|
||||||
.bypass = 0,
|
.bypass = 0,
|
||||||
.target_level = 3,
|
.target_level = 3,
|
||||||
.compression_gain = 6,
|
.compression_gain = 6,
|
||||||
|
@ -577,17 +585,19 @@ const SpeechConfig WEAK speech_cfg_default = {
|
||||||
* bypass(0/1): bypass enable or disable.
|
* bypass(0/1): bypass enable or disable.
|
||||||
* gain(float): normalized gain. It is usually less than or equal to 0
|
* gain(float): normalized gain. It is usually less than or equal to 0
|
||||||
* num(0~6): the number of EQs
|
* num(0~6): the number of EQs
|
||||||
* params: {type, frequency, gain, q}. It supports a lot of types,
|
* params: {type, frequency, gain, q}. It supports a lot of types, please refer to iirfilt.h file
|
||||||
*please refer to iirfilt.h file Resource consumption: RAM: None FLASE:
|
* Resource consumption:
|
||||||
*None MIPS: fs = 16kHz, 0.5M/section; Note: None
|
* RAM: None
|
||||||
|
* FLASE: None
|
||||||
|
* MIPS: fs = 16kHz, 0.5M/section;
|
||||||
|
* Note:
|
||||||
|
* None
|
||||||
****************************************************************************************************/
|
****************************************************************************************************/
|
||||||
.tx_eq =
|
.tx_eq = {
|
||||||
{
|
|
||||||
.bypass = 0,
|
.bypass = 0,
|
||||||
.gain = 0.f,
|
.gain = 0.f,
|
||||||
.num = 1,
|
.num = 1,
|
||||||
.params =
|
.params = {
|
||||||
{
|
|
||||||
{IIR_BIQUARD_HPF, {{60, 0, 0.707f}}},
|
{IIR_BIQUARD_HPF, {{60, 0, 0.707f}}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -606,8 +616,7 @@ const SpeechConfig WEAK speech_cfg_default = {
|
||||||
* Note:
|
* Note:
|
||||||
* None
|
* None
|
||||||
****************************************************************************************************/
|
****************************************************************************************************/
|
||||||
.tx_post_gain =
|
.tx_post_gain = {
|
||||||
{
|
|
||||||
.bypass = 0,
|
.bypass = 0,
|
||||||
.gain_dB = 6.0f,
|
.gain_dB = 6.0f,
|
||||||
},
|
},
|
||||||
|
@ -641,8 +650,7 @@ const SpeechConfig WEAK speech_cfg_default = {
|
||||||
* Note:
|
* Note:
|
||||||
* None
|
* None
|
||||||
****************************************************************************************************/
|
****************************************************************************************************/
|
||||||
.rx_ns =
|
.rx_ns = {
|
||||||
{
|
|
||||||
.bypass = 0,
|
.bypass = 0,
|
||||||
.denoise_dB = -12,
|
.denoise_dB = -12,
|
||||||
},
|
},
|
||||||
|
@ -657,8 +665,7 @@ const SpeechConfig WEAK speech_cfg_default = {
|
||||||
* Note:
|
* Note:
|
||||||
* None
|
* None
|
||||||
****************************************************************************************************/
|
****************************************************************************************************/
|
||||||
.rx_ns2 =
|
.rx_ns2 = {
|
||||||
{
|
|
||||||
.bypass = 0,
|
.bypass = 0,
|
||||||
.denoise_dB = -15,
|
.denoise_dB = -15,
|
||||||
},
|
},
|
||||||
|
@ -673,8 +680,7 @@ const SpeechConfig WEAK speech_cfg_default = {
|
||||||
* Note:
|
* Note:
|
||||||
* None
|
* None
|
||||||
****************************************************************************************************/
|
****************************************************************************************************/
|
||||||
.rx_ns2float =
|
.rx_ns2float = {
|
||||||
{
|
|
||||||
.bypass = 0,
|
.bypass = 0,
|
||||||
.denoise_dB = -15,
|
.denoise_dB = -15,
|
||||||
.banks = 64,
|
.banks = 64,
|
||||||
|
@ -690,8 +696,7 @@ const SpeechConfig WEAK speech_cfg_default = {
|
||||||
* Note:
|
* Note:
|
||||||
* None
|
* None
|
||||||
****************************************************************************************************/
|
****************************************************************************************************/
|
||||||
.rx_ns3 =
|
.rx_ns3 = {
|
||||||
{
|
|
||||||
.bypass = 0,
|
.bypass = 0,
|
||||||
.mode = NS3_SUPPRESSION_HIGH,
|
.mode = NS3_SUPPRESSION_HIGH,
|
||||||
},
|
},
|
||||||
|
@ -706,8 +711,7 @@ const SpeechConfig WEAK speech_cfg_default = {
|
||||||
* Note:
|
* Note:
|
||||||
* None
|
* None
|
||||||
****************************************************************************************************/
|
****************************************************************************************************/
|
||||||
.rx_noise_gate =
|
.rx_noise_gate = {
|
||||||
{
|
|
||||||
.bypass = 0,
|
.bypass = 0,
|
||||||
.data_threshold = 640,
|
.data_threshold = 640,
|
||||||
.data_shift = 1,
|
.data_shift = 1,
|
||||||
|
@ -725,8 +729,7 @@ const SpeechConfig WEAK speech_cfg_default = {
|
||||||
* Note:
|
* Note:
|
||||||
* None
|
* None
|
||||||
****************************************************************************************************/
|
****************************************************************************************************/
|
||||||
.rx_compexp =
|
.rx_compexp = {
|
||||||
{
|
|
||||||
.bypass = 0,
|
.bypass = 0,
|
||||||
.comp_threshold = -10.f,
|
.comp_threshold = -10.f,
|
||||||
.comp_slope = 0.5f,
|
.comp_slope = 0.5f,
|
||||||
|
@ -748,8 +751,7 @@ const SpeechConfig WEAK speech_cfg_default = {
|
||||||
* Note:
|
* Note:
|
||||||
* None
|
* None
|
||||||
****************************************************************************************************/
|
****************************************************************************************************/
|
||||||
.rx_agc =
|
.rx_agc = {
|
||||||
{
|
|
||||||
.bypass = 0,
|
.bypass = 0,
|
||||||
.target_level = 3,
|
.target_level = 3,
|
||||||
.compression_gain = 6,
|
.compression_gain = 6,
|
||||||
|
@ -766,13 +768,11 @@ const SpeechConfig WEAK speech_cfg_default = {
|
||||||
* Note:
|
* Note:
|
||||||
* None
|
* None
|
||||||
****************************************************************************************************/
|
****************************************************************************************************/
|
||||||
.rx_eq =
|
.rx_eq = {
|
||||||
{
|
|
||||||
.bypass = 0,
|
.bypass = 0,
|
||||||
.gain = 0.f,
|
.gain = 0.f,
|
||||||
.num = 1,
|
.num = 1,
|
||||||
.params =
|
.params = {
|
||||||
{
|
|
||||||
{IIR_BIQUARD_HPF, {{60, 0, 0.707f}}},
|
{IIR_BIQUARD_HPF, {{60, 0, 0.707f}}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -787,8 +787,7 @@ const SpeechConfig WEAK speech_cfg_default = {
|
||||||
* Note:
|
* Note:
|
||||||
* None
|
* None
|
||||||
****************************************************************************************************/
|
****************************************************************************************************/
|
||||||
.rx_post_gain =
|
.rx_post_gain = {
|
||||||
{
|
|
||||||
.bypass = 0,
|
.bypass = 0,
|
||||||
.gain_dB = 6.0f,
|
.gain_dB = 6.0f,
|
||||||
},
|
},
|
||||||
|
|
|
@ -17,18 +17,14 @@
|
||||||
* Usage:
|
* Usage:
|
||||||
* 1. Enable SCO_CP_ACCEL ?= 1 to enable dual core in sco
|
* 1. Enable SCO_CP_ACCEL ?= 1 to enable dual core in sco
|
||||||
* 2. Enable SCO_TRACE_CP_ACCEL ?= 1 to see debug log.
|
* 2. Enable SCO_TRACE_CP_ACCEL ?= 1 to see debug log.
|
||||||
* 3. Change channel number if the algo(run in cp) input is more than one
|
* 3. Change channel number if the algo(run in cp) input is more than one channel: sco_cp_init(speech_tx_frame_len, 1);
|
||||||
*channel: sco_cp_init(speech_tx_frame_len, 1);
|
* 4. The code between SCO_CP_ACCEL_ALGO_START(); and SCO_CP_ACCEL_ALGO_END(); will run in CP core.
|
||||||
* 4. The code between SCO_CP_ACCEL_ALGO_START(); and SCO_CP_ACCEL_ALGO_END();
|
* 5. These algorithms will work in AP. Need to move this algorithms from overlay to fast ram.
|
||||||
*will run in CP core.
|
|
||||||
* 5. These algorithms will work in AP. Need to move this algorithms from
|
|
||||||
*overlay to fast ram.
|
|
||||||
*
|
*
|
||||||
* NOTE:
|
* NOTE:
|
||||||
* 1. spx fft and hw fft will share buffer, so just one core can use these
|
* 1. spx fft and hw fft will share buffer, so just one core can use these fft.
|
||||||
*fft.
|
* 2. audio_dump_add_channel_data function can not work correctly in CP core, because
|
||||||
* 2. audio_dump_add_channel_data function can not work correctly in CP core,
|
* audio_dump_add_channel_data is possible called after audio_dump_run();
|
||||||
*because audio_dump_add_channel_data is possible called after audio_dump_run();
|
|
||||||
* 3. AP and CP just can use 85%
|
* 3. AP and CP just can use 85%
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
@ -37,14 +33,14 @@
|
||||||
* 1. FFT, RAM, CODE overlay
|
* 1. FFT, RAM, CODE overlay
|
||||||
**/
|
**/
|
||||||
#if defined(SCO_CP_ACCEL)
|
#if defined(SCO_CP_ACCEL)
|
||||||
#include "cmsis_os.h"
|
|
||||||
#include "cp_accel.h"
|
#include "cp_accel.h"
|
||||||
#include "hal_location.h"
|
#include "hal_location.h"
|
||||||
#include "hal_timer.h"
|
|
||||||
#include "hal_trace.h"
|
#include "hal_trace.h"
|
||||||
|
#include "hal_timer.h"
|
||||||
|
#include "cmsis_os.h"
|
||||||
|
#include "speech_cfg.h"
|
||||||
#include "math.h"
|
#include "math.h"
|
||||||
#include "norflash_api.h"
|
#include "norflash_api.h"
|
||||||
#include "speech_cfg.h"
|
|
||||||
|
|
||||||
// malloc data from pool in init function
|
// malloc data from pool in init function
|
||||||
#define FRAME_LEN_MAX (256)
|
#define FRAME_LEN_MAX (256)
|
||||||
|
@ -78,21 +74,20 @@ static CP_BSS_LOC int g_channel_num;
|
||||||
static int g_require_cnt = 0;
|
static int g_require_cnt = 0;
|
||||||
static int g_run_cnt = 0;
|
static int g_run_cnt = 0;
|
||||||
|
|
||||||
int sco_cp_process(short *pcm_buf, short *ref_buf, int *_pcm_len) {
|
int sco_cp_process(short *pcm_buf, short *ref_buf, int *_pcm_len)
|
||||||
|
{
|
||||||
int32_t pcm_len = *_pcm_len;
|
int32_t pcm_len = *_pcm_len;
|
||||||
uint32_t wait_cnt = 0;
|
uint32_t wait_cnt = 0;
|
||||||
|
|
||||||
ASSERT(g_frame_len * g_channel_num == pcm_len,
|
ASSERT(g_frame_len * g_channel_num == pcm_len, "[%s] g_frame_len(%d) * g_channel_num(%d) != pcm_len(%d)", __func__, g_frame_len, g_channel_num, pcm_len);
|
||||||
"[%s] g_frame_len(%d) * g_channel_num(%d) != pcm_len(%d)", __func__,
|
|
||||||
g_frame_len, g_channel_num, pcm_len);
|
|
||||||
|
|
||||||
// Check CP has new data to get and can get data from buffer
|
// Check CP has new data to get and can get data from buffer
|
||||||
#if defined(SCO_TRACE_CP_ACCEL)
|
#if defined(SCO_TRACE_CP_ACCEL)
|
||||||
TRACE(4, "[%s] g_require_cnt: %d, status: %d, pcm_len: %d", __func__,
|
TRACE(4,"[%s] g_require_cnt: %d, status: %d, pcm_len: %d", __func__, g_require_cnt, g_cp_state, pcm_len);
|
||||||
g_require_cnt, g_cp_state, pcm_len);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while (g_cp_state == CP_SCO_STATE_WORKING) {
|
while (g_cp_state == CP_SCO_STATE_WORKING)
|
||||||
|
{
|
||||||
hal_sys_timer_delay_us(10);
|
hal_sys_timer_delay_us(10);
|
||||||
|
|
||||||
if (wait_cnt++ > 300000) { // 3s
|
if (wait_cnt++ > 300000) { // 3s
|
||||||
|
@ -100,9 +95,11 @@ int sco_cp_process(short *pcm_buf, short *ref_buf, int *_pcm_len) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_cp_state == CP_SCO_STATE_IDLE) {
|
if (g_cp_state == CP_SCO_STATE_IDLE)
|
||||||
|
{
|
||||||
speech_copy_int16(g_in_pcm_buf, pcm_buf, pcm_len);
|
speech_copy_int16(g_in_pcm_buf, pcm_buf, pcm_len);
|
||||||
if (ref_buf) {
|
if (ref_buf)
|
||||||
|
{
|
||||||
speech_copy_int16(g_in_ref_buf, ref_buf, pcm_len / g_channel_num);
|
speech_copy_int16(g_in_ref_buf, ref_buf, pcm_len / g_channel_num);
|
||||||
}
|
}
|
||||||
speech_copy_int16(pcm_buf, g_out_pcm_buf, g_pcm_len);
|
speech_copy_int16(pcm_buf, g_out_pcm_buf, g_pcm_len);
|
||||||
|
@ -111,9 +108,10 @@ int sco_cp_process(short *pcm_buf, short *ref_buf, int *_pcm_len) {
|
||||||
|
|
||||||
g_require_cnt++;
|
g_require_cnt++;
|
||||||
g_cp_state = CP_SCO_STATE_WORKING;
|
g_cp_state = CP_SCO_STATE_WORKING;
|
||||||
cp_accel_send_event_mcu2cp(
|
cp_accel_send_event_mcu2cp(CP_BUILD_ID(CP_TASK_SCO, CP_EVENT_SCO_PROCESSING));
|
||||||
CP_BUILD_ID(CP_TASK_SCO, CP_EVENT_SCO_PROCESSING));
|
}
|
||||||
} else {
|
else
|
||||||
|
{
|
||||||
// Multi channels to one channel
|
// Multi channels to one channel
|
||||||
#if 0
|
#if 0
|
||||||
for (int i = 0; i < pcm_len / g_channel_num; i++)
|
for (int i = 0; i < pcm_len / g_channel_num; i++)
|
||||||
|
@ -135,7 +133,8 @@ int sco_cp_process(short *pcm_buf, short *ref_buf, int *_pcm_len) {
|
||||||
extern int sco_cp_algo(short *pcm_buf, short *ref_buf, int *_pcm_len);
|
extern int sco_cp_algo(short *pcm_buf, short *ref_buf, int *_pcm_len);
|
||||||
|
|
||||||
CP_TEXT_SRAM_LOC
|
CP_TEXT_SRAM_LOC
|
||||||
static unsigned int sco_cp_main(uint8_t event) {
|
static unsigned int sco_cp_main(uint8_t event)
|
||||||
|
{
|
||||||
#if defined(SCO_TRACE_CP_ACCEL)
|
#if defined(SCO_TRACE_CP_ACCEL)
|
||||||
TRACE(2,"[%s] g_run_cnt: %d", __func__, g_run_cnt);
|
TRACE(2,"[%s] g_run_cnt: %d", __func__, g_run_cnt);
|
||||||
#endif
|
#endif
|
||||||
|
@ -168,21 +167,17 @@ static unsigned int sco_cp_main(uint8_t event) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct cp_task_desc TASK_DESC_SCO = {CP_ACCEL_STATE_CLOSED, sco_cp_main,
|
static struct cp_task_desc TASK_DESC_SCO = {CP_ACCEL_STATE_CLOSED, sco_cp_main, NULL, NULL, NULL};
|
||||||
NULL, NULL, NULL};
|
int sco_cp_init(int frame_len, int channel_num)
|
||||||
int sco_cp_init(int frame_len, int channel_num) {
|
{
|
||||||
TRACE(3, "[%s] frame_len: %d, channel_num: %d", __func__, frame_len,
|
TRACE(3,"[%s] frame_len: %d, channel_num: %d", __func__, frame_len, channel_num);
|
||||||
channel_num);
|
ASSERT(frame_len <= FRAME_LEN_MAX, "[%s] frame_len(%d) > FRAME_LEN_MAX", __func__, frame_len);
|
||||||
ASSERT(frame_len <= FRAME_LEN_MAX, "[%s] frame_len(%d) > FRAME_LEN_MAX",
|
ASSERT(channel_num <= CHANNEL_NUM_MAX, "[%s] channel_num(%d) > CHANNEL_NUM_MAX", __func__, channel_num);
|
||||||
__func__, frame_len);
|
|
||||||
ASSERT(channel_num <= CHANNEL_NUM_MAX,
|
|
||||||
"[%s] channel_num(%d) > CHANNEL_NUM_MAX", __func__, channel_num);
|
|
||||||
|
|
||||||
g_require_cnt = 0;
|
g_require_cnt = 0;
|
||||||
g_run_cnt = 0;
|
g_run_cnt = 0;
|
||||||
|
|
||||||
norflash_api_flush_disable(NORFLASH_API_USER_CP,
|
norflash_api_flush_disable(NORFLASH_API_USER_CP,(uint32_t)cp_accel_init_done);
|
||||||
(uint32_t)cp_accel_init_done);
|
|
||||||
cp_accel_open(CP_TASK_SCO, &TASK_DESC_SCO);
|
cp_accel_open(CP_TASK_SCO, &TASK_DESC_SCO);
|
||||||
|
|
||||||
uint32_t cnt=0;
|
uint32_t cnt=0;
|
||||||
|
@ -217,9 +212,11 @@ int sco_cp_init(int frame_len, int channel_num) {
|
||||||
TRACE(2,"[%s] status = %d", __func__, g_cp_state);
|
TRACE(2,"[%s] status = %d", __func__, g_cp_state);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int sco_cp_deinit(void) {
|
int sco_cp_deinit(void)
|
||||||
|
{
|
||||||
TRACE(1,"[%s] ...", __func__);
|
TRACE(1,"[%s] ...", __func__);
|
||||||
|
|
||||||
cp_accel_close(CP_TASK_SCO);
|
cp_accel_close(CP_TASK_SCO);
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#include "audio_dump.h"
|
|
||||||
#include "bt_sco_chain.h"
|
#include "bt_sco_chain.h"
|
||||||
#include "hal_trace.h"
|
|
||||||
#include "speech_cfg.h"
|
|
||||||
#include "speech_memory.h"
|
#include "speech_memory.h"
|
||||||
#include "speech_utils.h"
|
#include "speech_utils.h"
|
||||||
|
#include "hal_trace.h"
|
||||||
|
#include "audio_dump.h"
|
||||||
|
#include "speech_cfg.h"
|
||||||
|
|
||||||
#if defined(SPEECH_TX_24BIT)
|
#if defined(SPEECH_TX_24BIT)
|
||||||
int32_t *aec_echo_buf = NULL;
|
int32_t *aec_echo_buf = NULL;
|
||||||
|
@ -27,8 +27,11 @@ static short *aec_echo_buf_ptr;
|
||||||
SpeechDcFilterState *speech_tx_dc_filter_st = NULL;
|
SpeechDcFilterState *speech_tx_dc_filter_st = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int speech_init(int tx_sample_rate, int rx_sample_rate, int tx_frame_ms,
|
int speech_init(int tx_sample_rate, int rx_sample_rate,
|
||||||
int rx_frame_ms, int sco_frame_ms, uint8_t *buf, int len) {
|
int tx_frame_ms, int rx_frame_ms,
|
||||||
|
int sco_frame_ms,
|
||||||
|
uint8_t *buf, int len)
|
||||||
|
{
|
||||||
// we shoule keep a minmum buffer for speech heap
|
// we shoule keep a minmum buffer for speech heap
|
||||||
// MSBC_16K_SAMPLE_RATE = 0, 560 bytes
|
// MSBC_16K_SAMPLE_RATE = 0, 560 bytes
|
||||||
// MSBC_16K_SAMPLE_RATE = 1, 2568 bytes
|
// MSBC_16K_SAMPLE_RATE = 1, 2568 bytes
|
||||||
|
@ -58,12 +61,9 @@ int speech_init(int tx_sample_rate, int rx_sample_rate, int tx_frame_ms,
|
||||||
.gain = 0.f,
|
.gain = 0.f,
|
||||||
};
|
};
|
||||||
|
|
||||||
speech_tx_dc_filter_st =
|
speech_tx_dc_filter_st = speech_dc_filter_create(tx_sample_rate, frame_len, &dc_filter_cfg);
|
||||||
speech_dc_filter_create(tx_sample_rate, frame_len, &dc_filter_cfg);
|
speech_dc_filter_ctl(speech_tx_dc_filter_st, SPEECH_DC_FILTER_SET_CHANNEL_NUM, &channel_num);
|
||||||
speech_dc_filter_ctl(speech_tx_dc_filter_st, SPEECH_DC_FILTER_SET_CHANNEL_NUM,
|
speech_dc_filter_ctl(speech_tx_dc_filter_st, SPEECH_DC_FILTER_SET_DATA_SEPARATION, &data_separation);
|
||||||
&channel_num);
|
|
||||||
speech_dc_filter_ctl(speech_tx_dc_filter_st,
|
|
||||||
SPEECH_DC_FILTER_SET_DATA_SEPARATION, &data_separation);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
audio_dump_init(frame_len, sizeof(int16_t), 3);
|
audio_dump_init(frame_len, sizeof(int16_t), 3);
|
||||||
|
@ -71,7 +71,8 @@ int speech_init(int tx_sample_rate, int rx_sample_rate, int tx_frame_ms,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int speech_deinit(void) {
|
int speech_deinit(void)
|
||||||
|
{
|
||||||
#if defined(SPEECH_TX_DC_FILTER)
|
#if defined(SPEECH_TX_DC_FILTER)
|
||||||
speech_dc_filter_destroy(speech_tx_dc_filter_st);
|
speech_dc_filter_destroy(speech_tx_dc_filter_st);
|
||||||
#endif
|
#endif
|
||||||
|
@ -80,8 +81,7 @@ int speech_deinit(void) {
|
||||||
|
|
||||||
size_t total = 0, used = 0, max_used = 0;
|
size_t total = 0, used = 0, max_used = 0;
|
||||||
speech_memory_info(&total, &used, &max_used);
|
speech_memory_info(&total, &used, &max_used);
|
||||||
TRACE(3, "SPEECH MALLOC MEM: total - %d, used - %d, max_used - %d.", total,
|
TRACE(3,"SPEECH MALLOC MEM: total - %d, used - %d, max_used - %d.", total, used, max_used);
|
||||||
used, max_used);
|
|
||||||
ASSERT(used == 0, "[%s] used != 0", __func__);
|
ASSERT(used == 0, "[%s] used != 0", __func__);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -91,7 +91,8 @@ int speech_deinit(void) {
|
||||||
extern void bt_sco_get_tdm_buffer(uint8_t **buf, uint32_t *len);
|
extern void bt_sco_get_tdm_buffer(uint8_t **buf, uint32_t *len);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int speech_tx_process(void *_pcm_buf, void *_ref_buf, int *_pcm_len) {
|
int speech_tx_process(void *_pcm_buf, void *_ref_buf, int *_pcm_len)
|
||||||
|
{
|
||||||
#if defined(SPEECH_TX_24BIT)
|
#if defined(SPEECH_TX_24BIT)
|
||||||
int32_t *pcm_buf = (int32_t *)_pcm_buf;
|
int32_t *pcm_buf = (int32_t *)_pcm_buf;
|
||||||
int32_t *ref_buf = (int32_t *)_ref_buf;
|
int32_t *ref_buf = (int32_t *)_ref_buf;
|
||||||
|
@ -109,18 +110,12 @@ int speech_tx_process(void *_pcm_buf, void *_ref_buf, int *_pcm_len) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
audio_dump_clear_up();
|
audio_dump_clear_up();
|
||||||
audio_dump_add_channel_data(0, ref_buf,
|
audio_dump_add_channel_data(0, ref_buf, pcm_len / SPEECH_CODEC_CAPTURE_CHANNEL_NUM);
|
||||||
pcm_len / SPEECH_CODEC_CAPTURE_CHANNEL_NUM);
|
audio_dump_add_channel_data_from_multi_channels(1, pcm_buf, pcm_len / SPEECH_CODEC_CAPTURE_CHANNEL_NUM, SPEECH_CODEC_CAPTURE_CHANNEL_NUM, 0);
|
||||||
audio_dump_add_channel_data_from_multi_channels(
|
audio_dump_add_channel_data_from_multi_channels(2, pcm_buf, pcm_len / SPEECH_CODEC_CAPTURE_CHANNEL_NUM, SPEECH_CODEC_CAPTURE_CHANNEL_NUM, 1);
|
||||||
1, pcm_buf, pcm_len / SPEECH_CODEC_CAPTURE_CHANNEL_NUM,
|
|
||||||
SPEECH_CODEC_CAPTURE_CHANNEL_NUM, 0);
|
|
||||||
audio_dump_add_channel_data_from_multi_channels(
|
|
||||||
2, pcm_buf, pcm_len / SPEECH_CODEC_CAPTURE_CHANNEL_NUM,
|
|
||||||
SPEECH_CODEC_CAPTURE_CHANNEL_NUM, 1);
|
|
||||||
|
|
||||||
#if defined(BONE_SENSOR_TDM)
|
#if defined(BONE_SENSOR_TDM)
|
||||||
audio_dump_add_channel_data(3, bone_buf,
|
audio_dump_add_channel_data(3, bone_buf, pcm16_len/SPEECH_CODEC_CAPTURE_CHANNEL_NUM);
|
||||||
pcm16_len / SPEECH_CODEC_CAPTURE_CHANNEL_NUM);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
audio_dump_run();
|
audio_dump_run();
|
||||||
|
@ -135,8 +130,7 @@ int speech_tx_process(void *_pcm_buf, void *_ref_buf, int *_pcm_len) {
|
||||||
|
|
||||||
// Add your algrithm here and disable #if macro
|
// Add your algrithm here and disable #if macro
|
||||||
#if 1
|
#if 1
|
||||||
for (int i = 0, j = 0; i < pcm_len;
|
for (int i = 0, j = 0; i < pcm_len; i += SPEECH_CODEC_CAPTURE_CHANNEL_NUM, j++) {
|
||||||
i += SPEECH_CODEC_CAPTURE_CHANNEL_NUM, j++) {
|
|
||||||
// choose main microphone data
|
// choose main microphone data
|
||||||
pcm_buf[j] = pcm_buf[i];
|
pcm_buf[j] = pcm_buf[i];
|
||||||
// choose reference data, i.e. loopback
|
// choose reference data, i.e. loopback
|
||||||
|
@ -154,7 +148,8 @@ int speech_tx_process(void *_pcm_buf, void *_ref_buf, int *_pcm_len) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int speech_rx_process(void *pcm_buf, int *pcm_len) {
|
int speech_rx_process(void *pcm_buf, int *pcm_len)
|
||||||
|
{
|
||||||
// Add your algorithm here
|
// Add your algorithm here
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
|
@ -1,10 +1,10 @@
|
||||||
#include "audio_dump.h"
|
|
||||||
#include "bt_sco_chain.h"
|
#include "bt_sco_chain.h"
|
||||||
#include "hal_trace.h"
|
|
||||||
#include "speech_memory.h"
|
#include "speech_memory.h"
|
||||||
#include "speech_utils.h"
|
#include "speech_utils.h"
|
||||||
#include "spf-postapi.h"
|
#include "hal_trace.h"
|
||||||
|
#include "audio_dump.h"
|
||||||
#include "vcp-api.h"
|
#include "vcp-api.h"
|
||||||
|
#include "spf-postapi.h"
|
||||||
|
|
||||||
#define ALANGO_TRACE(s, ...) TRACE(1,"%s: " s, __FUNCTION__, ## __VA_ARGS__)
|
#define ALANGO_TRACE(s, ...) TRACE(1,"%s: " s, __FUNCTION__, ## __VA_ARGS__)
|
||||||
|
|
||||||
|
@ -28,8 +28,8 @@ mem_reg_t reg[NUM_MEM_REGIONS];
|
||||||
#if SPEECH_CODEC_CAPTURE_CHANNEL_NUM >= 2
|
#if SPEECH_CODEC_CAPTURE_CHANNEL_NUM >= 2
|
||||||
static int16_t *deinterleaved_buf = NULL;
|
static int16_t *deinterleaved_buf = NULL;
|
||||||
|
|
||||||
static void deinterleave_audio(int16_t *dst, int16_t *src, uint32_t len,
|
static void deinterleave_audio(int16_t *dst, int16_t *src, uint32_t len, uint32_t ch_num)
|
||||||
uint32_t ch_num) {
|
{
|
||||||
uint32_t samples_per_channel = len / ch_num;
|
uint32_t samples_per_channel = len / ch_num;
|
||||||
|
|
||||||
for (uint32_t i = 0; i < samples_per_channel; i++) {
|
for (uint32_t i = 0; i < samples_per_channel; i++) {
|
||||||
|
@ -40,8 +40,11 @@ static void deinterleave_audio(int16_t *dst, int16_t *src, uint32_t len,
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int speech_init(int tx_sample_rate, int rx_sample_rate, int tx_frame_ms,
|
int speech_init(int tx_sample_rate, int rx_sample_rate,
|
||||||
int rx_frame_ms, int sco_frame_ms, uint8_t *buf, int len) {
|
int tx_frame_ms, int rx_frame_ms,
|
||||||
|
int sco_frame_ms,
|
||||||
|
uint8_t *buf, int len)
|
||||||
|
{
|
||||||
speech_heap_init(buf, len);
|
speech_heap_init(buf, len);
|
||||||
|
|
||||||
int frame_len = SPEECH_FRAME_MS_TO_LEN(tx_sample_rate, tx_frame_ms);
|
int frame_len = SPEECH_FRAME_MS_TO_LEN(tx_sample_rate, tx_frame_ms);
|
||||||
|
@ -60,9 +63,7 @@ int speech_init(int tx_sample_rate, int rx_sample_rate, int tx_frame_ms,
|
||||||
ALANGO_TRACE(1,"Profile error: %d", err.err);
|
ALANGO_TRACE(1,"Profile error: %d", err.err);
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(frame_len % curr_profile->p_gen->frlen == 0,
|
ASSERT(frame_len % curr_profile->p_gen->frlen == 0, "Profile error: frame_len(%d) should be divided by frlen(%d)", frame_len, curr_profile->p_gen->frlen);
|
||||||
"Profile error: frame_len(%d) should be divided by frlen(%d)",
|
|
||||||
frame_len, curr_profile->p_gen->frlen);
|
|
||||||
|
|
||||||
unsigned int smem = vcp_get_hook_size();
|
unsigned int smem = vcp_get_hook_size();
|
||||||
mem = speech_malloc(smem);
|
mem = speech_malloc(smem);
|
||||||
|
@ -73,25 +74,20 @@ int speech_init(int tx_sample_rate, int rx_sample_rate, int tx_frame_ms,
|
||||||
|
|
||||||
for (int i = 0; i < NUM_MEM_REGIONS; i++) {
|
for (int i = 0; i < NUM_MEM_REGIONS; i++) {
|
||||||
reg[i].mem = (void *)speech_malloc(reg[i].size);
|
reg[i].mem = (void *)speech_malloc(reg[i].size);
|
||||||
ALANGO_TRACE(2, "I need %d bytes of memory in memory region %d to work.\n",
|
ALANGO_TRACE(2,"I need %d bytes of memory in memory region %d to work.\n", reg[i].size, i + 1);
|
||||||
reg[i].size, i + 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = vcp_init_debug(curr_profile, reg);
|
err = vcp_init_debug(curr_profile, reg);
|
||||||
if (err.err == ERR_NOT_ENOUGH_MEMORY) {
|
if (err.err == ERR_NOT_ENOUGH_MEMORY) {
|
||||||
ALANGO_TRACE(2, "%d more bytes needed in region %d!\n", -reg[err.pid].size,
|
ALANGO_TRACE(2,"%d more bytes needed in region %d!\n", -reg[err.pid].size, err.pid);
|
||||||
err.pid);
|
|
||||||
} else if (err.err == ERR_UNKNOWN) {
|
} else if (err.err == ERR_UNKNOWN) {
|
||||||
ALANGO_TRACE(0,"vcp_init_debug() returns UNKNOWN error\n!");
|
ALANGO_TRACE(0,"vcp_init_debug() returns UNKNOWN error\n!");
|
||||||
} else if (err.err != ERR_NO_ERROR) {
|
} else if (err.err != ERR_NO_ERROR) {
|
||||||
ALANGO_TRACE(2, "vcp_init_debug() returns error %d, pid %d!\n", err.err,
|
ALANGO_TRACE(2,"vcp_init_debug() returns error %d, pid %d!\n", err.err, err.pid);
|
||||||
err.pid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if SPEECH_CODEC_CAPTURE_CHANNEL_NUM >= 2
|
#if SPEECH_CODEC_CAPTURE_CHANNEL_NUM >= 2
|
||||||
deinterleaved_buf =
|
deinterleaved_buf = speech_malloc(curr_profile->p_gen->frlen * SPEECH_CODEC_CAPTURE_CHANNEL_NUM * sizeof(int16_t));
|
||||||
speech_malloc(curr_profile->p_gen->frlen *
|
|
||||||
SPEECH_CODEC_CAPTURE_CHANNEL_NUM * sizeof(int16_t));
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
audio_dump_init(frame_len, sizeof(int16_t), 3);
|
audio_dump_init(frame_len, sizeof(int16_t), 3);
|
||||||
|
@ -99,7 +95,8 @@ int speech_init(int tx_sample_rate, int rx_sample_rate, int tx_frame_ms,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int speech_deinit(void) {
|
int speech_deinit(void)
|
||||||
|
{
|
||||||
speech_free(aec_echo_buf_ptr);
|
speech_free(aec_echo_buf_ptr);
|
||||||
speech_free(mem);
|
speech_free(mem);
|
||||||
|
|
||||||
|
@ -112,8 +109,7 @@ int speech_deinit(void) {
|
||||||
|
|
||||||
size_t total = 0, used = 0, max_used = 0;
|
size_t total = 0, used = 0, max_used = 0;
|
||||||
speech_memory_info(&total, &used, &max_used);
|
speech_memory_info(&total, &used, &max_used);
|
||||||
TRACE(3, "SPEECH MALLOC MEM: total - %d, used - %d, max_used - %d.", total,
|
TRACE(3,"SPEECH MALLOC MEM: total - %d, used - %d, max_used - %d.", total, used, max_used);
|
||||||
used, max_used);
|
|
||||||
ASSERT(used == 0, "[%s] used != 0", __func__);
|
ASSERT(used == 0, "[%s] used != 0", __func__);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -123,7 +119,8 @@ int speech_deinit(void) {
|
||||||
extern void bt_sco_get_tdm_buffer(uint8_t **buf, uint32_t *len);
|
extern void bt_sco_get_tdm_buffer(uint8_t **buf, uint32_t *len);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int speech_tx_process(void *pcm_buf, void *ref_buf, int *pcm_len) {
|
int speech_tx_process(void *pcm_buf, void *ref_buf, int *pcm_len)
|
||||||
|
{
|
||||||
int16_t *pcm16_buf = (int16_t *)pcm_buf;
|
int16_t *pcm16_buf = (int16_t *)pcm_buf;
|
||||||
int16_t *ref16_buf = (int16_t *)ref_buf;
|
int16_t *ref16_buf = (int16_t *)ref_buf;
|
||||||
int pcm16_len = *pcm_len;
|
int pcm16_len = *pcm_len;
|
||||||
|
@ -135,18 +132,12 @@ int speech_tx_process(void *pcm_buf, void *ref_buf, int *pcm_len) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
audio_dump_clear_up();
|
audio_dump_clear_up();
|
||||||
audio_dump_add_channel_data(0, ref_buf,
|
audio_dump_add_channel_data(0, ref_buf, pcm16_len / SPEECH_CODEC_CAPTURE_CHANNEL_NUM);
|
||||||
pcm16_len / SPEECH_CODEC_CAPTURE_CHANNEL_NUM);
|
audio_dump_add_channel_data_from_multi_channels(1, pcm16_buf, pcm16_len / SPEECH_CODEC_CAPTURE_CHANNEL_NUM, SPEECH_CODEC_CAPTURE_CHANNEL_NUM, 0);
|
||||||
audio_dump_add_channel_data_from_multi_channels(
|
audio_dump_add_channel_data_from_multi_channels(2, pcm16_buf, pcm16_len / SPEECH_CODEC_CAPTURE_CHANNEL_NUM, SPEECH_CODEC_CAPTURE_CHANNEL_NUM, 1);
|
||||||
1, pcm16_buf, pcm16_len / SPEECH_CODEC_CAPTURE_CHANNEL_NUM,
|
|
||||||
SPEECH_CODEC_CAPTURE_CHANNEL_NUM, 0);
|
|
||||||
audio_dump_add_channel_data_from_multi_channels(
|
|
||||||
2, pcm16_buf, pcm16_len / SPEECH_CODEC_CAPTURE_CHANNEL_NUM,
|
|
||||||
SPEECH_CODEC_CAPTURE_CHANNEL_NUM, 1);
|
|
||||||
|
|
||||||
#if defined(BONE_SENSOR_TDM)
|
#if defined(BONE_SENSOR_TDM)
|
||||||
audio_dump_add_channel_data(3, bone_buf,
|
audio_dump_add_channel_data(3, bone_buf, pcm16_len/SPEECH_CODEC_CAPTURE_CHANNEL_NUM);
|
||||||
pcm16_len / SPEECH_CODEC_CAPTURE_CHANNEL_NUM);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
audio_dump_run();
|
audio_dump_run();
|
||||||
|
@ -161,21 +152,13 @@ int speech_tx_process(void *pcm_buf, void *ref_buf, int *pcm_len) {
|
||||||
}
|
}
|
||||||
pcm16_len /= SPEECH_CODEC_CAPTURE_CHANNEL_NUM;
|
pcm16_len /= SPEECH_CODEC_CAPTURE_CHANNEL_NUM;
|
||||||
#else
|
#else
|
||||||
for (int i = 0, j = 0; i < pcm16_len;
|
for (int i = 0, j = 0; i < pcm16_len; i += curr_profile->p_gen->frlen * SPEECH_CODEC_CAPTURE_CHANNEL_NUM, j += curr_profile->p_gen->frlen) {
|
||||||
i += curr_profile->p_gen->frlen * SPEECH_CODEC_CAPTURE_CHANNEL_NUM,
|
|
||||||
j += curr_profile->p_gen->frlen) {
|
|
||||||
#if SPEECH_CODEC_CAPTURE_CHANNEL_NUM >= 2
|
#if SPEECH_CODEC_CAPTURE_CHANNEL_NUM >= 2
|
||||||
deinterleave_audio(deinterleaved_buf, &pcm16_buf[i],
|
deinterleave_audio(deinterleaved_buf, &pcm16_buf[i], curr_profile->p_gen->frlen * SPEECH_CODEC_CAPTURE_CHANNEL_NUM, SPEECH_CODEC_CAPTURE_CHANNEL_NUM);
|
||||||
curr_profile->p_gen->frlen *
|
err_t err = vcp_process_tx(reg, deinterleaved_buf, &ref16_buf[j], &pcm16_buf[j]);
|
||||||
SPEECH_CODEC_CAPTURE_CHANNEL_NUM,
|
//memcpy(&pcm16_buf[j], deinterleaved_buf, curr_profile->p_gen->frlen * sizeof(int16_t));
|
||||||
SPEECH_CODEC_CAPTURE_CHANNEL_NUM);
|
|
||||||
err_t err =
|
|
||||||
vcp_process_tx(reg, deinterleaved_buf, &ref16_buf[j], &pcm16_buf[j]);
|
|
||||||
// memcpy(&pcm16_buf[j], deinterleaved_buf, curr_profile->p_gen->frlen *
|
|
||||||
// sizeof(int16_t));
|
|
||||||
#else
|
#else
|
||||||
err_t err =
|
err_t err = vcp_process_tx(reg, &pcm16_buf[i], &ref16_buf[j], &pcm16_buf[j]);
|
||||||
vcp_process_tx(reg, &pcm16_buf[i], &ref16_buf[j], &pcm16_buf[j]);
|
|
||||||
#endif
|
#endif
|
||||||
if (err.err != ERR_NO_ERROR) {
|
if (err.err != ERR_NO_ERROR) {
|
||||||
ALANGO_TRACE(1,"vcp_process_tx error: %d", err.err);
|
ALANGO_TRACE(1,"vcp_process_tx error: %d", err.err);
|
||||||
|
@ -193,7 +176,8 @@ int speech_tx_process(void *pcm_buf, void *ref_buf, int *pcm_len) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int speech_rx_process(void *pcm_buf, int *pcm_len) {
|
int speech_rx_process(void *pcm_buf, int *pcm_len)
|
||||||
|
{
|
||||||
int16_t *pcm16_buf = (int16_t *)pcm_buf;
|
int16_t *pcm16_buf = (int16_t *)pcm_buf;
|
||||||
int pcm16_len = *pcm_len;
|
int pcm16_len = *pcm_len;
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
* trademark and other intellectual property rights.
|
* trademark and other intellectual property rights.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include "aud_section.h"
|
|
||||||
#include "bt_sco_chain_cfg.h"
|
#include "bt_sco_chain_cfg.h"
|
||||||
|
#include "aud_section.h"
|
||||||
#include "hal_trace.h"
|
#include "hal_trace.h"
|
||||||
|
|
||||||
static bool speech_tuning_status = false;
|
static bool speech_tuning_status = false;
|
||||||
|
@ -29,7 +29,8 @@ typedef struct {
|
||||||
|
|
||||||
static AUDIO_SECTION_SPEECH_CFG_T audio_section_speech_cfg;
|
static AUDIO_SECTION_SPEECH_CFG_T audio_section_speech_cfg;
|
||||||
|
|
||||||
int store_speech_cfg_into_audio_section(SpeechConfig *cfg) {
|
int store_speech_cfg_into_audio_section(SpeechConfig *cfg)
|
||||||
|
{
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
memcpy(&audio_section_speech_cfg.cfg, cfg, sizeof(SpeechConfig));
|
memcpy(&audio_section_speech_cfg.cfg, cfg, sizeof(SpeechConfig));
|
||||||
|
@ -38,16 +39,21 @@ int store_speech_cfg_into_audio_section(SpeechConfig *cfg) {
|
||||||
(uint8_t *)&audio_section_speech_cfg,
|
(uint8_t *)&audio_section_speech_cfg,
|
||||||
sizeof(AUDIO_SECTION_SPEECH_CFG_T));
|
sizeof(AUDIO_SECTION_SPEECH_CFG_T));
|
||||||
|
|
||||||
if (res) {
|
|
||||||
|
if(res)
|
||||||
|
{
|
||||||
TRACE(2,"[%s] ERROR: res = %d", __func__, res);
|
TRACE(2,"[%s] ERROR: res = %d", __func__, res);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
TRACE(1,"[%s] Store speech cfg into audio section!!!", __func__);
|
TRACE(1,"[%s] Store speech cfg into audio section!!!", __func__);
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *load_speech_cfg_from_audio_section(void) {
|
void *load_speech_cfg_from_audio_section(void)
|
||||||
|
{
|
||||||
int res = 0;
|
int res = 0;
|
||||||
res = audio_section_load_cfg(AUDIO_SECTION_DEVICE_SPEECH,
|
res = audio_section_load_cfg(AUDIO_SECTION_DEVICE_SPEECH,
|
||||||
(uint8_t *)&audio_section_speech_cfg,
|
(uint8_t *)&audio_section_speech_cfg,
|
||||||
|
@ -55,10 +61,13 @@ void *load_speech_cfg_from_audio_section(void) {
|
||||||
|
|
||||||
void *res_ptr = NULL;
|
void *res_ptr = NULL;
|
||||||
|
|
||||||
if (res) {
|
if (res)
|
||||||
|
{
|
||||||
TRACE(2,"[%s] ERROR: res = %d", __func__, res);
|
TRACE(2,"[%s] ERROR: res = %d", __func__, res);
|
||||||
res_ptr = NULL;
|
res_ptr = NULL;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
TRACE(1,"[%s] Load speech cfg from audio section!!!", __func__);
|
TRACE(1,"[%s] Load speech cfg from audio section!!!", __func__);
|
||||||
res_ptr = (void *)&audio_section_speech_cfg.cfg;
|
res_ptr = (void *)&audio_section_speech_cfg.cfg;
|
||||||
}
|
}
|
||||||
|
@ -67,35 +76,41 @@ void *load_speech_cfg_from_audio_section(void) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int speech_tuning_set_status(bool en) {
|
int speech_tuning_set_status(bool en)
|
||||||
|
{
|
||||||
speech_tuning_status = en;
|
speech_tuning_status = en;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool speech_tuning_get_status(void) { return speech_tuning_status; }
|
bool speech_tuning_get_status(void)
|
||||||
|
{
|
||||||
|
return speech_tuning_status;
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t speech_tuning_check(unsigned char *buf, uint32_t len) {
|
uint32_t speech_tuning_check(unsigned char *buf, uint32_t len)
|
||||||
|
{
|
||||||
uint32_t res = 0;
|
uint32_t res = 0;
|
||||||
|
|
||||||
// Check valid
|
// Check valid
|
||||||
uint32_t config_size = sizeof(SpeechConfig);
|
uint32_t config_size = sizeof(SpeechConfig);
|
||||||
|
|
||||||
if (config_size != len) {
|
if (config_size != len)
|
||||||
|
{
|
||||||
TRACE(2,"[speech tuning] len(%d) != config_size(%d)", len, config_size);
|
TRACE(2,"[speech tuning] len(%d) != config_size(%d)", len, config_size);
|
||||||
res = 1;
|
res = 1;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
TRACE(1,"[speech tuning] len(%d) is OK", len);
|
TRACE(1,"[speech tuning] len(%d) is OK", len);
|
||||||
//SpeechConfig POSSIBLY_UNUSED *cfg = (SpeechConfig *)buf;
|
//SpeechConfig POSSIBLY_UNUSED *cfg = (SpeechConfig *)buf;
|
||||||
|
|
||||||
// Test parameters
|
// Test parameters
|
||||||
//#if defined(SPEECH_TX_2MIC_NS2)
|
//#if defined(SPEECH_TX_2MIC_NS2)
|
||||||
// TRACE(1,"[speech tuning] TX: delay_taps(x100): %d",
|
// TRACE(1,"[speech tuning] TX: delay_taps(x100): %d", (int)(cfg->tx_2mic_ns2.delay_taps * 100));
|
||||||
// (int)(cfg->tx_2mic_ns2.delay_taps * 100));
|
|
||||||
//#endif
|
//#endif
|
||||||
//#if defined(SPEECH_TX_NOISE_GATE)
|
//#if defined(SPEECH_TX_NOISE_GATE)
|
||||||
// TRACE(1,"[speech tuning] TX: data_threshold: %d",
|
// TRACE(1,"[speech tuning] TX: data_threshold: %d", cfg->tx_noise_gate.data_threshold);
|
||||||
// cfg->tx_noise_gate.data_threshold);
|
|
||||||
//#endif
|
//#endif
|
||||||
//#if defined(SPEECH_TX_EQ)
|
//#if defined(SPEECH_TX_EQ)
|
||||||
// TRACE(1,"[speech tuning] TX: eq num: %d", cfg->tx_eq.num);
|
// TRACE(1,"[speech tuning] TX: eq num: %d", cfg->tx_eq.num);
|
||||||
|
@ -108,16 +123,19 @@ uint32_t speech_tuning_check(unsigned char *buf, uint32_t len) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t speech_tuning_rx_callback(unsigned char *buf, uint32_t len) {
|
uint32_t speech_tuning_rx_callback(unsigned char *buf, uint32_t len)
|
||||||
|
{
|
||||||
uint32_t res = 0;
|
uint32_t res = 0;
|
||||||
|
|
||||||
res = speech_tuning_check(buf, len);
|
res = speech_tuning_check(buf, len);
|
||||||
|
|
||||||
if (res) {
|
if (res)
|
||||||
|
{
|
||||||
TRACE(1,"[speech tuning] ERROR: Send check res = %d", res);
|
TRACE(1,"[speech tuning] ERROR: Send check res = %d", res);
|
||||||
TRACE(0, "[Speech Tuning] res : 1; info : Send len(%d) != config_size(%d);",
|
TRACE(0,"[Speech Tuning] res : 1; info : Send len(%d) != config_size(%d);", len, sizeof(SpeechConfig));
|
||||||
len, sizeof(SpeechConfig));
|
}
|
||||||
} else {
|
else
|
||||||
|
{
|
||||||
// Save cfg
|
// Save cfg
|
||||||
speech_store_config((SpeechConfig *)buf);
|
speech_store_config((SpeechConfig *)buf);
|
||||||
|
|
||||||
|
@ -132,24 +150,29 @@ uint32_t speech_tuning_rx_callback(unsigned char *buf, uint32_t len) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef AUDIO_SECTION_ENABLE
|
#ifdef AUDIO_SECTION_ENABLE
|
||||||
uint32_t speech_tuning_burn_rx_callback(unsigned char *buf, uint32_t len) {
|
uint32_t speech_tuning_burn_rx_callback(unsigned char *buf, uint32_t len)
|
||||||
|
{
|
||||||
uint32_t res = 0;
|
uint32_t res = 0;
|
||||||
|
|
||||||
res = speech_tuning_check(buf, len);
|
res = speech_tuning_check(buf, len);
|
||||||
|
|
||||||
if (res) {
|
if (res)
|
||||||
|
{
|
||||||
TRACE(1,"[speech tuning] ERROR: Burn check res = %d", res);
|
TRACE(1,"[speech tuning] ERROR: Burn check res = %d", res);
|
||||||
TRACE(0, "[Speech Tuning] res : 1; info : Burn len(%d) != config_size(%d);",
|
TRACE(0,"[Speech Tuning] res : 1; info : Burn len(%d) != config_size(%d);", len, sizeof(SpeechConfig));
|
||||||
len, sizeof(SpeechConfig));
|
}
|
||||||
} else {
|
else
|
||||||
|
{
|
||||||
res = store_speech_cfg_into_audio_section((SpeechConfig *)buf);
|
res = store_speech_cfg_into_audio_section((SpeechConfig *)buf);
|
||||||
|
|
||||||
if (res) {
|
if(res)
|
||||||
|
{
|
||||||
TRACE(1,"[speech tuning] ERROR: Store res = %d", res);
|
TRACE(1,"[speech tuning] ERROR: Store res = %d", res);
|
||||||
res += 100;
|
res += 100;
|
||||||
TRACE(0, "[Speech Tuning] res : 2; info : Do not enable "
|
TRACE(0,"[Speech Tuning] res : 2; info : Do not enable AUDIO_SECTION_ENABLE;");
|
||||||
"AUDIO_SECTION_ENABLE;");
|
}
|
||||||
} else {
|
else
|
||||||
|
{
|
||||||
TRACE(0,"[speech tuning] OK: Store cfg");
|
TRACE(0,"[speech tuning] OK: Store cfg");
|
||||||
TRACE(0,"[Speech Tuning] res : 0;");
|
TRACE(0,"[Speech Tuning] res : 0;");
|
||||||
}
|
}
|
||||||
|
@ -159,15 +182,13 @@ uint32_t speech_tuning_burn_rx_callback(unsigned char *buf, uint32_t len) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int speech_tuning_init(void) {
|
int speech_tuning_init(void)
|
||||||
|
{
|
||||||
#if defined(HAL_TRACE_RX_ENABLE) && !defined(SPEECH_TX_THIRDPARTY)
|
#if defined(HAL_TRACE_RX_ENABLE) && !defined(SPEECH_TX_THIRDPARTY)
|
||||||
hal_trace_rx_register("Speech Tuning",
|
hal_trace_rx_register("Speech Tuning", (HAL_TRACE_RX_CALLBACK_T)speech_tuning_rx_callback);
|
||||||
(HAL_TRACE_RX_CALLBACK_T)speech_tuning_rx_callback);
|
|
||||||
|
|
||||||
#ifdef AUDIO_SECTION_ENABLE
|
#ifdef AUDIO_SECTION_ENABLE
|
||||||
hal_trace_rx_register(
|
hal_trace_rx_register("Speech Tuning Burn", (HAL_TRACE_RX_CALLBACK_T)speech_tuning_burn_rx_callback);
|
||||||
"Speech Tuning Burn",
|
|
||||||
(HAL_TRACE_RX_CALLBACK_T)speech_tuning_burn_rx_callback);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -177,13 +198,15 @@ int speech_tuning_init(void) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int speech_tuning_open(void) {
|
int speech_tuning_open(void)
|
||||||
|
{
|
||||||
#ifdef AUDIO_SECTION_ENABLE
|
#ifdef AUDIO_SECTION_ENABLE
|
||||||
SpeechConfig *speech_cfg_load = NULL;
|
SpeechConfig *speech_cfg_load = NULL;
|
||||||
|
|
||||||
speech_cfg_load = (SpeechConfig *)load_speech_cfg_from_audio_section();
|
speech_cfg_load = (SpeechConfig *)load_speech_cfg_from_audio_section();
|
||||||
|
|
||||||
if (speech_cfg_load) {
|
if (speech_cfg_load)
|
||||||
|
{
|
||||||
speech_store_config(speech_cfg_load);
|
speech_store_config(speech_cfg_load);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -193,7 +216,8 @@ int speech_tuning_open(void) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int speech_tuning_close(void) {
|
int speech_tuning_close(void)
|
||||||
|
{
|
||||||
speech_tuning_set_status(false);
|
speech_tuning_set_status(false);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -17,22 +17,23 @@
|
||||||
#include "mbed.h"
|
#include "mbed.h"
|
||||||
#endif
|
#endif
|
||||||
// Standard C Included Files
|
// Standard C Included Files
|
||||||
|
#include <string.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <stdio.h>
|
||||||
#ifdef MBED
|
#ifdef MBED
|
||||||
//#include "rtos.h"
|
//#include "rtos.h"
|
||||||
#endif
|
#endif
|
||||||
#ifdef MBED
|
#ifdef MBED
|
||||||
#include "SDFileSystem.h"
|
#include "SDFileSystem.h"
|
||||||
#endif
|
#endif
|
||||||
#include "app_audio.h"
|
|
||||||
#include "cqueue.h"
|
#include "cqueue.h"
|
||||||
|
#include "hal_uart.h"
|
||||||
#include "hal_timer.h"
|
#include "hal_timer.h"
|
||||||
#include "hal_trace.h"
|
#include "hal_trace.h"
|
||||||
#include "hal_uart.h"
|
#include "app_audio.h"
|
||||||
|
|
||||||
|
|
||||||
// BT
|
// BT
|
||||||
|
|
||||||
|
@ -51,7 +52,8 @@ static enum APP_AUDIO_CACHE_T voicecvsd_cache_status = APP_AUDIO_CACHE_QTY;
|
||||||
#define LOCK_VOICECVSD_QUEUE() \
|
#define LOCK_VOICECVSD_QUEUE() \
|
||||||
osMutexWait(g_voicecvsd_queue_mutex_id, osWaitForever)
|
osMutexWait(g_voicecvsd_queue_mutex_id, osWaitForever)
|
||||||
|
|
||||||
#define UNLOCK_VOICECVSD_QUEUE() osMutexRelease(g_voicecvsd_queue_mutex_id)
|
#define UNLOCK_VOICECVSD_QUEUE() \
|
||||||
|
osMutexRelease(g_voicecvsd_queue_mutex_id)
|
||||||
|
|
||||||
void xLOCK_VOICECVSD_QUEUE(void)
|
void xLOCK_VOICECVSD_QUEUE(void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -14,26 +14,28 @@
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
// Standard C Included Files
|
// Standard C Included Files
|
||||||
#include "cqueue.h"
|
#include <string.h>
|
||||||
#include "hal_timer.h"
|
|
||||||
#include "hal_trace.h"
|
|
||||||
#include "hal_uart.h"
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <stdio.h>
|
||||||
|
#include "cqueue.h"
|
||||||
|
#include "hal_uart.h"
|
||||||
|
#include "hal_timer.h"
|
||||||
|
#include "hal_trace.h"
|
||||||
|
|
||||||
uint8_t digmic_buf[100*1024];
|
uint8_t digmic_buf[100*1024];
|
||||||
uint32_t digmic_buf_len = 0;
|
uint32_t digmic_buf_len = 0;
|
||||||
|
|
||||||
uint32_t dig_mic_audio_more_data(uint8_t *buf, uint32_t len) {
|
uint32_t dig_mic_audio_more_data(uint8_t *buf, uint32_t len)
|
||||||
|
{
|
||||||
TRACE(2,"%s:%d\n", __func__, __LINE__);
|
TRACE(2,"%s:%d\n", __func__, __LINE__);
|
||||||
memcpy(buf, digmic_buf, len);
|
memcpy(buf, digmic_buf, len);
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
uint32_t dig_mic_audio_data_come(uint8_t *buf, uint32_t len) {
|
uint32_t dig_mic_audio_data_come(uint8_t *buf, uint32_t len)
|
||||||
|
{
|
||||||
TRACE(2,"%s:%d\n", __func__, __LINE__);
|
TRACE(2,"%s:%d\n", __func__, __LINE__);
|
||||||
|
|
||||||
memcpy(digmic_buf + digmic_buf_len, buf, len);
|
memcpy(digmic_buf + digmic_buf_len, buf, len);
|
||||||
|
|
|
@ -14,15 +14,15 @@
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
// Standard C Included Files
|
// Standard C Included Files
|
||||||
#include "cqueue.h"
|
#include <string.h>
|
||||||
#include "hal_timer.h"
|
|
||||||
#include "hal_trace.h"
|
|
||||||
#include "hal_uart.h"
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <stdio.h>
|
||||||
|
#include "cqueue.h"
|
||||||
|
#include "hal_uart.h"
|
||||||
|
#include "hal_timer.h"
|
||||||
|
#include "hal_trace.h"
|
||||||
#ifdef RTOS
|
#ifdef RTOS
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -38,20 +38,22 @@ unsigned char flac_queue_buf[FLAC_QUEUE_SIZE];
|
||||||
CQueue flac_queue;
|
CQueue flac_queue;
|
||||||
static uint32_t ok_to_decode = 0;
|
static uint32_t ok_to_decode = 0;
|
||||||
|
|
||||||
#define LOCK_FLAC_QUEUE() osMutexWait(g_flac_queue_mutex_id, osWaitForever)
|
#define LOCK_FLAC_QUEUE() \
|
||||||
|
osMutexWait(g_flac_queue_mutex_id, osWaitForever)
|
||||||
|
|
||||||
#define UNLOCK_FLAC_QUEUE() osMutexRelease(g_flac_queue_mutex_id)
|
#define UNLOCK_FLAC_QUEUE() \
|
||||||
|
osMutexRelease(g_flac_queue_mutex_id)
|
||||||
|
|
||||||
static void copy_one_trace_to_two_track_16bits(uint16_t *src_buf,
|
static void copy_one_trace_to_two_track_16bits(uint16_t *src_buf, uint16_t *dst_buf, uint32_t src_len)
|
||||||
uint16_t *dst_buf,
|
{
|
||||||
uint32_t src_len) {
|
|
||||||
uint32_t i = 0;
|
uint32_t i = 0;
|
||||||
for (i = 0; i < src_len; ++i) {
|
for (i = 0; i < src_len; ++i) {
|
||||||
dst_buf[i*2 + 0] = dst_buf[i*2 + 1] = src_buf[i];
|
dst_buf[i*2 + 0] = dst_buf[i*2 + 1] = src_buf[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int store_flac_buffer(unsigned char *buf, unsigned int len) {
|
int store_flac_buffer(unsigned char *buf, unsigned int len)
|
||||||
|
{
|
||||||
LOCK_FLAC_QUEUE();
|
LOCK_FLAC_QUEUE();
|
||||||
EnCQueue(&flac_queue, buf, len);
|
EnCQueue(&flac_queue, buf, len);
|
||||||
if (LengthOfCQueue(&flac_queue) > FLAC_TEMP_BUFFER_SIZE*2) {
|
if (LengthOfCQueue(&flac_queue) > FLAC_TEMP_BUFFER_SIZE*2) {
|
||||||
|
@ -62,7 +64,8 @@ int store_flac_buffer(unsigned char *buf, unsigned int len) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int decode_flac_frame(unsigned char *pcm_buffer, unsigned int pcm_len) {
|
int decode_flac_frame(unsigned char *pcm_buffer, unsigned int pcm_len)
|
||||||
|
{
|
||||||
uint32_t r = 0, got_len = 0;
|
uint32_t r = 0, got_len = 0;
|
||||||
unsigned char *e1 = NULL, *e2 = NULL;
|
unsigned char *e1 = NULL, *e2 = NULL;
|
||||||
unsigned int len1 = 0, len2 = 0;
|
unsigned int len1 = 0, len2 = 0;
|
||||||
|
@ -77,8 +80,7 @@ get_again:
|
||||||
}
|
}
|
||||||
|
|
||||||
//memcpy(pcm_buffer + got_len, e1, len1);
|
//memcpy(pcm_buffer + got_len, e1, len1);
|
||||||
copy_one_trace_to_two_track_16bits(
|
copy_one_trace_to_two_track_16bits((uint16_t *)e1, (uint16_t *)(pcm_buffer + got_len), len1/2);
|
||||||
(uint16_t *)e1, (uint16_t *)(pcm_buffer + got_len), len1 / 2);
|
|
||||||
|
|
||||||
LOCK_FLAC_QUEUE();
|
LOCK_FLAC_QUEUE();
|
||||||
DeCQueue(&flac_queue, 0, len1);
|
DeCQueue(&flac_queue, 0, len1);
|
||||||
|
@ -88,8 +90,7 @@ get_again:
|
||||||
|
|
||||||
if (len2 != 0) {
|
if (len2 != 0) {
|
||||||
//memcpy(pcm_buffer + got_len, e2, len2);
|
//memcpy(pcm_buffer + got_len, e2, len2);
|
||||||
copy_one_trace_to_two_track_16bits(
|
copy_one_trace_to_two_track_16bits((uint16_t *)e2, (uint16_t *)(pcm_buffer + got_len), len2/2);
|
||||||
(uint16_t *)e2, (uint16_t *)(pcm_buffer + got_len), len2 / 2);
|
|
||||||
|
|
||||||
LOCK_FLAC_QUEUE();
|
LOCK_FLAC_QUEUE();
|
||||||
DeCQueue(&flac_queue, 0, len2);
|
DeCQueue(&flac_queue, 0, len2);
|
||||||
|
@ -104,13 +105,15 @@ get_again:
|
||||||
return pcm_len;
|
return pcm_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t flac_audio_data_come(uint8_t *buf, uint32_t len) {
|
uint32_t flac_audio_data_come(uint8_t *buf, uint32_t len)
|
||||||
|
{
|
||||||
TRACE(1,"data come %d\n", len);
|
TRACE(1,"data come %d\n", len);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t flac_audio_more_data(uint8_t *buf, uint32_t len) {
|
uint32_t flac_audio_more_data(uint8_t *buf, uint32_t len)
|
||||||
|
{
|
||||||
uint32_t l = 0;
|
uint32_t l = 0;
|
||||||
//uint32_t cur_ticks = 0, ticks = 0;
|
//uint32_t cur_ticks = 0, ticks = 0;
|
||||||
|
|
||||||
|
@ -125,7 +128,8 @@ uint32_t flac_audio_more_data(uint8_t *buf, uint32_t len) {
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
int flac_audio_init(void) {
|
int flac_audio_init(void)
|
||||||
|
{
|
||||||
g_flac_queue_mutex_id = osMutexCreate((osMutex(g_flac_queue_mutex)));
|
g_flac_queue_mutex_id = osMutexCreate((osMutex(g_flac_queue_mutex)));
|
||||||
/* flac queue*/
|
/* flac queue*/
|
||||||
InitCQueue(&flac_queue, FLAC_QUEUE_SIZE, (unsigned char *)&flac_queue_buf);
|
InitCQueue(&flac_queue, FLAC_QUEUE_SIZE, (unsigned char *)&flac_queue_buf);
|
||||||
|
|
|
@ -15,23 +15,23 @@
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#ifdef CHIP_BEST1000
|
#ifdef CHIP_BEST1000
|
||||||
|
|
||||||
#include "app_audio.h"
|
|
||||||
#include "app_overlay.h"
|
|
||||||
#include "app_utils.h"
|
|
||||||
#include "audiobuffer.h"
|
|
||||||
#include "audioflinger.h"
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
#include "cqueue.h"
|
#include "hal_trace.h"
|
||||||
#include "fmdec.h"
|
#include "fmdec.h"
|
||||||
#include "hal_analogif.h"
|
|
||||||
#include "hal_chipid.h"
|
|
||||||
#include "hal_cmu.h"
|
|
||||||
#include "hal_dma.h"
|
#include "hal_dma.h"
|
||||||
#include "hal_timer.h"
|
#include "hal_timer.h"
|
||||||
#include "hal_trace.h"
|
#include "hal_cmu.h"
|
||||||
#include "pmu.h"
|
#include "hal_analogif.h"
|
||||||
|
#include "hal_chipid.h"
|
||||||
|
#include "audioflinger.h"
|
||||||
|
#include "audiobuffer.h"
|
||||||
|
#include "cqueue.h"
|
||||||
|
#include "app_audio.h"
|
||||||
|
#include "app_utils.h"
|
||||||
|
#include "app_overlay.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
#include "pmu.h"
|
||||||
|
|
||||||
//#define FM_DEBUG 1
|
//#define FM_DEBUG 1
|
||||||
|
|
||||||
|
@ -56,18 +56,14 @@
|
||||||
extern int app_bt_stream_local_volume_get(void);
|
extern int app_bt_stream_local_volume_get(void);
|
||||||
static int32_t *fm_sample_buffer_p;
|
static int32_t *fm_sample_buffer_p;
|
||||||
|
|
||||||
static void fm_handler(uint8_t chan, uint32_t remains, uint32_t error,
|
static void fm_handler(uint8_t chan, uint32_t remains, uint32_t error, struct HAL_DMA_DESC_T *lli)
|
||||||
struct HAL_DMA_DESC_T *lli) {
|
{
|
||||||
static int cnt = 0;
|
static int cnt = 0;
|
||||||
int16_t fm_decbuf[(FM_SAMPLE_NUM/9)];
|
int16_t fm_decbuf[(FM_SAMPLE_NUM/9)];
|
||||||
FmDemodulate(
|
FmDemodulate((int16_t *)(fm_sample_buffer_p +((cnt%FM_FRAME_NUM)*FM_SAMPLE_NUM)), fm_decbuf,FM_SAMPLE_NUM);
|
||||||
(int16_t *)(fm_sample_buffer_p + ((cnt % FM_FRAME_NUM) * FM_SAMPLE_NUM)),
|
|
||||||
fm_decbuf, FM_SAMPLE_NUM);
|
|
||||||
cnt++;
|
cnt++;
|
||||||
app_audio_pcmbuff_put((uint8_t *)fm_decbuf, (FM_SAMPLE_NUM/9)<<1);
|
app_audio_pcmbuff_put((uint8_t *)fm_decbuf, (FM_SAMPLE_NUM/9)<<1);
|
||||||
FmDemodulate(
|
FmDemodulate((int16_t *)(fm_sample_buffer_p +((cnt%FM_FRAME_NUM)*FM_SAMPLE_NUM)), fm_decbuf,FM_SAMPLE_NUM);
|
||||||
(int16_t *)(fm_sample_buffer_p + ((cnt % FM_FRAME_NUM) * FM_SAMPLE_NUM)),
|
|
||||||
fm_decbuf, FM_SAMPLE_NUM);
|
|
||||||
cnt++;
|
cnt++;
|
||||||
app_audio_pcmbuff_put((uint8_t *)fm_decbuf, (FM_SAMPLE_NUM/9)<<1);
|
app_audio_pcmbuff_put((uint8_t *)fm_decbuf, (FM_SAMPLE_NUM/9)<<1);
|
||||||
|
|
||||||
|
@ -84,13 +80,13 @@ static void fm_handler(uint8_t chan, uint32_t remains, uint32_t error,
|
||||||
diff_ticks = TICKS_TO_MS(cur_ticks - preTicks);
|
diff_ticks = TICKS_TO_MS(cur_ticks - preTicks);
|
||||||
preTicks = cur_ticks;
|
preTicks = cur_ticks;
|
||||||
}
|
}
|
||||||
TRACE(3, "[fm_handler] diff=%d add:%d remain:%d input", diff_ticks,
|
TRACE(3,"[fm_handler] diff=%d add:%d remain:%d input", diff_ticks, (FM_SAMPLE_NUM/9)<<1, app_audio_pcmbuff_length());
|
||||||
(FM_SAMPLE_NUM / 9) << 1, app_audio_pcmbuff_length());
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t fm_pcm_more_data(uint8_t *buf, uint32_t len) {
|
uint32_t fm_pcm_more_data(uint8_t *buf, uint32_t len)
|
||||||
|
{
|
||||||
app_audio_pcmbuff_get(buf, len);
|
app_audio_pcmbuff_get(buf, len);
|
||||||
#ifdef FM_DEBUG
|
#ifdef FM_DEBUG
|
||||||
{
|
{
|
||||||
|
@ -104,39 +100,42 @@ uint32_t fm_pcm_more_data(uint8_t *buf, uint32_t len) {
|
||||||
preTicks = cur_ticks;
|
preTicks = cur_ticks;
|
||||||
}
|
}
|
||||||
|
|
||||||
TRACE(
|
TRACE(5,"[fm_pcm_more_data] diff=%d get:%d remain:%d output isr:0x%08x cnt:%d", diff_ticks, len/2, app_audio_pcmbuff_length(), FM_DIGITAL_REG(0x40160020), FM_DIGITAL_REG(0x40160028));
|
||||||
5,
|
|
||||||
"[fm_pcm_more_data] diff=%d get:%d remain:%d output isr:0x%08x cnt:%d",
|
|
||||||
diff_ticks, len / 2, app_audio_pcmbuff_length(),
|
|
||||||
FM_DIGITAL_REG(0x40160020), FM_DIGITAL_REG(0x40160028));
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t fm_capture_more_data(uint8_t *buf, uint32_t len) {
|
uint32_t fm_capture_more_data(uint8_t *buf, uint32_t len)
|
||||||
|
{
|
||||||
fm_handler(0,0,0,NULL);
|
fm_handler(0,0,0,NULL);
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fm_radio_digit_init(void) {
|
void fm_radio_digit_init(void)
|
||||||
FM_DIGITAL_REG(0xd0350244) = (FM_DIGITAL_REG(0xd0350244) & ~0x01fff) |
|
{
|
||||||
0x20f; //-890k -> 0 if_shift, for 110.5292m adc
|
FM_DIGITAL_REG(0xd0350244) = (FM_DIGITAL_REG(0xd0350244) & ~0x01fff) | 0x20f; //-890k -> 0 if_shift, for 110.5292m adc
|
||||||
|
|
||||||
// FM_DIGITAL_REG(0x40180e0c) = 0x34;
|
// FM_DIGITAL_REG(0x40180e0c) = 0x34;
|
||||||
// FM_DIGITAL_REG(0x4000a050) = (FM_DIGITAL_REG(0x4000a050) & ~0x18000) |
|
//FM_DIGITAL_REG(0x4000a050) = (FM_DIGITAL_REG(0x4000a050) & ~0x18000) | 0x18000;
|
||||||
// 0x18000;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef ATAN2_HARDWARE
|
#ifdef ATAN2_HARDWARE
|
||||||
|
|
||||||
|
|
||||||
FM_DIGITAL_REG(0xd0330038) |= (1 << 11);
|
FM_DIGITAL_REG(0xd0330038) |= (1 << 11);
|
||||||
FM_DIGITAL_REG(0xd0330038) |= (1 << 17);
|
FM_DIGITAL_REG(0xd0330038) |= (1 << 17);
|
||||||
FM_DIGITAL_REG(0xd0350248) = 0x80c00000;
|
FM_DIGITAL_REG(0xd0350248) = 0x80c00000;
|
||||||
// FM_DIGITAL_REG(0x40160030) = 1;
|
// FM_DIGITAL_REG(0x40160030) = 1;
|
||||||
// FM_DIGITAL_REG(0x40160000) = 0x21;
|
// FM_DIGITAL_REG(0x40160000) = 0x21;
|
||||||
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
FM_DIGITAL_REG(0xd0330038) |= (1 << 11);
|
FM_DIGITAL_REG(0xd0330038) |= (1 << 11);
|
||||||
FM_DIGITAL_REG(0xd0350248) = 0x80c00000;
|
FM_DIGITAL_REG(0xd0350248) = 0x80c00000;
|
||||||
// FM_DIGITAL_REG(0x40160030) = 1;
|
// FM_DIGITAL_REG(0x40160030) = 1;
|
||||||
|
@ -144,14 +143,18 @@ void fm_radio_digit_init(void) {
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef SINGLECHANLE
|
#ifdef SINGLECHANLE
|
||||||
// 0x4000a010 bit2 д0 <20><>channel dac
|
//0x4000a010 bit2 写0 单channel dac
|
||||||
FM_DIGITAL_REG(0x4000a010) = (1 << 5) |(1<<4);
|
FM_DIGITAL_REG(0x4000a010) = (1 << 5) |(1<<4);
|
||||||
#else
|
#else
|
||||||
|
|
||||||
FM_DIGITAL_REG(0x4000a010) = (1 << 5) | (1 << 2)|(1<<4);
|
FM_DIGITAL_REG(0x4000a010) = (1 << 5) | (1 << 2)|(1<<4);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
FM_DIGITAL_REG(0x4000a020) = ~0UL;
|
FM_DIGITAL_REG(0x4000a020) = ~0UL;
|
||||||
FM_DIGITAL_REG(0x4000a02c) = 4;
|
FM_DIGITAL_REG(0x4000a02c) = 4;
|
||||||
FM_DIGITAL_REG(0x4000a030) = 4;
|
FM_DIGITAL_REG(0x4000a030) = 4;
|
||||||
|
@ -190,24 +193,23 @@ void fm_radio_digit_init(void) {
|
||||||
// FM_DIGITAL_REG(0x40010014) = 0x03a80005;
|
// FM_DIGITAL_REG(0x40010014) = 0x03a80005;
|
||||||
//FM_DIGITAL_REG(0x40010018) = 0x00200019;
|
//FM_DIGITAL_REG(0x40010018) = 0x00200019;
|
||||||
FM_DIGITAL_REG(0x4000a050) = 0x24200000; //for adc_div_3_6 bypass
|
FM_DIGITAL_REG(0x4000a050) = 0x24200000; //for adc_div_3_6 bypass
|
||||||
FM_DIGITAL_REG(0x4000a050) = (FM_DIGITAL_REG(0x4000a050) & ~0x780) |
|
FM_DIGITAL_REG(0x4000a050) = (FM_DIGITAL_REG(0x4000a050) & ~0x780) | 0x380; // for channel 1 adc volume, bit10~7
|
||||||
0x380; // for channel 1 adc volume, bit10~7
|
FM_DIGITAL_REG(0x4000a050) = (FM_DIGITAL_REG(0x4000a050) & ~0x18000) | 0x18000; // for dual channel adc/dac
|
||||||
FM_DIGITAL_REG(0x4000a050) = (FM_DIGITAL_REG(0x4000a050) & ~0x18000) |
|
|
||||||
0x18000; // for dual channel adc/dac
|
|
||||||
|
|
||||||
#ifdef SINGLECHANLE
|
#ifdef SINGLECHANLE
|
||||||
// 0x4000a050 bit16 д0 <20><>channel dac for codec
|
//0x4000a050 bit16 写0 单channel dac for codec
|
||||||
FM_DIGITAL_REG(0x4000a050) =(FM_DIGITAL_REG(0x4000a050) & ~ (1 << 16));
|
FM_DIGITAL_REG(0x4000a050) =(FM_DIGITAL_REG(0x4000a050) & ~ (1 << 16));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
FM_DIGITAL_REG(0x4000a048) = (FM_DIGITAL_REG(0x4000a048) & ~0x00000f00) |
|
|
||||||
0x40000900; // set for sdm gain
|
FM_DIGITAL_REG(0x4000a048) = (FM_DIGITAL_REG(0x4000a048) & ~0x00000f00) | 0x40000900; //set for sdm gain
|
||||||
FM_DIGITAL_REG(0x4000a044) = (FM_DIGITAL_REG(0x4000a044) & ~0x60000000) |
|
FM_DIGITAL_REG(0x4000a044) = (FM_DIGITAL_REG(0x4000a044) & ~0x60000000) | 0x60000000; //for adc en, and dac en
|
||||||
0x60000000; // for adc en, and dac en
|
|
||||||
|
|
||||||
// Start DAC
|
// Start DAC
|
||||||
FM_DIGITAL_REG(0x4000a010) |= (1 << 1);
|
FM_DIGITAL_REG(0x4000a010) |= (1 << 1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Delay 2 ms
|
// Delay 2 ms
|
||||||
// for (volatile int kk = 0; kk < 1000/64; kk++);
|
// for (volatile int kk = 0; kk < 1000/64; kk++);
|
||||||
osDelay(2);
|
osDelay(2);
|
||||||
|
@ -216,8 +218,10 @@ void fm_radio_digit_init(void) {
|
||||||
// Start ADC
|
// Start ADC
|
||||||
// FM_DIGITAL_REG(0x4000a010) |= (1 << 0);
|
// FM_DIGITAL_REG(0x4000a010) |= (1 << 0);
|
||||||
|
|
||||||
|
|
||||||
#ifdef ATAN2_HARDWARE
|
#ifdef ATAN2_HARDWARE
|
||||||
|
|
||||||
|
|
||||||
#ifdef FM_NEWMODE
|
#ifdef FM_NEWMODE
|
||||||
FM_DIGITAL_REG(0x40160030) = 1;
|
FM_DIGITAL_REG(0x40160030) = 1;
|
||||||
FM_DIGITAL_REG(0x40160000) = 0x1;
|
FM_DIGITAL_REG(0x40160000) = 0x1;
|
||||||
|
@ -235,9 +239,11 @@ void fm_radio_digit_init(void) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int fm_radio_analog_init(void) {
|
int fm_radio_analog_init(void)
|
||||||
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
// fm initial
|
// fm initial
|
||||||
|
@ -245,30 +251,31 @@ int fm_radio_analog_init(void) {
|
||||||
rfspi_wvalue( 8'h01 , 16'b1010_1101_1111_1111 ) ; // power on fm lna
|
rfspi_wvalue( 8'h01 , 16'b1010_1101_1111_1111 ) ; // power on fm lna
|
||||||
rfspi_wvalue( 8'h02 , 16'b1000_0000_1001_0100 ) ; // reg_fm_lna_pu_mixersw
|
rfspi_wvalue( 8'h02 , 16'b1000_0000_1001_0100 ) ; // reg_fm_lna_pu_mixersw
|
||||||
|
|
||||||
rfspi_wvalue( 8'h1a , 16'b0101_0000_1011_0000 ) ; //
|
rfspi_wvalue( 8'h1a , 16'b0101_0000_1011_0000 ) ; // reg_bt_vco_fm_buff_vctrl_dr=1
|
||||||
reg_bt_vco_fm_buff_vctrl_dr=1
|
|
||||||
|
|
||||||
rfspi_wvalue( 8'h18 , 16'b0000_0110_1000_0000 ) ; // power on vco
|
rfspi_wvalue( 8'h18 , 16'b0000_0110_1000_0000 ) ; // power on vco
|
||||||
|
|
||||||
rfspi_wvalue( 8'h19 , 16'b0110_0100_0100_0000 ) ; // reg_bt_vco_fm_buff_vctrl
|
rfspi_wvalue( 8'h19 , 16'b0110_0100_0100_0000 ) ; // reg_bt_vco_fm_buff_vctrl
|
||||||
rfspi_wvalue( 8'h1d , 16'b0111_1000_1010_0100 ) ; // reg_bt_rfpll_pu_dr
|
rfspi_wvalue( 8'h1d , 16'b0111_1000_1010_0100 ) ; // reg_bt_rfpll_pu_dr
|
||||||
rfspi_wvalue( 8'h1c , 16'b0000_0000_1100_1000 ) ; // reg_bt_vco_fm_lo_en
|
rfspi_wvalue( 8'h1c , 16'b0000_0000_1100_1000 ) ; // reg_bt_vco_fm_lo_en reg_bt_vco_fm_div_ctrl=8
|
||||||
reg_bt_vco_fm_div_ctrl=8
|
|
||||||
|
|
||||||
rfspi_wvalue( 8'h0a , 16'b0001_0010_0010_1111 ) ; // reg_btfm_flt_fm_en
|
rfspi_wvalue( 8'h0a , 16'b0001_0010_0010_1111 ) ; // reg_btfm_flt_fm_en
|
||||||
|
|
||||||
rfspi_wvalue( 8'h2d , 16'b0000_0111_1000_0010 ) ; // bb ldo on
|
rfspi_wvalue( 8'h2d , 16'b0000_0111_1000_0010 ) ; // bb ldo on reg_bb_ldo_pu_vddr15a_dr
|
||||||
reg_bb_ldo_pu_vddr15a_dr rfspi_wvalue( 8'h07 , 16'b0000_0010_1011_1001 ) ; //
|
rfspi_wvalue( 8'h07 , 16'b0000_0010_1011_1001 ) ; // reg_btfm_flt_pu_dr
|
||||||
reg_btfm_flt_pu_dr
|
|
||||||
|
|
||||||
rfspi_wvalue( 8'h2a , 16'b0001_0110_1100_0000 ) ; // reg_bt_rfpll_sdm_freq_dr
|
rfspi_wvalue( 8'h2a , 16'b0001_0110_1100_0000 ) ; // reg_bt_rfpll_sdm_freq_dr
|
||||||
rfspi_wvalue( 8'h26 , 16'b0000_0000_0000_0000 ) ; // vco freq[31:16] ( 2400 +
|
rfspi_wvalue( 8'h26 , 16'b0000_0000_0000_0000 ) ; // vco freq[31:16] ( 2400 + x )*2^25/26MHZ*N (2400+x= frf)
|
||||||
x )*2^25/26MHZ*N (2400+x= frf) rfspi_wvalue( 8'h25 , 16'b0000_0000_0000_0000 )
|
rfspi_wvalue( 8'h25 , 16'b0000_0000_0000_0000 ) ; // vco freq[15:00] fm_freq = frf/(4*reg_bt_vco_fm_div_ctrl)
|
||||||
; // vco freq[15:00] fm_freq = frf/(4*reg_bt_vco_fm_div_ctrl) rfspi_wvalue(
|
rfspi_wvalue( 8'h17 , 16'b1000_0000_0000_0000 ) ; // reg_bt_vco_calen
|
||||||
8'h17 , 16'b1000_0000_0000_0000 ) ; // reg_bt_vco_calen
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fm_write_rf_reg( 0x2c , 0b0111000001011100 ) ; // dig_vtoi_en
|
fm_write_rf_reg( 0x2c , 0b0111000001011100 ) ; // dig_vtoi_en
|
||||||
fm_write_rf_reg( 0x01 , 0b1010110111111111 ) ; // power on fm lna
|
fm_write_rf_reg( 0x01 , 0b1010110111111111 ) ; // power on fm lna
|
||||||
fm_write_rf_reg( 0x02 , 0b1000000010010100 ) ; // reg_fm_lna_pu_mixersw
|
fm_write_rf_reg( 0x02 , 0b1000000010010100 ) ; // reg_fm_lna_pu_mixersw
|
||||||
|
@ -279,26 +286,31 @@ int fm_radio_analog_init(void) {
|
||||||
|
|
||||||
fm_write_rf_reg( 0x19 , 0b0110010001000000 ) ; // reg_bt_vco_fm_buff_vctrl
|
fm_write_rf_reg( 0x19 , 0b0110010001000000 ) ; // reg_bt_vco_fm_buff_vctrl
|
||||||
fm_write_rf_reg( 0x1d , 0b0111100010100100 ) ; // reg_bt_rfpll_pu_dr
|
fm_write_rf_reg( 0x1d , 0b0111100010100100 ) ; // reg_bt_rfpll_pu_dr
|
||||||
fm_write_rf_reg(
|
fm_write_rf_reg( 0x1c , 0b0000000011001000 ) ; // reg_bt_vco_fm_lo_en reg_bt_vco_fm_div_ctrl=8
|
||||||
0x1c, 0b0000000011001000); // reg_bt_vco_fm_lo_en reg_bt_vco_fm_div_ctrl=8
|
|
||||||
|
|
||||||
fm_write_rf_reg( 0x0a , 0b0001001000101111 ) ; // reg_btfm_flt_fm_en
|
fm_write_rf_reg( 0x0a , 0b0001001000101111 ) ; // reg_btfm_flt_fm_en
|
||||||
|
|
||||||
fm_write_rf_reg(0x2d,
|
fm_write_rf_reg( 0x2d , 0b0000011110000010 ) ; // bb ldo on reg_bb_ldo_pu_vddr15a_dr
|
||||||
0b0000011110000010); // bb ldo on reg_bb_ldo_pu_vddr15a_dr
|
|
||||||
fm_write_rf_reg( 0x07 , 0b0000001010111001 ) ; // reg_btfm_flt_pu_dr
|
fm_write_rf_reg( 0x07 , 0b0000001010111001 ) ; // reg_btfm_flt_pu_dr
|
||||||
|
|
||||||
fm_write_rf_reg( 0x2a , 0b0001011011000000 ) ; // reg_bt_rfpll_sdm_freq_dr
|
fm_write_rf_reg( 0x2a , 0b0001011011000000 ) ; // reg_bt_rfpll_sdm_freq_dr
|
||||||
fm_write_rf_reg(0x26, 0b0000000000000000); // vco freq[31:16] ( 2400 + x
|
fm_write_rf_reg( 0x26 , 0b0000000000000000 ) ; // vco freq[31:16] ( 2400 + x )*2^25/26MHZ*N (2400+x= frf)
|
||||||
// )*2^25/26MHZ*N (2400+x= frf)
|
fm_write_rf_reg( 0x25 , 0b0000000000000000 ) ; // vco freq[15:00] fm_freq = frf/(4*reg_bt_vco_fm_div_ctrl)
|
||||||
fm_write_rf_reg(0x25, 0b0000000000000000); // vco freq[15:00] fm_freq =
|
|
||||||
// frf/(4*reg_bt_vco_fm_div_ctrl)
|
|
||||||
fm_write_rf_reg( 0x17 , 0b1000000000000000 ) ; // reg_bt_vco_calen
|
fm_write_rf_reg( 0x17 , 0b1000000000000000 ) ; // reg_bt_vco_calen
|
||||||
|
|
||||||
// adcҲҪ<D2B2><D2AA><EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA> cmu
|
|
||||||
// 0x40000060[29] = 1 <20><><EFBFBD><EFBFBD>ȶ<EFBFBD><C8B6><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѱ<EFBFBD><D1B1>bit<69><74><EFBFBD><EFBFBD>ˡ<EFBFBD>
|
|
||||||
|
|
||||||
// <20><>Ҫ<EFBFBD><D2AA><EFBFBD>õ<EFBFBD>spi<70>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ana interface:
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//adc也要开的话,需要配 cmu
|
||||||
|
//0x40000060[29] = 1 最好先读再写,否则把别的bit冲掉了。
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//需要配置的spi寄存器:ana interface:
|
||||||
|
|
||||||
//0x05 = 0xFCB1 // Audio Pll
|
//0x05 = 0xFCB1 // Audio Pll
|
||||||
//0x06 = 0x881C
|
//0x06 = 0x881C
|
||||||
|
@ -306,6 +318,7 @@ int fm_radio_analog_init(void) {
|
||||||
//0x37 = 0x1000 // codec_bbpll1_fm_adc_clk_en
|
//0x37 = 0x1000 // codec_bbpll1_fm_adc_clk_en
|
||||||
//0x31 = 0x0130 // codec_tx_en_ldac codec_tx_en_rdac
|
//0x31 = 0x0130 // codec_tx_en_ldac codec_tx_en_rdac
|
||||||
|
|
||||||
|
|
||||||
ret = fm_write_rf_reg(0x05 , 0xfcb1);
|
ret = fm_write_rf_reg(0x05 , 0xfcb1);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -332,9 +345,11 @@ int fm_radio_analog_init(void) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//delay 32ms
|
//delay 32ms
|
||||||
osDelay(32);
|
osDelay(32);
|
||||||
|
|
||||||
|
|
||||||
ret = fm_write_rf_reg(0x31 , 0x0130);
|
ret = fm_write_rf_reg(0x31 , 0x0130);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -382,13 +397,16 @@ void fm_radio_poweron(void)
|
||||||
pmu_fm_config(1);
|
pmu_fm_config(1);
|
||||||
|
|
||||||
fm_write_rf_reg(0x0c, 0x3584);
|
fm_write_rf_reg(0x0c, 0x3584);
|
||||||
if (hal_get_chip_metal_id() == HAL_CHIP_METAL_ID_2 ||
|
if(hal_get_chip_metal_id() == HAL_CHIP_METAL_ID_2 || hal_get_chip_metal_id() == HAL_CHIP_METAL_ID_3) ////
|
||||||
hal_get_chip_metal_id() == HAL_CHIP_METAL_ID_3) ////
|
|
||||||
{
|
{
|
||||||
FM_DIGITAL_REG(0xc00003b4)=0x00060020;//turn off bt sleep
|
FM_DIGITAL_REG(0xc00003b4)=0x00060020;//turn off bt sleep
|
||||||
} else if (hal_get_chip_metal_id() == HAL_CHIP_METAL_ID_4) {
|
}
|
||||||
|
else if(hal_get_chip_metal_id() == HAL_CHIP_METAL_ID_4)
|
||||||
|
{
|
||||||
FM_DIGITAL_REG(0xc00003b0)=0x00060020;//turn off bt sleep
|
FM_DIGITAL_REG(0xc00003b0)=0x00060020;//turn off bt sleep
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
FM_DIGITAL_REG(0xc00003ac)=0x00060020;//turn off bt sleep
|
FM_DIGITAL_REG(0xc00003ac)=0x00060020;//turn off bt sleep
|
||||||
}
|
}
|
||||||
FM_DIGITAL_REG(0xd0330038) = 0x00008D0D;
|
FM_DIGITAL_REG(0xd0330038) = 0x00008D0D;
|
||||||
|
@ -396,14 +414,16 @@ void fm_radio_poweron(void)
|
||||||
//fm_write_rf_reg(0x02, 0xe694);
|
//fm_write_rf_reg(0x02, 0xe694);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *fm_radio_get_ext_buff(int size) {
|
void* fm_radio_get_ext_buff(int size)
|
||||||
|
{
|
||||||
uint8_t *pBuff = NULL;
|
uint8_t *pBuff = NULL;
|
||||||
size = size+size%4;
|
size = size+size%4;
|
||||||
app_audio_mempool_get_buff(&pBuff, size);
|
app_audio_mempool_get_buff(&pBuff, size);
|
||||||
return (void*)pBuff;
|
return (void*)pBuff;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fm_radio_player(bool on) {
|
int fm_radio_player(bool on)
|
||||||
|
{
|
||||||
static struct AF_STREAM_CONFIG_T stream_cfg;
|
static struct AF_STREAM_CONFIG_T stream_cfg;
|
||||||
static bool isRun = false;
|
static bool isRun = false;
|
||||||
uint8_t *buff = NULL;
|
uint8_t *buff = NULL;
|
||||||
|
@ -421,9 +441,10 @@ int fm_radio_player(bool on) {
|
||||||
osDelay(200);
|
osDelay(200);
|
||||||
buff = (uint8_t *)fm_radio_get_ext_buff(FM_AUDIO_BUFFER_SIZE*2);
|
buff = (uint8_t *)fm_radio_get_ext_buff(FM_AUDIO_BUFFER_SIZE*2);
|
||||||
app_audio_pcmbuff_init(buff, FM_AUDIO_BUFFER_SIZE*2);
|
app_audio_pcmbuff_init(buff, FM_AUDIO_BUFFER_SIZE*2);
|
||||||
fm_sample_buffer_p =
|
fm_sample_buffer_p = (int32_t *)fm_radio_get_ext_buff(FM_SAMPLE_BUFFER_SIZE);
|
||||||
(int32_t *)fm_radio_get_ext_buff(FM_SAMPLE_BUFFER_SIZE);
|
#if FPGA==0
|
||||||
app_overlay_select(APP_OVERLAY_FM);
|
app_overlay_select(APP_OVERLAY_FM);
|
||||||
|
#endif
|
||||||
memset(&stream_cfg, 0, sizeof(stream_cfg));
|
memset(&stream_cfg, 0, sizeof(stream_cfg));
|
||||||
stream_cfg.vol = app_bt_stream_local_volume_get();
|
stream_cfg.vol = app_bt_stream_local_volume_get();
|
||||||
stream_cfg.handler = fm_capture_more_data;
|
stream_cfg.handler = fm_capture_more_data;
|
||||||
|
@ -438,7 +459,11 @@ int fm_radio_player(bool on) {
|
||||||
stream_cfg.bits = AUD_BITS_16;
|
stream_cfg.bits = AUD_BITS_16;
|
||||||
stream_cfg.channel_num = AUD_CHANNEL_NUM_1;
|
stream_cfg.channel_num = AUD_CHANNEL_NUM_1;
|
||||||
stream_cfg.sample_rate = AUD_SAMPRATE_48000;
|
stream_cfg.sample_rate = AUD_SAMPRATE_48000;
|
||||||
|
#if FPGA==0
|
||||||
stream_cfg.device = AUD_STREAM_USE_INT_CODEC;
|
stream_cfg.device = AUD_STREAM_USE_INT_CODEC;
|
||||||
|
#else
|
||||||
|
stream_cfg.device = AUD_STREAM_USE_EXT_CODEC;
|
||||||
|
#endif
|
||||||
stream_cfg.io_path = AUD_OUTPUT_PATH_SPEAKER;
|
stream_cfg.io_path = AUD_OUTPUT_PATH_SPEAKER;
|
||||||
stream_cfg.vol = app_bt_stream_local_volume_get();
|
stream_cfg.vol = app_bt_stream_local_volume_get();
|
||||||
stream_cfg.handler = fm_pcm_more_data;
|
stream_cfg.handler = fm_pcm_more_data;
|
||||||
|
@ -459,10 +484,12 @@ int fm_radio_player(bool on) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fm_tune(uint32_t freqkhz) {
|
int fm_tune(uint32_t freqkhz)
|
||||||
|
{
|
||||||
uint32_t reg;
|
uint32_t reg;
|
||||||
unsigned long long tmp = 0;
|
unsigned long long tmp = 0;
|
||||||
|
|
||||||
|
|
||||||
//[rfpll_cal]
|
//[rfpll_cal]
|
||||||
fm_write_rf_reg(0x21,0x3979); // ref sel 52MHz
|
fm_write_rf_reg(0x21,0x3979); // ref sel 52MHz
|
||||||
fm_write_rf_reg(0x22,0x7A22); // doubler setting
|
fm_write_rf_reg(0x22,0x7A22); // doubler setting
|
||||||
|
@ -485,15 +512,18 @@ int fm_tune(uint32_t freqkhz) {
|
||||||
|
|
||||||
osDelay(20);
|
osDelay(20);
|
||||||
|
|
||||||
|
|
||||||
fm_write_rf_reg(0x1d,0x7ac4); // close pll loop
|
fm_write_rf_reg(0x1d,0x7ac4); // close pll loop
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fm_test_main(void) {
|
void fm_test_main(void)
|
||||||
|
{
|
||||||
fm_radio_player(true);
|
fm_radio_player(true);
|
||||||
osDelay(20);
|
osDelay(20);
|
||||||
fm_tune(90500);
|
fm_tune(90500);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -14,19 +14,20 @@
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
// Standard C Included Files
|
// Standard C Included Files
|
||||||
#include "cmsis_os.h"
|
#include <string.h>
|
||||||
#include "cqueue.h"
|
|
||||||
#include "hal_timer.h"
|
|
||||||
#include "hal_trace.h"
|
|
||||||
#include "hal_uart.h"
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <stdio.h>
|
||||||
|
#include "cmsis_os.h"
|
||||||
|
#include "cqueue.h"
|
||||||
|
#include "hal_uart.h"
|
||||||
|
#include "hal_timer.h"
|
||||||
|
#include "hal_trace.h"
|
||||||
|
|
||||||
// BT
|
// BT
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/* mutex */
|
/* mutex */
|
||||||
osMutexId g_voicemsbc_queue_mutex_id;
|
osMutexId g_voicemsbc_queue_mutex_id;
|
||||||
|
@ -42,7 +43,8 @@ static uint32_t ok_to_decode = 0;
|
||||||
#define LOCK_VOICEMSBC_QUEUE() \
|
#define LOCK_VOICEMSBC_QUEUE() \
|
||||||
osMutexWait(g_voicemsbc_queue_mutex_id, osWaitForever)
|
osMutexWait(g_voicemsbc_queue_mutex_id, osWaitForever)
|
||||||
|
|
||||||
#define UNLOCK_VOICEMSBC_QUEUE() osMutexRelease(g_voicemsbc_queue_mutex_id)
|
#define UNLOCK_VOICEMSBC_QUEUE() \
|
||||||
|
osMutexRelease(g_voicemsbc_queue_mutex_id)
|
||||||
|
|
||||||
static void dump_buffer_to_psram(char *buf, unsigned int len)
|
static void dump_buffer_to_psram(char *buf, unsigned int len)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
#include "plc_utils.h"
|
|
||||||
#include "hal_trace.h"
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "plc_utils.h"
|
||||||
|
#include "hal_trace.h"
|
||||||
|
|
||||||
#if defined(CHIP_BEST1400) || defined(CHIP_BEST1402) || \
|
#if defined(CHIP_BEST1400) || defined(CHIP_BEST1402) || defined(CHIP_BEST2300P) || defined(CHIP_BEST2300A)
|
||||||
defined(CHIP_BEST2300P) || defined(CHIP_BEST2300A)
|
|
||||||
#define MSBC_MUTE_PATTERN (0x55)
|
#define MSBC_MUTE_PATTERN (0x55)
|
||||||
#else
|
#else
|
||||||
#define MSBC_MUTE_PATTERN (0x00)
|
#define MSBC_MUTE_PATTERN (0x00)
|
||||||
|
@ -20,8 +19,9 @@
|
||||||
//#define ENABLE_PAD_CHECK
|
//#define ENABLE_PAD_CHECK
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* if msbc frame is filled by 10+ samples in the trail, crc maybe not detect
|
* if msbc frame is filled by 10+ samples in the trail, crc maybe not detect this
|
||||||
* this satuation. Do not check this by default
|
* satuation.
|
||||||
|
* Do not check this by default
|
||||||
*/
|
*/
|
||||||
//#define ENABLE_TRAILING_ZERO_CHECK
|
//#define ENABLE_TRAILING_ZERO_CHECK
|
||||||
|
|
||||||
|
@ -58,10 +58,12 @@ static const uint8_t sbc_crc_tbl[256] = {
|
||||||
0x10, 0x0D, 0x2A, 0x37, 0x64, 0x79, 0x5E, 0x43, 0xB2, 0xAF, 0x88, 0x95,
|
0x10, 0x0D, 0x2A, 0x37, 0x64, 0x79, 0x5E, 0x43, 0xB2, 0xAF, 0x88, 0x95,
|
||||||
0xC6, 0xDB, 0xFC, 0xE1, 0x5A, 0x47, 0x60, 0x7D, 0x2E, 0x33, 0x14, 0x09,
|
0xC6, 0xDB, 0xFC, 0xE1, 0x5A, 0x47, 0x60, 0x7D, 0x2E, 0x33, 0x14, 0x09,
|
||||||
0x7F, 0x62, 0x45, 0x58, 0x0B, 0x16, 0x31, 0x2C, 0x97, 0x8A, 0xAD, 0xB0,
|
0x7F, 0x62, 0x45, 0x58, 0x0B, 0x16, 0x31, 0x2C, 0x97, 0x8A, 0xAD, 0xB0,
|
||||||
0xE3, 0xFE, 0xD9, 0xC4};
|
0xE3, 0xFE, 0xD9, 0xC4
|
||||||
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int sco_parse_synchronization_header(uint8_t *buf, uint8_t *sn) {
|
static int sco_parse_synchronization_header(uint8_t *buf, uint8_t *sn)
|
||||||
|
{
|
||||||
uint8_t sn1, sn2;
|
uint8_t sn1, sn2;
|
||||||
#ifdef ENABLE_CRC_CHECK
|
#ifdef ENABLE_CRC_CHECK
|
||||||
uint8_t fcs = 0x0F;
|
uint8_t fcs = 0x0F;
|
||||||
|
@ -71,12 +73,15 @@ static int sco_parse_synchronization_header(uint8_t *buf, uint8_t *sn) {
|
||||||
#endif
|
#endif
|
||||||
*sn = 0xff;
|
*sn = 0xff;
|
||||||
#if defined(MSBC_SYNC_HACKER)
|
#if defined(MSBC_SYNC_HACKER)
|
||||||
if (((buf[0] != 0x01) && (buf[0] != 0x00)) || ((buf[1] & 0x0f) != 0x08) ||
|
if (((buf[0] != 0x01) && (buf[0] != 0x00)) ||
|
||||||
|
((buf[1] & 0x0f) != 0x08) ||
|
||||||
(buf[2] != 0xad)) {
|
(buf[2] != 0xad)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if ((buf[0] != 0x01) || ((buf[1] & 0x0f) != 0x08) || (buf[2] != 0xad)) {
|
if ((buf[0] != 0x01) ||
|
||||||
|
((buf[1] & 0x0f) != 0x08) ||
|
||||||
|
(buf[2] != 0xad)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -103,7 +108,8 @@ static int sco_parse_synchronization_header(uint8_t *buf, uint8_t *sn) {
|
||||||
/* Sum the whole byte */
|
/* Sum the whole byte */
|
||||||
fcs = sbc_crc_tbl[fcs ^ buf[ind]];
|
fcs = sbc_crc_tbl[fcs ^ buf[ind]];
|
||||||
ind = ind + 1;
|
ind = ind + 1;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
if (sb == 7) {
|
if (sb == 7) {
|
||||||
/* Sum the next 4 bits */
|
/* Sum the next 4 bits */
|
||||||
|
|
||||||
|
@ -113,7 +119,8 @@ static int sco_parse_synchronization_header(uint8_t *buf, uint8_t *sn) {
|
||||||
bit = (uint8_t)((0x01 & (buf[ind] >> shift--)) ^ (fcs >> 7));
|
bit = (uint8_t)((0x01 & (buf[ind] >> shift--)) ^ (fcs >> 7));
|
||||||
if (bit) {
|
if (bit) {
|
||||||
fcs = (uint8_t)(((fcs << 1) | bit) ^ 0x1C);
|
fcs = (uint8_t)(((fcs << 1) | bit) ^ 0x1C);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
fcs = (uint8_t)((fcs << 1));
|
fcs = (uint8_t)((fcs << 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,7 +147,8 @@ static int sco_parse_synchronization_header(uint8_t *buf, uint8_t *sn) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_BLE_CONFLICT_CHECK
|
#ifdef ENABLE_BLE_CONFLICT_CHECK
|
||||||
static bool memcmp_U8(uint8_t *x, uint8_t *y, uint16_t size) {
|
static bool memcmp_U8(uint8_t *x, uint8_t *y, uint16_t size)
|
||||||
|
{
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
if (x[i] != y[i])
|
if (x[i] != y[i])
|
||||||
return true;
|
return true;
|
||||||
|
@ -149,13 +157,12 @@ static bool memcmp_U8(uint8_t *x, uint8_t *y, uint16_t size) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// when signal is mute, msbc data remains the same except seq num. We should
|
// when signal is mute, msbc data remains the same except seq num. We should check history flag,
|
||||||
// check history flag, otherwise a single conflict may be detected twice
|
// otherwise a single conflict may be detected twice
|
||||||
static bool update_ble_sco_conflict(PacketLossState *st, uint8_t *last_pkt,
|
static bool update_ble_sco_conflict(PacketLossState* st, uint8_t *last_pkt, uint8_t *pkt)
|
||||||
uint8_t *pkt) {
|
{
|
||||||
// do not check padding byte as it maybe useless when msbc_offset is 1
|
// do not check padding byte as it maybe useless when msbc_offset is 1
|
||||||
bool ret = (st->prev_ble_sco_conflict_flag[1] == false &&
|
bool ret = (st->prev_ble_sco_conflict_flag[1] == false && memcmp_U8(last_pkt, pkt, MSBC_PKTSIZE - 1) == false);
|
||||||
memcmp_U8(last_pkt, pkt, MSBC_PKTSIZE - 1) == false);
|
|
||||||
|
|
||||||
memcpy(&last_pkt[0], &last_pkt[MSBC_PKTSIZE], MSBC_PKTSIZE);
|
memcpy(&last_pkt[0], &last_pkt[MSBC_PKTSIZE], MSBC_PKTSIZE);
|
||||||
memcpy(&last_pkt[MSBC_PKTSIZE], pkt, MSBC_PKTSIZE);
|
memcpy(&last_pkt[MSBC_PKTSIZE], pkt, MSBC_PKTSIZE);
|
||||||
|
@ -163,7 +170,8 @@ static bool update_ble_sco_conflict(PacketLossState *st, uint8_t *last_pkt,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool check_ble_sco_conflict(PacketLossState *st, bool ret) {
|
static bool check_ble_sco_conflict(PacketLossState* st, bool ret)
|
||||||
|
{
|
||||||
st->prev_ble_sco_conflict_flag[1] = st->prev_ble_sco_conflict_flag[0];
|
st->prev_ble_sco_conflict_flag[1] = st->prev_ble_sco_conflict_flag[0];
|
||||||
st->prev_ble_sco_conflict_flag[0] = ret;
|
st->prev_ble_sco_conflict_flag[0] = ret;
|
||||||
|
|
||||||
|
@ -171,7 +179,8 @@ static bool check_ble_sco_conflict(PacketLossState *st, bool ret) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static bool msbc_check_controller_mute_pattern(uint8_t *pkt, uint8_t pattern) {
|
static bool msbc_check_controller_mute_pattern(uint8_t *pkt, uint8_t pattern)
|
||||||
|
{
|
||||||
// do not check padding byte as it maybe useless when msbc_offset is 1
|
// do not check padding byte as it maybe useless when msbc_offset is 1
|
||||||
for (int i = 0; i < MSBC_PKTSIZE - 1; i++)
|
for (int i = 0; i < MSBC_PKTSIZE - 1; i++)
|
||||||
if (pkt[i] != pattern)
|
if (pkt[i] != pattern)
|
||||||
|
@ -181,7 +190,8 @@ static bool msbc_check_controller_mute_pattern(uint8_t *pkt, uint8_t pattern) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_TRAILING_ZERO_CHECK
|
#ifdef ENABLE_TRAILING_ZERO_CHECK
|
||||||
static int msbc_check_pkt_trailing_zeros(uint8_t *pkt) {
|
static int msbc_check_pkt_trailing_zeros(uint8_t *pkt)
|
||||||
|
{
|
||||||
int idx = MSBC_PKTSIZE;
|
int idx = MSBC_PKTSIZE;
|
||||||
|
|
||||||
for (int i = MSBC_PKTSIZE - 1; i >= 0; i--) {
|
for (int i = MSBC_PKTSIZE - 1; i >= 0; i--) {
|
||||||
|
@ -195,21 +205,22 @@ static int msbc_check_pkt_trailing_zeros(uint8_t *pkt) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static uint8_t get_next_sequence_num(uint8_t seq_num) {
|
static uint8_t get_next_sequence_num(uint8_t seq_num)
|
||||||
|
{
|
||||||
return (seq_num + 1 == 4) ? 0 : (seq_num + 1);
|
return (seq_num + 1 == 4) ? 0 : (seq_num + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void packet_loss_detection_init(PacketLossState *st) {
|
void packet_loss_detection_init(PacketLossState *st)
|
||||||
|
{
|
||||||
st->last_seq_num = 0xff;
|
st->last_seq_num = 0xff;
|
||||||
|
|
||||||
memset(st->last_pkt, 0, sizeof(st->last_pkt));
|
memset(st->last_pkt, 0, sizeof(st->last_pkt));
|
||||||
memset(st->prev_ble_sco_conflict_flag, 0,
|
memset(st->prev_ble_sco_conflict_flag, 0, sizeof(st->prev_ble_sco_conflict_flag));
|
||||||
sizeof(st->prev_ble_sco_conflict_flag));
|
|
||||||
memset(st->hist, 0, sizeof(st->hist));
|
memset(st->hist, 0, sizeof(st->hist));
|
||||||
}
|
}
|
||||||
|
|
||||||
plc_type_t packet_loss_detection_process(PacketLossState *st,
|
plc_type_t packet_loss_detection_process(PacketLossState *st, uint8_t *sbc_buf)
|
||||||
uint8_t *sbc_buf) {
|
{
|
||||||
plc_type_t plc_type = PLC_TYPE_PASS;
|
plc_type_t plc_type = PLC_TYPE_PASS;
|
||||||
|
|
||||||
#ifdef ENABLE_BLE_CONFLICT_CHECK
|
#ifdef ENABLE_BLE_CONFLICT_CHECK
|
||||||
|
@ -256,18 +267,22 @@ plc_type_t packet_loss_detection_process(PacketLossState *st,
|
||||||
if (st->last_seq_num == 0xff) {
|
if (st->last_seq_num == 0xff) {
|
||||||
if (seq_num == 0xff) {
|
if (seq_num == 0xff) {
|
||||||
plc_type = PLC_TYPE_SEQUENCE_DISCONTINUE;
|
plc_type = PLC_TYPE_SEQUENCE_DISCONTINUE;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
plc_type = PLC_TYPE_PASS;
|
plc_type = PLC_TYPE_PASS;
|
||||||
}
|
}
|
||||||
st->last_seq_num = seq_num;
|
st->last_seq_num = seq_num;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
if (seq_num == 0xff) {
|
if (seq_num == 0xff) {
|
||||||
st->last_seq_num = 0xff;
|
st->last_seq_num = 0xff;
|
||||||
plc_type = PLC_TYPE_SEQUENCE_DISCONTINUE;
|
plc_type = PLC_TYPE_SEQUENCE_DISCONTINUE;
|
||||||
} else if (seq_num == get_next_sequence_num(st->last_seq_num)) {
|
}
|
||||||
|
else if (seq_num == get_next_sequence_num(st->last_seq_num)) {
|
||||||
st->last_seq_num = seq_num;
|
st->last_seq_num = seq_num;
|
||||||
plc_type = PLC_TYPE_PASS;
|
plc_type = PLC_TYPE_PASS;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
st->last_seq_num = 0xff;
|
st->last_seq_num = 0xff;
|
||||||
plc_type = PLC_TYPE_SEQUENCE_DISCONTINUE;
|
plc_type = PLC_TYPE_SEQUENCE_DISCONTINUE;
|
||||||
}
|
}
|
||||||
|
@ -283,8 +298,8 @@ plc_type_t packet_loss_detection_process(PacketLossState *st,
|
||||||
return plc_type;
|
return plc_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
void packet_loss_detection_update_histogram(PacketLossState *st,
|
void packet_loss_detection_update_histogram(PacketLossState *st, plc_type_t plc_type)
|
||||||
plc_type_t plc_type) {
|
{
|
||||||
if (plc_type < 0 || plc_type >= PLC_TYPE_NUM) {
|
if (plc_type < 0 || plc_type >= PLC_TYPE_NUM) {
|
||||||
TRACE(2,"[%s] plc type %d is invalid", __FUNCTION__, plc_type);
|
TRACE(2,"[%s] plc type %d is invalid", __FUNCTION__, plc_type);
|
||||||
return;
|
return;
|
||||||
|
@ -298,7 +313,8 @@ void packet_loss_detection_update_histogram(PacketLossState *st,
|
||||||
st->hist[plc_type] += 1;
|
st->hist[plc_type] += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void packet_loss_detection_report(PacketLossState *st) {
|
void packet_loss_detection_report(PacketLossState *st)
|
||||||
|
{
|
||||||
uint32_t packet_loss_num = 0;
|
uint32_t packet_loss_num = 0;
|
||||||
|
|
||||||
for (uint8_t i = 1; i < PLC_TYPE_NUM; i++) {
|
for (uint8_t i = 1; i < PLC_TYPE_NUM; i++) {
|
||||||
|
@ -308,6 +324,5 @@ void packet_loss_detection_report(PacketLossState *st) {
|
||||||
|
|
||||||
uint32_t packet_total_num = st->hist[0] + packet_loss_num;
|
uint32_t packet_total_num = st->hist[0] + packet_loss_num;
|
||||||
TRACE(4,"[%s] packet loss percent %d/10000(%d/%d)", __FUNCTION__,
|
TRACE(4,"[%s] packet loss percent %d/10000(%d/%d)", __FUNCTION__,
|
||||||
(int32_t)(10000.f * packet_loss_num / packet_total_num),
|
(int32_t)(10000.f * packet_loss_num/ packet_total_num), packet_loss_num, packet_total_num);
|
||||||
packet_loss_num, packet_total_num);
|
|
||||||
}
|
}
|
|
@ -20,44 +20,44 @@
|
||||||
#include "mbed.h"
|
#include "mbed.h"
|
||||||
#include "rtos.h"
|
#include "rtos.h"
|
||||||
#endif
|
#endif
|
||||||
#include "SDFileSystem.h"
|
#include <string.h>
|
||||||
#include "app_audio.h"
|
|
||||||
#include "audioflinger.h"
|
|
||||||
#include "cqueue.h"
|
|
||||||
#include "hal_timer.h"
|
|
||||||
#include "hal_trace.h"
|
|
||||||
#include "hal_uart.h"
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <stdio.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <ctype.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include "SDFileSystem.h"
|
||||||
|
#include "hal_uart.h"
|
||||||
|
#include "hal_timer.h"
|
||||||
|
#include "hal_trace.h"
|
||||||
|
#include "audioflinger.h"
|
||||||
|
#include "cqueue.h"
|
||||||
|
#include "app_audio.h"
|
||||||
|
|
||||||
#include "audiohw.h"
|
|
||||||
#include "channel_mode.h"
|
|
||||||
#include "codec_platform.h"
|
|
||||||
#include "codeclib.h"
|
|
||||||
#include "codecs.h"
|
|
||||||
#include "compressor.h"
|
|
||||||
#include "dsp_core.h"
|
|
||||||
#include "eq.h"
|
#include "eq.h"
|
||||||
#include "metadata.h"
|
|
||||||
#include "metadata_parsers.h"
|
|
||||||
#include "pga.h"
|
#include "pga.h"
|
||||||
|
#include "metadata.h"
|
||||||
|
#include "dsp_core.h"
|
||||||
|
#include "codecs.h"
|
||||||
|
#include "codeclib.h"
|
||||||
|
#include "compressor.h"
|
||||||
|
#include "channel_mode.h"
|
||||||
|
#include "audiohw.h"
|
||||||
|
#include "codec_platform.h"
|
||||||
|
#include "metadata_parsers.h"
|
||||||
|
|
||||||
#include "app_key.h"
|
|
||||||
#include "app_overlay.h"
|
|
||||||
#include "app_thread.h"
|
|
||||||
#include "app_utils.h"
|
|
||||||
#include "hal_overlay.h"
|
#include "hal_overlay.h"
|
||||||
|
#include "app_overlay.h"
|
||||||
#include "rbpcmbuf.h"
|
#include "rbpcmbuf.h"
|
||||||
#include "rbplay.h"
|
#include "rbplay.h"
|
||||||
|
#include "app_thread.h"
|
||||||
|
#include "app_utils.h"
|
||||||
|
#include "app_key.h"
|
||||||
|
|
||||||
#include "rb_ctl.h"
|
|
||||||
#include "rbplaysd.h"
|
#include "rbplaysd.h"
|
||||||
|
#include "rb_ctl.h"
|
||||||
|
|
||||||
/* Internals */
|
/* Internals */
|
||||||
|
|
||||||
|
@ -75,18 +75,10 @@ extern "C" void hal_sysfreq_print(void);
|
||||||
#define RBPLAY_DEBUG 1
|
#define RBPLAY_DEBUG 1
|
||||||
#if RBPLAY_DEBUG
|
#if RBPLAY_DEBUG
|
||||||
#define _LOG_DBG(str,...) TRACE(0,_LOG_TAG""str, ##__VA_ARGS__)
|
#define _LOG_DBG(str,...) TRACE(0,_LOG_TAG""str, ##__VA_ARGS__)
|
||||||
#define _LOG_ERR(str, ...) \
|
#define _LOG_ERR(str,...) TRACE(0,_LOG_TAG"err:"""str, ##__VA_ARGS__)
|
||||||
TRACE(0, \
|
|
||||||
_LOG_TAG "err:" \
|
|
||||||
"" str, \
|
|
||||||
##__VA_ARGS__)
|
|
||||||
#else
|
#else
|
||||||
#define _LOG_DBG(str,...)
|
#define _LOG_DBG(str,...)
|
||||||
#define _LOG_ERR(str, ...) \
|
#define _LOG_ERR(str,...) TRACE(0,_LOG_TAG"err:"""str, ##__VA_ARGS__)
|
||||||
TRACE(0, \
|
|
||||||
_LOG_TAG "err:" \
|
|
||||||
"" str, \
|
|
||||||
##__VA_ARGS__)
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "rb_ctl.h"
|
#include "rb_ctl.h"
|
||||||
|
@ -111,6 +103,7 @@ int rb_ctl_mailbox_put(RBCTL_MSG_BLOCK *msg_src);
|
||||||
//playlist
|
//playlist
|
||||||
extern playlist_struct sd_playlist;
|
extern playlist_struct sd_playlist;
|
||||||
|
|
||||||
|
|
||||||
rb_ctl_struct rb_ctl_context;
|
rb_ctl_struct rb_ctl_context;
|
||||||
|
|
||||||
extern void rb_thread_set_decode_vars(int fd, int type ,void* id3);
|
extern void rb_thread_set_decode_vars(int fd, int type ,void* id3);
|
||||||
|
@ -122,9 +115,13 @@ extern bool rb_pcmbuf_suspend_play_loop(void);
|
||||||
void app_rbplay_load_playlist(playlist_struct *list );
|
void app_rbplay_load_playlist(playlist_struct *list );
|
||||||
int rb_thread_post_msg(RB_MODULE_EVT evt,uint32_t arg );
|
int rb_thread_post_msg(RB_MODULE_EVT evt,uint32_t arg );
|
||||||
|
|
||||||
static rb_ctl_status rb_ctl_get_status(void) { return rb_ctl_context.status; }
|
static rb_ctl_status rb_ctl_get_status(void)
|
||||||
|
{
|
||||||
|
return rb_ctl_context.status;
|
||||||
|
}
|
||||||
|
|
||||||
bool rb_ctl_parse_file(const char *file_path) {
|
bool rb_ctl_parse_file(const char* file_path)
|
||||||
|
{
|
||||||
/* open file */
|
/* open file */
|
||||||
|
|
||||||
_LOG_DBG(1,"open file %s\n", file_path);
|
_LOG_DBG(1,"open file %s\n", file_path);
|
||||||
|
@ -134,25 +131,21 @@ bool rb_ctl_parse_file(const char *file_path) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!get_metadata(&rb_ctl_context.song_id3, rb_ctl_context.file_handle,
|
if (!get_metadata(&rb_ctl_context.song_id3, rb_ctl_context.file_handle, rb_ctl_context.rb_fname)) {
|
||||||
rb_ctl_context.rb_fname)) {
|
|
||||||
_LOG_DBG(0,"get_metadata failed\n");
|
_LOG_DBG(0,"get_metadata failed\n");
|
||||||
close(rb_ctl_context.file_handle);
|
close(rb_ctl_context.file_handle);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_LOG_DBG(4, "%s bitr:%d,saps %d, freq:%d\n", __func__,
|
_LOG_DBG(4,"%s bitr:%d,saps %d, freq:%d\n",__func__,rb_ctl_context.song_id3.bitrate,rb_ctl_context.song_id3.samples,rb_ctl_context.song_id3.frequency);
|
||||||
rb_ctl_context.song_id3.bitrate, rb_ctl_context.song_id3.samples,
|
|
||||||
rb_ctl_context.song_id3.frequency);
|
|
||||||
|
|
||||||
rb_thread_set_decode_vars(rb_ctl_context.file_handle,
|
rb_thread_set_decode_vars(rb_ctl_context.file_handle, rb_ctl_context.song_id3.codectype,&rb_ctl_context.song_id3);
|
||||||
rb_ctl_context.song_id3.codectype,
|
|
||||||
&rb_ctl_context.song_id3);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void rb_ctl_vol_operation(bool inc) {
|
void rb_ctl_vol_operation(bool inc )
|
||||||
|
{
|
||||||
uint32_t ret;
|
uint32_t ret;
|
||||||
struct AF_STREAM_CONFIG_T *stream_cfg = NULL;
|
struct AF_STREAM_CONFIG_T *stream_cfg = NULL;
|
||||||
|
|
||||||
|
@ -161,6 +154,7 @@ void rb_ctl_vol_operation(bool inc) {
|
||||||
if(inc ) {
|
if(inc ) {
|
||||||
if(rb_ctl_context.rb_player_vol < 16 ) {
|
if(rb_ctl_context.rb_player_vol < 16 ) {
|
||||||
rb_ctl_context.rb_player_vol++;
|
rb_ctl_context.rb_player_vol++;
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(rb_ctl_context.rb_player_vol > 1 ) {
|
if(rb_ctl_context.rb_player_vol > 1 ) {
|
||||||
|
@ -170,19 +164,20 @@ void rb_ctl_vol_operation(bool inc) {
|
||||||
if(rb_ctl_context.status != RB_CTL_PLAYING)
|
if(rb_ctl_context.status != RB_CTL_PLAYING)
|
||||||
return ;
|
return ;
|
||||||
|
|
||||||
ret = af_stream_get_cfg(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK, &stream_cfg,
|
ret = af_stream_get_cfg(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK, &stream_cfg, true);
|
||||||
true);
|
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
stream_cfg->vol = rb_ctl_context.rb_player_vol;
|
stream_cfg->vol = rb_ctl_context.rb_player_vol;
|
||||||
af_stream_setup(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK, stream_cfg);
|
af_stream_setup(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK, stream_cfg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool rb_ctl_is_playing(void) {
|
bool rb_ctl_is_playing(void)
|
||||||
|
{
|
||||||
return (rb_ctl_context.status == RB_CTL_PLAYING);
|
return (rb_ctl_context.status == RB_CTL_PLAYING);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rb_ctl_set_vol(uint32_t vol) {
|
void rb_ctl_set_vol(uint32_t vol)
|
||||||
|
{
|
||||||
uint32_t ret;
|
uint32_t ret;
|
||||||
struct AF_STREAM_CONFIG_T *stream_cfg = NULL;
|
struct AF_STREAM_CONFIG_T *stream_cfg = NULL;
|
||||||
|
|
||||||
|
@ -194,15 +189,15 @@ void rb_ctl_set_vol(uint32_t vol) {
|
||||||
vol = (vol > 16)?16:vol;
|
vol = (vol > 16)?16:vol;
|
||||||
rb_ctl_context.rb_player_vol = vol;
|
rb_ctl_context.rb_player_vol = vol;
|
||||||
|
|
||||||
ret = af_stream_get_cfg(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK, &stream_cfg,
|
ret = af_stream_get_cfg(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK, &stream_cfg, true);
|
||||||
true);
|
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
stream_cfg->vol = rb_ctl_context.rb_player_vol;
|
stream_cfg->vol = rb_ctl_context.rb_player_vol;
|
||||||
af_stream_setup(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK, stream_cfg);
|
af_stream_setup(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK, stream_cfg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void rb_ctl_stop_play(void) {
|
void rb_ctl_stop_play(void )
|
||||||
|
{
|
||||||
_LOG_DBG(1,"%s \n",__func__);
|
_LOG_DBG(1,"%s \n",__func__);
|
||||||
|
|
||||||
rb_codec_set_halt(1);
|
rb_codec_set_halt(1);
|
||||||
|
@ -221,7 +216,8 @@ void rb_ctl_stop_play(void) {
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void rb_ctl_sync_stop_play(void) {
|
void rb_ctl_sync_stop_play(void )
|
||||||
|
{
|
||||||
rb_player_sync_set_wait_thread(osThreadGetId());
|
rb_player_sync_set_wait_thread(osThreadGetId());
|
||||||
|
|
||||||
rb_ctl_stop_play();
|
rb_ctl_stop_play();
|
||||||
|
@ -234,7 +230,8 @@ void rb_ctl_sync_stop_play(void) {
|
||||||
rb_ctl_context.file_handle = -1;
|
rb_ctl_context.file_handle = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void rb_ctl_pause_playing(void) {
|
void rb_ctl_pause_playing(void )
|
||||||
|
{
|
||||||
af_stream_stop(AUD_STREAM_ID_0,AUD_STREAM_PLAYBACK);
|
af_stream_stop(AUD_STREAM_ID_0,AUD_STREAM_PLAYBACK);
|
||||||
_LOG_DBG(0," af stream close \n");
|
_LOG_DBG(0," af stream close \n");
|
||||||
af_stream_close(AUD_STREAM_ID_0,AUD_STREAM_PLAYBACK);
|
af_stream_close(AUD_STREAM_ID_0,AUD_STREAM_PLAYBACK);
|
||||||
|
@ -248,65 +245,70 @@ void rb_ctl_pause_playing(void) {
|
||||||
_LOG_DBG(1,"%s sucessed ",__func__);
|
_LOG_DBG(1,"%s sucessed ",__func__);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rb_ctl_resume_playing(void) {
|
void rb_ctl_resume_playing(void )
|
||||||
|
{
|
||||||
#ifndef __TWS__
|
#ifndef __TWS__
|
||||||
rb_pcmbuf_init();
|
rb_pcmbuf_init();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void rb_ctl_set_priority(int priority) {
|
|
||||||
|
void rb_ctl_set_priority(int priority)
|
||||||
|
{
|
||||||
osThreadSetPriority(rb_ctl_tid, (osPriority)priority);
|
osThreadSetPriority(rb_ctl_tid, (osPriority)priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
int rb_ctl_get_priority(void) { return (int)osThreadGetPriority(rb_ctl_tid); }
|
int rb_ctl_get_priority(void)
|
||||||
|
{
|
||||||
|
return (int)osThreadGetPriority(rb_ctl_tid);
|
||||||
|
}
|
||||||
|
|
||||||
int rb_ctl_get_default_priority(void) { return rb_ctl_default_priority; }
|
int rb_ctl_get_default_priority(void)
|
||||||
|
{
|
||||||
|
return rb_ctl_default_priority;
|
||||||
|
}
|
||||||
|
|
||||||
void rb_ctl_reset_priority(void) {
|
void rb_ctl_reset_priority(void)
|
||||||
|
{
|
||||||
osThreadSetPriority(rb_ctl_tid, (osPriority)rb_ctl_default_priority);
|
osThreadSetPriority(rb_ctl_tid, (osPriority)rb_ctl_default_priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __IAG_BLE_INCLUDE__
|
#ifdef __IAG_BLE_INCLUDE__
|
||||||
extern "C" void app_ble_inform_music_switch(uint16_t index);
|
extern "C" void app_ble_inform_music_switch(uint16_t index);
|
||||||
#endif
|
#endif
|
||||||
static int rb_ctl_handle_event(RBCTL_MSG_BLOCK *msg_body) {
|
static int rb_ctl_handle_event(RBCTL_MSG_BLOCK *msg_body)
|
||||||
|
{
|
||||||
RB_MODULE_EVT evt =(RB_MODULE_EVT) msg_body->evt;
|
RB_MODULE_EVT evt =(RB_MODULE_EVT) msg_body->evt;
|
||||||
uint32_t arg = msg_body->arg;
|
uint32_t arg = msg_body->arg;
|
||||||
// hal_sysfreq_print();
|
// hal_sysfreq_print();
|
||||||
|
|
||||||
|
|
||||||
switch(evt) {
|
switch(evt) {
|
||||||
case RB_MODULE_EVT_PLAY:
|
case RB_MODULE_EVT_PLAY:
|
||||||
if(rb_ctl_context.status != RB_CTL_IDLE) {
|
if(rb_ctl_context.status != RB_CTL_IDLE) {
|
||||||
if(rb_ctl_context.status == RB_CTL_SUSPEND)
|
if(rb_ctl_context.status == RB_CTL_SUSPEND)
|
||||||
rb_thread_send_resume();
|
rb_thread_send_resume();
|
||||||
else
|
else
|
||||||
_LOG_DBG(2, "%s st %d not in idle \n", __func__,
|
_LOG_DBG(2,"%s st %d not in idle \n",__func__,rb_ctl_context.status);
|
||||||
rb_ctl_context.status);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_LOG_DBG(3, " %s start %d/%d ", __func__, rb_ctl_context.curr_song_idx,
|
_LOG_DBG(3," %s start %d/%d ",__func__, rb_ctl_context.curr_song_idx ,sd_playlist.total_songs);
|
||||||
sd_playlist.total_songs);
|
|
||||||
if(sd_playlist.total_songs > 0 ) {
|
if(sd_playlist.total_songs > 0 ) {
|
||||||
playlist_item *it;
|
playlist_item *it;
|
||||||
|
|
||||||
it = app_rbplay_get_playitem(rb_ctl_context.curr_song_idx) ;
|
it = app_rbplay_get_playitem(rb_ctl_context.curr_song_idx) ;
|
||||||
|
|
||||||
if(it == NULL) {
|
if(it == NULL) {
|
||||||
_LOG_DBG(2, " %s get item fail idx %d", __func__,
|
_LOG_DBG(2," %s get item fail idx %d",__func__,rb_ctl_context.curr_song_idx);
|
||||||
rb_ctl_context.curr_song_idx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_LOG_DBG(2, "%s start songidx %d \n", __func__,
|
_LOG_DBG(2,"%s start songidx %d \n",__func__,rb_ctl_context.curr_song_idx);
|
||||||
rb_ctl_context.curr_song_idx);
|
|
||||||
|
|
||||||
memcpy(rb_ctl_context.rb_audio_file, it->file_path,
|
memcpy(rb_ctl_context.rb_audio_file,it->file_path,sizeof(uint16_t)*FILE_PATH_LEN - 4);
|
||||||
sizeof(uint16_t) * FILE_PATH_LEN - 4);
|
memcpy(rb_ctl_context.rb_fname,it->file_name,sizeof(rb_ctl_context.rb_fname));
|
||||||
memcpy(rb_ctl_context.rb_fname, it->file_name,
|
|
||||||
sizeof(rb_ctl_context.rb_fname));
|
|
||||||
|
|
||||||
if(rb_ctl_parse_file((const char*)rb_ctl_context.rb_audio_file)) {
|
if(rb_ctl_parse_file((const char*)rb_ctl_context.rb_audio_file)) {
|
||||||
_LOG_DBG(2, "%s start init, the tid 0x%x\n", __func__,
|
_LOG_DBG(2,"%s start init, the tid 0x%x\n",__func__,osThreadGetId());
|
||||||
osThreadGetId());
|
|
||||||
rb_play_codec_init();
|
rb_play_codec_init();
|
||||||
_LOG_DBG(1,"%s start run\n",__func__);
|
_LOG_DBG(1,"%s start run\n",__func__);
|
||||||
rb_play_codec_run();
|
rb_play_codec_run();
|
||||||
|
@ -314,8 +316,7 @@ static int rb_ctl_handle_event(RBCTL_MSG_BLOCK *msg_body) {
|
||||||
app_rbcodec_ctl_set_play_status(true);
|
app_rbcodec_ctl_set_play_status(true);
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
_LOG_DBG(2, "%s evt %d parse fail,find next\n", __func__,
|
_LOG_DBG(2,"%s evt %d parse fail,find next\n",__func__,msg_body->evt);
|
||||||
msg_body->evt);
|
|
||||||
rb_thread_post_msg(RB_MODULE_EVT_PLAY_NEXT,true);
|
rb_thread_post_msg(RB_MODULE_EVT_PLAY_NEXT,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -359,6 +360,7 @@ static int rb_ctl_handle_event(RBCTL_MSG_BLOCK *msg_body) {
|
||||||
} else if( rb_ctl_context.status == RB_CTL_SUSPEND) {
|
} else if( rb_ctl_context.status == RB_CTL_SUSPEND) {
|
||||||
rb_thread_post_msg(RB_MODULE_EVT_STOP,0 );
|
rb_thread_post_msg(RB_MODULE_EVT_STOP,0 );
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
}
|
}
|
||||||
if(arg == 0) {
|
if(arg == 0) {
|
||||||
rb_ctl_context.curr_song_idx--;
|
rb_ctl_context.curr_song_idx--;
|
||||||
|
@ -399,6 +401,7 @@ static int rb_ctl_handle_event(RBCTL_MSG_BLOCK *msg_body) {
|
||||||
} else if( rb_ctl_context.status == RB_CTL_SUSPEND) {
|
} else if( rb_ctl_context.status == RB_CTL_SUSPEND) {
|
||||||
rb_thread_post_msg(RB_MODULE_EVT_STOP,0 );
|
rb_thread_post_msg(RB_MODULE_EVT_STOP,0 );
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rb_ctl_context.curr_song_idx = (uint16_t)arg;
|
rb_ctl_context.curr_song_idx = (uint16_t)arg;
|
||||||
|
@ -462,35 +465,41 @@ static int rb_ctl_handle_event(RBCTL_MSG_BLOCK *msg_body) {
|
||||||
#endif
|
#endif
|
||||||
#ifdef SBC_RECORD_TEST
|
#ifdef SBC_RECORD_TEST
|
||||||
|
|
||||||
case SBC_RECORD_ACTION_START: {
|
case SBC_RECORD_ACTION_START:
|
||||||
|
{
|
||||||
rb_ctl_context.sbc_record_on = true;
|
rb_ctl_context.sbc_record_on = true;
|
||||||
app_rbplay_set_store_flag(true);
|
app_rbplay_set_store_flag(true);
|
||||||
app_rbplay_open_sbc_file();
|
app_rbplay_open_sbc_file();
|
||||||
|
|
||||||
} break;
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case SBC_RECORD_ACTION_DATA_IND: {
|
case SBC_RECORD_ACTION_DATA_IND:
|
||||||
|
{
|
||||||
if(rb_ctl_context.sbc_record_on) {
|
if(rb_ctl_context.sbc_record_on) {
|
||||||
app_rbplay_process_sbc_data();
|
app_rbplay_process_sbc_data();
|
||||||
}
|
}
|
||||||
} break;
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case SBC_RECORD_ACTION_STOP: {
|
case SBC_RECORD_ACTION_STOP:
|
||||||
|
{
|
||||||
rb_ctl_context.sbc_record_on = false;
|
rb_ctl_context.sbc_record_on = false;
|
||||||
app_rbplay_set_store_flag(false);
|
app_rbplay_set_store_flag(false);
|
||||||
app_rbplay_close_sbc_file();
|
app_rbplay_close_sbc_file();
|
||||||
} break;
|
}
|
||||||
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(SBC_RECORD_ACTION_DATA_IND !=msg_body->evt)
|
if(SBC_RECORD_ACTION_DATA_IND !=msg_body->evt)
|
||||||
_LOG_DBG(3, "%s rbcodec evt %d ,st %d ended\n", __func__, msg_body->evt,
|
_LOG_DBG(3,"%s rbcodec evt %d ,st %d ended\n",__func__,msg_body->evt,rb_ctl_context.status);
|
||||||
rb_ctl_context.status);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rb_thread_post_msg(RB_MODULE_EVT evt, uint32_t arg) {
|
int rb_thread_post_msg(RB_MODULE_EVT evt,uint32_t arg )
|
||||||
|
{
|
||||||
int ret;
|
int ret;
|
||||||
RBCTL_MSG_BLOCK msg;
|
RBCTL_MSG_BLOCK msg;
|
||||||
|
|
||||||
|
@ -505,12 +514,14 @@ int rb_thread_post_msg(RB_MODULE_EVT evt, uint32_t arg) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void app_wait_player_stoped(void) {
|
void app_wait_player_stoped(void )
|
||||||
|
{
|
||||||
while(rb_ctl_context.status != RB_CTL_IDLE)
|
while(rb_ctl_context.status != RB_CTL_IDLE)
|
||||||
osThreadYield();
|
osThreadYield();
|
||||||
}
|
}
|
||||||
|
|
||||||
void app_wait_player_suspend(void) {
|
void app_wait_player_suspend(void )
|
||||||
|
{
|
||||||
if(rb_ctl_context.status == RB_CTL_IDLE)
|
if(rb_ctl_context.status == RB_CTL_IDLE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -518,7 +529,8 @@ void app_wait_player_suspend(void) {
|
||||||
osThreadYield();
|
osThreadYield();
|
||||||
}
|
}
|
||||||
|
|
||||||
void app_wait_player_resumed(void) {
|
void app_wait_player_resumed(void )
|
||||||
|
{
|
||||||
if(rb_ctl_context.status == RB_CTL_IDLE)
|
if(rb_ctl_context.status == RB_CTL_IDLE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -526,12 +538,14 @@ void app_wait_player_resumed(void) {
|
||||||
osThreadYield();
|
osThreadYield();
|
||||||
}
|
}
|
||||||
|
|
||||||
void rb_thread_send_play(void) {
|
void rb_thread_send_play(void )
|
||||||
|
{
|
||||||
_LOG_DBG(1," %s ",__FUNCTION__);
|
_LOG_DBG(1," %s ",__FUNCTION__);
|
||||||
rb_thread_post_msg(RB_MODULE_EVT_PLAY, (uint32_t)osThreadGetId());
|
rb_thread_post_msg(RB_MODULE_EVT_PLAY, (uint32_t)osThreadGetId());
|
||||||
}
|
}
|
||||||
|
|
||||||
void rb_thread_send_stop(void) {
|
void rb_thread_send_stop(void )
|
||||||
|
{
|
||||||
_LOG_DBG(1," %s ",__FUNCTION__);
|
_LOG_DBG(1," %s ",__FUNCTION__);
|
||||||
rb_thread_post_msg(RB_MODULE_EVT_STOP, (uint32_t)osThreadGetId());
|
rb_thread_post_msg(RB_MODULE_EVT_STOP, (uint32_t)osThreadGetId());
|
||||||
|
|
||||||
|
@ -539,7 +553,8 @@ void rb_thread_send_stop(void) {
|
||||||
app_wait_player_stoped();
|
app_wait_player_stoped();
|
||||||
}
|
}
|
||||||
|
|
||||||
void rb_thread_send_pause(void) {
|
void rb_thread_send_pause(void)
|
||||||
|
{
|
||||||
_LOG_DBG(1," %s ",__FUNCTION__);
|
_LOG_DBG(1," %s ",__FUNCTION__);
|
||||||
|
|
||||||
rb_thread_post_msg(RB_MODULE_EVT_SUSPEND,(uint32_t)osThreadGetId());
|
rb_thread_post_msg(RB_MODULE_EVT_SUSPEND,(uint32_t)osThreadGetId());
|
||||||
|
@ -548,7 +563,8 @@ void rb_thread_send_pause(void) {
|
||||||
_LOG_DBG(1," %s end",__FUNCTION__);
|
_LOG_DBG(1," %s end",__FUNCTION__);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rb_thread_send_resume(void) {
|
void rb_thread_send_resume(void)
|
||||||
|
{
|
||||||
_LOG_DBG(1," %s ",__FUNCTION__);
|
_LOG_DBG(1," %s ",__FUNCTION__);
|
||||||
|
|
||||||
rb_thread_post_msg(RB_MODULE_EVT_RESUME,(uint32_t)osThreadGetId());
|
rb_thread_post_msg(RB_MODULE_EVT_RESUME,(uint32_t)osThreadGetId());
|
||||||
|
@ -556,14 +572,16 @@ void rb_thread_send_resume(void) {
|
||||||
_LOG_DBG(1," %s end",__FUNCTION__);
|
_LOG_DBG(1," %s end",__FUNCTION__);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rb_play_dual_play_restore(uint8_t stream_type) {
|
void rb_play_dual_play_restore(uint8_t stream_type )
|
||||||
|
{
|
||||||
_LOG_DBG(2,"%s %d \n", __func__, __LINE__);
|
_LOG_DBG(2,"%s %d \n", __func__, __LINE__);
|
||||||
|
|
||||||
rb_thread_post_msg(RB_MODULE_EVT_RESTORE_DUAL_PLAY, stream_type);
|
rb_thread_post_msg(RB_MODULE_EVT_RESTORE_DUAL_PLAY, stream_type);
|
||||||
_LOG_DBG(2,"%s %d \n", __func__, __LINE__);
|
_LOG_DBG(2,"%s %d \n", __func__, __LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rb_thread_send_switch(bool next) {
|
void rb_thread_send_switch(bool next)
|
||||||
|
{
|
||||||
_LOG_DBG(2,"%s %d \n", __func__, __LINE__);
|
_LOG_DBG(2,"%s %d \n", __func__, __LINE__);
|
||||||
|
|
||||||
rb_thread_post_msg(RB_MODULE_EVT_PLAY_NEXT,next);
|
rb_thread_post_msg(RB_MODULE_EVT_PLAY_NEXT,next);
|
||||||
|
@ -571,85 +589,99 @@ void rb_thread_send_switch(bool next) {
|
||||||
_LOG_DBG(2,"%s %d \n", __func__, __LINE__);
|
_LOG_DBG(2,"%s %d \n", __func__, __LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rb_play_linein_start(void) {
|
void rb_play_linein_start(void )
|
||||||
|
{
|
||||||
_LOG_DBG(2,"%s %d \n", __func__, __LINE__);
|
_LOG_DBG(2,"%s %d \n", __func__, __LINE__);
|
||||||
|
|
||||||
rb_thread_post_msg(RB_MODULE_EVT_LINEIN_START, 0);
|
rb_thread_post_msg(RB_MODULE_EVT_LINEIN_START, 0);
|
||||||
_LOG_DBG(2,"%s %d \n", __func__, __LINE__);
|
_LOG_DBG(2,"%s %d \n", __func__, __LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rb_play_reconfig_stream(uint32_t arg) {
|
void rb_play_reconfig_stream(uint32_t arg )
|
||||||
|
{
|
||||||
_LOG_DBG(3,"%s %d arg:0x%x\n", __func__, __LINE__, arg);
|
_LOG_DBG(3,"%s %d arg:0x%x\n", __func__, __LINE__, arg);
|
||||||
|
|
||||||
rb_thread_post_msg(RB_MODULE_EVT_RECONFIG_STREAM, arg);
|
rb_thread_post_msg(RB_MODULE_EVT_RECONFIG_STREAM, arg);
|
||||||
_LOG_DBG(2,"%s %d \n", __func__, __LINE__);
|
_LOG_DBG(2,"%s %d \n", __func__, __LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rb_play_set_tws_mode(uint32_t arg) {
|
void rb_play_set_tws_mode(uint32_t arg )
|
||||||
|
{
|
||||||
_LOG_DBG(3,"%s %d arg:0x%x\n", __func__, __LINE__, arg);
|
_LOG_DBG(3,"%s %d arg:0x%x\n", __func__, __LINE__, arg);
|
||||||
|
|
||||||
rb_thread_post_msg(RB_MODULE_EVT_SET_TWS_MODE, arg);
|
rb_thread_post_msg(RB_MODULE_EVT_SET_TWS_MODE, arg);
|
||||||
_LOG_DBG(2,"%s %d \n", __func__, __LINE__);
|
_LOG_DBG(2,"%s %d \n", __func__, __LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rb_thread_send_play_idx(uint32_t array_subidx) {
|
void rb_thread_send_play_idx(uint32_t array_subidx)
|
||||||
|
{
|
||||||
_LOG_DBG(2," %s array_subidx %d, ",__FUNCTION__,array_subidx);
|
_LOG_DBG(2," %s array_subidx %d, ",__FUNCTION__,array_subidx);
|
||||||
|
|
||||||
rb_thread_post_msg(RB_MODULE_EVT_PLAY_IDX,array_subidx);
|
rb_thread_post_msg(RB_MODULE_EVT_PLAY_IDX,array_subidx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rb_thread_send_vol(bool inc) {
|
|
||||||
|
void rb_thread_send_vol(bool inc)
|
||||||
|
{
|
||||||
_LOG_DBG(2," %s inc %d, ",__FUNCTION__,inc);
|
_LOG_DBG(2," %s inc %d, ",__FUNCTION__,inc);
|
||||||
|
|
||||||
rb_thread_post_msg(RB_MODULE_EVT_CHANGE_VOL,inc);
|
rb_thread_post_msg(RB_MODULE_EVT_CHANGE_VOL,inc);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rb_thread_send_status_change(void) {
|
void rb_thread_send_status_change(void )
|
||||||
|
{
|
||||||
_LOG_DBG(1," %s , ",__FUNCTION__);
|
_LOG_DBG(1," %s , ",__FUNCTION__);
|
||||||
|
|
||||||
rb_thread_post_msg(RB_MODULE_EVT_CHANGE_IDLE,0);
|
rb_thread_post_msg(RB_MODULE_EVT_CHANGE_IDLE,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rb_thread_set_vol(uint32_t vol) {
|
void rb_thread_set_vol(uint32_t vol)
|
||||||
|
{
|
||||||
_LOG_DBG(1," %s , ",__FUNCTION__);
|
_LOG_DBG(1," %s , ",__FUNCTION__);
|
||||||
|
|
||||||
rb_thread_post_msg(RB_MODULE_EVT_SET_VOL, vol);
|
rb_thread_post_msg(RB_MODULE_EVT_SET_VOL, vol);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rb_thread_send_del_file(uint16_t idx) {
|
void rb_thread_send_del_file(uint16_t idx )
|
||||||
|
{
|
||||||
_LOG_DBG(1," %s , ",__FUNCTION__);
|
_LOG_DBG(1," %s , ",__FUNCTION__);
|
||||||
|
|
||||||
rb_thread_post_msg(RB_MODULE_EVT_DEL_FILE,idx);
|
rb_thread_post_msg(RB_MODULE_EVT_DEL_FILE,idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rb_thread_send_sbc_record_start(void) {
|
void rb_thread_send_sbc_record_start(void )
|
||||||
|
{
|
||||||
_LOG_DBG(1," %s , ",__FUNCTION__);
|
_LOG_DBG(1," %s , ",__FUNCTION__);
|
||||||
|
|
||||||
rb_thread_post_msg(SBC_RECORD_ACTION_START,(uint32_t)osThreadGetId());
|
rb_thread_post_msg(SBC_RECORD_ACTION_START,(uint32_t)osThreadGetId());
|
||||||
}
|
}
|
||||||
|
|
||||||
void rb_thread_send_sbc_record_data_ind(void) {
|
void rb_thread_send_sbc_record_data_ind(void )
|
||||||
|
{
|
||||||
if(!rb_ctl_context.sbc_record_on)
|
if(!rb_ctl_context.sbc_record_on)
|
||||||
return ;
|
return ;
|
||||||
// _LOG_DBG(1," %s , ",__FUNCTION__);
|
// _LOG_DBG(1," %s , ",__FUNCTION__);
|
||||||
rb_thread_post_msg(SBC_RECORD_ACTION_DATA_IND,(uint32_t)osThreadGetId());
|
rb_thread_post_msg(SBC_RECORD_ACTION_DATA_IND,(uint32_t)osThreadGetId());
|
||||||
}
|
}
|
||||||
|
|
||||||
void rb_thread_send_sbc_record_stop(void) {
|
void rb_thread_send_sbc_record_stop(void )
|
||||||
|
{
|
||||||
_LOG_DBG(1," %s , ",__FUNCTION__);
|
_LOG_DBG(1," %s , ",__FUNCTION__);
|
||||||
|
|
||||||
rb_thread_post_msg(SBC_RECORD_ACTION_STOP,(uint32_t)osThreadGetId());
|
rb_thread_post_msg(SBC_RECORD_ACTION_STOP,(uint32_t)osThreadGetId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//interface for audio module
|
//interface for audio module
|
||||||
static bool user_key_pause_stream = false;
|
static bool user_key_pause_stream = false;
|
||||||
void app_rbplay_audio_reset_pause_status(void) {
|
void app_rbplay_audio_reset_pause_status(void)
|
||||||
|
{
|
||||||
user_key_pause_stream = false;
|
user_key_pause_stream = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_rbplay_audio_onoff(bool onoff, uint16_t aud_id) {
|
int app_rbplay_audio_onoff(bool onoff, uint16_t aud_id)
|
||||||
_LOG_DBG(3, " %s onoff %d, get status:%d", __FUNCTION__, onoff,
|
{
|
||||||
rb_ctl_get_status());
|
_LOG_DBG(3," %s onoff %d, get status:%d",__FUNCTION__,onoff, rb_ctl_get_status());
|
||||||
|
|
||||||
if(app_rbcodec_check_hfp_active()&& !onoff) {
|
if(app_rbcodec_check_hfp_active()&& !onoff) {
|
||||||
if( RB_CTL_PLAYING == rb_ctl_get_status()) {
|
if( RB_CTL_PLAYING == rb_ctl_get_status()) {
|
||||||
|
@ -672,7 +704,8 @@ int app_rbplay_audio_onoff(bool onoff, uint16_t aud_id) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void app_rbplay_pause_resume(void) {
|
void app_rbplay_pause_resume(void)
|
||||||
|
{
|
||||||
_LOG_DBG(2," %s get status:%d",__func__, rb_ctl_get_status());
|
_LOG_DBG(2," %s get status:%d",__func__, rb_ctl_get_status());
|
||||||
|
|
||||||
user_key_pause_stream = true;
|
user_key_pause_stream = true;
|
||||||
|
@ -687,7 +720,8 @@ void app_rbplay_pause_resume(void) {
|
||||||
}
|
}
|
||||||
//sbc reader run within thread
|
//sbc reader run within thread
|
||||||
|
|
||||||
static int rb_ctl_mailbox_init(void) {
|
static int rb_ctl_mailbox_init(void)
|
||||||
|
{
|
||||||
rb_ctl_mailbox = osMailCreate(osMailQ(rb_ctl_mailbox), NULL);
|
rb_ctl_mailbox = osMailCreate(osMailQ(rb_ctl_mailbox), NULL);
|
||||||
if (rb_ctl_mailbox == NULL) {
|
if (rb_ctl_mailbox == NULL) {
|
||||||
TRACE(0,"Failed to Create rb_ctl_mailbox\n");
|
TRACE(0,"Failed to Create rb_ctl_mailbox\n");
|
||||||
|
@ -696,7 +730,8 @@ static int rb_ctl_mailbox_init(void) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rb_ctl_mailbox_put(RBCTL_MSG_BLOCK *msg_src) {
|
int rb_ctl_mailbox_put(RBCTL_MSG_BLOCK* msg_src)
|
||||||
|
{
|
||||||
osStatus status;
|
osStatus status;
|
||||||
|
|
||||||
RBCTL_MSG_BLOCK *msg_p = NULL;
|
RBCTL_MSG_BLOCK *msg_p = NULL;
|
||||||
|
@ -717,7 +752,8 @@ int rb_ctl_mailbox_put(RBCTL_MSG_BLOCK *msg_src) {
|
||||||
return (int)status;
|
return (int)status;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rb_ctl_mailbox_free(RBCTL_MSG_BLOCK *msg_p) {
|
int rb_ctl_mailbox_free(RBCTL_MSG_BLOCK* msg_p)
|
||||||
|
{
|
||||||
osStatus status;
|
osStatus status;
|
||||||
|
|
||||||
status = osMailFree(rb_ctl_mailbox, msg_p);
|
status = osMailFree(rb_ctl_mailbox, msg_p);
|
||||||
|
@ -725,7 +761,8 @@ int rb_ctl_mailbox_free(RBCTL_MSG_BLOCK *msg_p) {
|
||||||
return (int)status;
|
return (int)status;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rb_ctl_mailbox_get(RBCTL_MSG_BLOCK **msg_p) {
|
int rb_ctl_mailbox_get(RBCTL_MSG_BLOCK** msg_p)
|
||||||
|
{
|
||||||
osEvent evt;
|
osEvent evt;
|
||||||
evt = osMailGet(rb_ctl_mailbox, osWaitForever);
|
evt = osMailGet(rb_ctl_mailbox, osWaitForever);
|
||||||
if (evt.status == osEventMail) {
|
if (evt.status == osEventMail) {
|
||||||
|
@ -770,7 +807,8 @@ void rb_ctl_action_stop(void)
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
static void rb_ctl_thread(void const *argument) {
|
static void rb_ctl_thread(void const *argument)
|
||||||
|
{
|
||||||
osEvent evt;
|
osEvent evt;
|
||||||
#if 1
|
#if 1
|
||||||
app_sysfreq_req(APP_SYSFREQ_USER_APP_PLAYER, APP_SYSFREQ_208M);
|
app_sysfreq_req(APP_SYSFREQ_USER_APP_PLAYER, APP_SYSFREQ_208M);
|
||||||
|
@ -781,6 +819,7 @@ static void rb_ctl_thread(void const *argument) {
|
||||||
rb_ctl_context.rb_player_vol = 6;
|
rb_ctl_context.rb_player_vol = 6;
|
||||||
rb_ctl_context.status = RB_CTL_IDLE;
|
rb_ctl_context.status = RB_CTL_IDLE;
|
||||||
|
|
||||||
|
|
||||||
rb_ctl_context.curr_song_idx = 0;
|
rb_ctl_context.curr_song_idx = 0;
|
||||||
//load playlist here
|
//load playlist here
|
||||||
|
|
||||||
|
@ -803,7 +842,9 @@ static void rb_ctl_thread(void const *argument) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int rb_ctl_init(void) {
|
|
||||||
|
int rb_ctl_init(void)
|
||||||
|
{
|
||||||
_LOG_DBG(1,"%s \n",__func__);
|
_LOG_DBG(1,"%s \n",__func__);
|
||||||
|
|
||||||
rb_ctl_context.init_done = false;
|
rb_ctl_context.init_done = false;
|
||||||
|
@ -824,10 +865,23 @@ int rb_ctl_init(void) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t rb_ctl_get_vol(void) { return rb_ctl_context.rb_player_vol; }
|
uint8_t rb_ctl_get_vol(void)
|
||||||
|
{
|
||||||
|
return rb_ctl_context.rb_player_vol;
|
||||||
|
}
|
||||||
|
|
||||||
bool rb_ctl_is_init_done(void) { return rb_ctl_context.init_done; }
|
bool rb_ctl_is_init_done(void)
|
||||||
|
{
|
||||||
|
return rb_ctl_context.init_done;
|
||||||
|
}
|
||||||
|
|
||||||
bool rb_ctl_is_paused(void) { return (RB_CTL_SUSPEND == rb_ctl_get_status()); }
|
bool rb_ctl_is_paused(void)
|
||||||
|
{
|
||||||
|
return ( RB_CTL_SUSPEND == rb_ctl_get_status());
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t rb_ctl_songs_count(void)
|
||||||
|
{
|
||||||
|
return sd_playlist.total_songs;
|
||||||
|
}
|
||||||
|
|
||||||
uint16_t rb_ctl_songs_count(void) { return sd_playlist.total_songs; }
|
|
||||||
|
|
|
@ -15,24 +15,24 @@
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
/* rbpcmbuf source */
|
/* rbpcmbuf source */
|
||||||
/* pcmbuf management & af control & mixer */
|
/* pcmbuf management & af control & mixer */
|
||||||
#include <ctype.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <ctype.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#ifdef MBED
|
#ifdef MBED
|
||||||
#include "mbed.h"
|
#include "mbed.h"
|
||||||
#include "rtos.h"
|
#include "rtos.h"
|
||||||
#endif
|
#endif
|
||||||
#include "app_audio.h"
|
|
||||||
#include "app_utils.h"
|
|
||||||
#include "audioflinger.h"
|
#include "audioflinger.h"
|
||||||
#include "cqueue.h"
|
#include "cqueue.h"
|
||||||
|
#include "app_audio.h"
|
||||||
|
#include "app_utils.h"
|
||||||
#include "hal_trace.h"
|
#include "hal_trace.h"
|
||||||
|
|
||||||
#include "rbpcmbuf.h"
|
|
||||||
#include "rbplay.h"
|
#include "rbplay.h"
|
||||||
|
#include "rbpcmbuf.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
#define RB_PCMBUF_DMA_BUFFER_SIZE (1024*12)
|
#define RB_PCMBUF_DMA_BUFFER_SIZE (1024*12)
|
||||||
|
@ -47,17 +47,17 @@ static osMutexId _rb_media_buf_queue_mutex_id = NULL;
|
||||||
static osMutexDef(_rb_media_buf_queue_mutex);
|
static osMutexDef(_rb_media_buf_queue_mutex);
|
||||||
|
|
||||||
#define LOCK_MEDIA_BUF_QUEUE() \
|
#define LOCK_MEDIA_BUF_QUEUE() \
|
||||||
if (osErrorISR == \
|
if(osErrorISR == osMutexWait(_rb_media_buf_queue_mutex_id, osWaitForever)) {\
|
||||||
osMutexWait(_rb_media_buf_queue_mutex_id, osWaitForever)) { \
|
|
||||||
error("%s LOCK_MEDIA_BUF_QUEUE from IRQ!!!!!!!\n",__func__);\
|
error("%s LOCK_MEDIA_BUF_QUEUE from IRQ!!!!!!!\n",__func__);\
|
||||||
}
|
}\
|
||||||
|
|
||||||
#define UNLOCK_MEDIA_BUF_QUEUE() \
|
#define UNLOCK_MEDIA_BUF_QUEUE() \
|
||||||
if(osErrorISR == osMutexRelease(_rb_media_buf_queue_mutex_id)){ \
|
if(osErrorISR == osMutexRelease(_rb_media_buf_queue_mutex_id)){ \
|
||||||
error("%s UNLOCK_MEDIA_BUF_QUEUE from IRQ!!!!!!\n"); \
|
error("%s UNLOCK_MEDIA_BUF_QUEUE from IRQ!!!!!!\n"); \
|
||||||
}
|
} \
|
||||||
|
|
||||||
static uint32_t rbplay_more_data(uint8_t *buf, uint32_t len) {
|
static uint32_t rbplay_more_data(uint8_t *buf, uint32_t len)
|
||||||
|
{
|
||||||
CQItemType *e1 = NULL;
|
CQItemType *e1 = NULL;
|
||||||
CQItemType *e2 = NULL;
|
CQItemType *e2 = NULL;
|
||||||
unsigned int len1 = 0;
|
unsigned int len1 = 0;
|
||||||
|
@ -83,17 +83,16 @@ static uint32_t rbplay_more_data(uint8_t *buf, uint32_t len) {
|
||||||
}
|
}
|
||||||
|
|
||||||
extern uint8_t rb_ctl_get_vol(void);
|
extern uint8_t rb_ctl_get_vol(void);
|
||||||
void rb_pcmbuf_init(void) {
|
void rb_pcmbuf_init(void)
|
||||||
|
{
|
||||||
info("pcmbuff init");
|
info("pcmbuff init");
|
||||||
if(!_rb_media_buf_queue_mutex_id)
|
if(!_rb_media_buf_queue_mutex_id)
|
||||||
_rb_media_buf_queue_mutex_id =
|
_rb_media_buf_queue_mutex_id = osMutexCreate((osMutex(_rb_media_buf_queue_mutex)));
|
||||||
osMutexCreate((osMutex(_rb_media_buf_queue_mutex)));
|
|
||||||
|
|
||||||
app_audio_mempool_init();
|
app_audio_mempool_init();
|
||||||
|
|
||||||
app_audio_mempool_get_buff(&rb_pcmbuf_media_buf, RB_PCMBUF_MEDIA_BUFFER_SIZE);
|
app_audio_mempool_get_buff(&rb_pcmbuf_media_buf, RB_PCMBUF_MEDIA_BUFFER_SIZE);
|
||||||
InitCQueue(&rb_pcmbuf_media_buf_queue, RB_PCMBUF_MEDIA_BUFFER_SIZE,
|
InitCQueue(&rb_pcmbuf_media_buf_queue, RB_PCMBUF_MEDIA_BUFFER_SIZE, (unsigned char *)rb_pcmbuf_media_buf);
|
||||||
(unsigned char *)rb_pcmbuf_media_buf);
|
|
||||||
|
|
||||||
app_audio_mempool_get_buff(&rbplay_dma_buffer, RB_PCMBUF_DMA_BUFFER_SIZE);
|
app_audio_mempool_get_buff(&rbplay_dma_buffer, RB_PCMBUF_DMA_BUFFER_SIZE);
|
||||||
app_audio_mempool_get_buff(&rb_decode_out_buff, RB_DECODE_OUT_BUFFER_SIZE);
|
app_audio_mempool_get_buff(&rb_decode_out_buff, RB_DECODE_OUT_BUFFER_SIZE);
|
||||||
|
@ -116,23 +115,26 @@ void rb_pcmbuf_init(void) {
|
||||||
af_stream_start(AUD_STREAM_ID_0,AUD_STREAM_PLAYBACK);
|
af_stream_start(AUD_STREAM_ID_0,AUD_STREAM_PLAYBACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *rb_pcmbuf_request_buffer(int *size) {
|
void *rb_pcmbuf_request_buffer(int *size)
|
||||||
|
{
|
||||||
*size = RB_DECODE_OUT_BUFFER_SIZE / 4;
|
*size = RB_DECODE_OUT_BUFFER_SIZE / 4;
|
||||||
return rb_decode_out_buff;
|
return rb_decode_out_buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
void rb_pcmbuf_write(unsigned int size) {
|
void rb_pcmbuf_write(unsigned int size)
|
||||||
|
{
|
||||||
int ret ;
|
int ret ;
|
||||||
do {
|
do {
|
||||||
LOCK_MEDIA_BUF_QUEUE();
|
LOCK_MEDIA_BUF_QUEUE();
|
||||||
ret = EnCQueue(&rb_pcmbuf_media_buf_queue, (CQItemType *)rb_decode_out_buff,
|
ret = EnCQueue(&rb_pcmbuf_media_buf_queue, (CQItemType *)rb_decode_out_buff, size*(2*2));
|
||||||
size * (2 * 2));
|
|
||||||
UNLOCK_MEDIA_BUF_QUEUE();
|
UNLOCK_MEDIA_BUF_QUEUE();
|
||||||
osThreadYield();
|
osThreadYield();
|
||||||
} while (ret == CQ_ERR);
|
} while (ret == CQ_ERR);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rb_pcmbuf_stop(void) {
|
void rb_pcmbuf_stop(void)
|
||||||
|
{
|
||||||
af_stream_stop(AUD_STREAM_ID_0,AUD_STREAM_PLAYBACK);
|
af_stream_stop(AUD_STREAM_ID_0,AUD_STREAM_PLAYBACK);
|
||||||
af_stream_close(AUD_STREAM_ID_0,AUD_STREAM_PLAYBACK);
|
af_stream_close(AUD_STREAM_ID_0,AUD_STREAM_PLAYBACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,34 +16,34 @@
|
||||||
/* rbplay source */
|
/* rbplay source */
|
||||||
/* playback control & rockbox codec porting & codec thread */
|
/* playback control & rockbox codec porting & codec thread */
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <string.h>
|
||||||
#include <fcntl.h>
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <stdio.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <ctype.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#ifdef MBED
|
#ifdef MBED
|
||||||
#include "mbed.h"
|
#include "mbed.h"
|
||||||
#include "rtos.h"
|
#include "rtos.h"
|
||||||
#endif
|
#endif
|
||||||
#include "app_overlay.h"
|
#include "metadata.h"
|
||||||
#include "apps.h"
|
|
||||||
#include "audioflinger.h"
|
|
||||||
#include "codecs.h"
|
#include "codecs.h"
|
||||||
#include "eq_export.h"
|
#include "eq_export.h"
|
||||||
#include "hal_overlay.h"
|
#include "hal_overlay.h"
|
||||||
|
#include "app_overlay.h"
|
||||||
|
#include "audioflinger.h"
|
||||||
#include "hal_trace.h"
|
#include "hal_trace.h"
|
||||||
#include "metadata.h"
|
#include "apps.h"
|
||||||
|
|
||||||
#include "app_key.h"
|
#include "rbpcmbuf.h"
|
||||||
|
#include "rbplaysd.h"
|
||||||
#include "app_thread.h"
|
#include "app_thread.h"
|
||||||
#include "app_utils.h"
|
#include "app_utils.h"
|
||||||
#include "rbpcmbuf.h"
|
#include "app_key.h"
|
||||||
#include "rbplay.h"
|
#include "rbplay.h"
|
||||||
#include "rbplaysd.h"
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
#ifdef __TWS__
|
#ifdef __TWS__
|
||||||
|
@ -66,9 +66,7 @@ void sbc_codec_main(int r);
|
||||||
void sbc_codec_run(void);
|
void sbc_codec_run(void);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void rb_pcm_player_open(enum AUD_BITS_T bits,
|
extern void rb_pcm_player_open(enum AUD_BITS_T bits,enum AUD_SAMPRATE_T sample_rate,enum AUD_CHANNEL_NUM_T channel_num,uint8_t vol) ;
|
||||||
enum AUD_SAMPRATE_T sample_rate,
|
|
||||||
enum AUD_CHANNEL_NUM_T channel_num, uint8_t vol);
|
|
||||||
|
|
||||||
#if defined(__TWS__)
|
#if defined(__TWS__)
|
||||||
typedef struct _rb_tws_codec_info{
|
typedef struct _rb_tws_codec_info{
|
||||||
|
@ -94,8 +92,7 @@ int rb_decode_mailbox_put(RBTHREAD_MSG_BLOCK *msg_src);
|
||||||
static osMailQId rb_decode_mailbox = NULL;
|
static osMailQId rb_decode_mailbox = NULL;
|
||||||
|
|
||||||
static void rb_decode_thread(void const *argument);
|
static void rb_decode_thread(void const *argument);
|
||||||
osThreadDef(rb_decode_thread, osPriorityAboveNormal, 1, 1024 * 2,
|
osThreadDef(rb_decode_thread, osPriorityAboveNormal, 1, 1024 * 2, "rb_decorder");
|
||||||
"rb_decorder");
|
|
||||||
|
|
||||||
// rbcodec info
|
// rbcodec info
|
||||||
static int song_fd;
|
static int song_fd;
|
||||||
|
@ -125,11 +122,15 @@ extern void rb_thread_send_status_change(void);
|
||||||
|
|
||||||
enum APP_SYSFREQ_FREQ_T rb_player_get_work_freq(void);
|
enum APP_SYSFREQ_FREQ_T rb_player_get_work_freq(void);
|
||||||
|
|
||||||
static void rb_player_sync_close_done(void) { thread_tid_waiter = NULL; }
|
static void rb_player_sync_close_done(void)
|
||||||
|
{
|
||||||
|
thread_tid_waiter = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
extern void rb_check_stream_reconfig(int32_t freq, uint8_t ch);
|
extern void rb_check_stream_reconfig(int32_t freq, uint8_t ch);
|
||||||
static void f_codec_pcmbuf_insert_callback(const void *ch1, const void *ch2,
|
static void f_codec_pcmbuf_insert_callback(
|
||||||
int count) {
|
const void *ch1, const void *ch2, int count)
|
||||||
|
{
|
||||||
struct dsp_buffer src;
|
struct dsp_buffer src;
|
||||||
struct dsp_buffer dst;
|
struct dsp_buffer dst;
|
||||||
|
|
||||||
|
@ -160,9 +161,7 @@ static void f_codec_pcmbuf_insert_callback(const void *ch1, const void *ch2,
|
||||||
#else
|
#else
|
||||||
|
|
||||||
if(codec_info.update_codec_info){
|
if(codec_info.update_codec_info){
|
||||||
rb_set_sbc_encoder_freq_ch(
|
rb_set_sbc_encoder_freq_ch(codec_info.sample_freq, codec_info.channel_num); //should call this to set trigger timer
|
||||||
codec_info.sample_freq,
|
|
||||||
codec_info.channel_num); // should call this to set trigger timer
|
|
||||||
rb_check_stream_reconfig(codec_info.sample_freq, codec_info.channel_num);
|
rb_check_stream_reconfig(codec_info.sample_freq, codec_info.channel_num);
|
||||||
codec_info.update_codec_info = 0;
|
codec_info.update_codec_info = 0;
|
||||||
}
|
}
|
||||||
|
@ -193,12 +192,14 @@ static void f_codec_pcmbuf_insert_callback(const void *ch1, const void *ch2,
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void f_audio_codec_update_elapsed(unsigned long elapsed) {
|
static void f_audio_codec_update_elapsed(unsigned long elapsed)
|
||||||
|
{
|
||||||
//info("Update elapsed: %d", elapsed);
|
//info("Update elapsed: %d", elapsed);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t f_codec_filebuf_callback(void *ptr, size_t size) {
|
static size_t f_codec_filebuf_callback(void *ptr, size_t size)
|
||||||
|
{
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
ret = read(song_fd, ptr, size);
|
ret = read(song_fd, ptr, size);
|
||||||
if(ret < 0) {
|
if(ret < 0) {
|
||||||
|
@ -206,13 +207,16 @@ static size_t f_codec_filebuf_callback(void *ptr, size_t size) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *f_codec_request_buffer_callback(size_t *realsize, size_t reqsize) {
|
static void * f_codec_request_buffer_callback(size_t *realsize, size_t reqsize)
|
||||||
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *f_codec_advance_buffer_callback(size_t amount) {
|
static void * f_codec_advance_buffer_callback(size_t amount)
|
||||||
|
{
|
||||||
off_t ret = lseek(song_fd, (off_t)(ci->curpos + amount), SEEK_SET);
|
off_t ret = lseek(song_fd, (off_t)(ci->curpos + amount), SEEK_SET);
|
||||||
if(ret < 0) {
|
if(ret < 0) {
|
||||||
error("File seek fail");
|
error("File seek fail");
|
||||||
|
@ -221,9 +225,11 @@ static void *f_codec_advance_buffer_callback(size_t amount) {
|
||||||
|
|
||||||
ci->curpos += amount;
|
ci->curpos += amount;
|
||||||
return (void *)ci;
|
return (void *)ci;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool f_codec_seek_buffer_callback(size_t newpos) {
|
static bool f_codec_seek_buffer_callback(size_t newpos)
|
||||||
|
{
|
||||||
off_t ret = lseek(song_fd, (off_t)newpos, SEEK_SET);
|
off_t ret = lseek(song_fd, (off_t)newpos, SEEK_SET);
|
||||||
if(ret < 0) {
|
if(ret < 0) {
|
||||||
error("File seek fail");
|
error("File seek fail");
|
||||||
|
@ -234,21 +240,26 @@ static bool f_codec_seek_buffer_callback(size_t newpos) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void f_codec_seek_complete_callback(void) {
|
static void f_codec_seek_complete_callback(void)
|
||||||
|
{
|
||||||
info("Seek complete");
|
info("Seek complete");
|
||||||
dsp_configure(ci->dsp, DSP_FLUSH, 0);
|
dsp_configure(ci->dsp, DSP_FLUSH, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void f_audio_codec_update_offset(size_t offset) {}
|
static void f_audio_codec_update_offset(size_t offset)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
static void f_codec_configure_callback(int setting, intptr_t value) {
|
static void f_codec_configure_callback(int setting, intptr_t value)
|
||||||
|
{
|
||||||
dsp_configure(ci->dsp, setting, value);
|
dsp_configure(ci->dsp, setting, value);
|
||||||
#ifdef __TWS__
|
#ifdef __TWS__
|
||||||
if(setting == DSP_SET_FREQUENCY){
|
if(setting == DSP_SET_FREQUENCY){
|
||||||
if(codec_info.sample_freq != value)
|
if(codec_info.sample_freq != value)
|
||||||
codec_info.update_codec_info = 1;
|
codec_info.update_codec_info = 1;
|
||||||
codec_info.sample_freq = value;
|
codec_info.sample_freq = value;
|
||||||
} else if (setting == DSP_SET_STEREO_MODE) {
|
}
|
||||||
|
else if(setting == DSP_SET_STEREO_MODE){
|
||||||
if(codec_info.channel_num != (value == STEREO_MONO ? 1 : 2))
|
if(codec_info.channel_num != (value == STEREO_MONO ? 1 : 2))
|
||||||
codec_info.update_codec_info = 1;
|
codec_info.update_codec_info = 1;
|
||||||
codec_info.channel_num = value == STEREO_MONO ? 1 : 2;
|
codec_info.channel_num = value == STEREO_MONO ? 1 : 2;
|
||||||
|
@ -256,16 +267,21 @@ static void f_codec_configure_callback(int setting, intptr_t value) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum codec_command_action f_codec_get_command_callback(intptr_t *param) {
|
static enum codec_command_action f_codec_get_command_callback(intptr_t *param)
|
||||||
|
{
|
||||||
if (rb_decode_halt_flag == 1)
|
if (rb_decode_halt_flag == 1)
|
||||||
return CODEC_ACTION_HALT ;
|
return CODEC_ACTION_HALT ;
|
||||||
|
|
||||||
return CODEC_ACTION_NULL;
|
return CODEC_ACTION_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool f_codec_loop_track_callback(void) { return false; }
|
static bool f_codec_loop_track_callback(void)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static void init_ci_file(void) {
|
static void init_ci_file(void)
|
||||||
|
{
|
||||||
ci->codec_get_buffer = 0;
|
ci->codec_get_buffer = 0;
|
||||||
ci->pcmbuf_insert = f_codec_pcmbuf_insert_callback;
|
ci->pcmbuf_insert = f_codec_pcmbuf_insert_callback;
|
||||||
ci->set_elapsed = f_audio_codec_update_elapsed;
|
ci->set_elapsed = f_audio_codec_update_elapsed;
|
||||||
|
@ -280,7 +296,8 @@ static void init_ci_file(void) {
|
||||||
ci->loop_track = f_codec_loop_track_callback;
|
ci->loop_track = f_codec_loop_track_callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rb_play_init(void) {
|
static void rb_play_init(void)
|
||||||
|
{
|
||||||
init_dsp();
|
init_dsp();
|
||||||
|
|
||||||
init_ci_file();
|
init_ci_file();
|
||||||
|
@ -290,21 +307,24 @@ static void rb_play_init(void) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void rb_play_codec_init(void) {
|
void rb_play_codec_init(void)
|
||||||
|
{
|
||||||
RBTHREAD_MSG_BLOCK msg;
|
RBTHREAD_MSG_BLOCK msg;
|
||||||
msg.evt = (uint32_t)RB_CTRL_CMD_CODEC_INIT;
|
msg.evt = (uint32_t)RB_CTRL_CMD_CODEC_INIT;
|
||||||
msg.arg = (uint32_t)0;
|
msg.arg = (uint32_t)0;
|
||||||
rb_decode_mailbox_put(&msg);
|
rb_decode_mailbox_put(&msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rb_play_codec_run(void) {
|
void rb_play_codec_run(void)
|
||||||
|
{
|
||||||
RBTHREAD_MSG_BLOCK msg;
|
RBTHREAD_MSG_BLOCK msg;
|
||||||
msg.evt = (uint32_t)RB_CTRL_CMD_CODEC_RUN;
|
msg.evt = (uint32_t)RB_CTRL_CMD_CODEC_RUN;
|
||||||
msg.arg = (uint32_t)0;
|
msg.arg = (uint32_t)0;
|
||||||
rb_decode_mailbox_put(&msg);
|
rb_decode_mailbox_put(&msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int rb_codec_init_desc(void) {
|
static int rb_codec_init_desc(void )
|
||||||
|
{
|
||||||
info("Init decode format: %d", song_format);
|
info("Init decode format: %d", song_format);
|
||||||
|
|
||||||
switch (song_format) {
|
switch (song_format) {
|
||||||
|
@ -341,7 +361,8 @@ static int rb_codec_init_desc(void) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int rb_codec_loop_on(void) {
|
static int rb_codec_loop_on(void)
|
||||||
|
{
|
||||||
#ifdef __TWS__
|
#ifdef __TWS__
|
||||||
//set start transfer to slave
|
//set start transfer to slave
|
||||||
tws_local_player_set_tran_2_slave_flag(1);
|
tws_local_player_set_tran_2_slave_flag(1);
|
||||||
|
@ -373,7 +394,8 @@ static int rb_codec_loop_on(void) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int rb_thread_process_evt(RB_CTRL_CMD_T evt) {
|
static int rb_thread_process_evt(RB_CTRL_CMD_T evt)
|
||||||
|
{
|
||||||
info("Decode event:%d", evt);
|
info("Decode event:%d", evt);
|
||||||
|
|
||||||
switch(evt) {
|
switch(evt) {
|
||||||
|
@ -426,7 +448,8 @@ static int rb_thread_process_evt(RB_CTRL_CMD_T evt) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rb_decode_mailbox_put(RBTHREAD_MSG_BLOCK *msg_src) {
|
int rb_decode_mailbox_put(RBTHREAD_MSG_BLOCK* msg_src)
|
||||||
|
{
|
||||||
osStatus status;
|
osStatus status;
|
||||||
|
|
||||||
RBTHREAD_MSG_BLOCK *msg_p = NULL;
|
RBTHREAD_MSG_BLOCK *msg_p = NULL;
|
||||||
|
@ -445,7 +468,8 @@ int rb_decode_mailbox_put(RBTHREAD_MSG_BLOCK *msg_src) {
|
||||||
return (int)status;
|
return (int)status;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rb_decode_mailbox_free(RBTHREAD_MSG_BLOCK *msg_p) {
|
int rb_decode_mailbox_free(RBTHREAD_MSG_BLOCK* msg_p)
|
||||||
|
{
|
||||||
osStatus status;
|
osStatus status;
|
||||||
|
|
||||||
status = osMailFree(rb_decode_mailbox, msg_p);
|
status = osMailFree(rb_decode_mailbox, msg_p);
|
||||||
|
@ -453,7 +477,8 @@ int rb_decode_mailbox_free(RBTHREAD_MSG_BLOCK *msg_p) {
|
||||||
return (int)status;
|
return (int)status;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rb_decode_mailbox_get(RBTHREAD_MSG_BLOCK **msg_p) {
|
int rb_decode_mailbox_get(RBTHREAD_MSG_BLOCK** msg_p)
|
||||||
|
{
|
||||||
osEvent evt;
|
osEvent evt;
|
||||||
evt = osMailGet(rb_decode_mailbox, osWaitForever);
|
evt = osMailGet(rb_decode_mailbox, osWaitForever);
|
||||||
if (evt.status == osEventMail) {
|
if (evt.status == osEventMail) {
|
||||||
|
@ -463,7 +488,8 @@ int rb_decode_mailbox_get(RBTHREAD_MSG_BLOCK **msg_p) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rb_decode_thread(void const *argument) {
|
static void rb_decode_thread(void const *argument)
|
||||||
|
{
|
||||||
RB_CTRL_CMD_T action;
|
RB_CTRL_CMD_T action;
|
||||||
RBTHREAD_MSG_BLOCK* msg_p;
|
RBTHREAD_MSG_BLOCK* msg_p;
|
||||||
|
|
||||||
|
@ -484,10 +510,12 @@ static void rb_decode_thread(void const *argument) {
|
||||||
osSignalSet(rb_decode_tid, 0x1203);
|
osSignalSet(rb_decode_tid, 0x1203);
|
||||||
rb_caller_tid = NULL;
|
rb_caller_tid = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_rbplay_open(void) {
|
int app_rbplay_open(void)
|
||||||
|
{
|
||||||
if (rb_decode_tid != NULL) {
|
if (rb_decode_tid != NULL) {
|
||||||
warn("Decode thread reopen");
|
warn("Decode thread reopen");
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -508,30 +536,40 @@ int app_rbplay_open(void) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rb_codec_running(void) { return ((rb_decode_halt_flag == 0) ? 1 : 0); }
|
int rb_codec_running(void)
|
||||||
|
{
|
||||||
|
return ((rb_decode_halt_flag == 0)?1:0);
|
||||||
|
}
|
||||||
|
|
||||||
void rb_codec_set_halt(int halt) { rb_decode_halt_flag = halt; }
|
void rb_codec_set_halt(int halt)
|
||||||
|
{
|
||||||
|
rb_decode_halt_flag = halt;
|
||||||
|
}
|
||||||
|
|
||||||
void rb_thread_set_decode_vars(int fd, int type, void *id3) {
|
void rb_thread_set_decode_vars(int fd, int type ,void* id3)
|
||||||
|
{
|
||||||
song_fd =fd;
|
song_fd =fd;
|
||||||
song_format = type;
|
song_format = type;
|
||||||
current_id3 = (struct mp3entry *)id3;
|
current_id3 = (struct mp3entry *)id3;
|
||||||
}
|
}
|
||||||
|
|
||||||
void rb_player_sync_set_wait_thread(osThreadId tid) {
|
void rb_player_sync_set_wait_thread(osThreadId tid)
|
||||||
|
{
|
||||||
if(rbplay_loop_on)
|
if(rbplay_loop_on)
|
||||||
thread_tid_waiter = tid;
|
thread_tid_waiter = tid;
|
||||||
else
|
else
|
||||||
thread_tid_waiter = NULL;
|
thread_tid_waiter = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void rb_player_sync_wait_close(void) {
|
void rb_player_sync_wait_close(void )
|
||||||
|
{
|
||||||
while(NULL != thread_tid_waiter) {
|
while(NULL != thread_tid_waiter) {
|
||||||
osThreadYield();
|
osThreadYield();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum APP_SYSFREQ_FREQ_T rb_player_get_work_freq(void) {
|
enum APP_SYSFREQ_FREQ_T rb_player_get_work_freq(void)
|
||||||
|
{
|
||||||
enum APP_SYSFREQ_FREQ_T freq;
|
enum APP_SYSFREQ_FREQ_T freq;
|
||||||
|
|
||||||
hal_sysfreq_print();
|
hal_sysfreq_print();
|
||||||
|
@ -573,3 +611,5 @@ enum APP_SYSFREQ_FREQ_T rb_player_get_work_freq(void) {
|
||||||
info("Decode thread run at: %d", freq);
|
info("Decode thread run at: %d", freq);
|
||||||
return freq;
|
return freq;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -16,18 +16,18 @@
|
||||||
/* rbplay source */
|
/* rbplay source */
|
||||||
/* playback control & rockbox codec porting & codec thread */
|
/* playback control & rockbox codec porting & codec thread */
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <string.h>
|
||||||
#include <fcntl.h>
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <stdio.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <ctype.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "SDFileSystem.h"
|
|
||||||
#include "hal_trace.h"
|
#include "hal_trace.h"
|
||||||
#include "metadata.h"
|
#include "metadata.h"
|
||||||
|
#include "SDFileSystem.h"
|
||||||
#include "rbplaysd.h"
|
#include "rbplaysd.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
|
@ -41,7 +41,8 @@ static playlist_item sd_curritem;
|
||||||
|
|
||||||
playlist_struct sd_playlist;
|
playlist_struct sd_playlist;
|
||||||
|
|
||||||
static void playlist_insert(playlist_item *item) {
|
static void playlist_insert(playlist_item* item)
|
||||||
|
{
|
||||||
int fd;
|
int fd;
|
||||||
fd = open(PLAYLIST_PATH, O_RDWR | O_CREAT);
|
fd = open(PLAYLIST_PATH, O_RDWR | O_CREAT);
|
||||||
if (fd <= 0) {
|
if (fd <= 0) {
|
||||||
|
@ -54,7 +55,8 @@ static void playlist_insert(playlist_item *item) {
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool sdcard_mount(void) {
|
static bool sdcard_mount(void)
|
||||||
|
{
|
||||||
if (sdfs) {
|
if (sdfs) {
|
||||||
info("SD card already mount");
|
info("SD card already mount");
|
||||||
return true;
|
return true;
|
||||||
|
@ -78,7 +80,8 @@ static bool sdcard_mount(void) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void app_rbplay_gen_playlist(playlist_struct *list) {
|
static void app_rbplay_gen_playlist(playlist_struct *list)
|
||||||
|
{
|
||||||
struct dirent *p;
|
struct dirent *p;
|
||||||
DIR *d;
|
DIR *d;
|
||||||
uint32_t total;
|
uint32_t total;
|
||||||
|
@ -119,8 +122,7 @@ static void app_rbplay_gen_playlist(playlist_struct *list) {
|
||||||
get_metadata(¤t_id3, fd, sd_curritem.file_path);
|
get_metadata(¤t_id3, fd, sd_curritem.file_path);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
if (current_id3.bitrate == 0 || current_id3.filesize == 0 ||
|
if(current_id3.bitrate == 0 || current_id3.filesize == 0 || current_id3.length == 0)
|
||||||
current_id3.length == 0)
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
info("bits:%d, type:%d, freq:%d", current_id3.bitrate,
|
info("bits:%d, type:%d, freq:%d", current_id3.bitrate,
|
||||||
|
@ -137,36 +139,31 @@ static void app_rbplay_gen_playlist(playlist_struct *list) {
|
||||||
str = current_id3.title;
|
str = current_id3.title;
|
||||||
if(str != NULL) {
|
if(str != NULL) {
|
||||||
memset(sd_curritem_p->title,0x0,MP3_TITLE_LEN);
|
memset(sd_curritem_p->title,0x0,MP3_TITLE_LEN);
|
||||||
memcpy(sd_curritem_p->title, str,
|
memcpy(sd_curritem_p->title ,str,strlen(str)>MP3_TITLE_LEN?MP3_TITLE_LEN:strlen(str));
|
||||||
strlen(str) > MP3_TITLE_LEN ? MP3_TITLE_LEN : strlen(str));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
str = current_id3.artist;
|
str = current_id3.artist;
|
||||||
if(str != NULL) {
|
if(str != NULL) {
|
||||||
memset(sd_curritem_p->artist,0x0,MP3_ARTIST_LEN);
|
memset(sd_curritem_p->artist,0x0,MP3_ARTIST_LEN);
|
||||||
memcpy(sd_curritem_p->artist, str,
|
memcpy(sd_curritem_p->artist ,str,strlen(str)>MP3_ARTIST_LEN?MP3_ARTIST_LEN:strlen(str));
|
||||||
strlen(str) > MP3_ARTIST_LEN ? MP3_ARTIST_LEN : strlen(str));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
str = current_id3.album;
|
str = current_id3.album;
|
||||||
if(str != NULL) {
|
if(str != NULL) {
|
||||||
memset(sd_curritem_p->album,0x0,MP3_ALBUM_LEN);
|
memset(sd_curritem_p->album,0x0,MP3_ALBUM_LEN);
|
||||||
memcpy(sd_curritem_p->album, str,
|
memcpy(sd_curritem_p->album ,str,strlen(str)>MP3_ALBUM_LEN?MP3_ALBUM_LEN:strlen(str));
|
||||||
strlen(str) > MP3_ALBUM_LEN ? MP3_ALBUM_LEN : strlen(str));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
str = current_id3.genre_string;
|
str = current_id3.genre_string;
|
||||||
if(str != NULL) {
|
if(str != NULL) {
|
||||||
memset(sd_curritem_p->genre,0x0,MP3_GENRE_LEN);
|
memset(sd_curritem_p->genre,0x0,MP3_GENRE_LEN);
|
||||||
memcpy(sd_curritem_p->genre, str,
|
memcpy(sd_curritem_p->genre ,str,strlen(str)>MP3_GENRE_LEN?MP3_GENRE_LEN:strlen(str));
|
||||||
strlen(str) > MP3_GENRE_LEN ? MP3_GENRE_LEN : strlen(str));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
str = current_id3.composer;
|
str = current_id3.composer;
|
||||||
if(str != NULL) {
|
if(str != NULL) {
|
||||||
memset(sd_curritem_p->composer,0x0,MP3_COMPOSER_LEN);
|
memset(sd_curritem_p->composer,0x0,MP3_COMPOSER_LEN);
|
||||||
memcpy(sd_curritem_p->composer, str,
|
memcpy(sd_curritem_p->composer ,str,strlen(str)>MP3_COMPOSER_LEN?MP3_COMPOSER_LEN:strlen(str));
|
||||||
strlen(str) > MP3_COMPOSER_LEN ? MP3_COMPOSER_LEN : strlen(str));
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
playlist_insert(sd_curritem_p);
|
playlist_insert(sd_curritem_p);
|
||||||
|
@ -178,9 +175,11 @@ static void app_rbplay_gen_playlist(playlist_struct *list) {
|
||||||
|
|
||||||
closedir(d);
|
closedir(d);
|
||||||
info("---------%d audio file searched---------" , total);
|
info("---------%d audio file searched---------" , total);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void app_rbplay_load_playlist(playlist_struct *list) {
|
void app_rbplay_load_playlist(playlist_struct *list)
|
||||||
|
{
|
||||||
if(sdcard_mount() == false)
|
if(sdcard_mount() == false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -189,7 +188,8 @@ void app_rbplay_load_playlist(playlist_struct *list) {
|
||||||
app_rbplay_gen_playlist(list);
|
app_rbplay_gen_playlist(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
playlist_item *app_rbplay_get_playitem(const int idx) {
|
playlist_item *app_rbplay_get_playitem(const int idx)
|
||||||
|
{
|
||||||
int fd;
|
int fd;
|
||||||
if(idx >= sd_playlist.total_songs) {
|
if(idx >= sd_playlist.total_songs) {
|
||||||
warn("Index exceed: %d / %d", idx, sd_playlist.total_songs);
|
warn("Index exceed: %d / %d", idx, sd_playlist.total_songs);
|
||||||
|
@ -212,7 +212,8 @@ playlist_item *app_rbplay_get_playitem(const int idx) {
|
||||||
return sd_playlist.current_item;
|
return sd_playlist.current_item;
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_ctl_remove_file(const int idx) {
|
int app_ctl_remove_file(const int idx)
|
||||||
|
{
|
||||||
playlist_item *item = app_rbplay_get_playitem(idx);
|
playlist_item *item = app_rbplay_get_playitem(idx);
|
||||||
if (!item)
|
if (!item)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -220,3 +221,5 @@ int app_ctl_remove_file(const int idx) {
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -13,13 +13,13 @@
|
||||||
* trademark and other intellectual property rights.
|
* trademark and other intellectual property rights.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include "app_utils.h"
|
|
||||||
#include "audio_dump.h"
|
|
||||||
#include "audioflinger.h"
|
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
|
#include "app_utils.h"
|
||||||
|
#include "audioflinger.h"
|
||||||
#include "hal_timer.h"
|
#include "hal_timer.h"
|
||||||
#include "hal_trace.h"
|
#include "hal_trace.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
#include "audio_dump.h"
|
||||||
// #include "local_wav.h"
|
// #include "local_wav.h"
|
||||||
|
|
||||||
#define CHANNEL_NUM (2)
|
#define CHANNEL_NUM (2)
|
||||||
|
@ -31,9 +31,11 @@
|
||||||
#define SAMPLE_BITS (16)
|
#define SAMPLE_BITS (16)
|
||||||
#define SAMPLE_BYTES (SAMPLE_BITS / 8)
|
#define SAMPLE_BYTES (SAMPLE_BITS / 8)
|
||||||
|
|
||||||
|
|
||||||
#define TX_SAMPLE_RATE (16000)
|
#define TX_SAMPLE_RATE (16000)
|
||||||
#define RX_SAMPLE_RATE (16000)
|
#define RX_SAMPLE_RATE (16000)
|
||||||
|
|
||||||
|
|
||||||
#define TX_FRAME_LEN (256)
|
#define TX_FRAME_LEN (256)
|
||||||
#define RX_FRAME_LEN (256)
|
#define RX_FRAME_LEN (256)
|
||||||
|
|
||||||
|
@ -56,7 +58,8 @@ static uint32_t POSSIBLY_UNUSED codec_playback_cnt = 0;
|
||||||
|
|
||||||
#define CODEC_STREAM_ID AUD_STREAM_ID_0
|
#define CODEC_STREAM_ID AUD_STREAM_ID_0
|
||||||
|
|
||||||
static uint32_t codec_capture_callback(uint8_t *buf, uint32_t len) {
|
static uint32_t codec_capture_callback(uint8_t *buf, uint32_t len)
|
||||||
|
{
|
||||||
int POSSIBLY_UNUSED pcm_len = len / sizeof(VOICE_PCM_T) / CHANNEL_NUM;
|
int POSSIBLY_UNUSED pcm_len = len / sizeof(VOICE_PCM_T) / CHANNEL_NUM;
|
||||||
VOICE_PCM_T POSSIBLY_UNUSED *pcm_buf[CHANNEL_NUM];
|
VOICE_PCM_T POSSIBLY_UNUSED *pcm_buf[CHANNEL_NUM];
|
||||||
int interval_len = len * 2 / CHANNEL_NUM;
|
int interval_len = len * 2 / CHANNEL_NUM;
|
||||||
|
@ -74,7 +77,8 @@ static uint32_t codec_capture_callback(uint8_t *buf, uint32_t len) {
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t codec_playback_callback(uint8_t *buf, uint32_t len) {
|
static uint32_t codec_playback_callback(uint8_t *buf, uint32_t len)
|
||||||
|
{
|
||||||
int POSSIBLY_UNUSED pcm_len = len / sizeof(VOICE_PCM_T) / CHANNEL_NUM;
|
int POSSIBLY_UNUSED pcm_len = len / sizeof(VOICE_PCM_T) / CHANNEL_NUM;
|
||||||
VOICE_PCM_T POSSIBLY_UNUSED *pcm_buf[CHANNEL_NUM];
|
VOICE_PCM_T POSSIBLY_UNUSED *pcm_buf[CHANNEL_NUM];
|
||||||
int interval_len = len * 2 / CHANNEL_NUM;
|
int interval_len = len * 2 / CHANNEL_NUM;
|
||||||
|
@ -88,7 +92,8 @@ static uint32_t codec_playback_callback(uint8_t *buf, uint32_t len) {
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int voice_start(bool on) {
|
static int voice_start(bool on)
|
||||||
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
static bool isRun = false;
|
static bool isRun = false;
|
||||||
enum APP_SYSFREQ_FREQ_T freq = APP_SYSFREQ_208M;
|
enum APP_SYSFREQ_FREQ_T freq = APP_SYSFREQ_208M;
|
||||||
|
@ -104,8 +109,7 @@ static int voice_start(bool on) {
|
||||||
af_set_priority(AF_USER_TEST, osPriorityHigh);
|
af_set_priority(AF_USER_TEST, osPriorityHigh);
|
||||||
|
|
||||||
app_sysfreq_req(APP_SYSFREQ_USER_APP_0, freq);
|
app_sysfreq_req(APP_SYSFREQ_USER_APP_0, freq);
|
||||||
TRACE(2, "[%s] sys freq calc : %d\n", __func__,
|
TRACE(2, "[%s] sys freq calc : %d\n", __func__, hal_sys_timer_calc_cpu_freq(5, 0));
|
||||||
hal_sys_timer_calc_cpu_freq(5, 0));
|
|
||||||
|
|
||||||
// Initialize Cqueue
|
// Initialize Cqueue
|
||||||
codec_capture_cnt = 0;
|
codec_capture_cnt = 0;
|
||||||
|
@ -123,8 +127,7 @@ static int voice_start(bool on) {
|
||||||
stream_cfg.handler = codec_capture_callback;
|
stream_cfg.handler = codec_capture_callback;
|
||||||
stream_cfg.data_ptr = codec_capture_buf;
|
stream_cfg.data_ptr = codec_capture_buf;
|
||||||
|
|
||||||
TRACE(3, "[%s] codec capture sample_rate: %d, data_size: %d", __func__,
|
TRACE(3, "[%s] codec capture sample_rate: %d, data_size: %d", __func__, stream_cfg.sample_rate, stream_cfg.data_size);
|
||||||
stream_cfg.sample_rate, stream_cfg.data_size);
|
|
||||||
af_stream_open(CODEC_STREAM_ID, AUD_STREAM_CAPTURE, &stream_cfg);
|
af_stream_open(CODEC_STREAM_ID, AUD_STREAM_CAPTURE, &stream_cfg);
|
||||||
ASSERT(ret == 0, "codec capture failed: %d", ret);
|
ASSERT(ret == 0, "codec capture failed: %d", ret);
|
||||||
|
|
||||||
|
@ -140,8 +143,7 @@ static int voice_start(bool on) {
|
||||||
stream_cfg.handler = codec_playback_callback;
|
stream_cfg.handler = codec_playback_callback;
|
||||||
stream_cfg.data_ptr = codec_playback_buf;
|
stream_cfg.data_ptr = codec_playback_buf;
|
||||||
|
|
||||||
TRACE(3, "[%s] codec playback sample_rate: %d, data_size: %d", __func__,
|
TRACE(3, "[%s] codec playback sample_rate: %d, data_size: %d", __func__, stream_cfg.sample_rate, stream_cfg.data_size);
|
||||||
stream_cfg.sample_rate, stream_cfg.data_size);
|
|
||||||
af_stream_open(CODEC_STREAM_ID, AUD_STREAM_PLAYBACK, &stream_cfg);
|
af_stream_open(CODEC_STREAM_ID, AUD_STREAM_PLAYBACK, &stream_cfg);
|
||||||
ASSERT(ret == 0, "codec playback failed: %d", ret);
|
ASSERT(ret == 0, "codec playback failed: %d", ret);
|
||||||
|
|
||||||
|
@ -150,7 +152,9 @@ static int voice_start(bool on) {
|
||||||
// Start
|
// Start
|
||||||
af_stream_start(CODEC_STREAM_ID, AUD_STREAM_CAPTURE);
|
af_stream_start(CODEC_STREAM_ID, AUD_STREAM_CAPTURE);
|
||||||
af_stream_start(CODEC_STREAM_ID, AUD_STREAM_PLAYBACK);
|
af_stream_start(CODEC_STREAM_ID, AUD_STREAM_PLAYBACK);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
// Close stream
|
// Close stream
|
||||||
af_stream_stop(CODEC_STREAM_ID, AUD_STREAM_PLAYBACK);
|
af_stream_stop(CODEC_STREAM_ID, AUD_STREAM_PLAYBACK);
|
||||||
af_stream_stop(CODEC_STREAM_ID, AUD_STREAM_CAPTURE);
|
af_stream_stop(CODEC_STREAM_ID, AUD_STREAM_CAPTURE);
|
||||||
|
@ -172,7 +176,8 @@ static int voice_start(bool on) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool voice_test_status = true;
|
static bool voice_test_status = true;
|
||||||
void voice_test(void) {
|
void voice_test(void)
|
||||||
|
{
|
||||||
TRACE(2, "[%s] status = %d", __func__, voice_test_status);
|
TRACE(2, "[%s] status = %d", __func__, voice_test_status);
|
||||||
|
|
||||||
voice_start(voice_test_status);
|
voice_start(voice_test_status);
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -14,25 +14,25 @@
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
// Standard C Included Files
|
// Standard C Included Files
|
||||||
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "cmsis_os.h"
|
||||||
|
#include "plat_types.h"
|
||||||
|
#include "hal_uart.h"
|
||||||
|
#include "hal_timer.h"
|
||||||
|
#include "hal_trace.h"
|
||||||
|
#include "cqueue.h"
|
||||||
#include "app_audio.h"
|
#include "app_audio.h"
|
||||||
#include "app_overlay.h"
|
#include "app_overlay.h"
|
||||||
#include "app_ring_merge.h"
|
#include "app_ring_merge.h"
|
||||||
#include "audio_prompt_sbc.h"
|
|
||||||
#include "bt_sco_chain.h"
|
|
||||||
#include "cmsis_os.h"
|
|
||||||
#include "cqueue.h"
|
|
||||||
#include "hal_timer.h"
|
|
||||||
#include "hal_trace.h"
|
|
||||||
#include "hal_uart.h"
|
|
||||||
#include "hfp_api.h"
|
|
||||||
#include "iir_resample.h"
|
|
||||||
#include "plat_types.h"
|
|
||||||
#include "tgt_hardware.h"
|
#include "tgt_hardware.h"
|
||||||
#include <math.h>
|
#include "bt_sco_chain.h"
|
||||||
#include <stdbool.h>
|
#include "iir_resample.h"
|
||||||
#include <stdio.h>
|
#include "hfp_api.h"
|
||||||
#include <stdlib.h>
|
#include "audio_prompt_sbc.h"
|
||||||
#include <string.h>
|
|
||||||
#ifdef TX_RX_PCM_MASK
|
#ifdef TX_RX_PCM_MASK
|
||||||
#include "bt_drv_interface.h"
|
#include "bt_drv_interface.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -101,8 +101,7 @@ static IirResampleState *downlink_resample_st = NULL;
|
||||||
|
|
||||||
#if defined(HFP_1_6_ENABLE)
|
#if defined(HFP_1_6_ENABLE)
|
||||||
static btif_sbc_decoder_t *msbc_decoder;
|
static btif_sbc_decoder_t *msbc_decoder;
|
||||||
static float msbc_eq_band_gain[CFG_HW_AUD_EQ_NUM_BANDS] = {0, 0, 0, 0,
|
static float msbc_eq_band_gain[CFG_HW_AUD_EQ_NUM_BANDS]= {0,0,0,0,0,0,0,0};
|
||||||
0, 0, 0, 0};
|
|
||||||
|
|
||||||
#define MSBC_ENCODE_PCM_LEN (240)
|
#define MSBC_ENCODE_PCM_LEN (240)
|
||||||
|
|
||||||
|
@ -126,9 +125,7 @@ LpcPlcState *msbc_plc_state = NULL;
|
||||||
#define VOICEBTPCM_TRACE(s,...)
|
#define VOICEBTPCM_TRACE(s,...)
|
||||||
//TRACE(s, ##__VA_ARGS__)
|
//TRACE(s, ##__VA_ARGS__)
|
||||||
|
|
||||||
#if defined(CHIP_BEST1400) || defined(CHIP_BEST1402) || \
|
#if defined(CHIP_BEST1400) || defined(CHIP_BEST1402) || defined(CHIP_BEST2300P) || defined(CHIP_BEST2300A) || defined(CHIP_BEST2001)
|
||||||
defined(CHIP_BEST2300P) || defined(CHIP_BEST2300A) || \
|
|
||||||
defined(CHIP_BEST2001)
|
|
||||||
#define MSBC_MUTE_PATTERN (0x55)
|
#define MSBC_MUTE_PATTERN (0x55)
|
||||||
#else
|
#else
|
||||||
#define MSBC_MUTE_PATTERN (0x00)
|
#define MSBC_MUTE_PATTERN (0x00)
|
||||||
|
@ -149,18 +146,14 @@ static PacketLossState pld;
|
||||||
|
|
||||||
extern bool bt_sco_codec_is_msbc(void);
|
extern bool bt_sco_codec_is_msbc(void);
|
||||||
|
|
||||||
int process_downlink_msbc_frames(unsigned char *msbc_buf, unsigned int msbc_len,
|
int process_downlink_msbc_frames(unsigned char *msbc_buf, unsigned int msbc_len, unsigned char *pcm_buf,unsigned int pcm_len);
|
||||||
unsigned char *pcm_buf, unsigned int pcm_len);
|
int process_downlink_cvsd_frames(unsigned char *cvsd_buf, unsigned int cvsd_len, unsigned char *pcm_buf,unsigned int pcm_len);
|
||||||
int process_downlink_cvsd_frames(unsigned char *cvsd_buf, unsigned int cvsd_len,
|
int process_uplink_msbc_frames(unsigned char *pcm_buf, unsigned int pcm_len, unsigned char *msbc_buf,unsigned int msbc_len);
|
||||||
unsigned char *pcm_buf, unsigned int pcm_len);
|
int process_uplink_cvsd_frames(unsigned char *pcm_buf, unsigned int pcm_len, unsigned char *cvsd_buf,unsigned int cvsd_len);
|
||||||
int process_uplink_msbc_frames(unsigned char *pcm_buf, unsigned int pcm_len,
|
|
||||||
unsigned char *msbc_buf, unsigned int msbc_len);
|
|
||||||
int process_uplink_cvsd_frames(unsigned char *pcm_buf, unsigned int pcm_len,
|
|
||||||
unsigned char *cvsd_buf, unsigned int cvsd_len);
|
|
||||||
|
|
||||||
int process_downlink_bt_voice_frames(uint8_t *in_buf, uint32_t in_len,
|
|
||||||
uint8_t *out_buf, uint32_t out_len,
|
int process_downlink_bt_voice_frames(uint8_t *in_buf, uint32_t in_len, uint8_t *out_buf,uint32_t out_len,int32_t codec_type)
|
||||||
int32_t codec_type) {
|
{
|
||||||
//TRACE(3,"[%s] in_len = %d, out_len = %d", __FUNCTION__, in_len, out_len);
|
//TRACE(3,"[%s] in_len = %d, out_len = %d", __FUNCTION__, in_len, out_len);
|
||||||
|
|
||||||
#if defined(SPEECH_RX_24BIT)
|
#if defined(SPEECH_RX_24BIT)
|
||||||
|
@ -176,24 +169,20 @@ int process_downlink_bt_voice_frames(uint8_t *in_buf, uint32_t in_len,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bt_sco_codec_is_msbc()) {
|
if (bt_sco_codec_is_msbc()) {
|
||||||
process_downlink_msbc_frames(in_buf, in_len, (uint8_t *)pcm_buf,
|
process_downlink_msbc_frames(in_buf, in_len, (uint8_t *)pcm_buf, pcm_len * sizeof(int16_t));
|
||||||
pcm_len * sizeof(int16_t));
|
|
||||||
|
|
||||||
// Down sampling
|
// Down sampling
|
||||||
if (resample_needed_flag) {
|
if (resample_needed_flag) {
|
||||||
iir_resample_process(downlink_resample_st, pcm_buf, (int16_t *)out_buf,
|
iir_resample_process(downlink_resample_st, pcm_buf, (int16_t *)out_buf, pcm_len);
|
||||||
pcm_len);
|
|
||||||
pcm_buf = (int16_t *)out_buf;
|
pcm_buf = (int16_t *)out_buf;
|
||||||
pcm_len >>= 1;
|
pcm_len >>= 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
process_downlink_cvsd_frames(in_buf, in_len, (uint8_t *)pcm_buf,
|
process_downlink_cvsd_frames(in_buf, in_len, (uint8_t *)pcm_buf, pcm_len * sizeof(int16_t));
|
||||||
pcm_len * sizeof(int16_t));
|
|
||||||
|
|
||||||
// Up sampling
|
// Up sampling
|
||||||
if (resample_needed_flag) {
|
if (resample_needed_flag) {
|
||||||
iir_resample_process(downlink_resample_st, pcm_buf, (int16_t *)out_buf,
|
iir_resample_process(downlink_resample_st, pcm_buf, (int16_t *)out_buf, pcm_len);
|
||||||
pcm_len);
|
|
||||||
pcm_buf = (int16_t *)out_buf;
|
pcm_buf = (int16_t *)out_buf;
|
||||||
pcm_len <<= 1;
|
pcm_len <<= 1;
|
||||||
}
|
}
|
||||||
|
@ -215,10 +204,8 @@ int process_downlink_bt_voice_frames(uint8_t *in_buf, uint32_t in_len,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int process_uplink_bt_voice_frames(uint8_t *in_buf, uint32_t in_len,
|
int process_uplink_bt_voice_frames(uint8_t *in_buf, uint32_t in_len, uint8_t *ref_buf, uint32_t ref_len, uint8_t *out_buf,uint32_t out_len,int32_t codec_type)
|
||||||
uint8_t *ref_buf, uint32_t ref_len,
|
{
|
||||||
uint8_t *out_buf, uint32_t out_len,
|
|
||||||
int32_t codec_type) {
|
|
||||||
//TRACE(3,"[%s] in_len = %d, out_len = %d", __FUNCTION__, in_len, out_len);
|
//TRACE(3,"[%s] in_len = %d, out_len = %d", __FUNCTION__, in_len, out_len);
|
||||||
|
|
||||||
#if defined(SPEECH_TX_24BIT)
|
#if defined(SPEECH_TX_24BIT)
|
||||||
|
@ -230,32 +217,21 @@ int process_uplink_bt_voice_frames(uint8_t *in_buf, uint32_t in_len,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SPEECH_TX_AEC_CODEC_REF)
|
#if defined(SPEECH_TX_AEC_CODEC_REF)
|
||||||
ASSERT(pcm_len % (SPEECH_CODEC_CAPTURE_CHANNEL_NUM + 1) == 0,
|
ASSERT(pcm_len % (SPEECH_CODEC_CAPTURE_CHANNEL_NUM + 1) == 0, "[%s] pcm_len(%d) should be divided by %d", __FUNCTION__, pcm_len, SPEECH_CODEC_CAPTURE_CHANNEL_NUM + 1);
|
||||||
"[%s] pcm_len(%d) should be divided by %d", __FUNCTION__, pcm_len,
|
|
||||||
SPEECH_CODEC_CAPTURE_CHANNEL_NUM + 1);
|
|
||||||
// copy reference buffer
|
// copy reference buffer
|
||||||
#if defined(SPEECH_TX_AEC) || defined(SPEECH_TX_AEC2) || \
|
#if defined(SPEECH_TX_AEC) || defined(SPEECH_TX_AEC2) || defined(SPEECH_TX_AEC3) || defined(SPEECH_TX_AEC2FLOAT) || defined(SPEECH_TX_THIRDPARTY)
|
||||||
defined(SPEECH_TX_AEC3) || defined(SPEECH_TX_AEC2FLOAT) || \
|
for (int i = SPEECH_CODEC_CAPTURE_CHANNEL_NUM, j = 0; i < pcm_len; i += SPEECH_CODEC_CAPTURE_CHANNEL_NUM + 1, j++) {
|
||||||
defined(SPEECH_TX_THIRDPARTY)
|
|
||||||
for (int i = SPEECH_CODEC_CAPTURE_CHANNEL_NUM, j = 0; i < pcm_len;
|
|
||||||
i += SPEECH_CODEC_CAPTURE_CHANNEL_NUM + 1, j++) {
|
|
||||||
aec_echo_buf[j] = pcm_buf[i];
|
aec_echo_buf[j] = pcm_buf[i];
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
for (int i = 0, j = 0; i < pcm_len; i += SPEECH_CODEC_CAPTURE_CHANNEL_NUM + 1,
|
for (int i = 0, j = 0; i < pcm_len; i += SPEECH_CODEC_CAPTURE_CHANNEL_NUM + 1, j += SPEECH_CODEC_CAPTURE_CHANNEL_NUM) {
|
||||||
j += SPEECH_CODEC_CAPTURE_CHANNEL_NUM) {
|
|
||||||
for (int k = 0; k < SPEECH_CODEC_CAPTURE_CHANNEL_NUM; k++)
|
for (int k = 0; k < SPEECH_CODEC_CAPTURE_CHANNEL_NUM; k++)
|
||||||
pcm_buf[j + k] = pcm_buf[i + k];
|
pcm_buf[j + k] = pcm_buf[i + k];
|
||||||
}
|
}
|
||||||
pcm_len = pcm_len / (SPEECH_CODEC_CAPTURE_CHANNEL_NUM + 1) *
|
pcm_len = pcm_len / (SPEECH_CODEC_CAPTURE_CHANNEL_NUM + 1) * SPEECH_CODEC_CAPTURE_CHANNEL_NUM;
|
||||||
SPEECH_CODEC_CAPTURE_CHANNEL_NUM;
|
#elif (defined(SPEECH_TX_AEC) || defined(SPEECH_TX_AEC2) || defined(SPEECH_TX_AEC3) || defined(SPEECH_TX_AEC2FLOAT) || defined(SPEECH_TX_THIRDPARTY))
|
||||||
#elif (defined(SPEECH_TX_AEC) || defined(SPEECH_TX_AEC2) || \
|
|
||||||
defined(SPEECH_TX_AEC3) || defined(SPEECH_TX_AEC2FLOAT) || \
|
|
||||||
defined(SPEECH_TX_THIRDPARTY))
|
|
||||||
int ref_pcm_len = ref_len / sizeof(int16_t);
|
int ref_pcm_len = ref_len / sizeof(int16_t);
|
||||||
ASSERT(pcm_len / SPEECH_CODEC_CAPTURE_CHANNEL_NUM == ref_pcm_len,
|
ASSERT(pcm_len / SPEECH_CODEC_CAPTURE_CHANNEL_NUM == ref_pcm_len, "[%s] Length error: %d / %d != %d", __func__, pcm_len, SPEECH_CODEC_CAPTURE_CHANNEL_NUM, ref_pcm_len);
|
||||||
"[%s] Length error: %d / %d != %d", __func__, pcm_len,
|
|
||||||
SPEECH_CODEC_CAPTURE_CHANNEL_NUM, ref_pcm_len);
|
|
||||||
|
|
||||||
for (int i = 0; i < ref_pcm_len; i++) {
|
for (int i = 0; i < ref_pcm_len; i++) {
|
||||||
aec_echo_buf[i] = ref_buf[i];
|
aec_echo_buf[i] = ref_buf[i];
|
||||||
|
@ -275,33 +251,30 @@ int process_uplink_bt_voice_frames(uint8_t *in_buf, uint32_t in_len,
|
||||||
if (bt_sco_codec_is_msbc()) {
|
if (bt_sco_codec_is_msbc()) {
|
||||||
// Up sampling
|
// Up sampling
|
||||||
if (resample_needed_flag) {
|
if (resample_needed_flag) {
|
||||||
iir_resample_process(uplink_resample_st, (int16_t *)pcm_buf_16bits,
|
iir_resample_process(uplink_resample_st, (int16_t *)pcm_buf_16bits, resample_buf, pcm_len);
|
||||||
resample_buf, pcm_len);
|
|
||||||
pcm_buf_16bits = resample_buf;
|
pcm_buf_16bits = resample_buf;
|
||||||
pcm_len = sco_frame_length;
|
pcm_len = sco_frame_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
process_uplink_msbc_frames((uint8_t *)pcm_buf_16bits,
|
process_uplink_msbc_frames((uint8_t *)pcm_buf_16bits, pcm_len * sizeof(int16_t), out_buf, out_len);
|
||||||
pcm_len * sizeof(int16_t), out_buf, out_len);
|
|
||||||
} else {
|
} else {
|
||||||
// Down sampling
|
// Down sampling
|
||||||
if (resample_needed_flag) {
|
if (resample_needed_flag) {
|
||||||
iir_resample_process(uplink_resample_st, (int16_t *)pcm_buf_16bits,
|
iir_resample_process(uplink_resample_st, (int16_t *)pcm_buf_16bits, resample_buf, pcm_len);
|
||||||
resample_buf, pcm_len);
|
|
||||||
pcm_buf_16bits = resample_buf;
|
pcm_buf_16bits = resample_buf;
|
||||||
pcm_len = sco_frame_length;
|
pcm_len = sco_frame_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
process_uplink_cvsd_frames((uint8_t *)pcm_buf_16bits,
|
process_uplink_cvsd_frames((uint8_t *)pcm_buf_16bits, pcm_len * sizeof(int16_t), out_buf, out_len);
|
||||||
pcm_len * sizeof(int16_t), out_buf, out_len);
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int process_downlink_msbc_frames(unsigned char *msbc_buf, unsigned int msbc_len,
|
int process_downlink_msbc_frames(unsigned char *msbc_buf, unsigned int msbc_len, unsigned char *pcm_buf,unsigned int pcm_len)
|
||||||
unsigned char *pcm_buf, unsigned int pcm_len) {
|
{
|
||||||
#if defined(HFP_1_6_ENABLE)
|
#if defined(HFP_1_6_ENABLE)
|
||||||
|
|
||||||
|
|
||||||
btif_sbc_pcm_data_t pcm_data;
|
btif_sbc_pcm_data_t pcm_data;
|
||||||
unsigned int msbc_offset_lowdelay = 0;
|
unsigned int msbc_offset_lowdelay = 0;
|
||||||
unsigned int i,j;
|
unsigned int i,j;
|
||||||
|
@ -311,21 +284,18 @@ int process_downlink_msbc_frames(unsigned char *msbc_buf, unsigned int msbc_len,
|
||||||
unsigned int frame_counter=0;
|
unsigned int frame_counter=0;
|
||||||
unsigned short byte_decode = 0;
|
unsigned short byte_decode = 0;
|
||||||
unsigned int msbc_offset_total = 0;
|
unsigned int msbc_offset_total = 0;
|
||||||
int msbc_offset_drift[6] = {
|
int msbc_offset_drift[6] = {0, };
|
||||||
0,
|
|
||||||
};
|
|
||||||
|
|
||||||
short *dec_pcm_buf=( short *)pcm_buf;
|
short *dec_pcm_buf=( short *)pcm_buf;
|
||||||
unsigned char dec_msbc_buf[MSBC_LEN_PER_FRAME] = {
|
unsigned char dec_msbc_buf[MSBC_LEN_PER_FRAME] = {0, };
|
||||||
0,
|
|
||||||
};
|
|
||||||
|
|
||||||
//unsigned int timer_begin=hal_sys_timer_get();
|
//unsigned int timer_begin=hal_sys_timer_get();
|
||||||
|
|
||||||
//TRACE(2,"process_downlink_msbc_frames:pcm_len:%d,msbc_len:%d",pcm_len,msbc_len);
|
//TRACE(2,"process_downlink_msbc_frames:pcm_len:%d,msbc_len:%d",pcm_len,msbc_len);
|
||||||
|
|
||||||
//TRACE(1,"decode_msbc_frame,msbc_len:%d",msbc_len);
|
//TRACE(1,"decode_msbc_frame,msbc_len:%d",msbc_len);
|
||||||
for (i = 0; i < msbc_len; i++) {
|
for(i =0; i<msbc_len; i++)
|
||||||
|
{
|
||||||
msbc_buf_all[i+MSBC_LEN_FORMBT_PER_FRAME]=msbc_buffer[i];
|
msbc_buf_all[i+MSBC_LEN_FORMBT_PER_FRAME]=msbc_buffer[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -338,31 +308,37 @@ int process_downlink_msbc_frames(unsigned char *msbc_buf, unsigned int msbc_len,
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for (j = 0; j < msbc_len / MSBC_LEN_FORMBT_PER_FRAME; j++) {
|
for(j =0; j<msbc_len/MSBC_LEN_FORMBT_PER_FRAME; j++)
|
||||||
|
{
|
||||||
frame_flag[j]=0;
|
frame_flag[j]=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msbc_find_first_sync == 0) {
|
if(msbc_find_first_sync==0)
|
||||||
for (i = 0; i < msbc_len; i++) {
|
{
|
||||||
if ((msbc_buf_all[i] == 0x01) && ((msbc_buf_all[i + 1] & 0x0f) == 0x08) &&
|
for(i =0; i<msbc_len; i++)
|
||||||
(msbc_buf_all[i + 2] == 0xad))
|
{
|
||||||
break;
|
if((msbc_buf_all[i]==0x01)&&((msbc_buf_all[i+1]&0x0f)==0x08)&&(msbc_buf_all[i+2]==0xad))break;
|
||||||
}
|
}
|
||||||
|
|
||||||
TRACE(1,"sync......:%d",i);
|
TRACE(1,"sync......:%d",i);
|
||||||
|
|
||||||
if (i < msbc_len) {
|
if(i<msbc_len)
|
||||||
|
{
|
||||||
msbc_find_first_sync=1;
|
msbc_find_first_sync=1;
|
||||||
msbc_offset=i%MSBC_LEN_FORMBT_PER_FRAME;
|
msbc_offset=i%MSBC_LEN_FORMBT_PER_FRAME;
|
||||||
msbc_offset_total=i;
|
msbc_offset_total=i;
|
||||||
} else {
|
}
|
||||||
for (j = 0; j < msbc_len / MSBC_LEN_FORMBT_PER_FRAME; j++) {
|
else
|
||||||
|
{
|
||||||
|
for (j = 0; j < msbc_len / MSBC_LEN_FORMBT_PER_FRAME; j++)
|
||||||
|
{
|
||||||
frame_flag[j] = 1;
|
frame_flag[j] = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msbc_find_first_sync == 1) {
|
if(msbc_find_first_sync==1)
|
||||||
|
{
|
||||||
int value=0;
|
int value=0;
|
||||||
unsigned char headerm1 = 0;
|
unsigned char headerm1 = 0;
|
||||||
unsigned char header0 = 0;
|
unsigned char header0 = 0;
|
||||||
|
@ -371,53 +347,55 @@ int process_downlink_msbc_frames(unsigned char *msbc_buf, unsigned int msbc_len,
|
||||||
unsigned char header3 = 0;
|
unsigned char header3 = 0;
|
||||||
// unsigned char tail0 = 0;
|
// unsigned char tail0 = 0;
|
||||||
|
|
||||||
if (msbc_offset == 0 || msbc_offset == 1) {
|
if(msbc_offset==0||msbc_offset==1)
|
||||||
|
{
|
||||||
msbc_offset_lowdelay=msbc_offset+60;
|
msbc_offset_lowdelay=msbc_offset+60;
|
||||||
//msbc_offset_lowdelay=msbc_offset;
|
//msbc_offset_lowdelay=msbc_offset;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
msbc_offset_lowdelay=msbc_offset;
|
msbc_offset_lowdelay=msbc_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//check again
|
//check again
|
||||||
for (j = 0; j < (msbc_len / MSBC_LEN_FORMBT_PER_FRAME); j++) {
|
for(j =0; j<(msbc_len/MSBC_LEN_FORMBT_PER_FRAME); j++)
|
||||||
if (next_frame_flag == 1) {
|
{
|
||||||
|
if (next_frame_flag == 1)
|
||||||
|
{
|
||||||
next_frame_flag = 0;
|
next_frame_flag = 0;
|
||||||
frame_flag[j] = 1;
|
frame_flag[j] = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (msbc_offset_lowdelay == 0 && j == 0) {
|
if(msbc_offset_lowdelay==0&&j==0)
|
||||||
|
{
|
||||||
headerm1=0x01;
|
headerm1=0x01;
|
||||||
} else {
|
}
|
||||||
headerm1 = msbc_buf_all[msbc_offset_lowdelay +
|
else
|
||||||
j * MSBC_LEN_FORMBT_PER_FRAME - 1];
|
{
|
||||||
|
headerm1 = msbc_buf_all[msbc_offset_lowdelay + j*MSBC_LEN_FORMBT_PER_FRAME-1];
|
||||||
}
|
}
|
||||||
|
|
||||||
header0 =
|
header0 = msbc_buf_all[msbc_offset_lowdelay + j*MSBC_LEN_FORMBT_PER_FRAME];
|
||||||
msbc_buf_all[msbc_offset_lowdelay + j * MSBC_LEN_FORMBT_PER_FRAME];
|
header1 = msbc_buf_all[msbc_offset_lowdelay + j*MSBC_LEN_FORMBT_PER_FRAME + 1];
|
||||||
header1 = msbc_buf_all[msbc_offset_lowdelay +
|
header2 = msbc_buf_all[msbc_offset_lowdelay + j*MSBC_LEN_FORMBT_PER_FRAME + 2];
|
||||||
j * MSBC_LEN_FORMBT_PER_FRAME + 1];
|
header3 = msbc_buf_all[msbc_offset_lowdelay + j*MSBC_LEN_FORMBT_PER_FRAME + 3];
|
||||||
header2 = msbc_buf_all[msbc_offset_lowdelay +
|
|
||||||
j * MSBC_LEN_FORMBT_PER_FRAME + 2];
|
|
||||||
header3 = msbc_buf_all[msbc_offset_lowdelay +
|
|
||||||
j * MSBC_LEN_FORMBT_PER_FRAME + 3];
|
|
||||||
|
|
||||||
/*if ((headerm1 == 0x01) && ((header0 & 0x0f) == 0x08) && (header1 ==
|
/*if ((headerm1 == 0x01) && ((header0 & 0x0f) == 0x08) && (header1 == 0xad) ||
|
||||||
0xad) || (header0 == 0x01) && ((header1 & 0x0f) == 0x08) && (header2 ==
|
(header0 == 0x01) && ((header1 & 0x0f) == 0x08) && (header2 == 0xad) ||
|
||||||
0xad) || (header1 == 0x01) && ((header2 & 0x0f) == 0x08) && (header3 ==
|
(header1 == 0x01) && ((header2 & 0x0f) == 0x08) && (header3 == 0xad))
|
||||||
0xad))
|
|
||||||
{
|
{
|
||||||
frame_flag[j] = 0;
|
frame_flag[j] = 0;
|
||||||
}*/
|
}*/
|
||||||
if ((headerm1 == 0x01) && ((header0 & 0x0f) == 0x08) &&
|
if ((headerm1 == 0x01) && ((header0 & 0x0f) == 0x08) && (header1 == 0xad))
|
||||||
(header1 == 0xad)) {
|
{
|
||||||
frame_flag[j] = 0;
|
frame_flag[j] = 0;
|
||||||
// It seems that offset is reduced by 1
|
// It seems that offset is reduced by 1
|
||||||
msbc_offset_drift[j] = -1;
|
msbc_offset_drift[j] = -1;
|
||||||
TRACE(1,"[%s] msbc_offset is reduced by 1", __FUNCTION__);
|
TRACE(1,"[%s] msbc_offset is reduced by 1", __FUNCTION__);
|
||||||
/*
|
/*
|
||||||
tail0 = msbc_buf_all[msbc_offset_lowdelay +
|
tail0 = msbc_buf_all[msbc_offset_lowdelay + j*MSBC_LEN_FORMBT_PER_FRAME + 59 - 1];
|
||||||
j*MSBC_LEN_FORMBT_PER_FRAME + 59 - 1]; if (tail0 == 0x00 || tail0 ==
|
if (tail0 == 0x00 || tail0 == 0x01|| tail0==0xff)
|
||||||
0x01|| tail0==0xff)
|
|
||||||
{
|
{
|
||||||
frame_flag[j] = 0;
|
frame_flag[j] = 0;
|
||||||
}
|
}
|
||||||
|
@ -427,13 +405,13 @@ int process_downlink_msbc_frames(unsigned char *msbc_buf, unsigned int msbc_len,
|
||||||
next_frame_flag = 1;
|
next_frame_flag = 1;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
} else if ((header0 == 0x01) && ((header1 & 0x0f) == 0x08) &&
|
}
|
||||||
(header2 == 0xad)) {
|
else if ((header0 == 0x01) && ((header1 & 0x0f) == 0x08) && (header2 == 0xad))
|
||||||
|
{
|
||||||
frame_flag[j] = 0;
|
frame_flag[j] = 0;
|
||||||
/*
|
/*
|
||||||
tail0 = msbc_buf_all[msbc_offset_lowdelay +
|
tail0 = msbc_buf_all[msbc_offset_lowdelay + j*MSBC_LEN_FORMBT_PER_FRAME + 59];
|
||||||
j*MSBC_LEN_FORMBT_PER_FRAME + 59]; if (tail0 == 0x00 || tail0 ==
|
if (tail0 == 0x00 || tail0 == 0x01|| tail0==0xff)
|
||||||
0x01|| tail0==0xff)
|
|
||||||
{
|
{
|
||||||
frame_flag[j] = 0;
|
frame_flag[j] = 0;
|
||||||
}
|
}
|
||||||
|
@ -443,15 +421,15 @@ int process_downlink_msbc_frames(unsigned char *msbc_buf, unsigned int msbc_len,
|
||||||
next_frame_flag = 1;
|
next_frame_flag = 1;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
} else if ((header1 == 0x01) && ((header2 & 0x0f) == 0x08) &&
|
}
|
||||||
(header3 == 0xad)) {
|
else if ((header1 == 0x01) && ((header2 & 0x0f) == 0x08) && (header3 == 0xad))
|
||||||
|
{
|
||||||
frame_flag[j] = 0;
|
frame_flag[j] = 0;
|
||||||
msbc_offset_drift[j] = 1;
|
msbc_offset_drift[j] = 1;
|
||||||
TRACE(1,"[%s] msbc_offset is increased by 1", __FUNCTION__);
|
TRACE(1,"[%s] msbc_offset is increased by 1", __FUNCTION__);
|
||||||
/*
|
/*
|
||||||
tail0 = msbc_buf_all[msbc_offset_lowdelay +
|
tail0 = msbc_buf_all[msbc_offset_lowdelay + j*MSBC_LEN_FORMBT_PER_FRAME + 59 + 1];
|
||||||
j*MSBC_LEN_FORMBT_PER_FRAME + 59 + 1]; if (tail0 == 0x00 ||
|
if (tail0 == 0x00 || tail0==0x01|| tail0==0xff)
|
||||||
tail0==0x01|| tail0==0xff)
|
|
||||||
{
|
{
|
||||||
frame_flag[j] = 0;
|
frame_flag[j] = 0;
|
||||||
}
|
}
|
||||||
|
@ -461,52 +439,54 @@ int process_downlink_msbc_frames(unsigned char *msbc_buf, unsigned int msbc_len,
|
||||||
next_frame_flag = 1;
|
next_frame_flag = 1;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
} else {
|
}
|
||||||
if ((header0 == MSBC_MUTE_PATTERN) &&
|
else
|
||||||
((header1 & 0x0f) == (MSBC_MUTE_PATTERN & 0x0f)) &&
|
{
|
||||||
(header2 == MSBC_MUTE_PATTERN)) {
|
if ((header0 == MSBC_MUTE_PATTERN)&& ((header1 & 0x0f) == (MSBC_MUTE_PATTERN & 0x0f)) && (header2 == MSBC_MUTE_PATTERN))
|
||||||
|
{
|
||||||
frame_flag[j]=1;
|
frame_flag[j]=1;
|
||||||
} else {
|
}
|
||||||
if ((msbc_offset_lowdelay + j * MSBC_LEN_FORMBT_PER_FRAME) >=
|
else
|
||||||
msbc_offset_total) {
|
{
|
||||||
|
if((msbc_offset_lowdelay+j*MSBC_LEN_FORMBT_PER_FRAME)>=msbc_offset_total)
|
||||||
|
{
|
||||||
frame_flag[j]=3;
|
frame_flag[j]=3;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
frame_flag[j]=1;
|
frame_flag[j]=1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (j = 0; j < msbc_len / MSBC_LEN_FORMBT_PER_FRAME; j++) {
|
for(j =0; j<msbc_len/MSBC_LEN_FORMBT_PER_FRAME; j++)
|
||||||
|
{
|
||||||
value=value|frame_flag[j];
|
value=value|frame_flag[j];
|
||||||
}
|
}
|
||||||
//abnormal msbc packet.
|
//abnormal msbc packet.
|
||||||
if (value > 1)
|
if(value>1)msbc_find_first_sync=0;
|
||||||
msbc_find_first_sync = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((frame_counter < msbc_len / MSBC_LEN_FORMBT_PER_FRAME) &&
|
while((frame_counter<msbc_len/MSBC_LEN_FORMBT_PER_FRAME)&&(frame_counter<pcm_len/BYTES_PER_PCM_FRAME))
|
||||||
(frame_counter < pcm_len / BYTES_PER_PCM_FRAME)) {
|
{
|
||||||
// TRACE(3,"[%s] decoding, offset %d, offset drift %d", __FUNCTION__,
|
//TRACE(3,"[%s] decoding, offset %d, offset drift %d", __FUNCTION__, msbc_offset, msbc_offset_drift[frame_counter]);
|
||||||
// msbc_offset, msbc_offset_drift[frame_counter]);
|
|
||||||
// skip first byte when msbc_offset == 0 and msbc_offset_drift == -1
|
// skip first byte when msbc_offset == 0 and msbc_offset_drift == -1
|
||||||
unsigned int start_idx = 0;
|
unsigned int start_idx = 0;
|
||||||
if (msbc_offset_lowdelay == 0 && msbc_offset_drift[frame_counter] == -1) {
|
if (msbc_offset_lowdelay == 0 && msbc_offset_drift[frame_counter] == -1) {
|
||||||
start_idx = 1;
|
start_idx = 1;
|
||||||
dec_msbc_buf[0] = 0x01;
|
dec_msbc_buf[0] = 0x01;
|
||||||
}
|
}
|
||||||
for (i = start_idx; i < MSBC_LEN_PER_FRAME; i++) {
|
for(i = start_idx; i<MSBC_LEN_PER_FRAME; i++)
|
||||||
|
{
|
||||||
//DecMsbcBuf[i]=DecMsbcBufAll[i+msbc_offset_lowdelay+frame_counter*MSBC_LEN_FORMBT_PER_FRAME+2];
|
//DecMsbcBuf[i]=DecMsbcBufAll[i+msbc_offset_lowdelay+frame_counter*MSBC_LEN_FORMBT_PER_FRAME+2];
|
||||||
dec_msbc_buf[i] = msbc_buf_all[i + msbc_offset_lowdelay +
|
dec_msbc_buf[i]=msbc_buf_all[i+msbc_offset_lowdelay+msbc_offset_drift[frame_counter]+frame_counter*MSBC_LEN_FORMBT_PER_FRAME];
|
||||||
msbc_offset_drift[frame_counter] +
|
|
||||||
frame_counter * MSBC_LEN_FORMBT_PER_FRAME];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//TRACE(1,"msbc header:0x%x",DecMsbcBuf[0]);
|
//TRACE(1,"msbc header:0x%x",DecMsbcBuf[0]);
|
||||||
|
|
||||||
#ifdef SPEECH_RX_PLC_DUMP_DATA
|
#ifdef SPEECH_RX_PLC_DUMP_DATA
|
||||||
audio_dump_add_channel_data(2, (short *)dec_msbc_buf,
|
audio_dump_add_channel_data(2, (short *)dec_msbc_buf, MSBC_LEN_PER_FRAME/2);
|
||||||
MSBC_LEN_PER_FRAME / 2);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
plc_type_t plc_type = packet_loss_detection_process(&pld, dec_msbc_buf);
|
plc_type_t plc_type = packet_loss_detection_process(&pld, dec_msbc_buf);
|
||||||
|
@ -521,12 +501,13 @@ int process_downlink_msbc_frames(unsigned char *msbc_buf, unsigned int msbc_len,
|
||||||
pcm_data.dataLen = 0;
|
pcm_data.dataLen = 0;
|
||||||
pcm_data.data = (uint8_t *)dec_pcm_buf;
|
pcm_data.data = (uint8_t *)dec_pcm_buf;
|
||||||
|
|
||||||
ret = btif_sbc_decode_frames(msbc_decoder, (unsigned char *)dec_msbc_buf,
|
ret = btif_sbc_decode_frames(msbc_decoder,
|
||||||
MSBC_LEN_PER_FRAME, &byte_decode, &pcm_data,
|
(unsigned char *)dec_msbc_buf,
|
||||||
SAMPLES_LEN_PER_FRAME * 2, msbc_eq_band_gain);
|
MSBC_LEN_PER_FRAME, &byte_decode,
|
||||||
|
&pcm_data, SAMPLES_LEN_PER_FRAME*2,
|
||||||
|
msbc_eq_band_gain);
|
||||||
|
|
||||||
// ASSERT(ret == BT_STS_SUCCESS, "[%s] msbc decoder should never fail",
|
//ASSERT(ret == BT_STS_SUCCESS, "[%s] msbc decoder should never fail", __FUNCTION__);
|
||||||
// __FUNCTION__);
|
|
||||||
if (ret != BT_STS_SUCCESS) {
|
if (ret != BT_STS_SUCCESS) {
|
||||||
plc_type = PLC_TYPE_DECODER_ERROR;
|
plc_type = PLC_TYPE_DECODER_ERROR;
|
||||||
packet_loss_detection_update_histogram(&pld, plc_type);
|
packet_loss_detection_update_histogram(&pld, plc_type);
|
||||||
|
@ -540,21 +521,22 @@ int process_downlink_msbc_frames(unsigned char *msbc_buf, unsigned int msbc_len,
|
||||||
PLC_good_frame(&msbc_plc_state, dec_pcm_buf, dec_pcm_buf);
|
PLC_good_frame(&msbc_plc_state, dec_pcm_buf, dec_pcm_buf);
|
||||||
#endif
|
#endif
|
||||||
#ifdef SPEECH_RX_PLC_DUMP_DATA
|
#ifdef SPEECH_RX_PLC_DUMP_DATA
|
||||||
audio_dump_add_channel_data(0, (short *)dec_pcm_buf,
|
audio_dump_add_channel_data(0, (short *)dec_pcm_buf, MSBC_ENCODE_PCM_LEN/2);
|
||||||
MSBC_ENCODE_PCM_LEN / 2);
|
|
||||||
#endif
|
#endif
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
TRACE(1,"PLC bad frame, plc type: %d", plc_type);
|
TRACE(1,"PLC bad frame, plc type: %d", plc_type);
|
||||||
#if defined(PLC_DEBUG_PRINT_DATA)
|
#if defined(PLC_DEBUG_PRINT_DATA)
|
||||||
DUMP8("0x%02x, ", dec_msbc_buf, 60);
|
DUMP8("0x%02x, ", dec_msbc_buf, 60);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef SPEECH_RX_PLC_DUMP_DATA
|
#ifdef SPEECH_RX_PLC_DUMP_DATA
|
||||||
for (uint32_t i = 0; i < MSBC_ENCODE_PCM_LEN / 2; i++) {
|
for(uint32_t i=0; i< MSBC_ENCODE_PCM_LEN/2; i++)
|
||||||
|
{
|
||||||
audio_dump_temp_buf[i] = (plc_type - 1) * 5000;
|
audio_dump_temp_buf[i] = (plc_type - 1) * 5000;
|
||||||
}
|
}
|
||||||
audio_dump_add_channel_data(0, audio_dump_temp_buf,
|
audio_dump_add_channel_data(0, audio_dump_temp_buf, MSBC_ENCODE_PCM_LEN/2);
|
||||||
MSBC_ENCODE_PCM_LEN / 2);
|
|
||||||
#endif
|
#endif
|
||||||
#if defined(ENABLE_LPC_PLC)
|
#if defined(ENABLE_LPC_PLC)
|
||||||
lpc_plc_generate(msbc_plc_state, dec_pcm_buf,
|
lpc_plc_generate(msbc_plc_state, dec_pcm_buf,
|
||||||
|
@ -571,8 +553,7 @@ int process_downlink_msbc_frames(unsigned char *msbc_buf, unsigned int msbc_len,
|
||||||
pcm_data.dataLen = MSBC_ENCODE_PCM_LEN;
|
pcm_data.dataLen = MSBC_ENCODE_PCM_LEN;
|
||||||
pcm_data.data = (uint8_t *)(msbc_plc_encoder_buffer + MSBC_CODEC_DELAY);
|
pcm_data.data = (uint8_t *)(msbc_plc_encoder_buffer + MSBC_CODEC_DELAY);
|
||||||
|
|
||||||
btif_plc_update_sbc_decoder_state(msbc_plc_encoder, &pcm_data,
|
btif_plc_update_sbc_decoder_state(msbc_plc_encoder, &pcm_data, msbc_decoder, msbc_eq_band_gain);
|
||||||
msbc_decoder, msbc_eq_band_gain);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
@ -581,21 +562,20 @@ int process_downlink_msbc_frames(unsigned char *msbc_buf, unsigned int msbc_len,
|
||||||
pcm_data.dataLen = 0;
|
pcm_data.dataLen = 0;
|
||||||
pcm_data.data = (uint8_t *)dec_pcm_buf;
|
pcm_data.data = (uint8_t *)dec_pcm_buf;
|
||||||
|
|
||||||
ret =
|
ret = btif_sbc_decode_frames(msbc_decoder,
|
||||||
btif_sbc_decode_frames(msbc_decoder, (unsigned char *)indices0,
|
(unsigned char *)indices0,
|
||||||
MSBC_LEN_PER_FRAME, &byte_decode, &pcm_data,
|
MSBC_LEN_PER_FRAME, &byte_decode,
|
||||||
SAMPLES_LEN_PER_FRAME * 2, msbc_eq_band_gain);
|
&pcm_data, SAMPLES_LEN_PER_FRAME*2,
|
||||||
|
msbc_eq_band_gain);
|
||||||
|
|
||||||
PLC_bad_frame(&msbc_plc_state, dec_pcm_buf, dec_pcm_buf);
|
PLC_bad_frame(&msbc_plc_state, dec_pcm_buf, dec_pcm_buf);
|
||||||
|
|
||||||
ASSERT(ret == BT_STS_SUCCESS, "[%s] msbc decoder should never fail",
|
ASSERT(ret == BT_STS_SUCCESS, "[%s] msbc decoder should never fail", __FUNCTION__);
|
||||||
__FUNCTION__);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SPEECH_RX_PLC_DUMP_DATA
|
#ifdef SPEECH_RX_PLC_DUMP_DATA
|
||||||
audio_dump_add_channel_data(1, (short *)dec_pcm_buf,
|
audio_dump_add_channel_data(1, (short *)dec_pcm_buf, MSBC_ENCODE_PCM_LEN/2);
|
||||||
MSBC_ENCODE_PCM_LEN / 2);
|
|
||||||
audio_dump_run();
|
audio_dump_run();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -603,7 +583,8 @@ int process_downlink_msbc_frames(unsigned char *msbc_buf, unsigned int msbc_len,
|
||||||
frame_counter++;
|
frame_counter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < MSBC_LEN_FORMBT_PER_FRAME; i++) {
|
for(i =0; i<MSBC_LEN_FORMBT_PER_FRAME; i++)
|
||||||
|
{
|
||||||
msbc_buf_all[i]=msbc_buf_all[i+msbc_len];
|
msbc_buf_all[i]=msbc_buf_all[i+msbc_len];
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -621,13 +602,11 @@ int process_downlink_msbc_frames(unsigned char *msbc_buf, unsigned int msbc_len,
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define MSBC_OFFSET_HEADER0_BYTES \
|
#define MSBC_OFFSET_HEADER0_BYTES ((MSBC_LEN_PER_FRAME-MSBC_OFFSET_BYTES)%MSBC_LEN_PER_FRAME)
|
||||||
((MSBC_LEN_PER_FRAME - MSBC_OFFSET_BYTES) % MSBC_LEN_PER_FRAME)
|
#define MSBC_OFFSET_HEADER1_BYTES ((MSBC_LEN_PER_FRAME-MSBC_OFFSET_BYTES+1)%MSBC_LEN_PER_FRAME)
|
||||||
#define MSBC_OFFSET_HEADER1_BYTES \
|
|
||||||
((MSBC_LEN_PER_FRAME - MSBC_OFFSET_BYTES + 1) % MSBC_LEN_PER_FRAME)
|
|
||||||
|
|
||||||
int process_uplink_msbc_frames(unsigned char *pcm_buf, unsigned int pcm_len,
|
int process_uplink_msbc_frames(unsigned char *pcm_buf, unsigned int pcm_len, unsigned char *msbc_buf,unsigned int msbc_len)
|
||||||
unsigned char *msbc_buf, unsigned int msbc_len) {
|
{
|
||||||
#if defined(HFP_1_6_ENABLE)
|
#if defined(HFP_1_6_ENABLE)
|
||||||
uint32_t frame_counter=0;
|
uint32_t frame_counter=0;
|
||||||
static uint32_t frame_counter_total=0;
|
static uint32_t frame_counter_total=0;
|
||||||
|
@ -638,23 +617,21 @@ int process_uplink_msbc_frames(unsigned char *pcm_buf, unsigned int pcm_len,
|
||||||
|
|
||||||
//TRACE(2,"process_uplink_msbc_frames:pcm_len:%d,msbc_len:%d",pcm_len,msbc_len);
|
//TRACE(2,"process_uplink_msbc_frames:pcm_len:%d,msbc_len:%d",pcm_len,msbc_len);
|
||||||
|
|
||||||
while ((frame_counter < msbc_len / MSBC_LEN_FORMBT_PER_FRAME) &&
|
while((frame_counter<msbc_len/MSBC_LEN_FORMBT_PER_FRAME)&&(frame_counter<pcm_len/BYTES_PER_PCM_FRAME))
|
||||||
(frame_counter < pcm_len / BYTES_PER_PCM_FRAME)) {
|
{
|
||||||
unsigned short *msbc_buf_dst_p;
|
unsigned short *msbc_buf_dst_p;
|
||||||
pcm_data_enc.data = pcm_buf+frame_counter*BYTES_PER_PCM_FRAME;
|
pcm_data_enc.data = pcm_buf+frame_counter*BYTES_PER_PCM_FRAME;
|
||||||
pcm_data_enc.dataLen = BYTES_PER_PCM_FRAME;
|
pcm_data_enc.dataLen = BYTES_PER_PCM_FRAME;
|
||||||
|
|
||||||
#if (MSBC_OFFSET_BYTES == 0) || (MSBC_OFFSET_BYTES == 1) || \
|
#if (MSBC_OFFSET_BYTES==0)||(MSBC_OFFSET_BYTES==1)||(MSBC_OFFSET_BYTES==2)
|
||||||
(MSBC_OFFSET_BYTES == 2)
|
|
||||||
//body
|
//body
|
||||||
btif_sbc_encode_frames(msbc_encoder, &pcm_data_enc, &bytes_encoded,
|
btif_sbc_encode_frames(msbc_encoder, &pcm_data_enc, &bytes_encoded, &(msbc_buf_frame[2-MSBC_OFFSET_BYTES]), (uint16_t *)&msbc_len_frame, 0xFFFF);
|
||||||
&(msbc_buf_frame[2 - MSBC_OFFSET_BYTES]),
|
|
||||||
(uint16_t *)&msbc_len_frame, 0xFFFF);
|
|
||||||
//tail
|
//tail
|
||||||
msbc_buf_frame[59-MSBC_OFFSET_BYTES]=0x00;
|
msbc_buf_frame[59-MSBC_OFFSET_BYTES]=0x00;
|
||||||
//header
|
//header
|
||||||
msbc_buf_frame[MSBC_OFFSET_HEADER0_BYTES]=0x01;
|
msbc_buf_frame[MSBC_OFFSET_HEADER0_BYTES]=0x01;
|
||||||
switch ((frame_counter_total % 4)) {
|
switch((frame_counter_total%4))
|
||||||
|
{
|
||||||
case 0:
|
case 0:
|
||||||
msbc_buf_frame[MSBC_OFFSET_HEADER1_BYTES]=0x08;
|
msbc_buf_frame[MSBC_OFFSET_HEADER1_BYTES]=0x08;
|
||||||
break;
|
break;
|
||||||
|
@ -668,18 +645,17 @@ int process_uplink_msbc_frames(unsigned char *pcm_buf, unsigned int pcm_len,
|
||||||
msbc_buf_frame[MSBC_OFFSET_HEADER1_BYTES]=0xf8;
|
msbc_buf_frame[MSBC_OFFSET_HEADER1_BYTES]=0xf8;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
msbc_buf_dst_p =
|
msbc_buf_dst_p=(uint16_t *)(msbc_buf+frame_counter*MSBC_LEN_PER_FRAME*2);
|
||||||
(uint16_t *)(msbc_buf + frame_counter * MSBC_LEN_PER_FRAME * 2);
|
|
||||||
|
|
||||||
for (int i = 0; i < MSBC_LEN_PER_FRAME; i++) {
|
for (int i = 0; i < MSBC_LEN_PER_FRAME; i++)
|
||||||
|
{
|
||||||
msbc_buf_dst_p[i] = msbc_buf_frame[i]<<8;
|
msbc_buf_dst_p[i] = msbc_buf_frame[i]<<8;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
btif_sbc_encode_frames(msbc_encoder, &pcm_data_enc, &bytes_encoded,
|
btif_sbc_encode_frames(msbc_encoder, &pcm_data_enc, &bytes_encoded, &(msbc_buf_frame[MSBC_LEN_PER_FRAME+2]), (uint16_t *)&msbc_len_frame, 0xFFFF);
|
||||||
&(msbc_buf_frame[MSBC_LEN_PER_FRAME + 2]),
|
|
||||||
(uint16_t *)&msbc_len_frame, 0xFFFF);
|
|
||||||
msbc_buf_frame[MSBC_LEN_PER_FRAME+0]=0x01;
|
msbc_buf_frame[MSBC_LEN_PER_FRAME+0]=0x01;
|
||||||
switch ((frame_counter_total % 4)) {
|
switch((frame_counter_total%4))
|
||||||
|
{
|
||||||
case 0:
|
case 0:
|
||||||
msbc_buf_frame[MSBC_LEN_PER_FRAME+1]=0x08;
|
msbc_buf_frame[MSBC_LEN_PER_FRAME+1]=0x08;
|
||||||
break;
|
break;
|
||||||
|
@ -694,14 +670,15 @@ int process_uplink_msbc_frames(unsigned char *pcm_buf, unsigned int pcm_len,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
msbc_buf_frame[MSBC_LEN_PER_FRAME+59]=0x00;
|
msbc_buf_frame[MSBC_LEN_PER_FRAME+59]=0x00;
|
||||||
msbc_buf_dst_p =
|
msbc_buf_dst_p=(uint16_t *)(msbc_buf+frame_counter*MSBC_LEN_PER_FRAME*2);
|
||||||
(uint16_t *)(msbc_buf + frame_counter * MSBC_LEN_PER_FRAME * 2);
|
|
||||||
|
|
||||||
for (int i = 0; i < MSBC_LEN_PER_FRAME; i++) {
|
for (int i = 0; i < MSBC_LEN_PER_FRAME; i++)
|
||||||
|
{
|
||||||
msbc_buf_dst_p[i] = msbc_buf_frame[MSBC_OFFSET_BYTES+i]<<8;
|
msbc_buf_dst_p[i] = msbc_buf_frame[MSBC_OFFSET_BYTES+i]<<8;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < MSBC_LEN_PER_FRAME; i++) {
|
for (int i = 0; i < MSBC_LEN_PER_FRAME; i++)
|
||||||
|
{
|
||||||
msbc_buf_frame[i] = msbc_buf_frame[MSBC_LEN_PER_FRAME+i];
|
msbc_buf_frame[i] = msbc_buf_frame[MSBC_LEN_PER_FRAME+i];
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -726,10 +703,10 @@ int process_uplink_msbc_frames(unsigned char *pcm_buf, unsigned int pcm_len,
|
||||||
|
|
||||||
#define CVSD_PCM_SIZE (120)
|
#define CVSD_PCM_SIZE (120)
|
||||||
|
|
||||||
static POSSIBLY_UNUSED uint8_t
|
static POSSIBLY_UNUSED uint8_t cvsd_buf_all[CVSD_PACKET_SIZE + CVSD_OFFSET_BYTES];
|
||||||
cvsd_buf_all[CVSD_PACKET_SIZE + CVSD_OFFSET_BYTES];
|
|
||||||
|
|
||||||
POSSIBLY_UNUSED plc_type_t check_cvsd_mute_pattern(uint8_t *buf, uint32_t len) {
|
POSSIBLY_UNUSED plc_type_t check_cvsd_mute_pattern(uint8_t *buf, uint32_t len)
|
||||||
|
{
|
||||||
for (uint32_t i = 0; i < len; i++)
|
for (uint32_t i = 0; i < len; i++)
|
||||||
if (buf[i] != CVSD_MUTE_PATTERN)
|
if (buf[i] != CVSD_MUTE_PATTERN)
|
||||||
return PLC_TYPE_PASS;
|
return PLC_TYPE_PASS;
|
||||||
|
@ -737,14 +714,12 @@ POSSIBLY_UNUSED plc_type_t check_cvsd_mute_pattern(uint8_t *buf, uint32_t len) {
|
||||||
return PLC_TYPE_CONTROLLER_MUTE;
|
return PLC_TYPE_CONTROLLER_MUTE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int process_downlink_cvsd_frames(unsigned char *cvsd_buf, unsigned int cvsd_len,
|
int process_downlink_cvsd_frames(unsigned char *cvsd_buf, unsigned int cvsd_len, unsigned char *pcm_buf,unsigned int pcm_len)
|
||||||
unsigned char *pcm_buf, unsigned int pcm_len) {
|
{
|
||||||
// TRACE(2,"process_downlink_cvsd_frames
|
//TRACE(2,"process_downlink_cvsd_frames pcm_len:%d,cvsd_len:%d",pcm_len,cvsd_len);
|
||||||
// pcm_len:%d,cvsd_len:%d",pcm_len,cvsd_len);
|
|
||||||
|
|
||||||
#if defined(CVSD_BYPASS) && defined(ENABLE_LPC_PLC)
|
#if defined(CVSD_BYPASS) && defined(ENABLE_LPC_PLC)
|
||||||
ASSERT(cvsd_len % CVSD_PACKET_SIZE == 0, "[%s] cvsd input length(%d) error",
|
ASSERT(cvsd_len % CVSD_PACKET_SIZE == 0, "[%s] cvsd input length(%d) error", __FUNCTION__, cvsd_len);
|
||||||
__FUNCTION__, cvsd_len);
|
|
||||||
for (uint32_t i = 0; i < cvsd_len; i += CVSD_PACKET_SIZE) {
|
for (uint32_t i = 0; i < cvsd_len; i += CVSD_PACKET_SIZE) {
|
||||||
memcpy(&cvsd_buf_all[CVSD_OFFSET_BYTES], cvsd_buf, CVSD_PACKET_SIZE);
|
memcpy(&cvsd_buf_all[CVSD_OFFSET_BYTES], cvsd_buf, CVSD_PACKET_SIZE);
|
||||||
memcpy(cvsd_buf, cvsd_buf_all, CVSD_PACKET_SIZE);
|
memcpy(cvsd_buf, cvsd_buf_all, CVSD_PACKET_SIZE);
|
||||||
|
@ -788,18 +763,19 @@ int process_downlink_cvsd_frames(unsigned char *cvsd_buf, unsigned int cvsd_len,
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int process_uplink_cvsd_frames(unsigned char *pcm_buf, unsigned int pcm_len,
|
int process_uplink_cvsd_frames(unsigned char *pcm_buf, unsigned int pcm_len, unsigned char *cvsd_buf,unsigned int cvsd_len)
|
||||||
unsigned char *cvsd_buf, unsigned int cvsd_len) {
|
{
|
||||||
// TRACE(2,"process_uplink_cvsd_frames
|
//TRACE(2,"process_uplink_cvsd_frames pcm_len:%d,cvsd_len:%d",pcm_len,cvsd_len);
|
||||||
// pcm_len:%d,cvsd_len:%d",pcm_len,cvsd_len);
|
|
||||||
#if defined(CVSD_BYPASS)
|
#if defined(CVSD_BYPASS)
|
||||||
Pcm8kToCvsd((short *)pcm_buf, cvsd_buf, pcm_len/2);
|
Pcm8kToCvsd((short *)pcm_buf, cvsd_buf, pcm_len/2);
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
void *voicebtpcm_get_ext_buff(int size) {
|
void *voicebtpcm_get_ext_buff(int size)
|
||||||
|
{
|
||||||
uint8_t *pBuff = NULL;
|
uint8_t *pBuff = NULL;
|
||||||
if (size % 4) {
|
if (size % 4)
|
||||||
|
{
|
||||||
size = size + (4 - size % 4);
|
size = size + (4 - size % 4);
|
||||||
}
|
}
|
||||||
app_audio_mempool_get_buff(&pBuff, size);
|
app_audio_mempool_get_buff(&pBuff, size);
|
||||||
|
@ -808,29 +784,25 @@ void *voicebtpcm_get_ext_buff(int size) {
|
||||||
}
|
}
|
||||||
// sco sample rate: encoder/decoder sample rate
|
// sco sample rate: encoder/decoder sample rate
|
||||||
// codec sample rate: hardware sample rate
|
// codec sample rate: hardware sample rate
|
||||||
int voicebtpcm_pcm_audio_init(int sco_sample_rate, int codec_sample_rate) {
|
int voicebtpcm_pcm_audio_init(int sco_sample_rate, int codec_sample_rate)
|
||||||
|
{
|
||||||
uint8_t POSSIBLY_UNUSED *speech_buf = NULL;
|
uint8_t POSSIBLY_UNUSED *speech_buf = NULL;
|
||||||
int POSSIBLY_UNUSED speech_len = 0;
|
int POSSIBLY_UNUSED speech_len = 0;
|
||||||
|
|
||||||
sco_frame_length =
|
sco_frame_length = SPEECH_FRAME_MS_TO_LEN(sco_sample_rate, SPEECH_SCO_FRAME_MS);
|
||||||
SPEECH_FRAME_MS_TO_LEN(sco_sample_rate, SPEECH_SCO_FRAME_MS);
|
codec_frame_length = SPEECH_FRAME_MS_TO_LEN(codec_sample_rate, SPEECH_SCO_FRAME_MS);
|
||||||
codec_frame_length =
|
|
||||||
SPEECH_FRAME_MS_TO_LEN(codec_sample_rate, SPEECH_SCO_FRAME_MS);
|
|
||||||
|
|
||||||
TRACE(3, "[%s] TX: sample rate = %d, frame len = %d", __func__,
|
TRACE(3, "[%s] TX: sample rate = %d, frame len = %d", __func__, codec_sample_rate, codec_frame_length);
|
||||||
codec_sample_rate, codec_frame_length);
|
TRACE(3, "[%s] RX: sample rate = %d, frame len = %d", __func__, codec_sample_rate, codec_frame_length);
|
||||||
TRACE(3, "[%s] RX: sample rate = %d, frame len = %d", __func__,
|
|
||||||
codec_sample_rate, codec_frame_length);
|
|
||||||
|
|
||||||
memset(cvsd_buf_all, CVSD_MUTE_PATTERN, sizeof(cvsd_buf_all));
|
memset(cvsd_buf_all, CVSD_MUTE_PATTERN, sizeof(cvsd_buf_all));
|
||||||
#if defined(HFP_1_6_ENABLE)
|
#if defined(HFP_1_6_ENABLE)
|
||||||
|
|
||||||
memset(msbc_buf_all,MSBC_MUTE_PATTERN&0xFF, sizeof(msbc_buf_all));
|
memset(msbc_buf_all,MSBC_MUTE_PATTERN&0xFF, sizeof(msbc_buf_all));
|
||||||
if (bt_sco_codec_is_msbc()) {
|
if (bt_sco_codec_is_msbc())
|
||||||
app_audio_mempool_get_buff((uint8_t **)&msbc_encoder,
|
{
|
||||||
sizeof(btif_sbc_encoder_t));
|
app_audio_mempool_get_buff((uint8_t **)&msbc_encoder, sizeof(btif_sbc_encoder_t));
|
||||||
app_audio_mempool_get_buff((uint8_t **)&msbc_decoder,
|
app_audio_mempool_get_buff((uint8_t **)&msbc_decoder, sizeof(btif_sbc_decoder_t));
|
||||||
sizeof(btif_sbc_decoder_t));
|
|
||||||
|
|
||||||
//init msbc encoder
|
//init msbc encoder
|
||||||
btif_sbc_init_encoder(msbc_encoder);
|
btif_sbc_init_encoder(msbc_encoder);
|
||||||
|
@ -845,15 +817,18 @@ int voicebtpcm_pcm_audio_init(int sco_sample_rate, int codec_sample_rate) {
|
||||||
msbc_encoder->streamInfo.numSubBands = 8;
|
msbc_encoder->streamInfo.numSubBands = 8;
|
||||||
|
|
||||||
//init msbc decoder
|
//init msbc decoder
|
||||||
const float EQLevel[25] = {
|
const float EQLevel[25] =
|
||||||
|
{
|
||||||
0.0630957, 0.0794328, 0.1, 0.1258925, 0.1584893,
|
0.0630957, 0.0794328, 0.1, 0.1258925, 0.1584893,
|
||||||
0.1995262, 0.2511886, 0.3162278, 0.398107, 0.5011872,
|
0.1995262, 0.2511886, 0.3162278, 0.398107, 0.5011872,
|
||||||
0.6309573, 0.794328, 1, 1.258925, 1.584893,
|
0.6309573, 0.794328, 1, 1.258925, 1.584893,
|
||||||
1.995262, 2.5118864, 3.1622776, 3.9810717, 5.011872,
|
1.995262, 2.5118864, 3.1622776, 3.9810717, 5.011872,
|
||||||
6.309573, 7.943282, 10, 12.589254, 15.848932}; //-12~12
|
6.309573, 7.943282, 10, 12.589254, 15.848932
|
||||||
|
};//-12~12
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
|
|
||||||
for (i = 0; i < sizeof(msbc_eq_band_gain) / sizeof(float); i++) {
|
for (i=0; i<sizeof(msbc_eq_band_gain)/sizeof(float); i++)
|
||||||
|
{
|
||||||
msbc_eq_band_gain[i] = EQLevel[cfg_aud_eq_sbc_band_settings[i]+12];
|
msbc_eq_band_gain[i] = EQLevel[cfg_aud_eq_sbc_band_settings[i]+12];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -881,8 +856,7 @@ int voicebtpcm_pcm_audio_init(int sco_sample_rate, int codec_sample_rate) {
|
||||||
packet_loss_detection_init(&pld);
|
packet_loss_detection_init(&pld);
|
||||||
|
|
||||||
#if defined(ENABLE_PLC_ENCODER)
|
#if defined(ENABLE_PLC_ENCODER)
|
||||||
app_audio_mempool_get_buff((uint8_t **)&msbc_plc_encoder,
|
app_audio_mempool_get_buff((uint8_t **)&msbc_plc_encoder, sizeof(btif_sbc_encoder_t));
|
||||||
sizeof(btif_sbc_encoder_t));
|
|
||||||
btif_sbc_init_encoder(msbc_plc_encoder);
|
btif_sbc_init_encoder(msbc_plc_encoder);
|
||||||
msbc_plc_encoder->streamInfo.mSbcFlag = 1;
|
msbc_plc_encoder->streamInfo.mSbcFlag = 1;
|
||||||
msbc_plc_encoder->streamInfo.bitPool = 26;
|
msbc_plc_encoder->streamInfo.bitPool = 26;
|
||||||
|
@ -894,11 +868,10 @@ int voicebtpcm_pcm_audio_init(int sco_sample_rate, int codec_sample_rate) {
|
||||||
/* The number of subbands in the stream (4 or 8) */
|
/* The number of subbands in the stream (4 or 8) */
|
||||||
msbc_plc_encoder->streamInfo.numSubBands = 8;
|
msbc_plc_encoder->streamInfo.numSubBands = 8;
|
||||||
msbc_plc_encoder->streamInfo.numChannels = 1;
|
msbc_plc_encoder->streamInfo.numChannels = 1;
|
||||||
app_audio_mempool_get_buff((uint8_t **)&msbc_plc_encoder_buffer,
|
app_audio_mempool_get_buff((uint8_t **)&msbc_plc_encoder_buffer, sizeof(int16_t) * (SAMPLES_LEN_PER_FRAME + MSBC_CODEC_DELAY));
|
||||||
sizeof(int16_t) *
|
|
||||||
(SAMPLES_LEN_PER_FRAME + MSBC_CODEC_DELAY));
|
|
||||||
#endif
|
#endif
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
#ifndef ENABLE_LPC_PLC
|
#ifndef ENABLE_LPC_PLC
|
||||||
|
@ -911,8 +884,7 @@ int voicebtpcm_pcm_audio_init(int sco_sample_rate, int codec_sample_rate) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef SPEECH_RX_PLC_DUMP_DATA
|
#ifdef SPEECH_RX_PLC_DUMP_DATA
|
||||||
audio_dump_temp_buf =
|
audio_dump_temp_buf = (int16_t *)voicebtpcm_get_ext_buff(sizeof(int16_t) * 120);
|
||||||
(int16_t *)voicebtpcm_get_ext_buff(sizeof(int16_t) * 120);
|
|
||||||
audio_dump_init(120, sizeof(short), 3);
|
audio_dump_init(120, sizeof(short), 3);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -920,15 +892,12 @@ int voicebtpcm_pcm_audio_init(int sco_sample_rate, int codec_sample_rate) {
|
||||||
|
|
||||||
if (resample_needed_flag) {
|
if (resample_needed_flag) {
|
||||||
TRACE(1, "[%s] SCO <-- Resample --> CODEC", __func__);
|
TRACE(1, "[%s] SCO <-- Resample --> CODEC", __func__);
|
||||||
resample_buf =
|
resample_buf = (int16_t *)voicebtpcm_get_ext_buff(sizeof(int16_t) * sco_frame_length);
|
||||||
(int16_t *)voicebtpcm_get_ext_buff(sizeof(int16_t) * sco_frame_length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(SCO_OPTIMIZE_FOR_RAM)
|
#if defined(SCO_OPTIMIZE_FOR_RAM)
|
||||||
sco_overlay_ram_buf_len =
|
sco_overlay_ram_buf_len = hal_overlay_get_text_free_size((enum HAL_OVERLAY_ID_T)APP_OVERLAY_HFP);
|
||||||
hal_overlay_get_text_free_size((enum HAL_OVERLAY_ID_T)APP_OVERLAY_HFP);
|
sco_overlay_ram_buf = (uint8_t *)hal_overlay_get_text_free_addr((enum HAL_OVERLAY_ID_T)APP_OVERLAY_HFP);
|
||||||
sco_overlay_ram_buf = (uint8_t *)hal_overlay_get_text_free_addr(
|
|
||||||
(enum HAL_OVERLAY_ID_T)APP_OVERLAY_HFP);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
speech_len = app_audio_mempool_free_buff_size() - APP_BT_STREAM_USE_BUF_SIZE;
|
speech_len = app_audio_mempool_free_buff_size() - APP_BT_STREAM_USE_BUF_SIZE;
|
||||||
|
@ -936,16 +905,11 @@ int voicebtpcm_pcm_audio_init(int sco_sample_rate, int codec_sample_rate) {
|
||||||
|
|
||||||
int tx_frame_ms = SPEECH_PROCESS_FRAME_MS;
|
int tx_frame_ms = SPEECH_PROCESS_FRAME_MS;
|
||||||
int rx_frame_ms = SPEECH_SCO_FRAME_MS;
|
int rx_frame_ms = SPEECH_SCO_FRAME_MS;
|
||||||
speech_init(codec_sample_rate, codec_sample_rate, tx_frame_ms, rx_frame_ms,
|
speech_init(codec_sample_rate, codec_sample_rate, tx_frame_ms, rx_frame_ms, SPEECH_SCO_FRAME_MS, speech_buf, speech_len);
|
||||||
SPEECH_SCO_FRAME_MS, speech_buf, speech_len);
|
|
||||||
|
|
||||||
if (resample_needed_flag) {
|
if (resample_needed_flag) {
|
||||||
uplink_resample_st = iir_resample_init(
|
uplink_resample_st = iir_resample_init(codec_frame_length, iir_resample_choose_mode(codec_sample_rate, sco_sample_rate));
|
||||||
codec_frame_length,
|
downlink_resample_st = iir_resample_init(sco_frame_length, iir_resample_choose_mode(sco_sample_rate, codec_sample_rate));
|
||||||
iir_resample_choose_mode(codec_sample_rate, sco_sample_rate));
|
|
||||||
downlink_resample_st = iir_resample_init(
|
|
||||||
sco_frame_length,
|
|
||||||
iir_resample_choose_mode(sco_sample_rate, codec_sample_rate));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(ENABLE_LPC_PLC)
|
#if defined(ENABLE_LPC_PLC)
|
||||||
|
@ -955,10 +919,10 @@ int voicebtpcm_pcm_audio_init(int sco_sample_rate, int codec_sample_rate) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int voicebtpcm_pcm_audio_deinit(void) {
|
int voicebtpcm_pcm_audio_deinit(void)
|
||||||
|
{
|
||||||
TRACE(1,"[%s] Close...", __func__);
|
TRACE(1,"[%s] Close...", __func__);
|
||||||
// TRACE(2,"[%s] app audio buffer free = %d", __func__,
|
// TRACE(2,"[%s] app audio buffer free = %d", __func__, app_audio_mempool_free_buff_size());
|
||||||
// app_audio_mempool_free_buff_size());
|
|
||||||
|
|
||||||
#if defined(ENABLE_LPC_PLC)
|
#if defined(ENABLE_LPC_PLC)
|
||||||
lpc_plc_destroy(msbc_plc_state);
|
lpc_plc_destroy(msbc_plc_state);
|
||||||
|
|
|
@ -17,22 +17,23 @@
|
||||||
#include "mbed.h"
|
#include "mbed.h"
|
||||||
#endif
|
#endif
|
||||||
// Standard C Included Files
|
// Standard C Included Files
|
||||||
|
#include <string.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "hal_timer.h"
|
|
||||||
#include "hal_trace.h"
|
|
||||||
#include "hal_uart.h"
|
#include "hal_uart.h"
|
||||||
|
#include "hal_trace.h"
|
||||||
|
#include "hal_timer.h"
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* * @brief Standard Winodws PCM wave file header length
|
* * @brief Standard Winodws PCM wave file header length
|
||||||
* */
|
* */
|
||||||
#define WAVE_FILE_HEADER_SIZE 0x2CU
|
#define WAVE_FILE_HEADER_SIZE 0x2CU
|
||||||
|
|
||||||
typedef struct wave_header {
|
typedef struct wave_header
|
||||||
|
{
|
||||||
uint8_t riff[4];
|
uint8_t riff[4];
|
||||||
uint32_t size;
|
uint32_t size;
|
||||||
uint8_t waveFlag[4];
|
uint8_t waveFlag[4];
|
||||||
|
@ -51,7 +52,8 @@ typedef struct wave_header {
|
||||||
/*!
|
/*!
|
||||||
* * @brief Wave file structure
|
* * @brief Wave file structure
|
||||||
* */
|
* */
|
||||||
typedef struct wave_file {
|
typedef struct wave_file
|
||||||
|
{
|
||||||
wave_header_t header;
|
wave_header_t header;
|
||||||
uint32_t *data;
|
uint32_t *data;
|
||||||
}wave_file_t;
|
}wave_file_t;
|
||||||
|
@ -69,13 +71,16 @@ static int32_t (*wav_file_playback_callback)(int32_t) = NULL;
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Code
|
// Code
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void wav_file_set_playeback_cb(int32_t (*cb)(int32_t)) {
|
void wav_file_set_playeback_cb(int32_t (* cb)(int32_t))
|
||||||
|
{
|
||||||
wav_file_playback_callback = cb;
|
wav_file_playback_callback = cb;
|
||||||
}
|
}
|
||||||
bool wav_file_isplaydone(void) {
|
bool wav_file_isplaydone(void)
|
||||||
|
{
|
||||||
return (g_curr_play_index >= g_total_play_count)? true : false;
|
return (g_curr_play_index >= g_total_play_count)? true : false;
|
||||||
}
|
}
|
||||||
uint32_t wav_file_audio_more_data(uint8_t *buf, uint32_t len) {
|
uint32_t wav_file_audio_more_data(uint8_t *buf, uint32_t len)
|
||||||
|
{
|
||||||
// static uint32_t g_preIrqTime = 0;
|
// static uint32_t g_preIrqTime = 0;
|
||||||
uint32_t reallen = 0;
|
uint32_t reallen = 0;
|
||||||
// int32_t stime,etime;
|
// int32_t stime,etime;
|
||||||
|
@ -102,9 +107,7 @@ uint32_t wav_file_audio_more_data(uint8_t *buf, uint32_t len) {
|
||||||
return (len);
|
return (len);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TRACE(5,"wav_file_audio_more_data irqDur:%d fsSpend:%d, readbuff:0x%08x
|
// TRACE(5,"wav_file_audio_more_data irqDur:%d fsSpend:%d, readbuff:0x%08x %d/%d\n ", TICKS_TO_MS(stime - g_preIrqTime),TICKS_TO_MS(etime - stime),buf,reallen,len);
|
||||||
// %d/%d\n ", TICKS_TO_MS(stime - g_preIrqTime),TICKS_TO_MS(etime -
|
|
||||||
// stime),buf,reallen,len);
|
|
||||||
// g_preIrqTime = stime;
|
// g_preIrqTime = stime;
|
||||||
|
|
||||||
/* walk index */
|
/* walk index */
|
||||||
|
@ -113,13 +116,15 @@ uint32_t wav_file_audio_more_data(uint8_t *buf, uint32_t len) {
|
||||||
return reallen;
|
return reallen;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t get_wav_data(wave_file_t *waveFile) {
|
uint32_t get_wav_data(wave_file_t *waveFile)
|
||||||
|
{
|
||||||
uint8_t *dataTemp = (uint8_t *)waveFile->data;
|
uint8_t *dataTemp = (uint8_t *)waveFile->data;
|
||||||
|
|
||||||
// check for RIFF
|
// check for RIFF
|
||||||
memcpy(waveFile->header.riff, dataTemp, 4);
|
memcpy(waveFile->header.riff, dataTemp, 4);
|
||||||
dataTemp += 4;
|
dataTemp += 4;
|
||||||
if (memcmp((uint8_t *)waveFile->header.riff, "RIFF", 4)) {
|
if( memcmp( (uint8_t*)waveFile->header.riff, "RIFF", 4) )
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,14 +137,16 @@ uint32_t get_wav_data(wave_file_t *waveFile) {
|
||||||
// .wav file flag
|
// .wav file flag
|
||||||
memcpy(waveFile->header.waveFlag, dataTemp, 4);
|
memcpy(waveFile->header.waveFlag, dataTemp, 4);
|
||||||
dataTemp += 4;
|
dataTemp += 4;
|
||||||
if (memcmp((uint8_t *)waveFile->header.waveFlag, "WAVE", 4)) {
|
if( memcmp( (uint8_t*)waveFile->header.waveFlag, "WAVE", 4) )
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// fmt
|
// fmt
|
||||||
memcpy(waveFile->header.fmt, dataTemp, 4);
|
memcpy(waveFile->header.fmt, dataTemp, 4);
|
||||||
dataTemp += 4;
|
dataTemp += 4;
|
||||||
if (memcmp((uint8_t *)waveFile->header.fmt, "fmt ", 4)) {
|
if( memcmp( (uint8_t*)waveFile->header.fmt, "fmt ", 4) )
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,7 +184,8 @@ uint32_t get_wav_data(wave_file_t *waveFile) {
|
||||||
// Data
|
// Data
|
||||||
memcpy(waveFile->header.dataFlag, dataTemp, 4);
|
memcpy(waveFile->header.dataFlag, dataTemp, 4);
|
||||||
dataTemp += 4;
|
dataTemp += 4;
|
||||||
if (memcmp((uint8_t *)waveFile->header.dataFlag, "data ", 4)) {
|
if( memcmp( (uint8_t*)waveFile->header.dataFlag, "data ", 4) )
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
memcpy(&waveFile->header.length, dataTemp, 4);
|
memcpy(&waveFile->header.length, dataTemp, 4);
|
||||||
|
@ -186,7 +194,9 @@ uint32_t get_wav_data(wave_file_t *waveFile) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void audio_wav_init(wave_file_t *newWav) {
|
|
||||||
|
void audio_wav_init(wave_file_t *newWav)
|
||||||
|
{
|
||||||
get_wav_data(newWav);
|
get_wav_data(newWav);
|
||||||
|
|
||||||
// Configure the play audio g_format
|
// Configure the play audio g_format
|
||||||
|
@ -196,7 +206,8 @@ void audio_wav_init(wave_file_t *newWav) {
|
||||||
//g_format.mono_streo = (sai_mono_streo_t)((newWav->header.channels) - 1);
|
//g_format.mono_streo = (sai_mono_streo_t)((newWav->header.channels) - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t play_wav_file(char *file_path) {
|
uint32_t play_wav_file(char *file_path)
|
||||||
|
{
|
||||||
uint32_t bytesToRead = 0;
|
uint32_t bytesToRead = 0;
|
||||||
|
|
||||||
wave_file_t *newWav = &g_wave_file_info;
|
wave_file_t *newWav = &g_wave_file_info;
|
||||||
|
@ -217,8 +228,7 @@ uint32_t play_wav_file(char *file_path) {
|
||||||
audio_wav_init(newWav);
|
audio_wav_init(newWav);
|
||||||
|
|
||||||
// Remove header size from byte count
|
// Remove header size from byte count
|
||||||
// Adjust note duration by divider value, wav tables in pcm_data.h are 200ms
|
// Adjust note duration by divider value, wav tables in pcm_data.h are 200ms by default
|
||||||
// by default
|
|
||||||
bytesToRead = (newWav->header.length - WAVE_FILE_HEADER_SIZE);
|
bytesToRead = (newWav->header.length - WAVE_FILE_HEADER_SIZE);
|
||||||
|
|
||||||
g_curr_play_index = 0;
|
g_curr_play_index = 0;
|
||||||
|
@ -227,7 +237,8 @@ uint32_t play_wav_file(char *file_path) {
|
||||||
return newWav->header.sampFreq;
|
return newWav->header.sampFreq;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t stop_wav_file(void) {
|
uint32_t stop_wav_file(void)
|
||||||
|
{
|
||||||
memset(&g_wave_file_info, 0, sizeof(g_wave_file_info));
|
memset(&g_wave_file_info, 0, sizeof(g_wave_file_info));
|
||||||
g_curr_play_index = 0;
|
g_curr_play_index = 0;
|
||||||
g_total_play_count = 0;
|
g_total_play_count = 0;
|
||||||
|
|
|
@ -13,19 +13,19 @@
|
||||||
* trademark and other intellectual property rights.
|
* trademark and other intellectual property rights.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include "app_battery.h"
|
|
||||||
#include "app_status_ind.h"
|
|
||||||
#include "app_thread.h"
|
|
||||||
#include "apps.h"
|
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
#include "hal_chipid.h"
|
#include "tgt_hardware.h"
|
||||||
|
#include "pmu.h"
|
||||||
|
#include "hal_timer.h"
|
||||||
#include "hal_gpadc.h"
|
#include "hal_gpadc.h"
|
||||||
|
#include "hal_trace.h"
|
||||||
#include "hal_gpio.h"
|
#include "hal_gpio.h"
|
||||||
#include "hal_iomux.h"
|
#include "hal_iomux.h"
|
||||||
#include "hal_timer.h"
|
#include "hal_chipid.h"
|
||||||
#include "hal_trace.h"
|
#include "app_thread.h"
|
||||||
#include "pmu.h"
|
#include "app_battery.h"
|
||||||
#include "tgt_hardware.h"
|
#include "apps.h"
|
||||||
|
#include "app_status_ind.h"
|
||||||
#ifdef BT_USB_AUDIO_DUAL_MODE
|
#ifdef BT_USB_AUDIO_DUAL_MODE
|
||||||
#include "btusb_audio.h"
|
#include "btusb_audio.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -74,31 +74,21 @@ extern "C" bool app_usbaudio_mode_on(void);
|
||||||
#define CHARGER_PLUGINOUT_DEBOUNCE_CNT (3)
|
#define CHARGER_PLUGINOUT_DEBOUNCE_CNT (3)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define APP_BATTERY_CHARGING_PLUGOUT_DEDOUNCE_CNT \
|
#define APP_BATTERY_CHARGING_PLUGOUT_DEDOUNCE_CNT (APP_BATTERY_CHARGING_PERIODIC_MS<500?3:1)
|
||||||
(APP_BATTERY_CHARGING_PERIODIC_MS < 500 ? 3 : 1)
|
|
||||||
|
|
||||||
#define APP_BATTERY_CHARGING_EXTPIN_MEASURE_CNT \
|
#define APP_BATTERY_CHARGING_EXTPIN_MEASURE_CNT (APP_BATTERY_CHARGING_PERIODIC_MS<2*1000?2*1000/APP_BATTERY_CHARGING_PERIODIC_MS:1)
|
||||||
(APP_BATTERY_CHARGING_PERIODIC_MS < 2 * 1000 \
|
|
||||||
? 2 * 1000 / APP_BATTERY_CHARGING_PERIODIC_MS \
|
|
||||||
: 1)
|
|
||||||
#define APP_BATTERY_CHARGING_EXTPIN_DEDOUNCE_CNT (6)
|
#define APP_BATTERY_CHARGING_EXTPIN_DEDOUNCE_CNT (6)
|
||||||
|
|
||||||
#define APP_BATTERY_CHARGING_OVERVOLT_MEASURE_CNT \
|
#define APP_BATTERY_CHARGING_OVERVOLT_MEASURE_CNT (APP_BATTERY_CHARGING_PERIODIC_MS<2*1000?2*1000/APP_BATTERY_CHARGING_PERIODIC_MS:1)
|
||||||
(APP_BATTERY_CHARGING_PERIODIC_MS < 2 * 1000 \
|
|
||||||
? 2 * 1000 / APP_BATTERY_CHARGING_PERIODIC_MS \
|
|
||||||
: 1)
|
|
||||||
#define APP_BATTERY_CHARGING_OVERVOLT_DEDOUNCE_CNT (3)
|
#define APP_BATTERY_CHARGING_OVERVOLT_DEDOUNCE_CNT (3)
|
||||||
|
|
||||||
#define APP_BATTERY_CHARGING_SLOPE_MEASURE_CNT \
|
#define APP_BATTERY_CHARGING_SLOPE_MEASURE_CNT (APP_BATTERY_CHARGING_PERIODIC_MS<20*1000?20*1000/APP_BATTERY_CHARGING_PERIODIC_MS:1)
|
||||||
(APP_BATTERY_CHARGING_PERIODIC_MS < 20 * 1000 \
|
|
||||||
? 20 * 1000 / APP_BATTERY_CHARGING_PERIODIC_MS \
|
|
||||||
: 1)
|
|
||||||
#define APP_BATTERY_CHARGING_SLOPE_TABLE_COUNT (6)
|
#define APP_BATTERY_CHARGING_SLOPE_TABLE_COUNT (6)
|
||||||
|
|
||||||
|
|
||||||
#define APP_BATTERY_REPORT_INTERVAL (5)
|
#define APP_BATTERY_REPORT_INTERVAL (5)
|
||||||
|
|
||||||
#define APP_BATTERY_MV_BASE \
|
#define APP_BATTERY_MV_BASE ((APP_BATTERY_MAX_MV-APP_BATTERY_PD_MV)/(APP_BATTERY_LEVEL_NUM))
|
||||||
((APP_BATTERY_MAX_MV - APP_BATTERY_PD_MV) / (APP_BATTERY_LEVEL_NUM))
|
|
||||||
|
|
||||||
#define APP_BATTERY_STABLE_COUNT (5)
|
#define APP_BATTERY_STABLE_COUNT (5)
|
||||||
#define APP_BATTERY_MEASURE_PERIODIC_FAST_MS (200)
|
#define APP_BATTERY_MEASURE_PERIODIC_FAST_MS (200)
|
||||||
|
@ -107,17 +97,15 @@ extern "C" bool app_usbaudio_mode_on(void);
|
||||||
#else
|
#else
|
||||||
#define APP_BATTERY_MEASURE_PERIODIC_NORMAL_MS (10000)
|
#define APP_BATTERY_MEASURE_PERIODIC_NORMAL_MS (10000)
|
||||||
#endif
|
#endif
|
||||||
#define APP_BATTERY_CHARGING_PERIODIC_MS \
|
#define APP_BATTERY_CHARGING_PERIODIC_MS (APP_BATTERY_MEASURE_PERIODIC_NORMAL_MS)
|
||||||
(APP_BATTERY_MEASURE_PERIODIC_NORMAL_MS)
|
|
||||||
|
|
||||||
#define APP_BATTERY_SET_MESSAGE(appevt, status, volt) \
|
#define APP_BATTERY_SET_MESSAGE(appevt, status, volt) (appevt = (((uint32_t)status&0xffff)<<16)|(volt&0xffff))
|
||||||
(appevt = (((uint32_t)status & 0xffff) << 16) | (volt & 0xffff))
|
#define APP_BATTERY_GET_STATUS(appevt, status) (status = (appevt>>16)&0xffff)
|
||||||
#define APP_BATTERY_GET_STATUS(appevt, status) \
|
|
||||||
(status = (appevt >> 16) & 0xffff)
|
|
||||||
#define APP_BATTERY_GET_VOLT(appevt, volt) (volt = appevt&0xffff)
|
#define APP_BATTERY_GET_VOLT(appevt, volt) (volt = appevt&0xffff)
|
||||||
#define APP_BATTERY_GET_PRAMS(appevt, prams) ((prams) = appevt&0xffff)
|
#define APP_BATTERY_GET_PRAMS(appevt, prams) ((prams) = appevt&0xffff)
|
||||||
|
|
||||||
enum APP_BATTERY_MEASURE_PERIODIC_T {
|
enum APP_BATTERY_MEASURE_PERIODIC_T
|
||||||
|
{
|
||||||
APP_BATTERY_MEASURE_PERIODIC_FAST = 0,
|
APP_BATTERY_MEASURE_PERIODIC_FAST = 0,
|
||||||
APP_BATTERY_MEASURE_PERIODIC_NORMAL,
|
APP_BATTERY_MEASURE_PERIODIC_NORMAL,
|
||||||
APP_BATTERY_MEASURE_PERIODIC_CHARGING,
|
APP_BATTERY_MEASURE_PERIODIC_CHARGING,
|
||||||
|
@ -125,17 +113,19 @@ enum APP_BATTERY_MEASURE_PERIODIC_T {
|
||||||
APP_BATTERY_MEASURE_PERIODIC_QTY,
|
APP_BATTERY_MEASURE_PERIODIC_QTY,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct APP_BATTERY_MEASURE_CHARGER_STATUS_T {
|
struct APP_BATTERY_MEASURE_CHARGER_STATUS_T
|
||||||
|
{
|
||||||
HAL_GPADC_MV_T prevolt;
|
HAL_GPADC_MV_T prevolt;
|
||||||
int32_t slope_1000[APP_BATTERY_CHARGING_SLOPE_TABLE_COUNT];
|
int32_t slope_1000[APP_BATTERY_CHARGING_SLOPE_TABLE_COUNT];
|
||||||
int slope_1000_index;
|
int slope_1000_index;
|
||||||
int cnt;
|
int cnt;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef void (*APP_BATTERY_EVENT_CB_T)(enum APP_BATTERY_STATUS_T,
|
|
||||||
APP_BATTERY_MV_T volt);
|
|
||||||
|
|
||||||
struct APP_BATTERY_MEASURE_T {
|
typedef void (*APP_BATTERY_EVENT_CB_T)(enum APP_BATTERY_STATUS_T, APP_BATTERY_MV_T volt);
|
||||||
|
|
||||||
|
struct APP_BATTERY_MEASURE_T
|
||||||
|
{
|
||||||
uint32_t start_time;
|
uint32_t start_time;
|
||||||
enum APP_BATTERY_STATUS_T status;
|
enum APP_BATTERY_STATUS_T status;
|
||||||
#ifdef __INTERCONNECTION__
|
#ifdef __INTERCONNECTION__
|
||||||
|
@ -162,8 +152,7 @@ static enum APP_BATTERY_CHARGER_T app_battery_charger_forcegetstatus(void);
|
||||||
|
|
||||||
static void app_battery_pluginout_debounce_start(void);
|
static void app_battery_pluginout_debounce_start(void);
|
||||||
static void app_battery_pluginout_debounce_handler(void const *param);
|
static void app_battery_pluginout_debounce_handler(void const *param);
|
||||||
osTimerDef(APP_BATTERY_PLUGINOUT_DEBOUNCE,
|
osTimerDef (APP_BATTERY_PLUGINOUT_DEBOUNCE, app_battery_pluginout_debounce_handler);
|
||||||
app_battery_pluginout_debounce_handler);
|
|
||||||
static osTimerId app_battery_pluginout_debounce_timer = NULL;
|
static osTimerId app_battery_pluginout_debounce_timer = NULL;
|
||||||
static uint32_t app_battery_pluginout_debounce_ctx = 0;
|
static uint32_t app_battery_pluginout_debounce_ctx = 0;
|
||||||
static uint32_t app_battery_pluginout_debounce_cnt = 0;
|
static uint32_t app_battery_pluginout_debounce_cnt = 0;
|
||||||
|
@ -176,47 +165,59 @@ static struct APP_BATTERY_MEASURE_T app_battery_measure;
|
||||||
static int app_battery_charger_handle_process(void);
|
static int app_battery_charger_handle_process(void);
|
||||||
|
|
||||||
#ifdef __INTERCONNECTION__
|
#ifdef __INTERCONNECTION__
|
||||||
uint8_t *app_battery_get_mobile_support_self_defined_command_p(void) {
|
uint8_t* app_battery_get_mobile_support_self_defined_command_p(void)
|
||||||
|
{
|
||||||
return &app_battery_measure.isMobileSupportSelfDefinedCommand;
|
return &app_battery_measure.isMobileSupportSelfDefinedCommand;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void app_battery_irqhandler(uint16_t irq_val, HAL_GPADC_MV_T volt) {
|
|
||||||
|
void app_battery_irqhandler(uint16_t irq_val, HAL_GPADC_MV_T volt)
|
||||||
|
{
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
uint32_t meanBattVolt = 0;
|
uint32_t meanBattVolt = 0;
|
||||||
HAL_GPADC_MV_T vbat = volt;
|
HAL_GPADC_MV_T vbat = volt;
|
||||||
APP_BATTERY_TRACE(2,"%s %d",__func__, vbat);
|
APP_BATTERY_TRACE(2,"%s %d",__func__, vbat);
|
||||||
if (vbat == HAL_GPADC_BAD_VALUE) {
|
if (vbat == HAL_GPADC_BAD_VALUE)
|
||||||
|
{
|
||||||
app_battery_measure.cb(APP_BATTERY_STATUS_INVALID, vbat);
|
app_battery_measure.cb(APP_BATTERY_STATUS_INVALID, vbat);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (defined(BTUSB_AUDIO_MODE) || defined(BTUSB_AUDIO_MODE))
|
#if (defined(BTUSB_AUDIO_MODE) || defined(BTUSB_AUDIO_MODE))
|
||||||
if (app_usbaudio_mode_on())
|
if(app_usbaudio_mode_on()) return ;
|
||||||
return;
|
|
||||||
#endif
|
#endif
|
||||||
app_battery_measure
|
app_battery_measure.voltage[app_battery_measure.index++%APP_BATTERY_STABLE_COUNT] = vbat<<2;
|
||||||
.voltage[app_battery_measure.index++ % APP_BATTERY_STABLE_COUNT] = vbat
|
|
||||||
<< 2;
|
|
||||||
|
|
||||||
if (app_battery_measure.index > APP_BATTERY_STABLE_COUNT) {
|
if (app_battery_measure.index > APP_BATTERY_STABLE_COUNT)
|
||||||
for (i = 0; i < APP_BATTERY_STABLE_COUNT; i++) {
|
{
|
||||||
|
for (i=0; i<APP_BATTERY_STABLE_COUNT; i++)
|
||||||
|
{
|
||||||
meanBattVolt += app_battery_measure.voltage[i];
|
meanBattVolt += app_battery_measure.voltage[i];
|
||||||
}
|
}
|
||||||
meanBattVolt /= APP_BATTERY_STABLE_COUNT;
|
meanBattVolt /= APP_BATTERY_STABLE_COUNT;
|
||||||
if (app_battery_measure.cb) {
|
if (app_battery_measure.cb)
|
||||||
if (meanBattVolt > app_battery_measure.highvolt) {
|
{
|
||||||
|
if (meanBattVolt>app_battery_measure.highvolt)
|
||||||
|
{
|
||||||
app_battery_measure.cb(APP_BATTERY_STATUS_OVERVOLT, meanBattVolt);
|
app_battery_measure.cb(APP_BATTERY_STATUS_OVERVOLT, meanBattVolt);
|
||||||
} else if ((meanBattVolt > app_battery_measure.pdvolt) &&
|
}
|
||||||
(meanBattVolt < app_battery_measure.lowvolt)) {
|
else if((meanBattVolt>app_battery_measure.pdvolt) && (meanBattVolt<app_battery_measure.lowvolt))
|
||||||
|
{
|
||||||
app_battery_measure.cb(APP_BATTERY_STATUS_UNDERVOLT, meanBattVolt);
|
app_battery_measure.cb(APP_BATTERY_STATUS_UNDERVOLT, meanBattVolt);
|
||||||
} else if (meanBattVolt < app_battery_measure.pdvolt) {
|
}
|
||||||
|
else if(meanBattVolt<app_battery_measure.pdvolt)
|
||||||
|
{
|
||||||
app_battery_measure.cb(APP_BATTERY_STATUS_PDVOLT, meanBattVolt);
|
app_battery_measure.cb(APP_BATTERY_STATUS_PDVOLT, meanBattVolt);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
app_battery_measure.cb(APP_BATTERY_STATUS_NORMAL, meanBattVolt);
|
app_battery_measure.cb(APP_BATTERY_STATUS_NORMAL, meanBattVolt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
int8_t level = 0;
|
int8_t level = 0;
|
||||||
meanBattVolt = vbat<<2;
|
meanBattVolt = vbat<<2;
|
||||||
level = (meanBattVolt-APP_BATTERY_PD_MV)/APP_BATTERY_MV_BASE;
|
level = (meanBattVolt-APP_BATTERY_PD_MV)/APP_BATTERY_MV_BASE;
|
||||||
|
@ -228,8 +229,7 @@ void app_battery_irqhandler(uint16_t irq_val, HAL_GPADC_MV_T volt) {
|
||||||
|
|
||||||
app_battery_measure.currvolt = meanBattVolt;
|
app_battery_measure.currvolt = meanBattVolt;
|
||||||
#ifdef __INTERCONNECTION__
|
#ifdef __INTERCONNECTION__
|
||||||
APP_BATTERY_INFO_T *pBatteryInfo =
|
APP_BATTERY_INFO_T* pBatteryInfo = (APP_BATTERY_INFO_T*)&app_battery_measure.currentBatteryInfo;
|
||||||
(APP_BATTERY_INFO_T *)&app_battery_measure.currentBatteryInfo;
|
|
||||||
pBatteryInfo->batteryLevel = level;
|
pBatteryInfo->batteryLevel = level;
|
||||||
#else
|
#else
|
||||||
app_battery_measure.currlevel = level;
|
app_battery_measure.currlevel = level;
|
||||||
|
@ -237,13 +237,14 @@ void app_battery_irqhandler(uint16_t irq_val, HAL_GPADC_MV_T volt) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void app_battery_timer_start(enum APP_BATTERY_MEASURE_PERIODIC_T periodic)
|
||||||
app_battery_timer_start(enum APP_BATTERY_MEASURE_PERIODIC_T periodic) {
|
{
|
||||||
uint32_t periodic_millisec = 0;
|
uint32_t periodic_millisec = 0;
|
||||||
|
|
||||||
if (app_battery_measure.periodic != periodic){
|
if (app_battery_measure.periodic != periodic){
|
||||||
app_battery_measure.periodic = periodic;
|
app_battery_measure.periodic = periodic;
|
||||||
switch (periodic) {
|
switch (periodic)
|
||||||
|
{
|
||||||
case APP_BATTERY_MEASURE_PERIODIC_FAST:
|
case APP_BATTERY_MEASURE_PERIODIC_FAST:
|
||||||
periodic_millisec = APP_BATTERY_MEASURE_PERIODIC_FAST_MS;
|
periodic_millisec = APP_BATTERY_MEASURE_PERIODIC_FAST_MS;
|
||||||
break;
|
break;
|
||||||
|
@ -260,13 +261,13 @@ app_battery_timer_start(enum APP_BATTERY_MEASURE_PERIODIC_T periodic) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void app_battery_timer_handler(void const *param) {
|
static void app_battery_timer_handler(void const *param)
|
||||||
hal_gpadc_open(HAL_GPADC_CHAN_BATTERY, HAL_GPADC_ATP_ONESHOT,
|
{
|
||||||
app_battery_irqhandler);
|
hal_gpadc_open(HAL_GPADC_CHAN_BATTERY, HAL_GPADC_ATP_ONESHOT, app_battery_irqhandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void app_battery_event_process(enum APP_BATTERY_STATUS_T status,
|
static void app_battery_event_process(enum APP_BATTERY_STATUS_T status, APP_BATTERY_MV_T volt)
|
||||||
APP_BATTERY_MV_T volt) {
|
{
|
||||||
uint32_t app_battevt;
|
uint32_t app_battevt;
|
||||||
APP_MESSAGE_BLOCK msg;
|
APP_MESSAGE_BLOCK msg;
|
||||||
|
|
||||||
|
@ -276,13 +277,15 @@ static void app_battery_event_process(enum APP_BATTERY_STATUS_T status,
|
||||||
msg.msg_body.message_id = app_battevt;
|
msg.msg_body.message_id = app_battevt;
|
||||||
msg.msg_body.message_ptr = (uint32_t)NULL;
|
msg.msg_body.message_ptr = (uint32_t)NULL;
|
||||||
app_mailbox_put(&msg);
|
app_mailbox_put(&msg);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_battery_handle_process_normal(uint32_t status,
|
int app_battery_handle_process_normal(uint32_t status, union APP_BATTERY_MSG_PRAMS prams)
|
||||||
union APP_BATTERY_MSG_PRAMS prams) {
|
{
|
||||||
int8_t level = 0;
|
int8_t level = 0;
|
||||||
|
|
||||||
switch (status) {
|
switch (status)
|
||||||
|
{
|
||||||
case APP_BATTERY_STATUS_UNDERVOLT:
|
case APP_BATTERY_STATUS_UNDERVOLT:
|
||||||
TRACE(1,"UNDERVOLT:%d", prams.volt);
|
TRACE(1,"UNDERVOLT:%d", prams.volt);
|
||||||
app_status_indication_set(APP_STATUS_INDICATION_CHARGENEED);
|
app_status_indication_set(APP_STATUS_INDICATION_CHARGENEED);
|
||||||
|
@ -304,12 +307,14 @@ int app_battery_handle_process_normal(uint32_t status,
|
||||||
level = APP_BATTERY_LEVEL_MAX;
|
level = APP_BATTERY_LEVEL_MAX;
|
||||||
#ifdef __INTERCONNECTION__
|
#ifdef __INTERCONNECTION__
|
||||||
APP_BATTERY_INFO_T* pBatteryInfo;
|
APP_BATTERY_INFO_T* pBatteryInfo;
|
||||||
pBatteryInfo =
|
pBatteryInfo = (APP_BATTERY_INFO_T*)&app_battery_measure.currentBatteryInfo;
|
||||||
(APP_BATTERY_INFO_T *)&app_battery_measure.currentBatteryInfo;
|
|
||||||
pBatteryInfo->batteryLevel = level;
|
pBatteryInfo->batteryLevel = level;
|
||||||
if (level == APP_BATTERY_LEVEL_MAX) {
|
if(level == APP_BATTERY_LEVEL_MAX)
|
||||||
|
{
|
||||||
level = 9;
|
level = 9;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
level /= 10;
|
level /= 10;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -326,7 +331,8 @@ int app_battery_handle_process_normal(uint32_t status,
|
||||||
break;
|
break;
|
||||||
case APP_BATTERY_STATUS_CHARGING:
|
case APP_BATTERY_STATUS_CHARGING:
|
||||||
TRACE(1,"CHARGING-->APP_BATTERY_CHARGER :%d", prams.charger);
|
TRACE(1,"CHARGING-->APP_BATTERY_CHARGER :%d", prams.charger);
|
||||||
if (prams.charger == APP_BATTERY_CHARGER_PLUGIN) {
|
if (prams.charger == APP_BATTERY_CHARGER_PLUGIN)
|
||||||
|
{
|
||||||
#ifdef BT_USB_AUDIO_DUAL_MODE
|
#ifdef BT_USB_AUDIO_DUAL_MODE
|
||||||
TRACE(1,"%s:PLUGIN.", __func__);
|
TRACE(1,"%s:PLUGIN.", __func__);
|
||||||
btusb_switch(BTUSB_MODE_USB);
|
btusb_switch(BTUSB_MODE_USB);
|
||||||
|
@ -350,9 +356,10 @@ int app_battery_handle_process_normal(uint32_t status,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_battery_handle_process_charging(uint32_t status,
|
int app_battery_handle_process_charging(uint32_t status, union APP_BATTERY_MSG_PRAMS prams)
|
||||||
union APP_BATTERY_MSG_PRAMS prams) {
|
{
|
||||||
switch (status) {
|
switch (status)
|
||||||
|
{
|
||||||
case APP_BATTERY_STATUS_OVERVOLT:
|
case APP_BATTERY_STATUS_OVERVOLT:
|
||||||
case APP_BATTERY_STATUS_NORMAL:
|
case APP_BATTERY_STATUS_NORMAL:
|
||||||
case APP_BATTERY_STATUS_UNDERVOLT:
|
case APP_BATTERY_STATUS_UNDERVOLT:
|
||||||
|
@ -361,7 +368,8 @@ int app_battery_handle_process_charging(uint32_t status,
|
||||||
break;
|
break;
|
||||||
case APP_BATTERY_STATUS_CHARGING:
|
case APP_BATTERY_STATUS_CHARGING:
|
||||||
TRACE(1,"CHARGING:%d", prams.charger);
|
TRACE(1,"CHARGING:%d", prams.charger);
|
||||||
if (prams.charger == APP_BATTERY_CHARGER_PLUGOUT) {
|
if (prams.charger == APP_BATTERY_CHARGER_PLUGOUT)
|
||||||
|
{
|
||||||
#ifdef BT_USB_AUDIO_DUAL_MODE
|
#ifdef BT_USB_AUDIO_DUAL_MODE
|
||||||
TRACE(1,"%s:PlUGOUT.", __func__);
|
TRACE(1,"%s:PlUGOUT.", __func__);
|
||||||
btusb_switch(BTUSB_MODE_BT);
|
btusb_switch(BTUSB_MODE_BT);
|
||||||
|
@ -373,7 +381,9 @@ int app_battery_handle_process_charging(uint32_t status,
|
||||||
app_battery_measure.status = APP_BATTERY_STATUS_NORMAL;
|
app_battery_measure.status = APP_BATTERY_STATUS_NORMAL;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
} else if (prams.charger == APP_BATTERY_CHARGER_PLUGIN) {
|
}
|
||||||
|
else if (prams.charger == APP_BATTERY_CHARGER_PLUGIN)
|
||||||
|
{
|
||||||
#ifdef BT_USB_AUDIO_DUAL_MODE
|
#ifdef BT_USB_AUDIO_DUAL_MODE
|
||||||
TRACE(1,"%s:PLUGIN.", __func__);
|
TRACE(1,"%s:PLUGIN.", __func__);
|
||||||
btusb_switch(BTUSB_MODE_USB);
|
btusb_switch(BTUSB_MODE_USB);
|
||||||
|
@ -385,8 +395,10 @@ int app_battery_handle_process_charging(uint32_t status,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (app_battery_charger_handle_process() <= 0) {
|
if (app_battery_charger_handle_process()<=0)
|
||||||
if (app_status_indication_get() != APP_STATUS_INDICATION_FULLCHARGE) {
|
{
|
||||||
|
if (app_status_indication_get() != APP_STATUS_INDICATION_FULLCHARGE)
|
||||||
|
{
|
||||||
TRACE(1,"FULL_CHARGING:%d", app_battery_measure.currvolt);
|
TRACE(1,"FULL_CHARGING:%d", app_battery_measure.currvolt);
|
||||||
app_status_indication_set(APP_STATUS_INDICATION_FULLCHARGE);
|
app_status_indication_set(APP_STATUS_INDICATION_FULLCHARGE);
|
||||||
app_shutdown();
|
app_shutdown();
|
||||||
|
@ -404,7 +416,8 @@ int app_battery_handle_process_charging(uint32_t status,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int app_battery_handle_process(APP_MESSAGE_BODY *msg_body) {
|
static int app_battery_handle_process(APP_MESSAGE_BODY *msg_body)
|
||||||
|
{
|
||||||
uint8_t status;
|
uint8_t status;
|
||||||
union APP_BATTERY_MSG_PRAMS msg_prams;
|
union APP_BATTERY_MSG_PRAMS msg_prams;
|
||||||
|
|
||||||
|
@ -412,16 +425,19 @@ static int app_battery_handle_process(APP_MESSAGE_BODY *msg_body) {
|
||||||
APP_BATTERY_GET_PRAMS(msg_body->message_id, msg_prams.prams);
|
APP_BATTERY_GET_PRAMS(msg_body->message_id, msg_prams.prams);
|
||||||
|
|
||||||
uint32_t generatedSeed = hal_sys_timer_get();
|
uint32_t generatedSeed = hal_sys_timer_get();
|
||||||
for (uint8_t index = 0; index < sizeof(bt_addr); index++) {
|
for (uint8_t index = 0; index < sizeof(bt_addr); index++)
|
||||||
generatedSeed ^=
|
{
|
||||||
(((uint32_t)(bt_addr[index])) << (hal_sys_timer_get() & 0xF));
|
generatedSeed ^= (((uint32_t)(bt_addr[index])) << (hal_sys_timer_get()&0xF));
|
||||||
}
|
}
|
||||||
srand(generatedSeed);
|
srand(generatedSeed);
|
||||||
|
|
||||||
if (status == APP_BATTERY_STATUS_PLUGINOUT){
|
if (status == APP_BATTERY_STATUS_PLUGINOUT){
|
||||||
app_battery_pluginout_debounce_start();
|
app_battery_pluginout_debounce_start();
|
||||||
} else {
|
}
|
||||||
switch (app_battery_measure.status) {
|
else
|
||||||
|
{
|
||||||
|
switch (app_battery_measure.status)
|
||||||
|
{
|
||||||
case APP_BATTERY_STATUS_NORMAL:
|
case APP_BATTERY_STATUS_NORMAL:
|
||||||
app_battery_handle_process_normal((uint32_t)status, msg_prams);
|
app_battery_handle_process_normal((uint32_t)status, msg_prams);
|
||||||
break;
|
break;
|
||||||
|
@ -434,41 +450,44 @@ static int app_battery_handle_process(APP_MESSAGE_BODY *msg_body) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (NULL != app_battery_measure.user_cb) {
|
if (NULL != app_battery_measure.user_cb)
|
||||||
|
{
|
||||||
uint8_t batteryLevel;
|
uint8_t batteryLevel;
|
||||||
#ifdef __INTERCONNECTION__
|
#ifdef __INTERCONNECTION__
|
||||||
APP_BATTERY_INFO_T* pBatteryInfo;
|
APP_BATTERY_INFO_T* pBatteryInfo;
|
||||||
pBatteryInfo =
|
pBatteryInfo = (APP_BATTERY_INFO_T*)&app_battery_measure.currentBatteryInfo;
|
||||||
(APP_BATTERY_INFO_T *)&app_battery_measure.currentBatteryInfo;
|
pBatteryInfo->chargingStatus = ((app_battery_measure.status == APP_BATTERY_STATUS_CHARGING)? 1:0);
|
||||||
pBatteryInfo->chargingStatus =
|
|
||||||
((app_battery_measure.status == APP_BATTERY_STATUS_CHARGING) ? 1 : 0);
|
|
||||||
batteryLevel = pBatteryInfo->batteryLevel;
|
batteryLevel = pBatteryInfo->batteryLevel;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
batteryLevel = app_battery_measure.currlevel;
|
batteryLevel = app_battery_measure.currlevel;
|
||||||
#endif
|
#endif
|
||||||
app_battery_measure.user_cb(app_battery_measure.currvolt, batteryLevel,
|
app_battery_measure.user_cb(app_battery_measure.currvolt,
|
||||||
app_battery_measure.status, status, msg_prams);
|
batteryLevel, app_battery_measure.status,status,msg_prams);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_battery_register(APP_BATTERY_CB_T user_cb) {
|
int app_battery_register(APP_BATTERY_CB_T user_cb)
|
||||||
if (NULL == app_battery_measure.user_cb) {
|
{
|
||||||
|
if(NULL == app_battery_measure.user_cb)
|
||||||
|
{
|
||||||
app_battery_measure.user_cb = user_cb;
|
app_battery_measure.user_cb = user_cb;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_battery_get_info(APP_BATTERY_MV_T *currvolt, uint8_t *currlevel,
|
int app_battery_get_info(APP_BATTERY_MV_T *currvolt, uint8_t *currlevel, enum APP_BATTERY_STATUS_T *status)
|
||||||
enum APP_BATTERY_STATUS_T *status) {
|
{
|
||||||
if (currvolt) {
|
if (currvolt)
|
||||||
|
{
|
||||||
*currvolt = app_battery_measure.currvolt;
|
*currvolt = app_battery_measure.currvolt;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currlevel) {
|
if (currlevel)
|
||||||
|
{
|
||||||
#ifdef __INTERCONNECTION__
|
#ifdef __INTERCONNECTION__
|
||||||
*currlevel = app_battery_measure.currentBatteryInfo;
|
*currlevel = app_battery_measure.currentBatteryInfo;
|
||||||
#else
|
#else
|
||||||
|
@ -476,26 +495,24 @@ int app_battery_get_info(APP_BATTERY_MV_T *currvolt, uint8_t *currlevel,
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status) {
|
if (status)
|
||||||
|
{
|
||||||
*status = app_battery_measure.status;
|
*status = app_battery_measure.status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_battery_open(void) {
|
int app_battery_open(void)
|
||||||
APP_BATTERY_TRACE(3, "%s batt range:%d~%d", __func__, APP_BATTERY_MIN_MV,
|
{
|
||||||
APP_BATTERY_MAX_MV);
|
APP_BATTERY_TRACE(3,"%s batt range:%d~%d",__func__, APP_BATTERY_MIN_MV, APP_BATTERY_MAX_MV);
|
||||||
int nRet = APP_BATTERY_OPEN_MODE_INVALID;
|
int nRet = APP_BATTERY_OPEN_MODE_INVALID;
|
||||||
|
|
||||||
if (app_battery_timer == NULL)
|
if (app_battery_timer == NULL)
|
||||||
app_battery_timer =
|
app_battery_timer = osTimerCreate (osTimer(APP_BATTERY), osTimerPeriodic, NULL);
|
||||||
osTimerCreate(osTimer(APP_BATTERY), osTimerPeriodic, NULL);
|
|
||||||
|
|
||||||
if (app_battery_pluginout_debounce_timer == NULL)
|
if (app_battery_pluginout_debounce_timer == NULL)
|
||||||
app_battery_pluginout_debounce_timer =
|
app_battery_pluginout_debounce_timer = osTimerCreate (osTimer(APP_BATTERY_PLUGINOUT_DEBOUNCE), osTimerOnce, &app_battery_pluginout_debounce_ctx);
|
||||||
osTimerCreate(osTimer(APP_BATTERY_PLUGINOUT_DEBOUNCE), osTimerOnce,
|
|
||||||
&app_battery_pluginout_debounce_ctx);
|
|
||||||
|
|
||||||
app_battery_measure.status = APP_BATTERY_STATUS_NORMAL;
|
app_battery_measure.status = APP_BATTERY_STATUS_NORMAL;
|
||||||
#ifdef __INTERCONNECTION__
|
#ifdef __INTERCONNECTION__
|
||||||
|
@ -521,32 +538,26 @@ int app_battery_open(void) {
|
||||||
|
|
||||||
app_set_threadhandle(APP_MODUAL_BATTERY, app_battery_handle_process);
|
app_set_threadhandle(APP_MODUAL_BATTERY, app_battery_handle_process);
|
||||||
|
|
||||||
if (app_battery_ext_charger_detecter_cfg.pin != HAL_IOMUX_PIN_NUM) {
|
if (app_battery_ext_charger_detecter_cfg.pin != HAL_IOMUX_PIN_NUM)
|
||||||
hal_iomux_init((struct HAL_IOMUX_PIN_FUNCTION_MAP
|
{
|
||||||
*)&app_battery_ext_charger_detecter_cfg,
|
hal_iomux_init((struct HAL_IOMUX_PIN_FUNCTION_MAP *)&app_battery_ext_charger_detecter_cfg, 1);
|
||||||
1);
|
hal_gpio_pin_set_dir((enum HAL_GPIO_PIN_T)app_battery_ext_charger_detecter_cfg.pin, HAL_GPIO_DIR_IN, 1);
|
||||||
hal_gpio_pin_set_dir(
|
|
||||||
(enum HAL_GPIO_PIN_T)app_battery_ext_charger_detecter_cfg.pin,
|
|
||||||
HAL_GPIO_DIR_IN, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (app_battery_ext_charger_enable_cfg.pin != HAL_IOMUX_PIN_NUM) {
|
if (app_battery_ext_charger_enable_cfg.pin != HAL_IOMUX_PIN_NUM)
|
||||||
hal_iomux_init((struct HAL_IOMUX_PIN_FUNCTION_MAP
|
{
|
||||||
*)&app_battery_ext_charger_detecter_cfg,
|
hal_iomux_init((struct HAL_IOMUX_PIN_FUNCTION_MAP *)&app_battery_ext_charger_detecter_cfg, 1);
|
||||||
1);
|
hal_gpio_pin_set_dir((enum HAL_GPIO_PIN_T)app_battery_ext_charger_detecter_cfg.pin, HAL_GPIO_DIR_OUT, 1);
|
||||||
hal_gpio_pin_set_dir(
|
|
||||||
(enum HAL_GPIO_PIN_T)app_battery_ext_charger_detecter_cfg.pin,
|
|
||||||
HAL_GPIO_DIR_OUT, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (app_battery_charger_indication_open() == APP_BATTERY_CHARGER_PLUGIN) {
|
if (app_battery_charger_indication_open() == APP_BATTERY_CHARGER_PLUGIN)
|
||||||
|
{
|
||||||
app_battery_measure.status = APP_BATTERY_STATUS_CHARGING;
|
app_battery_measure.status = APP_BATTERY_STATUS_CHARGING;
|
||||||
app_battery_measure.start_time = hal_sys_timer_get();
|
app_battery_measure.start_time = hal_sys_timer_get();
|
||||||
//pmu_charger_plugin_config();
|
//pmu_charger_plugin_config();
|
||||||
if (app_battery_ext_charger_enable_cfg.pin != HAL_IOMUX_PIN_NUM) {
|
if (app_battery_ext_charger_enable_cfg.pin != HAL_IOMUX_PIN_NUM)
|
||||||
hal_gpio_pin_set_dir(
|
{
|
||||||
(enum HAL_GPIO_PIN_T)app_battery_ext_charger_detecter_cfg.pin,
|
hal_gpio_pin_set_dir((enum HAL_GPIO_PIN_T)app_battery_ext_charger_detecter_cfg.pin, HAL_GPIO_DIR_OUT, 0);
|
||||||
HAL_GPIO_DIR_OUT, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (CHARGER_PLUGINOUT_RESET == 0)
|
#if (CHARGER_PLUGINOUT_RESET == 0)
|
||||||
|
@ -554,7 +565,9 @@ int app_battery_open(void) {
|
||||||
#else
|
#else
|
||||||
nRet = APP_BATTERY_OPEN_MODE_CHARGING;
|
nRet = APP_BATTERY_OPEN_MODE_CHARGING;
|
||||||
#endif
|
#endif
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
app_battery_measure.status = APP_BATTERY_STATUS_NORMAL;
|
app_battery_measure.status = APP_BATTERY_STATUS_NORMAL;
|
||||||
//pmu_charger_plugout_config();
|
//pmu_charger_plugout_config();
|
||||||
nRet = APP_BATTERY_OPEN_MODE_NORMAL;
|
nRet = APP_BATTERY_OPEN_MODE_NORMAL;
|
||||||
|
@ -562,7 +575,8 @@ int app_battery_open(void) {
|
||||||
return nRet;
|
return nRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_battery_start(void) {
|
int app_battery_start(void)
|
||||||
|
{
|
||||||
APP_BATTERY_TRACE(2,"%s %d",__func__, APP_BATTERY_MEASURE_PERIODIC_FAST_MS);
|
APP_BATTERY_TRACE(2,"%s %d",__func__, APP_BATTERY_MEASURE_PERIODIC_FAST_MS);
|
||||||
|
|
||||||
app_battery_timer_start(APP_BATTERY_MEASURE_PERIODIC_FAST);
|
app_battery_timer_start(APP_BATTERY_MEASURE_PERIODIC_FAST);
|
||||||
|
@ -570,26 +584,30 @@ int app_battery_start(void) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_battery_stop(void) {
|
int app_battery_stop(void)
|
||||||
|
{
|
||||||
osTimerStop(app_battery_timer);
|
osTimerStop(app_battery_timer);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_battery_close(void) {
|
int app_battery_close(void)
|
||||||
|
{
|
||||||
hal_gpadc_close(HAL_GPADC_CHAN_BATTERY);
|
hal_gpadc_close(HAL_GPADC_CHAN_BATTERY);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t app_battery_charger_slope_calc(int32_t t1, int32_t v1,
|
|
||||||
int32_t t2, int32_t v2) {
|
static int32_t app_battery_charger_slope_calc(int32_t t1, int32_t v1, int32_t t2, int32_t v2)
|
||||||
|
{
|
||||||
int32_t slope_1000;
|
int32_t slope_1000;
|
||||||
slope_1000 = (v2-v1)*1000/(t2-t1);
|
slope_1000 = (v2-v1)*1000/(t2-t1);
|
||||||
return slope_1000;
|
return slope_1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int app_battery_charger_handle_process(void) {
|
static int app_battery_charger_handle_process(void)
|
||||||
|
{
|
||||||
int nRet = 1;
|
int nRet = 1;
|
||||||
int8_t i=0,cnt=0;
|
int8_t i=0,cnt=0;
|
||||||
uint32_t slope_1000 = 0;
|
uint32_t slope_1000 = 0;
|
||||||
|
@ -599,38 +617,45 @@ static int app_battery_charger_handle_process(void) {
|
||||||
|
|
||||||
charging_min = hal_sys_timer_get() - app_battery_measure.start_time;
|
charging_min = hal_sys_timer_get() - app_battery_measure.start_time;
|
||||||
charging_min = TICKS_TO_MS(charging_min)/1000/60;
|
charging_min = TICKS_TO_MS(charging_min)/1000/60;
|
||||||
if (charging_min >= app_battery_measure.chargetimeout) {
|
if (charging_min >= app_battery_measure.chargetimeout)
|
||||||
|
{
|
||||||
// TRACE(0,"TIMEROUT-->FULL_CHARGING");
|
// TRACE(0,"TIMEROUT-->FULL_CHARGING");
|
||||||
nRet = -1;
|
nRet = -1;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((app_battery_measure.charger_status.cnt++ %
|
if ((app_battery_measure.charger_status.cnt++%APP_BATTERY_CHARGING_OVERVOLT_MEASURE_CNT) == 0)
|
||||||
APP_BATTERY_CHARGING_OVERVOLT_MEASURE_CNT) == 0) {
|
{
|
||||||
if (app_battery_measure.currvolt >=
|
if (app_battery_measure.currvolt>=(app_battery_measure.highvolt+APP_BATTERY_CHARGE_OFFSET_MV))
|
||||||
(app_battery_measure.highvolt + APP_BATTERY_CHARGE_OFFSET_MV)) {
|
{
|
||||||
overvolt_full_charge_cnt++;
|
overvolt_full_charge_cnt++;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
overvolt_full_charge_cnt = 0;
|
overvolt_full_charge_cnt = 0;
|
||||||
}
|
}
|
||||||
if (overvolt_full_charge_cnt >=
|
if (overvolt_full_charge_cnt>=APP_BATTERY_CHARGING_OVERVOLT_DEDOUNCE_CNT)
|
||||||
APP_BATTERY_CHARGING_OVERVOLT_DEDOUNCE_CNT) {
|
{
|
||||||
//TRACE(0,"OVERVOLT-->FULL_CHARGING");
|
//TRACE(0,"OVERVOLT-->FULL_CHARGING");
|
||||||
nRet = -1;
|
nRet = -1;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((app_battery_measure.charger_status.cnt++ %
|
if ((app_battery_measure.charger_status.cnt++%APP_BATTERY_CHARGING_EXTPIN_MEASURE_CNT) == 0)
|
||||||
APP_BATTERY_CHARGING_EXTPIN_MEASURE_CNT) == 0) {
|
{
|
||||||
if (app_battery_ext_charger_detecter_cfg.pin != HAL_IOMUX_PIN_NUM) {
|
if (app_battery_ext_charger_detecter_cfg.pin != HAL_IOMUX_PIN_NUM)
|
||||||
if (hal_gpio_pin_get_val(
|
{
|
||||||
(enum HAL_GPIO_PIN_T)app_battery_ext_charger_detecter_cfg.pin)) {
|
if (hal_gpio_pin_get_val((enum HAL_GPIO_PIN_T)app_battery_ext_charger_detecter_cfg.pin))
|
||||||
|
{
|
||||||
ext_pin_full_charge_cnt++;
|
ext_pin_full_charge_cnt++;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
ext_pin_full_charge_cnt = 0;
|
ext_pin_full_charge_cnt = 0;
|
||||||
}
|
}
|
||||||
if (ext_pin_full_charge_cnt >= APP_BATTERY_CHARGING_EXTPIN_DEDOUNCE_CNT) {
|
if (ext_pin_full_charge_cnt>=APP_BATTERY_CHARGING_EXTPIN_DEDOUNCE_CNT)
|
||||||
|
{
|
||||||
TRACE(0,"EXT PIN-->FULL_CHARGING");
|
TRACE(0,"EXT PIN-->FULL_CHARGING");
|
||||||
nRet = -1;
|
nRet = -1;
|
||||||
goto exit;
|
goto exit;
|
||||||
|
@ -638,44 +663,41 @@ static int app_battery_charger_handle_process(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((app_battery_measure.charger_status.cnt++ %
|
if ((app_battery_measure.charger_status.cnt++%APP_BATTERY_CHARGING_SLOPE_MEASURE_CNT) == 0)
|
||||||
APP_BATTERY_CHARGING_SLOPE_MEASURE_CNT) == 0) {
|
{
|
||||||
if (!app_battery_measure.charger_status.prevolt) {
|
if (!app_battery_measure.charger_status.prevolt)
|
||||||
app_battery_measure.charger_status
|
{
|
||||||
.slope_1000[app_battery_measure.charger_status.slope_1000_index %
|
app_battery_measure.charger_status.slope_1000[app_battery_measure.charger_status.slope_1000_index%APP_BATTERY_CHARGING_SLOPE_TABLE_COUNT] = slope_1000;
|
||||||
APP_BATTERY_CHARGING_SLOPE_TABLE_COUNT] = slope_1000;
|
|
||||||
app_battery_measure.charger_status.prevolt = app_battery_measure.currvolt;
|
app_battery_measure.charger_status.prevolt = app_battery_measure.currvolt;
|
||||||
for (i = 0; i < APP_BATTERY_CHARGING_SLOPE_TABLE_COUNT; i++) {
|
for (i=0; i<APP_BATTERY_CHARGING_SLOPE_TABLE_COUNT; i++)
|
||||||
|
{
|
||||||
app_battery_measure.charger_status.slope_1000[i]=100;
|
app_battery_measure.charger_status.slope_1000[i]=100;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
slope_1000 = app_battery_charger_slope_calc(
|
else
|
||||||
0, app_battery_measure.charger_status.prevolt,
|
{
|
||||||
APP_BATTERY_CHARGING_PERIODIC_MS *
|
slope_1000 = app_battery_charger_slope_calc(0, app_battery_measure.charger_status.prevolt,
|
||||||
APP_BATTERY_CHARGING_SLOPE_MEASURE_CNT / 1000,
|
APP_BATTERY_CHARGING_PERIODIC_MS*APP_BATTERY_CHARGING_SLOPE_MEASURE_CNT/1000, app_battery_measure.currvolt);
|
||||||
app_battery_measure.currvolt);
|
app_battery_measure.charger_status.slope_1000[app_battery_measure.charger_status.slope_1000_index%APP_BATTERY_CHARGING_SLOPE_TABLE_COUNT] = slope_1000;
|
||||||
app_battery_measure.charger_status
|
|
||||||
.slope_1000[app_battery_measure.charger_status.slope_1000_index %
|
|
||||||
APP_BATTERY_CHARGING_SLOPE_TABLE_COUNT] = slope_1000;
|
|
||||||
app_battery_measure.charger_status.prevolt = app_battery_measure.currvolt;
|
app_battery_measure.charger_status.prevolt = app_battery_measure.currvolt;
|
||||||
for (i = 0; i < APP_BATTERY_CHARGING_SLOPE_TABLE_COUNT; i++) {
|
for (i=0; i<APP_BATTERY_CHARGING_SLOPE_TABLE_COUNT; i++)
|
||||||
|
{
|
||||||
if (app_battery_measure.charger_status.slope_1000[i]>0)
|
if (app_battery_measure.charger_status.slope_1000[i]>0)
|
||||||
cnt++;
|
cnt++;
|
||||||
else
|
else
|
||||||
cnt--;
|
cnt--;
|
||||||
TRACE(3, "slope_1000[%d]=%d cnt:%d", i,
|
TRACE(3,"slope_1000[%d]=%d cnt:%d", i,app_battery_measure.charger_status.slope_1000[i], cnt);
|
||||||
app_battery_measure.charger_status.slope_1000[i], cnt);
|
|
||||||
}
|
}
|
||||||
TRACE(3, "app_battery_charger_slope_proc slope*1000=%d cnt:%d nRet:%d",
|
TRACE(3,"app_battery_charger_slope_proc slope*1000=%d cnt:%d nRet:%d", slope_1000, cnt, nRet);
|
||||||
slope_1000, cnt, nRet);
|
if (cnt>1)
|
||||||
if (cnt > 1) {
|
{
|
||||||
nRet = 1;
|
nRet = 1;
|
||||||
}/*else (3>=cnt && cnt>=-3){
|
}/*else (3>=cnt && cnt>=-3){
|
||||||
nRet = 0;
|
nRet = 0;
|
||||||
}*/
|
}*/else
|
||||||
else {
|
{
|
||||||
if (app_battery_measure.currvolt >=
|
if (app_battery_measure.currvolt>=(app_battery_measure.highvolt-APP_BATTERY_CHARGE_OFFSET_MV))
|
||||||
(app_battery_measure.highvolt - APP_BATTERY_CHARGE_OFFSET_MV)) {
|
{
|
||||||
TRACE(0,"SLOPE-->FULL_CHARGING");
|
TRACE(0,"SLOPE-->FULL_CHARGING");
|
||||||
nRet = -1;
|
nRet = -1;
|
||||||
}
|
}
|
||||||
|
@ -687,16 +709,20 @@ exit:
|
||||||
return nRet;
|
return nRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum APP_BATTERY_CHARGER_T app_battery_charger_forcegetstatus(void) {
|
static enum APP_BATTERY_CHARGER_T app_battery_charger_forcegetstatus(void)
|
||||||
|
{
|
||||||
enum APP_BATTERY_CHARGER_T status = APP_BATTERY_CHARGER_QTY;
|
enum APP_BATTERY_CHARGER_T status = APP_BATTERY_CHARGER_QTY;
|
||||||
enum PMU_CHARGER_STATUS_T charger;
|
enum PMU_CHARGER_STATUS_T charger;
|
||||||
|
|
||||||
charger = pmu_charger_get_status();
|
charger = pmu_charger_get_status();
|
||||||
|
|
||||||
if (charger == PMU_CHARGER_PLUGIN) {
|
if (charger == PMU_CHARGER_PLUGIN)
|
||||||
|
{
|
||||||
status = APP_BATTERY_CHARGER_PLUGIN;
|
status = APP_BATTERY_CHARGER_PLUGIN;
|
||||||
// TRACE(0,"force APP_BATTERY_CHARGER_PLUGIN");
|
// TRACE(0,"force APP_BATTERY_CHARGER_PLUGIN");
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
status = APP_BATTERY_CHARGER_PLUGOUT;
|
status = APP_BATTERY_CHARGER_PLUGOUT;
|
||||||
// TRACE(0,"force APP_BATTERY_CHARGER_PLUGOUT");
|
// TRACE(0,"force APP_BATTERY_CHARGER_PLUGOUT");
|
||||||
}
|
}
|
||||||
|
@ -704,64 +730,63 @@ static enum APP_BATTERY_CHARGER_T app_battery_charger_forcegetstatus(void) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void app_battery_charger_handler(enum PMU_CHARGER_STATUS_T status) {
|
static void app_battery_charger_handler(enum PMU_CHARGER_STATUS_T status)
|
||||||
|
{
|
||||||
TRACE(2,"%s: status=%d", __func__, status);
|
TRACE(2,"%s: status=%d", __func__, status);
|
||||||
pmu_charger_set_irq_handler(NULL);
|
pmu_charger_set_irq_handler(NULL);
|
||||||
app_battery_event_process(APP_BATTERY_STATUS_PLUGINOUT,
|
app_battery_event_process(APP_BATTERY_STATUS_PLUGINOUT,
|
||||||
(status == PMU_CHARGER_PLUGIN)
|
(status == PMU_CHARGER_PLUGIN) ? APP_BATTERY_CHARGER_PLUGIN : APP_BATTERY_CHARGER_PLUGOUT);
|
||||||
? APP_BATTERY_CHARGER_PLUGIN
|
|
||||||
: APP_BATTERY_CHARGER_PLUGOUT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void app_battery_pluginout_debounce_start(void) {
|
static void app_battery_pluginout_debounce_start(void)
|
||||||
|
{
|
||||||
TRACE(1,"%s", __func__);
|
TRACE(1,"%s", __func__);
|
||||||
app_battery_pluginout_debounce_ctx =
|
app_battery_pluginout_debounce_ctx = (uint32_t)app_battery_charger_forcegetstatus();
|
||||||
(uint32_t)app_battery_charger_forcegetstatus();
|
|
||||||
app_battery_pluginout_debounce_cnt = 1;
|
app_battery_pluginout_debounce_cnt = 1;
|
||||||
osTimerStart(app_battery_pluginout_debounce_timer,
|
osTimerStart(app_battery_pluginout_debounce_timer, CHARGER_PLUGINOUT_DEBOUNCE_MS);
|
||||||
CHARGER_PLUGINOUT_DEBOUNCE_MS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void app_battery_pluginout_debounce_handler(void const *param) {
|
static void app_battery_pluginout_debounce_handler(void const *param)
|
||||||
enum APP_BATTERY_CHARGER_T status_charger =
|
{
|
||||||
app_battery_charger_forcegetstatus();
|
enum APP_BATTERY_CHARGER_T status_charger = app_battery_charger_forcegetstatus();
|
||||||
|
|
||||||
if(app_battery_pluginout_debounce_ctx == (uint32_t) status_charger){
|
if(app_battery_pluginout_debounce_ctx == (uint32_t) status_charger){
|
||||||
app_battery_pluginout_debounce_cnt++;
|
app_battery_pluginout_debounce_cnt++;
|
||||||
} else {
|
}
|
||||||
TRACE(2, "%s dithering cnt %u", __func__,
|
else
|
||||||
app_battery_pluginout_debounce_cnt);
|
{
|
||||||
|
TRACE(2,"%s dithering cnt %u", __func__, app_battery_pluginout_debounce_cnt);
|
||||||
app_battery_pluginout_debounce_cnt = 0;
|
app_battery_pluginout_debounce_cnt = 0;
|
||||||
app_battery_pluginout_debounce_ctx = (uint32_t)status_charger;
|
app_battery_pluginout_debounce_ctx = (uint32_t)status_charger;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (app_battery_pluginout_debounce_cnt >= CHARGER_PLUGINOUT_DEBOUNCE_CNT){
|
if (app_battery_pluginout_debounce_cnt >= CHARGER_PLUGINOUT_DEBOUNCE_CNT){
|
||||||
TRACE(2, "%s %s", __func__,
|
TRACE(2,"%s %s", __func__, status_charger == APP_BATTERY_CHARGER_PLUGOUT ? "PLUGOUT" : "PLUGIN");
|
||||||
status_charger == APP_BATTERY_CHARGER_PLUGOUT ? "PLUGOUT" : "PLUGIN");
|
if (status_charger == APP_BATTERY_CHARGER_PLUGIN)
|
||||||
if (status_charger == APP_BATTERY_CHARGER_PLUGIN) {
|
{
|
||||||
if (app_battery_ext_charger_enable_cfg.pin != HAL_IOMUX_PIN_NUM) {
|
if (app_battery_ext_charger_enable_cfg.pin != HAL_IOMUX_PIN_NUM)
|
||||||
hal_gpio_pin_set_dir(
|
{
|
||||||
(enum HAL_GPIO_PIN_T)app_battery_ext_charger_detecter_cfg.pin,
|
hal_gpio_pin_set_dir((enum HAL_GPIO_PIN_T)app_battery_ext_charger_detecter_cfg.pin, HAL_GPIO_DIR_OUT, 0);
|
||||||
HAL_GPIO_DIR_OUT, 0);
|
|
||||||
}
|
}
|
||||||
app_battery_measure.start_time = hal_sys_timer_get();
|
app_battery_measure.start_time = hal_sys_timer_get();
|
||||||
} else {
|
}
|
||||||
if (app_battery_ext_charger_enable_cfg.pin != HAL_IOMUX_PIN_NUM) {
|
else
|
||||||
hal_gpio_pin_set_dir(
|
{
|
||||||
(enum HAL_GPIO_PIN_T)app_battery_ext_charger_detecter_cfg.pin,
|
if (app_battery_ext_charger_enable_cfg.pin != HAL_IOMUX_PIN_NUM)
|
||||||
HAL_GPIO_DIR_OUT, 1);
|
{
|
||||||
|
hal_gpio_pin_set_dir((enum HAL_GPIO_PIN_T)app_battery_ext_charger_detecter_cfg.pin, HAL_GPIO_DIR_OUT, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
app_battery_event_process(APP_BATTERY_STATUS_CHARGING, status_charger);
|
app_battery_event_process(APP_BATTERY_STATUS_CHARGING, status_charger);
|
||||||
pmu_charger_set_irq_handler(app_battery_charger_handler);
|
pmu_charger_set_irq_handler(app_battery_charger_handler);
|
||||||
osTimerStop(app_battery_pluginout_debounce_timer);
|
osTimerStop(app_battery_pluginout_debounce_timer);
|
||||||
}else{
|
}else{
|
||||||
osTimerStart(app_battery_pluginout_debounce_timer,
|
osTimerStart(app_battery_pluginout_debounce_timer, CHARGER_PLUGINOUT_DEBOUNCE_MS);
|
||||||
CHARGER_PLUGINOUT_DEBOUNCE_MS);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_battery_charger_indication_open(void) {
|
int app_battery_charger_indication_open(void)
|
||||||
|
{
|
||||||
enum APP_BATTERY_CHARGER_T status = APP_BATTERY_CHARGER_QTY;
|
enum APP_BATTERY_CHARGER_T status = APP_BATTERY_CHARGER_QTY;
|
||||||
uint8_t cnt = 0;
|
uint8_t cnt = 0;
|
||||||
|
|
||||||
|
@ -769,16 +794,19 @@ int app_battery_charger_indication_open(void) {
|
||||||
|
|
||||||
pmu_charger_init();
|
pmu_charger_init();
|
||||||
|
|
||||||
do {
|
do
|
||||||
|
{
|
||||||
status = app_battery_charger_forcegetstatus();
|
status = app_battery_charger_forcegetstatus();
|
||||||
if (status == APP_BATTERY_CHARGER_PLUGIN)
|
if (status == APP_BATTERY_CHARGER_PLUGIN)
|
||||||
break;
|
break;
|
||||||
osDelay(20);
|
osDelay(20);
|
||||||
} while (cnt++ < 5);
|
}
|
||||||
|
while(cnt++<5);
|
||||||
|
|
||||||
if (app_battery_ext_charger_detecter_cfg.pin != HAL_IOMUX_PIN_NUM) {
|
if (app_battery_ext_charger_detecter_cfg.pin != HAL_IOMUX_PIN_NUM)
|
||||||
if (!hal_gpio_pin_get_val(
|
{
|
||||||
(enum HAL_GPIO_PIN_T)app_battery_ext_charger_detecter_cfg.pin)) {
|
if (!hal_gpio_pin_get_val((enum HAL_GPIO_PIN_T)app_battery_ext_charger_detecter_cfg.pin))
|
||||||
|
{
|
||||||
status = APP_BATTERY_CHARGER_PLUGIN;
|
status = APP_BATTERY_CHARGER_PLUGIN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -788,7 +816,8 @@ int app_battery_charger_indication_open(void) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t app_battery_current_level(void) {
|
int8_t app_battery_current_level(void)
|
||||||
|
{
|
||||||
#ifdef __INTERCONNECTION__
|
#ifdef __INTERCONNECTION__
|
||||||
return app_battery_measure.currentBatteryInfo & 0x7f;
|
return app_battery_measure.currentBatteryInfo & 0x7f;
|
||||||
#else
|
#else
|
||||||
|
@ -796,7 +825,8 @@ int8_t app_battery_current_level(void) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t app_battery_is_charging(void) {
|
int8_t app_battery_is_charging(void)
|
||||||
|
{
|
||||||
return (APP_BATTERY_STATUS_CHARGING == app_battery_measure.status);
|
return (APP_BATTERY_STATUS_CHARGING == app_battery_measure.status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -810,7 +840,8 @@ typedef uint16_t NTP_TEMPERATURE_C_T;
|
||||||
|
|
||||||
typedef void (*NTC_CAPTURE_MEASURE_CB_T)(NTP_TEMPERATURE_C_T);
|
typedef void (*NTC_CAPTURE_MEASURE_CB_T)(NTP_TEMPERATURE_C_T);
|
||||||
|
|
||||||
struct NTC_CAPTURE_MEASURE_T {
|
struct NTC_CAPTURE_MEASURE_T
|
||||||
|
{
|
||||||
NTP_TEMPERATURE_C_T temperature;
|
NTP_TEMPERATURE_C_T temperature;
|
||||||
NTP_VOLTAGE_MV_T currvolt;
|
NTP_VOLTAGE_MV_T currvolt;
|
||||||
NTP_VOLTAGE_MV_T voltage[NTC_CAPTURE_STABLE_COUNT];
|
NTP_VOLTAGE_MV_T voltage[NTC_CAPTURE_STABLE_COUNT];
|
||||||
|
@ -820,36 +851,38 @@ struct NTC_CAPTURE_MEASURE_T {
|
||||||
|
|
||||||
static struct NTC_CAPTURE_MEASURE_T ntc_capture_measure;
|
static struct NTC_CAPTURE_MEASURE_T ntc_capture_measure;
|
||||||
|
|
||||||
void ntc_capture_irqhandler(uint16_t irq_val, HAL_GPADC_MV_T volt) {
|
void ntc_capture_irqhandler(uint16_t irq_val, HAL_GPADC_MV_T volt)
|
||||||
|
{
|
||||||
uint32_t meanVolt = 0;
|
uint32_t meanVolt = 0;
|
||||||
TRACE(3,"%s %d irq:0x%04x",__func__, volt, irq_val);
|
TRACE(3,"%s %d irq:0x%04x",__func__, volt, irq_val);
|
||||||
|
|
||||||
if (volt == HAL_GPADC_BAD_VALUE) {
|
if (volt == HAL_GPADC_BAD_VALUE)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ntc_capture_measure
|
ntc_capture_measure.voltage[ntc_capture_measure.index++%NTC_CAPTURE_STABLE_COUNT] = volt;
|
||||||
.voltage[ntc_capture_measure.index++ % NTC_CAPTURE_STABLE_COUNT] = volt;
|
|
||||||
|
|
||||||
if (ntc_capture_measure.index > NTC_CAPTURE_STABLE_COUNT) {
|
if (ntc_capture_measure.index > NTC_CAPTURE_STABLE_COUNT)
|
||||||
for (uint8_t i = 0; i < NTC_CAPTURE_STABLE_COUNT; i++) {
|
{
|
||||||
|
for (uint8_t i=0; i<NTC_CAPTURE_STABLE_COUNT; i++)
|
||||||
|
{
|
||||||
meanVolt += ntc_capture_measure.voltage[i];
|
meanVolt += ntc_capture_measure.voltage[i];
|
||||||
}
|
}
|
||||||
meanVolt /= NTC_CAPTURE_STABLE_COUNT;
|
meanVolt /= NTC_CAPTURE_STABLE_COUNT;
|
||||||
ntc_capture_measure.currvolt = meanVolt;
|
ntc_capture_measure.currvolt = meanVolt;
|
||||||
} else if (!ntc_capture_measure.currvolt) {
|
}
|
||||||
|
else if (!ntc_capture_measure.currvolt)
|
||||||
|
{
|
||||||
ntc_capture_measure.currvolt = volt;
|
ntc_capture_measure.currvolt = volt;
|
||||||
}
|
}
|
||||||
ntc_capture_measure.temperature =
|
ntc_capture_measure.temperature = ((int32_t)ntc_capture_measure.currvolt - NTC_CAPTURE_VOLTAGE_REF)/NTC_CAPTURE_TEMPERATURE_STEP + NTC_CAPTURE_TEMPERATURE_REF;
|
||||||
((int32_t)ntc_capture_measure.currvolt - NTC_CAPTURE_VOLTAGE_REF) /
|
|
||||||
NTC_CAPTURE_TEMPERATURE_STEP +
|
|
||||||
NTC_CAPTURE_TEMPERATURE_REF;
|
|
||||||
pmu_ntc_capture_disable();
|
pmu_ntc_capture_disable();
|
||||||
TRACE(3, "%s ad:%d temperature:%d", __func__, ntc_capture_measure.currvolt,
|
TRACE(3,"%s ad:%d temperature:%d",__func__, ntc_capture_measure.currvolt, ntc_capture_measure.temperature);
|
||||||
ntc_capture_measure.temperature);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ntc_capture_open(void) {
|
int ntc_capture_open(void)
|
||||||
|
{
|
||||||
|
|
||||||
ntc_capture_measure.currvolt = 0;
|
ntc_capture_measure.currvolt = 0;
|
||||||
ntc_capture_measure.index = 0;
|
ntc_capture_measure.index = 0;
|
||||||
|
@ -857,14 +890,14 @@ int ntc_capture_open(void) {
|
||||||
ntc_capture_measure.cb = NULL;
|
ntc_capture_measure.cb = NULL;
|
||||||
|
|
||||||
pmu_ntc_capture_enable();
|
pmu_ntc_capture_enable();
|
||||||
hal_gpadc_open(HAL_GPADC_CHAN_0, HAL_GPADC_ATP_ONESHOT,
|
hal_gpadc_open(HAL_GPADC_CHAN_0, HAL_GPADC_ATP_ONESHOT, ntc_capture_irqhandler);
|
||||||
ntc_capture_irqhandler);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ntc_capture_start(void) {
|
int ntc_capture_start(void)
|
||||||
|
{
|
||||||
pmu_ntc_capture_enable();
|
pmu_ntc_capture_enable();
|
||||||
hal_gpadc_open(HAL_GPADC_CHAN_0, HAL_GPADC_ATP_ONESHOT,
|
hal_gpadc_open(HAL_GPADC_CHAN_0, HAL_GPADC_ATP_ONESHOT, ntc_capture_irqhandler);
|
||||||
ntc_capture_irqhandler);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
cur_dir := $(dir $(lastword $(MAKEFILE_LIST)))
|
||||||
|
|
||||||
|
obj-y := $(patsubst $(cur_dir)%,%,$(wildcard $(cur_dir)*.c $(cur_dir)*.cpp $(cur_dir)*.S))
|
||||||
|
|
||||||
|
|
||||||
|
obj-y := $(obj-y:.c=.o)
|
||||||
|
obj-y := $(obj-y:.cpp=.o)
|
||||||
|
obj-y := $(obj-y:.S=.o)
|
||||||
|
|
||||||
|
ccflags-y += \
|
||||||
|
$(BT_IF_INCLUDES) \
|
||||||
|
$(BT_PROFILES_INCLUDES) \
|
||||||
|
-Iservices/bt_app \
|
||||||
|
-Iservices/bt_app/a2dp_codecs/include \
|
||||||
|
-Iservices/audioflinger \
|
||||||
|
-Iservices/nvrecord \
|
||||||
|
-Iservices/overlay \
|
||||||
|
-Iservices/resources \
|
||||||
|
-Iservices/audio_process \
|
||||||
|
-Iapps/apptester \
|
||||||
|
-Iapps/factory \
|
||||||
|
-Iutils/crc32 \
|
||||||
|
-Iplatform/drivers/bt \
|
||||||
|
-Iplatform/drivers/ana \
|
||||||
|
-Iapps/audioplayers/rbplay \
|
||||||
|
-Itests/anc_usb \
|
||||||
|
-Iapps/anc/inc \
|
||||||
|
-Iapps/ota \
|
||||||
|
-Ithirdparty/userapi \
|
||||||
|
-Iservices/voicepath \
|
||||||
|
-Iservices/voicepath/gsound/gsound_service \
|
||||||
|
-Iservices/voicepath/gsound/gsound_target \
|
||||||
|
-Iservices/communication \
|
||||||
|
-Iutils/cqueue \
|
||||||
|
-Iservices/ai_voice/ama/ama_manager \
|
||||||
|
-Iservices/ai_voice/manager \
|
||||||
|
-Iservices/multimedia/audio/codec/sbc/inc \
|
||||||
|
-Iservices/multimedia/audio/codec/sbc/src/inc \
|
||||||
|
-Iservices/interconnection
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,307 @@
|
||||||
|
/***************************************************************************
|
||||||
|
*
|
||||||
|
* Copyright 2015-2019 BES.
|
||||||
|
* All rights reserved. All unpublished rights reserved.
|
||||||
|
*
|
||||||
|
* No part of this work may be used or reproduced in any form or by any
|
||||||
|
* means, or stored in a database or retrieval system, without prior written
|
||||||
|
* permission of BES.
|
||||||
|
*
|
||||||
|
* Use of this work is governed by a license granted by BES.
|
||||||
|
* This work contains confidential and proprietary information of
|
||||||
|
* BES. which is protected by copyright, trade secret,
|
||||||
|
* trademark and other intellectual property rights.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
#include "stdio.h"
|
||||||
|
#include "cmsis_os.h"
|
||||||
|
#include "hal_timer.h"
|
||||||
|
#include "hal_trace.h"
|
||||||
|
#include "app_audio.h"
|
||||||
|
|
||||||
|
#include "a2dp_api.h"
|
||||||
|
#include "app_bt.h"
|
||||||
|
#include "btapp.h"
|
||||||
|
#include "usb_audio_app.h"
|
||||||
|
#include "btusb_audio.h"
|
||||||
|
|
||||||
|
extern void btusbaudio_entry(void);
|
||||||
|
extern void btusbaudio_exit(void);
|
||||||
|
extern a2dp_stream_t* app_bt_get_steam(enum BT_DEVICE_ID_T id);
|
||||||
|
extern int app_bt_get_bt_addr(enum BT_DEVICE_ID_T id,bt_bdaddr_t *bdaddr);
|
||||||
|
extern bool app_bt_a2dp_service_is_connected(void);
|
||||||
|
int app_bt_A2DP_OpenStream(a2dp_stream_t *Stream, bt_bdaddr_t *Addr);
|
||||||
|
int app_bt_A2DP_CloseStream(a2dp_stream_t *Stream);
|
||||||
|
|
||||||
|
extern bool btapp_hfp_is_call_active(void);
|
||||||
|
static bool btusb_usb_is_on = false;
|
||||||
|
static enum BTUSB_MODE btusb_mode = BTUSB_MODE_INVALID;
|
||||||
|
static bool btusb_bt_audio_is_suspend = false;
|
||||||
|
|
||||||
|
#define BT_USB_DEBUG() //TRACE(2,"_debug: %s,%d",__func__,__LINE__)
|
||||||
|
extern struct BT_DEVICE_T app_bt_device;
|
||||||
|
|
||||||
|
static void _btusb_stream_open(unsigned int timeout_ms)
|
||||||
|
{
|
||||||
|
a2dp_stream_t *stream = NULL;
|
||||||
|
bt_bdaddr_t bdaddr;
|
||||||
|
uint32_t stime = 0;
|
||||||
|
uint32_t etime = 0;
|
||||||
|
|
||||||
|
stime = hal_sys_timer_get();
|
||||||
|
//BT_USB_DEBUG();
|
||||||
|
stream = (a2dp_stream_t*)app_bt_get_steam(BT_DEVICE_ID_1);
|
||||||
|
|
||||||
|
app_bt_get_bt_addr(BT_DEVICE_ID_1,&bdaddr);
|
||||||
|
if(stream)
|
||||||
|
{
|
||||||
|
//struct BT_DEVICE_T *bt_dev = &app_bt_device;
|
||||||
|
//A2DP_Register((a2dp_stream_t *)bt_dev->a2dp_stream[BT_DEVICE_ID_1]->a2dp_stream, &a2dp_avdtpcodec, NULL, (A2dpCallback) a2dp_callback);
|
||||||
|
//AVRCP_Register((AvrcpChannel *)bt_dev->avrcp_channel[BT_DEVICE_ID_1]->avrcp_channel_handle, (AvrcpCallback)avrcp_callback_CT, BTIF_AVRCP_CT_CATEGORY_1 | BTIF_AVRCP_CT_CATEGORY_2 | BTIF_AVRCP_TG_CATEGORY_2);
|
||||||
|
BT_USB_DEBUG();
|
||||||
|
osDelay(10);
|
||||||
|
app_bt_A2DP_OpenStream(stream,&bdaddr);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
BT_USB_DEBUG();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
if(app_bt_a2dp_service_is_connected()){
|
||||||
|
etime = hal_sys_timer_get();
|
||||||
|
TRACE(1,"_debug: a2dp service connected, wait time = 0x%x.",TICKS_TO_MS(etime - stime));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
etime = hal_sys_timer_get();
|
||||||
|
if(TICKS_TO_MS(etime - stime) >= timeout_ms)
|
||||||
|
{
|
||||||
|
TRACE(1,"_debug: a2dp service connect timeout = 0x%x.",
|
||||||
|
TICKS_TO_MS(etime - stime));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
osDelay(10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//BT_USB_DEBUG();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void _btusb_stream_close(unsigned int timeout_ms)
|
||||||
|
{
|
||||||
|
a2dp_stream_t *stream = NULL;
|
||||||
|
uint32_t stime = 0;
|
||||||
|
uint32_t etime = 0;
|
||||||
|
|
||||||
|
stime = hal_sys_timer_get();
|
||||||
|
BT_USB_DEBUG();
|
||||||
|
stream = (a2dp_stream_t*)app_bt_get_steam(BT_DEVICE_ID_1);
|
||||||
|
if(stream)
|
||||||
|
{
|
||||||
|
BT_USB_DEBUG();
|
||||||
|
app_bt_A2DP_CloseStream(stream);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
BT_USB_DEBUG();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
stime = hal_sys_timer_get();
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
if(!app_bt_a2dp_service_is_connected()){
|
||||||
|
//struct BT_DEVICE_T *bt_dev = &app_bt_device;
|
||||||
|
//AVRCP_Deregister(bt_dev->avrcp_channel[BT_DEVICE_ID_1]->avrcp_channel_handle);
|
||||||
|
//A2DP_Deregister(stream);
|
||||||
|
etime = hal_sys_timer_get();
|
||||||
|
TRACE(1,"a2dp service diconnected, wait time = 0x%x.",
|
||||||
|
TICKS_TO_MS(etime - stime));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
etime = hal_sys_timer_get();
|
||||||
|
if(TICKS_TO_MS(etime - stime) >= timeout_ms)
|
||||||
|
{
|
||||||
|
TRACE(1,"a2dp service diconnect timeout = 0x%x.",
|
||||||
|
TICKS_TO_MS(etime - stime));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
osDelay(10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BT_USB_DEBUG();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void btusb_usbaudio_entry(void)
|
||||||
|
{
|
||||||
|
BT_USB_DEBUG();
|
||||||
|
btusbaudio_entry();
|
||||||
|
btusb_usb_is_on = true ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void btusb_usbaudio_open(void)
|
||||||
|
{
|
||||||
|
BT_USB_DEBUG();
|
||||||
|
if(!btusb_usb_is_on)
|
||||||
|
{
|
||||||
|
btusb_usbaudio_entry();
|
||||||
|
BT_USB_DEBUG();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
usb_audio_app(1);
|
||||||
|
}
|
||||||
|
BT_USB_DEBUG();
|
||||||
|
}
|
||||||
|
|
||||||
|
void btusb_usbaudio_close(void)
|
||||||
|
{
|
||||||
|
BT_USB_DEBUG();
|
||||||
|
if(btusb_usb_is_on)
|
||||||
|
{
|
||||||
|
usb_audio_app(0);
|
||||||
|
BT_USB_DEBUG();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
BT_USB_DEBUG();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void btusb_btaudio_close(bool is_wait)
|
||||||
|
{
|
||||||
|
BT_USB_DEBUG();
|
||||||
|
//if(!btusb_bt_audio_is_suspend)
|
||||||
|
{
|
||||||
|
BT_USB_DEBUG();
|
||||||
|
if(is_wait)
|
||||||
|
{
|
||||||
|
app_audio_sendrequest(APP_PLAY_BACK_AUDIO, (uint8_t)APP_BT_SETTING_CLOSEALL, 0);
|
||||||
|
_btusb_stream_close(BTUSB_OUTTIME_MS);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_btusb_stream_close(0);
|
||||||
|
}
|
||||||
|
btusb_bt_audio_is_suspend = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void btusb_btaudio_open(bool is_wait)
|
||||||
|
{
|
||||||
|
BT_USB_DEBUG();
|
||||||
|
//if(btusb_bt_audio_is_suspend)
|
||||||
|
{
|
||||||
|
TRACE(2,"%s: %d.",__func__,__LINE__);
|
||||||
|
if(is_wait)
|
||||||
|
{
|
||||||
|
_btusb_stream_open(BTUSB_OUTTIME_MS);
|
||||||
|
app_audio_sendrequest(APP_PLAY_BACK_AUDIO, (uint8_t)APP_BT_SETTING_CLOSE, 0);
|
||||||
|
app_audio_sendrequest(APP_PLAY_BACK_AUDIO, (uint8_t)APP_BT_SETTING_SETUP, 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_btusb_stream_open(0);
|
||||||
|
}
|
||||||
|
TRACE(2,"%s: %d.",__func__,__LINE__);
|
||||||
|
btusb_bt_audio_is_suspend = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void btusb_switch(enum BTUSB_MODE mode)
|
||||||
|
{
|
||||||
|
//BT_USB_DEBUG();
|
||||||
|
if(mode != BTUSB_MODE_BT && mode != BTUSB_MODE_USB)
|
||||||
|
{
|
||||||
|
ASSERT(0, "%s:%d, mode = %d.",__func__,__LINE__,mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(btusb_mode == mode) {
|
||||||
|
BT_USB_DEBUG();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(btusb_mode == BTUSB_MODE_INVALID)
|
||||||
|
{
|
||||||
|
if(mode == BTUSB_MODE_BT) {
|
||||||
|
TRACE(1,"%s: switch to BT mode.",__func__);
|
||||||
|
btusb_mode = BTUSB_MODE_BT;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
TRACE(1,"%s: switch to USB mode.",__func__);
|
||||||
|
//btusb_btaudio_close(true);
|
||||||
|
osDelay(500);
|
||||||
|
btusb_usbaudio_open();
|
||||||
|
btusb_mode = BTUSB_MODE_USB;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(mode == BTUSB_MODE_BT) {
|
||||||
|
TRACE(1,"%s: switch to BT mode.",__func__);
|
||||||
|
if(btusb_usb_is_on)
|
||||||
|
{
|
||||||
|
TRACE(1,"%s: btusb_usbaudio_close.",__func__);
|
||||||
|
btusb_usbaudio_close();
|
||||||
|
TRACE(1,"%s: btusb_usbaudio_close done.",__func__);
|
||||||
|
osDelay(500);
|
||||||
|
}
|
||||||
|
btusb_mode = BTUSB_MODE_BT;
|
||||||
|
btusb_btaudio_open(true);
|
||||||
|
TRACE(1,"%s: switch to BT mode done.",__func__);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(btapp_hfp_is_call_active() == 1)
|
||||||
|
{
|
||||||
|
TRACE(1,"%s: hfp is call active.",__func__);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
TRACE(1,"%s: switch to USB mode.",__func__);
|
||||||
|
btusb_btaudio_close(true);
|
||||||
|
TRACE(1,"%s: btusb_btaudio_close done.",__func__);
|
||||||
|
osDelay(500);
|
||||||
|
btusb_usbaudio_open();
|
||||||
|
btusb_mode = BTUSB_MODE_USB;
|
||||||
|
TRACE(1,"%s: switch to USB mode done.",__func__);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool btusb_is_bt_mode(void)
|
||||||
|
{
|
||||||
|
BT_USB_DEBUG();
|
||||||
|
return btusb_mode == BTUSB_MODE_BT ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool btusb_is_usb_mode(void)
|
||||||
|
{
|
||||||
|
return btusb_mode == BTUSB_MODE_USB ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(BT_USB_AUDIO_DUAL_MODE_TEST)
|
||||||
|
void test_btusb_switch(void)
|
||||||
|
{
|
||||||
|
if(btusb_mode == BTUSB_MODE_BT)
|
||||||
|
{
|
||||||
|
btusb_switch(BTUSB_MODE_USB);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
btusb_switch(BTUSB_MODE_BT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_btusb_switch_to_bt(void)
|
||||||
|
{
|
||||||
|
btusb_switch(BTUSB_MODE_BT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_btusb_switch_to_usb(void)
|
||||||
|
{
|
||||||
|
btusb_switch(BTUSB_MODE_USB);
|
||||||
|
}
|
||||||
|
#endif
|
|
@ -0,0 +1,40 @@
|
||||||
|
/***************************************************************************
|
||||||
|
*
|
||||||
|
* Copyright 2015-2019 BES.
|
||||||
|
* All rights reserved. All unpublished rights reserved.
|
||||||
|
*
|
||||||
|
* No part of this work may be used or reproduced in any form or by any
|
||||||
|
* means, or stored in a database or retrieval system, without prior written
|
||||||
|
* permission of BES.
|
||||||
|
*
|
||||||
|
* Use of this work is governed by a license granted by BES.
|
||||||
|
* This work contains confidential and proprietary information of
|
||||||
|
* BES. which is protected by copyright, trade secret,
|
||||||
|
* trademark and other intellectual property rights.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
#ifndef _BTUSB_AUDIO_H_
|
||||||
|
#define _BTUSB_AUDIO_H_
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define BTUSB_OUTTIME_MS 1000
|
||||||
|
enum BTUSB_MODE{
|
||||||
|
BTUSB_MODE_BT,
|
||||||
|
BTUSB_MODE_USB,
|
||||||
|
BTUSB_MODE_INVALID
|
||||||
|
};
|
||||||
|
|
||||||
|
void btusb_usbaudio_open(void);
|
||||||
|
void btusb_usbaudio_close(void);
|
||||||
|
void btusb_btaudio_open(bool is_wait);
|
||||||
|
void btusb_btaudio_close(bool is_wait);
|
||||||
|
void btusb_switch(enum BTUSB_MODE mode);
|
||||||
|
bool btusb_is_bt_mode(void);
|
||||||
|
bool btusb_is_usb_mode(void);
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif // _BTUSB_AUDIO_H_
|
||||||
|
|
|
@ -0,0 +1,139 @@
|
||||||
|
/***************************************************************************
|
||||||
|
*
|
||||||
|
* Copyright 2015-2019 BES.
|
||||||
|
* All rights reserved. All unpublished rights reserved.
|
||||||
|
*
|
||||||
|
* No part of this work may be used or reproduced in any form or by any
|
||||||
|
* means, or stored in a database or retrieval system, without prior written
|
||||||
|
* permission of BES.
|
||||||
|
*
|
||||||
|
* Use of this work is governed by a license granted by BES.
|
||||||
|
* This work contains confidential and proprietary information of
|
||||||
|
* BES. which is protected by copyright, trade secret,
|
||||||
|
* trademark and other intellectual property rights.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
#include "cmsis_os.h"
|
||||||
|
#include "hal_trace.h"
|
||||||
|
#include "app_utils.h"
|
||||||
|
#include "usb_audio_app.h"
|
||||||
|
#include "usbaudio_thread.h"
|
||||||
|
|
||||||
|
static void usb_thread(void const *argument);
|
||||||
|
osThreadDef(usb_thread, osPriorityHigh, 1, 2048, "usb");
|
||||||
|
|
||||||
|
osMailQDef (usb_mailbox, USB_MAILBOX_MAX, USB_MESSAGE);
|
||||||
|
static osMailQId usb_mailbox = NULL;
|
||||||
|
static uint8_t usb_mailbox_cnt = 0;
|
||||||
|
#define USBAUDIO_DEBUG TRACE
|
||||||
|
static int usb_mailbox_init(void)
|
||||||
|
{
|
||||||
|
USBAUDIO_DEBUG("%s,%d",__func__,__LINE__);
|
||||||
|
usb_mailbox = osMailCreate(osMailQ(usb_mailbox), NULL);
|
||||||
|
if (usb_mailbox == NULL) {
|
||||||
|
USBAUDIO_DEBUG("Failed to Create usb_mailbox\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
usb_mailbox_cnt = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int usb_mailbox_put(USB_MESSAGE* msg_src)
|
||||||
|
{
|
||||||
|
osStatus status;
|
||||||
|
USB_MESSAGE *msg_p = NULL;
|
||||||
|
|
||||||
|
USBAUDIO_DEBUG("%s,%d",__func__,__LINE__);
|
||||||
|
if(usb_mailbox_cnt >= 1)
|
||||||
|
{
|
||||||
|
USBAUDIO_DEBUG("%s,%d usb_mailbox_cnt = %d.",
|
||||||
|
__func__,__LINE__,usb_mailbox_cnt);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
msg_p = (USB_MESSAGE*)osMailAlloc(usb_mailbox, 0);
|
||||||
|
ASSERT(msg_p, "osMailAlloc error");
|
||||||
|
msg_p->id = msg_src->id;
|
||||||
|
msg_p->ptr = msg_src->ptr;
|
||||||
|
msg_p->param0 = msg_src->param0;
|
||||||
|
msg_p->param1 = msg_src->param1;
|
||||||
|
|
||||||
|
status = osMailPut(usb_mailbox, msg_p);
|
||||||
|
if (osOK == status)
|
||||||
|
usb_mailbox_cnt++;
|
||||||
|
USBAUDIO_DEBUG("%s,%d,usb_mailbox_cnt = %d.",__func__,__LINE__,usb_mailbox_cnt);
|
||||||
|
return (int)status;
|
||||||
|
}
|
||||||
|
|
||||||
|
int usb_mailbox_free(USB_MESSAGE* msg_p)
|
||||||
|
{
|
||||||
|
osStatus status;
|
||||||
|
|
||||||
|
USBAUDIO_DEBUG("%s,%d",__func__,__LINE__);
|
||||||
|
status = osMailFree(usb_mailbox, msg_p);
|
||||||
|
if (osOK == status)
|
||||||
|
usb_mailbox_cnt--;
|
||||||
|
USBAUDIO_DEBUG("%s,%d,usb_mailbox_cnt = %d.",__func__,__LINE__,usb_mailbox_cnt);
|
||||||
|
return (int)status;
|
||||||
|
}
|
||||||
|
|
||||||
|
int usb_mailbox_get(USB_MESSAGE **msg_p)
|
||||||
|
{
|
||||||
|
osEvent evt;
|
||||||
|
evt = osMailGet(usb_mailbox, osWaitForever);
|
||||||
|
if (evt.status == osEventMail) {
|
||||||
|
*msg_p = (USB_MESSAGE*)evt.value.p;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void usb_thread(void const *argument)
|
||||||
|
{
|
||||||
|
// USB_FUNC_T usb_funcp;
|
||||||
|
USBAUDIO_DEBUG("%s,%d",__func__,__LINE__);
|
||||||
|
while(1){
|
||||||
|
USB_MESSAGE *msg_p = NULL;
|
||||||
|
|
||||||
|
if (!usb_mailbox_get(&msg_p)) {
|
||||||
|
//TRACE(2,"_debug: %s,%d",__func__,__LINE__);
|
||||||
|
USBAUDIO_DEBUG("usb_thread: id = 0x%x, ptr = 0x%x,param0 = 0x%x,param1 = 0x%x.",
|
||||||
|
msg_p->id,msg_p->ptr,msg_p->param0,msg_p->param1);
|
||||||
|
usb_mailbox_free(msg_p);
|
||||||
|
usb_audio_app_loop();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void usb_enqueue_cmd(uint32_t data)
|
||||||
|
{
|
||||||
|
USB_MESSAGE usb_msg;
|
||||||
|
|
||||||
|
usb_msg.id = 0;
|
||||||
|
usb_msg.param0 = 0;
|
||||||
|
usb_msg.param1 = 0;
|
||||||
|
usb_msg.ptr = 0;
|
||||||
|
usb_mailbox_put(&usb_msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
int usb_os_init(void)
|
||||||
|
{
|
||||||
|
osThreadId usb_tid;
|
||||||
|
|
||||||
|
USBAUDIO_DEBUG("%s,%d",__func__,__LINE__);
|
||||||
|
if (usb_mailbox_init()) {
|
||||||
|
USBAUDIO_DEBUG("_debug: %s,%d",__func__,__LINE__);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
usb_tid = osThreadCreate(osThread(usb_thread), NULL);
|
||||||
|
if (usb_tid == NULL) {
|
||||||
|
USBAUDIO_DEBUG("Failed to Create usb_thread\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
usb_audio_set_enqueue_cmd_callback(usb_enqueue_cmd);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
/***************************************************************************
|
||||||
|
*
|
||||||
|
* Copyright 2015-2019 BES.
|
||||||
|
* All rights reserved. All unpublished rights reserved.
|
||||||
|
*
|
||||||
|
* No part of this work may be used or reproduced in any form or by any
|
||||||
|
* means, or stored in a database or retrieval system, without prior written
|
||||||
|
* permission of BES.
|
||||||
|
*
|
||||||
|
* Use of this work is governed by a license granted by BES.
|
||||||
|
* This work contains confidential and proprietary information of
|
||||||
|
* BES. which is protected by copyright, trade secret,
|
||||||
|
* trademark and other intellectual property rights.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
#ifndef __USB_THREAD_H__
|
||||||
|
#define __USB_THREAD_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define USB_MAILBOX_MAX (20)
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint32_t id;
|
||||||
|
uint32_t ptr;
|
||||||
|
uint32_t param0;
|
||||||
|
uint32_t param1;
|
||||||
|
} USB_MESSAGE;
|
||||||
|
|
||||||
|
|
||||||
|
//typedef int (*USB_MOD_HANDLER_T)(USB_MESSAGE_BODY *);
|
||||||
|
typedef void (*USB_FUNC_T)(uint32_t, uint32_t);
|
||||||
|
|
||||||
|
int usb_mailbox_put(USB_MESSAGE* msg_src);
|
||||||
|
|
||||||
|
int usb_mailbox_free(USB_MESSAGE* msg_p);
|
||||||
|
|
||||||
|
int usb_mailbox_get(USB_MESSAGE** msg_p);
|
||||||
|
|
||||||
|
int usb_os_init(void);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // __USB_THREAD_H__
|
||||||
|
|
|
@ -14,18 +14,19 @@
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#ifdef __PC_CMD_UART__
|
#ifdef __PC_CMD_UART__
|
||||||
#include "app_cmd.h"
|
|
||||||
#include "app_thread.h"
|
|
||||||
#include "audio_process.h"
|
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
#include "hal_cmd.h"
|
|
||||||
#include "hal_trace.h"
|
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
#include "app_thread.h"
|
||||||
|
#include "app_cmd.h"
|
||||||
|
#include "hal_cmd.h"
|
||||||
|
#include "hal_trace.h"
|
||||||
|
#include "audio_process.h"
|
||||||
|
|
||||||
#define APP_CMD_TRACE(s,...) TRACE(s, ##__VA_ARGS__)
|
#define APP_CMD_TRACE(s,...) TRACE(s, ##__VA_ARGS__)
|
||||||
|
|
||||||
void cmd_event_process(hal_cmd_rx_status_t status) {
|
void cmd_event_process(hal_cmd_rx_status_t status)
|
||||||
|
{
|
||||||
APP_CMD_TRACE(1,"%s",__func__);
|
APP_CMD_TRACE(1,"%s",__func__);
|
||||||
APP_MESSAGE_BLOCK msg;
|
APP_MESSAGE_BLOCK msg;
|
||||||
msg.mod_id = APP_MODUAL_CMD;
|
msg.mod_id = APP_MODUAL_CMD;
|
||||||
|
@ -35,14 +36,16 @@ void cmd_event_process(hal_cmd_rx_status_t status) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int app_cmd_handle_process(APP_MESSAGE_BODY *msg_body) {
|
static int app_cmd_handle_process(APP_MESSAGE_BODY *msg_body)
|
||||||
|
{
|
||||||
hal_cmd_run((hal_cmd_rx_status_t)msg_body->message_id);
|
hal_cmd_run((hal_cmd_rx_status_t)msg_body->message_id);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t app_cmd_flag = 0;
|
uint8_t app_cmd_flag = 0;
|
||||||
|
|
||||||
void app_cmd_open(void) {
|
void app_cmd_open(void)
|
||||||
|
{
|
||||||
APP_CMD_TRACE(1,"%s",__func__);
|
APP_CMD_TRACE(1,"%s",__func__);
|
||||||
|
|
||||||
app_cmd_flag = 1;
|
app_cmd_flag = 1;
|
||||||
|
@ -53,9 +56,11 @@ void app_cmd_open(void) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void app_cmd_close(void) {
|
void app_cmd_close(void)
|
||||||
|
{
|
||||||
APP_CMD_TRACE(1,"%s",__func__);
|
APP_CMD_TRACE(1,"%s",__func__);
|
||||||
if (app_cmd_flag) {
|
if(app_cmd_flag)
|
||||||
|
{
|
||||||
app_cmd_flag = 0;
|
app_cmd_flag = 0;
|
||||||
hal_cmd_close();
|
hal_cmd_close();
|
||||||
app_set_threadhandle(APP_MODUAL_CMD, NULL);
|
app_set_threadhandle(APP_MODUAL_CMD, NULL);
|
||||||
|
@ -63,3 +68,4 @@ void app_cmd_close(void) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -13,15 +13,15 @@
|
||||||
* trademark and other intellectual property rights.
|
* trademark and other intellectual property rights.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include "app_spec_ostimer.h"
|
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
#include "hal_trace.h"
|
|
||||||
#include "stdint.h"
|
#include "stdint.h"
|
||||||
|
#include "app_spec_ostimer.h"
|
||||||
|
#include "hal_trace.h"
|
||||||
|
|
||||||
|
|
||||||
/// Create timer
|
/// Create timer
|
||||||
osStatus app_spec_timer_create(SPEC_TIMER_CTX_T *spec_timer_ctx,
|
osStatus app_spec_timer_create (SPEC_TIMER_CTX_T *spec_timer_ctx, const osTimerDef_t *timer_def, os_timer_type type, void *argument)
|
||||||
const osTimerDef_t *timer_def,
|
{
|
||||||
os_timer_type type, void *argument) {
|
|
||||||
spec_timer_ctx->type = type;
|
spec_timer_ctx->type = type;
|
||||||
spec_timer_ctx->argument = argument;
|
spec_timer_ctx->argument = argument;
|
||||||
spec_timer_ctx->timerid = osTimerCreate(timer_def, type, spec_timer_ctx);
|
spec_timer_ctx->timerid = osTimerCreate(timer_def, type, spec_timer_ctx);
|
||||||
|
@ -29,8 +29,8 @@ osStatus app_spec_timer_create(SPEC_TIMER_CTX_T *spec_timer_ctx,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Start or restart timer
|
/// Start or restart timer
|
||||||
osStatus app_spec_timer_start(SPEC_TIMER_CTX_T *spec_timer_ctx,
|
osStatus app_spec_timer_start (SPEC_TIMER_CTX_T *spec_timer_ctx, uint32_t millisec)
|
||||||
uint32_t millisec) {
|
{
|
||||||
osStatus status;
|
osStatus status;
|
||||||
|
|
||||||
//TRACE(1,"%s", __func__);
|
//TRACE(1,"%s", __func__);
|
||||||
|
@ -48,16 +48,19 @@ osStatus app_spec_timer_start(SPEC_TIMER_CTX_T *spec_timer_ctx,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Stop timer
|
/// Stop timer
|
||||||
osStatus app_spec_timer_stop(SPEC_TIMER_CTX_T *spec_timer_ctx) {
|
osStatus app_spec_timer_stop (SPEC_TIMER_CTX_T *spec_timer_ctx)
|
||||||
|
{
|
||||||
return osTimerStop(spec_timer_ctx->timerid);
|
return osTimerStop(spec_timer_ctx->timerid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Delete timer
|
/// Delete timer
|
||||||
osStatus app_spec_timer_delete(SPEC_TIMER_CTX_T *spec_timer_ctx) {
|
osStatus app_spec_timer_delete (SPEC_TIMER_CTX_T *spec_timer_ctx)
|
||||||
|
{
|
||||||
return osTimerDelete(spec_timer_ctx->timerid);
|
return osTimerDelete(spec_timer_ctx->timerid);
|
||||||
}
|
}
|
||||||
|
|
||||||
void app_spec_timer_handler(void const *para) {
|
void app_spec_timer_handler(void const *para)
|
||||||
|
{
|
||||||
SPEC_TIMER_CTX_T *spec_timer_ctx = (SPEC_TIMER_CTX_T *)para;
|
SPEC_TIMER_CTX_T *spec_timer_ctx = (SPEC_TIMER_CTX_T *)para;
|
||||||
|
|
||||||
if (spec_timer_ctx->ctx > UINT16_MAX){
|
if (spec_timer_ctx->ctx > UINT16_MAX){
|
||||||
|
|
|
@ -13,11 +13,12 @@
|
||||||
* trademark and other intellectual property rights.
|
* trademark and other intellectual property rights.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include "app_thread.h"
|
|
||||||
#include "app_utils.h"
|
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
#include "hal_timer.h"
|
|
||||||
#include "hal_trace.h"
|
#include "hal_trace.h"
|
||||||
|
#include "hal_timer.h"
|
||||||
|
#include "app_utils.h"
|
||||||
|
#include "app_thread.h"
|
||||||
|
|
||||||
|
|
||||||
static APP_MOD_HANDLER_T mod_handler[APP_MODUAL_NUM];
|
static APP_MOD_HANDLER_T mod_handler[APP_MODUAL_NUM];
|
||||||
|
|
||||||
|
@ -29,7 +30,8 @@ static osMailQId app_mailbox = NULL;
|
||||||
static uint8_t app_mailbox_cnt = 0;
|
static uint8_t app_mailbox_cnt = 0;
|
||||||
osThreadId app_thread_tid;
|
osThreadId app_thread_tid;
|
||||||
|
|
||||||
static int app_mailbox_init(void) {
|
static int app_mailbox_init(void)
|
||||||
|
{
|
||||||
app_mailbox = osMailCreate(osMailQ(app_mailbox), NULL);
|
app_mailbox = osMailCreate(osMailQ(app_mailbox), NULL);
|
||||||
if (app_mailbox == NULL) {
|
if (app_mailbox == NULL) {
|
||||||
TRACE(0,"Failed to Create app_mailbox\n");
|
TRACE(0,"Failed to Create app_mailbox\n");
|
||||||
|
@ -39,7 +41,8 @@ static int app_mailbox_init(void) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_mailbox_put(APP_MESSAGE_BLOCK *msg_src) {
|
int app_mailbox_put(APP_MESSAGE_BLOCK* msg_src)
|
||||||
|
{
|
||||||
osStatus status;
|
osStatus status;
|
||||||
|
|
||||||
APP_MESSAGE_BLOCK *msg_p = NULL;
|
APP_MESSAGE_BLOCK *msg_p = NULL;
|
||||||
|
@ -52,10 +55,9 @@ int app_mailbox_put(APP_MESSAGE_BLOCK *msg_src) {
|
||||||
for (uint8_t i=0; i<APP_MAILBOX_MAX; i++){
|
for (uint8_t i=0; i<APP_MAILBOX_MAX; i++){
|
||||||
evt = osMailGet(app_mailbox, 0);
|
evt = osMailGet(app_mailbox, 0);
|
||||||
if (evt.status == osEventMail) {
|
if (evt.status == osEventMail) {
|
||||||
TRACE_IMM(
|
TRACE_IMM(9,"cnt:%d mod:%d src:%08x tim:%d id:%x ptr:%08x para:%08x/%08x/%08x",
|
||||||
9,
|
i,
|
||||||
"cnt:%d mod:%d src:%08x tim:%d id:%x ptr:%08x para:%08x/%08x/%08x",
|
((APP_MESSAGE_BLOCK *)(evt.value.p))->mod_id,
|
||||||
i, ((APP_MESSAGE_BLOCK *)(evt.value.p))->mod_id,
|
|
||||||
((APP_MESSAGE_BLOCK *)(evt.value.p))->src_thread,
|
((APP_MESSAGE_BLOCK *)(evt.value.p))->src_thread,
|
||||||
((APP_MESSAGE_BLOCK *)(evt.value.p))->system_time,
|
((APP_MESSAGE_BLOCK *)(evt.value.p))->system_time,
|
||||||
((APP_MESSAGE_BLOCK *)(evt.value.p))->msg_body.message_id,
|
((APP_MESSAGE_BLOCK *)(evt.value.p))->msg_body.message_id,
|
||||||
|
@ -88,7 +90,8 @@ int app_mailbox_put(APP_MESSAGE_BLOCK *msg_src) {
|
||||||
return (int)status;
|
return (int)status;
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_mailbox_free(APP_MESSAGE_BLOCK *msg_p) {
|
int app_mailbox_free(APP_MESSAGE_BLOCK* msg_p)
|
||||||
|
{
|
||||||
osStatus status;
|
osStatus status;
|
||||||
|
|
||||||
status = osMailFree(app_mailbox, msg_p);
|
status = osMailFree(app_mailbox, msg_p);
|
||||||
|
@ -98,7 +101,8 @@ int app_mailbox_free(APP_MESSAGE_BLOCK *msg_p) {
|
||||||
return (int)status;
|
return (int)status;
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_mailbox_get(APP_MESSAGE_BLOCK **msg_p) {
|
int app_mailbox_get(APP_MESSAGE_BLOCK** msg_p)
|
||||||
|
{
|
||||||
osEvent evt;
|
osEvent evt;
|
||||||
evt = osMailGet(app_mailbox, osWaitForever);
|
evt = osMailGet(app_mailbox, osWaitForever);
|
||||||
if (evt.status == osEventMail) {
|
if (evt.status == osEventMail) {
|
||||||
|
@ -108,7 +112,8 @@ int app_mailbox_get(APP_MESSAGE_BLOCK **msg_p) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void app_thread(void const *argument) {
|
static void app_thread(void const *argument)
|
||||||
|
{
|
||||||
while(1){
|
while(1){
|
||||||
APP_MESSAGE_BLOCK *msg_p = NULL;
|
APP_MESSAGE_BLOCK *msg_p = NULL;
|
||||||
|
|
||||||
|
@ -125,7 +130,8 @@ static void app_thread(void const *argument) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_os_init(void) {
|
int app_os_init(void)
|
||||||
|
{
|
||||||
if (app_mailbox_init())
|
if (app_mailbox_init())
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
@ -137,8 +143,8 @@ int app_os_init(void) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_set_threadhandle(enum APP_MODUAL_ID_T mod_id,
|
int app_set_threadhandle(enum APP_MODUAL_ID_T mod_id, APP_MOD_HANDLER_T handler)
|
||||||
APP_MOD_HANDLER_T handler) {
|
{
|
||||||
if (mod_id>=APP_MODUAL_NUM)
|
if (mod_id>=APP_MODUAL_NUM)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
@ -146,8 +152,13 @@ int app_set_threadhandle(enum APP_MODUAL_ID_T mod_id,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *app_os_tid_get(void) { return (void *)app_thread_tid; }
|
void * app_os_tid_get(void)
|
||||||
|
{
|
||||||
|
return (void *)app_thread_tid;
|
||||||
|
}
|
||||||
|
|
||||||
bool app_is_module_registered(enum APP_MODUAL_ID_T mod_id) {
|
bool app_is_module_registered(enum APP_MODUAL_ID_T mod_id)
|
||||||
|
{
|
||||||
return mod_handler[mod_id];
|
return mod_handler[mod_id];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,6 @@
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#ifndef __APP_THREAD_H__
|
#ifndef __APP_THREAD_H__
|
||||||
#define __APP_THREAD_H__
|
#define __APP_THREAD_H__
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -81,8 +79,7 @@ int app_mailbox_get(APP_MESSAGE_BLOCK **msg_p);
|
||||||
|
|
||||||
int app_os_init(void);
|
int app_os_init(void);
|
||||||
|
|
||||||
int app_set_threadhandle(enum APP_MODUAL_ID_T mod_id,
|
int app_set_threadhandle(enum APP_MODUAL_ID_T mod_id, APP_MOD_HANDLER_T handler);
|
||||||
APP_MOD_HANDLER_T handler);
|
|
||||||
|
|
||||||
void * app_os_tid_get(void);
|
void * app_os_tid_get(void);
|
||||||
|
|
||||||
|
|
|
@ -13,13 +13,13 @@
|
||||||
* trademark and other intellectual property rights.
|
* trademark and other intellectual property rights.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include "app_utils.h"
|
|
||||||
#include "analog.h"
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "hal_timer.h"
|
|
||||||
#include "hal_trace.h"
|
#include "hal_trace.h"
|
||||||
|
#include "hal_timer.h"
|
||||||
#include "hal_wdt.h"
|
#include "hal_wdt.h"
|
||||||
#include "pmu.h"
|
#include "pmu.h"
|
||||||
|
#include "analog.h"
|
||||||
|
#include "app_utils.h"
|
||||||
#ifdef RTOS
|
#ifdef RTOS
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -41,16 +41,19 @@
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
* NOTE:
|
* NOTE:
|
||||||
* The macro QOS_USERS works only when the APP_SYSFREQ_USER_APP_XXX is not large
|
* The macro QOS_USERS works only when the APP_SYSFREQ_USER_APP_XXX is not large than
|
||||||
* than 32, currently this works, but if the are more user, another way needed
|
* 32, currently this works, but if the are more user, another way needed
|
||||||
*/
|
*/
|
||||||
#define QOS_USERS \
|
#define QOS_USERS ((1 << (APP_SYSFREQ_USER_AI_VOICE)) | \
|
||||||
((1 << (APP_SYSFREQ_USER_AI_VOICE)) | (1 << (APP_SYSFREQ_USER_BT_A2DP)))
|
(1 << (APP_SYSFREQ_USER_BT_A2DP)))
|
||||||
|
|
||||||
static const uint32_t freq_map[] = {
|
static const uint32_t freq_map[] = {
|
||||||
[HAL_CMU_FREQ_32K] = FREQ_FREE, [HAL_CMU_FREQ_26M] = FREQ_26M,
|
[HAL_CMU_FREQ_32K] = FREQ_FREE,
|
||||||
[HAL_CMU_FREQ_52M] = FREQ_52M, [HAL_CMU_FREQ_78M] = FREQ_78M,
|
[HAL_CMU_FREQ_26M] = FREQ_26M,
|
||||||
[HAL_CMU_FREQ_104M] = FREQ_104M, [HAL_CMU_FREQ_208M] = FREQ_208M,
|
[HAL_CMU_FREQ_52M] = FREQ_52M,
|
||||||
|
[HAL_CMU_FREQ_78M] = FREQ_78M,
|
||||||
|
[HAL_CMU_FREQ_104M] = FREQ_104M,
|
||||||
|
[HAL_CMU_FREQ_208M] = FREQ_208M,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint32_t user_map[] = {
|
static const uint32_t user_map[] = {
|
||||||
|
@ -86,8 +89,8 @@ static uint32_t qos_freqs_map;
|
||||||
*/
|
*/
|
||||||
static uint32_t qos_users_map;
|
static uint32_t qos_users_map;
|
||||||
|
|
||||||
static int app_qosfreq_req(enum APP_SYSFREQ_USER_T user,
|
static int app_qosfreq_req(enum APP_SYSFREQ_USER_T user, enum APP_SYSFREQ_FREQ_T freq)
|
||||||
enum APP_SYSFREQ_FREQ_T freq) {
|
{
|
||||||
int ret;
|
int ret;
|
||||||
int qos_freq_num = 0;
|
int qos_freq_num = 0;
|
||||||
uint32_t max_qos_freq = 0;
|
uint32_t max_qos_freq = 0;
|
||||||
|
@ -157,23 +160,21 @@ static int app_qosfreq_req(enum APP_SYSFREQ_USER_T user,
|
||||||
|
|
||||||
user = APP_SYSFREQ_USER_QOS;
|
user = APP_SYSFREQ_USER_QOS;
|
||||||
TRACE(2, "User %d require sysfreq %d", user, qos_freq_num);
|
TRACE(2, "User %d require sysfreq %d", user, qos_freq_num);
|
||||||
ret = hal_sysfreq_req((enum HAL_SYSFREQ_USER_T)user,
|
ret = hal_sysfreq_req((enum HAL_SYSFREQ_USER_T)user, (enum HAL_CMU_FREQ_T)qos_freq_num);
|
||||||
(enum HAL_CMU_FREQ_T)qos_freq_num);
|
|
||||||
|
|
||||||
int_unlock(lock);
|
int_unlock(lock);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_sysfreq_req(enum APP_SYSFREQ_USER_T user,
|
int app_sysfreq_req(enum APP_SYSFREQ_USER_T user, enum APP_SYSFREQ_FREQ_T freq)
|
||||||
enum APP_SYSFREQ_FREQ_T freq) {
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
// if user is qos user
|
// if user is qos user
|
||||||
if ((1 << user) & QOS_USERS) {
|
if ((1 << user) & QOS_USERS) {
|
||||||
ret = app_qosfreq_req(user, freq);
|
ret = app_qosfreq_req(user, freq);
|
||||||
} else { // if user is NOT qos user
|
} else { // if user is NOT qos user
|
||||||
ret = hal_sysfreq_req((enum HAL_SYSFREQ_USER_T)user,
|
ret = hal_sysfreq_req((enum HAL_SYSFREQ_USER_T)user, (enum HAL_CMU_FREQ_T)freq);
|
||||||
(enum HAL_CMU_FREQ_T)freq);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -187,24 +188,28 @@ static osTimerId wdt_ping_timer_id;
|
||||||
osTimerDef(wdt_ping_timer, watchdog_ping_handler);
|
osTimerDef(wdt_ping_timer, watchdog_ping_handler);
|
||||||
static uint32_t wdt_ping_period;
|
static uint32_t wdt_ping_period;
|
||||||
|
|
||||||
static void watchdog_ping(void) {
|
static void watchdog_ping(void)
|
||||||
|
{
|
||||||
hal_wdt_ping(HAL_WDT_ID_0);
|
hal_wdt_ping(HAL_WDT_ID_0);
|
||||||
#ifndef CHIP_BEST2000
|
#ifndef CHIP_BEST2000
|
||||||
pmu_wdt_feed();
|
pmu_wdt_feed();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void app_wdt_irq_handle(enum HAL_WDT_ID_T id, uint32_t status) {
|
static void app_wdt_irq_handle(enum HAL_WDT_ID_T id, uint32_t status)
|
||||||
|
{
|
||||||
analog_aud_codec_mute();
|
analog_aud_codec_mute();
|
||||||
ASSERT(0, "%s id:%d status:%d",__func__, id, status);
|
ASSERT(0, "%s id:%d status:%d",__func__, id, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pmu_wdt_irq_handle(void) {
|
static void pmu_wdt_irq_handle(void)
|
||||||
|
{
|
||||||
analog_aud_codec_mute();
|
analog_aud_codec_mute();
|
||||||
ASSERT(1, "%s", __func__);
|
ASSERT(1, "%s", __func__);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void watchdog_ping_handler(void const *unused) {
|
static void watchdog_ping_handler(void const *unused)
|
||||||
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
watchdog_ping();
|
watchdog_ping();
|
||||||
|
@ -216,7 +221,8 @@ static void watchdog_ping_handler(void const *unused) {
|
||||||
osTimerStart(wdt_ping_timer_id, wdt_ping_period);
|
osTimerStart(wdt_ping_timer_id, wdt_ping_period);
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_wdt_open(int seconds) {
|
int app_wdt_open(int seconds)
|
||||||
|
{
|
||||||
uint32_t lock = int_lock();
|
uint32_t lock = int_lock();
|
||||||
|
|
||||||
hal_wdt_set_irq_callback(HAL_WDT_ID_0, app_wdt_irq_handle);
|
hal_wdt_set_irq_callback(HAL_WDT_ID_0, app_wdt_irq_handle);
|
||||||
|
@ -239,7 +245,8 @@ int app_wdt_open(int seconds) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_wdt_reopen(int seconds) {
|
int app_wdt_reopen(int seconds)
|
||||||
|
{
|
||||||
uint32_t lock = int_lock();
|
uint32_t lock = int_lock();
|
||||||
hal_wdt_stop(HAL_WDT_ID_0);
|
hal_wdt_stop(HAL_WDT_ID_0);
|
||||||
hal_wdt_set_timeout(HAL_WDT_ID_0, seconds);
|
hal_wdt_set_timeout(HAL_WDT_ID_0, seconds);
|
||||||
|
@ -254,7 +261,8 @@ int app_wdt_reopen(int seconds) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_wdt_close(void) {
|
int app_wdt_close(void)
|
||||||
|
{
|
||||||
uint32_t lock;
|
uint32_t lock;
|
||||||
|
|
||||||
osTimerStop(wdt_ping_timer_id);
|
osTimerStop(wdt_ping_timer_id);
|
||||||
|
@ -270,3 +278,4 @@ int app_wdt_close(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
#ifdef __RAND_FROM_MIC__
|
#ifdef __RAND_FROM_MIC__
|
||||||
#include "randfrommic.h"
|
|
||||||
#include "app_audio.h"
|
|
||||||
#include "app_bt_stream.h"
|
|
||||||
#include "app_utils.h"
|
|
||||||
#include "audioflinger.h"
|
#include "audioflinger.h"
|
||||||
#include "cmsis_gcc.h"
|
|
||||||
#include "cmsis_os.h"
|
|
||||||
#include "hal_timer.h"
|
|
||||||
#include "hal_trace.h"
|
#include "hal_trace.h"
|
||||||
#include "stdio.h"
|
#include "app_utils.h"
|
||||||
#include "stdlib.h"
|
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
#include "stdlib.h"
|
||||||
|
#include "stdio.h"
|
||||||
|
#include "app_bt_stream.h"
|
||||||
|
#include "randfrommic.h"
|
||||||
|
#include "hal_timer.h"
|
||||||
|
#include "cmsis_os.h"
|
||||||
|
#include "cmsis_gcc.h"
|
||||||
|
#include "app_audio.h"
|
||||||
|
|
||||||
#if BT_DRV_DEBUG
|
#if BT_DRV_DEBUG
|
||||||
#define RAND_TRACE(n, fmt, ...) TRACE(n, fmt, ##__VA_ARGS__)
|
#define RAND_TRACE(n, fmt, ...) TRACE(n, fmt, ##__VA_ARGS__)
|
||||||
|
@ -32,19 +32,24 @@ static bool randInitialised = false;
|
||||||
#define RAND_GRAB_BITS_PER_SAMPLE 4
|
#define RAND_GRAB_BITS_PER_SAMPLE 4
|
||||||
#define RAND_GRAB_BITS_MASK_PER_SAMPLE ((1 << RAND_GRAB_BITS_PER_SAMPLE)-1)
|
#define RAND_GRAB_BITS_MASK_PER_SAMPLE ((1 << RAND_GRAB_BITS_PER_SAMPLE)-1)
|
||||||
|
|
||||||
RAND_NUMBER_T randomBuffer = {
|
RAND_NUMBER_T randomBuffer =
|
||||||
|
{
|
||||||
25,
|
25,
|
||||||
RAND_STATUS_CLOSE,
|
RAND_STATUS_CLOSE,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description: parse mic data according to the stream cfg(bit mode and channel
|
* Description: parse mic data according to the stream cfg(bit mode and channel number)
|
||||||
* number) only the lowest byte of each frame is taken ADC format: 16bit mode ->
|
* only the lowest byte of each frame is taken
|
||||||
* [15:0] is valid 24bit mode -> [23:4] is valid 32bit mode -> [31:12] is valid
|
* ADC format:
|
||||||
|
* 16bit mode -> [15:0] is valid
|
||||||
|
* 24bit mode -> [23:4] is valid
|
||||||
|
* 32bit mode -> [31:12] is valid
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static int randDataParse(uint8_t *buf, uint32_t len, enum AUD_BITS_T bits,
|
static int randDataParse(uint8_t *buf, uint32_t len, enum AUD_BITS_T bits,
|
||||||
enum AUD_CHANNEL_NUM_T ch_num) {
|
enum AUD_CHANNEL_NUM_T ch_num)
|
||||||
|
{
|
||||||
uint8_t index = 0;
|
uint8_t index = 0;
|
||||||
|
|
||||||
union {
|
union {
|
||||||
|
@ -61,46 +66,49 @@ static int randDataParse(uint8_t *buf, uint32_t len, enum AUD_BITS_T bits,
|
||||||
RAND_TRACE(1, "%s", __func__);
|
RAND_TRACE(1, "%s", __func__);
|
||||||
RAND_DUMP("%x ",buf, 16);
|
RAND_DUMP("%x ",buf, 16);
|
||||||
|
|
||||||
switch (bits) {
|
switch (bits)
|
||||||
case AUD_BITS_16: {
|
{
|
||||||
|
case AUD_BITS_16:
|
||||||
|
{
|
||||||
uint16_t* content = (uint16_t *)buf;
|
uint16_t* content = (uint16_t *)buf;
|
||||||
|
|
||||||
for (index = 0; index < 4; index++) {
|
for (index = 0;index < 4; index++)
|
||||||
seedData.value[index] =
|
{
|
||||||
((*content) & RAND_GRAB_BITS_MASK_PER_SAMPLE) |
|
seedData.value[index] = ((*content) & RAND_GRAB_BITS_MASK_PER_SAMPLE) |
|
||||||
(((*(content + ch_num)) & RAND_GRAB_BITS_MASK_PER_SAMPLE)
|
(((*(content+ch_num)) & RAND_GRAB_BITS_MASK_PER_SAMPLE) << RAND_GRAB_BITS_PER_SAMPLE);
|
||||||
<< RAND_GRAB_BITS_PER_SAMPLE);
|
|
||||||
content += ((8/RAND_GRAB_BITS_PER_SAMPLE)*ch_num);
|
content += ((8/RAND_GRAB_BITS_PER_SAMPLE)*ch_num);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case AUD_BITS_24: {
|
case AUD_BITS_24:
|
||||||
|
{
|
||||||
uint32_t* content = (uint32_t *)buf;
|
uint32_t* content = (uint32_t *)buf;
|
||||||
for (index = 0; index < 4; index++) {
|
for (index = 0;index < 4; index++)
|
||||||
|
{
|
||||||
// bit 23:4 are valid
|
// bit 23:4 are valid
|
||||||
seedData.value[index] =
|
seedData.value[index] = (((*content) >> 4) & RAND_GRAB_BITS_MASK_PER_SAMPLE) |
|
||||||
(((*content) >> 4) & RAND_GRAB_BITS_MASK_PER_SAMPLE) |
|
((((*(content+ch_num)) >> 4)&RAND_GRAB_BITS_MASK_PER_SAMPLE) << RAND_GRAB_BITS_PER_SAMPLE);
|
||||||
((((*(content + ch_num)) >> 4) & RAND_GRAB_BITS_MASK_PER_SAMPLE)
|
|
||||||
<< RAND_GRAB_BITS_PER_SAMPLE);
|
|
||||||
content += ((8/RAND_GRAB_BITS_PER_SAMPLE)*ch_num);
|
content += ((8/RAND_GRAB_BITS_PER_SAMPLE)*ch_num);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case AUD_BITS_32: {
|
case AUD_BITS_32:
|
||||||
|
{
|
||||||
uint32_t* content = (uint32_t *)buf;
|
uint32_t* content = (uint32_t *)buf;
|
||||||
for (index = 0; index < 4; index++) {
|
for (index = 0;index < 4; index++)
|
||||||
|
{
|
||||||
// bit 31:12 are valid
|
// bit 31:12 are valid
|
||||||
seedData.value[index] =
|
seedData.value[index] = (((*content) >> 12) & RAND_GRAB_BITS_MASK_PER_SAMPLE) |
|
||||||
(((*content) >> 12) & RAND_GRAB_BITS_MASK_PER_SAMPLE) |
|
((((*(content+ch_num)) >> 12) & RAND_GRAB_BITS_MASK_PER_SAMPLE) << RAND_GRAB_BITS_PER_SAMPLE);
|
||||||
((((*(content + ch_num)) >> 12) & RAND_GRAB_BITS_MASK_PER_SAMPLE)
|
|
||||||
<< RAND_GRAB_BITS_PER_SAMPLE);
|
|
||||||
content += ((8/RAND_GRAB_BITS_PER_SAMPLE)*ch_num);
|
content += ((8/RAND_GRAB_BITS_PER_SAMPLE)*ch_num);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default:
|
||||||
|
{
|
||||||
return -1;
|
return -1;
|
||||||
} break;
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
randSeed = seedData.seedValue;
|
randSeed = seedData.seedValue;
|
||||||
|
@ -108,18 +116,21 @@ static int randDataParse(uint8_t *buf, uint32_t len, enum AUD_BITS_T bits,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void generateRand(bool on) {
|
static void generateRand(bool on)
|
||||||
|
{
|
||||||
struct AF_STREAM_CONFIG_T stream_cfg;
|
struct AF_STREAM_CONFIG_T stream_cfg;
|
||||||
|
|
||||||
RAND_TRACE(2, "%s op:%d", __func__, on);
|
RAND_TRACE(2, "%s op:%d", __func__, on);
|
||||||
|
|
||||||
if (on) {
|
if (on)
|
||||||
|
{
|
||||||
randomBuffer.skipRound = 10;
|
randomBuffer.skipRound = 10;
|
||||||
|
|
||||||
randomBuffer.status = random_mic_is_on(&deviceId);
|
randomBuffer.status = random_mic_is_on(&deviceId);
|
||||||
RAND_TRACE(2, "%s random status = %d", __func__, randomBuffer.status);
|
RAND_TRACE(2, "%s random status = %d", __func__, randomBuffer.status);
|
||||||
|
|
||||||
if (RAND_STATUS_CLOSE == randomBuffer.status) {
|
if (RAND_STATUS_CLOSE == randomBuffer.status)
|
||||||
|
{
|
||||||
app_sysfreq_req(APP_SYSFREQ_USER_RANDOM, APP_SYSFREQ_208M);
|
app_sysfreq_req(APP_SYSFREQ_USER_RANDOM, APP_SYSFREQ_208M);
|
||||||
app_capture_audio_mempool_init();
|
app_capture_audio_mempool_init();
|
||||||
app_capture_audio_mempool_get_buff(&captureBuffer,
|
app_capture_audio_mempool_get_buff(&captureBuffer,
|
||||||
|
@ -138,15 +149,22 @@ static void generateRand(bool on) {
|
||||||
af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE, &stream_cfg);
|
af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE, &stream_cfg);
|
||||||
af_stream_start(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
af_stream_start(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
||||||
randomBuffer.status = RAND_STATUS_OPEN;
|
randomBuffer.status = RAND_STATUS_OPEN;
|
||||||
} else if (RAND_STATUS_MIC_OPENED == randomBuffer.status) {
|
}
|
||||||
|
else if(RAND_STATUS_MIC_OPENED == randomBuffer.status)
|
||||||
|
{
|
||||||
af_stream_start(deviceId, AUD_STREAM_CAPTURE);
|
af_stream_start(deviceId, AUD_STREAM_CAPTURE);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
// release the acquired system clock
|
// release the acquired system clock
|
||||||
app_sysfreq_req(APP_SYSFREQ_USER_RANDOM, APP_SYSFREQ_32K);
|
app_sysfreq_req(APP_SYSFREQ_USER_RANDOM, APP_SYSFREQ_32K);
|
||||||
if (RAND_STATUS_MIC_OPENED == randomBuffer.status) {
|
if (RAND_STATUS_MIC_OPENED == randomBuffer.status)
|
||||||
|
{
|
||||||
af_stream_stop(deviceId, AUD_STREAM_CAPTURE);
|
af_stream_stop(deviceId, AUD_STREAM_CAPTURE);
|
||||||
} else if (RAND_STATUS_OPEN == randomBuffer.status) {
|
}
|
||||||
|
else if (RAND_STATUS_OPEN == randomBuffer.status)
|
||||||
|
{
|
||||||
af_stream_stop(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
af_stream_stop(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
||||||
af_stream_close(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
af_stream_close(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
||||||
}
|
}
|
||||||
|
@ -154,37 +172,46 @@ static void generateRand(bool on) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t rand_data_handle(uint8_t *buf, uint32_t len) {
|
static uint32_t rand_data_handle(uint8_t *buf, uint32_t len)
|
||||||
if (buf == NULL) {
|
{
|
||||||
|
if (buf == NULL)
|
||||||
|
{
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((1 == randomBuffer.skipRound) &&
|
if ((1 == randomBuffer.skipRound) &&
|
||||||
(!randDataParse(buf, len, AUD_BITS_16, AUD_CHANNEL_NUM_1))) {
|
(!randDataParse(buf, len, AUD_BITS_16, AUD_CHANNEL_NUM_1)))
|
||||||
|
{
|
||||||
generateRand(false);
|
generateRand(false);
|
||||||
randomBuffer.skipRound = 0;
|
randomBuffer.skipRound = 0;
|
||||||
} else if (1 != randomBuffer.skipRound) {
|
}
|
||||||
|
else if (1 != randomBuffer.skipRound)
|
||||||
|
{
|
||||||
randomBuffer.skipRound--;
|
randomBuffer.skipRound--;
|
||||||
}
|
}
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
void initSeed(void) {
|
void initSeed(void)
|
||||||
|
{
|
||||||
uint8_t count = 100; // avoid deed loop
|
uint8_t count = 100; // avoid deed loop
|
||||||
|
|
||||||
RAND_TRACE(2, "%s:+++ initialised = %d", __func__, randInitialised);
|
RAND_TRACE(2, "%s:+++ initialised = %d", __func__, randInitialised);
|
||||||
|
|
||||||
if (randInitialised) {
|
if (randInitialised)
|
||||||
|
{
|
||||||
generateRand(true);
|
generateRand(true);
|
||||||
|
|
||||||
while ((0 != randomBuffer.skipRound) && (0 != count)) {
|
while ((0 != randomBuffer.skipRound) && (0 != count))
|
||||||
|
{
|
||||||
osDelay(10);
|
osDelay(10);
|
||||||
count --;
|
count --;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((0 == count) || (false == randInitialised)) {
|
if ((0 == count) || (false == randInitialised))
|
||||||
|
{
|
||||||
RAND_TRACE(1, "%s not ready", __func__);
|
RAND_TRACE(1, "%s not ready", __func__);
|
||||||
randSeed = (uint32_t)hal_sys_timer_get();
|
randSeed = (uint32_t)hal_sys_timer_get();
|
||||||
generateRand(false);
|
generateRand(false);
|
||||||
|
@ -194,36 +221,47 @@ void initSeed(void) {
|
||||||
RAND_TRACE(2, "%s:--- count = %d", __func__, count);
|
RAND_TRACE(2, "%s:--- count = %d", __func__, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
void random_status_sync(void) {
|
void random_status_sync(void)
|
||||||
if (RAND_STATUS_OPEN == randomBuffer.status) {
|
{
|
||||||
|
if (RAND_STATUS_OPEN == randomBuffer.status)
|
||||||
|
{
|
||||||
RAND_TRACE(1, "%s random mic has already on,should be closed", __func__);
|
RAND_TRACE(1, "%s random mic has already on,should be closed", __func__);
|
||||||
generateRand(false);
|
generateRand(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void random_data_process(uint8_t *buf, uint32_t len,enum AUD_BITS_T bits,
|
void random_data_process(uint8_t *buf, uint32_t len,enum AUD_BITS_T bits,
|
||||||
enum AUD_CHANNEL_NUM_T ch_num) {
|
enum AUD_CHANNEL_NUM_T ch_num)
|
||||||
if (buf == NULL) {
|
{
|
||||||
|
if (buf == NULL)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((RAND_STATUS_MIC_STARTED == randomBuffer.status) ||
|
if ((RAND_STATUS_MIC_STARTED == randomBuffer.status) ||
|
||||||
(RAND_STATUS_MIC_OPENED == randomBuffer.status)) {
|
(RAND_STATUS_MIC_OPENED == randomBuffer.status))
|
||||||
if (len >= RANDOM_CAPTURE_BUFFER_SIZE / 2) {
|
{
|
||||||
RAND_TRACE(4, "%s buf address = 0x%p, bits = %d, channel num = %d",
|
if (len >= RANDOM_CAPTURE_BUFFER_SIZE/2)
|
||||||
__func__, buf, bits, ch_num);
|
{
|
||||||
|
RAND_TRACE(4, "%s buf address = 0x%p, bits = %d, channel num = %d", __func__, buf, bits, ch_num);
|
||||||
RAND_DUMP("%02x ", buf, 32);
|
RAND_DUMP("%02x ", buf, 32);
|
||||||
if ((1 == randomBuffer.skipRound) &&
|
if ((1 == randomBuffer.skipRound) &&
|
||||||
(!randDataParse(buf, len, bits, ch_num))) {
|
(!randDataParse(buf, len, bits, ch_num)))
|
||||||
|
{
|
||||||
generateRand(false);
|
generateRand(false);
|
||||||
randomBuffer.skipRound = 0;
|
randomBuffer.skipRound = 0;
|
||||||
} else if (1 != randomBuffer.skipRound) {
|
}
|
||||||
|
else if (1 != randomBuffer.skipRound)
|
||||||
|
{
|
||||||
randomBuffer.skipRound--;
|
randomBuffer.skipRound--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void randInit(void) { randInitialised = true; }
|
void randInit(void)
|
||||||
|
{
|
||||||
|
randInitialised = true;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -18,6 +18,7 @@ ccflags-y += \
|
||||||
-Iapps/key \
|
-Iapps/key \
|
||||||
-Iplatform/drivers/bt \
|
-Iplatform/drivers/bt \
|
||||||
-Iplatform/drivers/ana \
|
-Iplatform/drivers/ana \
|
||||||
|
-Iplatform/drivers/usb/usb_dev/inc \
|
||||||
-Iapps/battery \
|
-Iapps/battery \
|
||||||
-Iservices/multimedia/audio/codec/sbc/inc \
|
-Iservices/multimedia/audio/codec/sbc/inc \
|
||||||
-Iservices/multimedia/audio/codec/sbc/src/inc \
|
-Iservices/multimedia/audio/codec/sbc/src/inc \
|
||||||
|
|
|
@ -13,44 +13,46 @@
|
||||||
* trademark and other intellectual property rights.
|
* trademark and other intellectual property rights.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include "app_factory.h"
|
|
||||||
#include "app_bt_stream.h"
|
|
||||||
#include "app_key.h"
|
|
||||||
#include "app_media_player.h"
|
|
||||||
#include "bluetooth.h"
|
|
||||||
#include "bt_drv_interface.h"
|
|
||||||
#include "bt_drv_reg_op.h"
|
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
|
#include "list.h"
|
||||||
|
#include "hal_trace.h"
|
||||||
#include "hal_bootmode.h"
|
#include "hal_bootmode.h"
|
||||||
#include "hal_cmu.h"
|
#include "hal_cmu.h"
|
||||||
#include "hal_sleep.h"
|
#include "hal_sleep.h"
|
||||||
#include "hal_trace.h"
|
#include "app_key.h"
|
||||||
#include "list.h"
|
#include "app_factory.h"
|
||||||
|
#include "bt_drv_interface.h"
|
||||||
|
#include "bt_drv_reg_op.h"
|
||||||
|
#include "bluetooth.h"
|
||||||
#include "nvrecord.h"
|
#include "nvrecord.h"
|
||||||
#include "nvrecord_dev.h"
|
#include "nvrecord_dev.h"
|
||||||
#include "nvrecord_env.h"
|
#include "nvrecord_env.h"
|
||||||
#include "pmu.h"
|
|
||||||
#include "resources.h"
|
#include "resources.h"
|
||||||
|
#include "app_bt_stream.h"
|
||||||
|
#include "app_media_player.h"
|
||||||
|
#include "pmu.h"
|
||||||
|
|
||||||
// for init
|
// for init
|
||||||
#include "app_battery.h"
|
#include "apps.h"
|
||||||
#include "app_key.h"
|
|
||||||
#include "app_overlay.h"
|
|
||||||
#include "app_pwl.h"
|
|
||||||
#include "app_status_ind.h"
|
#include "app_status_ind.h"
|
||||||
#include "app_thread.h"
|
#include "app_thread.h"
|
||||||
|
#include "app_key.h"
|
||||||
|
#include "app_pwl.h"
|
||||||
|
#include "app_overlay.h"
|
||||||
|
#include "app_battery.h"
|
||||||
#include "app_utils.h"
|
#include "app_utils.h"
|
||||||
#include "apps.h"
|
|
||||||
|
|
||||||
// for bt
|
// for bt
|
||||||
|
#include "besbt.h"
|
||||||
#include "app_bt.h"
|
#include "app_bt.h"
|
||||||
#include "app_factory_bt.h"
|
#include "app_factory_bt.h"
|
||||||
#include "besbt.h"
|
|
||||||
|
|
||||||
// for audio
|
// for audio
|
||||||
|
#include "audioflinger.h"
|
||||||
#include "app_audio.h"
|
#include "app_audio.h"
|
||||||
#include "app_utils.h"
|
#include "app_utils.h"
|
||||||
#include "audioflinger.h"
|
|
||||||
|
|
||||||
|
|
||||||
// for progress
|
// for progress
|
||||||
#include "hal_uart.h"
|
#include "hal_uart.h"
|
||||||
|
@ -76,22 +78,20 @@ void app_bt_key_shutdown(APP_KEY_STATUS *status, void *param);
|
||||||
void app_factorymode_result_set(bool result);
|
void app_factorymode_result_set(bool result);
|
||||||
|
|
||||||
static osThreadId app_factorymode_tid= NULL;
|
static osThreadId app_factorymode_tid= NULL;
|
||||||
static struct message_t send_msg = {
|
static struct message_t send_msg = { { PREFIX_CHAR, }, };
|
||||||
{
|
|
||||||
PREFIX_CHAR,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
static unsigned char send_seq = 0;
|
static unsigned char send_seq = 0;
|
||||||
|
|
||||||
osTimerId app_factory_timer = NULL;
|
osTimerId app_factory_timer = NULL;
|
||||||
osTimerDef (APP_FACTORY_TIMER, app_factorymode_timehandler);
|
osTimerDef (APP_FACTORY_TIMER, app_factorymode_timehandler);
|
||||||
|
|
||||||
int app_factorymode_languageswitch_proc(void) {
|
int app_factorymode_languageswitch_proc(void)
|
||||||
|
{
|
||||||
#ifdef MEDIA_PLAYER_SUPPORT
|
#ifdef MEDIA_PLAYER_SUPPORT
|
||||||
int lan;
|
int lan;
|
||||||
int new_lan;
|
int new_lan;
|
||||||
struct nvrecord_env_t *nvrecord_env;
|
struct nvrecord_env_t *nvrecord_env;
|
||||||
|
|
||||||
|
|
||||||
APP_FACTORY_TRACE(1,"%s",__func__);
|
APP_FACTORY_TRACE(1,"%s",__func__);
|
||||||
lan = app_play_audio_get_lang();
|
lan = app_play_audio_get_lang();
|
||||||
new_lan = lan;
|
new_lan = lan;
|
||||||
|
@ -107,14 +107,15 @@ int app_factorymode_languageswitch_proc(void) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void app_factorymode_languageswitch(APP_KEY_STATUS *status, void *param) {
|
void app_factorymode_languageswitch(APP_KEY_STATUS *status, void *param)
|
||||||
|
{
|
||||||
app_factorymode_languageswitch_proc();
|
app_factorymode_languageswitch_proc();
|
||||||
}
|
}
|
||||||
|
|
||||||
void app_factorymode_enter(void) {
|
void app_factorymode_enter(void)
|
||||||
|
{
|
||||||
APP_FACTORY_TRACE(1,"%s",__func__);
|
APP_FACTORY_TRACE(1,"%s",__func__);
|
||||||
hal_sw_bootmode_set(HAL_SW_BOOTMODE_TEST_MODE |
|
hal_sw_bootmode_set(HAL_SW_BOOTMODE_TEST_MODE|HAL_SW_BOOTMODE_TEST_SIGNALINGMODE);
|
||||||
HAL_SW_BOOTMODE_TEST_SIGNALINGMODE);
|
|
||||||
hal_cmu_sys_reboot();
|
hal_cmu_sys_reboot();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,12 +123,20 @@ extern "C" {
|
||||||
|
|
||||||
static bool isInFactoryMode = false;
|
static bool isInFactoryMode = false;
|
||||||
|
|
||||||
bool app_factorymode_get(void) { return isInFactoryMode; }
|
bool app_factorymode_get(void)
|
||||||
|
{
|
||||||
|
return isInFactoryMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
void app_factorymode_set(bool set)
|
||||||
|
{
|
||||||
|
isInFactoryMode = set;
|
||||||
|
}
|
||||||
|
|
||||||
void app_factorymode_set(bool set) { isInFactoryMode = set; }
|
|
||||||
}
|
}
|
||||||
#ifdef POWERKEY_I2C_SWITCH
|
#ifdef POWERKEY_I2C_SWITCH
|
||||||
void app_factorymode_i2c_switch(APP_KEY_STATUS *status, void *param) {
|
void app_factorymode_i2c_switch(APP_KEY_STATUS *status, void *param)
|
||||||
|
{
|
||||||
static int i = 0;
|
static int i = 0;
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
|
@ -145,49 +154,30 @@ void app_factorymode_i2c_switch(APP_KEY_STATUS *status, void *param) {
|
||||||
|
|
||||||
#ifdef __IBRT_IBRT_TESTMODE__
|
#ifdef __IBRT_IBRT_TESTMODE__
|
||||||
void bt_drv_ibrt_test_key_click(APP_KEY_STATUS *status, void *param);
|
void bt_drv_ibrt_test_key_click(APP_KEY_STATUS *status, void *param);
|
||||||
void bt_drv_ibrt_test_key_click(APP_KEY_STATUS *status, void *param) {
|
void bt_drv_ibrt_test_key_click(APP_KEY_STATUS *status, void *param)
|
||||||
|
{
|
||||||
btdrv_connect_ibrt_device(bt_addr);
|
btdrv_connect_ibrt_device(bt_addr);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void app_factorymode_key_init(void) {
|
void app_factorymode_key_init(void)
|
||||||
|
{
|
||||||
const APP_KEY_HANDLE app_factorymode_handle_cfg[] = {
|
const APP_KEY_HANDLE app_factorymode_handle_cfg[] = {
|
||||||
#ifdef POWERKEY_I2C_SWITCH
|
#ifdef POWERKEY_I2C_SWITCH
|
||||||
{{APP_KEY_CODE_PWR, APP_KEY_EVENT_RAMPAGECLICK},
|
{{APP_KEY_CODE_PWR,APP_KEY_EVENT_RAMPAGECLICK},"bt i2c key",app_factorymode_i2c_switch, NULL},
|
||||||
"bt i2c key",
|
|
||||||
app_factorymode_i2c_switch,
|
|
||||||
NULL},
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef __POWERKEY_CTRL_ONOFF_ONLY__
|
#ifdef __POWERKEY_CTRL_ONOFF_ONLY__
|
||||||
{{APP_KEY_CODE_PWR, APP_KEY_EVENT_UP},
|
{{APP_KEY_CODE_PWR,APP_KEY_EVENT_UP},"bt function key",app_bt_key_shutdown, NULL},
|
||||||
"bt function key",
|
|
||||||
app_bt_key_shutdown,
|
|
||||||
NULL},
|
|
||||||
#else
|
#else
|
||||||
{{APP_KEY_CODE_PWR, APP_KEY_EVENT_LONGLONGPRESS},
|
{{APP_KEY_CODE_PWR,APP_KEY_EVENT_LONGLONGPRESS},"bt function key",app_bt_key_shutdown, NULL},
|
||||||
"bt function key",
|
|
||||||
app_bt_key_shutdown,
|
|
||||||
NULL},
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef __IBRT_IBRT_TESTMODE__
|
#ifdef __IBRT_IBRT_TESTMODE__
|
||||||
{{APP_KEY_CODE_PWR, APP_KEY_EVENT_CLICK},
|
{{APP_KEY_CODE_PWR,APP_KEY_EVENT_CLICK},"bt function key",bt_drv_ibrt_test_key_click, NULL},
|
||||||
"bt function key",
|
|
||||||
bt_drv_ibrt_test_key_click,
|
|
||||||
NULL},
|
|
||||||
#else
|
#else
|
||||||
{{APP_KEY_CODE_PWR, APP_KEY_EVENT_CLICK},
|
{{APP_KEY_CODE_PWR,APP_KEY_EVENT_CLICK},"bt function key",app_factorymode_languageswitch, NULL},
|
||||||
"bt function key",
|
|
||||||
app_factorymode_languageswitch,
|
|
||||||
NULL},
|
|
||||||
#endif
|
#endif
|
||||||
{{APP_KEY_CODE_PWR, APP_KEY_EVENT_DOUBLECLICK},
|
{{APP_KEY_CODE_PWR,APP_KEY_EVENT_DOUBLECLICK},"bt function key",app_factorymode_bt_xtalcalib, NULL},
|
||||||
"bt function key",
|
{{APP_KEY_CODE_PWR,APP_KEY_EVENT_LONGPRESS},"bt function key",app_factorymode_bt_signalingtest, NULL},
|
||||||
app_factorymode_bt_xtalcalib,
|
|
||||||
NULL},
|
|
||||||
{{APP_KEY_CODE_PWR, APP_KEY_EVENT_LONGPRESS},
|
|
||||||
"bt function key",
|
|
||||||
app_factorymode_bt_signalingtest,
|
|
||||||
NULL},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
uint8_t i = 0;
|
uint8_t i = 0;
|
||||||
|
@ -195,68 +185,70 @@ void app_factorymode_key_init(void) {
|
||||||
APP_FACTORY_TRACE(1,"%s",__func__);
|
APP_FACTORY_TRACE(1,"%s",__func__);
|
||||||
|
|
||||||
app_key_handle_clear();
|
app_key_handle_clear();
|
||||||
for (i = 0; i < (sizeof(app_factorymode_handle_cfg) / sizeof(APP_KEY_HANDLE));
|
for (i=0; i<(sizeof(app_factorymode_handle_cfg)/sizeof(APP_KEY_HANDLE)); i++){
|
||||||
i++) {
|
|
||||||
app_key_handle_registration(&app_factorymode_handle_cfg[i]);
|
app_key_handle_registration(&app_factorymode_handle_cfg[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void app_factorymode_audioloopswitch(APP_KEY_STATUS *status,
|
static void app_factorymode_audioloopswitch(APP_KEY_STATUS *status, void *param)
|
||||||
void *param) {
|
{
|
||||||
static bool onaudioloop = false;
|
static bool onaudioloop = false;
|
||||||
|
|
||||||
onaudioloop = onaudioloop?false:true;
|
onaudioloop = onaudioloop?false:true;
|
||||||
|
|
||||||
if (onaudioloop)
|
if (onaudioloop)
|
||||||
app_audio_sendrequest(APP_FACTORYMODE_AUDIO_LOOP,
|
app_audio_sendrequest(APP_FACTORYMODE_AUDIO_LOOP, (uint8_t)APP_BT_SETTING_OPEN, 0);
|
||||||
(uint8_t)APP_BT_SETTING_OPEN, 0);
|
|
||||||
else
|
else
|
||||||
app_audio_sendrequest(APP_FACTORYMODE_AUDIO_LOOP,
|
app_audio_sendrequest(APP_FACTORYMODE_AUDIO_LOOP, (uint8_t)APP_BT_SETTING_CLOSE, 0);
|
||||||
(uint8_t)APP_BT_SETTING_CLOSE, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void app_factorymode_test_key_init(void) {
|
void app_factorymode_test_key_init(void)
|
||||||
|
{
|
||||||
const APP_KEY_HANDLE app_factorymode_handle_cfg[] = {
|
const APP_KEY_HANDLE app_factorymode_handle_cfg[] = {
|
||||||
{{APP_KEY_CODE_PWR, APP_KEY_EVENT_CLICK},
|
{{APP_KEY_CODE_PWR,APP_KEY_EVENT_CLICK},"bt function key",app_factorymode_audioloopswitch, NULL},
|
||||||
"bt function key",
|
|
||||||
app_factorymode_audioloopswitch,
|
|
||||||
NULL},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
uint8_t i = 0;
|
uint8_t i = 0;
|
||||||
APP_FACTORY_TRACE(1,"%s",__func__);
|
APP_FACTORY_TRACE(1,"%s",__func__);
|
||||||
for (i = 0; i < (sizeof(app_factorymode_handle_cfg) / sizeof(APP_KEY_HANDLE));
|
for (i=0; i<(sizeof(app_factorymode_handle_cfg)/sizeof(APP_KEY_HANDLE)); i++){
|
||||||
i++) {
|
|
||||||
app_key_handle_registration(&app_factorymode_handle_cfg[i]);
|
app_key_handle_registration(&app_factorymode_handle_cfg[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void app_factorymode_result_clean(void) {
|
void app_factorymode_result_clean(void)
|
||||||
|
{
|
||||||
osSignalClear(app_factorymode_tid, 0x01);
|
osSignalClear(app_factorymode_tid, 0x01);
|
||||||
osSignalClear(app_factorymode_tid, 0x02);
|
osSignalClear(app_factorymode_tid, 0x02);
|
||||||
}
|
}
|
||||||
|
|
||||||
void app_factorymode_result_set(bool result) {
|
void app_factorymode_result_set(bool result)
|
||||||
|
{
|
||||||
if (result)
|
if (result)
|
||||||
osSignalSet(app_factorymode_tid ,0x01);
|
osSignalSet(app_factorymode_tid ,0x01);
|
||||||
else
|
else
|
||||||
osSignalSet(app_factorymode_tid ,0x02);
|
osSignalSet(app_factorymode_tid ,0x02);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool app_factorymode_result_wait(void) {
|
bool app_factorymode_result_wait(void)
|
||||||
|
{
|
||||||
bool nRet;
|
bool nRet;
|
||||||
osEvent evt;
|
osEvent evt;
|
||||||
|
|
||||||
while (1) {
|
while(1)
|
||||||
|
{
|
||||||
//wait any signal
|
//wait any signal
|
||||||
evt = osSignalWait(0x0, osWaitForever);
|
evt = osSignalWait(0x0, osWaitForever);
|
||||||
|
|
||||||
//get role from signal value
|
//get role from signal value
|
||||||
if (evt.status == osEventSignal) {
|
if(evt.status == osEventSignal)
|
||||||
if (evt.value.signals & 0x01) {
|
{
|
||||||
|
if(evt.value.signals & 0x01)
|
||||||
|
{
|
||||||
nRet = true;
|
nRet = true;
|
||||||
break;
|
break;
|
||||||
} else if (evt.value.signals & 0x02) {
|
}
|
||||||
|
else if(evt.value.signals & 0x02)
|
||||||
|
{
|
||||||
nRet = false;
|
nRet = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -265,7 +257,8 @@ bool app_factorymode_result_wait(void) {
|
||||||
return nRet;
|
return nRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int app_factorymode_send_progress(uint8_t progress) {
|
static int app_factorymode_send_progress (uint8_t progress)
|
||||||
|
{
|
||||||
APP_MESSAGE_BLOCK msg;
|
APP_MESSAGE_BLOCK msg;
|
||||||
|
|
||||||
msg.mod_id = APP_MODUAL_OHTER;
|
msg.mod_id = APP_MODUAL_OHTER;
|
||||||
|
@ -276,7 +269,8 @@ static int app_factorymode_send_progress(uint8_t progress) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int app_factorymode_send_code(uint32_t progress) {
|
static int app_factorymode_send_code (uint32_t progress)
|
||||||
|
{
|
||||||
APP_MESSAGE_BLOCK msg;
|
APP_MESSAGE_BLOCK msg;
|
||||||
|
|
||||||
msg.mod_id = APP_MODUAL_OHTER;
|
msg.mod_id = APP_MODUAL_OHTER;
|
||||||
|
@ -287,7 +281,8 @@ static int app_factorymode_send_code(uint32_t progress) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_factorymode_proc(void) {
|
int app_factorymode_proc(void)
|
||||||
|
{
|
||||||
uint8_t cnt = 0;
|
uint8_t cnt = 0;
|
||||||
bool nRet;
|
bool nRet;
|
||||||
app_factorymode_tid = osThreadGetId();
|
app_factorymode_tid = osThreadGetId();
|
||||||
|
@ -318,8 +313,8 @@ exit:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned char app_factorymode_msg_check_sum(unsigned char *buf,
|
static unsigned char app_factorymode_msg_check_sum(unsigned char *buf, unsigned char len)
|
||||||
unsigned char len) {
|
{
|
||||||
int i;
|
int i;
|
||||||
unsigned char sum = 0;
|
unsigned char sum = 0;
|
||||||
|
|
||||||
|
@ -330,7 +325,8 @@ static unsigned char app_factorymode_msg_check_sum(unsigned char *buf,
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int app_factorymode_msg_uart_send(const unsigned char *buf, size_t len) {
|
static int app_factorymode_msg_uart_send(const unsigned char *buf, size_t len)
|
||||||
|
{
|
||||||
uint32_t sent = 0;
|
uint32_t sent = 0;
|
||||||
|
|
||||||
while (sent < len) {
|
while (sent < len) {
|
||||||
|
@ -344,7 +340,8 @@ static int app_factorymode_msg_uart_send(const unsigned char *buf, size_t len) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int app_factorymode_msg_send_ping(void) {
|
static int app_factorymode_msg_send_ping(void)
|
||||||
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
send_msg.hdr.type = 0x88;
|
send_msg.hdr.type = 0x88;
|
||||||
|
@ -352,16 +349,15 @@ static int app_factorymode_msg_send_ping(void) {
|
||||||
send_msg.hdr.len = 2;
|
send_msg.hdr.len = 2;
|
||||||
send_msg.data[0] = 0xaa;
|
send_msg.data[0] = 0xaa;
|
||||||
send_msg.data[1] = 0x55;
|
send_msg.data[1] = 0x55;
|
||||||
send_msg.data[2] = ~app_factorymode_msg_check_sum(
|
send_msg.data[2] = ~app_factorymode_msg_check_sum((unsigned char *)&send_msg, MSG_TOTAL_LEN(&send_msg) - 1);
|
||||||
(unsigned char *)&send_msg, MSG_TOTAL_LEN(&send_msg) - 1);
|
|
||||||
|
|
||||||
ret = app_factorymode_msg_uart_send((unsigned char *)&send_msg,
|
ret = app_factorymode_msg_uart_send((unsigned char *)&send_msg, MSG_TOTAL_LEN(&send_msg));
|
||||||
MSG_TOTAL_LEN(&send_msg));
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int app_factorymode_msg_send_progress(uint8_t progress) {
|
static int app_factorymode_msg_send_progress (uint8_t progress)
|
||||||
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
send_msg.hdr.type = 0x88;
|
send_msg.hdr.type = 0x88;
|
||||||
|
@ -369,16 +365,15 @@ static int app_factorymode_msg_send_progress(uint8_t progress) {
|
||||||
send_msg.hdr.len = 2;
|
send_msg.hdr.len = 2;
|
||||||
send_msg.data[0] = progress;
|
send_msg.data[0] = progress;
|
||||||
send_msg.data[1] = 100;
|
send_msg.data[1] = 100;
|
||||||
send_msg.data[2] = ~app_factorymode_msg_check_sum(
|
send_msg.data[2] = ~app_factorymode_msg_check_sum((unsigned char *)&send_msg, MSG_TOTAL_LEN(&send_msg) - 1);
|
||||||
(unsigned char *)&send_msg, MSG_TOTAL_LEN(&send_msg) - 1);
|
|
||||||
|
|
||||||
ret = app_factorymode_msg_uart_send((unsigned char *)&send_msg,
|
ret = app_factorymode_msg_uart_send((unsigned char *)&send_msg, MSG_TOTAL_LEN(&send_msg));
|
||||||
MSG_TOTAL_LEN(&send_msg));
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int app_factorymode_msg_send_32bitcode(uint32_t code) {
|
static int app_factorymode_msg_send_32bitcode(uint32_t code)
|
||||||
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
send_msg.hdr.type = 0x88;
|
send_msg.hdr.type = 0x88;
|
||||||
|
@ -386,16 +381,15 @@ static int app_factorymode_msg_send_32bitcode(uint32_t code) {
|
||||||
send_msg.hdr.len = 4;
|
send_msg.hdr.len = 4;
|
||||||
send_msg.data[0] = 0xf2;
|
send_msg.data[0] = 0xf2;
|
||||||
*(uint32_t *)&(send_msg.data[1]) = code;
|
*(uint32_t *)&(send_msg.data[1]) = code;
|
||||||
send_msg.data[4] = ~app_factorymode_msg_check_sum(
|
send_msg.data[4] = ~app_factorymode_msg_check_sum((unsigned char *)&send_msg, MSG_TOTAL_LEN(&send_msg) - 1);
|
||||||
(unsigned char *)&send_msg, MSG_TOTAL_LEN(&send_msg) - 1);
|
|
||||||
|
|
||||||
ret = app_factorymode_msg_uart_send((unsigned char *)&send_msg,
|
ret = app_factorymode_msg_uart_send((unsigned char *)&send_msg, MSG_TOTAL_LEN(&send_msg));
|
||||||
MSG_TOTAL_LEN(&send_msg));
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int app_factorymode_process(APP_MESSAGE_BODY *msg_body) {
|
static int app_factorymode_process(APP_MESSAGE_BODY *msg_body)
|
||||||
|
{
|
||||||
if (msg_body->message_id == 1){
|
if (msg_body->message_id == 1){
|
||||||
app_factorymode_msg_send_ping();
|
app_factorymode_msg_send_ping();
|
||||||
}
|
}
|
||||||
|
@ -408,16 +402,20 @@ static int app_factorymode_process(APP_MESSAGE_BODY *msg_body) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int app_factorymode_uart_init(void) {
|
static int app_factorymode_uart_init(void)
|
||||||
|
{
|
||||||
struct HAL_UART_CFG_T uart_cfg;
|
struct HAL_UART_CFG_T uart_cfg;
|
||||||
|
|
||||||
memset(&uart_cfg, 0, sizeof(struct HAL_UART_CFG_T));
|
memset(&uart_cfg, 0, sizeof(struct HAL_UART_CFG_T));
|
||||||
uart_cfg.parity = HAL_UART_PARITY_NONE, uart_cfg.stop = HAL_UART_STOP_BITS_1,
|
uart_cfg.parity = HAL_UART_PARITY_NONE,
|
||||||
|
uart_cfg.stop = HAL_UART_STOP_BITS_1,
|
||||||
uart_cfg.data = HAL_UART_DATA_BITS_8,
|
uart_cfg.data = HAL_UART_DATA_BITS_8,
|
||||||
uart_cfg.flow = HAL_UART_FLOW_CONTROL_NONE,//HAL_UART_FLOW_CONTROL_RTSCTS,
|
uart_cfg.flow = HAL_UART_FLOW_CONTROL_NONE,//HAL_UART_FLOW_CONTROL_RTSCTS,
|
||||||
uart_cfg.tx_level = HAL_UART_FIFO_LEVEL_1_2,
|
uart_cfg.tx_level = HAL_UART_FIFO_LEVEL_1_2,
|
||||||
uart_cfg.rx_level = HAL_UART_FIFO_LEVEL_1_4, uart_cfg.baud = 921600,
|
uart_cfg.rx_level = HAL_UART_FIFO_LEVEL_1_4,
|
||||||
uart_cfg.dma_rx = false, uart_cfg.dma_tx = false,
|
uart_cfg.baud = 921600,
|
||||||
|
uart_cfg.dma_rx = false,
|
||||||
|
uart_cfg.dma_tx = false,
|
||||||
uart_cfg.dma_rx_stop_on_err = false;
|
uart_cfg.dma_rx_stop_on_err = false;
|
||||||
hal_uart_close(HAL_UART_ID_0);
|
hal_uart_close(HAL_UART_ID_0);
|
||||||
hal_uart_open(HAL_UART_ID_0, &uart_cfg);
|
hal_uart_open(HAL_UART_ID_0, &uart_cfg);
|
||||||
|
@ -425,7 +423,9 @@ static int app_factorymode_uart_init(void) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void app_factorymode_timehandler(void const *param) {
|
|
||||||
|
static void app_factorymode_timehandler(void const *param)
|
||||||
|
{
|
||||||
APP_MESSAGE_BLOCK msg;
|
APP_MESSAGE_BLOCK msg;
|
||||||
|
|
||||||
msg.mod_id = APP_MODUAL_OHTER;
|
msg.mod_id = APP_MODUAL_OHTER;
|
||||||
|
@ -433,7 +433,8 @@ static void app_factorymode_timehandler(void const *param) {
|
||||||
app_mailbox_put(&msg);
|
app_mailbox_put(&msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t app_factorymode_indication_init(void) {
|
static uint8_t app_factorymode_indication_init(void)
|
||||||
|
{
|
||||||
struct APP_PWL_CFG_T cfg;
|
struct APP_PWL_CFG_T cfg;
|
||||||
|
|
||||||
memset(&cfg, 0, sizeof(struct APP_PWL_CFG_T));
|
memset(&cfg, 0, sizeof(struct APP_PWL_CFG_T));
|
||||||
|
@ -443,8 +444,8 @@ static uint8_t app_factorymode_indication_init(void) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t
|
static uint8_t app_factorymode_status_indication(APP_FACTORYMODE_STATUS_INDICATION_T status)
|
||||||
app_factorymode_status_indication(APP_FACTORYMODE_STATUS_INDICATION_T status) {
|
{
|
||||||
struct APP_PWL_CFG_T cfg0;
|
struct APP_PWL_CFG_T cfg0;
|
||||||
struct APP_PWL_CFG_T cfg1;
|
struct APP_PWL_CFG_T cfg1;
|
||||||
APP_FACTORY_TRACE(2,"%s %d",__func__, status);
|
APP_FACTORY_TRACE(2,"%s %d",__func__, status);
|
||||||
|
@ -503,7 +504,8 @@ app_factorymode_status_indication(APP_FACTORYMODE_STATUS_INDICATION_T status) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_factorymode_init(uint32_t factorymode) {
|
int app_factorymode_init(uint32_t factorymode)
|
||||||
|
{
|
||||||
uint8_t cnt = 0;
|
uint8_t cnt = 0;
|
||||||
int nRet = 0;
|
int nRet = 0;
|
||||||
uint32_t capval = 0x00;
|
uint32_t capval = 0x00;
|
||||||
|
@ -525,8 +527,7 @@ int app_factorymode_init(uint32_t factorymode) {
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
app_set_threadhandle(APP_MODUAL_OHTER, app_factorymode_process);
|
app_set_threadhandle(APP_MODUAL_OHTER, app_factorymode_process);
|
||||||
app_factory_timer =
|
app_factory_timer = osTimerCreate (osTimer(APP_FACTORY_TIMER), osTimerPeriodic, NULL);
|
||||||
osTimerCreate(osTimer(APP_FACTORY_TIMER), osTimerPeriodic, NULL);
|
|
||||||
osTimerStart(app_factory_timer, 300);
|
osTimerStart(app_factory_timer, 300);
|
||||||
app_factorymode_send_progress(10);
|
app_factorymode_send_progress(10);
|
||||||
|
|
||||||
|
@ -591,7 +592,8 @@ exit:
|
||||||
return nRet;
|
return nRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_factorymode_calib_only(void) {
|
int app_factorymode_calib_only(void)
|
||||||
|
{
|
||||||
uint8_t cnt = 0;
|
uint8_t cnt = 0;
|
||||||
int nRet = 0;
|
int nRet = 0;
|
||||||
uint32_t capval = 0x00;
|
uint32_t capval = 0x00;
|
||||||
|
@ -609,8 +611,7 @@ int app_factorymode_calib_only(void) {
|
||||||
app_factorymode_indication_init();
|
app_factorymode_indication_init();
|
||||||
|
|
||||||
app_set_threadhandle(APP_MODUAL_OHTER, app_factorymode_process);
|
app_set_threadhandle(APP_MODUAL_OHTER, app_factorymode_process);
|
||||||
app_factory_timer =
|
app_factory_timer = osTimerCreate(osTimer(APP_FACTORY_TIMER),osTimerPeriodic,NULL);
|
||||||
osTimerCreate(osTimer(APP_FACTORY_TIMER), osTimerPeriodic, NULL);
|
|
||||||
osTimerStart(app_factory_timer,300);
|
osTimerStart(app_factory_timer,300);
|
||||||
app_factorymode_status_indication(APP_FACTORYMODE_STATUS_INDICATION_RUNNING);
|
app_factorymode_status_indication(APP_FACTORYMODE_STATUS_INDICATION_RUNNING);
|
||||||
app_factorymode_send_progress(10);
|
app_factorymode_send_progress(10);
|
||||||
|
@ -649,21 +650,25 @@ exit:
|
||||||
|
|
||||||
#ifdef __USB_COMM__
|
#ifdef __USB_COMM__
|
||||||
// for usb
|
// for usb
|
||||||
|
#include "usb_cdc.h"
|
||||||
#include "hal_timer.h"
|
#include "hal_timer.h"
|
||||||
#include "hwtimer_list.h"
|
#include "hwtimer_list.h"
|
||||||
#include "usb_cdc.h"
|
|
||||||
|
|
||||||
#include "app_factory_cdc_comm.h"
|
|
||||||
#include "hal_usb.h"
|
#include "hal_usb.h"
|
||||||
|
#include "app_factory_cdc_comm.h"
|
||||||
#include "sys_api_cdc_comm.h"
|
#include "sys_api_cdc_comm.h"
|
||||||
|
|
||||||
static const struct USB_SERIAL_CFG_T cdc_cfg = {
|
static const struct USB_SERIAL_CFG_T cdc_cfg = {
|
||||||
.mode = USB_SERIAL_API_NONBLOCKING,
|
.mode = USB_SERIAL_API_NONBLOCKING,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void usb_serial_recv_timeout(void *param) { usb_serial_cancel_recv(); }
|
static void usb_serial_recv_timeout(void *param)
|
||||||
|
{
|
||||||
|
usb_serial_cancel_recv();
|
||||||
|
}
|
||||||
|
|
||||||
int app_factorymode_cdc_comm(void) {
|
int app_factorymode_cdc_comm(void)
|
||||||
|
{
|
||||||
HWTIMER_ID timer;
|
HWTIMER_ID timer;
|
||||||
pmu_usb_config(PMU_USB_CONFIG_TYPE_DEVICE);
|
pmu_usb_config(PMU_USB_CONFIG_TYPE_DEVICE);
|
||||||
usb_serial_open(&cdc_cfg);
|
usb_serial_open(&cdc_cfg);
|
||||||
|
|
|
@ -15,8 +15,7 @@
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#ifndef __APP_FACTORY_H__
|
#ifndef __APP_FACTORY_H__
|
||||||
#define __APP_FACTORY_H__
|
#define __APP_FACTORY_H__
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#define APP_FACTORY_TRACE(s,...) TRACE(s, ##__VA_ARGS__)
|
#define APP_FACTORY_TRACE(s,...) TRACE(s, ##__VA_ARGS__)
|
||||||
|
|
||||||
void app_factorymode_result_set(bool result);
|
void app_factorymode_result_set(bool result);
|
||||||
|
|
|
@ -13,28 +13,30 @@
|
||||||
* trademark and other intellectual property rights.
|
* trademark and other intellectual property rights.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include "app_bt_stream.h"
|
|
||||||
#include "app_factory.h"
|
|
||||||
#include "app_media_player.h"
|
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
#include "hal_trace.h"
|
#include "hal_trace.h"
|
||||||
#include "resources.h"
|
#include "resources.h"
|
||||||
|
#include "app_bt_stream.h"
|
||||||
|
#include "app_media_player.h"
|
||||||
|
#include "app_factory.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
|
||||||
// for audio
|
// for audio
|
||||||
|
#include "audioflinger.h"
|
||||||
#include "app_audio.h"
|
#include "app_audio.h"
|
||||||
#include "app_utils.h"
|
#include "app_utils.h"
|
||||||
#include "audioflinger.h"
|
|
||||||
|
|
||||||
#include "app_factory_audio.h"
|
#include "app_factory_audio.h"
|
||||||
|
|
||||||
|
|
||||||
#ifdef __FACTORY_MODE_SUPPORT__
|
#ifdef __FACTORY_MODE_SUPPORT__
|
||||||
|
|
||||||
#define BT_AUDIO_FACTORMODE_BUFF_SIZE (1024*2)
|
#define BT_AUDIO_FACTORMODE_BUFF_SIZE (1024*2)
|
||||||
static enum APP_AUDIO_CACHE_T a2dp_cache_status = APP_AUDIO_CACHE_QTY;
|
static enum APP_AUDIO_CACHE_T a2dp_cache_status = APP_AUDIO_CACHE_QTY;
|
||||||
static int16_t *app_audioloop_play_cache = NULL;
|
static int16_t *app_audioloop_play_cache = NULL;
|
||||||
|
|
||||||
static uint32_t app_factorymode_data_come(uint8_t *buf, uint32_t len) {
|
static uint32_t app_factorymode_data_come(uint8_t *buf, uint32_t len)
|
||||||
|
{
|
||||||
DUMP16("%d,",(int*)buf,30);
|
DUMP16("%d,",(int*)buf,30);
|
||||||
|
|
||||||
app_audio_pcmbuff_put(buf, len);
|
app_audio_pcmbuff_put(buf, len);
|
||||||
|
@ -44,23 +46,23 @@ static uint32_t app_factorymode_data_come(uint8_t *buf, uint32_t len) {
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t app_factorymode_more_data(uint8_t *buf, uint32_t len) {
|
static uint32_t app_factorymode_more_data(uint8_t *buf, uint32_t len)
|
||||||
|
{
|
||||||
if (a2dp_cache_status != APP_AUDIO_CACHE_QTY){
|
if (a2dp_cache_status != APP_AUDIO_CACHE_QTY){
|
||||||
app_audio_pcmbuff_get((uint8_t *)app_audioloop_play_cache, len/2);
|
app_audio_pcmbuff_get((uint8_t *)app_audioloop_play_cache, len/2);
|
||||||
app_bt_stream_copy_track_one_to_two_16bits(
|
app_bt_stream_copy_track_one_to_two_16bits((int16_t *)buf, app_audioloop_play_cache, len/2/2);
|
||||||
(int16_t *)buf, app_audioloop_play_cache, len / 2 / 2);
|
|
||||||
}
|
}
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_factorymode_audioloop(bool on, enum APP_SYSFREQ_FREQ_T freq) {
|
int app_factorymode_audioloop(bool on, enum APP_SYSFREQ_FREQ_T freq)
|
||||||
|
{
|
||||||
uint8_t *buff_play = NULL;
|
uint8_t *buff_play = NULL;
|
||||||
uint8_t *buff_capture = NULL;
|
uint8_t *buff_capture = NULL;
|
||||||
uint8_t *buff_loop = NULL;
|
uint8_t *buff_loop = NULL;
|
||||||
struct AF_STREAM_CONFIG_T stream_cfg;
|
struct AF_STREAM_CONFIG_T stream_cfg;
|
||||||
static bool isRun = false;
|
static bool isRun = false;
|
||||||
APP_FACTORY_TRACE(3, "app_factorymode_audioloop work:%d op:%d freq:%d", isRun,
|
APP_FACTORY_TRACE(3,"app_factorymode_audioloop work:%d op:%d freq:%d", isRun, on, freq);
|
||||||
on, freq);
|
|
||||||
|
|
||||||
if (isRun==on)
|
if (isRun==on)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -75,8 +77,7 @@ int app_factorymode_audioloop(bool on, enum APP_SYSFREQ_FREQ_T freq) {
|
||||||
app_audio_mempool_init();
|
app_audio_mempool_init();
|
||||||
app_audio_mempool_get_buff(&buff_capture, BT_AUDIO_FACTORMODE_BUFF_SIZE);
|
app_audio_mempool_get_buff(&buff_capture, BT_AUDIO_FACTORMODE_BUFF_SIZE);
|
||||||
app_audio_mempool_get_buff(&buff_play, BT_AUDIO_FACTORMODE_BUFF_SIZE*2);
|
app_audio_mempool_get_buff(&buff_play, BT_AUDIO_FACTORMODE_BUFF_SIZE*2);
|
||||||
app_audio_mempool_get_buff((uint8_t **)&app_audioloop_play_cache,
|
app_audio_mempool_get_buff((uint8_t **)&app_audioloop_play_cache, BT_AUDIO_FACTORMODE_BUFF_SIZE*2/2/2);
|
||||||
BT_AUDIO_FACTORMODE_BUFF_SIZE * 2 / 2 / 2);
|
|
||||||
app_audio_mempool_get_buff(&buff_loop, BT_AUDIO_FACTORMODE_BUFF_SIZE<<2);
|
app_audio_mempool_get_buff(&buff_loop, BT_AUDIO_FACTORMODE_BUFF_SIZE<<2);
|
||||||
app_audio_pcmbuff_init(buff_loop, BT_AUDIO_FACTORMODE_BUFF_SIZE<<2);
|
app_audio_pcmbuff_init(buff_loop, BT_AUDIO_FACTORMODE_BUFF_SIZE<<2);
|
||||||
memset(&stream_cfg, 0, sizeof(stream_cfg));
|
memset(&stream_cfg, 0, sizeof(stream_cfg));
|
||||||
|
@ -93,7 +94,11 @@ int app_factorymode_audioloop(bool on, enum APP_SYSFREQ_FREQ_T freq) {
|
||||||
#else
|
#else
|
||||||
stream_cfg.sample_rate = AUD_SAMPRATE_8000;
|
stream_cfg.sample_rate = AUD_SAMPRATE_8000;
|
||||||
#endif
|
#endif
|
||||||
|
#if FPGA==0
|
||||||
stream_cfg.device = AUD_STREAM_USE_INT_CODEC;
|
stream_cfg.device = AUD_STREAM_USE_INT_CODEC;
|
||||||
|
#else
|
||||||
|
stream_cfg.device = AUD_STREAM_USE_EXT_CODEC;
|
||||||
|
#endif
|
||||||
stream_cfg.vol = TGT_VOLUME_LEVEL_15;
|
stream_cfg.vol = TGT_VOLUME_LEVEL_15;
|
||||||
stream_cfg.io_path = AUD_INPUT_PATH_MAINMIC;
|
stream_cfg.io_path = AUD_INPUT_PATH_MAINMIC;
|
||||||
stream_cfg.handler = app_factorymode_data_come;
|
stream_cfg.handler = app_factorymode_data_come;
|
||||||
|
@ -127,33 +132,44 @@ int app_factorymode_audioloop(bool on, enum APP_SYSFREQ_FREQ_T freq) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_factorymode_output_pcmpatten(audio_test_pcmpatten_t *pcmpatten,
|
int app_factorymode_output_pcmpatten(audio_test_pcmpatten_t *pcmpatten, uint8_t *buf, uint32_t len)
|
||||||
uint8_t *buf, uint32_t len) {
|
{
|
||||||
uint32_t remain_size = len;
|
uint32_t remain_size = len;
|
||||||
uint32_t curr_size = 0;
|
uint32_t curr_size = 0;
|
||||||
|
|
||||||
if (remain_size > pcmpatten->len) {
|
if (remain_size > pcmpatten->len)
|
||||||
|
{
|
||||||
do{
|
do{
|
||||||
if (pcmpatten->cuur_buf_pos) {
|
if (pcmpatten->cuur_buf_pos)
|
||||||
|
{
|
||||||
curr_size = pcmpatten->len-pcmpatten->cuur_buf_pos;
|
curr_size = pcmpatten->len-pcmpatten->cuur_buf_pos;
|
||||||
memcpy(buf,&(pcmpatten->buf[pcmpatten->cuur_buf_pos/2]), curr_size);
|
memcpy(buf,&(pcmpatten->buf[pcmpatten->cuur_buf_pos/2]), curr_size);
|
||||||
remain_size -= curr_size;
|
remain_size -= curr_size;
|
||||||
pcmpatten->cuur_buf_pos = 0;
|
pcmpatten->cuur_buf_pos = 0;
|
||||||
} else if (remain_size > pcmpatten->len) {
|
}
|
||||||
|
else if (remain_size>pcmpatten->len)
|
||||||
|
{
|
||||||
memcpy(buf+curr_size, pcmpatten->buf, pcmpatten->len);
|
memcpy(buf+curr_size, pcmpatten->buf, pcmpatten->len);
|
||||||
curr_size += pcmpatten->len;
|
curr_size += pcmpatten->len;
|
||||||
remain_size -= pcmpatten->len;
|
remain_size -= pcmpatten->len;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
memcpy(buf+curr_size,pcmpatten->buf, remain_size);
|
memcpy(buf+curr_size,pcmpatten->buf, remain_size);
|
||||||
pcmpatten->cuur_buf_pos = remain_size;
|
pcmpatten->cuur_buf_pos = remain_size;
|
||||||
remain_size = 0;
|
remain_size = 0;
|
||||||
}
|
}
|
||||||
}while(remain_size);
|
}while(remain_size);
|
||||||
} else {
|
}
|
||||||
if ((pcmpatten->len - pcmpatten->cuur_buf_pos) >= len) {
|
else
|
||||||
|
{
|
||||||
|
if ((pcmpatten->len - pcmpatten->cuur_buf_pos) >= len)
|
||||||
|
{
|
||||||
memcpy(buf, &(pcmpatten->buf[pcmpatten->cuur_buf_pos/2]),len);
|
memcpy(buf, &(pcmpatten->buf[pcmpatten->cuur_buf_pos/2]),len);
|
||||||
pcmpatten->cuur_buf_pos += len;
|
pcmpatten->cuur_buf_pos += len;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
curr_size = pcmpatten->len-pcmpatten->cuur_buf_pos;
|
curr_size = pcmpatten->len-pcmpatten->cuur_buf_pos;
|
||||||
memcpy(buf, &(pcmpatten->buf[pcmpatten->cuur_buf_pos/2]),curr_size);
|
memcpy(buf, &(pcmpatten->buf[pcmpatten->cuur_buf_pos/2]),curr_size);
|
||||||
pcmpatten->cuur_buf_pos = len - curr_size;
|
pcmpatten->cuur_buf_pos = len - curr_size;
|
||||||
|
@ -181,14 +197,12 @@ struct mic_st_t {
|
||||||
signed long out[N];
|
signed long out[N];
|
||||||
};
|
};
|
||||||
|
|
||||||
int app_factorymode_mic_cancellation_run(void *mic_st, signed short *inbuf,
|
int app_factorymode_mic_cancellation_run(void * mic_st, signed short *inbuf, int sample)
|
||||||
int sample) {
|
{
|
||||||
struct mic_st_t *st = (struct mic_st_t *)mic_st;
|
struct mic_st_t *st = (struct mic_st_t *)mic_st;
|
||||||
int i,k,jj,ii;
|
int i,k,jj,ii;
|
||||||
// int dataWidth = 16; // input word format is 16 bit twos complement
|
//int dataWidth = 16; // input word format is 16 bit twos complement fractional format 1.15
|
||||||
// fractional format 1.15
|
int twiddleWidth = 16; // input word format is 16 bit twos complement fractional format 2.14
|
||||||
int twiddleWidth =
|
|
||||||
16; // input word format is 16 bit twos complement fractional format 2.14
|
|
||||||
FftMode_t ifft = FFT_MODE;
|
FftMode_t ifft = FFT_MODE;
|
||||||
|
|
||||||
make_symmetric_twiddles(st->w,N,twiddleWidth);
|
make_symmetric_twiddles(st->w,N,twiddleWidth);
|
||||||
|
@ -199,33 +213,30 @@ int app_factorymode_mic_cancellation_run(void *mic_st, signed short *inbuf,
|
||||||
st->x[i].im = 0;
|
st->x[i].im = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ii = 0; ii < 1; ii++) {
|
for(ii = 0; ii < 1; ii++)
|
||||||
|
{
|
||||||
k = 0;
|
k = 0;
|
||||||
for (jj = 0; jj < N * 2; jj += 2) {
|
for (jj = 0; jj < N*2; jj+=2)
|
||||||
|
{
|
||||||
FftData_t tmp;
|
FftData_t tmp;
|
||||||
|
|
||||||
tmp.re = st->x[jj].re;
|
tmp.re = st->x[jj].re;
|
||||||
tmp.im = st->x[jj].im;
|
tmp.im = st->x[jj].im;
|
||||||
|
|
||||||
st->data_even[k].re =
|
st->data_even[k].re = tmp.re;//(int) (double(tmp.re)*double(1 << FFTR4_INPUT_FORMAT_Y)) ;
|
||||||
tmp.re; //(int) (double(tmp.re)*double(1 << FFTR4_INPUT_FORMAT_Y)) ;
|
st->data_even[k].im = tmp.im;//(int) (double(tmp.im)*double(1 << FFTR4_INPUT_FORMAT_Y)) ;
|
||||||
st->data_even[k].im =
|
|
||||||
tmp.im; //(int) (double(tmp.im)*double(1 << FFTR4_INPUT_FORMAT_Y)) ;
|
|
||||||
tmp.re = st->x[jj+1].re;
|
tmp.re = st->x[jj+1].re;
|
||||||
tmp.im = st->x[jj+1].im;
|
tmp.im = st->x[jj+1].im;
|
||||||
st->data_odd[k].re =
|
st->data_odd[k].re = tmp.re;//(int) (double(tmp.re)*double(1 << FFTR4_INPUT_FORMAT_Y)) ;
|
||||||
tmp.re; //(int) (double(tmp.re)*double(1 << FFTR4_INPUT_FORMAT_Y)) ;
|
st->data_odd[k].im = tmp.im;//(int) (double(tmp.im)*double(1 << FFTR4_INPUT_FORMAT_Y)) ;
|
||||||
st->data_odd[k].im =
|
|
||||||
tmp.im; //(int) (double(tmp.im)*double(1 << FFTR4_INPUT_FORMAT_Y)) ;
|
|
||||||
k++;
|
k++;
|
||||||
}
|
}
|
||||||
|
|
||||||
fftr4(NFFT / 2, st->data_even, st->w, FFTR4_TWIDDLE_WIDTH, FFTR4_DATA_WIDTH,
|
fftr4(NFFT/2, st->data_even, st->w, FFTR4_TWIDDLE_WIDTH, FFTR4_DATA_WIDTH, ifft);
|
||||||
ifft);
|
fftr4(NFFT/2, st->data_odd, st->w, FFTR4_TWIDDLE_WIDTH, FFTR4_DATA_WIDTH, ifft);
|
||||||
fftr4(NFFT / 2, st->data_odd, st->w, FFTR4_TWIDDLE_WIDTH, FFTR4_DATA_WIDTH,
|
|
||||||
ifft);
|
|
||||||
|
|
||||||
for (jj = 0; jj < NFFT / 2; jj++) {
|
for (jj = 0; jj < NFFT/2; jj++)
|
||||||
|
{
|
||||||
|
|
||||||
int idx = dibit_reverse_int(jj, NFFT/2);
|
int idx = dibit_reverse_int(jj, NFFT/2);
|
||||||
st->data_even_d[jj].re = st->data_even[idx].re;
|
st->data_even_d[jj].re = st->data_even[idx].re;
|
||||||
|
@ -233,15 +244,14 @@ int app_factorymode_mic_cancellation_run(void *mic_st, signed short *inbuf,
|
||||||
st->data_odd_d[jj].re = st->data_odd[idx].re;
|
st->data_odd_d[jj].re = st->data_odd[idx].re;
|
||||||
st->data_odd_d[jj].im = st->data_odd[idx].im;
|
st->data_odd_d[jj].im = st->data_odd[idx].im;
|
||||||
}
|
}
|
||||||
for (jj = 0; jj < NFFT / 2; jj++) {
|
for (jj=0;jj<NFFT/2;jj++)
|
||||||
|
{
|
||||||
long long mbr,mbi;
|
long long mbr,mbi;
|
||||||
FftData_t ta;
|
FftData_t ta;
|
||||||
FftData_t tmp;
|
FftData_t tmp;
|
||||||
double a;
|
double a;
|
||||||
mbr = (long long)(st->data_odd_d[jj].re) * st->w128[jj].re -
|
mbr = (long long)(st->data_odd_d[jj].re) * st->w128[jj].re - (long long)(st->data_odd_d[jj].im) * st->w128[jj].im;
|
||||||
(long long)(st->data_odd_d[jj].im) * st->w128[jj].im;
|
mbi = (long long)(st->data_odd_d[jj].im) * st->w128[jj].re + (long long)(st->data_odd_d[jj].re) * st->w128[jj].im;
|
||||||
mbi = (long long)(st->data_odd_d[jj].im) * st->w128[jj].re +
|
|
||||||
(long long)(st->data_odd_d[jj].re) * st->w128[jj].im;
|
|
||||||
ta.re = int(mbr>>(FFTR4_TWIDDLE_WIDTH-2));
|
ta.re = int(mbr>>(FFTR4_TWIDDLE_WIDTH-2));
|
||||||
ta.im = int(mbi>>(FFTR4_TWIDDLE_WIDTH-2));
|
ta.im = int(mbi>>(FFTR4_TWIDDLE_WIDTH-2));
|
||||||
st->data[jj].re = (st->data_even_d[jj].re + ta.re)/2;
|
st->data[jj].re = (st->data_even_d[jj].re + ta.re)/2;
|
||||||
|
@ -251,19 +261,15 @@ int app_factorymode_mic_cancellation_run(void *mic_st, signed short *inbuf,
|
||||||
st->data[jj+NFFT/2].im = (st->data_even_d[jj].im - ta.im)/2;
|
st->data[jj+NFFT/2].im = (st->data_even_d[jj].im - ta.im)/2;
|
||||||
//data[jj+NFFT/2] = sat(data[jj+NFFT/2],FFTR4_DATA_WIDTH);
|
//data[jj+NFFT/2] = sat(data[jj+NFFT/2],FFTR4_DATA_WIDTH);
|
||||||
|
|
||||||
a = st->data[jj].re; /// double(1 << FFTR4_OUTPUT_FORMAT_Y);// * double(1
|
a = st->data[jj].re;///double(1 << FFTR4_OUTPUT_FORMAT_Y);// * double(1 << FFTR4_SCALE);
|
||||||
/// << FFTR4_SCALE);
|
|
||||||
tmp.re = (int)a;
|
tmp.re = (int)a;
|
||||||
a = st->data[jj].im; /// double(1 << FFTR4_OUTPUT_FORMAT_Y);// * double(1
|
a = st->data[jj].im;///double(1 << FFTR4_OUTPUT_FORMAT_Y);// * double(1 << FFTR4_SCALE);
|
||||||
/// << FFTR4_SCALE);
|
|
||||||
tmp.im = (int)a;
|
tmp.im = (int)a;
|
||||||
st->x[ii*NFFT+jj].re = (int) tmp.re;
|
st->x[ii*NFFT+jj].re = (int) tmp.re;
|
||||||
st->x[ii*NFFT+jj].im = (int) tmp.im;
|
st->x[ii*NFFT+jj].im = (int) tmp.im;
|
||||||
a = st->data[jj + NFFT / 2].re; /// double(1 << FFTR4_OUTPUT_FORMAT_Y);//
|
a = st->data[jj+NFFT/2].re;///double(1 << FFTR4_OUTPUT_FORMAT_Y);// * double(1 << FFTR4_SCALE);
|
||||||
/// * double(1 << FFTR4_SCALE);
|
|
||||||
tmp.re = (int)a;
|
tmp.re = (int)a;
|
||||||
a = st->data[jj + NFFT / 2].im; /// double(1 << FFTR4_OUTPUT_FORMAT_Y);//
|
a = st->data[jj+NFFT/2].im;///double(1 << FFTR4_OUTPUT_FORMAT_Y);// * double(1 << FFTR4_SCALE);
|
||||||
/// * double(1 << FFTR4_SCALE);
|
|
||||||
tmp.im = (int)a;
|
tmp.im = (int)a;
|
||||||
st->x[ii*NFFT+jj+NFFT/2].re = (int) tmp.re;
|
st->x[ii*NFFT+jj+NFFT/2].re = (int) tmp.re;
|
||||||
st->x[ii*NFFT+jj+NFFT/2].im = (int) tmp.im;
|
st->x[ii*NFFT+jj+NFFT/2].im = (int) tmp.im;
|
||||||
|
@ -275,12 +281,15 @@ int app_factorymode_mic_cancellation_run(void *mic_st, signed short *inbuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void *app_factorymode_mic_cancellation_init(void *(*alloc_ext)(int)) {
|
void *app_factorymode_mic_cancellation_init(void* (* alloc_ext)(int))
|
||||||
|
{
|
||||||
struct mic_st_t *mic_st;
|
struct mic_st_t *mic_st;
|
||||||
mic_st = (struct mic_st_t *)alloc_ext(sizeof(struct mic_st_t));
|
mic_st = (struct mic_st_t *)alloc_ext(sizeof(struct mic_st_t));
|
||||||
return (void *)mic_st;
|
return (void *)mic_st;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -13,72 +13,78 @@
|
||||||
* trademark and other intellectual property rights.
|
* trademark and other intellectual property rights.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include "app_factory_bt.h"
|
|
||||||
#include "app_battery.h"
|
|
||||||
#include "app_factory.h"
|
|
||||||
#include "app_utils.h"
|
|
||||||
#include "apps.h"
|
|
||||||
#include "bluetooth.h"
|
|
||||||
#include "bt_drv_interface.h"
|
|
||||||
#include "bt_drv_reg_op.h"
|
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
#include "conmgr_api.h"
|
|
||||||
#include "hal_bootmode.h"
|
|
||||||
#include "hal_chipid.h"
|
|
||||||
#include "hal_sleep.h"
|
|
||||||
#include "hal_trace.h"
|
#include "hal_trace.h"
|
||||||
|
#include "hal_sleep.h"
|
||||||
|
#include "bt_drv_interface.h"
|
||||||
#include "intersyshci.h"
|
#include "intersyshci.h"
|
||||||
#include "me_api.h"
|
#include "apps.h"
|
||||||
|
#include "app_factory.h"
|
||||||
|
#include "app_factory_bt.h"
|
||||||
|
#include "app_utils.h"
|
||||||
|
#include "bluetooth.h"
|
||||||
#include "nvrecord.h"
|
#include "nvrecord.h"
|
||||||
#include "nvrecord_dev.h"
|
#include "nvrecord_dev.h"
|
||||||
#include "pmu.h"
|
#include "pmu.h"
|
||||||
#include "tgt_hardware.h"
|
#include "tgt_hardware.h"
|
||||||
|
#include "app_battery.h"
|
||||||
|
#include "bt_drv_reg_op.h"
|
||||||
|
#include "conmgr_api.h"
|
||||||
|
#include "me_api.h"
|
||||||
|
#include "hal_bootmode.h"
|
||||||
|
#include "hal_chipid.h"
|
||||||
|
|
||||||
|
|
||||||
#define APP_FACT_CPU_WAKE_LOCK HAL_CPU_WAKE_LOCK_USER_3
|
#define APP_FACT_CPU_WAKE_LOCK HAL_CPU_WAKE_LOCK_USER_3
|
||||||
|
|
||||||
#ifdef __FACTORY_MODE_SUPPORT__
|
#ifdef __FACTORY_MODE_SUPPORT__
|
||||||
static uint8_t inquiry_buff[] = {0x01, 0x72, 0x77, 0xb0, 0x18, 0x57, 0x60, 0x01,
|
static uint8_t inquiry_buff[] = {0x01, 0x72, 0x77, 0xb0, 0x18, 0x57, 0x60,\
|
||||||
0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00};
|
0x01, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00};
|
||||||
|
|
||||||
|
|
||||||
static btif_cmgr_handler_t *app_factorymode_cmgrHandler;
|
static btif_cmgr_handler_t *app_factorymode_cmgrHandler;
|
||||||
|
|
||||||
|
|
||||||
static void bt_error_check_timer_handler(void const *param);
|
static void bt_error_check_timer_handler(void const *param);
|
||||||
osTimerDef(bt_error_check_timer, bt_error_check_timer_handler);
|
osTimerDef(bt_error_check_timer, bt_error_check_timer_handler);
|
||||||
static osTimerId bt_error_check_timer_id = NULL;
|
static osTimerId bt_error_check_timer_id = NULL;
|
||||||
uint8_t test_mode_type=0;
|
uint8_t test_mode_type=0;
|
||||||
static void bt_error_check_timer_handler(void const *param) {
|
static void bt_error_check_timer_handler(void const *param)
|
||||||
|
{
|
||||||
//dump rssi
|
//dump rssi
|
||||||
bt_drv_rssi_dump_handler();
|
bt_drv_rssi_dump_handler();
|
||||||
//check BT core status
|
//check BT core status
|
||||||
if (bt_drv_error_check_handler()) {
|
if(bt_drv_error_check_handler())
|
||||||
if (test_mode_type == 1) {
|
{
|
||||||
hal_sw_bootmode_set(HAL_SW_BOOTMODE_TEST_MODE |
|
if(test_mode_type==1)
|
||||||
HAL_SW_BOOTMODE_TEST_SIGNALINGMODE);
|
{
|
||||||
} else if (test_mode_type == 2) {
|
hal_sw_bootmode_set(HAL_SW_BOOTMODE_TEST_MODE|HAL_SW_BOOTMODE_TEST_SIGNALINGMODE);
|
||||||
hal_sw_bootmode_set(HAL_SW_BOOTMODE_TEST_MODE |
|
}
|
||||||
HAL_SW_BOOTMODE_TEST_NOSIGNALINGMODE);
|
else if(test_mode_type==2)
|
||||||
|
{
|
||||||
|
hal_sw_bootmode_set(HAL_SW_BOOTMODE_TEST_MODE|HAL_SW_BOOTMODE_TEST_NOSIGNALINGMODE);
|
||||||
}
|
}
|
||||||
hal_cmu_sys_reboot();
|
hal_cmu_sys_reboot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void app_factorymode_bt_inquiry_buff_update(void) {
|
static void app_factorymode_bt_inquiry_buff_update(void)
|
||||||
|
{
|
||||||
bt_bdaddr_t flsh_dongle_addr;
|
bt_bdaddr_t flsh_dongle_addr;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
ret = nvrec_dev_get_dongleaddr(&flsh_dongle_addr);
|
ret = nvrec_dev_get_dongleaddr(&flsh_dongle_addr);
|
||||||
if(0 == ret) {
|
if(0 == ret) {
|
||||||
memcpy((void *)&inquiry_buff[1], (void *)flsh_dongle_addr.address,
|
memcpy((void *)&inquiry_buff[1],(void *)flsh_dongle_addr.address,BTIF_BD_ADDR_SIZE);
|
||||||
BTIF_BD_ADDR_SIZE);
|
|
||||||
DUMP8("0x%02x ", &inquiry_buff[2], BTIF_BD_ADDR_SIZE);
|
DUMP8("0x%02x ", &inquiry_buff[2], BTIF_BD_ADDR_SIZE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void app_factorymode_CmgrCallback(btif_cmgr_handler_t *cHandler,
|
static void app_factorymode_CmgrCallback(btif_cmgr_handler_t *cHandler,
|
||||||
cmgr_event_t Event,
|
cmgr_event_t Event,
|
||||||
bt_status_t Status) {
|
bt_status_t Status)
|
||||||
APP_FACTORY_TRACE(4, "%s cHandler:%p Event:%d status:%d", __func__, cHandler,
|
{
|
||||||
Event, Status);
|
APP_FACTORY_TRACE(4,"%s cHandler:%p Event:%d status:%d", __func__, cHandler, Event, Status);
|
||||||
if (Event == BTIF_CMEVENT_DATA_LINK_CON_CNF){
|
if (Event == BTIF_CMEVENT_DATA_LINK_CON_CNF){
|
||||||
if (Status == BT_STS_SUCCESS){
|
if (Status == BT_STS_SUCCESS){
|
||||||
APP_FACTORY_TRACE(0,"connect ok");
|
APP_FACTORY_TRACE(0,"connect ok");
|
||||||
|
@ -100,19 +106,20 @@ static void app_factorymode_CmgrCallback(btif_cmgr_handler_t *cHandler,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void app_factorymode_bt_InquiryResult_add(void) {
|
static void app_factorymode_bt_InquiryResult_add(void)
|
||||||
|
{
|
||||||
U8 len = 15;
|
U8 len = 15;
|
||||||
bool rssi = false, extended = false;
|
bool rssi = false, extended = false;
|
||||||
U8* parm = (U8*)inquiry_buff;
|
U8* parm = (U8*)inquiry_buff;
|
||||||
|
|
||||||
/* Found one or more devices. Report to clients */
|
/* Found one or more devices. Report to clients */
|
||||||
APP_FACTORY_TRACE(4, "%s len:%d rssi:%d extended:%d", __func__, len, rssi,
|
APP_FACTORY_TRACE(4,"%s len:%d rssi:%d extended:%d", __func__, len, rssi, extended);
|
||||||
extended);
|
|
||||||
DUMP8("0x%02x ", parm, len);
|
DUMP8("0x%02x ", parm, len);
|
||||||
btif_me_inquiry_result_setup(parm, rssi, extended);
|
btif_me_inquiry_result_setup(parm, rssi, extended);
|
||||||
}
|
}
|
||||||
|
|
||||||
void app_factorymode_bt_create_connect(void) {
|
void app_factorymode_bt_create_connect(void)
|
||||||
|
{
|
||||||
bt_status_t status;
|
bt_status_t status;
|
||||||
bt_bdaddr_t *bdAddr = (bt_bdaddr_t *)(inquiry_buff+1);
|
bt_bdaddr_t *bdAddr = (bt_bdaddr_t *)(inquiry_buff+1);
|
||||||
|
|
||||||
|
@ -120,7 +127,8 @@ void app_factorymode_bt_create_connect(void) {
|
||||||
APP_FACTORY_TRACE(2,"%s:%d", __func__, status);
|
APP_FACTORY_TRACE(2,"%s:%d", __func__, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
void app_factorymode_bt_init_connect(void) {
|
void app_factorymode_bt_init_connect(void)
|
||||||
|
{
|
||||||
app_factorymode_cmgrHandler = btif_cmgr_handler_create();
|
app_factorymode_cmgrHandler = btif_cmgr_handler_create();
|
||||||
|
|
||||||
btif_cmgr_register_handler(app_factorymode_cmgrHandler,
|
btif_cmgr_register_handler(app_factorymode_cmgrHandler,
|
||||||
|
@ -137,7 +145,8 @@ extern osTimerId app_bt_accessmode_timer;
|
||||||
#define XTAL_FCAP_RANGE (0xFF)
|
#define XTAL_FCAP_RANGE (0xFF)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void app_factorymode_bt_xtalrangetest(APP_KEY_STATUS *status, void *param) {
|
void app_factorymode_bt_xtalrangetest(APP_KEY_STATUS *status, void *param)
|
||||||
|
{
|
||||||
dev_addr_name devinfo;
|
dev_addr_name devinfo;
|
||||||
uint32_t fcap = 0;
|
uint32_t fcap = 0;
|
||||||
APP_FACTORY_TRACE(1,"%s",__func__);
|
APP_FACTORY_TRACE(1,"%s",__func__);
|
||||||
|
@ -151,8 +160,7 @@ void app_factorymode_bt_xtalrangetest(APP_KEY_STATUS *status, void *param) {
|
||||||
osTimerStop(app_bt_accessmode_timer);
|
osTimerStop(app_bt_accessmode_timer);
|
||||||
}
|
}
|
||||||
if (!bt_error_check_timer_id){
|
if (!bt_error_check_timer_id){
|
||||||
bt_error_check_timer_id =
|
bt_error_check_timer_id = osTimerCreate(osTimer(bt_error_check_timer), osTimerPeriodic, NULL);
|
||||||
osTimerCreate(osTimer(bt_error_check_timer), osTimerPeriodic, NULL);
|
|
||||||
}
|
}
|
||||||
if (bt_error_check_timer_id != NULL) {
|
if (bt_error_check_timer_id != NULL) {
|
||||||
osTimerStart(bt_error_check_timer_id, 1000);
|
osTimerStart(bt_error_check_timer_id, 1000);
|
||||||
|
@ -174,8 +182,7 @@ void app_factorymode_bt_xtalrangetest(APP_KEY_STATUS *status, void *param) {
|
||||||
devinfo.ble_addr = ble_addr;
|
devinfo.ble_addr = ble_addr;
|
||||||
devinfo.localname = BT_LOCAL_NAME;
|
devinfo.localname = BT_LOCAL_NAME;
|
||||||
nvrec_dev_localname_addr_init(&devinfo);
|
nvrec_dev_localname_addr_init(&devinfo);
|
||||||
btdrv_write_localinfo((char *)devinfo.localname,
|
btdrv_write_localinfo((char *)devinfo.localname, strlen(devinfo.localname) + 1, devinfo.btd_addr);
|
||||||
strlen(devinfo.localname) + 1, devinfo.btd_addr);
|
|
||||||
|
|
||||||
btdrv_vco_test_start(78);
|
btdrv_vco_test_start(78);
|
||||||
while(1){
|
while(1){
|
||||||
|
@ -186,7 +193,8 @@ void app_factorymode_bt_xtalrangetest(APP_KEY_STATUS *status, void *param) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void app_factorymode_bt_signalingtest(APP_KEY_STATUS *status, void *param) {
|
void app_factorymode_bt_signalingtest(APP_KEY_STATUS *status, void *param)
|
||||||
|
{
|
||||||
dev_addr_name devinfo;
|
dev_addr_name devinfo;
|
||||||
APP_FACTORY_TRACE(1,"%s",__func__);
|
APP_FACTORY_TRACE(1,"%s",__func__);
|
||||||
#ifdef __WATCHER_DOG_RESET__
|
#ifdef __WATCHER_DOG_RESET__
|
||||||
|
@ -199,8 +207,7 @@ void app_factorymode_bt_signalingtest(APP_KEY_STATUS *status, void *param) {
|
||||||
osTimerStop(app_bt_accessmode_timer);
|
osTimerStop(app_bt_accessmode_timer);
|
||||||
}
|
}
|
||||||
if (!bt_error_check_timer_id){
|
if (!bt_error_check_timer_id){
|
||||||
bt_error_check_timer_id =
|
bt_error_check_timer_id = osTimerCreate(osTimer(bt_error_check_timer), osTimerPeriodic, NULL);
|
||||||
osTimerCreate(osTimer(bt_error_check_timer), osTimerPeriodic, NULL);
|
|
||||||
}
|
}
|
||||||
if (bt_error_check_timer_id != NULL) {
|
if (bt_error_check_timer_id != NULL) {
|
||||||
osTimerStart(bt_error_check_timer_id, 1000);
|
osTimerStart(bt_error_check_timer_id, 1000);
|
||||||
|
@ -229,8 +236,7 @@ void app_factorymode_bt_signalingtest(APP_KEY_STATUS *status, void *param) {
|
||||||
memcpy(bt_addr,ibrt_address,6);
|
memcpy(bt_addr,ibrt_address,6);
|
||||||
memcpy(devinfo.btd_addr,ibrt_address,6);
|
memcpy(devinfo.btd_addr,ibrt_address,6);
|
||||||
#endif
|
#endif
|
||||||
btdrv_write_localinfo((char *)devinfo.localname,
|
btdrv_write_localinfo((char *)devinfo.localname, strlen(devinfo.localname) + 1, devinfo.btd_addr);
|
||||||
strlen(devinfo.localname) + 1, devinfo.btd_addr);
|
|
||||||
bt_drv_extra_config_after_init();
|
bt_drv_extra_config_after_init();
|
||||||
btdrv_enable_dut();
|
btdrv_enable_dut();
|
||||||
#ifdef __IBRT_IBRT_TESTMODE__
|
#ifdef __IBRT_IBRT_TESTMODE__
|
||||||
|
@ -239,7 +245,8 @@ void app_factorymode_bt_signalingtest(APP_KEY_STATUS *status, void *param) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_battery_stop(void);
|
int app_battery_stop(void);
|
||||||
void app_factorymode_bt_nosignalingtest(APP_KEY_STATUS *status, void *param) {
|
void app_factorymode_bt_nosignalingtest(APP_KEY_STATUS *status, void *param)
|
||||||
|
{
|
||||||
dev_addr_name devinfo;
|
dev_addr_name devinfo;
|
||||||
APP_FACTORY_TRACE(1,"%s",__func__);
|
APP_FACTORY_TRACE(1,"%s",__func__);
|
||||||
#ifdef __WATCHER_DOG_RESET__
|
#ifdef __WATCHER_DOG_RESET__
|
||||||
|
@ -251,8 +258,7 @@ void app_factorymode_bt_nosignalingtest(APP_KEY_STATUS *status, void *param) {
|
||||||
app_status_indication_set(APP_STATUS_INDICATION_TESTMODE1);
|
app_status_indication_set(APP_STATUS_INDICATION_TESTMODE1);
|
||||||
osTimerStop(app_bt_accessmode_timer);
|
osTimerStop(app_bt_accessmode_timer);
|
||||||
if (!bt_error_check_timer_id){
|
if (!bt_error_check_timer_id){
|
||||||
bt_error_check_timer_id =
|
bt_error_check_timer_id = osTimerCreate(osTimer(bt_error_check_timer), osTimerPeriodic, NULL);
|
||||||
osTimerCreate(osTimer(bt_error_check_timer), osTimerPeriodic, NULL);
|
|
||||||
}
|
}
|
||||||
if (bt_error_check_timer_id != NULL) {
|
if (bt_error_check_timer_id != NULL) {
|
||||||
osTimerStart(bt_error_check_timer_id, 1000);
|
osTimerStart(bt_error_check_timer_id, 1000);
|
||||||
|
@ -277,8 +283,7 @@ void app_factorymode_bt_nosignalingtest(APP_KEY_STATUS *status, void *param) {
|
||||||
devinfo.localname = BT_LOCAL_NAME;
|
devinfo.localname = BT_LOCAL_NAME;
|
||||||
devinfo.ble_name= BT_LOCAL_NAME;
|
devinfo.ble_name= BT_LOCAL_NAME;
|
||||||
nvrec_dev_localname_addr_init(&devinfo);
|
nvrec_dev_localname_addr_init(&devinfo);
|
||||||
btdrv_write_localinfo((char *)devinfo.localname,
|
btdrv_write_localinfo((char *)devinfo.localname, strlen(devinfo.localname) + 1, devinfo.btd_addr);
|
||||||
strlen(devinfo.localname) + 1, devinfo.btd_addr);
|
|
||||||
#endif
|
#endif
|
||||||
bt_drv_extra_config_after_init();
|
bt_drv_extra_config_after_init();
|
||||||
btdrv_hcioff();
|
btdrv_hcioff();
|
||||||
|
@ -291,7 +296,8 @@ void app_factorymode_bt_nosignalingtest(APP_KEY_STATUS *status, void *param) {
|
||||||
#endif
|
#endif
|
||||||
btdrv_uart_bridge_loop();
|
btdrv_uart_bridge_loop();
|
||||||
}
|
}
|
||||||
int app_factorymode_bt_xtalcalib_proc(void) {
|
int app_factorymode_bt_xtalcalib_proc(void)
|
||||||
|
{
|
||||||
uint32_t capval = 0x80;
|
uint32_t capval = 0x80;
|
||||||
int nRet;
|
int nRet;
|
||||||
|
|
||||||
|
@ -315,9 +321,11 @@ int app_factorymode_bt_xtalcalib_proc(void) {
|
||||||
return nRet;
|
return nRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
void app_factorymode_bt_xtalcalib(APP_KEY_STATUS *status, void *param) {
|
void app_factorymode_bt_xtalcalib(APP_KEY_STATUS *status, void *param)
|
||||||
|
{
|
||||||
APP_FACTORY_TRACE(1,"%s",__func__);
|
APP_FACTORY_TRACE(1,"%s",__func__);
|
||||||
app_factorymode_bt_xtalcalib_proc();
|
app_factorymode_bt_xtalcalib_proc();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -1,22 +1,19 @@
|
||||||
#ifdef __USB_COMM__
|
#ifdef __USB_COMM__
|
||||||
#include "app_factory_cdc_comm.h"
|
|
||||||
#include "plat_types.h"
|
|
||||||
#include "stdbool.h"
|
|
||||||
#include "stdint.h"
|
#include "stdint.h"
|
||||||
#include "stdio.h"
|
#include "stdbool.h"
|
||||||
|
#include "plat_types.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include "sys_api_cdc_comm.h"
|
#include "stdio.h"
|
||||||
#include "tool_msg.h"
|
#include "tool_msg.h"
|
||||||
|
#include "sys_api_cdc_comm.h"
|
||||||
|
#include "app_factory_cdc_comm.h"
|
||||||
|
|
||||||
static enum PARSE_STATE parse_state;
|
static enum PARSE_STATE parse_state;
|
||||||
static struct message_t recv_msg;
|
static struct message_t recv_msg;
|
||||||
static struct message_t send_msg = {
|
static struct message_t send_msg = { { PREFIX_CHAR, }, };
|
||||||
{
|
|
||||||
PREFIX_CHAR,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
static unsigned char check_sum(unsigned char *buf, unsigned char len) {
|
static unsigned char check_sum(unsigned char *buf, unsigned char len)
|
||||||
|
{
|
||||||
int i;
|
int i;
|
||||||
unsigned char sum = 0;
|
unsigned char sum = 0;
|
||||||
|
|
||||||
|
@ -27,7 +24,8 @@ static unsigned char check_sum(unsigned char *buf, unsigned char len) {
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
int send_reply(const unsigned char *payload, unsigned int len) {
|
int send_reply(const unsigned char *payload, unsigned int len)
|
||||||
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
if (len + 1 > sizeof(send_msg.data)) {
|
if (len + 1 > sizeof(send_msg.data)) {
|
||||||
|
@ -39,15 +37,15 @@ int send_reply(const unsigned char *payload, unsigned int len) {
|
||||||
send_msg.hdr.seq = recv_msg.hdr.seq;
|
send_msg.hdr.seq = recv_msg.hdr.seq;
|
||||||
send_msg.hdr.len = len;
|
send_msg.hdr.len = len;
|
||||||
memcpy(&send_msg.data[0], payload, len);
|
memcpy(&send_msg.data[0], payload, len);
|
||||||
send_msg.data[len] =
|
send_msg.data[len] = ~check_sum((unsigned char *)&send_msg, MSG_TOTAL_LEN(&send_msg) - 1);
|
||||||
~check_sum((unsigned char *)&send_msg, MSG_TOTAL_LEN(&send_msg) - 1);
|
|
||||||
|
|
||||||
ret = send_data((unsigned char *)&send_msg, MSG_TOTAL_LEN(&send_msg));
|
ret = send_data((unsigned char *)&send_msg, MSG_TOTAL_LEN(&send_msg));
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void reset_parse_state(unsigned char **buf, size_t *len) {
|
static void reset_parse_state(unsigned char **buf, size_t *len)
|
||||||
|
{
|
||||||
parse_state = PARSE_HEADER;
|
parse_state = PARSE_HEADER;
|
||||||
memset(&recv_msg.hdr, 0, sizeof(recv_msg.hdr));
|
memset(&recv_msg.hdr, 0, sizeof(recv_msg.hdr));
|
||||||
|
|
||||||
|
@ -55,7 +53,8 @@ static void reset_parse_state(unsigned char **buf, size_t *len) {
|
||||||
*len = sizeof(recv_msg.hdr);
|
*len = sizeof(recv_msg.hdr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum ERR_CODE check_msg_hdr(void) {
|
static enum ERR_CODE check_msg_hdr(void)
|
||||||
|
{
|
||||||
enum ERR_CODE errcode = ERR_NONE;
|
enum ERR_CODE errcode = ERR_NONE;
|
||||||
|
|
||||||
switch (recv_msg.hdr.type) {
|
switch (recv_msg.hdr.type) {
|
||||||
|
@ -88,8 +87,8 @@ static enum ERR_CODE check_msg_hdr(void) {
|
||||||
return errcode;
|
return errcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum ERR_CODE handle_sys_cmd(enum SYS_CMD_TYPE cmd, unsigned char *param,
|
static enum ERR_CODE handle_sys_cmd(enum SYS_CMD_TYPE cmd, unsigned char *param, unsigned int len)
|
||||||
unsigned int len) {
|
{
|
||||||
unsigned char cret[5];
|
unsigned char cret[5];
|
||||||
unsigned int bootmode;
|
unsigned int bootmode;
|
||||||
|
|
||||||
|
@ -150,7 +149,8 @@ static enum ERR_CODE handle_sys_cmd(enum SYS_CMD_TYPE cmd, unsigned char *param,
|
||||||
return ERR_NONE;
|
return ERR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum ERR_CODE handle_data(unsigned char **buf, size_t *len, int *extra) {
|
static enum ERR_CODE handle_data(unsigned char **buf, size_t *len, int *extra)
|
||||||
|
{
|
||||||
enum ERR_CODE errcode = ERR_NONE;
|
enum ERR_CODE errcode = ERR_NONE;
|
||||||
#if 0
|
#if 0
|
||||||
uint32_t rlen = 0;
|
uint32_t rlen = 0;
|
||||||
|
@ -166,8 +166,7 @@ static enum ERR_CODE handle_data(unsigned char **buf, size_t *len, int *extra) {
|
||||||
switch (recv_msg.hdr.type) {
|
switch (recv_msg.hdr.type) {
|
||||||
case TYPE_SYS: {
|
case TYPE_SYS: {
|
||||||
TRACE_TIME(0,"------ SYS CMD ------");
|
TRACE_TIME(0,"------ SYS CMD ------");
|
||||||
errcode = handle_sys_cmd((enum SYS_CMD_TYPE)recv_msg.data[0],
|
errcode = handle_sys_cmd((enum SYS_CMD_TYPE)recv_msg.data[0], &recv_msg.data[1], recv_msg.hdr.len - 1);
|
||||||
&recv_msg.data[1], recv_msg.hdr.len - 1);
|
|
||||||
if (errcode != ERR_NONE) {
|
if (errcode != ERR_NONE) {
|
||||||
return errcode;
|
return errcode;
|
||||||
}
|
}
|
||||||
|
@ -209,7 +208,8 @@ static enum ERR_CODE handle_data(unsigned char **buf, size_t *len, int *extra) {
|
||||||
return ERR_NONE;
|
return ERR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int parse_packet(unsigned char **buf, size_t *len) {
|
static int parse_packet(unsigned char **buf, size_t *len)
|
||||||
|
{
|
||||||
enum ERR_CODE errcode;
|
enum ERR_CODE errcode;
|
||||||
int rlen = *len;
|
int rlen = *len;
|
||||||
unsigned char *data;
|
unsigned char *data;
|
||||||
|
@ -264,7 +264,8 @@ _err:
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void comm_loop(void) {
|
void comm_loop(void)
|
||||||
|
{
|
||||||
int ret;
|
int ret;
|
||||||
unsigned char *buf = NULL;
|
unsigned char *buf = NULL;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
|
|
|
@ -11,8 +11,7 @@
|
||||||
#define TIMEOUT_INFINITE ((uint32_t)-1)
|
#define TIMEOUT_INFINITE ((uint32_t)-1)
|
||||||
|
|
||||||
const unsigned int default_recv_timeout_short = MS_TO_TICKS(500);
|
const unsigned int default_recv_timeout_short = MS_TO_TICKS(500);
|
||||||
const unsigned int default_recv_timeout_idle =
|
const unsigned int default_recv_timeout_idle = TIMEOUT_INFINITE; //MS_TO_TICKS(10 * 60 * 1000);
|
||||||
TIMEOUT_INFINITE; // MS_TO_TICKS(10 * 60 * 1000);
|
|
||||||
const unsigned int default_recv_timeout_4k_data = MS_TO_TICKS(500);
|
const unsigned int default_recv_timeout_4k_data = MS_TO_TICKS(500);
|
||||||
const unsigned int default_send_timeout = MS_TO_TICKS(500);
|
const unsigned int default_send_timeout = MS_TO_TICKS(500);
|
||||||
|
|
||||||
|
@ -30,7 +29,8 @@ static const struct USB_SERIAL_CFG_T cdc_cfg = {
|
||||||
.mode = USB_SERIAL_API_NONBLOCKING,
|
.mode = USB_SERIAL_API_NONBLOCKING,
|
||||||
};
|
};
|
||||||
|
|
||||||
void reset_transport(void) {
|
void reset_transport(void)
|
||||||
|
{
|
||||||
cancel_xfer = false;
|
cancel_xfer = false;
|
||||||
|
|
||||||
if (xfer_timer) {
|
if (xfer_timer) {
|
||||||
|
@ -45,13 +45,23 @@ void reset_transport(void) {
|
||||||
set_send_timeout(default_send_timeout);
|
set_send_timeout(default_send_timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_recv_timeout(unsigned int timeout) { recv_timeout = timeout; }
|
void set_recv_timeout(unsigned int timeout)
|
||||||
|
{
|
||||||
|
recv_timeout = timeout;
|
||||||
|
}
|
||||||
|
|
||||||
void set_send_timeout(unsigned int timeout) { send_timeout = timeout; }
|
void set_send_timeout(unsigned int timeout)
|
||||||
|
{
|
||||||
|
send_timeout = timeout;
|
||||||
|
}
|
||||||
|
|
||||||
static void usb_send_timeout(void *param) { usb_serial_cancel_send(); }
|
static void usb_send_timeout(void *param)
|
||||||
|
{
|
||||||
|
usb_serial_cancel_send();
|
||||||
|
}
|
||||||
|
|
||||||
static void usb_send_timer_start(void) {
|
static void usb_send_timer_start(void)
|
||||||
|
{
|
||||||
if (send_timeout == TIMEOUT_INFINITE) {
|
if (send_timeout == TIMEOUT_INFINITE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -61,13 +71,15 @@ static void usb_send_timer_start(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void usb_send_timer_stop(void) {
|
static void usb_send_timer_stop(void)
|
||||||
|
{
|
||||||
if (xfer_timer) {
|
if (xfer_timer) {
|
||||||
hwtimer_stop(xfer_timer);
|
hwtimer_stop(xfer_timer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int usb_send_data(const unsigned char *buf, size_t len) {
|
static int usb_send_data(const unsigned char *buf, size_t len)
|
||||||
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
usb_send_timer_start();
|
usb_send_timer_start();
|
||||||
|
@ -76,16 +88,21 @@ static int usb_send_data(const unsigned char *buf, size_t len) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int send_data(const unsigned char *buf, size_t len) {
|
int send_data(const unsigned char *buf, size_t len)
|
||||||
|
{
|
||||||
if (cancel_xfer) {
|
if (cancel_xfer) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return usb_send_data(buf, len);
|
return usb_send_data(buf, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void usb_recv_timeout(void *param) { usb_serial_cancel_recv(); }
|
static void usb_recv_timeout(void *param)
|
||||||
|
{
|
||||||
|
usb_serial_cancel_recv();
|
||||||
|
}
|
||||||
|
|
||||||
static void usb_recv_timer_start(void) {
|
static void usb_recv_timer_start(void)
|
||||||
|
{
|
||||||
if (recv_timeout == TIMEOUT_INFINITE) {
|
if (recv_timeout == TIMEOUT_INFINITE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -95,13 +112,15 @@ static void usb_recv_timer_start(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void usb_recv_timer_stop(void) {
|
static void usb_recv_timer_stop(void)
|
||||||
|
{
|
||||||
if (xfer_timer) {
|
if (xfer_timer) {
|
||||||
hwtimer_stop(xfer_timer);
|
hwtimer_stop(xfer_timer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int usb_recv_data(unsigned char *buf, size_t len, size_t *rlen) {
|
static int usb_recv_data(unsigned char *buf, size_t len, size_t *rlen)
|
||||||
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
usb_recv_timer_start();
|
usb_recv_timer_start();
|
||||||
|
@ -113,14 +132,16 @@ static int usb_recv_data(unsigned char *buf, size_t len, size_t *rlen) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int recv_data_ex(unsigned char *buf, size_t len, size_t expect, size_t *rlen) {
|
int recv_data_ex(unsigned char *buf, size_t len, size_t expect, size_t *rlen)
|
||||||
|
{
|
||||||
if (cancel_xfer) {
|
if (cancel_xfer) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return usb_recv_data(buf, expect, rlen);
|
return usb_recv_data(buf, expect, rlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int usb_handle_error(void) {
|
static int usb_handle_error(void)
|
||||||
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
TRACE(0,"****** Send break ******");
|
TRACE(0,"****** Send break ******");
|
||||||
|
@ -133,7 +154,8 @@ static int usb_handle_error(void) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int handle_error(void) {
|
int handle_error(void)
|
||||||
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
uint32_t err_time;
|
uint32_t err_time;
|
||||||
|
|
||||||
|
@ -160,16 +182,24 @@ int handle_error(void) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int usb_cancel_input(void) { return usb_serial_flush_recv_buffer(); }
|
static int usb_cancel_input(void)
|
||||||
|
{
|
||||||
|
return usb_serial_flush_recv_buffer();
|
||||||
|
}
|
||||||
|
|
||||||
int cancel_input(void) { return usb_cancel_input(); }
|
int cancel_input(void)
|
||||||
|
{
|
||||||
|
return usb_cancel_input();
|
||||||
|
}
|
||||||
|
|
||||||
void system_reboot(void) {
|
void system_reboot(void)
|
||||||
|
{
|
||||||
hal_sys_timer_delay(MS_TO_TICKS(10));
|
hal_sys_timer_delay(MS_TO_TICKS(10));
|
||||||
hal_cmu_sys_reboot();
|
hal_cmu_sys_reboot();
|
||||||
}
|
}
|
||||||
|
|
||||||
void system_shutdown(void) {
|
void system_shutdown(void)
|
||||||
|
{
|
||||||
#if 0
|
#if 0
|
||||||
if (dld_transport == TRANSPORT_USB) {
|
if (dld_transport == TRANSPORT_USB) {
|
||||||
// Avoid PC usb serial driver hanging
|
// Avoid PC usb serial driver hanging
|
||||||
|
@ -180,15 +210,20 @@ void system_shutdown(void) {
|
||||||
pmu_shutdown();
|
pmu_shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
void system_set_bootmode(unsigned int bootmode) {
|
void system_set_bootmode(unsigned int bootmode)
|
||||||
|
{
|
||||||
bootmode &= ~(HAL_SW_BOOTMODE_READ_ENABLED | HAL_SW_BOOTMODE_WRITE_ENABLED);
|
bootmode &= ~(HAL_SW_BOOTMODE_READ_ENABLED | HAL_SW_BOOTMODE_WRITE_ENABLED);
|
||||||
hal_sw_bootmode_set(bootmode);
|
hal_sw_bootmode_set(bootmode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void system_clear_bootmode(unsigned int bootmode) {
|
void system_clear_bootmode(unsigned int bootmode)
|
||||||
|
{
|
||||||
bootmode &= ~(HAL_SW_BOOTMODE_READ_ENABLED | HAL_SW_BOOTMODE_WRITE_ENABLED);
|
bootmode &= ~(HAL_SW_BOOTMODE_READ_ENABLED | HAL_SW_BOOTMODE_WRITE_ENABLED);
|
||||||
hal_sw_bootmode_clear(bootmode);
|
hal_sw_bootmode_clear(bootmode);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int system_get_bootmode(void) { return hal_sw_bootmode_get(); }
|
unsigned int system_get_bootmode(void)
|
||||||
|
{
|
||||||
|
return hal_sw_bootmode_get();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -13,12 +13,12 @@
|
||||||
* trademark and other intellectual property rights.
|
* trademark and other intellectual property rights.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include "app_key.h"
|
|
||||||
#include "app_thread.h"
|
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
#include "hal_trace.h"
|
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
#include "app_thread.h"
|
||||||
|
#include "app_key.h"
|
||||||
|
#include "hal_trace.h"
|
||||||
|
|
||||||
#define APP_KEY_TRACE(s,...) //TRACE(s, ##__VA_ARGS__)
|
#define APP_KEY_TRACE(s,...) //TRACE(s, ##__VA_ARGS__)
|
||||||
|
|
||||||
|
@ -28,13 +28,16 @@ typedef struct {
|
||||||
list_t *key_list;
|
list_t *key_list;
|
||||||
}APP_KEY_CONFIG;
|
}APP_KEY_CONFIG;
|
||||||
|
|
||||||
APP_KEY_CONFIG app_key_conifg = {.key_list = NULL};
|
APP_KEY_CONFIG app_key_conifg = {
|
||||||
|
.key_list = NULL
|
||||||
|
};
|
||||||
|
|
||||||
osPoolDef (app_key_handle_mempool, 20, APP_KEY_HANDLE);
|
osPoolDef (app_key_handle_mempool, 20, APP_KEY_HANDLE);
|
||||||
osPoolId app_key_handle_mempool = NULL;
|
osPoolId app_key_handle_mempool = NULL;
|
||||||
static uint8_t key_event_cnt = 0;
|
static uint8_t key_event_cnt = 0;
|
||||||
|
|
||||||
static int key_event_process(uint32_t key_code, uint8_t key_event) {
|
static int key_event_process(uint32_t key_code, uint8_t key_event)
|
||||||
|
{
|
||||||
uint32_t app_keyevt;
|
uint32_t app_keyevt;
|
||||||
APP_MESSAGE_BLOCK msg;
|
APP_MESSAGE_BLOCK msg;
|
||||||
|
|
||||||
|
@ -53,38 +56,39 @@ static int key_event_process(uint32_t key_code, uint8_t key_event) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void app_key_simulate_key_event(uint32_t key_code, uint8_t key_event) {
|
void app_key_simulate_key_event(uint32_t key_code, uint8_t key_event)
|
||||||
|
{
|
||||||
key_event_process(key_code, key_event);
|
key_event_process(key_code, key_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void app_key_handle_free(void *key_handle) {
|
static void app_key_handle_free(void *key_handle)
|
||||||
|
{
|
||||||
osPoolFree (app_key_handle_mempool, key_handle);
|
osPoolFree (app_key_handle_mempool, key_handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
static APP_KEY_HANDLE *app_key_handle_find(const APP_KEY_STATUS *key_status) {
|
static APP_KEY_HANDLE *app_key_handle_find(const APP_KEY_STATUS *key_status)
|
||||||
|
{
|
||||||
APP_KEY_HANDLE *key_handle = NULL;
|
APP_KEY_HANDLE *key_handle = NULL;
|
||||||
list_node_t *node = NULL;
|
list_node_t *node = NULL;
|
||||||
|
|
||||||
for (node = list_begin(app_key_conifg.key_list);
|
for (node = list_begin(app_key_conifg.key_list); node != list_end(app_key_conifg.key_list); node = list_next(node)) {
|
||||||
node != list_end(app_key_conifg.key_list); node = list_next(node)) {
|
|
||||||
key_handle = (APP_KEY_HANDLE *)list_node(node);
|
key_handle = (APP_KEY_HANDLE *)list_node(node);
|
||||||
if ((key_handle->key_status.code == key_status->code) &&
|
if ((key_handle->key_status.code == key_status->code)&&(key_handle->key_status.event == key_status->event))
|
||||||
(key_handle->key_status.event == key_status->event))
|
|
||||||
return key_handle;
|
return key_handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int app_key_handle_process(APP_MESSAGE_BODY *msg_body) {
|
static int app_key_handle_process(APP_MESSAGE_BODY *msg_body)
|
||||||
|
{
|
||||||
APP_KEY_STATUS key_status;
|
APP_KEY_STATUS key_status;
|
||||||
APP_KEY_HANDLE *key_handle = NULL;
|
APP_KEY_HANDLE *key_handle = NULL;
|
||||||
|
|
||||||
APP_KEY_GET_CODE(msg_body->message_id, key_status.code);
|
APP_KEY_GET_CODE(msg_body->message_id, key_status.code);
|
||||||
APP_KEY_GET_EVENT(msg_body->message_id, key_status.event);
|
APP_KEY_GET_EVENT(msg_body->message_id, key_status.event);
|
||||||
|
|
||||||
APP_KEY_TRACE(3, "%s code:%d event:%d", __func__, key_status.code,
|
APP_KEY_TRACE(3,"%s code:%d event:%d",__func__,key_status.code, key_status.event);
|
||||||
key_status.event);
|
|
||||||
|
|
||||||
key_event_cnt--;
|
key_event_cnt--;
|
||||||
|
|
||||||
|
@ -96,7 +100,8 @@ static int app_key_handle_process(APP_MESSAGE_BODY *msg_body) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_key_handle_registration(const APP_KEY_HANDLE *key_handle) {
|
int app_key_handle_registration(const APP_KEY_HANDLE *key_handle)
|
||||||
|
{
|
||||||
APP_KEY_HANDLE *dest_key_handle = NULL;
|
APP_KEY_HANDLE *dest_key_handle = NULL;
|
||||||
APP_KEY_TRACE(1,"%s",__func__);
|
APP_KEY_TRACE(1,"%s",__func__);
|
||||||
dest_key_handle = app_key_handle_find(&(key_handle->key_status));
|
dest_key_handle = app_key_handle_find(&(key_handle->key_status));
|
||||||
|
@ -109,22 +114,23 @@ int app_key_handle_registration(const APP_KEY_HANDLE *key_handle) {
|
||||||
}
|
}
|
||||||
if (dest_key_handle == NULL)
|
if (dest_key_handle == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
APP_KEY_TRACE(5, "%s set handle:0x%x code:%d event:%d function:%x", __func__,
|
APP_KEY_TRACE(5,"%s set handle:0x%x code:%d event:%d function:%x",__func__,dest_key_handle, key_handle->key_status.code, key_handle->key_status.event, key_handle->function);
|
||||||
dest_key_handle, key_handle->key_status.code,
|
|
||||||
key_handle->key_status.event, key_handle->function);
|
|
||||||
dest_key_handle->key_status.code = key_handle->key_status.code;
|
dest_key_handle->key_status.code = key_handle->key_status.code;
|
||||||
dest_key_handle->key_status.event = key_handle->key_status.event;
|
dest_key_handle->key_status.event = key_handle->key_status.event;
|
||||||
dest_key_handle->string = key_handle->string;
|
dest_key_handle->string = key_handle->string;
|
||||||
dest_key_handle->function = key_handle->function;
|
dest_key_handle->function = key_handle->function;
|
||||||
dest_key_handle->param = key_handle->param;
|
dest_key_handle->param = key_handle->param;;
|
||||||
;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void app_key_handle_clear(void) { list_clear(app_key_conifg.key_list); }
|
void app_key_handle_clear(void)
|
||||||
|
{
|
||||||
|
list_clear(app_key_conifg.key_list);
|
||||||
|
}
|
||||||
|
|
||||||
int app_key_open(int checkPwrKey) {
|
int app_key_open(int checkPwrKey)
|
||||||
|
{
|
||||||
APP_KEY_TRACE(2,"%s %x",__func__, app_key_conifg.key_list);
|
APP_KEY_TRACE(2,"%s %x",__func__, app_key_conifg.key_list);
|
||||||
|
|
||||||
if (app_key_conifg.key_list == NULL)
|
if (app_key_conifg.key_list == NULL)
|
||||||
|
@ -138,7 +144,8 @@ int app_key_open(int checkPwrKey) {
|
||||||
return hal_key_open(checkPwrKey, key_event_process);
|
return hal_key_open(checkPwrKey, key_event_process);
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_key_close(void) {
|
int app_key_close(void)
|
||||||
|
{
|
||||||
hal_key_close();
|
hal_key_close();
|
||||||
if (app_key_conifg.key_list != NULL)
|
if (app_key_conifg.key_list != NULL)
|
||||||
list_free(app_key_conifg.key_list);
|
list_free(app_key_conifg.key_list);
|
||||||
|
@ -146,12 +153,15 @@ int app_key_close(void) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t app_key_read_status(uint32_t code) {
|
uint32_t app_key_read_status(uint32_t code)
|
||||||
|
{
|
||||||
return (uint32_t)hal_key_read_status((enum HAL_KEY_CODE_T)code);
|
return (uint32_t)hal_key_read_status((enum HAL_KEY_CODE_T)code);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(_AUTO_TEST_)
|
#if defined(_AUTO_TEST_)
|
||||||
int simul_key_event_process(uint32_t key_code, uint8_t key_event) {
|
int simul_key_event_process(uint32_t key_code, uint8_t key_event)
|
||||||
|
{
|
||||||
return key_event_process(key_code, key_event);
|
return key_event_process(key_code, key_event);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -13,17 +13,12 @@
|
||||||
* trademark and other intellectual property rights.
|
* trademark and other intellectual property rights.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include "hal_key.h"
|
|
||||||
|
|
||||||
#ifndef __APP_KEY_H__
|
#ifndef __APP_KEY_H__
|
||||||
#define __APP_KEY_H__
|
#define __APP_KEY_H__
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#include "hal_key.h"
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define APP_KEY_SET_MESSAGE(appevt, code, evt) \
|
#define APP_KEY_SET_MESSAGE(appevt, code, evt) (appevt = (((uint32_t)code&0xffffff)<<8)|(evt&0xff))
|
||||||
(appevt = (((uint32_t)code & 0xffffff) << 8) | (evt & 0xff))
|
|
||||||
#define APP_KEY_GET_CODE(appevt, code) (code = (appevt>>8)&0xffffff)
|
#define APP_KEY_GET_CODE(appevt, code) (code = (appevt>>8)&0xffffff)
|
||||||
#define APP_KEY_GET_EVENT(appevt, evt) (evt = appevt&0xff)
|
#define APP_KEY_GET_EVENT(appevt, evt) (evt = appevt&0xff)
|
||||||
|
|
||||||
|
@ -111,8 +106,4 @@ void app_key_simulate_key_event(uint32_t key_code, uint8_t key_event);
|
||||||
#if defined(_AUTO_TEST_)
|
#if defined(_AUTO_TEST_)
|
||||||
int simul_key_event_process(uint32_t key_code, uint8_t key_event);
|
int simul_key_event_process(uint32_t key_code, uint8_t key_event);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
#endif//__FMDEC_H__
|
#endif//__FMDEC_H__
|
||||||
|
|
1705
apps/main/apps.cpp
1705
apps/main/apps.cpp
File diff suppressed because it is too large
Load Diff
|
@ -38,10 +38,10 @@ int app_reset(void);
|
||||||
int app_status_battery_report(uint8_t level);
|
int app_status_battery_report(uint8_t level);
|
||||||
|
|
||||||
int app_voice_report( APP_STATUS_INDICATION_T status,uint8_t device_id);
|
int app_voice_report( APP_STATUS_INDICATION_T status,uint8_t device_id);
|
||||||
int app_voice_report_generic(APP_STATUS_INDICATION_T status, uint8_t device_id,
|
int app_voice_report_generic(APP_STATUS_INDICATION_T status, uint8_t device_id, uint8_t isMerging);
|
||||||
uint8_t isMerging);
|
|
||||||
int app_voice_stop(APP_STATUS_INDICATION_T status, uint8_t device_id);
|
int app_voice_stop(APP_STATUS_INDICATION_T status, uint8_t device_id);
|
||||||
|
|
||||||
|
|
||||||
/*FixME*/
|
/*FixME*/
|
||||||
void app_status_set_num(const char* p);
|
void app_status_set_num(const char* p);
|
||||||
|
|
||||||
|
@ -68,6 +68,10 @@ void app_disconnect_all_bt_connections(void);
|
||||||
bool app_is_stack_ready(void);
|
bool app_is_stack_ready(void);
|
||||||
|
|
||||||
extern uint8_t latency_mode_is_open;
|
extern uint8_t latency_mode_is_open;
|
||||||
|
bool Curr_Is_Master(void);
|
||||||
|
bool Curr_Is_Slave(void);
|
||||||
|
extern uint8_t get_nv_role(void);
|
||||||
|
extern uint8_t get_curr_role(void);
|
||||||
extern uint8_t app_poweroff_flag;
|
extern uint8_t app_poweroff_flag;
|
||||||
extern bool MobileLinkLose_reboot;
|
extern bool MobileLinkLose_reboot;
|
||||||
extern bool factory_mode_status;
|
extern bool factory_mode_status;
|
||||||
|
@ -82,6 +86,7 @@ extern int app_nvrecord_rebuild(void);
|
||||||
extern void app_bt_power_off_customize();
|
extern void app_bt_power_off_customize();
|
||||||
////////////////////
|
////////////////////
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -13,21 +13,21 @@
|
||||||
* trademark and other intellectual property rights.
|
* trademark and other intellectual property rights.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include "cmsis_os.h"
|
|
||||||
#include "stdio.h"
|
#include "stdio.h"
|
||||||
|
#include "cmsis_os.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
|
||||||
#include "app_key.h"
|
|
||||||
#include "hal_iomux.h"
|
#include "hal_iomux.h"
|
||||||
#include "hal_sleep.h"
|
#include "app_key.h"
|
||||||
#include "hal_trace.h"
|
#include "hal_trace.h"
|
||||||
|
#include "hal_sleep.h"
|
||||||
|
|
||||||
|
#include "audioflinger.h"
|
||||||
|
#include "audiobuffer.h"
|
||||||
#include "app_thread.h"
|
#include "app_thread.h"
|
||||||
#include "app_utils.h"
|
#include "app_utils.h"
|
||||||
#include "audiobuffer.h"
|
|
||||||
#include "audioflinger.h"
|
|
||||||
#include "besbt.h"
|
|
||||||
#include "bt_drv_interface.h"
|
#include "bt_drv_interface.h"
|
||||||
|
#include "besbt.h"
|
||||||
|
|
||||||
#if defined(APP_TEST_AUDIO) && defined(ANC_APP)
|
#if defined(APP_TEST_AUDIO) && defined(ANC_APP)
|
||||||
#include "anc_usb_app.h"
|
#include "anc_usb_app.h"
|
||||||
|
@ -43,7 +43,8 @@ extern void app_anc_usb_init(void);
|
||||||
|
|
||||||
#define REG(a) *(volatile uint32_t *)(a)
|
#define REG(a) *(volatile uint32_t *)(a)
|
||||||
|
|
||||||
void bt_signaling_test(APP_KEY_STATUS *status, void *param) {
|
void bt_signaling_test(APP_KEY_STATUS *status, void *param)
|
||||||
|
{
|
||||||
TRACE(3,"%s %d,%d",__func__, status->code, status->event);
|
TRACE(3,"%s %d,%d",__func__, status->code, status->event);
|
||||||
|
|
||||||
hal_cpu_wake_lock(APP_TESTER_CPU_WAKE_LOCK);
|
hal_cpu_wake_lock(APP_TESTER_CPU_WAKE_LOCK);
|
||||||
|
@ -51,14 +52,16 @@ void bt_signaling_test(APP_KEY_STATUS *status, void *param) {
|
||||||
btdrv_enable_dut();
|
btdrv_enable_dut();
|
||||||
}
|
}
|
||||||
|
|
||||||
void bt_stack_test(APP_KEY_STATUS *status, void *param) {
|
void bt_stack_test(APP_KEY_STATUS *status, void *param)
|
||||||
|
{
|
||||||
TRACE(3,"%s %d,%d",__func__, status->code, status->event);
|
TRACE(3,"%s %d,%d",__func__, status->code, status->event);
|
||||||
|
|
||||||
btdrv_start_bt();
|
btdrv_start_bt();
|
||||||
BesbtInit();
|
BesbtInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void bt_ble_test(APP_KEY_STATUS *status, void *param) {
|
void bt_ble_test(APP_KEY_STATUS *status, void *param)
|
||||||
|
{
|
||||||
TRACE(3,"%s %d,%d",__func__, status->code, status->event);
|
TRACE(3,"%s %d,%d",__func__, status->code, status->event);
|
||||||
|
|
||||||
hal_cpu_wake_lock(APP_TESTER_CPU_WAKE_LOCK);
|
hal_cpu_wake_lock(APP_TESTER_CPU_WAKE_LOCK);
|
||||||
|
@ -69,7 +72,8 @@ void bt_ble_test(APP_KEY_STATUS *status, void *param) {
|
||||||
btdrv_uart_bridge_loop();
|
btdrv_uart_bridge_loop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void bt_test_104m(APP_KEY_STATUS *status, void *param) {
|
void bt_test_104m(APP_KEY_STATUS *status, void *param)
|
||||||
|
{
|
||||||
TRACE(3,"%s %d,%d",__func__, status->code, status->event);
|
TRACE(3,"%s %d,%d",__func__, status->code, status->event);
|
||||||
|
|
||||||
hal_analogif_reg_write(0x35,0x0);
|
hal_analogif_reg_write(0x35,0x0);
|
||||||
|
@ -80,39 +84,48 @@ void bt_test_104m(APP_KEY_STATUS *status, void *param) {
|
||||||
hal_analogif_reg_write(0xC,0x3790);
|
hal_analogif_reg_write(0xC,0x3790);
|
||||||
}
|
}
|
||||||
|
|
||||||
void bt_change_to_iic(APP_KEY_STATUS *status, void *param) {
|
void bt_change_to_iic(APP_KEY_STATUS *status, void *param)
|
||||||
|
{
|
||||||
TRACE(3,"%s %d,%d",__func__, status->code, status->event);
|
TRACE(3,"%s %d,%d",__func__, status->code, status->event);
|
||||||
|
|
||||||
hal_iomux_set_analog_i2c();
|
hal_iomux_set_analog_i2c();
|
||||||
}
|
}
|
||||||
|
|
||||||
void bt_change_to_uart0(APP_KEY_STATUS *status, void *param) {
|
void bt_change_to_uart0(APP_KEY_STATUS *status, void *param)
|
||||||
|
{
|
||||||
TRACE(3,"%s %d,%d",__func__, status->code, status->event);
|
TRACE(3,"%s %d,%d",__func__, status->code, status->event);
|
||||||
|
|
||||||
hal_iomux_set_uart0();
|
hal_iomux_set_uart0();
|
||||||
}
|
}
|
||||||
|
|
||||||
void app_switch_i2c_uart(APP_KEY_STATUS *status, void *param) {
|
void app_switch_i2c_uart(APP_KEY_STATUS *status, void *param)
|
||||||
|
{
|
||||||
static uint32_t flag = 1;
|
static uint32_t flag = 1;
|
||||||
|
|
||||||
TRACE(2,"[%s] flag = %d",__func__, flag);
|
TRACE(2,"[%s] flag = %d",__func__, flag);
|
||||||
if (flag) {
|
if(flag)
|
||||||
|
{
|
||||||
bt_change_to_iic(NULL, NULL);
|
bt_change_to_iic(NULL, NULL);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
bt_change_to_uart0(NULL, NULL);
|
bt_change_to_uart0(NULL, NULL);
|
||||||
}
|
}
|
||||||
flag = !flag;
|
flag = !flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_power_off(APP_KEY_STATUS *status, void *param) {
|
void test_power_off(APP_KEY_STATUS *status, void *param)
|
||||||
|
{
|
||||||
TRACE(0,"app_power_off\n");
|
TRACE(0,"app_power_off\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
extern APP_KEY_STATUS bt_key;
|
extern APP_KEY_STATUS bt_key;
|
||||||
|
|
||||||
void test_bt_key(APP_KEY_STATUS *status, void *param) {
|
void test_bt_key(APP_KEY_STATUS *status, void *param)
|
||||||
|
{
|
||||||
TRACE(3,"%s %d,%d",__func__, status->code, status->event);
|
TRACE(3,"%s %d,%d",__func__, status->code, status->event);
|
||||||
if (bt_key.code == 0xff) {
|
if(bt_key.code == 0xff)
|
||||||
|
{
|
||||||
bt_key.code = status->code;
|
bt_key.code = status->code;
|
||||||
bt_key.event = status->event;
|
bt_key.event = status->event;
|
||||||
OS_NotifyEvm();
|
OS_NotifyEvm();
|
||||||
|
@ -125,7 +138,8 @@ void test_bt_key(APP_KEY_STATUS *status, void *param) {
|
||||||
#define SD_BUF_SIZE (10)
|
#define SD_BUF_SIZE (10)
|
||||||
uint8_t sd_buf[SD_BUF_SIZE]={0,1,2,3,4,5,6,7,8,9};
|
uint8_t sd_buf[SD_BUF_SIZE]={0,1,2,3,4,5,6,7,8,9};
|
||||||
|
|
||||||
void test_sd_card() {
|
void test_sd_card()
|
||||||
|
{
|
||||||
sd_open();
|
sd_open();
|
||||||
|
|
||||||
dump_data2sd(APP_SDMMC_DUMP_OPEN, NULL , 0);
|
dump_data2sd(APP_SDMMC_DUMP_OPEN, NULL , 0);
|
||||||
|
@ -135,118 +149,84 @@ void test_sd_card() {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef APP_TEST_AUDIO
|
#ifdef APP_TEST_AUDIO
|
||||||
extern void adc_looptester(bool on, enum AUD_IO_PATH_T input_path,
|
extern void adc_looptester(bool on, enum AUD_IO_PATH_T input_path, enum AUD_SAMPRATE_T sample_rate);
|
||||||
enum AUD_SAMPRATE_T sample_rate);
|
void test_codec_loop(APP_KEY_STATUS *status, void *param)
|
||||||
void test_codec_loop(APP_KEY_STATUS *status, void *param) {
|
{
|
||||||
audio_buffer_init();
|
audio_buffer_init();
|
||||||
adc_looptester(true, AUD_INPUT_PATH_MAINMIC, AUD_SAMPRATE_8000);
|
adc_looptester(true, AUD_INPUT_PATH_MAINMIC, AUD_SAMPRATE_8000);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ANC_APP
|
#ifdef ANC_APP
|
||||||
void test_anc(APP_KEY_STATUS *status, void *param) { anc_usb_app((bool)param); }
|
void test_anc(APP_KEY_STATUS *status, void *param)
|
||||||
|
{
|
||||||
|
anc_usb_app((bool)param);
|
||||||
|
}
|
||||||
|
|
||||||
void test_usb_audio(APP_KEY_STATUS *status, void *param) {
|
void test_usb_audio(APP_KEY_STATUS *status, void *param)
|
||||||
|
{
|
||||||
usb_audio_app((bool)param);
|
usb_audio_app((bool)param);
|
||||||
//dualadc_audio_app((bool)param);
|
//dualadc_audio_app((bool)param);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void bt_change_to_jlink(APP_KEY_STATUS *status, void *param) {
|
void bt_change_to_jlink(APP_KEY_STATUS *status, void *param)
|
||||||
|
{
|
||||||
hal_iomux_set_jtag();
|
hal_iomux_set_jtag();
|
||||||
|
|
||||||
hal_cmu_jtag_clock_enable();
|
hal_cmu_jtag_clock_enable();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void bt_enable_tports(void) {
|
void bt_enable_tports(void)
|
||||||
|
{
|
||||||
hal_iomux_set_bt_tport();
|
hal_iomux_set_bt_tport();
|
||||||
bt_drv_bt_tport_type_config();
|
bt_drv_bt_tport_type_config();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef APP_TEST_AUDIO
|
#ifdef APP_TEST_AUDIO
|
||||||
extern void da_tester(uint8_t on);
|
extern void da_tester(uint8_t on);
|
||||||
void bt_test_dsp_process(APP_KEY_STATUS *status, void *param) { da_tester(1); }
|
void bt_test_dsp_process(APP_KEY_STATUS *status, void *param)
|
||||||
|
{
|
||||||
|
da_tester(1);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#define MENU_TITLE_MAX_SIZE (50)
|
#define MENU_TITLE_MAX_SIZE (50)
|
||||||
APP_KEY_HANDLE app_testcase[] = {
|
APP_KEY_HANDLE app_testcase[] = {
|
||||||
#if defined(APP_TEST_AUDIO) && defined(ANC_APP)
|
#if defined(APP_TEST_AUDIO) && defined(ANC_APP)
|
||||||
{{APP_KEY_CODE_FN2, APP_KEY_EVENT_UP},
|
{{APP_KEY_CODE_FN2,APP_KEY_EVENT_UP},"USB AUDIO TEST OFF",test_usb_audio, (void *)0},
|
||||||
"USB AUDIO TEST OFF",
|
{{APP_KEY_CODE_FN5,APP_KEY_EVENT_UP},"USB AUDIO TEST ON",test_usb_audio, (void *)1},
|
||||||
test_usb_audio,
|
|
||||||
(void *)0},
|
|
||||||
{{APP_KEY_CODE_FN5, APP_KEY_EVENT_UP},
|
|
||||||
"USB AUDIO TEST ON",
|
|
||||||
test_usb_audio,
|
|
||||||
(void *)1},
|
|
||||||
{{APP_KEY_CODE_FN3,APP_KEY_EVENT_UP},"ANC TEST OFF",test_anc, (void *)0},
|
{{APP_KEY_CODE_FN3,APP_KEY_EVENT_UP},"ANC TEST OFF",test_anc, (void *)0},
|
||||||
{{APP_KEY_CODE_FN6,APP_KEY_EVENT_UP},"ANC TEST ON",test_anc, (void *)1},
|
{{APP_KEY_CODE_FN6,APP_KEY_EVENT_UP},"ANC TEST ON",test_anc, (void *)1},
|
||||||
#else
|
#else
|
||||||
#ifdef APP_TEST_AUDIO
|
#ifdef APP_TEST_AUDIO
|
||||||
{{APP_KEY_CODE_FN1, APP_KEY_EVENT_LONGPRESS},
|
{{APP_KEY_CODE_FN1,APP_KEY_EVENT_LONGPRESS},"LONGPRESS: test_codec_loop",test_codec_loop, NULL},
|
||||||
"LONGPRESS: test_codec_loop",
|
|
||||||
test_codec_loop,
|
|
||||||
NULL},
|
|
||||||
#endif
|
#endif
|
||||||
{{APP_KEY_CODE_FN1, APP_KEY_EVENT_UP},
|
{{APP_KEY_CODE_FN1,APP_KEY_EVENT_UP},"bt_signaling_test",bt_signaling_test, NULL},
|
||||||
"bt_signaling_test",
|
|
||||||
bt_signaling_test,
|
|
||||||
NULL},
|
|
||||||
{{APP_KEY_CODE_FN2,APP_KEY_EVENT_UP},"bt gogogogo" ,bt_stack_test, NULL},
|
{{APP_KEY_CODE_FN2,APP_KEY_EVENT_UP},"bt gogogogo" ,bt_stack_test, NULL},
|
||||||
{{APP_KEY_CODE_FN3, APP_KEY_EVENT_UP},
|
{{APP_KEY_CODE_FN3,APP_KEY_EVENT_UP},"bt change to 104m",bt_test_104m, NULL},
|
||||||
"bt change to 104m",
|
|
||||||
bt_test_104m,
|
|
||||||
NULL},
|
|
||||||
{{APP_KEY_CODE_FN4,APP_KEY_EVENT_UP},"ble test mode" ,bt_ble_test, NULL},
|
{{APP_KEY_CODE_FN4,APP_KEY_EVENT_UP},"ble test mode" ,bt_ble_test, NULL},
|
||||||
#ifdef APP_TEST_AUDIO
|
#ifdef APP_TEST_AUDIO
|
||||||
{{APP_KEY_CODE_FN5, APP_KEY_EVENT_UP},
|
{{APP_KEY_CODE_FN5,APP_KEY_EVENT_UP},"dsp eq test" ,bt_test_dsp_process, NULL},
|
||||||
"dsp eq test",
|
|
||||||
bt_test_dsp_process,
|
|
||||||
NULL},
|
|
||||||
#endif
|
#endif
|
||||||
{{APP_KEY_CODE_FN5, APP_KEY_EVENT_LONGPRESS},
|
{{APP_KEY_CODE_FN5,APP_KEY_EVENT_LONGPRESS},"LONGPRESS: bt volume up key" ,test_bt_key, NULL},
|
||||||
"LONGPRESS: bt volume up key",
|
|
||||||
test_bt_key,
|
|
||||||
NULL},
|
|
||||||
|
|
||||||
{{APP_KEY_CODE_FN6, APP_KEY_EVENT_UP},
|
{{APP_KEY_CODE_FN6,APP_KEY_EVENT_UP},"bt volume down key" ,test_bt_key, NULL},
|
||||||
"bt volume down key",
|
{{APP_KEY_CODE_FN6,APP_KEY_EVENT_LONGPRESS},"LONGPRESS: bt volume down key" ,test_bt_key, NULL},
|
||||||
test_bt_key,
|
|
||||||
NULL},
|
|
||||||
{{APP_KEY_CODE_FN6, APP_KEY_EVENT_LONGPRESS},
|
|
||||||
"LONGPRESS: bt volume down key",
|
|
||||||
test_bt_key,
|
|
||||||
NULL},
|
|
||||||
|
|
||||||
{{APP_KEY_CODE_FN7, APP_KEY_EVENT_CLICK},
|
{{APP_KEY_CODE_FN7,APP_KEY_EVENT_CLICK},"bt function key" ,test_bt_key, NULL},
|
||||||
"bt function key",
|
{{APP_KEY_CODE_FN7,APP_KEY_EVENT_DOUBLECLICK},"DOUBLECLICK: bt function key" ,test_bt_key, NULL},
|
||||||
test_bt_key,
|
{{APP_KEY_CODE_FN7,APP_KEY_EVENT_LONGPRESS},"LONGPRESS: bt function key" ,test_bt_key, NULL},
|
||||||
NULL},
|
|
||||||
{{APP_KEY_CODE_FN7, APP_KEY_EVENT_DOUBLECLICK},
|
|
||||||
"DOUBLECLICK: bt function key",
|
|
||||||
test_bt_key,
|
|
||||||
NULL},
|
|
||||||
{{APP_KEY_CODE_FN7, APP_KEY_EVENT_LONGPRESS},
|
|
||||||
"LONGPRESS: bt function key",
|
|
||||||
test_bt_key,
|
|
||||||
NULL},
|
|
||||||
|
|
||||||
{{APP_KEY_CODE_FN8, APP_KEY_EVENT_UP},
|
{{APP_KEY_CODE_FN8,APP_KEY_EVENT_UP},"open jlink" ,bt_change_to_jlink, NULL},
|
||||||
"open jlink",
|
{{APP_KEY_CODE_FN9,APP_KEY_EVENT_UP},"iic_map2_P3_0" ,bt_change_to_iic, NULL},
|
||||||
bt_change_to_jlink,
|
{{APP_KEY_CODE_PWR,APP_KEY_EVENT_LONGPRESS},"LONGPRESS: power off" ,test_power_off, NULL},
|
||||||
NULL},
|
|
||||||
{{APP_KEY_CODE_FN9, APP_KEY_EVENT_UP},
|
|
||||||
"iic_map2_P3_0",
|
|
||||||
bt_change_to_iic,
|
|
||||||
NULL},
|
|
||||||
{{APP_KEY_CODE_PWR, APP_KEY_EVENT_LONGPRESS},
|
|
||||||
"LONGPRESS: power off",
|
|
||||||
test_power_off,
|
|
||||||
NULL},
|
|
||||||
#endif // !(APP_TEST_AUDIO && ANC_APP)
|
#endif // !(APP_TEST_AUDIO && ANC_APP)
|
||||||
{{0xff, APP_KEY_EVENT_NONE}, NULL, (uint32_t)NULL, 0},
|
{{0xff, APP_KEY_EVENT_NONE}, NULL, (uint32_t)NULL, 0},
|
||||||
};
|
};
|
||||||
|
|
||||||
int app_testcase_disp_menu(APP_KEY_HANDLE *testcase, bool printall) {
|
int app_testcase_disp_menu(APP_KEY_HANDLE* testcase, bool printall)
|
||||||
|
{
|
||||||
char buf[MENU_TITLE_MAX_SIZE+1];
|
char buf[MENU_TITLE_MAX_SIZE+1];
|
||||||
if (strlen(testcase->string)>(MENU_TITLE_MAX_SIZE-15)){
|
if (strlen(testcase->string)>(MENU_TITLE_MAX_SIZE-15)){
|
||||||
TRACE(0,"string too long, please check again\n");
|
TRACE(0,"string too long, please check again\n");
|
||||||
|
@ -265,8 +245,7 @@ int app_testcase_disp_menu(APP_KEY_HANDLE *testcase, bool printall) {
|
||||||
}
|
}
|
||||||
|
|
||||||
do{
|
do{
|
||||||
snprintf(buf, sizeof(buf), "| (0x%X)%s", testcase->key_status.code,
|
snprintf(buf, sizeof(buf), "| (0x%X)%s", testcase->key_status.code, testcase->string);
|
||||||
testcase->string);
|
|
||||||
memset(buf+strlen(buf), ' ', sizeof(buf)-strlen(buf)-3);
|
memset(buf+strlen(buf), ' ', sizeof(buf)-strlen(buf)-3);
|
||||||
buf[MENU_TITLE_MAX_SIZE-3] = '|';
|
buf[MENU_TITLE_MAX_SIZE-3] = '|';
|
||||||
buf[MENU_TITLE_MAX_SIZE-2] = '\r';
|
buf[MENU_TITLE_MAX_SIZE-2] = '\r';
|
||||||
|
@ -290,7 +269,8 @@ int app_testcase_disp_menu(APP_KEY_HANDLE *testcase, bool printall) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_testcase_key_response(APP_MESSAGE_BODY *msg_body) {
|
int app_testcase_key_response(APP_MESSAGE_BODY *msg_body)
|
||||||
|
{
|
||||||
uint8_t i = 0;
|
uint8_t i = 0;
|
||||||
APP_KEY_STATUS key_status;
|
APP_KEY_STATUS key_status;
|
||||||
|
|
||||||
|
@ -301,8 +281,7 @@ int app_testcase_key_response(APP_MESSAGE_BODY *msg_body) {
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
for (i=0; i<(sizeof(app_testcase)/sizeof(APP_KEY_HANDLE)); i++){
|
for (i=0; i<(sizeof(app_testcase)/sizeof(APP_KEY_HANDLE)); i++){
|
||||||
if (app_testcase[i].key_status.code == key_status.code &&
|
if (app_testcase[i].key_status.code == key_status.code && (app_testcase[i].key_status.event == key_status.event))
|
||||||
(app_testcase[i].key_status.event == key_status.event))
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -312,14 +291,14 @@ int app_testcase_key_response(APP_MESSAGE_BODY *msg_body) {
|
||||||
if (app_testcase[i].function != (uint32_t)NULL){
|
if (app_testcase[i].function != (uint32_t)NULL){
|
||||||
if (app_testcase[i].string != (uint32_t)NULL)
|
if (app_testcase[i].string != (uint32_t)NULL)
|
||||||
app_testcase_disp_menu(&app_testcase[i],0);
|
app_testcase_disp_menu(&app_testcase[i],0);
|
||||||
((APP_KEY_HANDLE_CB_T)app_testcase[i].function)(&key_status,
|
((APP_KEY_HANDLE_CB_T)app_testcase[i].function)(&key_status,app_testcase[i].param);
|
||||||
app_testcase[i].param);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void app_test_init(void) {
|
void app_test_init(void)
|
||||||
|
{
|
||||||
uint8_t i = 0;
|
uint8_t i = 0;
|
||||||
TRACE(1,"%s",__func__);
|
TRACE(1,"%s",__func__);
|
||||||
for (i=0; i<(sizeof(app_testcase)/sizeof(APP_KEY_HANDLE)); i++){
|
for (i=0; i<(sizeof(app_testcase)/sizeof(APP_KEY_HANDLE)); i++){
|
||||||
|
|
|
@ -1,111 +0,0 @@
|
||||||
#ifndef COMMON_APP_IMPORTS
|
|
||||||
#define COMMON_APP_IMPORTS
|
|
||||||
|
|
||||||
#include "a2dp_api.h"
|
|
||||||
#include "app_audio.h"
|
|
||||||
#include "app_battery.h"
|
|
||||||
#include "app_ble_include.h"
|
|
||||||
#include "app_bt.h"
|
|
||||||
#include "app_bt_func.h"
|
|
||||||
#include "app_bt_media_manager.h"
|
|
||||||
#include "app_key.h"
|
|
||||||
#include "app_overlay.h"
|
|
||||||
#include "app_pwl.h"
|
|
||||||
#include "app_status_ind.h"
|
|
||||||
#include "app_thread.h"
|
|
||||||
#include "app_utils.h"
|
|
||||||
#include "audioflinger.h"
|
|
||||||
#include "besbt.h"
|
|
||||||
#include "bt_drv_interface.h"
|
|
||||||
#include "bt_if.h"
|
|
||||||
#include "btapp.h"
|
|
||||||
#include "cmsis_os.h"
|
|
||||||
#include "crash_dump_section.h"
|
|
||||||
#include "factory_section.h"
|
|
||||||
#include "gapm_task.h"
|
|
||||||
#include "hal_bootmode.h"
|
|
||||||
#include "hal_i2c.h"
|
|
||||||
#include "hal_sleep.h"
|
|
||||||
#include "hal_timer.h"
|
|
||||||
#include "hal_trace.h"
|
|
||||||
#include "list.h"
|
|
||||||
#include "log_section.h"
|
|
||||||
#include "me_api.h"
|
|
||||||
#include "norflash_api.h"
|
|
||||||
#include "nvrecord.h"
|
|
||||||
#include "nvrecord_dev.h"
|
|
||||||
#include "nvrecord_env.h"
|
|
||||||
#include "os_api.h"
|
|
||||||
#include "pmu.h"
|
|
||||||
#include "stdio.h"
|
|
||||||
#include "string.h"
|
|
||||||
#include "tgt_hardware.h"
|
|
||||||
#ifdef __AI_VOICE__
|
|
||||||
#include "ai_manager.h"
|
|
||||||
#include "app_ai_if.h"
|
|
||||||
#include "app_ai_manager_api.h"
|
|
||||||
#include "app_ai_tws.h"
|
|
||||||
#endif
|
|
||||||
#include "app_tws_ibrt_cmd_handler.h"
|
|
||||||
#include "audio_process.h"
|
|
||||||
|
|
||||||
#ifdef __PC_CMD_UART__
|
|
||||||
#include "app_cmd.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __FACTORY_MODE_SUPPORT__
|
|
||||||
#include "app_factory.h"
|
|
||||||
#include "app_factory_bt.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __INTERCONNECTION__
|
|
||||||
#include "app_ble_mode_switch.h"
|
|
||||||
#include "app_interconnection.h"
|
|
||||||
#include "app_interconnection_ble.h"
|
|
||||||
#include "app_interconnection_logic_protocol.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __INTERACTION__
|
|
||||||
#include "app_interaction.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef BISTO_ENABLED
|
|
||||||
#include "app_ai_manager_api.h"
|
|
||||||
#include "gsound_custom_actions.h"
|
|
||||||
#include "gsound_custom_ota.h"
|
|
||||||
#include "gsound_custom_reset.h"
|
|
||||||
#include "nvrecord_gsound.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef IBRT_OTA
|
|
||||||
#include "ota_bes.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef MEDIA_PLAYER_SUPPORT
|
|
||||||
#include "app_media_player.h"
|
|
||||||
#include "resources.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef VOICE_DATAPATH
|
|
||||||
#include "app_voicepath.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef BT_USB_AUDIO_DUAL_MODE
|
|
||||||
#include "btusb_audio.h"
|
|
||||||
#include "usbaudio_thread.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef TILE_DATAPATH
|
|
||||||
#include "tile_target_ble.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(IBRT)
|
|
||||||
#include "app_ibrt_customif_cmd.h"
|
|
||||||
#include "app_ibrt_customif_ui.h"
|
|
||||||
#include "app_ibrt_if.h"
|
|
||||||
#include "app_ibrt_ui_test.h"
|
|
||||||
#include "app_ibrt_voice_report.h"
|
|
||||||
#include "app_tws_if.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,68 +0,0 @@
|
||||||
|
|
||||||
// Google Fast pairing Service
|
|
||||||
#include "common_apps_imports.h"
|
|
||||||
|
|
||||||
#ifdef GFPS_ENABLED
|
|
||||||
#include "app_gfps.h"
|
|
||||||
#ifdef GFPS_ENABLED
|
|
||||||
static void app_tell_battery_info_handler(uint8_t *batteryValueCount,
|
|
||||||
uint8_t *batteryValue) {
|
|
||||||
GFPS_BATTERY_STATUS_E status;
|
|
||||||
if (app_battery_is_charging()) {
|
|
||||||
status = BATTERY_CHARGING;
|
|
||||||
} else {
|
|
||||||
status = BATTERY_NOT_CHARGING;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: add the charger case's battery level
|
|
||||||
#ifdef IBRT
|
|
||||||
if (app_tws_ibrt_tws_link_connected()) {
|
|
||||||
*batteryValueCount = 2;
|
|
||||||
} else {
|
|
||||||
*batteryValueCount = 1;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
*batteryValueCount = 1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
TRACE(2, "%s,*batteryValueCount is %d", __func__, *batteryValueCount);
|
|
||||||
if (1 == *batteryValueCount) {
|
|
||||||
batteryValue[0] = ((app_battery_current_level() + 1) * 10) | (status << 7);
|
|
||||||
} else {
|
|
||||||
batteryValue[0] = ((app_battery_current_level() + 1) * 10) | (status << 7);
|
|
||||||
batteryValue[1] = ((app_battery_current_level() + 1) * 10) | (status << 7);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef GFPS_ENABLED
|
|
||||||
static void app_tell_battery_info_handler(uint8_t *batteryValueCount,
|
|
||||||
uint8_t *batteryValue) {
|
|
||||||
GFPS_BATTERY_STATUS_E status;
|
|
||||||
if (app_battery_is_charging()) {
|
|
||||||
status = BATTERY_CHARGING;
|
|
||||||
} else {
|
|
||||||
status = BATTERY_NOT_CHARGING;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: add the charger case's battery level
|
|
||||||
#ifdef IBRT
|
|
||||||
if (app_tws_ibrt_tws_link_connected()) {
|
|
||||||
*batteryValueCount = 2;
|
|
||||||
} else {
|
|
||||||
*batteryValueCount = 1;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
*batteryValueCount = 1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
TRACE(2, "%s,*batteryValueCount is %d", __func__, *batteryValueCount);
|
|
||||||
if (1 == *batteryValueCount) {
|
|
||||||
batteryValue[0] = ((app_battery_current_level() + 1) * 10) | (status << 7);
|
|
||||||
} else {
|
|
||||||
batteryValue[0] = ((app_battery_current_level() + 1) * 10) | (status << 7);
|
|
||||||
batteryValue[1] = ((app_battery_current_level() + 1) * 10) | (status << 7);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
|
@ -1,32 +0,0 @@
|
||||||
#include "ibrt.h"
|
|
||||||
#include "common_apps_imports.h"
|
|
||||||
#include "hal_gpio.h"
|
|
||||||
#include "tgt_hardware.h"
|
|
||||||
extern struct BT_DEVICE_T app_bt_device;
|
|
||||||
extern void hal_gpio_pin_set(enum HAL_GPIO_PIN_T pin);
|
|
||||||
|
|
||||||
bool Curr_Is_Master(void) {
|
|
||||||
static ibrt_ctrl_t *p_ibrt_ctrl = app_tws_ibrt_get_bt_ctrl_ctx();
|
|
||||||
if (p_ibrt_ctrl->current_role == IBRT_MASTER)
|
|
||||||
return 1;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Curr_Is_Slave(void) {
|
|
||||||
static ibrt_ctrl_t *p_ibrt_ctrl = app_tws_ibrt_get_bt_ctrl_ctx();
|
|
||||||
if (p_ibrt_ctrl->current_role == IBRT_SLAVE)
|
|
||||||
return 1;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t get_curr_role(void) {
|
|
||||||
static ibrt_ctrl_t *p_ibrt_ctrl = app_tws_ibrt_get_bt_ctrl_ctx();
|
|
||||||
return p_ibrt_ctrl->current_role;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t get_nv_role(void) {
|
|
||||||
static ibrt_ctrl_t *p_ibrt_ctrl = app_tws_ibrt_get_bt_ctrl_ctx();
|
|
||||||
return p_ibrt_ctrl->nv_role;
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
#pragma once
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
bool Curr_Is_Master(void);
|
|
||||||
uint8_t get_curr_role(void);
|
|
||||||
bool Curr_Is_Slave(void);
|
|
||||||
uint8_t get_nv_role(void);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -1,271 +0,0 @@
|
||||||
#include "a2dp_api.h"
|
|
||||||
#include "app_audio.h"
|
|
||||||
#include "app_battery.h"
|
|
||||||
#include "app_ble_include.h"
|
|
||||||
#include "app_bt.h"
|
|
||||||
#include "app_bt_func.h"
|
|
||||||
#include "app_bt_media_manager.h"
|
|
||||||
#include "app_key.h"
|
|
||||||
#include "app_overlay.h"
|
|
||||||
#include "app_pwl.h"
|
|
||||||
#include "app_status_ind.h"
|
|
||||||
#include "app_thread.h"
|
|
||||||
#include "app_tws_ibrt_cmd_handler.h"
|
|
||||||
#include "app_utils.h"
|
|
||||||
#include "apps.h"
|
|
||||||
#include "audio_process.h"
|
|
||||||
#include "audioflinger.h"
|
|
||||||
#include "besbt.h"
|
|
||||||
#include "bt_drv_interface.h"
|
|
||||||
#include "bt_if.h"
|
|
||||||
#include "btapp.h"
|
|
||||||
#include "cmsis_os.h"
|
|
||||||
#include "crash_dump_section.h"
|
|
||||||
#include "factory_section.h"
|
|
||||||
#include "gapm_task.h"
|
|
||||||
#include "hal_bootmode.h"
|
|
||||||
#include "hal_i2c.h"
|
|
||||||
#include "hal_sleep.h"
|
|
||||||
#include "hal_timer.h"
|
|
||||||
#include "hal_trace.h"
|
|
||||||
#include "list.h"
|
|
||||||
#include "log_section.h"
|
|
||||||
#include "me_api.h"
|
|
||||||
#include "norflash_api.h"
|
|
||||||
#include "nvrecord.h"
|
|
||||||
#include "nvrecord_dev.h"
|
|
||||||
#include "nvrecord_env.h"
|
|
||||||
#include "os_api.h"
|
|
||||||
#include "pmu.h"
|
|
||||||
#include "stdio.h"
|
|
||||||
#include "string.h"
|
|
||||||
#include "tgt_hardware.h"
|
|
||||||
|
|
||||||
#ifdef __INTERCONNECTION__
|
|
||||||
#include "app_ble_mode_switch.h"
|
|
||||||
#include "app_interconnection.h"
|
|
||||||
#include "app_interconnection_ble.h"
|
|
||||||
#include "app_interconnection_logic_protocol.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "app_ibrt_customif_cmd.h"
|
|
||||||
#include "app_ibrt_customif_ui.h"
|
|
||||||
#include "app_ibrt_if.h"
|
|
||||||
#include "app_ibrt_ui_test.h"
|
|
||||||
#include "app_ibrt_voice_report.h"
|
|
||||||
#include "app_tws_if.h"
|
|
||||||
|
|
||||||
#include "app_anc.h"
|
|
||||||
|
|
||||||
extern struct BT_DEVICE_T app_bt_device;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* handling of touch events when the devices are turned on
|
|
||||||
|
|
||||||
* Both pods active:
|
|
||||||
|
|
||||||
* Right Ear:
|
|
||||||
* Single tap : Play/Pause
|
|
||||||
* Double tap : Next track
|
|
||||||
* Hold : ANC on/off
|
|
||||||
* Triple tap : Volume Up
|
|
||||||
*
|
|
||||||
* Left Ear:
|
|
||||||
* Single tap : Play/Pause
|
|
||||||
* Double tap : Previous track
|
|
||||||
* Hold : ANC on/off
|
|
||||||
* Triple tap : Volume Down
|
|
||||||
|
|
||||||
* Single pod active:
|
|
||||||
|
|
||||||
* Single tap : Play/Pause
|
|
||||||
* Double tap : Next track
|
|
||||||
* Hold : Previous track
|
|
||||||
* Triple tap : Volume Up
|
|
||||||
* Quad tap : Volume Down
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
* We use app_ibrt_if_start_user_action for handling actions, as this will apply
|
|
||||||
locally if we are link master
|
|
||||||
* OR send it over the link to the other bud if we are not
|
|
||||||
*/
|
|
||||||
|
|
||||||
void send_vol_up(void) {
|
|
||||||
uint8_t action[] = {IBRT_ACTION_LOCAL_VOLUP};
|
|
||||||
app_ibrt_if_start_user_action(action, sizeof(action));
|
|
||||||
}
|
|
||||||
void send_play_pause(void) {
|
|
||||||
if (app_bt_device.a2dp_play_pause_flag != 0) {
|
|
||||||
uint8_t action[] = {IBRT_ACTION_PAUSE};
|
|
||||||
app_ibrt_if_start_user_action(action, sizeof(action));
|
|
||||||
} else {
|
|
||||||
uint8_t action[] = {IBRT_ACTION_PLAY};
|
|
||||||
app_ibrt_if_start_user_action(action, sizeof(action));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void send_vol_down(void) {
|
|
||||||
uint8_t action[] = {IBRT_ACTION_LOCAL_VOLDN};
|
|
||||||
app_ibrt_if_start_user_action(action, sizeof(action));
|
|
||||||
}
|
|
||||||
|
|
||||||
void send_next_track(void) {
|
|
||||||
uint8_t action[] = {IBRT_ACTION_FORWARD};
|
|
||||||
app_ibrt_if_start_user_action(action, sizeof(action));
|
|
||||||
}
|
|
||||||
|
|
||||||
void send_prev_track(void) {
|
|
||||||
uint8_t action[] = {IBRT_ACTION_BACKWARD};
|
|
||||||
app_ibrt_if_start_user_action(action, sizeof(action));
|
|
||||||
}
|
|
||||||
void app_key_single_tap(APP_KEY_STATUS *status, void *param) {
|
|
||||||
TRACE(2, "%s event %d", __func__, status->event);
|
|
||||||
|
|
||||||
if (!app_tws_ibrt_tws_link_connected()) {
|
|
||||||
// No other bud paired
|
|
||||||
TRACE(0, "Handling %s in single bud mode", __func__);
|
|
||||||
send_play_pause();
|
|
||||||
} else {
|
|
||||||
// Bud's are working as a pair
|
|
||||||
if (app_tws_is_left_side()) {
|
|
||||||
TRACE(0, "Handling %s as left bud", __func__);
|
|
||||||
// Lefty
|
|
||||||
send_play_pause();
|
|
||||||
} else {
|
|
||||||
TRACE(0, "Handling %s as right bud", __func__);
|
|
||||||
// Righty
|
|
||||||
send_play_pause();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void app_key_double_tap(APP_KEY_STATUS *status, void *param) {
|
|
||||||
TRACE(2, "%s event %d", __func__, status->event);
|
|
||||||
|
|
||||||
if (!app_tws_ibrt_tws_link_connected()) {
|
|
||||||
// No other bud paired
|
|
||||||
TRACE(0, "Handling %s in single bud mode", __func__);
|
|
||||||
send_next_track();
|
|
||||||
} else {
|
|
||||||
// Bud's are working as a pair
|
|
||||||
if (app_tws_is_left_side()) {
|
|
||||||
TRACE(0, "Handling %s as left bud", __func__);
|
|
||||||
// Lefty
|
|
||||||
send_prev_track();
|
|
||||||
} else {
|
|
||||||
TRACE(0, "Handling %s as right bud", __func__);
|
|
||||||
// Righty
|
|
||||||
send_next_track();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void app_key_triple_tap(APP_KEY_STATUS *status, void *param) {
|
|
||||||
TRACE(2, "%s event %d", __func__, status->event);
|
|
||||||
|
|
||||||
if (!app_tws_ibrt_tws_link_connected()) {
|
|
||||||
// No other bud paired
|
|
||||||
TRACE(0, "Handling %s in single bud mode", __func__);
|
|
||||||
send_vol_up();
|
|
||||||
} else {
|
|
||||||
// Bud's are working as a pair
|
|
||||||
if (app_tws_is_left_side()) {
|
|
||||||
TRACE(0, "Handling %s as left bud", __func__);
|
|
||||||
// Lefty
|
|
||||||
send_vol_down();
|
|
||||||
} else {
|
|
||||||
TRACE(0, "Handling %s as right bud", __func__);
|
|
||||||
// Righty
|
|
||||||
send_vol_up();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void app_key_quad_tap(APP_KEY_STATUS *status, void *param) {
|
|
||||||
TRACE(2, "%s event %d", __func__, status->event);
|
|
||||||
|
|
||||||
if (!app_tws_ibrt_tws_link_connected()) {
|
|
||||||
// No other bud paired
|
|
||||||
TRACE(0, "Handling %s in single bud mode", __func__);
|
|
||||||
send_vol_down();
|
|
||||||
} else {
|
|
||||||
// Bud's are working as a pair
|
|
||||||
if (app_tws_is_left_side()) {
|
|
||||||
TRACE(0, "Handling %s as left bud", __func__);
|
|
||||||
// Lefty
|
|
||||||
} else {
|
|
||||||
TRACE(0, "Handling %s as right bud", __func__);
|
|
||||||
// Righty
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void app_key_long_press_down(APP_KEY_STATUS *status, void *param) {
|
|
||||||
TRACE(2, "%s event %d", __func__, status->event);
|
|
||||||
|
|
||||||
if (!app_tws_ibrt_tws_link_connected()) {
|
|
||||||
// No other bud paired
|
|
||||||
TRACE(0, "Handling %s in single bud mode", __func__);
|
|
||||||
send_prev_track();
|
|
||||||
} else {
|
|
||||||
// Bud's are working as a pair
|
|
||||||
app_anc_key(status, param);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void app_key_reboot(APP_KEY_STATUS *status, void *param) {
|
|
||||||
TRACE(1, "%s ", __func__);
|
|
||||||
hal_cmu_sys_reboot();
|
|
||||||
}
|
|
||||||
|
|
||||||
void app_key_init(void) {
|
|
||||||
uint8_t i = 0;
|
|
||||||
TRACE(1, "%s", __func__);
|
|
||||||
|
|
||||||
const APP_KEY_HANDLE key_cfg[] = {
|
|
||||||
|
|
||||||
{{APP_KEY_CODE_PWR, APP_KEY_EVENT_CLICK}, "", app_key_single_tap, NULL},
|
|
||||||
{{APP_KEY_CODE_PWR, APP_KEY_EVENT_DOUBLECLICK},
|
|
||||||
"",
|
|
||||||
app_key_double_tap,
|
|
||||||
NULL},
|
|
||||||
{{APP_KEY_CODE_PWR, APP_KEY_EVENT_TRIPLECLICK},
|
|
||||||
"",
|
|
||||||
app_key_triple_tap,
|
|
||||||
NULL},
|
|
||||||
{{APP_KEY_CODE_PWR, APP_KEY_EVENT_ULTRACLICK},
|
|
||||||
"",
|
|
||||||
app_key_quad_tap,
|
|
||||||
NULL},
|
|
||||||
{{APP_KEY_CODE_PWR, APP_KEY_EVENT_LONGPRESS},
|
|
||||||
"",
|
|
||||||
app_key_long_press_down,
|
|
||||||
NULL},
|
|
||||||
};
|
|
||||||
|
|
||||||
app_key_handle_clear();
|
|
||||||
for (i = 0; i < (sizeof(key_cfg) / sizeof(APP_KEY_HANDLE)); i++) {
|
|
||||||
app_key_handle_registration(&key_cfg[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void app_key_init_on_charging(void) {
|
|
||||||
uint8_t i = 0;
|
|
||||||
const APP_KEY_HANDLE key_cfg[] = {
|
|
||||||
{{APP_KEY_CODE_PWR, APP_KEY_EVENT_LONGLONGPRESS},
|
|
||||||
"long press reboot",
|
|
||||||
app_key_reboot,
|
|
||||||
NULL},
|
|
||||||
// {{APP_KEY_CODE_PWR,APP_KEY_EVENT_CLICK},"bt function
|
|
||||||
// key",app_dfu_key_handler, NULL},
|
|
||||||
#ifdef __USB_COMM__
|
|
||||||
{{APP_KEY_CODE_PWR, APP_KEY_EVENT_LONGPRESS},
|
|
||||||
"usb cdc key",
|
|
||||||
app_usb_cdc_comm_key_handler,
|
|
||||||
NULL},
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
TRACE(1, "%s", __func__);
|
|
||||||
for (i = 0; i < (sizeof(key_cfg) / sizeof(APP_KEY_HANDLE)); i++) {
|
|
||||||
app_key_handle_registration(&key_cfg[i]);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,5 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
void app_key_init(void);
|
|
||||||
|
|
||||||
void app_key_init_on_charging(void);
|
|
|
@ -1,40 +0,0 @@
|
||||||
|
|
||||||
#include "led_control.h"
|
|
||||||
#include "common_apps_imports.h"
|
|
||||||
#include "ibrt.h"
|
|
||||||
|
|
||||||
/******************************LED_status_timer*********************************************************/
|
|
||||||
osTimerId LED_statusid = NULL;
|
|
||||||
|
|
||||||
osTimerDef(defLED_status, LED_statusfun);
|
|
||||||
|
|
||||||
void LED_statusinit(void) {
|
|
||||||
LED_statusid = osTimerCreate(osTimer(defLED_status), osTimerOnce, (void *)0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void LED_statusfun(const void *) {
|
|
||||||
// TRACE("\n\n!!!!!!enter %s\n\n",__func__);
|
|
||||||
if ((Curr_Is_Slave() || app_device_bt_is_connected()) &&
|
|
||||||
(!app_battery_is_charging())) {
|
|
||||||
app_status_indication_set(APP_STATUS_INDICATION_CONNECTED);
|
|
||||||
} else if (!app_device_bt_is_connected() && (!app_battery_is_charging())) {
|
|
||||||
app_status_indication_set(APP_STATUS_INDICATION_BOTHSCAN);
|
|
||||||
} else if (app_battery_is_charging()) {
|
|
||||||
app_status_indication_set(APP_STATUS_INDICATION_CHARGING);
|
|
||||||
}
|
|
||||||
// unsigned char firstaddr;
|
|
||||||
// I2C_ReadByte(decice_firstreg,&firstaddr);
|
|
||||||
// TRACE(3,"0X00 REG = 0x%x",firstaddr);
|
|
||||||
startLED_status(1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
void startLED_status(int ms) {
|
|
||||||
// TRACE("\n\n !!!!!!!!!!start %s\n\n",__func__);
|
|
||||||
osTimerStart(LED_statusid, ms);
|
|
||||||
}
|
|
||||||
void stopLED_status(void) {
|
|
||||||
// TRACE("\n\n!!!!!!!!!! stop %s\n\n",__func__);
|
|
||||||
osTimerStop(LED_statusid);
|
|
||||||
}
|
|
||||||
|
|
||||||
/********************************LED_status_timer*******************************************************/
|
|
|
@ -1,6 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
void LED_statusinit(void);
|
|
||||||
void startLED_status(int ms);
|
|
||||||
void stopLED_status(void);
|
|
||||||
void LED_statusfun(const void *);
|
|
|
@ -1,41 +0,0 @@
|
||||||
// LHDC needs a licence key
|
|
||||||
// We dont have one; so probably cant ever officially use this. But its here for
|
|
||||||
// preservation at the least
|
|
||||||
|
|
||||||
#if defined(A2DP_LHDC_ON)
|
|
||||||
extern "C" {
|
|
||||||
typedef struct bes_bt_local_info_t {
|
|
||||||
uint8_t bt_addr[BTIF_BD_ADDR_SIZE];
|
|
||||||
const char *bt_name;
|
|
||||||
uint8_t bt_len;
|
|
||||||
uint8_t ble_addr[BTIF_BD_ADDR_SIZE];
|
|
||||||
const char *ble_name;
|
|
||||||
uint8_t ble_len;
|
|
||||||
} bes_bt_local_info;
|
|
||||||
|
|
||||||
typedef int (*LHDC_GET_BT_INFO)(bes_bt_local_info *bt_info);
|
|
||||||
extern bool lhdcSetLicenseKeyTable(uint8_t *licTable, LHDC_GET_BT_INFO pFunc);
|
|
||||||
}
|
|
||||||
extern int bes_bt_local_info_get(bes_bt_local_info *local_info);
|
|
||||||
|
|
||||||
void lhdc_license_check() {
|
|
||||||
uint8_t lhdc_license_key = 0;
|
|
||||||
uint8_t *lhdc_license_data = (uint8_t *)__lhdc_license_start + 0x98;
|
|
||||||
TRACE(5, "lhdc_license_data:%p, lhdc license %02x %02x %02x %02x",
|
|
||||||
lhdc_license_data, lhdc_license_data[0], lhdc_license_data[1],
|
|
||||||
lhdc_license_data[2], lhdc_license_data[3]);
|
|
||||||
|
|
||||||
app_overlay_select(APP_OVERLAY_A2DP_LHDC);
|
|
||||||
TRACE(1, "current_overlay = %d", app_get_current_overlay());
|
|
||||||
|
|
||||||
lhdc_license_key =
|
|
||||||
lhdcSetLicenseKeyTable(lhdc_license_data, bes_bt_local_info_get);
|
|
||||||
TRACE(0, "lhdc_license_key:%d", lhdc_license_key);
|
|
||||||
|
|
||||||
if (lhdc_license_key) {
|
|
||||||
TRACE(0, "LHDC OK");
|
|
||||||
} else {
|
|
||||||
TRACE(0, "LHDC ERROR");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
|
@ -1,29 +0,0 @@
|
||||||
|
|
||||||
|
|
||||||
#ifdef RB_CODEC
|
|
||||||
extern bool app_rbcodec_check_hfp_active(void);
|
|
||||||
void app_switch_player_key(APP_KEY_STATUS *status, void *param) {
|
|
||||||
TRACE(3, "%s %d,%d", __func__, status->code, status->event);
|
|
||||||
|
|
||||||
if (!rb_ctl_is_init_done()) {
|
|
||||||
TRACE(0, "rb ctl not init done");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (app_rbcodec_check_hfp_active()) {
|
|
||||||
app_bt_key(status, param);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
app_rbplay_audio_reset_pause_status();
|
|
||||||
|
|
||||||
if (app_rbplay_mode_switch()) {
|
|
||||||
app_voice_report(APP_STATUS_INDICATION_POWERON, 0);
|
|
||||||
app_rbcodec_ctr_play_onoff(true);
|
|
||||||
} else {
|
|
||||||
app_rbcodec_ctr_play_onoff(false);
|
|
||||||
app_voice_report(APP_STATUS_INDICATION_POWEROFF, 0);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
|
@ -1,7 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifdef RB_CODEC
|
|
||||||
extern int rb_ctl_init();
|
|
||||||
extern bool rb_ctl_is_init_done(void);
|
|
||||||
extern void app_rbplay_audio_reset_pause_status(void);
|
|
||||||
#endif
|
|
|
@ -14,45 +14,46 @@
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
//#include "mbed.h"
|
//#include "mbed.h"
|
||||||
#include <assert.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
#include "cmsis_os.h"
|
||||||
|
#include "tgt_hardware.h"
|
||||||
|
#include "hal_uart.h"
|
||||||
|
#include "hal_timer.h"
|
||||||
|
#include "audioflinger.h"
|
||||||
|
#include "lockcqueue.h"
|
||||||
|
#include "hal_trace.h"
|
||||||
|
#include "hal_cmu.h"
|
||||||
|
#include "hal_chipid.h"
|
||||||
#include "analog.h"
|
#include "analog.h"
|
||||||
#include "app_audio.h"
|
|
||||||
#include "app_bt_stream.h"
|
#include "app_bt_stream.h"
|
||||||
#include "app_overlay.h"
|
#include "app_overlay.h"
|
||||||
|
#include "app_audio.h"
|
||||||
#include "app_utils.h"
|
#include "app_utils.h"
|
||||||
#include "apps.h"
|
|
||||||
#include "audioflinger.h"
|
|
||||||
#include "cmsis_os.h"
|
|
||||||
#include "hal_chipid.h"
|
|
||||||
#include "hal_cmu.h"
|
|
||||||
#include "hal_codec.h"
|
|
||||||
#include "hal_timer.h"
|
|
||||||
#include "hal_trace.h"
|
|
||||||
#include "hal_uart.h"
|
|
||||||
#include "lockcqueue.h"
|
|
||||||
#include "nvrecord.h"
|
#include "nvrecord.h"
|
||||||
#include "nvrecord_env.h"
|
#include "nvrecord_env.h"
|
||||||
#include "tgt_hardware.h"
|
#include "hal_codec.h"
|
||||||
|
#include "apps.h"
|
||||||
|
|
||||||
#include "app_ring_merge.h"
|
#include "app_ring_merge.h"
|
||||||
|
|
||||||
#include "app_bt_func.h"
|
|
||||||
#include "app_mic.h"
|
|
||||||
#include "besbt.h"
|
|
||||||
#include "bt_drv.h"
|
#include "bt_drv.h"
|
||||||
#include "bt_xtal_sync.h"
|
#include "bt_xtal_sync.h"
|
||||||
|
#include "besbt.h"
|
||||||
|
#include "app_bt_func.h"
|
||||||
|
#include "app_mic.h"
|
||||||
|
|
||||||
|
|
||||||
#include "app_bt_media_manager.h"
|
|
||||||
#include "app_hfp.h"
|
|
||||||
#include "app_thread.h"
|
#include "app_thread.h"
|
||||||
#include "btapp.h"
|
|
||||||
#include "cqueue.h"
|
#include "cqueue.h"
|
||||||
#include "hal_codec.h"
|
#include "btapp.h"
|
||||||
#include "hal_location.h"
|
#include "app_bt_media_manager.h"
|
||||||
#include "hal_sleep.h"
|
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
#include "hal_location.h"
|
||||||
|
#include "hal_codec.h"
|
||||||
|
#include "hal_sleep.h"
|
||||||
|
#include "app_hfp.h"
|
||||||
|
|
||||||
extern bool app_hfp_siri_is_active(void);
|
extern bool app_hfp_siri_is_active(void);
|
||||||
extern int a2dp_volume_2_level_convert(uint8_t vol);
|
extern int a2dp_volume_2_level_convert(uint8_t vol);
|
||||||
|
@ -69,33 +70,47 @@ static struct AF_STREAM_CONFIG_T mic_config[MIC_APP_MAX];
|
||||||
osMutexId app_mic_mutex_id = NULL;
|
osMutexId app_mic_mutex_id = NULL;
|
||||||
osMutexDef(app_mic_mutex);
|
osMutexDef(app_mic_mutex);
|
||||||
|
|
||||||
|
|
||||||
// flag of is first mic date, if true ,will delete to avoid POP voice
|
// flag of is first mic date, if true ,will delete to avoid POP voice
|
||||||
bool first_mic_in = false;
|
bool first_mic_in = false;
|
||||||
|
|
||||||
static int internal_mic_start(MIC_APP_TYPE new_mictype) {
|
static int internal_mic_start(MIC_APP_TYPE new_mictype)
|
||||||
|
{
|
||||||
TRACE(1,"MIC_EVENT_START,current_mictype=%d",current_mictype);
|
TRACE(1,"MIC_EVENT_START,current_mictype=%d",current_mictype);
|
||||||
assert(new_mictype != MIC_APP_NONE);
|
assert(new_mictype != MIC_APP_NONE);
|
||||||
if (current_mictype != MIC_APP_NONE) {
|
if (current_mictype != MIC_APP_NONE) {
|
||||||
TRACE(0,"MIC START ERROR################");
|
TRACE(0,"MIC START ERROR################");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (new_mictype == MIC_APP_SOC_CALL) {
|
if (new_mictype == MIC_APP_SOC_CALL)
|
||||||
if (btapp_hfp_get_call_state() || app_hfp_siri_is_active()) {
|
{
|
||||||
TRACE(2, "[%s] tws_mic_start_telephone_call: %d", __func__,
|
if (btapp_hfp_get_call_state() || app_hfp_siri_is_active())
|
||||||
mic_config[new_mictype].sample_rate);
|
{
|
||||||
if (mic_config[new_mictype].data_ptr != NULL) {
|
TRACE(2,"[%s] tws_mic_start_telephone_call: %d", __func__, mic_config[new_mictype].sample_rate);
|
||||||
} else {
|
if (mic_config[new_mictype].data_ptr != NULL)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
TRACE(1,"[%s] Warning sco play not started",__func__);
|
TRACE(1,"[%s] Warning sco play not started",__func__);
|
||||||
}
|
}
|
||||||
current_mictype = MIC_APP_SOC_CALL;
|
current_mictype = MIC_APP_SOC_CALL;
|
||||||
}
|
}
|
||||||
} else if (new_mictype == MIC_APP_SPEECH_RECO) {
|
}
|
||||||
} else if (new_mictype == MIC_APP_CSPOTTER) {
|
else if (new_mictype == MIC_APP_SPEECH_RECO)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else if (new_mictype == MIC_APP_CSPOTTER)
|
||||||
|
{
|
||||||
first_mic_in = true;
|
first_mic_in = true;
|
||||||
current_mictype = MIC_APP_CSPOTTER;
|
current_mictype = MIC_APP_CSPOTTER;
|
||||||
} else if (new_mictype == MIC_APP_MICRECORD) {
|
}
|
||||||
|
else if (new_mictype == MIC_APP_MICRECORD)
|
||||||
|
{
|
||||||
current_mictype = MIC_APP_MICRECORD;
|
current_mictype = MIC_APP_MICRECORD;
|
||||||
} else if (new_mictype == MIC_APP_OTHER) {
|
}
|
||||||
|
else if (new_mictype == MIC_APP_OTHER)
|
||||||
|
{
|
||||||
TRACE(0,"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
|
TRACE(0,"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +119,8 @@ static int internal_mic_start(MIC_APP_TYPE new_mictype) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int internal_mic_stop(MIC_APP_TYPE new_mictype) {
|
static int internal_mic_stop(MIC_APP_TYPE new_mictype)
|
||||||
|
{
|
||||||
TRACE(1,"MIC_EVENT_STOP,current_mictype=%d",current_mictype);
|
TRACE(1,"MIC_EVENT_STOP,current_mictype=%d",current_mictype);
|
||||||
//assert(currentMicStauts == currentStatus);
|
//assert(currentMicStauts == currentStatus);
|
||||||
if (new_mictype != current_mictype) {
|
if (new_mictype != current_mictype) {
|
||||||
|
@ -119,46 +135,50 @@ static int internal_mic_stop(MIC_APP_TYPE new_mictype) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int app_mic_process(APP_MESSAGE_BODY *msg_body) {
|
static int app_mic_process(APP_MESSAGE_BODY *msg_body)
|
||||||
|
{
|
||||||
MIC_EVENT_TYPE mic_event = (MIC_EVENT_TYPE)msg_body->message_id;
|
MIC_EVENT_TYPE mic_event = (MIC_EVENT_TYPE)msg_body->message_id;
|
||||||
MIC_APP_TYPE new_mictype = (MIC_APP_TYPE)msg_body->message_ptr;
|
MIC_APP_TYPE new_mictype = (MIC_APP_TYPE)msg_body->message_ptr;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
TRACE(4, "%s mic_event:%d new_mictype:%d current_mictype:%d", __func__,
|
TRACE(4,"%s mic_event:%d new_mictype:%d current_mictype:%d",__func__,mic_event, new_mictype, current_mictype);
|
||||||
mic_event, new_mictype, current_mictype);
|
|
||||||
|
|
||||||
osMutexWait(app_mic_mutex_id, osWaitForever);
|
osMutexWait(app_mic_mutex_id, osWaitForever);
|
||||||
if (mic_event == MIC_EVENT_START)
|
if (mic_event == MIC_EVENT_START)
|
||||||
ret = internal_mic_start(new_mictype);
|
ret = internal_mic_start(new_mictype);
|
||||||
else if (mic_event == MIC_EVENT_STOP)
|
else if (mic_event == MIC_EVENT_STOP)
|
||||||
ret = internal_mic_stop(new_mictype);
|
ret = internal_mic_stop(new_mictype);
|
||||||
else if (mic_event == MIC_EVENT_CHECK) {
|
else if (mic_event == MIC_EVENT_CHECK)
|
||||||
|
{
|
||||||
TRACE(1,"MIC_EVENT_CHECK,current_mictype=%d",current_mictype);
|
TRACE(1,"MIC_EVENT_CHECK,current_mictype=%d",current_mictype);
|
||||||
if (current_mictype != new_mictype) {
|
if (current_mictype != new_mictype)
|
||||||
|
{
|
||||||
if (current_mictype != MIC_APP_NONE)
|
if (current_mictype != MIC_APP_NONE)
|
||||||
internal_mic_stop(current_mictype);
|
internal_mic_stop(current_mictype);
|
||||||
if (new_mictype != MIC_APP_CSPOTTER)
|
if (new_mictype != MIC_APP_CSPOTTER)
|
||||||
internal_mic_start(new_mictype);
|
internal_mic_start(new_mictype);
|
||||||
ret = 0;
|
ret = 0;
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
assert(0);
|
assert(0);
|
||||||
osMutexRelease(app_mic_mutex_id);
|
osMutexRelease(app_mic_mutex_id);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void app_mic_init() {
|
void app_mic_init()
|
||||||
|
{
|
||||||
app_mic_mutex_id = osMutexCreate((osMutex(app_mic_mutex)));
|
app_mic_mutex_id = osMutexCreate((osMutex(app_mic_mutex)));
|
||||||
app_set_threadhandle(APP_MODUAL_MIC, app_mic_process);
|
app_set_threadhandle(APP_MODUAL_MIC, app_mic_process);
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_mic_register(MIC_APP_TYPE mic_type,
|
int app_mic_register(MIC_APP_TYPE mic_type, struct AF_STREAM_CONFIG_T *newStream)
|
||||||
struct AF_STREAM_CONFIG_T *newStream) {
|
{
|
||||||
TRACE(2, "app_mic_registration mic_type:%d,newStream=%p\n", mic_type,
|
TRACE(2,"app_mic_registration mic_type:%d,newStream=%p\n",mic_type,newStream);
|
||||||
newStream);
|
if (mic_type > MIC_APP_NONE && mic_type < MIC_APP_MAX)
|
||||||
if (mic_type > MIC_APP_NONE && mic_type < MIC_APP_MAX) {
|
{
|
||||||
osMutexWait(app_mic_mutex_id, osWaitForever);
|
osMutexWait(app_mic_mutex_id, osWaitForever);
|
||||||
if (memcmp(&mic_config[mic_type], newStream,
|
if (memcmp(&mic_config[mic_type],newStream,sizeof(struct AF_STREAM_CONFIG_T)) != 0)
|
||||||
sizeof(struct AF_STREAM_CONFIG_T)) != 0) {
|
{
|
||||||
TRACE(0,"app_mic_registration Warning mic stream config changed!!!");
|
TRACE(0,"app_mic_registration Warning mic stream config changed!!!");
|
||||||
}
|
}
|
||||||
memcpy(&mic_config[mic_type],newStream,sizeof(struct AF_STREAM_CONFIG_T));
|
memcpy(&mic_config[mic_type],newStream,sizeof(struct AF_STREAM_CONFIG_T));
|
||||||
|
@ -168,9 +188,11 @@ int app_mic_register(MIC_APP_TYPE mic_type,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_mic_deregister(MIC_APP_TYPE mic_type) {
|
int app_mic_deregister(MIC_APP_TYPE mic_type)
|
||||||
|
{
|
||||||
TRACE(1,"app_mic_deregister mic_type:%d\n",mic_type);
|
TRACE(1,"app_mic_deregister mic_type:%d\n",mic_type);
|
||||||
if (mic_type > MIC_APP_NONE && mic_type < MIC_APP_MAX) {
|
if (mic_type > MIC_APP_NONE && mic_type < MIC_APP_MAX)
|
||||||
|
{
|
||||||
osMutexWait(app_mic_mutex_id, osWaitForever);
|
osMutexWait(app_mic_mutex_id, osWaitForever);
|
||||||
memset(&mic_config[mic_type],0,sizeof(struct AF_STREAM_CONFIG_T));
|
memset(&mic_config[mic_type],0,sizeof(struct AF_STREAM_CONFIG_T));
|
||||||
osMutexRelease(app_mic_mutex_id);
|
osMutexRelease(app_mic_mutex_id);
|
||||||
|
@ -179,10 +201,12 @@ int app_mic_deregister(MIC_APP_TYPE mic_type) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool app_mic_is_registed(MIC_APP_TYPE mic_type) {
|
bool app_mic_is_registed(MIC_APP_TYPE mic_type)
|
||||||
|
{
|
||||||
TRACE(1,"app_mic_is_registed mic_type:%d\n",mic_type);
|
TRACE(1,"app_mic_is_registed mic_type:%d\n",mic_type);
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
if (mic_type > MIC_APP_NONE && mic_type < MIC_APP_MAX) {
|
if (mic_type > MIC_APP_NONE && mic_type < MIC_APP_MAX)
|
||||||
|
{
|
||||||
osMutexWait(app_mic_mutex_id, osWaitForever);
|
osMutexWait(app_mic_mutex_id, osWaitForever);
|
||||||
ret = mic_config[mic_type].data_ptr != NULL;
|
ret = mic_config[mic_type].data_ptr != NULL;
|
||||||
osMutexRelease(app_mic_mutex_id);
|
osMutexRelease(app_mic_mutex_id);
|
||||||
|
@ -190,7 +214,8 @@ bool app_mic_is_registed(MIC_APP_TYPE mic_type) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool app_mic_start(MIC_APP_TYPE mic_type) {
|
bool app_mic_start(MIC_APP_TYPE mic_type)
|
||||||
|
{
|
||||||
APP_MESSAGE_BLOCK msg;
|
APP_MESSAGE_BLOCK msg;
|
||||||
msg.mod_id = APP_MODUAL_MIC;
|
msg.mod_id = APP_MODUAL_MIC;
|
||||||
msg.msg_body.message_id = MIC_EVENT_START;
|
msg.msg_body.message_id = MIC_EVENT_START;
|
||||||
|
@ -199,7 +224,8 @@ bool app_mic_start(MIC_APP_TYPE mic_type) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool app_mic_stop(MIC_APP_TYPE mic_type) {
|
bool app_mic_stop(MIC_APP_TYPE mic_type)
|
||||||
|
{
|
||||||
APP_MESSAGE_BLOCK msg;
|
APP_MESSAGE_BLOCK msg;
|
||||||
msg.mod_id = APP_MODUAL_MIC;
|
msg.mod_id = APP_MODUAL_MIC;
|
||||||
msg.msg_body.message_id = MIC_EVENT_STOP;
|
msg.msg_body.message_id = MIC_EVENT_STOP;
|
||||||
|
@ -208,7 +234,8 @@ bool app_mic_stop(MIC_APP_TYPE mic_type) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void app_mic_check(MIC_APP_TYPE mic_type) {
|
void app_mic_check(MIC_APP_TYPE mic_type)
|
||||||
|
{
|
||||||
APP_MESSAGE_BLOCK msg;
|
APP_MESSAGE_BLOCK msg;
|
||||||
msg.mod_id = APP_MODUAL_MIC;
|
msg.mod_id = APP_MODUAL_MIC;
|
||||||
msg.msg_body.message_id = MIC_EVENT_CHECK;
|
msg.msg_body.message_id = MIC_EVENT_CHECK;
|
||||||
|
@ -216,10 +243,12 @@ void app_mic_check(MIC_APP_TYPE mic_type) {
|
||||||
app_mailbox_put(&msg);
|
app_mailbox_put(&msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
MIC_APP_TYPE app_mic_status(void) {
|
MIC_APP_TYPE app_mic_status(void)
|
||||||
|
{
|
||||||
MIC_APP_TYPE ret;
|
MIC_APP_TYPE ret;
|
||||||
osMutexWait(app_mic_mutex_id, osWaitForever);
|
osMutexWait(app_mic_mutex_id, osWaitForever);
|
||||||
ret= current_mictype;
|
ret= current_mictype;
|
||||||
osMutexRelease(app_mic_mutex_id);
|
osMutexRelease(app_mic_mutex_id);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ ccflags-y += \
|
||||||
-Iapps/i2c_sensor \
|
-Iapps/i2c_sensor \
|
||||||
-Iplatform/drivers/bt \
|
-Iplatform/drivers/bt \
|
||||||
-Iplatform/drivers/ana \
|
-Iplatform/drivers/ana \
|
||||||
|
-Iplatform/drivers/usb/usb_dev/inc \
|
||||||
-Iapps/battery
|
-Iapps/battery
|
||||||
|
|
||||||
ifeq ($(AUDIO_RESAMPLE),1)
|
ifeq ($(AUDIO_RESAMPLE),1)
|
||||||
|
|
|
@ -13,18 +13,18 @@
|
||||||
* trademark and other intellectual property rights.
|
* trademark and other intellectual property rights.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include "app_bt_stream.h"
|
|
||||||
#include "app_media_player.h"
|
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
#include "hal_trace.h"
|
#include "hal_trace.h"
|
||||||
#include "resources.h"
|
#include "resources.h"
|
||||||
|
#include "app_bt_stream.h"
|
||||||
|
#include "app_media_player.h"
|
||||||
//#include "app_factory.h"
|
//#include "app_factory.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
|
||||||
// for audio
|
// for audio
|
||||||
|
#include "audioflinger.h"
|
||||||
#include "app_audio.h"
|
#include "app_audio.h"
|
||||||
#include "app_utils.h"
|
#include "app_utils.h"
|
||||||
#include "audioflinger.h"
|
|
||||||
#include "hal_timer.h"
|
#include "hal_timer.h"
|
||||||
|
|
||||||
#include "app_mic_alg.h"
|
#include "app_mic_alg.h"
|
||||||
|
@ -42,6 +42,7 @@
|
||||||
|
|
||||||
#include "apps.h"
|
#include "apps.h"
|
||||||
|
|
||||||
|
|
||||||
#ifdef WEBRTC_AGC
|
#ifdef WEBRTC_AGC
|
||||||
#include "agc_main.h"
|
#include "agc_main.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -50,14 +51,17 @@
|
||||||
#define WEBRTC_NSX_BUFF_SIZE (14000)
|
#define WEBRTC_NSX_BUFF_SIZE (14000)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef WL_VAD
|
#ifdef WL_VAD
|
||||||
#include "vad_user.h"
|
#include "vad_user.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef WL_DEBUG_MODE
|
#ifdef WL_DEBUG_MODE
|
||||||
#include "nvrecord_env.h"
|
#include "nvrecord_env.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef REMOTE_UART
|
#ifdef REMOTE_UART
|
||||||
#include "app_remoter_uart.h"
|
#include "app_remoter_uart.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -75,27 +79,35 @@ static inline float clampf(float v, float min, float max) {
|
||||||
return v < min ? min : (v > max ? max : v);
|
return v < min ? min : (v > max ? max : v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef WL_NSX_5MS
|
#ifdef WL_NSX_5MS
|
||||||
#define BT_AUDIO_FACTORMODE_BUFF_SIZE (160*2)
|
#define BT_AUDIO_FACTORMODE_BUFF_SIZE (160*2)
|
||||||
#else
|
#else
|
||||||
#define BT_AUDIO_FACTORMODE_BUFF_SIZE (6*320*16)
|
#define BT_AUDIO_FACTORMODE_BUFF_SIZE (6*320*16)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define NSX_FRAME_SIZE 160
|
#define NSX_FRAME_SIZE 160
|
||||||
|
|
||||||
|
|
||||||
static enum APP_AUDIO_CACHE_T a2dp_cache_status = APP_AUDIO_CACHE_QTY;
|
static enum APP_AUDIO_CACHE_T a2dp_cache_status = APP_AUDIO_CACHE_QTY;
|
||||||
|
|
||||||
|
|
||||||
#if defined(WL_AEC)
|
#if defined(WL_AEC)
|
||||||
static short POSSIBLY_UNUSED aec_out[BT_AUDIO_FACTORMODE_BUFF_SIZE>>2];
|
static short POSSIBLY_UNUSED aec_out[BT_AUDIO_FACTORMODE_BUFF_SIZE>>2];
|
||||||
static short POSSIBLY_UNUSED far_buff[BT_AUDIO_FACTORMODE_BUFF_SIZE>>2];
|
static short POSSIBLY_UNUSED far_buff[BT_AUDIO_FACTORMODE_BUFF_SIZE>>2];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
static short POSSIBLY_UNUSED out_buff[BT_AUDIO_FACTORMODE_BUFF_SIZE>>2];
|
static short POSSIBLY_UNUSED out_buff[BT_AUDIO_FACTORMODE_BUFF_SIZE>>2];
|
||||||
static short POSSIBLY_UNUSED tmp_buff[BT_AUDIO_FACTORMODE_BUFF_SIZE>>2];
|
static short POSSIBLY_UNUSED tmp_buff[BT_AUDIO_FACTORMODE_BUFF_SIZE>>2];
|
||||||
|
|
||||||
//static short revert_buff[BT_AUDIO_FACTORMODE_BUFF_SIZE>>2];
|
//static short revert_buff[BT_AUDIO_FACTORMODE_BUFF_SIZE>>2];
|
||||||
//static short audio_uart_buff[BT_AUDIO_FACTORMODE_BUFF_SIZE>>2];
|
//static short audio_uart_buff[BT_AUDIO_FACTORMODE_BUFF_SIZE>>2];
|
||||||
|
|
||||||
|
|
||||||
#if SPEECH_CODEC_CAPTURE_CHANNEL_NUM == 2
|
#if SPEECH_CODEC_CAPTURE_CHANNEL_NUM == 2
|
||||||
|
|
||||||
static short POSSIBLY_UNUSED one_buff[BT_AUDIO_FACTORMODE_BUFF_SIZE>>2];
|
static short POSSIBLY_UNUSED one_buff[BT_AUDIO_FACTORMODE_BUFF_SIZE>>2];
|
||||||
|
@ -104,27 +116,26 @@ static short POSSIBLY_UNUSED two_buff[BT_AUDIO_FACTORMODE_BUFF_SIZE >> 2];
|
||||||
static short POSSIBLY_UNUSED left_out[BT_AUDIO_FACTORMODE_BUFF_SIZE>>2];
|
static short POSSIBLY_UNUSED left_out[BT_AUDIO_FACTORMODE_BUFF_SIZE>>2];
|
||||||
static short POSSIBLY_UNUSED right_out[BT_AUDIO_FACTORMODE_BUFF_SIZE>>2];
|
static short POSSIBLY_UNUSED right_out[BT_AUDIO_FACTORMODE_BUFF_SIZE>>2];
|
||||||
|
|
||||||
static void POSSIBLY_UNUSED aaudio_div_stero_to_rmono(int16_t *dst_buf,
|
static void POSSIBLY_UNUSED aaudio_div_stero_to_rmono(int16_t *dst_buf, int16_t *src_buf, uint32_t src_len)
|
||||||
int16_t *src_buf,
|
{
|
||||||
uint32_t src_len) {
|
|
||||||
// Copy from tail so that it works even if dst_buf == src_buf
|
// Copy from tail so that it works even if dst_buf == src_buf
|
||||||
for (uint32_t i = 0; i < src_len >> 1; i++) {
|
for (uint32_t i = 0; i < src_len>>1; i++)
|
||||||
|
{
|
||||||
dst_buf[i] = src_buf[i*2 + 1];
|
dst_buf[i] = src_buf[i*2 + 1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static void POSSIBLY_UNUSED aaudio_div_stero_to_lmono(int16_t *dst_buf,
|
static void POSSIBLY_UNUSED aaudio_div_stero_to_lmono(int16_t *dst_buf, int16_t *src_buf, uint32_t src_len)
|
||||||
int16_t *src_buf,
|
{
|
||||||
uint32_t src_len) {
|
|
||||||
// Copy from tail so that it works even if dst_buf == src_buf
|
// Copy from tail so that it works even if dst_buf == src_buf
|
||||||
for (uint32_t i = 0; i < src_len >> 1; i++) {
|
for (uint32_t i = 0; i < src_len>>1; i++)
|
||||||
|
{
|
||||||
dst_buf[i] = src_buf[i*2 + 0];
|
dst_buf[i] = src_buf[i*2 + 0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void POSSIBLY_UNUSED audio_mono2stereo_16bits(int16_t *dst_buf,
|
|
||||||
int16_t *left_buf,
|
static void POSSIBLY_UNUSED audio_mono2stereo_16bits(int16_t *dst_buf, int16_t *left_buf, int16_t *right_buf, uint32_t src_len)
|
||||||
int16_t *right_buf,
|
{
|
||||||
uint32_t src_len) {
|
|
||||||
uint32_t i = 0;
|
uint32_t i = 0;
|
||||||
for (i = 0; i < src_len; ++i) {
|
for (i = 0; i < src_len; ++i) {
|
||||||
dst_buf[i*2 + 0] = left_buf[i];
|
dst_buf[i*2 + 0] = left_buf[i];
|
||||||
|
@ -134,6 +145,7 @@ static void POSSIBLY_UNUSED audio_mono2stereo_16bits(int16_t *dst_buf,
|
||||||
|
|
||||||
#elif SPEECH_CODEC_CAPTURE_CHANNEL_NUM == 3
|
#elif SPEECH_CODEC_CAPTURE_CHANNEL_NUM == 3
|
||||||
|
|
||||||
|
|
||||||
#elif SPEECH_CODEC_CAPTURE_CHANNEL_NUM == 4
|
#elif SPEECH_CODEC_CAPTURE_CHANNEL_NUM == 4
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -143,32 +155,41 @@ extern uint32_t transfer_factor;
|
||||||
extern uint32_t diff_energy;
|
extern uint32_t diff_energy;
|
||||||
extern uint32_t level_shift;
|
extern uint32_t level_shift;
|
||||||
|
|
||||||
static inline double convert_multiple_to_db(uint32_t multiple) {
|
static inline double convert_multiple_to_db(uint32_t multiple)
|
||||||
|
{
|
||||||
return 20*log10(multiple);
|
return 20*log10(multiple);
|
||||||
}
|
}
|
||||||
#define DUMP_FRAME_LEN 0x3C0
|
#define DUMP_FRAME_LEN 0x3C0
|
||||||
static short POSSIBLY_UNUSED revert_buff[2+1*DUMP_FRAME_LEN];
|
static short POSSIBLY_UNUSED revert_buff[2+1*DUMP_FRAME_LEN];
|
||||||
int32_t tx_pcmbuf32[960];
|
int32_t tx_pcmbuf32[960];
|
||||||
|
|
||||||
|
|
||||||
extern int app_reset(void);
|
extern int app_reset(void);
|
||||||
|
|
||||||
extern void app_bt_volumeup();
|
extern void app_bt_volumeup();
|
||||||
extern void app_bt_volumedown();
|
extern void app_bt_volumedown();
|
||||||
|
|
||||||
void vol_state_process(uint32_t db_val) {
|
void vol_state_process(uint32_t db_val)
|
||||||
TRACE(2, "db value is:%d volume_is:%d ", db_val,
|
{
|
||||||
app_bt_stream_local_volume_get());
|
TRACE(2,"db value is:%d volume_is:%d ",db_val,app_bt_stream_local_volume_get());
|
||||||
|
|
||||||
if ((db_val < 52) && (app_bt_stream_local_volume_get() > 10)) {
|
if((db_val < 52) && (app_bt_stream_local_volume_get() > 10))
|
||||||
|
{
|
||||||
app_bt_volumedown();
|
app_bt_volumedown();
|
||||||
} else if ((db_val > 60) && (app_bt_stream_local_volume_get() < 13)) {
|
}
|
||||||
app_bt_volumeup();
|
else if((db_val > 60) && (app_bt_stream_local_volume_get() < 13))
|
||||||
} else if ((db_val > 72) && (app_bt_stream_local_volume_get() < 15)) {
|
{
|
||||||
app_bt_volumeup();
|
app_bt_volumeup();
|
||||||
}
|
}
|
||||||
|
else if((db_val > 72) && (app_bt_stream_local_volume_get() < 15))
|
||||||
|
{
|
||||||
|
app_bt_volumeup();
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t app_mic_alg_data_come(uint8_t *buf, uint32_t len) {
|
}
|
||||||
|
|
||||||
|
static uint32_t app_mic_alg_data_come(uint8_t *buf, uint32_t len)
|
||||||
|
{
|
||||||
uint32_t pcm_len = len>>1;
|
uint32_t pcm_len = len>>1;
|
||||||
|
|
||||||
short POSSIBLY_UNUSED *tx_pcmbuf16 = (short*)buf;
|
short POSSIBLY_UNUSED *tx_pcmbuf16 = (short*)buf;
|
||||||
|
@ -180,23 +201,27 @@ static uint32_t app_mic_alg_data_come(uint8_t *buf, uint32_t len) {
|
||||||
static int32_t nsx_cnt = 0;
|
static int32_t nsx_cnt = 0;
|
||||||
static int32_t dump_cnt = 0;
|
static int32_t dump_cnt = 0;
|
||||||
|
|
||||||
|
|
||||||
nsx_cnt++;
|
nsx_cnt++;
|
||||||
dump_cnt++;
|
dump_cnt++;
|
||||||
|
|
||||||
DUMP16("%d,",tx_pcmbuf16,30);
|
DUMP16("%d,",tx_pcmbuf16,30);
|
||||||
if (false == (nsx_cnt & 0x3F)) {
|
if(false == (nsx_cnt & 0x3F))
|
||||||
|
{
|
||||||
stime = hal_sys_timer_get();
|
stime = hal_sys_timer_get();
|
||||||
//TRACE("aecm echo time: lens:%d g_time_cnt:%d ",len, g_time_cnt);
|
//TRACE("aecm echo time: lens:%d g_time_cnt:%d ",len, g_time_cnt);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WL_DET
|
#ifdef WL_DET
|
||||||
if (nsx_cnt > 100) {
|
if(nsx_cnt > 100)
|
||||||
|
{
|
||||||
static double last_sum = 0,last_avg = 0;
|
static double last_sum = 0,last_avg = 0;
|
||||||
|
|
||||||
uint32_t sum_ss = 0;
|
uint32_t sum_ss = 0;
|
||||||
//short db_val = 0;
|
//short db_val = 0;
|
||||||
double db_sum = 0;
|
double db_sum = 0;
|
||||||
for (uint32_t i_cnt = 0; i_cnt < pcm_len; i_cnt++) {
|
for (uint32_t i_cnt = 0; i_cnt < pcm_len; i_cnt++)
|
||||||
|
{
|
||||||
sum_ss += ABS(tx_pcmbuf16[i_cnt]);
|
sum_ss += ABS(tx_pcmbuf16[i_cnt]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,16 +241,15 @@ static uint32_t app_mic_alg_data_come(uint8_t *buf, uint32_t len) {
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (false == (nsx_cnt & 0x3F)) {
|
|
||||||
// TRACE("drc 48 mic_alg 16k nsx 3 agc 15 closed speed time:%d ms and
|
if(false == (nsx_cnt & 0x3F))
|
||||||
// pcm_lens:%d freq:%d ", TICKS_TO_MS(hal_sys_timer_get() - stime),
|
{
|
||||||
// pcm_len,hal_sysfreq_get()); TRACE("notch 500 mic_alg 16k nsx 3 agc 15
|
//TRACE("drc 48 mic_alg 16k nsx 3 agc 15 closed speed time:%d ms and pcm_lens:%d freq:%d ", TICKS_TO_MS(hal_sys_timer_get() - stime), pcm_len,hal_sysfreq_get());
|
||||||
// closed speed time:%d ms and pcm_lens:%d freq:%d ",
|
//TRACE("notch 500 mic_alg 16k nsx 3 agc 15 closed speed time:%d ms and pcm_lens:%d freq:%d ", TICKS_TO_MS(hal_sys_timer_get() - stime), pcm_len,hal_sysfreq_get());
|
||||||
// TICKS_TO_MS(hal_sys_timer_get() - stime), pcm_len,hal_sysfreq_get());
|
TRACE(2,"denoise det speed time:%d ms and pcm_lens:%d freq:%d ", TICKS_TO_MS(hal_sys_timer_get() - stime), pcm_len,hal_sysfreq_get());
|
||||||
TRACE(2, "denoise det speed time:%d ms and pcm_lens:%d freq:%d ",
|
|
||||||
TICKS_TO_MS(hal_sys_timer_get() - stime), pcm_len, hal_sysfreq_get());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (a2dp_cache_status == APP_AUDIO_CACHE_QTY){
|
if (a2dp_cache_status == APP_AUDIO_CACHE_QTY){
|
||||||
a2dp_cache_status = APP_AUDIO_CACHE_OK;
|
a2dp_cache_status = APP_AUDIO_CACHE_OK;
|
||||||
}
|
}
|
||||||
|
@ -238,14 +262,13 @@ static uint32_t app_mic_alg_data_come(uint8_t *buf, uint32_t len) {
|
||||||
// #if SPEECH_CODEC_CAPTURE_CHANNEL_NUM == 2
|
// #if SPEECH_CODEC_CAPTURE_CHANNEL_NUM == 2
|
||||||
// #ifdef WL_AEC
|
// #ifdef WL_AEC
|
||||||
// app_audio_pcmbuff_get((uint8_t *)app_audioloop_play_cache, len/2);
|
// app_audio_pcmbuff_get((uint8_t *)app_audioloop_play_cache, len/2);
|
||||||
// app_bt_stream_copy_track_one_to_two_16bits((int16_t *)buf,
|
// app_bt_stream_copy_track_one_to_two_16bits((int16_t *)buf, app_audioloop_play_cache, len/2/2);
|
||||||
// app_audioloop_play_cache, len/2/2); #else
|
// #else
|
||||||
// app_audio_pcmbuff_get((uint8_t *)buf, len);
|
// app_audio_pcmbuff_get((uint8_t *)buf, len);
|
||||||
// #endif
|
// #endif
|
||||||
// #else
|
// #else
|
||||||
// app_audio_pcmbuff_get((uint8_t *)app_audioloop_play_cache, len/2);
|
// app_audio_pcmbuff_get((uint8_t *)app_audioloop_play_cache, len/2);
|
||||||
// app_bt_stream_copy_track_one_to_two_16bits((int16_t *)buf,
|
// app_bt_stream_copy_track_one_to_two_16bits((int16_t *)buf, app_audioloop_play_cache, len/2/2);
|
||||||
// app_audioloop_play_cache, len/2/2);
|
|
||||||
// #endif
|
// #endif
|
||||||
// }
|
// }
|
||||||
// return len;
|
// return len;
|
||||||
|
@ -253,7 +276,8 @@ static uint32_t app_mic_alg_data_come(uint8_t *buf, uint32_t len) {
|
||||||
|
|
||||||
static uint8_t buff_capture[BT_AUDIO_FACTORMODE_BUFF_SIZE];
|
static uint8_t buff_capture[BT_AUDIO_FACTORMODE_BUFF_SIZE];
|
||||||
|
|
||||||
int app_mic_alg_audioloop(bool on, enum APP_SYSFREQ_FREQ_T freq) {
|
int app_mic_alg_audioloop(bool on, enum APP_SYSFREQ_FREQ_T freq)
|
||||||
|
{
|
||||||
struct AF_STREAM_CONFIG_T stream_cfg;
|
struct AF_STREAM_CONFIG_T stream_cfg;
|
||||||
static bool isRun = false;
|
static bool isRun = false;
|
||||||
|
|
||||||
|
@ -264,18 +288,21 @@ int app_mic_alg_audioloop(bool on, enum APP_SYSFREQ_FREQ_T freq) {
|
||||||
|
|
||||||
if (on){
|
if (on){
|
||||||
|
|
||||||
|
|
||||||
app_sysfreq_req(APP_SYSFREQ_USER_APP_0, freq);
|
app_sysfreq_req(APP_SYSFREQ_USER_APP_0, freq);
|
||||||
|
|
||||||
a2dp_cache_status = APP_AUDIO_CACHE_QTY;
|
a2dp_cache_status = APP_AUDIO_CACHE_QTY;
|
||||||
|
|
||||||
memset(&stream_cfg, 0, sizeof(stream_cfg));
|
memset(&stream_cfg, 0, sizeof(stream_cfg));
|
||||||
|
|
||||||
|
|
||||||
stream_cfg.bits = AUD_BITS_16;
|
stream_cfg.bits = AUD_BITS_16;
|
||||||
|
|
||||||
stream_cfg.channel_num = AUD_CHANNEL_NUM_1;
|
stream_cfg.channel_num = AUD_CHANNEL_NUM_1;
|
||||||
|
|
||||||
stream_cfg.sample_rate = AUD_SAMPRATE_48000;
|
stream_cfg.sample_rate = AUD_SAMPRATE_48000;
|
||||||
|
|
||||||
|
|
||||||
stream_cfg.device = AUD_STREAM_USE_INT_CODEC;
|
stream_cfg.device = AUD_STREAM_USE_INT_CODEC;
|
||||||
|
|
||||||
stream_cfg.vol = CODEC_SADC_VOL;
|
stream_cfg.vol = CODEC_SADC_VOL;
|
||||||
|
@ -284,8 +311,7 @@ int app_mic_alg_audioloop(bool on, enum APP_SYSFREQ_FREQ_T freq) {
|
||||||
stream_cfg.handler = app_mic_alg_data_come;
|
stream_cfg.handler = app_mic_alg_data_come;
|
||||||
|
|
||||||
stream_cfg.data_ptr = BT_AUDIO_CACHE_2_UNCACHE(buff_capture);
|
stream_cfg.data_ptr = BT_AUDIO_CACHE_2_UNCACHE(buff_capture);
|
||||||
stream_cfg.data_size =
|
stream_cfg.data_size = BT_AUDIO_FACTORMODE_BUFF_SIZE*stream_cfg.channel_num;
|
||||||
BT_AUDIO_FACTORMODE_BUFF_SIZE * stream_cfg.channel_num;
|
|
||||||
af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE, &stream_cfg);
|
af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE, &stream_cfg);
|
||||||
|
|
||||||
// stream_cfg.channel_num = AUD_CHANNEL_NUM_2;
|
// stream_cfg.channel_num = AUD_CHANNEL_NUM_2;
|
||||||
|
@ -313,3 +339,5 @@ int app_mic_alg_audioloop(bool on, enum APP_SYSFREQ_FREQ_T freq) {
|
||||||
isRun=on;
|
isRun=on;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -13,14 +13,14 @@
|
||||||
* trademark and other intellectual property rights.
|
* trademark and other intellectual property rights.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include "app_pwl.h"
|
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
|
#include "tgt_hardware.h"
|
||||||
#include "hal_gpio.h"
|
#include "hal_gpio.h"
|
||||||
#include "hal_iomux.h"
|
#include "hal_iomux.h"
|
||||||
#include "hal_trace.h"
|
#include "hal_trace.h"
|
||||||
#include "pmu.h"
|
#include "pmu.h"
|
||||||
|
#include "app_pwl.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include "tgt_hardware.h"
|
|
||||||
|
|
||||||
#define APP_PWL_TRACE(s,...)
|
#define APP_PWL_TRACE(s,...)
|
||||||
//TRACE(s, ##__VA_ARGS__)
|
//TRACE(s, ##__VA_ARGS__)
|
||||||
|
@ -42,7 +42,8 @@ struct APP_PWL_T {
|
||||||
|
|
||||||
static struct APP_PWL_T app_pwl[APP_PWL_ID_QTY];
|
static struct APP_PWL_T app_pwl[APP_PWL_ID_QTY];
|
||||||
|
|
||||||
static void app_pwl_timehandler(void const *param) {
|
static void app_pwl_timehandler(void const *param)
|
||||||
|
{
|
||||||
struct APP_PWL_T *pwl = (struct APP_PWL_T *)param;
|
struct APP_PWL_T *pwl = (struct APP_PWL_T *)param;
|
||||||
struct APP_PWL_CFG_T *cfg = &(pwl->config);
|
struct APP_PWL_CFG_T *cfg = &(pwl->config);
|
||||||
APP_PWL_TRACE(2,"%s %x",__func__, param);
|
APP_PWL_TRACE(2,"%s %x",__func__, param);
|
||||||
|
@ -60,54 +61,48 @@ static void app_pwl_timehandler(void const *param) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
APP_PWL_TRACE(3, "idx:%d pin:%d lvl:%d", pwl->partidx,
|
APP_PWL_TRACE(3,"idx:%d pin:%d lvl:%d", pwl->partidx, cfg_hw_pinmux_pwl[pwl->id].pin, cfg->part[pwl->partidx].level);
|
||||||
cfg_hw_pinmux_pwl[pwl->id].pin, cfg->part[pwl->partidx].level);
|
|
||||||
if(!cfg->part[pwl->partidx].level){
|
if(!cfg->part[pwl->partidx].level){
|
||||||
#if defined(__PMU_VIO_DYNAMIC_CTRL_MODE__)
|
#if defined(__PMU_VIO_DYNAMIC_CTRL_MODE__)
|
||||||
pmu_viorise_req(pwl->id == APP_PWL_ID_0 ? PMU_VIORISE_REQ_USER_PWL0
|
pmu_viorise_req(pwl->id == APP_PWL_ID_0 ? PMU_VIORISE_REQ_USER_PWL0 : PMU_VIORISE_REQ_USER_PWL1, true);
|
||||||
: PMU_VIORISE_REQ_USER_PWL1,
|
|
||||||
true);
|
|
||||||
#endif
|
#endif
|
||||||
hal_gpio_pin_set((enum HAL_GPIO_PIN_T)cfg_hw_pinmux_pwl[pwl->id].pin);
|
hal_gpio_pin_set((enum HAL_GPIO_PIN_T)cfg_hw_pinmux_pwl[pwl->id].pin);
|
||||||
}else{
|
}else{
|
||||||
hal_gpio_pin_clr((enum HAL_GPIO_PIN_T)cfg_hw_pinmux_pwl[pwl->id].pin);
|
hal_gpio_pin_clr((enum HAL_GPIO_PIN_T)cfg_hw_pinmux_pwl[pwl->id].pin);
|
||||||
#if defined(__PMU_VIO_DYNAMIC_CTRL_MODE__)
|
#if defined(__PMU_VIO_DYNAMIC_CTRL_MODE__)
|
||||||
pmu_viorise_req(pwl->id == APP_PWL_ID_0 ? PMU_VIORISE_REQ_USER_PWL0
|
pmu_viorise_req(pwl->id == APP_PWL_ID_0 ? PMU_VIORISE_REQ_USER_PWL0 : PMU_VIORISE_REQ_USER_PWL1, false);
|
||||||
: PMU_VIORISE_REQ_USER_PWL1,
|
|
||||||
false);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
osTimerStart(pwl->timer, cfg->part[pwl->partidx].time);
|
osTimerStart(pwl->timer, cfg->part[pwl->partidx].time);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int app_pwl_open(void) {
|
int app_pwl_open(void)
|
||||||
|
{
|
||||||
#if (CFG_HW_PLW_NUM > 0)
|
#if (CFG_HW_PLW_NUM > 0)
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
APP_PWL_TRACE(1,"%s",__func__);
|
APP_PWL_TRACE(1,"%s",__func__);
|
||||||
for (i=0;i<APP_PWL_ID_QTY;i++){
|
for (i=0;i<APP_PWL_ID_QTY;i++){
|
||||||
app_pwl[i].id = APP_PWL_ID_QTY;
|
app_pwl[i].id = APP_PWL_ID_QTY;
|
||||||
memset(&(app_pwl[i].config), 0, sizeof(struct APP_PWL_CFG_T));
|
memset(&(app_pwl[i].config), 0, sizeof(struct APP_PWL_CFG_T));
|
||||||
hal_iomux_init((struct HAL_IOMUX_PIN_FUNCTION_MAP *)&cfg_hw_pinmux_pwl[i],
|
hal_iomux_init((struct HAL_IOMUX_PIN_FUNCTION_MAP *)&cfg_hw_pinmux_pwl[i], 1);
|
||||||
1);
|
hal_gpio_pin_set_dir((enum HAL_GPIO_PIN_T)cfg_hw_pinmux_pwl[i].pin, HAL_GPIO_DIR_OUT, 1);
|
||||||
hal_gpio_pin_set_dir((enum HAL_GPIO_PIN_T)cfg_hw_pinmux_pwl[i].pin,
|
|
||||||
HAL_GPIO_DIR_OUT, 1);
|
|
||||||
}
|
}
|
||||||
app_pwl[APP_PWL_ID_0].timer = osTimerCreate(
|
app_pwl[APP_PWL_ID_0].timer = osTimerCreate (osTimer(APP_PWL_TIMER0), osTimerOnce, &app_pwl[APP_PWL_ID_0]);
|
||||||
osTimer(APP_PWL_TIMER0), osTimerOnce, &app_pwl[APP_PWL_ID_0]);
|
|
||||||
#if (CFG_HW_PLW_NUM == 2)
|
#if (CFG_HW_PLW_NUM == 2)
|
||||||
app_pwl[APP_PWL_ID_1].timer = osTimerCreate(
|
app_pwl[APP_PWL_ID_1].timer = osTimerCreate (osTimer(APP_PWL_TIMER1), osTimerOnce, &app_pwl[APP_PWL_ID_1]);
|
||||||
osTimer(APP_PWL_TIMER1), osTimerOnce, &app_pwl[APP_PWL_ID_1]);
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_pwl_start(enum APP_PWL_ID_T id) {
|
int app_pwl_start(enum APP_PWL_ID_T id)
|
||||||
|
{
|
||||||
#if (CFG_HW_PLW_NUM > 0)
|
#if (CFG_HW_PLW_NUM > 0)
|
||||||
struct APP_PWL_T *pwl = NULL;
|
struct APP_PWL_T *pwl = NULL;
|
||||||
struct APP_PWL_CFG_T *cfg = NULL;
|
struct APP_PWL_CFG_T *cfg = NULL;
|
||||||
|
|
||||||
|
|
||||||
if (id >= APP_PWL_ID_QTY) {
|
if (id >= APP_PWL_ID_QTY) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -128,21 +123,16 @@ int app_pwl_start(enum APP_PWL_ID_T id) {
|
||||||
|
|
||||||
osTimerStop(pwl->timer);
|
osTimerStop(pwl->timer);
|
||||||
|
|
||||||
APP_PWL_TRACE(3, "idx:%d pin:%d lvl:%d", pwl->partidx,
|
APP_PWL_TRACE(3,"idx:%d pin:%d lvl:%d", pwl->partidx, cfg_hw_pinmux_pwl[pwl->id].pin, cfg->part[pwl->partidx].level);
|
||||||
cfg_hw_pinmux_pwl[pwl->id].pin, cfg->part[pwl->partidx].level);
|
|
||||||
if(!cfg->part[pwl->partidx].level){
|
if(!cfg->part[pwl->partidx].level){
|
||||||
#if defined(__PMU_VIO_DYNAMIC_CTRL_MODE__)
|
#if defined(__PMU_VIO_DYNAMIC_CTRL_MODE__)
|
||||||
pmu_viorise_req(pwl->id == APP_PWL_ID_0 ? PMU_VIORISE_REQ_USER_PWL0
|
pmu_viorise_req(pwl->id == APP_PWL_ID_0 ? PMU_VIORISE_REQ_USER_PWL0 : PMU_VIORISE_REQ_USER_PWL1, false);
|
||||||
: PMU_VIORISE_REQ_USER_PWL1,
|
|
||||||
false);
|
|
||||||
#endif
|
#endif
|
||||||
hal_gpio_pin_set((enum HAL_GPIO_PIN_T)cfg_hw_pinmux_pwl[pwl->id].pin);
|
hal_gpio_pin_set((enum HAL_GPIO_PIN_T)cfg_hw_pinmux_pwl[pwl->id].pin);
|
||||||
}else{
|
}else{
|
||||||
hal_gpio_pin_clr((enum HAL_GPIO_PIN_T)cfg_hw_pinmux_pwl[pwl->id].pin);
|
hal_gpio_pin_clr((enum HAL_GPIO_PIN_T)cfg_hw_pinmux_pwl[pwl->id].pin);
|
||||||
#if defined(__PMU_VIO_DYNAMIC_CTRL_MODE__)
|
#if defined(__PMU_VIO_DYNAMIC_CTRL_MODE__)
|
||||||
pmu_viorise_req(pwl->id == APP_PWL_ID_0 ? PMU_VIORISE_REQ_USER_PWL0
|
pmu_viorise_req(pwl->id == APP_PWL_ID_0 ? PMU_VIORISE_REQ_USER_PWL0 : PMU_VIORISE_REQ_USER_PWL1, false);
|
||||||
: PMU_VIORISE_REQ_USER_PWL1,
|
|
||||||
false);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
osTimerStart(pwl->timer, cfg->part[pwl->partidx].time);
|
osTimerStart(pwl->timer, cfg->part[pwl->partidx].time);
|
||||||
|
@ -150,15 +140,15 @@ int app_pwl_start(enum APP_PWL_ID_T id) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_pwl_setup(enum APP_PWL_ID_T id, struct APP_PWL_CFG_T *cfg) {
|
int app_pwl_setup(enum APP_PWL_ID_T id, struct APP_PWL_CFG_T *cfg)
|
||||||
|
{
|
||||||
#if (CFG_HW_PLW_NUM > 0)
|
#if (CFG_HW_PLW_NUM > 0)
|
||||||
if (cfg == NULL || id >= APP_PWL_ID_QTY) {
|
if (cfg == NULL || id >= APP_PWL_ID_QTY) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
APP_PWL_TRACE(2,"%s %d",__func__, id);
|
APP_PWL_TRACE(2,"%s %d",__func__, id);
|
||||||
|
|
||||||
hal_gpio_pin_set_dir((enum HAL_GPIO_PIN_T)cfg_hw_pinmux_pwl[id].pin,
|
hal_gpio_pin_set_dir((enum HAL_GPIO_PIN_T)cfg_hw_pinmux_pwl[id].pin, HAL_GPIO_DIR_OUT, cfg->startlevel?0:1);
|
||||||
HAL_GPIO_DIR_OUT, cfg->startlevel ? 0 : 1);
|
|
||||||
app_pwl[id].id = id;
|
app_pwl[id].id = id;
|
||||||
memcpy(&(app_pwl[id].config), cfg, sizeof(struct APP_PWL_CFG_T));
|
memcpy(&(app_pwl[id].config), cfg, sizeof(struct APP_PWL_CFG_T));
|
||||||
|
|
||||||
|
@ -167,7 +157,8 @@ int app_pwl_setup(enum APP_PWL_ID_T id, struct APP_PWL_CFG_T *cfg) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_pwl_stop(enum APP_PWL_ID_T id) {
|
int app_pwl_stop(enum APP_PWL_ID_T id)
|
||||||
|
{
|
||||||
#if (CFG_HW_PLW_NUM > 0)
|
#if (CFG_HW_PLW_NUM > 0)
|
||||||
if (id >= APP_PWL_ID_QTY) {
|
if (id >= APP_PWL_ID_QTY) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -179,7 +170,8 @@ int app_pwl_stop(enum APP_PWL_ID_T id) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_pwl_close(void) {
|
int app_pwl_close(void)
|
||||||
|
{
|
||||||
#if (CFG_HW_PLW_NUM > 0)
|
#if (CFG_HW_PLW_NUM > 0)
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
for (i=0;i<APP_PWL_ID_QTY;i++){
|
for (i=0;i<APP_PWL_ID_QTY;i++){
|
||||||
|
@ -189,3 +181,5 @@ int app_pwl_close(void) {
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
cur_dir := $(dir $(lastword $(MAKEFILE_LIST)))
|
||||||
|
|
||||||
|
obj-y := $(patsubst $(cur_dir)%,%,$(wildcard $(cur_dir)*.c $(cur_dir)*.cpp $(cur_dir)*.S))
|
||||||
|
obj-y := $(obj-y:.c=.o)
|
||||||
|
obj-y := $(obj-y:.cpp=.o)
|
||||||
|
obj-y := $(obj-y:.S=.o)
|
||||||
|
|
||||||
|
subdir-ccflags-y += -Iservices/fs/sd \
|
||||||
|
-Iservices/fs/fat \
|
||||||
|
-Iservices/fs/fat/ChaN
|
||||||
|
|
||||||
|
ifeq ($(APP_TEST_SDMMC),1)
|
||||||
|
ccflags-y += -D__APP_TEST_SDMMC__
|
||||||
|
endif
|
|
@ -0,0 +1,200 @@
|
||||||
|
/***************************************************************************
|
||||||
|
*
|
||||||
|
* Copyright 2015-2019 BES.
|
||||||
|
* All rights reserved. All unpublished rights reserved.
|
||||||
|
*
|
||||||
|
* No part of this work may be used or reproduced in any form or by any
|
||||||
|
* means, or stored in a database or retrieval system, without prior written
|
||||||
|
* permission of BES.
|
||||||
|
*
|
||||||
|
* Use of this work is governed by a license granted by BES.
|
||||||
|
* This work contains confidential and proprietary information of
|
||||||
|
* BES. which is protected by copyright, trade secret,
|
||||||
|
* trademark and other intellectual property rights.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
#include "cmsis_os.h"
|
||||||
|
#include "hal_trace.h"
|
||||||
|
//#include "app_thread.h"
|
||||||
|
|
||||||
|
//#include "hal_sdmmc.h"
|
||||||
|
#include "SDFileSystem.h"
|
||||||
|
#include "audioflinger.h"
|
||||||
|
#include "audiobuffer.h"
|
||||||
|
#include "app_sdmmc.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define APP_TEST_PLAYBACK_BUFF_SIZE (120 * 20)
|
||||||
|
#define APP_TEST_CAPTURE_BUFF_SIZE (120 * 20)
|
||||||
|
extern uint8_t app_test_playback_buff[APP_TEST_PLAYBACK_BUFF_SIZE] __attribute__ ((aligned(4)));
|
||||||
|
extern uint8_t app_test_capture_buff[APP_TEST_CAPTURE_BUFF_SIZE] __attribute__ ((aligned(4)));
|
||||||
|
SDFileSystem sdfs("sd");
|
||||||
|
|
||||||
|
int sd_open()
|
||||||
|
{
|
||||||
|
DIR *d = opendir("/sd");
|
||||||
|
if (!d)
|
||||||
|
{
|
||||||
|
TRACE(0,"sd file system borked\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
TRACE(0,"---------root---------\n");
|
||||||
|
struct dirent *p;
|
||||||
|
while ((p = readdir(d)))
|
||||||
|
{
|
||||||
|
int len = sizeof( dirent);
|
||||||
|
TRACE(2,"%s %d\n", p->d_name, len);
|
||||||
|
}
|
||||||
|
closedir(d);
|
||||||
|
TRACE(0,"--------root end-------\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
extern uint32_t play_wav_file(char *file_path);
|
||||||
|
extern uint32_t stop_wav_file(void);
|
||||||
|
extern uint32_t wav_file_audio_more_data(uint8_t *buf, uint32_t len);
|
||||||
|
|
||||||
|
void test_wave_play(bool on)
|
||||||
|
{
|
||||||
|
struct AF_STREAM_CONFIG_T stream_cfg;
|
||||||
|
uint32_t reallen;
|
||||||
|
uint32_t totalreadsize;
|
||||||
|
uint32_t stime, etime;
|
||||||
|
|
||||||
|
char wave[] = "/sd/test_music.wav";
|
||||||
|
|
||||||
|
static bool isRun = false;
|
||||||
|
|
||||||
|
if (isRun==on)
|
||||||
|
return;
|
||||||
|
else
|
||||||
|
isRun=on;
|
||||||
|
|
||||||
|
|
||||||
|
TRACE(2,"%s %d\n", __func__, on);
|
||||||
|
memset(&stream_cfg, 0, sizeof(stream_cfg));
|
||||||
|
if (on){
|
||||||
|
play_wav_file(wave);
|
||||||
|
|
||||||
|
stream_cfg.bits = AUD_BITS_16;
|
||||||
|
stream_cfg.channel_num = AUD_CHANNEL_NUM_2;
|
||||||
|
stream_cfg.sample_rate = AUD_SAMPRATE_48000;
|
||||||
|
|
||||||
|
stream_cfg.device = AUD_STREAM_USE_INT_CODEC;
|
||||||
|
stream_cfg.io_path = AUD_OUTPUT_PATH_SPEAKER;
|
||||||
|
stream_cfg.vol = 0x03;
|
||||||
|
|
||||||
|
stream_cfg.handler = wav_file_audio_more_data;
|
||||||
|
stream_cfg.data_ptr = app_test_playback_buff;
|
||||||
|
stream_cfg.data_size = APP_TEST_PLAYBACK_BUFF_SIZE;
|
||||||
|
|
||||||
|
af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK, &stream_cfg);
|
||||||
|
af_stream_start(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK);
|
||||||
|
}else{
|
||||||
|
stop_wav_file();
|
||||||
|
af_stream_stop(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK);
|
||||||
|
af_stream_close(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FIL pcm_fil;
|
||||||
|
FRESULT pcm_res;
|
||||||
|
UINT pcm_num;
|
||||||
|
uint32_t pcm_save_more_data(uint8_t *buf, uint32_t len)
|
||||||
|
{
|
||||||
|
// TRACE(2,"%s\n len:%d", __func__, len);
|
||||||
|
|
||||||
|
audio_buffer_set_stereo2mono_16bits(buf, len, 1);
|
||||||
|
pcm_res = f_write(&pcm_fil,(uint8_t *)buf,len>>1,&pcm_num);
|
||||||
|
if(pcm_res != FR_OK)
|
||||||
|
{
|
||||||
|
TRACE(2,"[%s]:error-->res = %d", __func__, pcm_res);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ad_tester(bool run)
|
||||||
|
{
|
||||||
|
char filename[] = "/sd/audio_dump.bin";
|
||||||
|
|
||||||
|
struct AF_STREAM_CONFIG_T stream_cfg;
|
||||||
|
|
||||||
|
TRACE(2,"%s %d\n", __func__, run);
|
||||||
|
|
||||||
|
if (run){
|
||||||
|
memset(&stream_cfg, 0, sizeof(stream_cfg));
|
||||||
|
pcm_res = f_open(&pcm_fil,"test2.bin",FA_CREATE_ALWAYS | FA_WRITE);
|
||||||
|
if (pcm_res) {
|
||||||
|
TRACE(2,"[%s]:Cannot creat test2.bin...%d",__func__, pcm_res);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
stream_cfg.bits = AUD_BITS_16;
|
||||||
|
stream_cfg.channel_num = AUD_CHANNEL_NUM_2;
|
||||||
|
stream_cfg.sample_rate = AUD_SAMPRATE_48000;
|
||||||
|
|
||||||
|
stream_cfg.device = AUD_STREAM_USE_INT_CODEC;
|
||||||
|
stream_cfg.io_path = AUD_INPUT_PATH_MAINMIC;
|
||||||
|
stream_cfg.vol = 0x03;
|
||||||
|
|
||||||
|
stream_cfg.handler = pcm_save_more_data;
|
||||||
|
stream_cfg.data_ptr = app_test_playback_buff;
|
||||||
|
stream_cfg.data_size = APP_TEST_PLAYBACK_BUFF_SIZE;
|
||||||
|
|
||||||
|
af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE, &stream_cfg);
|
||||||
|
af_stream_start(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
||||||
|
}else{
|
||||||
|
af_stream_stop(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
||||||
|
af_stream_close(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
||||||
|
osDelay(1000);
|
||||||
|
|
||||||
|
f_close(&pcm_fil);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if dump data into sd, buffer length should make sd card speed enough
|
||||||
|
// Bench32.exe can test sd card speed in PC, then make sure bufer length, buffer length < 16k(sd driver)
|
||||||
|
void dump_data2sd(enum APP_SDMMC_DUMP_T opt, uint8_t *buf, uint32_t len)
|
||||||
|
{
|
||||||
|
static FIL sd_fil;
|
||||||
|
FRESULT res;
|
||||||
|
|
||||||
|
|
||||||
|
ASSERT(opt < APP_SDMMC_DUMP_NUM, "[%s] opt(%d) >= APP_SDMMC_DUMP_NUM", __func__, opt);
|
||||||
|
|
||||||
|
if(opt == APP_SDMMC_DUMP_OPEN)
|
||||||
|
{
|
||||||
|
// res = f_open(&sd_fil,"dump.bin",FA_CREATE_ALWAYS | FA_WRITE);
|
||||||
|
res = f_open(&sd_fil,"test.txt",FA_READ);
|
||||||
|
|
||||||
|
// ASSERT(pcm_res == FR_OK,"[%s]:Cannot creat dump.bin, res = %d",__func__, pcm_res);
|
||||||
|
}
|
||||||
|
if(opt == APP_SDMMC_DUMP_READ)
|
||||||
|
{
|
||||||
|
res = f_read(&sd_fil, buf, len, &pcm_num);
|
||||||
|
|
||||||
|
// ASSERT(pcm_res == FR_OK,"[%s]:Cannot creat dump.bin, res = %d",__func__, pcm_res);
|
||||||
|
}
|
||||||
|
else if(opt == APP_SDMMC_DUMP_WRITE)
|
||||||
|
{
|
||||||
|
res = f_write(&sd_fil, buf, len, &pcm_num);
|
||||||
|
|
||||||
|
// ASSERT(pcm_res == FR_OK,"[%s]:Write dump.bin failed, res = %d", __func__, pcm_res);
|
||||||
|
}
|
||||||
|
else if(opt == APP_SDMMC_DUMP_CLOSE)
|
||||||
|
{
|
||||||
|
res = f_close(&sd_fil);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(res == FR_OK)
|
||||||
|
{
|
||||||
|
TRACE(3,"[%s] SUCESS: opt = %d, res = %d",__func__, opt, res);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TRACE(3,"[%s] ERROR: opt = %d, res = %d",__func__, opt, res);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
/***************************************************************************
|
||||||
|
*
|
||||||
|
* Copyright 2015-2019 BES.
|
||||||
|
* All rights reserved. All unpublished rights reserved.
|
||||||
|
*
|
||||||
|
* No part of this work may be used or reproduced in any form or by any
|
||||||
|
* means, or stored in a database or retrieval system, without prior written
|
||||||
|
* permission of BES.
|
||||||
|
*
|
||||||
|
* Use of this work is governed by a license granted by BES.
|
||||||
|
* This work contains confidential and proprietary information of
|
||||||
|
* BES. which is protected by copyright, trade secret,
|
||||||
|
* trademark and other intellectual property rights.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
#ifndef __APP_SDMMC_H__
|
||||||
|
#define __APP_SDMMC_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
enum APP_SDMMC_DUMP_T{
|
||||||
|
APP_SDMMC_DUMP_OPEN = 0,
|
||||||
|
APP_SDMMC_DUMP_READ,
|
||||||
|
APP_SDMMC_DUMP_WRITE,
|
||||||
|
APP_SDMMC_DUMP_CLOSE,
|
||||||
|
APP_SDMMC_DUMP_NUM
|
||||||
|
};
|
||||||
|
|
||||||
|
int sd_open();
|
||||||
|
|
||||||
|
void dump_data2sd(enum APP_SDMMC_DUMP_T opt, uint8_t *buf, uint32_t len);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif//__FMDEC_H__
|
|
@ -0,0 +1,193 @@
|
||||||
|
cur_dir := $(dir $(lastword $(MAKEFILE_LIST)))
|
||||||
|
|
||||||
|
obj-y := $(patsubst $(cur_dir)%,%,$(wildcard $(cur_dir)*.c $(cur_dir)*.cpp $(cur_dir)*.S))
|
||||||
|
|
||||||
|
obj-y += ../../tests/anc_usb/usb_audio_app.c
|
||||||
|
obj-y += ../../tests/anc_usb/safe_queue.c
|
||||||
|
obj-y += ../../tests/anc_usb/memutils.c
|
||||||
|
|
||||||
|
ifeq ($(USB_AUDIO_SPEECH),1)
|
||||||
|
obj-y += ../../tests/anc_usb/speech_process.c
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(ANC_APP),1)
|
||||||
|
obj-y += ../../tests/anc_usb/anc_usb_app.c
|
||||||
|
endif
|
||||||
|
|
||||||
|
obj-y := $(obj-y:.c=.o)
|
||||||
|
obj-y := $(obj-y:.cpp=.o)
|
||||||
|
obj-y := $(obj-y:.S=.o)
|
||||||
|
|
||||||
|
|
||||||
|
ccflags-y += \
|
||||||
|
-Iutils/boot_struct \
|
||||||
|
-Iutils/crc32 \
|
||||||
|
-Iutils/hexdump \
|
||||||
|
-Iutils/hwtimer_list \
|
||||||
|
-Itests/programmer \
|
||||||
|
-Iplatform/drivers/usb/usb_dev/inc \
|
||||||
|
-Iplatform/drivers/ana \
|
||||||
|
-Iservices/multimedia/audio/process/adp/include \
|
||||||
|
-Iservices/multimedia/audio/process/anc/include \
|
||||||
|
-Iservices/multimedia/audio/process/filters/include \
|
||||||
|
-Iservices/multimedia/audio/process/resample/include \
|
||||||
|
-Iservices/multimedia/speech/inc \
|
||||||
|
-Iservices/audio_process \
|
||||||
|
-Iservices/nv_section/aud_section \
|
||||||
|
-Iservices/nv_section/include \
|
||||||
|
-Iservices/overlay \
|
||||||
|
-Itests/anc_usb
|
||||||
|
|
||||||
|
CFLAGS_usbaudio_entry.o += -DUSB_AUDIO_APP
|
||||||
|
CFLAGS_usb_audio_app.o += -DAUDIO_OUTPUT_VOLUME_DEFAULT=$(AUDIO_OUTPUT_VOLUME_DEFAULT)
|
||||||
|
CFLAGS_adda_loop_app.o += -DAUDIO_OUTPUT_VOLUME_DEFAULT=$(AUDIO_OUTPUT_VOLUME_DEFAULT)
|
||||||
|
|
||||||
|
ANC_USB_CFG_FLAGS :=
|
||||||
|
|
||||||
|
# ANC option
|
||||||
|
ifeq ($(ANC_APP),1)
|
||||||
|
ANC_USB_CFG_FLAGS += -DANC_APP
|
||||||
|
endif
|
||||||
|
|
||||||
|
# USB audio option
|
||||||
|
ifeq ($(USB_AUDIO_APP),1)
|
||||||
|
ANC_USB_CFG_FLAGS += -DUSB_AUDIO_APP
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(USB_HIGH_SPEED),1)
|
||||||
|
ANC_USB_CFG_FLAGS += -DUSB_HIGH_SPEED
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(AUDIO_RESAMPLE),1)
|
||||||
|
ANC_USB_CFG_FLAGS += -D__AUDIO_RESAMPLE__
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(ADC_CH_SEP_BUFF),1)
|
||||||
|
ANC_USB_CFG_FLAGS += -DADC_CH_SEP_BUFF
|
||||||
|
endif
|
||||||
|
|
||||||
|
include platform/drivers/usb/usb_dev/uaud_cfg_flags.mk
|
||||||
|
|
||||||
|
platform/drivers/usb/usb_dev/uaud_cfg_flags.mk: ;
|
||||||
|
|
||||||
|
ANC_USB_CFG_FLAGS += $(UAUD_CFG_FLAGS)
|
||||||
|
|
||||||
|
# USB audio configuration
|
||||||
|
ifeq ($(USB_AUDIO_DYN_CFG),1)
|
||||||
|
ifneq ($(AUDIO_RESAMPLE),1)
|
||||||
|
SW_CAPTURE_RESAMPLE ?= 1
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(AUDIO_PLAYBACK_24BIT),1)
|
||||||
|
ANC_USB_CFG_FLAGS += -DAUDIO_PLAYBACK_24BIT
|
||||||
|
endif
|
||||||
|
|
||||||
|
# DSD configuration
|
||||||
|
ifeq ($(HW_FIR_DSD_PROCESS),1)
|
||||||
|
ANC_USB_CFG_FLAGS += -D__HW_FIR_DSD_PROCESS__
|
||||||
|
endif
|
||||||
|
|
||||||
|
# EQ configuration
|
||||||
|
ifeq ($(HW_FIR_EQ_PROCESS),1)
|
||||||
|
ANC_USB_CFG_FLAGS += -D__HW_FIR_EQ_PROCESS__
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(HW_IIR_EQ_PROCESS),1)
|
||||||
|
ANC_USB_CFG_FLAGS += -D__HW_IIR_EQ_PROCESS__
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(SW_IIR_EQ_PROCESS),1)
|
||||||
|
ANC_USB_CFG_FLAGS += -D__SW_IIR_EQ_PROCESS__
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(HW_DAC_IIR_EQ_PROCESS),1)
|
||||||
|
ANC_USB_CFG_FLAGS += -D__HW_DAC_IIR_EQ_PROCESS__
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(SW_CAPTURE_RESAMPLE),1)
|
||||||
|
ANC_USB_CFG_FLAGS += -DSW_CAPTURE_RESAMPLE
|
||||||
|
endif
|
||||||
|
|
||||||
|
CFLAGS_usbaudio_entry.o += $(ANC_USB_CFG_FLAGS)
|
||||||
|
CFLAGS_usb_audio_app.o += $(ANC_USB_CFG_FLAGS)
|
||||||
|
CFLAGS_anc_usb_app.o += $(ANC_USB_CFG_FLAGS)
|
||||||
|
|
||||||
|
ifeq ($(ANC_KEY_DOUBLE_CLICK_ON_OFF),1)
|
||||||
|
CFLAGS_anc_usb_app.o += -DANC_KEY_DOUBLE_CLICK_ON_OFF
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(ANC_FF_ENABLED),1)
|
||||||
|
CFLAGS_anc_usb_app.o += -DANC_FF_ENABLED
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(ANC_FB_ENABLED),1)
|
||||||
|
CFLAGS_anc_usb_app.o += -DANC_FB_ENABLED
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(AUDIO_SECTION_SUPPT),1)
|
||||||
|
CFLAGS_anc_usb_app.o += -D__AUDIO_SECTION_SUPPT__
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(ANC_INIT_OFF),1)
|
||||||
|
CFLAGS_anc_usb_app.o += -DANC_INIT_OFF
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(PC_CMD_UART),1)
|
||||||
|
CFLAGS_usbaudio_entry.o += -D__PC_CMD_UART__
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(DELAY_STREAM_OPEN),1)
|
||||||
|
CFLAGS_usb_audio_app.o += -DDELAY_STREAM_OPEN
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(NOISE_GATING),1)
|
||||||
|
CFLAGS_usb_audio_app.o += -DNOISE_GATING
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(NOISE_REDUCTION),1)
|
||||||
|
CFLAGS_usb_audio_app.o += -DNOISE_REDUCTION
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(ANC_L_R_MISALIGN_WORKAROUND),1)
|
||||||
|
CFLAGS_usb_audio_app.o += -DANC_L_R_MISALIGN_WORKAROUND
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(ANDROID_ACCESSORY_SPEC),1)
|
||||||
|
CFLAGS_usb_audio_app.o += -DANDROID_ACCESSORY_SPEC
|
||||||
|
ifeq ($(ANDROID_VOICE_CMD_KEY),1)
|
||||||
|
CFLAGS_usb_audio_app.o += -DANDROID_VOICE_CMD_KEY
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(DUAL_AUX_MIC_MORE_FILTER),1)
|
||||||
|
CFLAGS_usb_audio_app.o += -DDUAL_AUX_MIC_MORE_FILTER
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(FREQ_RESP_EQ),1)
|
||||||
|
CFLAGS_usb_audio_app.o += -DFREQ_RESP_EQ
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(KEEP_SAME_LATENCY),1)
|
||||||
|
CFLAGS_usb_audio_app.o += -DKEEP_SAME_LATENCY
|
||||||
|
CFLAGS_speech_process.o += -DKEEP_SAME_LATENCY
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(USB_AUDIO_PWRKEY_TEST),1)
|
||||||
|
CFLAGS_usb_audio_app.o += -DUSB_AUDIO_PWRKEY_TEST
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(AUDIO_RESAMPLE),1)
|
||||||
|
# If neither best1000 nor best2000
|
||||||
|
ifeq ($(filter best1000 best2000,$(CHIP)),)
|
||||||
|
PLL_TUNE_SAMPLE_RATE ?= 1
|
||||||
|
endif
|
||||||
|
ifeq ($(PLL_TUNE_SAMPLE_RATE),1)
|
||||||
|
CFLAGS_usb_audio_app.o += -DPLL_TUNE_SAMPLE_RATE
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(USB_AUDIO_SPEECH),1)
|
||||||
|
CFLAGS_usbaudio_entry.o += -DUSB_AUDIO_SPEECH
|
||||||
|
CFLAGS_usb_audio_app.o += -DUSB_AUDIO_SPEECH
|
||||||
|
endif
|
|
@ -0,0 +1,347 @@
|
||||||
|
/***************************************************************************
|
||||||
|
*
|
||||||
|
* Copyright 2015-2019 BES.
|
||||||
|
* All rights reserved. All unpublished rights reserved.
|
||||||
|
*
|
||||||
|
* No part of this work may be used or reproduced in any form or by any
|
||||||
|
* means, or stored in a database or retrieval system, without prior written
|
||||||
|
* permission of BES.
|
||||||
|
*
|
||||||
|
* Use of this work is governed by a license granted by BES.
|
||||||
|
* This work contains confidential and proprietary information of
|
||||||
|
* BES. which is protected by copyright, trade secret,
|
||||||
|
* trademark and other intellectual property rights.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
#include "plat_addr_map.h"
|
||||||
|
#include "hal_cmu.h"
|
||||||
|
#include "hal_timer.h"
|
||||||
|
#include "hal_trace.h"
|
||||||
|
#include "hal_iomux.h"
|
||||||
|
#include "hal_dma.h"
|
||||||
|
#include "hal_key.h"
|
||||||
|
#include "hal_gpadc.h"
|
||||||
|
#include "hal_sleep.h"
|
||||||
|
#include "hal_sysfreq.h"
|
||||||
|
#include "cmsis.h"
|
||||||
|
#include "pmu.h"
|
||||||
|
#include "analog.h"
|
||||||
|
#include "string.h"
|
||||||
|
#include "hwtimer_list.h"
|
||||||
|
#include "audioflinger.h"
|
||||||
|
#if defined(ANC_APP)
|
||||||
|
#include "anc_usb_app.h"
|
||||||
|
#endif
|
||||||
|
#include "usb_audio_app.h"
|
||||||
|
#include "dualadc_audio_app.h"
|
||||||
|
#include "usb_audio_frm_defs.h"
|
||||||
|
#include "tgt_hardware.h"
|
||||||
|
#include "audio_process.h"
|
||||||
|
|
||||||
|
#ifdef RTOS
|
||||||
|
#include "cmsis_os.h"
|
||||||
|
#endif
|
||||||
|
#ifdef __PC_CMD_UART__
|
||||||
|
#include "hal_cmd.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef USB_AUDIO_SPEECH
|
||||||
|
#define CODEC_BUFF_FRAME_NUM (2 * 16)
|
||||||
|
#define USB_BUFF_FRAME_NUM (CODEC_BUFF_FRAME_NUM * 2)
|
||||||
|
#else
|
||||||
|
#define CODEC_BUFF_FRAME_NUM 4
|
||||||
|
#define USB_BUFF_FRAME_NUM 8
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (CODEC_BUFF_FRAME_NUM >= USB_BUFF_FRAME_NUM)
|
||||||
|
#error "Codec buffer frame num should be less than usb buffer frame num (on the requirement of conflict ctrl)"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef USB_AUDIO_DYN_CFG
|
||||||
|
#define USB_AUDIO_PLAYBACK_BUFF_SIZE NON_EXP_ALIGN(MAX_FRAME_SIZE_PLAYBACK * CODEC_BUFF_FRAME_NUM, DAC_BUFF_ALIGN)
|
||||||
|
#define USB_AUDIO_CAPTURE_BUFF_SIZE NON_EXP_ALIGN(MAX_FRAME_SIZE_CAPTURE * CODEC_BUFF_FRAME_NUM, ADC_BUFF_ALIGN)
|
||||||
|
|
||||||
|
#define USB_AUDIO_RECV_BUFF_SIZE NON_EXP_ALIGN(MAX_FRAME_SIZE_RECV * USB_BUFF_FRAME_NUM, RECV_BUFF_ALIGN)
|
||||||
|
#define USB_AUDIO_SEND_BUFF_SIZE NON_EXP_ALIGN(MAX_FRAME_SIZE_SEND * USB_BUFF_FRAME_NUM, SEND_BUFF_ALIGN)
|
||||||
|
|
||||||
|
#if defined(CHIP_BEST1000)
|
||||||
|
// FIR EQ is working on 16-bit
|
||||||
|
// FIR_EQ_buffer_size = max_playback_symbol_number_in_buffer * sizeof(int16_t)
|
||||||
|
#define USB_AUDIO_FIR_EQ_BUFF_SIZE USB_AUDIO_PLAYBACK_BUFF_SIZE
|
||||||
|
#elif defined(CHIP_BEST2000)
|
||||||
|
// FIR EQ is working on 32-bit
|
||||||
|
// FIR_EQ_buffer_size = max_playback_symbol_number_in_buffer * sizeof(int32_t)
|
||||||
|
#define USB_AUDIO_FIR_EQ_BUFF_SIZE (USB_AUDIO_PLAYBACK_BUFF_SIZE*2)
|
||||||
|
#elif defined(CHIP_BEST2300) || defined(CHIP_BEST2300P)
|
||||||
|
// FIR EQ is working on 32-bit
|
||||||
|
// FIR_EQ_buffer_size = max_playback_symbol_number_in_buffer * sizeof(int32_t)
|
||||||
|
#define USB_AUDIO_FIR_EQ_BUFF_SIZE (USB_AUDIO_PLAYBACK_BUFF_SIZE*2)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#else
|
||||||
|
#define USB_AUDIO_PLAYBACK_BUFF_SIZE NON_EXP_ALIGN(FRAME_SIZE_PLAYBACK * CODEC_BUFF_FRAME_NUM, DAC_BUFF_ALIGN)
|
||||||
|
#define USB_AUDIO_CAPTURE_BUFF_SIZE NON_EXP_ALIGN(FRAME_SIZE_CAPTURE * CODEC_BUFF_FRAME_NUM, ADC_BUFF_ALIGN)
|
||||||
|
|
||||||
|
#define USB_AUDIO_RECV_BUFF_SIZE NON_EXP_ALIGN(FRAME_SIZE_RECV * USB_BUFF_FRAME_NUM, RECV_BUFF_ALIGN)
|
||||||
|
#define USB_AUDIO_SEND_BUFF_SIZE NON_EXP_ALIGN(FRAME_SIZE_SEND * USB_BUFF_FRAME_NUM, SEND_BUFF_ALIGN)
|
||||||
|
|
||||||
|
#if defined(CHIP_BEST1000)
|
||||||
|
// FIR EQ is working on 16-bit
|
||||||
|
#define USB_AUDIO_FIR_EQ_BUFF_SIZE (USB_AUDIO_PLAYBACK_BUFF_SIZE * sizeof(int16_t) / SAMPLE_SIZE_PLAYBACK)
|
||||||
|
#elif defined(CHIP_BEST2000)
|
||||||
|
// FIR EQ is working on 16-bit
|
||||||
|
#define USB_AUDIO_FIR_EQ_BUFF_SIZE (USB_AUDIO_PLAYBACK_BUFF_SIZE * sizeof(int32_t) / SAMPLE_SIZE_PLAYBACK)
|
||||||
|
#elif defined(CHIP_BEST2300) || defined(CHIP_BEST2300P)
|
||||||
|
// FIR EQ is working on 16-bit
|
||||||
|
#define USB_AUDIO_FIR_EQ_BUFF_SIZE (USB_AUDIO_PLAYBACK_BUFF_SIZE * sizeof(int32_t) / SAMPLE_SIZE_PLAYBACK)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (defined(CHIP_BEST1000) && (defined(ANC_APP) || defined(_DUAL_AUX_MIC_))) && (CHAN_NUM_CAPTURE == CHAN_NUM_SEND)
|
||||||
|
// Resample input buffer size should be (half_of_max_sample_num * SAMPLE_SIZE_CAPTURE * CHAN_NUM_CAPTURE).
|
||||||
|
// half_of_max_sample_num = 48000 / 1000 * CODEC_BUFF_FRAME_NUM / 2 * 48 / 44
|
||||||
|
#define RESAMPLE_INPUT_BUFF_SIZE ALIGN(48000 / 1000 * SAMPLE_SIZE_CAPTURE * CHAN_NUM_CAPTURE * CODEC_BUFF_FRAME_NUM / 2 * 48 / 44, 4)
|
||||||
|
#else
|
||||||
|
#define RESAMPLE_INPUT_BUFF_SIZE 0
|
||||||
|
#endif
|
||||||
|
// Resample history buffer size should be
|
||||||
|
// sizeof(struct RESAMPLE_CTRL_T) + ((SAMPLE_NUM + phase_coef_num) * SAMPLE_SIZE_CAPTURE * CHAN_NUM_CAPTURE)
|
||||||
|
#define RESAMPLE_HISTORY_BUFF_SIZE (50 + (256 * SAMPLE_SIZE_CAPTURE * CHAN_NUM_CAPTURE))
|
||||||
|
#define USB_AUDIO_RESAMPLE_BUFF_SIZE (RESAMPLE_INPUT_BUFF_SIZE + RESAMPLE_HISTORY_BUFF_SIZE)
|
||||||
|
|
||||||
|
#define ALIGNED4 ALIGNED(4)
|
||||||
|
|
||||||
|
#if defined(USB_AUDIO_APP) || defined(DUALADC_AUDIO_TEST)
|
||||||
|
|
||||||
|
#ifdef AUDIO_ANC_FB_MC
|
||||||
|
static uint8_t ALIGNED4 playback_buff[USB_AUDIO_PLAYBACK_BUFF_SIZE * 9];//max 48->384 or 44.1->44.1*8;
|
||||||
|
#else
|
||||||
|
static uint8_t ALIGNED4 playback_buff[USB_AUDIO_PLAYBACK_BUFF_SIZE];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static uint8_t ALIGNED4 capture_buff[USB_AUDIO_CAPTURE_BUFF_SIZE];
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef USB_AUDIO_APP
|
||||||
|
#if defined(__HW_FIR_EQ_PROCESS__) && defined(__HW_IIR_EQ_PROCESS__)
|
||||||
|
static uint8_t ALIGNED4 eq_buff[USB_AUDIO_FIR_EQ_BUFF_SIZE+USB_AUDIO_IIR_EQ_BUFF_SIZE];
|
||||||
|
#elif defined(__HW_FIR_EQ_PROCESS__) && !defined(__HW_IIR_EQ_PROCESS__)
|
||||||
|
static uint8_t ALIGNED4 eq_buff[USB_AUDIO_FIR_EQ_BUFF_SIZE];
|
||||||
|
#elif !defined(__HW_FIR_EQ_PROCESS__) && defined(__HW_IIR_EQ_PROCESS__)
|
||||||
|
static uint8_t ALIGNED4 eq_buff[USB_AUDIO_IIR_EQ_BUFF_SIZE];
|
||||||
|
#else
|
||||||
|
static uint8_t ALIGNED4 eq_buff[0];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef SW_CAPTURE_RESAMPLE
|
||||||
|
static uint8_t ALIGNED4 resample_buff[USB_AUDIO_RESAMPLE_BUFF_SIZE];
|
||||||
|
#else
|
||||||
|
static uint8_t ALIGNED4 resample_buff[0];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static uint8_t ALIGNED4 recv_buff[USB_AUDIO_RECV_BUFF_SIZE];
|
||||||
|
static uint8_t ALIGNED4 send_buff[USB_AUDIO_SEND_BUFF_SIZE];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CFG_HW_KEY_LED_PIN
|
||||||
|
const struct HAL_IOMUX_PIN_FUNCTION_MAP pinmux_key_led[1] = {
|
||||||
|
{CFG_HW_KEY_LED_PIN, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_NOPULL},
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CFG_MIC_KEY
|
||||||
|
extern void mic_key_open (void);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static void uart_i2c_switch(void)
|
||||||
|
{
|
||||||
|
static int flag = 0;
|
||||||
|
|
||||||
|
flag ^= 1;
|
||||||
|
|
||||||
|
if (flag) {
|
||||||
|
hal_iomux_set_analog_i2c();
|
||||||
|
} else {
|
||||||
|
hal_iomux_set_uart0();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int POSSIBLY_UNUSED key_event_process(uint32_t key_code, uint8_t key_event)
|
||||||
|
{
|
||||||
|
TRACE(3,"%s: code=0x%X, event=%u", __FUNCTION__, key_code, key_event);
|
||||||
|
|
||||||
|
#ifdef CFG_HW_KEY_LED_PIN
|
||||||
|
if (key_event == HAL_KEY_EVENT_DOWN) {
|
||||||
|
hal_gpio_pin_set(CFG_HW_KEY_LED_PIN);
|
||||||
|
} else if (key_event == HAL_KEY_EVENT_UP) {
|
||||||
|
hal_gpio_pin_clr(CFG_HW_KEY_LED_PIN);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef USB_AUDIO_APP
|
||||||
|
if (usb_audio_app_key(key_code, key_event) == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef ANC_APP
|
||||||
|
if (anc_usb_app_key(key_code, key_event) == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (key_event == HAL_KEY_EVENT_CLICK) {
|
||||||
|
if (key_code == HAL_KEY_CODE_FN9) {
|
||||||
|
uart_i2c_switch();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void anc_usb_open(void)
|
||||||
|
{
|
||||||
|
TRACE(1,"%s", __FUNCTION__);
|
||||||
|
|
||||||
|
#ifdef __AUDIO_RESAMPLE__
|
||||||
|
hal_cmu_audio_resample_enable();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef USB_AUDIO_APP
|
||||||
|
struct USB_AUDIO_BUF_CFG cfg;
|
||||||
|
|
||||||
|
memset(&cfg, 0, sizeof(cfg));
|
||||||
|
cfg.play_buf = playback_buff;
|
||||||
|
#ifdef AUDIO_ANC_FB_MC
|
||||||
|
cfg.play_size = sizeof(playback_buff) / 9;
|
||||||
|
#else
|
||||||
|
cfg.play_size = sizeof(playback_buff);
|
||||||
|
#endif
|
||||||
|
cfg.cap_buf = capture_buff;
|
||||||
|
cfg.cap_size = sizeof(capture_buff);
|
||||||
|
cfg.recv_buf = recv_buff;
|
||||||
|
cfg.recv_size = sizeof(recv_buff);
|
||||||
|
cfg.send_buf = send_buff;
|
||||||
|
cfg.send_size = sizeof(send_buff);
|
||||||
|
cfg.eq_buf = eq_buff;
|
||||||
|
cfg.eq_size = sizeof(eq_buff);
|
||||||
|
cfg.resample_buf = resample_buff;
|
||||||
|
cfg.resample_size = sizeof(resample_buff);
|
||||||
|
|
||||||
|
usb_audio_app_init(&cfg);
|
||||||
|
usb_audio_app(1);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef ANC_APP
|
||||||
|
anc_usb_app_init(AUD_INPUT_PATH_MAINMIC, SAMPLE_RATE_PLAYBACK, SAMPLE_RATE_CAPTURE);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef DUALADC_AUDIO_TEST
|
||||||
|
dualadc_audio_app_init(playback_buff, USB_AUDIO_PLAYBACK_BUFF_SIZE,
|
||||||
|
capture_buff, USB_AUDIO_CAPTURE_BUFF_SIZE);
|
||||||
|
dualadc_audio_app(1);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(CFG_MIC_KEY)
|
||||||
|
mic_key_open();
|
||||||
|
#endif
|
||||||
|
#ifdef BT_USB_AUDIO_DUAL_MODE
|
||||||
|
return;
|
||||||
|
#endif
|
||||||
|
// Allow sleep
|
||||||
|
hal_sysfreq_req(HAL_SYSFREQ_USER_INIT, HAL_CMU_FREQ_32K);
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
#ifdef USB_AUDIO_APP
|
||||||
|
usb_audio_app_loop();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef ANC_APP
|
||||||
|
anc_usb_app_loop();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef RTOS
|
||||||
|
// Let the task sleep
|
||||||
|
osDelay(20);
|
||||||
|
#else // !RTOS
|
||||||
|
|
||||||
|
#ifdef __PC_CMD_UART__
|
||||||
|
hal_cmd_run();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
hal_sleep_enter_sleep();
|
||||||
|
|
||||||
|
#endif // !RTOS
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void anc_usb_close(void)
|
||||||
|
{
|
||||||
|
usb_audio_app(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef CFG_HW_GPADCKEY
|
||||||
|
void gpadc_key_handler(uint16_t irq_val, HAL_GPADC_MV_T volt)
|
||||||
|
{
|
||||||
|
static uint16_t stable_cnt = 0;
|
||||||
|
static uint16_t click_cnt = 0;
|
||||||
|
static uint32_t click_time;
|
||||||
|
uint32_t time;
|
||||||
|
enum HAL_KEY_EVENT_T event;
|
||||||
|
bool send_event = false;
|
||||||
|
|
||||||
|
time = hal_sys_timer_get();
|
||||||
|
|
||||||
|
if (volt < 100) {
|
||||||
|
stable_cnt++;
|
||||||
|
//TRACE(5,"adc_key down: volt=%u stable=%u click_cnt=%u click_time=%u time=%u", volt, stable_cnt, click_cnt, click_time, time);
|
||||||
|
} else {
|
||||||
|
if (stable_cnt > 1) {
|
||||||
|
//TRACE(5,"adc_key up: volt=%u stable=%u click_cnt=%u click_time=%u time=%u", volt, stable_cnt, click_cnt, click_time, time);
|
||||||
|
if (click_cnt == 0 || (time - click_time) < MS_TO_TICKS(500)) {
|
||||||
|
click_time = time;
|
||||||
|
click_cnt++;
|
||||||
|
if (click_cnt >= 3) {
|
||||||
|
send_event = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
send_event = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stable_cnt = 0;
|
||||||
|
|
||||||
|
if (click_cnt > 0 && (time - click_time) >= MS_TO_TICKS(500)) {
|
||||||
|
send_event = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (send_event) {
|
||||||
|
//TRACE(5,"adc_key click: volt=%u stable=%u click_cnt=%u click_time=%u time=%u", volt, stable_cnt, click_cnt, click_time, time);
|
||||||
|
if (click_cnt == 1) {
|
||||||
|
event = HAL_KEY_EVENT_CLICK;
|
||||||
|
} else if (click_cnt == 2) {
|
||||||
|
event = HAL_KEY_EVENT_DOUBLECLICK;
|
||||||
|
} else {
|
||||||
|
event = HAL_KEY_EVENT_TRIPLECLICK;
|
||||||
|
}
|
||||||
|
key_event_process(CFG_HW_GPADCKEY, event);
|
||||||
|
click_cnt = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// GDB can set a breakpoint on the main function only if it is
|
||||||
|
// declared as below, when linking with STD libraries.
|
||||||
|
int btusbaudio_entry(void)
|
||||||
|
{
|
||||||
|
anc_usb_open();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void btusbaudio_exit(void)
|
||||||
|
{
|
||||||
|
anc_usb_close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
cur_dir := $(dir $(lastword $(MAKEFILE_LIST)))
|
||||||
|
|
||||||
|
obj-y := $(patsubst $(cur_dir)%,%,$(wildcard $(cur_dir)*.c $(cur_dir)*.cpp $(cur_dir)*.S))
|
||||||
|
obj-y := $(obj-y:.c=.o)
|
||||||
|
obj-y := $(obj-y:.cpp=.o)
|
||||||
|
obj-y := $(obj-y:.S=.o)
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
/***************************************************************************
|
||||||
|
*
|
||||||
|
* Copyright 2015-2019 BES.
|
||||||
|
* All rights reserved. All unpublished rights reserved.
|
||||||
|
*
|
||||||
|
* No part of this work may be used or reproduced in any form or by any
|
||||||
|
* means, or stored in a database or retrieval system, without prior written
|
||||||
|
* permission of BES.
|
||||||
|
*
|
||||||
|
* Use of this work is governed by a license granted by BES.
|
||||||
|
* This work contains confidential and proprietary information of
|
||||||
|
* BES. which is protected by copyright, trade secret,
|
||||||
|
* trademark and other intellectual property rights.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
#include "cmsis_os.h"
|
||||||
|
#include "hal_trace.h"
|
||||||
|
#include "app_thread.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
/***************************************************************************
|
||||||
|
*
|
||||||
|
* Copyright 2015-2019 BES.
|
||||||
|
* All rights reserved. All unpublished rights reserved.
|
||||||
|
*
|
||||||
|
* No part of this work may be used or reproduced in any form or by any
|
||||||
|
* means, or stored in a database or retrieval system, without prior written
|
||||||
|
* permission of BES.
|
||||||
|
*
|
||||||
|
* Use of this work is governed by a license granted by BES.
|
||||||
|
* This work contains confidential and proprietary information of
|
||||||
|
* BES. which is protected by copyright, trade secret,
|
||||||
|
* trademark and other intellectual property rights.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
#ifndef __APP_USBHOST_H__
|
||||||
|
#define __APP_USBHOST_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif//__FMDEC_H__
|
|
@ -1,22 +1,20 @@
|
||||||
#include "app_voice_detector.h"
|
|
||||||
#include "app_thread.h"
|
|
||||||
#include "audioflinger.h"
|
|
||||||
#include "cmsis_os.h"
|
|
||||||
#include "hal_timer.h"
|
|
||||||
#include "hal_trace.h"
|
|
||||||
#include "tgt_hardware.h"
|
|
||||||
#include "voice_detector.h"
|
|
||||||
#include <assert.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include "cmsis_os.h"
|
||||||
|
#include "tgt_hardware.h"
|
||||||
|
#include "audioflinger.h"
|
||||||
|
#include "hal_trace.h"
|
||||||
|
#include "hal_timer.h"
|
||||||
|
#include "app_thread.h"
|
||||||
|
#include "voice_detector.h"
|
||||||
|
#include "app_voice_detector.h"
|
||||||
|
|
||||||
#define APP_VD_DEBUG
|
#define APP_VD_DEBUG
|
||||||
|
|
||||||
#ifdef APP_VD_DEBUG
|
#ifdef APP_VD_DEBUG
|
||||||
#define APP_VD_LOG(str, ...) LOG_DEBUG(LOG_MOD(AUD), str, ##__VA_ARGS__)
|
#define APP_VD_LOG(str, ...) LOG_DEBUG(LOG_MOD(AUD), str, ##__VA_ARGS__)
|
||||||
#else
|
#else
|
||||||
#define APP_VD_LOG(...) \
|
#define APP_VD_LOG(...) do{}while(0)
|
||||||
do { \
|
|
||||||
} while (0)
|
|
||||||
#endif
|
#endif
|
||||||
#define APP_VD_ERR(str, ...) LOG_ERROR(LOG_MOD(AUD), str, ##__VA_ARGS__)
|
#define APP_VD_ERR(str, ...) LOG_ERROR(LOG_MOD(AUD), str, ##__VA_ARGS__)
|
||||||
|
|
||||||
|
@ -24,8 +22,10 @@ osMutexId vd_mutex_id = NULL;
|
||||||
osMutexDef(vd_mutex);
|
osMutexDef(vd_mutex);
|
||||||
|
|
||||||
static int cmd_arr_evt_vad_start[] = {
|
static int cmd_arr_evt_vad_start[] = {
|
||||||
VOICE_DET_CMD_AUD_CAP_STOP, VOICE_DET_CMD_AUD_CAP_CLOSE,
|
VOICE_DET_CMD_AUD_CAP_STOP,
|
||||||
VOICE_DET_CMD_VAD_OPEN, VOICE_DET_CMD_VAD_START,
|
VOICE_DET_CMD_AUD_CAP_CLOSE,
|
||||||
|
VOICE_DET_CMD_VAD_OPEN,
|
||||||
|
VOICE_DET_CMD_VAD_START,
|
||||||
VOICE_DET_CMD_SYS_CLK_32K,
|
VOICE_DET_CMD_SYS_CLK_32K,
|
||||||
};
|
};
|
||||||
#if 0
|
#if 0
|
||||||
|
@ -44,8 +44,10 @@ static int cmd_arr_evt_cap_start[] = {
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
static int cmd_arr_evt_close[] = {
|
static int cmd_arr_evt_close[] = {
|
||||||
VOICE_DET_CMD_AUD_CAP_STOP, VOICE_DET_CMD_AUD_CAP_CLOSE,
|
VOICE_DET_CMD_AUD_CAP_STOP,
|
||||||
VOICE_DET_CMD_VAD_STOP, VOICE_DET_CMD_VAD_CLOSE,
|
VOICE_DET_CMD_AUD_CAP_CLOSE,
|
||||||
|
VOICE_DET_CMD_VAD_STOP,
|
||||||
|
VOICE_DET_CMD_VAD_CLOSE,
|
||||||
VOICE_DET_CMD_EXIT,
|
VOICE_DET_CMD_EXIT,
|
||||||
};
|
};
|
||||||
#if 1
|
#if 1
|
||||||
|
@ -61,7 +63,8 @@ static int cmd_arr_evt_vad_close[] = {
|
||||||
VOICE_DET_CMD_EXIT,
|
VOICE_DET_CMD_EXIT,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int app_voice_detector_process(APP_MESSAGE_BODY *msg_body) {
|
static int app_voice_detector_process(APP_MESSAGE_BODY *msg_body)
|
||||||
|
{
|
||||||
enum voice_detector_id id = (enum voice_detector_id)msg_body->message_id;
|
enum voice_detector_id id = (enum voice_detector_id)msg_body->message_id;
|
||||||
enum voice_detector_evt evt = (enum voice_detector_evt)msg_body->message_ptr;
|
enum voice_detector_evt evt = (enum voice_detector_evt)msg_body->message_ptr;
|
||||||
int ret = 0, num, *cmds;
|
int ret = 0, num, *cmds;
|
||||||
|
@ -112,7 +115,8 @@ static int app_voice_detector_process(APP_MESSAGE_BODY *msg_body) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void voice_detector_send_msg(uint32_t id, uint32_t evt) {
|
static void voice_detector_send_msg(uint32_t id, uint32_t evt)
|
||||||
|
{
|
||||||
APP_MESSAGE_BLOCK msg;
|
APP_MESSAGE_BLOCK msg;
|
||||||
|
|
||||||
msg.mod_id = APP_MODUAL_VOICE_DETECTOR;
|
msg.mod_id = APP_MODUAL_VOICE_DETECTOR;
|
||||||
|
@ -122,7 +126,8 @@ static void voice_detector_send_msg(uint32_t id, uint32_t evt) {
|
||||||
app_mailbox_put(&msg);
|
app_mailbox_put(&msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void voice_detector_wakeup_system(int state, void *param) {
|
static void voice_detector_wakeup_system(int state, void *param)
|
||||||
|
{
|
||||||
enum voice_detector_id id = VOICE_DETECTOR_ID_0;
|
enum voice_detector_id id = VOICE_DETECTOR_ID_0;
|
||||||
|
|
||||||
if (voice_detector_query_status(id) == VOICE_DET_STATE_VAD_START) {
|
if (voice_detector_query_status(id) == VOICE_DET_STATE_VAD_START) {
|
||||||
|
@ -133,7 +138,8 @@ static void voice_detector_wakeup_system(int state, void *param) {
|
||||||
// APP_VD_LOG("cpu freq=%d", hal_sys_timer_calc_cpu_freq(5,0));
|
// APP_VD_LOG("cpu freq=%d", hal_sys_timer_calc_cpu_freq(5,0));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void voice_not_detector_wakeup_system(int state, void *param) {
|
static void voice_not_detector_wakeup_system(int state, void *param)
|
||||||
|
{
|
||||||
enum voice_detector_id id = VOICE_DETECTOR_ID_0;
|
enum voice_detector_id id = VOICE_DETECTOR_ID_0;
|
||||||
|
|
||||||
if (voice_detector_query_status(id) == VOICE_DET_STATE_VAD_START) {
|
if (voice_detector_query_status(id) == VOICE_DET_STATE_VAD_START) {
|
||||||
|
@ -144,7 +150,8 @@ static void voice_not_detector_wakeup_system(int state, void *param) {
|
||||||
// APP_VD_LOG("cpu freq=%d", hal_sys_timer_calc_cpu_freq(5,0));
|
// APP_VD_LOG("cpu freq=%d", hal_sys_timer_calc_cpu_freq(5,0));
|
||||||
}
|
}
|
||||||
|
|
||||||
void app_voice_detector_init(void) {
|
void app_voice_detector_init(void)
|
||||||
|
{
|
||||||
APP_VD_LOG("%s", __func__);
|
APP_VD_LOG("%s", __func__);
|
||||||
|
|
||||||
if(vd_mutex_id == NULL){
|
if(vd_mutex_id == NULL){
|
||||||
|
@ -153,8 +160,8 @@ void app_voice_detector_init(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_voice_detector_open(enum voice_detector_id id,
|
int app_voice_detector_open(enum voice_detector_id id, enum AUD_VAD_TYPE_T vad_type)
|
||||||
enum AUD_VAD_TYPE_T vad_type) {
|
{
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
APP_VD_LOG("%s", __func__);
|
APP_VD_LOG("%s", __func__);
|
||||||
|
@ -176,7 +183,8 @@ int app_voice_detector_open(enum voice_detector_id id,
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_voice_detector_setup_vad(enum voice_detector_id id,
|
int app_voice_detector_setup_vad(enum voice_detector_id id,
|
||||||
struct AUD_VAD_CONFIG_T *conf) {
|
struct AUD_VAD_CONFIG_T *conf)
|
||||||
|
{
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
APP_VD_LOG("%s", __func__);
|
APP_VD_LOG("%s", __func__);
|
||||||
|
@ -193,7 +201,8 @@ int app_voice_detector_setup_vad(enum voice_detector_id id,
|
||||||
|
|
||||||
int app_voice_detector_setup_stream(enum voice_detector_id id,
|
int app_voice_detector_setup_stream(enum voice_detector_id id,
|
||||||
enum AUD_STREAM_T stream_id,
|
enum AUD_STREAM_T stream_id,
|
||||||
struct AF_STREAM_CONFIG_T *stream) {
|
struct AF_STREAM_CONFIG_T *stream)
|
||||||
|
{
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
APP_VD_LOG("%s", __func__);
|
APP_VD_LOG("%s", __func__);
|
||||||
|
@ -210,7 +219,9 @@ int app_voice_detector_setup_stream(enum voice_detector_id id,
|
||||||
|
|
||||||
int app_voice_detector_setup_callback(enum voice_detector_id id,
|
int app_voice_detector_setup_callback(enum voice_detector_id id,
|
||||||
enum voice_detector_cb_id func_id,
|
enum voice_detector_cb_id func_id,
|
||||||
voice_detector_cb_t func, void *param) {
|
voice_detector_cb_t func,
|
||||||
|
void *param)
|
||||||
|
{
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
APP_VD_LOG("%s", __func__);
|
APP_VD_LOG("%s", __func__);
|
||||||
|
@ -226,26 +237,31 @@ int app_voice_detector_setup_callback(enum voice_detector_id id,
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_voice_detector_send_event(enum voice_detector_id id,
|
int app_voice_detector_send_event(enum voice_detector_id id,
|
||||||
enum voice_detector_evt evt) {
|
enum voice_detector_evt evt)
|
||||||
|
{
|
||||||
APP_VD_LOG("%s, id=%d, evt=%d", __func__, id, evt);
|
APP_VD_LOG("%s, id=%d, evt=%d", __func__, id, evt);
|
||||||
|
|
||||||
voice_detector_send_msg(id, evt);
|
voice_detector_send_msg(id, evt);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void app_voice_detector_close(enum voice_detector_id id) {
|
void app_voice_detector_close(enum voice_detector_id id)
|
||||||
|
{
|
||||||
APP_VD_LOG("%s", __func__);
|
APP_VD_LOG("%s", __func__);
|
||||||
|
|
||||||
voice_detector_send_msg(id, VOICE_DET_EVT_CLOSE);
|
voice_detector_send_msg(id, VOICE_DET_EVT_CLOSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void app_voice_detector_capture_start(enum voice_detector_id id) {
|
void app_voice_detector_capture_start(enum voice_detector_id id)
|
||||||
|
{
|
||||||
APP_VD_LOG("%s", __func__);
|
APP_VD_LOG("%s", __func__);
|
||||||
|
|
||||||
voice_detector_send_msg(id, VOICE_DET_EVT_AUD_CAP_START);
|
voice_detector_send_msg(id, VOICE_DET_EVT_AUD_CAP_START);
|
||||||
}
|
}
|
||||||
|
|
||||||
void app_voice_detector_get_vad_data_info(
|
void app_voice_detector_get_vad_data_info(enum voice_detector_id id,
|
||||||
enum voice_detector_id id, struct CODEC_VAD_BUF_INFO_T *vad_buf_info) {
|
struct CODEC_VAD_BUF_INFO_T* vad_buf_info)
|
||||||
|
{
|
||||||
voice_detector_get_vad_data_info(id, vad_buf_info);
|
voice_detector_get_vad_data_info(id, vad_buf_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
|
#include "hal_trace.h"
|
||||||
|
#include "hal_cmu.h"
|
||||||
|
#include "hal_aud.h"
|
||||||
|
#include "hal_timer.h"
|
||||||
|
#include "hal_sleep.h"
|
||||||
#include "analog.h"
|
#include "analog.h"
|
||||||
#include "audioflinger.h"
|
#include "audioflinger.h"
|
||||||
#include "hal_aud.h"
|
|
||||||
#include "hal_cmu.h"
|
|
||||||
#include "hal_sleep.h"
|
|
||||||
#include "hal_timer.h"
|
|
||||||
#include "hal_trace.h"
|
|
||||||
//#include "app_audio.h"
|
//#include "app_audio.h"
|
||||||
#include "app_utils.h"
|
#include "app_utils.h"
|
||||||
#include "audio_dump.h"
|
|
||||||
#include "speech_ssat.h"
|
|
||||||
#include "voice_detector.h"
|
#include "voice_detector.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "audio_dump.h"
|
||||||
|
#include "speech_ssat.h"
|
||||||
|
|
||||||
#include "pmu.h"
|
#include "pmu.h"
|
||||||
#ifdef __CYBERON
|
#ifdef __CYBERON
|
||||||
|
@ -27,17 +27,13 @@
|
||||||
#ifdef VD_DEBUG
|
#ifdef VD_DEBUG
|
||||||
#define VD_LOG TRACE
|
#define VD_LOG TRACE
|
||||||
#else
|
#else
|
||||||
#define VD_LOG(...) \
|
#define VD_LOG(...) do{}while(0)
|
||||||
do { \
|
|
||||||
} while (0)
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef VD_TEST
|
#ifdef VD_TEST
|
||||||
#define VD_TRACE TRACE
|
#define VD_TRACE TRACE
|
||||||
#else
|
#else
|
||||||
#define VD_TRACE(...) \
|
#define VD_TRACE(...) do{}while(0)
|
||||||
do { \
|
|
||||||
} while (0)
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define CMD_QUEUE_DATA_SIZE 15
|
#define CMD_QUEUE_DATA_SIZE 15
|
||||||
|
@ -86,7 +82,8 @@ static void voice_detector_exec_callback(struct voice_detector_dev *pdev,
|
||||||
|
|
||||||
#define to_voice_dev(id) (&voice_det_devs[(id)])
|
#define to_voice_dev(id) (&voice_det_devs[(id)])
|
||||||
|
|
||||||
static int cmd_queue_enqueue(struct command_queue *q, int c) {
|
static int cmd_queue_enqueue(struct command_queue *q, int c)
|
||||||
|
{
|
||||||
if (q->idx >= CMD_QUEUE_DATA_SIZE) {
|
if (q->idx >= CMD_QUEUE_DATA_SIZE) {
|
||||||
VD_LOG(2, "%s, overflow cmd=%d", __func__, c);
|
VD_LOG(2, "%s, overflow cmd=%d", __func__, c);
|
||||||
return -2;
|
return -2;
|
||||||
|
@ -99,7 +96,8 @@ static int cmd_queue_enqueue(struct command_queue *q, int c) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cmd_queue_dequeue(struct command_queue *q) {
|
static int cmd_queue_dequeue(struct command_queue *q)
|
||||||
|
{
|
||||||
int cmd;
|
int cmd;
|
||||||
|
|
||||||
if (q->idx < 0) {
|
if (q->idx < 0) {
|
||||||
|
@ -118,19 +116,21 @@ static int cmd_queue_dequeue(struct command_queue *q) {
|
||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cmd_queue_is_empty(struct command_queue *q) {
|
static int cmd_queue_is_empty(struct command_queue *q)
|
||||||
|
{
|
||||||
return (q->idx < 0) ? 1 : 0;
|
return (q->idx < 0) ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void voice_detector_init_cmd_queue(struct command_queue *q) {
|
static void voice_detector_init_cmd_queue(struct command_queue *q)
|
||||||
|
{
|
||||||
if (q) {
|
if (q) {
|
||||||
q->idx = -1;
|
q->idx = -1;
|
||||||
q->out = -1;
|
q->out = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void voice_detector_init_vad(struct AUD_VAD_CONFIG_T *c, int id,
|
static void voice_detector_init_vad(struct AUD_VAD_CONFIG_T *c, int id, enum AUD_VAD_TYPE_T vad_type)
|
||||||
enum AUD_VAD_TYPE_T vad_type) {
|
{
|
||||||
if (c) {
|
if (c) {
|
||||||
c->type = vad_type;
|
c->type = vad_type;
|
||||||
#ifdef VAD_USE_8K_SAMPLE_RATE
|
#ifdef VAD_USE_8K_SAMPLE_RATE
|
||||||
|
@ -164,8 +164,8 @@ static void voice_detector_init_vad(struct AUD_VAD_CONFIG_T *c, int id,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int voice_detector_open(enum voice_detector_id id,
|
int voice_detector_open(enum voice_detector_id id, enum AUD_VAD_TYPE_T vad_type)
|
||||||
enum AUD_VAD_TYPE_T vad_type) {
|
{
|
||||||
struct voice_detector_dev *pdev;
|
struct voice_detector_dev *pdev;
|
||||||
|
|
||||||
if (id >= VOICE_DETECTOR_QTY) {
|
if (id >= VOICE_DETECTOR_QTY) {
|
||||||
|
@ -196,7 +196,8 @@ int voice_detector_open(enum voice_detector_id id,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void voice_detector_close(enum voice_detector_id id) {
|
void voice_detector_close(enum voice_detector_id id)
|
||||||
|
{
|
||||||
struct voice_detector_dev *pdev;
|
struct voice_detector_dev *pdev;
|
||||||
|
|
||||||
if (id >= VOICE_DETECTOR_QTY) {
|
if (id >= VOICE_DETECTOR_QTY) {
|
||||||
|
@ -214,7 +215,8 @@ void voice_detector_close(enum voice_detector_id id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int voice_detector_setup_vad(enum voice_detector_id id,
|
int voice_detector_setup_vad(enum voice_detector_id id,
|
||||||
struct AUD_VAD_CONFIG_T *conf) {
|
struct AUD_VAD_CONFIG_T *conf)
|
||||||
|
{
|
||||||
struct voice_detector_dev *pdev;
|
struct voice_detector_dev *pdev;
|
||||||
|
|
||||||
if (id >= VOICE_DETECTOR_QTY) {
|
if (id >= VOICE_DETECTOR_QTY) {
|
||||||
|
@ -237,8 +239,8 @@ int voice_detector_setup_vad(enum voice_detector_id id,
|
||||||
}
|
}
|
||||||
|
|
||||||
int voice_detector_setup_stream(enum voice_detector_id id,
|
int voice_detector_setup_stream(enum voice_detector_id id,
|
||||||
enum AUD_STREAM_T stream_id,
|
enum AUD_STREAM_T stream_id, struct AF_STREAM_CONFIG_T *stream)
|
||||||
struct AF_STREAM_CONFIG_T *stream) {
|
{
|
||||||
struct voice_detector_dev *pdev;
|
struct voice_detector_dev *pdev;
|
||||||
|
|
||||||
if (id >= VOICE_DETECTOR_QTY) {
|
if (id >= VOICE_DETECTOR_QTY) {
|
||||||
|
@ -261,8 +263,8 @@ int voice_detector_setup_stream(enum voice_detector_id id,
|
||||||
}
|
}
|
||||||
|
|
||||||
int voice_detector_setup_callback(enum voice_detector_id id,
|
int voice_detector_setup_callback(enum voice_detector_id id,
|
||||||
enum voice_detector_cb_id func_id,
|
enum voice_detector_cb_id func_id, voice_detector_cb_t func, void *param)
|
||||||
voice_detector_cb_t func, void *param) {
|
{
|
||||||
struct voice_detector_dev *pdev;
|
struct voice_detector_dev *pdev;
|
||||||
|
|
||||||
if (id >= VOICE_DETECTOR_QTY) {
|
if (id >= VOICE_DETECTOR_QTY) {
|
||||||
|
@ -285,8 +287,8 @@ int voice_detector_setup_callback(enum voice_detector_id id,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int voice_detector_send_cmd(enum voice_detector_id id,
|
int voice_detector_send_cmd(enum voice_detector_id id, enum voice_detector_cmd cmd)
|
||||||
enum voice_detector_cmd cmd) {
|
{
|
||||||
int r;
|
int r;
|
||||||
struct voice_detector_dev *pdev;
|
struct voice_detector_dev *pdev;
|
||||||
|
|
||||||
|
@ -300,8 +302,8 @@ int voice_detector_send_cmd(enum voice_detector_id id,
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
int voice_detector_send_cmd_array(enum voice_detector_id id, int *cmd_array,
|
int voice_detector_send_cmd_array(enum voice_detector_id id, int *cmd_array, int num)
|
||||||
int num) {
|
{
|
||||||
int r, i;
|
int r, i;
|
||||||
struct voice_detector_dev *pdev;
|
struct voice_detector_dev *pdev;
|
||||||
|
|
||||||
|
@ -319,8 +321,8 @@ int voice_detector_send_cmd_array(enum voice_detector_id id, int *cmd_array,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum voice_detector_state
|
enum voice_detector_state voice_detector_query_status(enum voice_detector_id id)
|
||||||
voice_detector_query_status(enum voice_detector_id id) {
|
{
|
||||||
struct voice_detector_dev *pdev;
|
struct voice_detector_dev *pdev;
|
||||||
|
|
||||||
if (id >= VOICE_DETECTOR_QTY) {
|
if (id >= VOICE_DETECTOR_QTY) {
|
||||||
|
@ -332,7 +334,8 @@ voice_detector_query_status(enum voice_detector_id id) {
|
||||||
return pdev->state;
|
return pdev->state;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void voice_detector_vad_callback(int found) {
|
static void voice_detector_vad_callback(int found)
|
||||||
|
{
|
||||||
struct voice_detector_dev *pdev;
|
struct voice_detector_dev *pdev;
|
||||||
enum voice_detector_id id = VOICE_DETECTOR_ID_0;
|
enum voice_detector_id id = VOICE_DETECTOR_ID_0;
|
||||||
|
|
||||||
|
@ -340,8 +343,8 @@ static void voice_detector_vad_callback(int found) {
|
||||||
|
|
||||||
pdev->wakeup_cnt++;
|
pdev->wakeup_cnt++;
|
||||||
|
|
||||||
VD_LOG(3, "%s, voice detector[%d], wakeup_cnt=%d", __func__, id,
|
VD_LOG(3, "%s, voice detector[%d], wakeup_cnt=%d",
|
||||||
pdev->wakeup_cnt);
|
__func__, id, pdev->wakeup_cnt);
|
||||||
|
|
||||||
if (pdev->wakeup_cnt == 1) {
|
if (pdev->wakeup_cnt == 1) {
|
||||||
/*
|
/*
|
||||||
|
@ -349,12 +352,12 @@ static void voice_detector_vad_callback(int found) {
|
||||||
* after CPU is waked up from sleeping.
|
* after CPU is waked up from sleeping.
|
||||||
* The VAD already can gernerates interrupts at this monment or later.
|
* The VAD already can gernerates interrupts at this monment or later.
|
||||||
*/
|
*/
|
||||||
voice_detector_exec_callback(pdev, found ? VOICE_DET_FIND_APP
|
voice_detector_exec_callback(pdev, found ? VOICE_DET_FIND_APP : VOICE_DET_NOT_FIND_APP);
|
||||||
: VOICE_DET_NOT_FIND_APP);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int voice_detector_vad_open(struct voice_detector_dev *pdev) {
|
static int voice_detector_vad_open(struct voice_detector_dev *pdev)
|
||||||
|
{
|
||||||
struct AUD_VAD_CONFIG_T *c = &pdev->conf;
|
struct AUD_VAD_CONFIG_T *c = &pdev->conf;
|
||||||
|
|
||||||
if (pdev->dfl) {
|
if (pdev->dfl) {
|
||||||
|
@ -367,7 +370,8 @@ static int voice_detector_vad_open(struct voice_detector_dev *pdev) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int voice_detector_vad_start(struct voice_detector_dev *pdev) {
|
static int voice_detector_vad_start(struct voice_detector_dev *pdev)
|
||||||
|
{
|
||||||
/* wakeup_cnt is cleared while VAD starts */
|
/* wakeup_cnt is cleared while VAD starts */
|
||||||
pdev->wakeup_cnt = 0;
|
pdev->wakeup_cnt = 0;
|
||||||
af_vad_start();
|
af_vad_start();
|
||||||
|
@ -377,7 +381,8 @@ static int voice_detector_vad_start(struct voice_detector_dev *pdev) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int voice_detector_vad_stop(struct voice_detector_dev *pdev) {
|
static int voice_detector_vad_stop(struct voice_detector_dev *pdev)
|
||||||
|
{
|
||||||
af_vad_stop();
|
af_vad_stop();
|
||||||
|
|
||||||
#ifdef I2C_VAD
|
#ifdef I2C_VAD
|
||||||
|
@ -385,8 +390,7 @@ static int voice_detector_vad_stop(struct voice_detector_dev *pdev) {
|
||||||
#else
|
#else
|
||||||
/* get vad buf info after stopping it */
|
/* get vad buf info after stopping it */
|
||||||
af_vad_get_data_info(&(pdev->vad_buf_info));
|
af_vad_get_data_info(&(pdev->vad_buf_info));
|
||||||
TRACE(4,
|
TRACE(4,"vad_buf base_addr:0x%x, buf_size:0x%x, data_count:%d, addr_count:%d",
|
||||||
"vad_buf base_addr:0x%x, buf_size:0x%x, data_count:%d, addr_count:%d",
|
|
||||||
pdev->vad_buf_info.base_addr, pdev->vad_buf_info.buf_size,
|
pdev->vad_buf_info.base_addr, pdev->vad_buf_info.buf_size,
|
||||||
pdev->vad_buf_info.data_count, pdev->vad_buf_info.addr_count);
|
pdev->vad_buf_info.data_count, pdev->vad_buf_info.addr_count);
|
||||||
#if defined(CHIP_BEST2300)
|
#if defined(CHIP_BEST2300)
|
||||||
|
@ -398,8 +402,9 @@ static int voice_detector_vad_stop(struct voice_detector_dev *pdev) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void voice_detector_get_vad_data_info(
|
void voice_detector_get_vad_data_info(enum voice_detector_id id,
|
||||||
enum voice_detector_id id, struct CODEC_VAD_BUF_INFO_T *vad_buf_info) {
|
struct CODEC_VAD_BUF_INFO_T* vad_buf_info)
|
||||||
|
{
|
||||||
|
|
||||||
struct voice_detector_dev *pdev;
|
struct voice_detector_dev *pdev;
|
||||||
|
|
||||||
|
@ -409,9 +414,11 @@ void voice_detector_get_vad_data_info(
|
||||||
vad_buf_info->buf_size = pdev->vad_buf_info.buf_size;
|
vad_buf_info->buf_size = pdev->vad_buf_info.buf_size;
|
||||||
vad_buf_info->data_count = pdev->vad_buf_info.data_count;
|
vad_buf_info->data_count = pdev->vad_buf_info.data_count;
|
||||||
vad_buf_info->addr_count = pdev->vad_buf_info.addr_count;
|
vad_buf_info->addr_count = pdev->vad_buf_info.addr_count;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int voice_detector_vad_close(struct voice_detector_dev *pdev) {
|
static int voice_detector_vad_close(struct voice_detector_dev *pdev)
|
||||||
|
{
|
||||||
#ifdef I2C_VAD
|
#ifdef I2C_VAD
|
||||||
vad_sensor_close();
|
vad_sensor_close();
|
||||||
#endif
|
#endif
|
||||||
|
@ -419,7 +426,8 @@ static int voice_detector_vad_close(struct voice_detector_dev *pdev) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int voice_detector_aud_cap_open(struct voice_detector_dev *pdev) {
|
static int voice_detector_aud_cap_open(struct voice_detector_dev *pdev)
|
||||||
|
{
|
||||||
struct AF_STREAM_CONFIG_T *conf = &pdev->cap_conf;
|
struct AF_STREAM_CONFIG_T *conf = &pdev->cap_conf;
|
||||||
|
|
||||||
if ((!conf->handler) || (!conf->data_ptr)) {
|
if ((!conf->handler) || (!conf->data_ptr)) {
|
||||||
|
@ -430,40 +438,43 @@ static int voice_detector_aud_cap_open(struct voice_detector_dev *pdev) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int voice_detector_aud_cap_start(struct voice_detector_dev *pdev) {
|
static int voice_detector_aud_cap_start(struct voice_detector_dev *pdev)
|
||||||
|
{
|
||||||
af_stream_start(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
af_stream_start(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int voice_detector_aud_cap_stop(struct voice_detector_dev *pdev) {
|
static int voice_detector_aud_cap_stop(struct voice_detector_dev *pdev)
|
||||||
|
{
|
||||||
af_stream_stop(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
af_stream_stop(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int voice_detector_aud_cap_close(struct voice_detector_dev *pdev) {
|
static int voice_detector_aud_cap_close(struct voice_detector_dev *pdev)
|
||||||
|
{
|
||||||
af_stream_close(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
af_stream_close(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int voice_detector_sys_clk(struct voice_detector_dev *pdev) {
|
static int voice_detector_sys_clk(struct voice_detector_dev *pdev)
|
||||||
|
{
|
||||||
#ifdef VD_TEST
|
#ifdef VD_TEST
|
||||||
app_sysfreq_req(APP_SYSFREQ_USER_APP_0,
|
app_sysfreq_req(APP_SYSFREQ_USER_APP_0, (enum APP_SYSFREQ_FREQ_T)(pdev->sys_clk));
|
||||||
(enum APP_SYSFREQ_FREQ_T)(pdev->sys_clk));
|
|
||||||
#else
|
#else
|
||||||
app_sysfreq_req(APP_SYSFREQ_USER_AI_VOICE,
|
app_sysfreq_req(APP_SYSFREQ_USER_AI_VOICE, (enum APP_SYSFREQ_FREQ_T)(pdev->sys_clk));
|
||||||
(enum APP_SYSFREQ_FREQ_T)(pdev->sys_clk));
|
|
||||||
#endif
|
#endif
|
||||||
// VD_TRACE(2,"%s, cpu freq=%d", __func__,
|
// VD_TRACE(2,"%s, cpu freq=%d", __func__, hal_sys_timer_calc_cpu_freq(5,0));
|
||||||
// hal_sys_timer_calc_cpu_freq(5,0));
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int voice_detector_exit(struct voice_detector_dev *pdev) {
|
static int voice_detector_exit(struct voice_detector_dev *pdev)
|
||||||
|
{
|
||||||
//TODO: exit process
|
//TODO: exit process
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int voice_detector_idle(struct voice_detector_dev *pdev) {
|
static int voice_detector_idle(struct voice_detector_dev *pdev)
|
||||||
|
{
|
||||||
//TODO: idle process
|
//TODO: idle process
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -491,8 +502,8 @@ static struct cmd_vector cmd_vectors[] = {
|
||||||
{"clk104m", VOICE_DET_CMD_SYS_CLK_104M, voice_detector_sys_clk},
|
{"clk104m", VOICE_DET_CMD_SYS_CLK_104M, voice_detector_sys_clk},
|
||||||
};
|
};
|
||||||
|
|
||||||
static int voice_detector_process_cmd(struct voice_detector_dev *pdev,
|
static int voice_detector_process_cmd(struct voice_detector_dev *pdev, int cmd)
|
||||||
int cmd) {
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
VD_LOG(3, "%s, cmd[%d]: %s", __func__, cmd, cmd_vectors[(int)cmd].name);
|
VD_LOG(3, "%s, cmd[%d]: %s", __func__, cmd, cmd_vectors[(int)cmd].name);
|
||||||
|
@ -517,12 +528,12 @@ static int voice_detector_process_cmd(struct voice_detector_dev *pdev,
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void voice_detector_set_status(struct voice_detector_dev *pdev,
|
static void voice_detector_set_status(struct voice_detector_dev *pdev, enum voice_detector_state s)
|
||||||
enum voice_detector_state s) {
|
{
|
||||||
if ((s == VOICE_DET_STATE_SYS_CLK_104M) ||
|
if ((s == VOICE_DET_STATE_SYS_CLK_104M)
|
||||||
(s == VOICE_DET_STATE_SYS_CLK_52M) ||
|
|| (s == VOICE_DET_STATE_SYS_CLK_52M)
|
||||||
(s == VOICE_DET_STATE_SYS_CLK_26M) ||
|
|| (s == VOICE_DET_STATE_SYS_CLK_26M)
|
||||||
(s == VOICE_DET_STATE_SYS_CLK_32K)) {
|
|| (s == VOICE_DET_STATE_SYS_CLK_32K)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pdev->state = s;
|
pdev->state = s;
|
||||||
|
@ -530,7 +541,8 @@ static void voice_detector_set_status(struct voice_detector_dev *pdev,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void voice_detector_exec_callback(struct voice_detector_dev *pdev,
|
static void voice_detector_exec_callback(struct voice_detector_dev *pdev,
|
||||||
enum voice_detector_cb_id id) {
|
enum voice_detector_cb_id id)
|
||||||
|
{
|
||||||
voice_detector_cb_t func;
|
voice_detector_cb_t func;
|
||||||
|
|
||||||
func = pdev->callback[id];
|
func = pdev->callback[id];
|
||||||
|
@ -541,7 +553,8 @@ static void voice_detector_exec_callback(struct voice_detector_dev *pdev,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int voice_detector_enhance_perform(enum voice_detector_id id) {
|
int voice_detector_enhance_perform(enum voice_detector_id id)
|
||||||
|
{
|
||||||
struct voice_detector_dev *pdev = to_voice_dev(id);
|
struct voice_detector_dev *pdev = to_voice_dev(id);
|
||||||
|
|
||||||
pdev->sys_clk = APP_SYSFREQ_26M;
|
pdev->sys_clk = APP_SYSFREQ_26M;
|
||||||
|
@ -550,7 +563,8 @@ int voice_detector_enhance_perform(enum voice_detector_id id) {
|
||||||
(enum APP_SYSFREQ_FREQ_T)(pdev->sys_clk));
|
(enum APP_SYSFREQ_FREQ_T)(pdev->sys_clk));
|
||||||
}
|
}
|
||||||
|
|
||||||
int voice_detector_run(enum voice_detector_id id, int continous) {
|
int voice_detector_run(enum voice_detector_id id, int continous)
|
||||||
|
{
|
||||||
int exit = 0;
|
int exit = 0;
|
||||||
int exit_code = 0;
|
int exit_code = 0;
|
||||||
struct voice_detector_dev *pdev;
|
struct voice_detector_dev *pdev;
|
||||||
|
@ -628,17 +642,24 @@ static uint32_t buff_capture[AUDIO_CAP_BUFF_SIZE / 4];
|
||||||
static uint32_t voice_det_evt = 0;
|
static uint32_t voice_det_evt = 0;
|
||||||
static uint8_t vad_data_buf[8 * 1024];
|
static uint8_t vad_data_buf[8 * 1024];
|
||||||
|
|
||||||
static void voice_detector_send_evt(uint32_t evt) { voice_det_evt = evt; }
|
static void voice_detector_send_evt(uint32_t evt)
|
||||||
|
{
|
||||||
|
voice_det_evt = evt;
|
||||||
|
}
|
||||||
|
|
||||||
static void print_vad_raw_data(uint8_t *buf, uint32_t len) {
|
static void print_vad_raw_data(uint8_t *buf, uint32_t len)
|
||||||
|
{
|
||||||
VD_TRACE(3,"%s, buf=%x, len=%d", __func__, (uint32_t)buf, len);
|
VD_TRACE(3,"%s, buf=%x, len=%d", __func__, (uint32_t)buf, len);
|
||||||
//TODO: print data
|
//TODO: print data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int State_M_1 = 0;
|
static int State_M_1 = 0;
|
||||||
void dc_filter_f(short *in, int len, float left_gain, float right_gain) {
|
void dc_filter_f(short *in, int len, float left_gain, float right_gain)
|
||||||
|
{
|
||||||
int tmp1;
|
int tmp1;
|
||||||
for (int i = 0; i < len; i += 1) {
|
for (int i = 0; i<len; i+=1)
|
||||||
|
{
|
||||||
State_M_1 = (15 * State_M_1 + in[i]) >> 4;
|
State_M_1 = (15 * State_M_1 + in[i]) >> 4;
|
||||||
tmp1 = in[i];
|
tmp1 = in[i];
|
||||||
tmp1 -= State_M_1;
|
tmp1 -= State_M_1;
|
||||||
|
@ -646,7 +667,9 @@ void dc_filter_f(short *in, int len, float left_gain, float right_gain) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t mic_data_come(uint8_t *buf, uint32_t len) {
|
|
||||||
|
static uint32_t mic_data_come(uint8_t *buf, uint32_t len)
|
||||||
|
{
|
||||||
static int come_cnt = 0;
|
static int come_cnt = 0;
|
||||||
short *p16data = (short *)buf;
|
short *p16data = (short *)buf;
|
||||||
uint32_t sample_len = len / 2;
|
uint32_t sample_len = len / 2;
|
||||||
|
@ -672,6 +695,7 @@ static uint32_t mic_data_come(uint8_t *buf, uint32_t len) {
|
||||||
TRACE(1,"CSpotter_GetResultScore return Score: %d", score);
|
TRACE(1,"CSpotter_GetResultScore return Score: %d", score);
|
||||||
|
|
||||||
CSpotter_Reset(h_CSpotter);
|
CSpotter_Reset(h_CSpotter);
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -692,7 +716,8 @@ static uint32_t mic_data_come(uint8_t *buf, uint32_t len) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __CYBERON
|
#ifdef __CYBERON
|
||||||
static int CSpotter_Init_bes() {
|
static int CSpotter_Init_bes()
|
||||||
|
{
|
||||||
#define TIMES (1000)
|
#define TIMES (1000)
|
||||||
int err;
|
int err;
|
||||||
int state_size, mem_size;
|
int state_size, mem_size;
|
||||||
|
@ -712,8 +737,7 @@ static int CSpotter_Init_bes() {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
mem_size = CSpotter_GetMemoryUsage_Sep((BYTE *)BASE_MODEL_DATA,
|
mem_size = CSpotter_GetMemoryUsage_Sep((BYTE*)BASE_MODEL_DATA, (BYTE*)COMMAND_MODEL_DATA, TIMES);
|
||||||
(BYTE *)COMMAND_MODEL_DATA, TIMES);
|
|
||||||
TRACE(1,"mem_size=%d",mem_size);
|
TRACE(1,"mem_size=%d",mem_size);
|
||||||
|
|
||||||
mem_pool = p_combuf+ cyb_buf_used;
|
mem_pool = p_combuf+ cyb_buf_used;
|
||||||
|
@ -724,9 +748,8 @@ static int CSpotter_Init_bes() {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
h_CSpotter = CSpotter_Init_Sep((BYTE *)BASE_MODEL_DATA,
|
h_CSpotter = CSpotter_Init_Sep((BYTE*)BASE_MODEL_DATA, (BYTE*)COMMAND_MODEL_DATA,
|
||||||
(BYTE *)COMMAND_MODEL_DATA, TIMES, mem_pool,
|
TIMES, mem_pool, mem_size, state_buffer, state_size, &err);
|
||||||
mem_size, state_buffer, state_size, &err);
|
|
||||||
if (!h_CSpotter) {
|
if (!h_CSpotter) {
|
||||||
TRACE(1,"CSpotter Init fail! err : %d\n", err);
|
TRACE(1,"CSpotter Init fail! err : %d\n", err);
|
||||||
err = -3;
|
err = -3;
|
||||||
|
@ -740,7 +763,8 @@ fail:
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void cmd_wait_handler(int state, void *param) {
|
static void cmd_wait_handler(int state, void *param)
|
||||||
|
{
|
||||||
voice_detector_send_evt(VOICE_DET_EVT_IDLE);
|
voice_detector_send_evt(VOICE_DET_EVT_IDLE);
|
||||||
|
|
||||||
VD_TRACE(2,"%s, state=%d", __func__, state);
|
VD_TRACE(2,"%s, state=%d", __func__, state);
|
||||||
|
@ -750,31 +774,33 @@ static void cmd_wait_handler(int state, void *param) {
|
||||||
// hal_sleep_enter_sleep();
|
// hal_sleep_enter_sleep();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_done_handler(int state, void *param) {
|
static void cmd_done_handler(int state, void *param)
|
||||||
|
{
|
||||||
VD_TRACE(2,"%s, state=%d", __func__, state);
|
VD_TRACE(2,"%s, state=%d", __func__, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cpu_det_find_wakeup_handler(int state, void *param) {
|
static void cpu_det_find_wakeup_handler(int state, void *param)
|
||||||
|
{
|
||||||
static uint32_t cpu_wakeup_cnt = 0;
|
static uint32_t cpu_wakeup_cnt = 0;
|
||||||
|
|
||||||
cpu_wakeup_cnt++;
|
cpu_wakeup_cnt++;
|
||||||
VD_TRACE(3,"%s, state=%d, cnt=%d", __func__, state, cpu_wakeup_cnt);
|
VD_TRACE(3,"%s, state=%d, cnt=%d", __func__, state, cpu_wakeup_cnt);
|
||||||
// VD_TRACE(2,"%s, calc sys freq=%d", __func__,
|
//VD_TRACE(2,"%s, calc sys freq=%d", __func__, hal_sys_timer_calc_cpu_freq(5,0));
|
||||||
// hal_sys_timer_calc_cpu_freq(5,0));
|
|
||||||
|
|
||||||
voice_detector_send_evt(VOICE_DET_EVT_AUD_CAP_START);
|
voice_detector_send_evt(VOICE_DET_EVT_AUD_CAP_START);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cpu_det_notfind_wakeup_handler(int state, void *param) {
|
static void cpu_det_notfind_wakeup_handler(int state, void *param)
|
||||||
|
{
|
||||||
|
|
||||||
VD_TRACE(2,"%s, state=%d", __func__, state);
|
VD_TRACE(2,"%s, state=%d", __func__, state);
|
||||||
// VD_TRACE(2,"%s, calc sys freq=%d", __func__,
|
//VD_TRACE(2,"%s, calc sys freq=%d", __func__, hal_sys_timer_calc_cpu_freq(5,0));
|
||||||
// hal_sys_timer_calc_cpu_freq(5,0));
|
|
||||||
|
|
||||||
voice_detector_send_evt(VOICE_DET_EVT_VAD_START);
|
voice_detector_send_evt(VOICE_DET_EVT_VAD_START);
|
||||||
}
|
}
|
||||||
|
|
||||||
void voice_detector_test(void) {
|
void voice_detector_test(void)
|
||||||
|
{
|
||||||
enum voice_detector_id id = VOICE_DETECTOR_ID_0;
|
enum voice_detector_id id = VOICE_DETECTOR_ID_0;
|
||||||
int r, run;
|
int r, run;
|
||||||
struct AF_STREAM_CONFIG_T stream_cfg;
|
struct AF_STREAM_CONFIG_T stream_cfg;
|
||||||
|
@ -810,17 +836,12 @@ void voice_detector_test(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
voice_detector_setup_stream(id, AUD_STREAM_CAPTURE, &stream_cfg);
|
voice_detector_setup_stream(id, AUD_STREAM_CAPTURE, &stream_cfg);
|
||||||
voice_detector_setup_callback(id, VOICE_DET_CB_RUN_WAIT, cmd_wait_handler,
|
voice_detector_setup_callback(id, VOICE_DET_CB_RUN_WAIT, cmd_wait_handler, NULL);
|
||||||
NULL);
|
voice_detector_setup_callback(id, VOICE_DET_CB_RUN_DONE, cmd_done_handler, NULL);
|
||||||
voice_detector_setup_callback(id, VOICE_DET_CB_RUN_DONE, cmd_done_handler,
|
voice_detector_setup_callback(id, VOICE_DET_FIND_APP, cpu_det_find_wakeup_handler, NULL);
|
||||||
NULL);
|
voice_detector_setup_callback(id, VOICE_DET_NOT_FIND_APP, cpu_det_notfind_wakeup_handler, NULL);
|
||||||
voice_detector_setup_callback(id, VOICE_DET_FIND_APP,
|
|
||||||
cpu_det_find_wakeup_handler, NULL);
|
|
||||||
voice_detector_setup_callback(id, VOICE_DET_NOT_FIND_APP,
|
|
||||||
cpu_det_notfind_wakeup_handler, NULL);
|
|
||||||
|
|
||||||
VD_TRACE(2, "%s, calc sys freq=%d", __func__,
|
VD_TRACE(2,"%s, calc sys freq=%d", __func__, hal_sys_timer_calc_cpu_freq(5,0));
|
||||||
hal_sys_timer_calc_cpu_freq(5, 0));
|
|
||||||
|
|
||||||
voice_detector_send_cmd(id, VOICE_DET_CMD_AUD_CAP_OPEN);
|
voice_detector_send_cmd(id, VOICE_DET_CMD_AUD_CAP_OPEN);
|
||||||
voice_detector_send_cmd(id, VOICE_DET_CMD_AUD_CAP_CLOSE);
|
voice_detector_send_cmd(id, VOICE_DET_CMD_AUD_CAP_CLOSE);
|
||||||
|
@ -873,8 +894,8 @@ void voice_detector_test(void) {
|
||||||
VD_TRACE(0,"wake up from deep sleep");
|
VD_TRACE(0,"wake up from deep sleep");
|
||||||
}
|
}
|
||||||
|
|
||||||
len = voice_detector_recv_vad_data(VOICE_DETECTOR_ID_0, vad_data_buf,
|
len = voice_detector_recv_vad_data(VOICE_DETECTOR_ID_0,
|
||||||
sizeof(vad_data_buf));
|
vad_data_buf, sizeof(vad_data_buf));
|
||||||
if (len) {
|
if (len) {
|
||||||
print_vad_raw_data(vad_data_buf, len);
|
print_vad_raw_data(vad_data_buf, len);
|
||||||
}
|
}
|
||||||
|
|
20
backup.sh
20
backup.sh
|
@ -1,20 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
BKPPATH="firmware-backups"
|
|
||||||
|
|
||||||
mkdir -p "$BKPPATH"
|
|
||||||
|
|
||||||
NOW=$(date +%s)
|
|
||||||
|
|
||||||
num=$(find /dev -name 'ttyACM*' | sort | rev | cut -c 1)
|
|
||||||
echo com is: "$num"
|
|
||||||
mapfile -t splitPorts <<< "$num"
|
|
||||||
echo "This tool assumes your buds are the only thing connected and are enumerated {right,left} order. YMMV"
|
|
||||||
echo "Right bud is at ${splitPorts[0]}"
|
|
||||||
echo "Left bud is at ${splitPorts[1]}"
|
|
||||||
|
|
||||||
echo "Please disconnect and reconnect the bud on the right"
|
|
||||||
bestool read-image --port "/dev/ttyACM${splitPorts[0]}" "${BKPPATH}/firmware-${NOW}-${splitPorts[0]}.bin.bkp"
|
|
||||||
|
|
||||||
echo "Please disconnect and reconnect the bud on the left"
|
|
||||||
bestool read-image --port "/dev/ttyACM${splitPorts[1]}" "${BKPPATH}/firmware-${NOW}-${splitPorts[1]}.bin.bkp"
|
|
7
build.sh
7
build.sh
|
@ -1,8 +1,9 @@
|
||||||
#!/usr/bin/env sh
|
#!/bin/bash
|
||||||
|
make -j T=open_source DEBUG=1 >log.txt 2>&1
|
||||||
|
|
||||||
if make -j "$(nproc)" T=open_source DEBUG=1 >log.txt 2>&1; then
|
if [ $? -eq 0 ]; then
|
||||||
echo "build success"
|
echo "build success"
|
||||||
else
|
else
|
||||||
echo "build failed and call log.txt"
|
echo "build failed and call log.txt"
|
||||||
grep "error:" log.txt
|
cat log.txt | grep "error:*"
|
||||||
fi
|
fi
|
||||||
|
|
5
clear.sh
5
clear.sh
|
@ -1,3 +1,2 @@
|
||||||
#!/usr/bin/env sh
|
#!/bin/bash
|
||||||
|
make T=open_source -j DEBUG=1 clean
|
||||||
make -j "$(nproc)" T=open_source DEBUG=1 clean
|
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue