├── android ├── res │ └── asound.rc ├── version.h ├── Tools.mk ├── LibasoundModuleRateSmartX.mk ├── Android.mk ├── TestSupport.mk ├── AudioCommon.mk └── SmartXAlsaPlugin.mk ├── private ├── src │ ├── samplerateconverter │ │ ├── coeffSrcFarrow │ │ │ ├── IasSrcFarrow_param_08000Hz_to_48000Hz.h │ │ │ ├── IasSrcFarrow_param_11025Hz_to_48000Hz.h │ │ │ ├── IasSrcFarrow_param_12000Hz_to_48000Hz.h │ │ │ ├── IasSrcFarrow_param_16000Hz_to_48000Hz.h │ │ │ ├── IasSrcFarrow_param_22050Hz_to_48000Hz.h │ │ │ ├── IasSrcFarrow_param_24000Hz_to_08000Hz.h │ │ │ ├── IasSrcFarrow_param_24000Hz_to_16000Hz.h │ │ │ ├── IasSrcFarrow_param_24000Hz_to_48000Hz.h │ │ │ ├── IasSrcFarrow_param_32000Hz_to_48000Hz.h │ │ │ ├── IasSrcFarrow_param_44100Hz_to_16000Hz.h │ │ │ ├── IasSrcFarrow_param_44100Hz_to_48000Hz.h │ │ │ ├── IasSrcFarrow_param_48000Hz_to_08000Hz.h │ │ │ ├── IasSrcFarrow_param_48000Hz_to_11025Hz.h │ │ │ ├── IasSrcFarrow_param_48000Hz_to_12000Hz.h │ │ │ ├── IasSrcFarrow_param_48000Hz_to_16000Hz.h │ │ │ ├── IasSrcFarrow_param_48000Hz_to_22050Hz.h │ │ │ ├── IasSrcFarrow_param_48000Hz_to_32000Hz.h │ │ │ ├── IasSrcFarrow_param_48000Hz_to_44100Hz.h │ │ │ ├── IasSrcFarrow_param_48000Hz_to_48000Hz.h │ │ │ └── IasSrcFarrow_param_48000Hz_to_24000Hz.h │ │ └── IasSrcController.cpp │ ├── helper │ │ └── IasIRunnable.cpp │ ├── common │ │ ├── IasCommonVersion.cpp │ │ ├── IasDataProbeHelper.cpp │ │ ├── IasAlsaTypeConversion.cpp │ │ ├── IasAudioLogging.cpp │ │ ├── IasIntProcCondVar.cpp │ │ ├── IasIntProcMutex.cpp │ │ └── IasAudioCommonTypes.cpp │ ├── audiobuffer │ │ ├── IasAudioRingBufferTypes.cpp │ │ ├── IasAudioRingBufferResult.cpp │ │ └── IasMetaDataFactory.cpp │ └── alsa_smartx_plugin │ │ └── IasAlsaSmartXPlugin.cpp ├── inc │ ├── helper │ │ └── version.h.in │ └── samplerateconverter │ │ └── IasSrcFarrowConfig.hpp └── res │ └── CMakeLists.txt ├── AudioCommon.pc.in ├── public ├── res │ └── 50-smartx.conf ├── inc │ ├── internal │ │ └── audio │ │ │ ├── common │ │ │ ├── IasCommonVersion.hpp │ │ │ ├── audiobuffer │ │ │ │ ├── IasAudioRingBufferTypes.hpp │ │ │ │ ├── IasAudioRingBufferResult.hpp │ │ │ │ ├── IasAudioIpcProtocolHead.hpp │ │ │ │ ├── IasAudioIpcProtocolTail.hpp │ │ │ │ ├── IasAudioIpcProtocolMacro.hpp │ │ │ │ ├── IasAudioIpcMessageContainer.hpp │ │ │ │ ├── IasAudioRingBufferMirror.hpp │ │ │ │ └── IasAudioRingBufferFactory.hpp │ │ │ ├── IasDataProbeHelper.hpp │ │ │ ├── alsa_smartx_plugin │ │ │ │ ├── IasSmartXPluginIpcStructures.hpp │ │ │ │ ├── IasAlsaPluginIpc.hpp │ │ │ │ ├── IasAlsaHwConstraintsStatic.hpp │ │ │ │ ├── IasAlsaHwConstraintsDynamic.hpp │ │ │ │ └── IasAlsaPluginShmConnection.hpp │ │ │ ├── helper │ │ │ │ ├── IasIRunnable.hpp │ │ │ │ └── IasCopyAudioAreaBuffers.hpp │ │ │ ├── IasAlsaTypeConversion.hpp │ │ │ ├── samplerateconverter │ │ │ │ ├── IasSrcWrapperBase.hpp │ │ │ │ ├── IasSrcWrapper.hpp │ │ │ │ └── IasSrcController.hpp │ │ │ ├── IasIntProcCondVar.hpp │ │ │ ├── IasFdSignal.hpp │ │ │ ├── IasIntProcMutex.hpp │ │ │ └── IasAudioLogging.hpp │ │ │ └── smartx_test_support │ │ │ ├── IasRingBufferTestWriter.hpp │ │ │ ├── IasRingBufferTestReader.hpp │ │ │ ├── IasTimeStampCounter.hpp │ │ │ ├── IasWavComp.hpp │ │ │ └── IasFilterEstimator.hpp │ └── audio │ │ └── common │ │ └── audiobuffer │ │ ├── IasMetaDataFactory.hpp │ │ └── IasMetaData.hpp └── doc │ └── 51_configuration.md ├── README.md ├── LICENSE.txt ├── CMakeLists.txt ├── CMakeLists.common_internal.txt ├── CMakeLists.common.txt └── CMakeLists.src_delivery.txt /android/res/asound.rc: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 Intel Corporation.All rights reserved. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # 5 | # ALSA library configuration file for SmartX API test 6 | # 7 | # pre-load the configuration files 8 | 9 | pcm_type.smartx { 10 | lib "libasound_module_pcm_smartx.so" 11 | } 12 | -------------------------------------------------------------------------------- /private/src/samplerateconverter/coeffSrcFarrow/IasSrcFarrow_param_08000Hz_to_48000Hz.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | // 7 | // Conversion from 8000 Hz to 48000 Hz 8 | // 9 | 10 | 64, // M, length of the impulse responses 11 | 7 // N, number of impulse responses 12 | -------------------------------------------------------------------------------- /private/src/samplerateconverter/coeffSrcFarrow/IasSrcFarrow_param_11025Hz_to_48000Hz.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | // 7 | // Conversion from 11025 Hz to 48000 Hz 8 | // 9 | 10 | 64, // M, length of the impulse responses 11 | 7 // N, number of impulse responses 12 | -------------------------------------------------------------------------------- /private/src/samplerateconverter/coeffSrcFarrow/IasSrcFarrow_param_12000Hz_to_48000Hz.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | // 7 | // Conversion from 12000 Hz to 48000 Hz 8 | // 9 | 10 | 64, // M, length of the impulse responses 11 | 7 // N, number of impulse responses 12 | -------------------------------------------------------------------------------- /private/src/samplerateconverter/coeffSrcFarrow/IasSrcFarrow_param_16000Hz_to_48000Hz.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | // 7 | // Conversion from 16000 Hz to 48000 Hz 8 | // 9 | 10 | 64, // M, length of the impulse responses 11 | 7 // N, number of impulse responses 12 | -------------------------------------------------------------------------------- /private/src/samplerateconverter/coeffSrcFarrow/IasSrcFarrow_param_22050Hz_to_48000Hz.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | // 7 | // Conversion from 22050 Hz to 48000 Hz 8 | // 9 | 10 | 64, // M, length of the impulse responses 11 | 7 // N, number of impulse responses 12 | -------------------------------------------------------------------------------- /private/src/samplerateconverter/coeffSrcFarrow/IasSrcFarrow_param_24000Hz_to_08000Hz.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | // 7 | // Conversion from 24000 Hz to 8000 Hz 8 | // 9 | 10 | 128, // M, length of the impulse responses 11 | 4 // N, number of impulse responses 12 | -------------------------------------------------------------------------------- /private/src/samplerateconverter/coeffSrcFarrow/IasSrcFarrow_param_24000Hz_to_16000Hz.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | // 7 | // Conversion from 24000 Hz to 16000 Hz 8 | // 9 | 10 | 80, // M, length of the impulse responses 11 | 6 // N, number of impulse responses 12 | -------------------------------------------------------------------------------- /private/src/samplerateconverter/coeffSrcFarrow/IasSrcFarrow_param_24000Hz_to_48000Hz.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | // 7 | // Conversion from 24000 Hz to 48000 Hz 8 | // 9 | 10 | 64, // M, length of the impulse responses 11 | 7 // N, number of impulse responses 12 | -------------------------------------------------------------------------------- /private/src/samplerateconverter/coeffSrcFarrow/IasSrcFarrow_param_32000Hz_to_48000Hz.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | // 7 | // Conversion from 32000 Hz to 48000 Hz 8 | // 9 | 10 | 64, // M, length of the impulse responses 11 | 7 // N, number of impulse responses 12 | -------------------------------------------------------------------------------- /private/src/samplerateconverter/coeffSrcFarrow/IasSrcFarrow_param_44100Hz_to_16000Hz.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | // 7 | // Conversion from 44100 Hz to 16000 Hz 8 | // 9 | 10 | 96, // M, length of the impulse responses 11 | 5 // N, number of impulse responses 12 | -------------------------------------------------------------------------------- /private/src/samplerateconverter/coeffSrcFarrow/IasSrcFarrow_param_44100Hz_to_48000Hz.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | // 7 | // Conversion from 44100 Hz to 48000 Hz 8 | // 9 | 10 | 64, // M, length of the impulse responses 11 | 7 // N, number of impulse responses 12 | -------------------------------------------------------------------------------- /private/src/samplerateconverter/coeffSrcFarrow/IasSrcFarrow_param_48000Hz_to_08000Hz.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | // 7 | // Conversion from 48000 Hz to 8000 Hz 8 | // 9 | 10 | 128, // M, length of the impulse responses 11 | 4 // N, number of impulse responses 12 | -------------------------------------------------------------------------------- /private/src/samplerateconverter/coeffSrcFarrow/IasSrcFarrow_param_48000Hz_to_11025Hz.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | // 7 | // Conversion from 48000 Hz to 11025 Hz 8 | // 9 | 10 | 96, // M, length of the impulse responses 11 | 4 // N, number of impulse responses 12 | -------------------------------------------------------------------------------- /private/src/samplerateconverter/coeffSrcFarrow/IasSrcFarrow_param_48000Hz_to_12000Hz.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | // 7 | // Conversion from 48000 Hz to 12000 Hz 8 | // 9 | 10 | 96, // M, length of the impulse responses 11 | 4 // N, number of impulse responses 12 | -------------------------------------------------------------------------------- /private/src/samplerateconverter/coeffSrcFarrow/IasSrcFarrow_param_48000Hz_to_16000Hz.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | // 7 | // Conversion from 48000 Hz to 16000 Hz 8 | // 9 | 10 | 96, // M, length of the impulse responses 11 | 5 // N, number of impulse responses 12 | -------------------------------------------------------------------------------- /private/src/samplerateconverter/coeffSrcFarrow/IasSrcFarrow_param_48000Hz_to_22050Hz.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | // 7 | // Conversion from 48000 Hz to 22050 Hz 8 | // 9 | 10 | 80, // M, length of the impulse responses 11 | 5 // N, number of impulse responses 12 | -------------------------------------------------------------------------------- /private/src/samplerateconverter/coeffSrcFarrow/IasSrcFarrow_param_48000Hz_to_32000Hz.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | // 7 | // Conversion from 48000 Hz to 32000 Hz 8 | // 9 | 10 | 80, // M, length of the impulse responses 11 | 6 // N, number of impulse responses 12 | -------------------------------------------------------------------------------- /private/src/samplerateconverter/coeffSrcFarrow/IasSrcFarrow_param_48000Hz_to_44100Hz.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | // 7 | // Conversion from 48000 Hz to 44100 Hz 8 | // 9 | 10 | 64, // M, length of the impulse responses 11 | 7 // N, number of impulse responses 12 | -------------------------------------------------------------------------------- /private/src/samplerateconverter/coeffSrcFarrow/IasSrcFarrow_param_48000Hz_to_48000Hz.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | // 7 | // Conversion from 48000 Hz to 48000 Hz 8 | // 9 | 10 | 48, // M, length of the impulse responses 11 | 7 // N, number of impulse responses 12 | -------------------------------------------------------------------------------- /private/src/samplerateconverter/coeffSrcFarrow/IasSrcFarrow_param_48000Hz_to_24000Hz.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | // 7 | // Conversion from 48000 Hz to 24000 Hz 8 | // 9 | 10 | 80, // M, length of the impulse responses 11 | 5 // N, number of impulse responses 12 | -------------------------------------------------------------------------------- /AudioCommon.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=@CMAKE_INSTALL_PREFIX@ 3 | libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@ 4 | includedir=${exec_prefix}/include 5 | 6 | Name: AVB-AudioModules 7 | Description: Common audio modules 8 | Version: @AUDIO_COMMON_VERSION_STRING@ 9 | Requires: 10 | Libs: -L${libdir} -lias-audio-common 11 | Cflags: -I${includedir}/avbaudiomodules 12 | -------------------------------------------------------------------------------- /private/src/helper/IasIRunnable.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | /** 7 | * @file 8 | */ 9 | 10 | #include "internal/audio/common/helper/IasIRunnable.hpp" 11 | 12 | namespace IasAudio 13 | { 14 | 15 | IasIRunnable::IasIRunnable() 16 | { 17 | 18 | } 19 | 20 | IasIRunnable::~IasIRunnable() 21 | { 22 | 23 | } 24 | 25 | }; 26 | -------------------------------------------------------------------------------- /android/version.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | 6 | */ 7 | 8 | #define AUDIO_COMMON_VERSION_MAJOR 4 /**< major number of library version */ 9 | #define AUDIO_COMMON_VERSION_MINOR 1 /**< minor number of library version */ 10 | #define AUDIO_COMMON_VERSION_REVISION 0 /**< subminor number of library version */ 11 | 12 | /** library version (string) */ 13 | #define VERSION_STRING "4.1.0" 14 | -------------------------------------------------------------------------------- /public/res/50-smartx.conf: -------------------------------------------------------------------------------- 1 | # Generic template for all ALSA <-> SmartXbar plugins 2 | # Can be used to dynamically create an ALSA to SmartXbar adapter by using it like this: 3 | # aplay -Dsmartx:MyNewDev ~/Music/ 4 | 5 | pcm.smartx { 6 | @args [ NAME ] 7 | @args.NAME { 8 | type string 9 | } 10 | type smartx 11 | name $NAME 12 | } 13 | 14 | # The same plugin is used for avb but with a different prefix. 15 | # Is has to be used like this: 16 | # aplay -Davb:MyNewDev ~/Music/ 17 | pcm.avb = pcm.smartx 18 | 19 | -------------------------------------------------------------------------------- /private/src/common/IasCommonVersion.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | /** 7 | * @file IasCommonVersion.cpp 8 | * @date 2017 9 | * @brief Get the version string of the ias-audio-common lib 10 | */ 11 | 12 | #include "internal/audio/common/IasCommonVersion.hpp" 13 | #include "version.h" 14 | 15 | namespace IasAudio { 16 | 17 | const char* getLibCommonVersion() 18 | { 19 | return VERSION_STRING; 20 | } 21 | 22 | 23 | } /* namespace IasAudio */ 24 | -------------------------------------------------------------------------------- /private/inc/helper/version.h.in: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | /** 7 | * @file 8 | */ 9 | #ifndef ${VERSION_H_INCLUDE_GUARD} 10 | #define ${VERSION_H_INCLUDE_GUARD} 11 | 12 | #define VERSION_MAJOR ${CURRENT_VERSION_MAJOR} 13 | #define VERSION_MINOR ${CURRENT_VERSION_MINOR} 14 | #define VERSION_REVISON ${CURRENT_VERSION_REVISION} 15 | 16 | #define VERSION_STRING "${CURRENT_VERSION_MAJOR}.${CURRENT_VERSION_MINOR}.${CURRENT_VERSION_REVISION}" 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /public/inc/internal/audio/common/IasCommonVersion.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | /** 7 | * @file IasCommonVersion.hpp 8 | * @date 2017 9 | * @brief Get the version string of the ias-audio-common lib 10 | */ 11 | 12 | #ifndef IASCOMMONVERSION_HPP_ 13 | #define IASCOMMONVERSION_HPP_ 14 | 15 | 16 | namespace IasAudio { 17 | 18 | __attribute__ ((visibility ("default"))) const char* getLibCommonVersion(); 19 | 20 | } /* namespace IasAudio */ 21 | 22 | 23 | 24 | #endif /* IASCOMMONVERSION_HPP_ */ 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | DISCONTINUATION OF PROJECT 2 | 3 | This project will no longer be maintained by Intel. 4 | 5 | Intel has ceased development and contributions including, but not limited to, maintenance, bug fixes, new releases, or updates, to this project. 6 | 7 | Intel no longer accepts patches to this project. 8 | 9 | If you have an ongoing need to use this project, are interested in independently developing it, or would like to maintain patches for the open source software community, please create your own fork of this project. 10 | 11 | Contact: webadmin@linux.intel.com 12 | # AVB-AudioModules 13 | 14 | Instruction for installation in Clearlinux 15 | 16 | 1. mkdir build & cd build 17 | 2. cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_INSTALL_LIBDIR=/usr/lib64 ../ 18 | 3. make 19 | 4. sudo make install 20 | -------------------------------------------------------------------------------- /android/Tools.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | 6 | include $(CLEAR_VARS) 7 | 8 | LOCAL_C_INCLUDES := \ 9 | $(LOCAL_PATH)/../private/inc/tools 10 | 11 | LOCAL_SRC_FILES := \ 12 | ../private/src/tools/latency/IasAlsa.cpp \ 13 | ../private/src/tools/latency/IasDelayMeasurement.cpp \ 14 | ../private/src/tools/latency/IasLatency.cpp \ 15 | ../private/src/tools/latency/main.cpp 16 | 17 | LOCAL_STATIC_LIBRARIES := \ 18 | libtbb \ 19 | liblog 20 | 21 | LOCAL_SHARED_LIBRARIES := \ 22 | libias-audio-common \ 23 | libias-core_libraries-foundation \ 24 | libias-core_libraries-base \ 25 | libdlt \ 26 | libias-core_libraries-command_line_parser \ 27 | libcutils \ 28 | libasound 29 | 30 | LOCAL_CFLAGS := $(IAS_COMMON_CFLAGS) -Wall -Wextra -Werror -Wpointer-arith 31 | 32 | LOCAL_CLANG := true 33 | 34 | LOCAL_MODULE := audio_latency_module_tools 35 | LOCAL_CLANG := true 36 | 37 | include $(BUILD_EXECUTABLE) 38 | -------------------------------------------------------------------------------- /android/LibasoundModuleRateSmartX.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | # 5 | 6 | include $(CLEAR_VARS) 7 | 8 | LOCAL_MODULE := libasound_module_rate_smartx 9 | LOCAL_PROPRIETARY_MODULE := true 10 | LOCAL_MODULE_OWNER := intel 11 | LOCAL_MODULE_TAGS := optional 12 | LOCAL_CLANG := true 13 | 14 | LOCAL_SRC_FILES := ../private/src/samplerateconverter/IasAlsa.cpp 15 | 16 | LOCAL_C_INCLUDES := \ 17 | $(LOCAL_PATH)/../public/inc \ 18 | $(LOCAL_PATH)/../private/inc/alsa_smartx_plugin \ 19 | bionic 20 | 21 | LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/../public/inc/ 22 | 23 | LOCAL_STATIC_LIBRARIES := \ 24 | libtbb 25 | 26 | LOCAL_SHARED_LIBRARIES := \ 27 | libias-android-pthread \ 28 | libasound \ 29 | libias-audio-common \ 30 | libias-core_libraries-foundation \ 31 | libias-core_libraries-base \ 32 | libdlt 33 | 34 | LOCAL_CFLAGS := $(IAS_COMMON_CFLAGS) -frtti -fexceptions -Werror -Wpointer-arith 35 | 36 | include $(BUILD_SHARED_LIBRARY) 37 | -------------------------------------------------------------------------------- /private/src/audiobuffer/IasAudioRingBufferTypes.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | /** 7 | * @file IasAudioRingBufferTypes.cpp 8 | * @date 2016 9 | * @brief 10 | */ 11 | 12 | #include "internal/audio/common/audiobuffer/IasAudioRingBufferTypes.hpp" 13 | 14 | namespace IasAudio{ 15 | 16 | #define STRING_RETURN_CASE(name) case name: return std::string(#name); break 17 | #define DEFAULT_STRING(name) default: return std::string(name) 18 | 19 | __attribute__ ((visibility ("default"))) std::string toString(const IasAudioRingBufferStreamingState& type) 20 | { 21 | switch(type) 22 | { 23 | STRING_RETURN_CASE(eIasRingBuffStreamingStateUndefined); 24 | STRING_RETURN_CASE(eIasRingBuffStreamingStateRunning); 25 | STRING_RETURN_CASE(eIasRingBuffStreamingStateStopWrite); 26 | STRING_RETURN_CASE(eIasRingBuffStreamingStateStopRead); 27 | DEFAULT_STRING("Unknown Error"); 28 | } 29 | } 30 | 31 | #undef STRING_RETURN_CASE 32 | #undef DEFAULT_STRING 33 | } 34 | -------------------------------------------------------------------------------- /public/doc/51_configuration.md: -------------------------------------------------------------------------------- 1 | # Configuration 2 | 3 | ## User ID and Group ID 4 | 5 | The audio related components like e.g. the SmartXbar or the avb_streamhandler create some files during runtime, like e.g. named pipes. To limit the access to these files, the user id *ias\_audio* and the corresponding group id *ias\_audio* are introduced by the ias-audio-common-config package. 6 | The user id, that is used to start audio applications, like e.g. a media player, has to be added to the group *ias\_audio* for being able to access the files created by the SmartXbar or the avb_streamhandler. 7 | 8 | ## The Runtime Directory 9 | 10 | The runtime directory /run/smartx for hosting the named pipes is also created by the ias-audio-common-config package. The user and group id of this directory is set to *ias\_audio*. The *GUID* flag is set, so that everything created below this directory will inherit the group id *ias\_audio*. 11 | 12 | To create the runtime directory, the systemd tmpfile functionality is used. This part is located in the meta-ias-audio layer in the recipe ias-audio-common-config.bb. -------------------------------------------------------------------------------- /public/inc/internal/audio/common/audiobuffer/IasAudioRingBufferTypes.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | /** 7 | * @file IasAudioRingBufferTypes.hpp 8 | * @date 2016 9 | * @brief Type definitions for IasAudioRingBuffer, IasAudioRingBufferReal, and IasAudioRingBufferMirror objects. 10 | */ 11 | 12 | #ifndef IASAUDIORINGBUFFERTYPES_HPP_ 13 | #define IASAUDIORINGBUFFERTYPES_HPP_ 14 | 15 | #include "audio/common/IasAudioCommonTypes.hpp" 16 | 17 | namespace IasAudio { 18 | 19 | /* 20 | * Streaming state of a ring buffer (only supported by real buffers). 21 | */ 22 | enum IasAudioRingBufferStreamingState 23 | { 24 | eIasRingBuffStreamingStateUndefined = 0, //!< not defined, e.g., in case of a mirror buffer 25 | eIasRingBuffStreamingStateRunning, //!< it is possible to write into and to write from the buffer 26 | eIasRingBuffStreamingStateStopWrite, //!< write accesses are blocked (PCM frames are discarded) 27 | eIasRingBuffStreamingStateStopRead //!< read accesses are blocked (no PCM frames are provided) 28 | }; 29 | 30 | std::string toString(const IasAudioRingBufferStreamingState& type); 31 | 32 | } 33 | #endif 34 | -------------------------------------------------------------------------------- /public/inc/internal/audio/common/audiobuffer/IasAudioRingBufferResult.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | /** 7 | * @file IasAudioRingBufferResult.hpp 8 | * @date 2015 9 | * @brief 10 | */ 11 | 12 | #ifndef IASAUDIORINGBUFFERRESULT_HPP_ 13 | #define IASAUDIORINGBUFFERRESULT_HPP_ 14 | 15 | #include "audio/common/IasAudioCommonTypes.hpp" 16 | 17 | namespace IasAudio { 18 | 19 | enum IasAudioRingBufferResult 20 | { 21 | eIasRingBuffOk = 0, //!< Success 22 | eIasRingBuffInvalidParam, //!< Invalid parameter 23 | eIasRingBuffNotInitialized, //!< Not initialized 24 | eIasRingBuffAlsaError, //!< general ALSA error 25 | eIasRingBuffAlsaXrunError, //!< XRUN recovery failed 26 | eIasRingBuffAlsaSuspendError, //!< SUSPEND recovery failed 27 | eIasRingBuffNotAllowed, //!< Not allowed here 28 | eIasRingBuffInvalidSampleSize, //!< Invalid sample size 29 | eIasRingBuffTimeOut, //!< timeout exceeded 30 | eIasRingBuffProbeError, //!< Probe error 31 | eIasRingBuffCondWaitFailed, //!< Cond wait failed 32 | }; 33 | 34 | std::string toString(const IasAudioRingBufferResult& type); 35 | 36 | } 37 | #endif 38 | -------------------------------------------------------------------------------- /private/res/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 Intel Corporation. All rights reserved. 2 | # 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | set( AUDIO_COMMON_VERSION_MAJOR 4 ) 6 | set( AUDIO_COMMON_VERSION_MINOR 0 ) 7 | set( AUDIO_COMMON_VERSION_REVISION 0 ) 8 | 9 | include( CMakeLists.common.txt ) 10 | 11 | IasCreateComponentDocumentation( audio common ${AUDIO_COMMON_VERSION_MAJOR} ${AUDIO_COMMON_VERSION_MINOR} ${AUDIO_COMMON_VERSION_REVISION} 12 | common 13 | ) 14 | 15 | IasCreateBbRecipeFile(audio ias-audio-common ${AUDIO_COMMON_VERSION_MAJOR} ${AUDIO_COMMON_VERSION_MINOR} ${AUDIO_COMMON_VERSION_REVISION} 16 | SUMMARY "Audio - Common" 17 | DESCRIPTION "Common Audio components" 18 | GROUP "Multimedia/Audio" 19 | YOCTO_LAYER meta-ias-audio 20 | YOCTO_RECIPE_FOLDER recipes-multimedia/common 21 | YOCTO_GEN_EXTRA_FLAGS NO_BINBB NO_SRC 22 | PACKAGE ias-audio-common 23 | PACKAGE_SUMMARY "Common Audio components" 24 | PACKAGE_DESCRIPTION "Common Audio components used by SmartXbar" 25 | PACKAGE_ENTITIES common 26 | PACKAGE_ENTITIES alsa_smartx_plugin 27 | PACKAGE_ENTITIES libasound_module_rate_smartx 28 | PACKAGE_BUILD_REQUIRES alsa-lib 29 | PACKAGE_BUILD_REQUIRES libsndfile1 30 | PACKAGE_BUILD_REQUIRES tbb 31 | PACKAGE_BUILD_REQUIRES boost 32 | ) 33 | -------------------------------------------------------------------------------- /private/src/audiobuffer/IasAudioRingBufferResult.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | /** 7 | * @file IasAudioRingBufferResult.cpp 8 | * @date 2015 9 | * @brief 10 | */ 11 | 12 | #include "internal/audio/common/audiobuffer/IasAudioRingBufferResult.hpp" 13 | 14 | namespace IasAudio{ 15 | 16 | #define STRING_RETURN_CASE(name) case name: return std::string(#name); break 17 | #define DEFAULT_STRING(name) default: return std::string(name) 18 | 19 | __attribute__ ((visibility ("default"))) std::string toString(const IasAudioRingBufferResult& type) 20 | { 21 | switch(type) 22 | { 23 | STRING_RETURN_CASE(eIasRingBuffOk); 24 | STRING_RETURN_CASE(eIasRingBuffInvalidParam); 25 | STRING_RETURN_CASE(eIasRingBuffNotInitialized); 26 | STRING_RETURN_CASE(eIasRingBuffAlsaError); 27 | STRING_RETURN_CASE(eIasRingBuffAlsaXrunError); 28 | STRING_RETURN_CASE(eIasRingBuffAlsaSuspendError); 29 | STRING_RETURN_CASE(eIasRingBuffNotAllowed); 30 | STRING_RETURN_CASE(eIasRingBuffInvalidSampleSize); 31 | STRING_RETURN_CASE(eIasRingBuffTimeOut); 32 | STRING_RETURN_CASE(eIasRingBuffProbeError); 33 | STRING_RETURN_CASE(eIasRingBuffCondWaitFailed); 34 | DEFAULT_STRING("Unknown Error"); 35 | } 36 | } 37 | 38 | #undef STRING_RETURN_CASE 39 | #undef DEFAULT_STRING 40 | } 41 | -------------------------------------------------------------------------------- /public/inc/internal/audio/common/IasDataProbeHelper.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | /** 7 | * @file IasDataProbeHelper.hpp 8 | * @date 2016 9 | * @brief 10 | */ 11 | 12 | #ifndef IASDATAPROBEHELPER_HPP_ 13 | #define IASDATAPROBEHELPER_HPP_ 14 | 15 | 16 | #include "audio/common/IasAudioCommonTypes.hpp" 17 | #include "internal/audio/common/IasAudioLogging.hpp" 18 | #include "internal/audio/common/IasDataProbe.hpp" 19 | #include 20 | 21 | namespace IasAudio { 22 | 23 | /** 24 | * @brief Data probe helper methods to ease the usage of the data probe 25 | */ 26 | 27 | namespace IasDataProbeHelper { 28 | 29 | __attribute__ ((visibility ("default"))) IasDataProbe::IasResult processQueueEntry(IasProbingQueueEntry &entry, 30 | IasDataProbePtr* probe, 31 | uint32_t probingBufferSize); 32 | 33 | __attribute__ ((visibility ("default"))) IasDataProbe::IasResult processQueueEntry(IasProbingQueueEntry &entry, 34 | IasDataProbePtr* probe, 35 | std::atomic *probingActive, 36 | uint32_t probingBufferSize); 37 | 38 | 39 | } 40 | 41 | } 42 | #endif 43 | -------------------------------------------------------------------------------- /private/inc/samplerateconverter/IasSrcFarrowConfig.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | /** 7 | * @file IasSrcFarrowConfig.hpp 8 | * @brief Configuration parameters for the sample rate converter 9 | * based on Farrow's structure. These parameters are processed 10 | * at compile time. 11 | * @date 2015 12 | */ 13 | 14 | #ifndef IASSRCFARROWCONFIG_HPP_ 15 | #define IASSRCFARROWCONFIG_HPP_ 16 | 17 | /* 18 | * Define for SSE optimization code 19 | */ 20 | #define IASSRCFARROWCONFIG_USE_SSE 1 21 | 22 | 23 | /* 24 | * Define whether float to int conversions shall saturate. 25 | * If this flag is not set, the behavior in case of overmodulation is 26 | * undefined, i.e., it might wrap-around or saturate or anything else. 27 | */ 28 | #define IASSRCFARROWCONFIG_USE_SATURATION 1 29 | 30 | 31 | /* Define the output gain, i.e., the factor that shall be applied to the 32 | * output signal. If the output signal shall be converted to fixed point, 33 | * this gain factor is applied before the conversion is done. 34 | * 35 | * This factor is applied even if the output signal shall be provided in 36 | * floating point format. 37 | * 38 | * The specified value is a linear factor (not in dB). 39 | */ 40 | #define IASSRCFARROWCONFIG_OUTPUT_GAIN (0.891250938f) 41 | 42 | 43 | #endif // IASSRCFARROWCONFIG_HPP_ 44 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (C) 2018 Intel Corporation. All rights reserved. 2 | 3 | SPDX-License-Identifier: BSD-3-Clause 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification,are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 3. Neither the name of the copyright holder nor the names of its 14 | contributors may be used to endorse or promote products derived from this 15 | software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 27 | OF THE POSSIBILITY OF SUCH DAMAGE 28 | -------------------------------------------------------------------------------- /public/inc/internal/audio/common/audiobuffer/IasAudioIpcProtocolHead.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | /** 8 | * @file IasAudioIpcProtocolHead.hpp 9 | * @date Oct 5, 2015 10 | * @version 0.1 11 | * @brief Can be used to build own protocol. 12 | * 13 | * Use the IasAudioIpcProtocolHead to start a protocol definition. 14 | * Before this including head and tail the IAS_AUDIO_IPC_MESSAGE_SIZE 15 | * and the IAS_AUDIO_IPC_QUEUE_SIZE must be set. 16 | * 17 | * #include "SomeOwnInclude.hpp" 18 | * 19 | * //Define the sizes first 20 | * #define IAS_AUDIO_IPC_MESSAGE_SIZE 100 21 | * #define IAS_AUDIO_IPC_QUEUE_SIZE 100 22 | * 23 | * // Include the start header 24 | * #include "audio/audiobuffer/IasAudioIpcProtocolHead.hpp" 25 | * 26 | * 27 | * 28 | * // ############################################################ 29 | * // IPC ID Definition Section 30 | * // Define any fixed size structure without heap memory here. 31 | * // For Template Arguments a typedef is required 32 | * // Example: ADD_IPC_ID(Ias::CLASS, 1234) 33 | * 34 | * 35 | * 36 | * 37 | * // END IPC ID Definition Section 38 | * // ############################################################# 39 | * 40 | * 41 | * 42 | * To end the protocol definition, use the tail include. 43 | * 44 | * #include "audio/audiobuffer/IasAudioIpcProtocolTail.hpp" 45 | * 46 | * NOTE: 47 | * o The Macro GET_IPC_ID(classname) is provided by the procotol, and is a compile time variable. 48 | * Zero is the unvalid id. 49 | * o All interface functions can be found in IasAudioIpc.hpp. 50 | * 51 | */ 52 | 53 | //Include the used macros and the base wrapper class. 54 | #include "IasAudioIpcProtocolMacro.hpp" 55 | 56 | namespace IasAudio { // Get the definitions in the correct namespace 57 | -------------------------------------------------------------------------------- /public/inc/internal/audio/common/audiobuffer/IasAudioIpcProtocolTail.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | /** 8 | * @file IasAudioIpcProtocolTail.hpp 9 | * @date Oct 5, 2015 10 | * @version 0.1 11 | * @brief Can be used to build own protocol. 12 | * 13 | * Use the IasAudioIpcProtocolHead to start a protocol definition. 14 | * Before this including head and tail the IAS_AUDIO_IPC_MESSAGE_SIZE 15 | * and the IAS_AUDIO_IPC_QUEUE_SIZE must be set. 16 | * 17 | * #include "SomeOwnInclude.hpp" 18 | * 19 | * //Define the sizes first 20 | * #define IAS_AUDIO_IPC_MESSAGE_SIZE 100 21 | * #define IAS_AUDIO_IPC_QUEUE_SIZE 100 22 | * 23 | * // Include the start header 24 | * #include "audio/audiobuffer/IasAudioIpcProtocolHead.hpp" 25 | * 26 | * 27 | * 28 | * // ############################################################ 29 | * // IPC ID Definition Section 30 | * // Define any fixed size structure without heap memory here. 31 | * // For Template Arguments a typedef is required 32 | * // Example: ADD_IPC_ID(Ias::CLASS, 1234) 33 | * 34 | * 35 | * 36 | * 37 | * // END IPC ID Definition Section 38 | * // ############################################################# 39 | * 40 | * 41 | * 42 | * To end the protocol definition, use the tail include. 43 | * 44 | * #include "audio/audiobuffer/IasAudioIpcProtocolTail.hpp" 45 | * 46 | * NOTE: 47 | * o The Macro GET_IPC_ID(classname) is provided by the procotol, and is a compile time variable. 48 | * Zero is the unvalid id. 49 | * o All interface functions can be found in IasAudioIpc.hpp. 50 | * 51 | */ 52 | 53 | } //Closes the namespace IasAudio. 54 | 55 | // undef unrequired macros 56 | #undef ADD_IPC_ID 57 | 58 | // include the message container with crc and message ids. 59 | #include "IasAudioIpcMessageContainer.hpp" 60 | 61 | // Include the ipc class. 62 | #include "IasAudioIpc.hpp" 63 | 64 | -------------------------------------------------------------------------------- /public/inc/internal/audio/common/audiobuffer/IasAudioIpcProtocolMacro.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | /** 8 | * @file IasAudioIpcProtocolMacro.hpp 9 | * @date Sep 23, 2015 10 | * @version 0.2 11 | * @brief Defines a protocol use by the IPC communication. The Head Macros and wrapper Strucuture. Also Opens a namespace IasAudio. 12 | * WARNING: Use the IasAudioIpcProtocolHead.hpp and IasAudioIpcProtocolTail.hpp 13 | */ 14 | #ifndef IASAUDIOIPCPROTOCOL_HPP_ 15 | #define IASAUDIOIPCPROTOCOL_HPP_ 16 | 17 | /* 18 | * System Includes 19 | */ 20 | #include 21 | 22 | /* 23 | * BOOST Includes 24 | */ 25 | #include 26 | 27 | /* 28 | * Ias Includes 29 | */ 30 | 31 | 32 | /* 33 | * IPC Includes 34 | */ 35 | 36 | 37 | #ifndef IAS_AUDIO_IPC_MESSAGE_SIZE 38 | #error The IAS_AUDIO_IPC_MESSAGE_SIZE is not defined. 39 | #endif 40 | 41 | namespace IasAudio{ 42 | 43 | /** 44 | * IasIpcId type is for internal use. 45 | */ 46 | typedef uint32_t IasIpcId; 47 | 48 | /** 49 | * Will be specialized with the different types. Compile error if not specified. 50 | */ 51 | template 52 | static IasIpcId getIpcId(); 53 | 54 | /** 55 | * This Macro is used to make a class IPC capable. With the classname and a unique id, 56 | * The class can be sent over the IPC. Zero is a non valid id. The macro will check if the 57 | * Message size is bigger than the maximum 58 | */ 59 | #define ADD_IPC_ID(classname, id)\ 60 | static_assert(sizeof(classname) <= IAS_AUDIO_IPC_MESSAGE_SIZE,\ 61 | "Class #classname is too large for the protocol Message size");\ 62 | static_assert(id, "Class ipc id is zero:"#classname);\ 63 | template<>\ 64 | IasIpcId getIpcId()\ 65 | {\ 66 | return id;\ 67 | } 68 | 69 | /** 70 | * Macro returns the type number of a specific class. 71 | */ 72 | #define GET_IPC_ID(classname) \ 73 | getIpcId() 74 | 75 | } 76 | 77 | #endif /* IASAUDIOIPCPROTOCOL_HPP_ */ 78 | -------------------------------------------------------------------------------- /public/inc/internal/audio/smartx_test_support/IasRingBufferTestWriter.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | /* 7 | * IasRingBufferTestWriter.hpp 8 | * 9 | * Created 2015 10 | */ 11 | 12 | #ifndef IASRINGBUFFERTESTWRITER_HPP_ 13 | #define IASRINGBUFFERTESTWRITER_HPP_ 14 | 15 | 16 | #include "audio/common/IasAudioCommonTypes.hpp" 17 | 18 | #include 19 | 20 | namespace IasAudio 21 | { 22 | 23 | class IasAudioRingBuffer; 24 | 25 | class __attribute__ ((visibility ("default"))) IasRingBufferTestWriter 26 | { 27 | 28 | public: 29 | 30 | IasRingBufferTestWriter(IasAudioRingBuffer* buffer, 31 | uint32_t periodSize, 32 | uint32_t numChannels, 33 | IasAudioCommonDataFormat dataType, 34 | std::string fileName); 35 | 36 | 37 | ~IasRingBufferTestWriter(); 38 | 39 | IasAudioCommonResult init(); 40 | 41 | IasAudioCommonResult writeToBuffer(uint32_t chanIdx); 42 | 43 | 44 | private: 45 | 46 | IasRingBufferTestWriter(IasRingBufferTestWriter const &other); 47 | 48 | IasRingBufferTestWriter& operator=(IasRingBufferTestWriter const &other); 49 | 50 | IasAudioCommonResult read( uint32_t* numReadSamples, int16_t* readDest); 51 | 52 | IasAudioCommonResult read( uint32_t* numReadSamples, int32_t* readDest); 53 | 54 | IasAudioCommonResult read( uint32_t* numReadSamples, float* readDest); 55 | 56 | template< typename T> 57 | IasAudioCommonResult copy( uint32_t numSamples, uint32_t chanIdx); 58 | 59 | IasAudioRingBuffer* mRingBuffer; 60 | uint32_t mPeriodSize; 61 | uint32_t mNumChannels; 62 | int32_t mSampleSize; 63 | IasAudioCommonDataFormat mDataType; 64 | void* mWriteBuf; 65 | SNDFILE* mDataFile; 66 | IasAudioArea* mAreas; 67 | uint32_t mNumBufferChannels; 68 | std::string mFileName; 69 | bool mInitialized; 70 | uint64_t mSamplesReadFromFile; 71 | 72 | }; 73 | 74 | } 75 | #endif 76 | -------------------------------------------------------------------------------- /android/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 Intel Corporation.All rights reserved. 2 | 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | #--------------------------------------------------------------------------------------------------- 6 | # Android Version Constants definition: 7 | # Redefine here android version in order to be able to use equality, greater than, etc.. rules. 8 | # Use 9 | # ANDROID_VERSION_ to provide the adaption 10 | # 11 | # You can use the conditional expressions rules as: 12 | # ifeq ("$(shell [ $(ANDROID_VERSION) -gt $(ANDROID_N) ] && echo true)", "true") 13 | #--------------------------------------------------------------------------------------------------- 14 | ANDROID_M := 6 15 | ANDROID_N := 7 16 | ANDROID_O := 8 17 | 18 | ANDROID_VERSION_6 := $(ANDROID_M) 19 | ANDROID_VERSION_7 := $(ANDROID_N) 20 | ANDROID_VERSION_8 := $(ANDROID_O) 21 | ANDROID_VERSION_O := $(ANDROID_O) 22 | ANDROID_VERSION_OMR1 := $(ANDROID_O) 23 | 24 | ANDROID_SUPPORTED_VERSIONS := 6 7 O 8 OMR1 25 | 26 | #------------------------------------------------------------------ 27 | # Determining Android version of current build 28 | # first letter may be major version or may be the dessert letter... 29 | #------------------------------------------------------------------ 30 | PLATFORM_VERSION_FIRST_LETTER := $(word 1, $(subst ., ,$(PLATFORM_VERSION))) 31 | 32 | $(info "PLATFORM_VERSION $(PLATFORM_VERSION)") 33 | $(info "PLATFORM_VERSION_FIRST_LETTER $(PLATFORM_VERSION_FIRST_LETTER)") 34 | 35 | $(foreach item, $(ANDROID_SUPPORTED_VERSIONS),\ 36 | $(if $(call streq,$(PLATFORM_VERSION_FIRST_LETTER),$(item)),\ 37 | $(eval ANDROID_VERSION := $(ANDROID_VERSION_$(item))),)) 38 | 39 | $(if $(ANDROID_VERSION),$(info "ANDROID_VERSION $(ANDROID_VERSION)"),\ 40 | $(error Unsupported Android version)) 41 | 42 | ####################################################################### 43 | 44 | LOCAL_PATH := $(call my-dir) 45 | 46 | include $(LOCAL_PATH)/AudioCommon.mk 47 | 48 | include $(LOCAL_PATH)/SmartXAlsaPlugin.mk 49 | 50 | include $(LOCAL_PATH)/Tools.mk 51 | 52 | include $(LOCAL_PATH)/LibasoundModuleRateSmartX.mk 53 | 54 | #include $(LOCAL_PATH)/TestSupport.mk 55 | 56 | #include $(LOCAL_PATH)/test/Android.mk 57 | -------------------------------------------------------------------------------- /public/inc/internal/audio/smartx_test_support/IasRingBufferTestReader.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | /* 7 | * IasRingBufferTestReader.hpp 8 | * 9 | * Created 2015 10 | */ 11 | 12 | #ifndef IASRINGBUFFERTESTREADER_HPP_ 13 | #define IASRINGBUFFERTESTREADER_HPP_ 14 | 15 | #include "internal/audio/common/audiobuffer/IasAudioRingBuffer.hpp" 16 | 17 | #include 18 | 19 | 20 | 21 | namespace IasAudio 22 | { 23 | class IasAudioRingBuffer; 24 | 25 | class __attribute__ ((visibility ("default"))) IasRingBufferTestReader 26 | { 27 | public: 28 | 29 | IasRingBufferTestReader(IasAudioRingBuffer* buffer, 30 | uint32_t periodSize, 31 | uint32_t numChannels, 32 | IasAudioCommonDataFormat dataType, 33 | std::string fileName); 34 | 35 | ~IasRingBufferTestReader(); 36 | 37 | IasAudioCommonResult init(); 38 | 39 | IasAudioCommonResult readFromBuffer(uint32_t chanIdx); 40 | 41 | 42 | private: 43 | 44 | IasRingBufferTestReader(IasRingBufferTestReader const &other); 45 | 46 | IasRingBufferTestReader& operator=(IasRingBufferTestReader const &other); 47 | 48 | template 49 | IasAudioCommonResult copy( uint32_t numSamples, uint32_t chanIdx); 50 | 51 | 52 | IasAudioCommonResult write(sf_count_t* numWrittenSamples,int32_t* src); 53 | 54 | IasAudioCommonResult write(sf_count_t* numWrittenSamples,int16_t* src); 55 | 56 | IasAudioCommonResult write(sf_count_t* numWrittenSamples,float* src); 57 | 58 | IasAudioRingBuffer *mRingBuffer; 59 | uint32_t mPeriodSize; 60 | uint32_t mNumChannels; 61 | int32_t mSampleSize; 62 | IasAudioCommonDataFormat mDataType; 63 | void* mReadBuf; 64 | SNDFILE* mDataFile; 65 | IasAudioArea* mAreas; 66 | uint32_t mNumBufferChannels; 67 | std::string mFileName; 68 | bool mInitialized; 69 | uint64_t mSamplesWrittenToFile; 70 | 71 | 72 | }; 73 | 74 | } 75 | #endif 76 | -------------------------------------------------------------------------------- /public/inc/internal/audio/common/alsa_smartx_plugin/IasSmartXPluginIpcStructures.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | /** 8 | * @file IasSmartXPluginIpcStructures.hpp 9 | * @date Oct 5, 2015 10 | * @version 0.1 11 | * @brief Defines the structures that are transfered between the smartx and the smartx alsa plugin via ipc. 12 | */ 13 | #ifndef IAS_SMARTXPLUGIN_IPCSTRUCTURES_HPP_ 14 | #define IAS_SMARTXPLUGIN_IPCSTRUCTURES_HPP_ 15 | 16 | 17 | #include "audio/common/IasAudioCommonTypes.hpp" 18 | 19 | namespace IasAudio { 20 | 21 | /** 22 | * @brief This Structure defines possible IPC communication commands. 23 | */ 24 | enum IasAudioIpcPluginControl 25 | { 26 | eIasAudioIpcInvalid = -1, 27 | eIasAudioIpcNAK, 28 | eIasAudioIpcACK, 29 | eIasAudioIpcGetLatency, 30 | eIasAudioIpcStart, 31 | eIasAudioIpcPause, 32 | eIasAudioIpcResume, 33 | eIasAudioIpcStop, 34 | eIasAudioIpcDrain, 35 | eIasAudioIpcParameters 36 | }; 37 | 38 | /** 39 | * @brief toString method for IasAudioIpcPluginControl 40 | * 41 | * @param[in] type Enum value of IasAudioIpcPluginControl 42 | * 43 | * @return Type as string 44 | */ 45 | std::string toString(const IasAudioIpcPluginControl &type); 46 | 47 | /** 48 | * @brief Structure to tell the smartx which parameters has been chosen. 49 | * 50 | */ 51 | struct IasAudioCurrentSetParameters 52 | { 53 | uint32_t numChannels; 54 | uint32_t sampleRate; 55 | uint32_t periodSize; 56 | uint32_t numPeriods; 57 | IasAudioCommonDataFormat dataFormat; 58 | }; 59 | 60 | 61 | 62 | /** 63 | * @brief A Common container for response messages. Will contain the actual command plus the response package. 64 | * for further types see in the IPC definition. 65 | * 66 | */ 67 | template 68 | struct IasAudioIpcPluginControlData 69 | { 70 | IasAudioIpcPluginControlData(): 71 | control(eIasAudioIpcInvalid) 72 | {;} 73 | 74 | IasAudioIpcPluginControlData(IasAudioIpcPluginControl type, ContainedType theResponse): 75 | control(type), 76 | response(theResponse) 77 | {;} 78 | 79 | IasAudioIpcPluginControl control; 80 | ContainedType response; 81 | }; 82 | 83 | } 84 | 85 | #endif /* IAS_SMARTXPLUGIN_IPCSTRUCTURES_HPP_ */ 86 | -------------------------------------------------------------------------------- /private/src/audiobuffer/IasMetaDataFactory.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | /** 7 | * @file IasMetaDataFactory.cpp 8 | * @date 2015 9 | * @brief This is a wrapper for the IasUserMetaDataFactory template class 10 | * 11 | * It has to be provided as source code to allow definition of user-defined data struct 12 | */ 13 | 14 | #include "audio/common/audiobuffer/IasMetaDataFactory.hpp" 15 | #include "audio/common/audiobuffer/IasMetaData.hpp" 16 | #include "audio/common/audiobuffer/IasUserMetaDataFactory.hpp" 17 | 18 | namespace IasAudio { 19 | 20 | struct IasUserMetaData 21 | { 22 | IasMetaDataHeader header; // mUserFactory; 39 | }; 40 | 41 | IasMetaDataFactory::IasMetaDataFactory(IasMemoryAllocator *memAlloc) 42 | :mInternal(new IasMetaDataFactoryInternal(memAlloc)) 43 | { 44 | //Nothing to do here 45 | } 46 | 47 | IasMetaDataFactory::~IasMetaDataFactory() 48 | { 49 | delete mInternal; 50 | } 51 | 52 | IasAudioCommonResult IasMetaDataFactory::create(const std::string &name, uint32_t nrBuffers, IasMetaData **metaData) 53 | { 54 | return mInternal->mUserFactory.create(name, nrBuffers, metaData); 55 | } 56 | 57 | IasAudioCommonResult IasMetaDataFactory::destroy(IasMetaData *metaData) 58 | { 59 | return mInternal->mUserFactory.destroy(metaData); 60 | } 61 | 62 | IasAudioCommonResult IasMetaDataFactory::find(const std::string &name, uint32_t *nrBuffers, IasMetaData **metaData) const 63 | { 64 | return mInternal->mUserFactory.find(name, nrBuffers, metaData); 65 | } 66 | 67 | uint32_t IasMetaDataFactory::getSize(uint32_t nrBuffers) 68 | { 69 | return static_cast(nrBuffers * sizeof(IasUserMetaData) + nrBuffers * sizeof(IasMetaData)); 70 | } 71 | 72 | 73 | 74 | } // namespace IasAudio 75 | -------------------------------------------------------------------------------- /public/inc/internal/audio/common/helper/IasIRunnable.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | /** 7 | * @file 8 | */ 9 | 10 | #ifndef _IAS_IRUNNABLE_HPP 11 | #define _IAS_IRUNNABLE_HPP 12 | 13 | #include "audio/common/IasAudioCommonTypes.hpp" 14 | 15 | /** 16 | * @brief IasAudio 17 | */ 18 | namespace IasAudio 19 | { 20 | 21 | /** 22 | * @brief IRunnable interface for usage with the IasThread. 23 | */ 24 | class IAS_AUDIO_PUBLIC IasIRunnable 25 | { 26 | public: 27 | 28 | /** 29 | * Constructor. 30 | */ 31 | IasIRunnable(); 32 | 33 | /** 34 | * Destructor. 35 | */ 36 | virtual ~IasIRunnable(); 37 | 38 | /** 39 | * Function called before the run function. 40 | * 41 | * @returns Value indicating success or failure. 42 | */ 43 | virtual IasAudioCommonResult beforeRun() = 0; 44 | 45 | /** 46 | * The actual run function, does the processing. 47 | * 48 | * Stay inside the function until all processing is finished or shutDown is called. 49 | * If this call returns an error value, this error value is reported via the return value of \ref IasThread::start(). 50 | * In case of an error, the thread still needs to be shutdown explicitly through calling \ref IasThread::stop(). 51 | * 52 | * @returns Value indicating success or failure. 53 | * 54 | * @note This value can be accessed through \ref IasThread::getRunThreadResult. 55 | */ 56 | virtual IasAudioCommonResult run() = 0; 57 | 58 | /** 59 | * ShutDown code, 60 | * called when thread is going to be terminated. 61 | * 62 | * Exit the \ref run function when this function is called. 63 | * 64 | * @returns Value indicating success or failure. 65 | * 66 | */ 67 | virtual IasAudioCommonResult shutDown() = 0; 68 | 69 | /** 70 | * Function called after the run function. 71 | * 72 | * @returns Value indicating success or failure. 73 | * 74 | * If this call returns an error value and run() was successful, it is reported via the return value of IasThread::stop(). 75 | */ 76 | virtual IasAudioCommonResult afterRun() = 0; 77 | 78 | 79 | }; 80 | 81 | }; //namespace IasAudio 82 | 83 | 84 | #endif /* _IAS_IRUNNABLE_HPP_ */ 85 | -------------------------------------------------------------------------------- /public/inc/internal/audio/smartx_test_support/IasTimeStampCounter.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | /** 7 | * @file IasTimeStampCounter.hpp 8 | * @brief Time Stamp Counter, based on rdtsc, to be used for performance optimizations. 9 | * @date May 06, 2013 10 | */ 11 | 12 | #ifndef IASTIMESTAMPCOUNTER_HPP_ 13 | #define IASTIMESTAMPCOUNTER_HPP_ 14 | 15 | 16 | 17 | namespace IasAudio { 18 | 19 | 20 | /** 21 | * @brief Private inline function to get the current time stamp (rdtsc) 22 | */ 23 | inline uint32_t getTimeStamp() 24 | { 25 | uint32_t tsc=0; 26 | 27 | __asm__ volatile( 28 | "rdtsc;" 29 | "movl %%eax, %0;" 30 | : "=r" (tsc) 31 | : "0" (tsc) 32 | : "%eax", "%edx" 33 | ); 34 | return tsc; 35 | } 36 | 37 | 38 | /** 39 | * @brief Private inline function to get the current time stamp (rdtsc), 64 bit version 40 | */ 41 | inline uint64_t getTimeStamp64(void) 42 | { 43 | uint32_t a, d; 44 | 45 | __asm__ volatile("rdtsc" : "=a" (a), "=d" (d)); 46 | 47 | return (((uint64_t)a) | (((uint64_t)d) << 32)); 48 | } 49 | 50 | 51 | class IasTimeStampCounter 52 | { 53 | public: 54 | /** 55 | * @brief Constructor. 56 | */ 57 | IasTimeStampCounter() { mTimeStampStart = getTimeStamp(); }; 58 | 59 | /** 60 | * @brief Destructor, virtual by default. 61 | */ 62 | virtual ~IasTimeStampCounter() {}; 63 | 64 | /** 65 | * @brief reset() method -> starts a new measurement. 66 | */ 67 | void reset() { mTimeStampStart = static_cast(getTimeStamp()); }; 68 | 69 | /** 70 | * @brief get() method -> gets the number of (rdtsc) clock ticks since the last reset. 71 | */ 72 | uint32_t get() { return (getTimeStamp() - mTimeStampStart); }; 73 | 74 | 75 | private: 76 | /** 77 | * @brief Copy constructor, private unimplemented to prevent misuse. 78 | */ 79 | IasTimeStampCounter(IasTimeStampCounter const &other); 80 | 81 | /** 82 | * @brief Assignment operator, private unimplemented to prevent misuse. 83 | */ 84 | IasTimeStampCounter& operator=(IasTimeStampCounter const &other); 85 | 86 | // Member variables 87 | uint32_t mTimeStampStart; ///< The rdtsc time stamp when the reset() method was called. 88 | }; 89 | 90 | 91 | 92 | } // namespace IasAudio 93 | 94 | 95 | #endif // IASTIMESTAMPCOUNTER_HPP_ 96 | -------------------------------------------------------------------------------- /private/src/alsa_smartx_plugin/IasAlsaSmartXPlugin.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | /** 7 | * @file IasAlsaSmartXPlugin.cpp 8 | * @date 20 Sep. 2015 9 | * @brief Interface that is loaded by the alsa library dl-loader. 10 | * Communicates with the a common shared memory audio ring buffer. 11 | */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #include "audio/common/IasAudioCommonTypes.hpp" 20 | #include "alsa_smartx_plugin/IasAlsaSmartXConnector.hpp" 21 | #include "internal/audio/common/IasAudioLogging.hpp" 22 | 23 | /** 24 | * Plugin Export Function 25 | */ 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | __attribute__ ((visibility ("default"))) SND_PCM_PLUGIN_DEFINE_FUNC(smartx) 30 | { 31 | // Not used 32 | (void)root; 33 | int err = 0; 34 | 35 | char *dbgLvl = getenv("DBG_LVL"); 36 | if (dbgLvl != nullptr && strlen(dbgLvl) <=1) 37 | { 38 | IasAudio::IasAudioLogging::addDltContextItem("SXP", (DltLogLevelType)std::stoul(dbgLvl), DLT_TRACE_STATUS_ON); 39 | IasAudio::IasAudioLogging::addDltContextItem("SHM", (DltLogLevelType)std::stoul(dbgLvl), DLT_TRACE_STATUS_ON); 40 | } 41 | 42 | IasAudio::IasAlsaSmartXConnector* smartXConnector; 43 | smartXConnector = new IasAudio::IasAlsaSmartXConnector(); 44 | IAS_ASSERT(smartXConnector != nullptr); 45 | if(smartXConnector->loadConfig(conf) == -EINVAL) 46 | { 47 | delete smartXConnector; 48 | return -EINVAL; 49 | } 50 | if((err = smartXConnector->init(name, stream, mode))) 51 | { 52 | snd_pcm_t *pcm = smartXConnector->getPCMHandle(); 53 | if (pcm != nullptr) 54 | { 55 | // In case the ioplug was already created we have a pcm handle. 56 | // Closing this handle will automatically free the memory of our smartXConnector 57 | snd_pcm_close(pcm); 58 | } 59 | else 60 | { 61 | // In case we got an error before creating the pcm handle we have to free the memory 62 | // here explicitly. 63 | delete smartXConnector; 64 | } 65 | return err; 66 | } 67 | 68 | IAS_ASSERT(smartXConnector->getPCMHandle() != nullptr); 69 | *pcmp = smartXConnector->getPCMHandle(); 70 | 71 | char *dbgId = getenv("DBG_ID"); 72 | if (dbgId != nullptr && strlen(dbgId) <=4) 73 | { 74 | DLT_REGISTER_APP(dbgId, "SmartX Plugin"); 75 | DLT_VERBOSE_MODE(); 76 | } 77 | return 0; 78 | 79 | } 80 | 81 | __attribute__ ((visibility ("default"))) SND_PCM_PLUGIN_SYMBOL(smartx) 82 | 83 | #ifdef __cplusplus 84 | } 85 | #endif 86 | -------------------------------------------------------------------------------- /android/TestSupport.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | # 5 | 6 | include $(CLEAR_VARS) 7 | 8 | LOCAL_C_INCLUDES := \ 9 | $(LOCAL_EXPORT_C_INCLUDE_DIRS) \ 10 | $(LOCAL_PATH)/../public/inc \ 11 | $(LOCAL_PATH)/../private/inc \ 12 | bionic 13 | 14 | LOCAL_SRC_FILES := \ 15 | ../private/src/smartx_test_support/shm_test_support_processes/IasPipeMessage.cpp \ 16 | ../private/src/smartx_test_support/IasFftFunctions.cpp \ 17 | ../private/src/smartx_test_support/IasRingBufferTestWriter.cpp \ 18 | ../private/src/smartx_test_support/IasRingBufferTestReader.cpp \ 19 | ../private/src/smartx_test_support/IasWavComp.cpp \ 20 | ../private/src/smartx_test_support/IasFilterEstimator.cpp \ 21 | ../private/src/smartx_test_support/IasThdnEstimator.cpp 22 | 23 | LOCAL_MODULE := libias-audio-smartx_test_support 24 | LOCAL_MODULE_OWNER := intel 25 | LOCAL_MODULE_TAGS := optional 26 | LOCAL_CLANG := true 27 | 28 | LOCAL_SHARED_LIBRARIES:= \ 29 | libasound \ 30 | libias-audio-common \ 31 | libias-android-pthread \ 32 | libias-core_libraries-base \ 33 | libias-core_libraries-foundation \ 34 | libsndfile-1.0.27 \ 35 | libdlt 36 | 37 | LOCAL_STATIC_LIBRARIES:= \ 38 | libboost \ 39 | libboost_serialization 40 | 41 | LOCAL_CFLAGS := $(IAS_COMMON_CFLAGS) -msse -msse2 -frtti -fexceptions -Werror \ 42 | -Wpointer-arith 43 | 44 | include $(BUILD_SHARED_LIBRARY) 45 | 46 | 47 | ####################################################################### 48 | # Client Application for shared memory test 49 | ####################################################################### 50 | include $(CLEAR_VARS) 51 | 52 | LOCAL_C_INCLUDES := \ 53 | $(LOCAL_PATH)/../public/inc/internal/audio \ 54 | $(LOCAL_PATH)/../private/inc \ 55 | bionic 56 | 57 | LOCAL_SRC_FILES := \ 58 | ../private/src/smartx_test_support/shm_test_support_processes/IasShmClientProcess.cpp 59 | 60 | LOCAL_STATIC_LIBRARIES := \ 61 | liblog \ 62 | libtbb \ 63 | libboost 64 | 65 | LOCAL_SHARED_LIBRARIES := \ 66 | libias-audio-common \ 67 | libias-audio-smartx_test_support \ 68 | libias-core_libraries-foundation \ 69 | libias-core_libraries-test_support \ 70 | libias-core_libraries-command_line_parser \ 71 | libias-core_libraries-base \ 72 | libdlt \ 73 | libsndfile-1.0.27 \ 74 | libasound 75 | 76 | ifeq ("$(shell [ $(ANDROID_VERSION) -eq $(ANDROID_M) ] && echo true)", "true") 77 | BOOST_SHARED_FOLDER := /mnt/eavb/misc/media/ 78 | else 79 | BOOST_SHARED_FOLDER := /mnt/eavb/misc/audioserver/ 80 | endif 81 | 82 | LOCAL_CFLAGS := $(IAS_COMMON_CFLAGS) \ 83 | -Wall -Wextra -Werror -Wpointer-arith \ 84 | -frtti -fexceptions \ 85 | -DBOOST_INTERPROCESS_SHARED_DIR_PATH=\"$(BOOST_SHARED_FOLDER)\" 86 | 87 | LOCAL_MODULE := ias_shm_client_process 88 | LOCAL_CLANG := true 89 | 90 | include $(BUILD_EXECUTABLE) 91 | -------------------------------------------------------------------------------- /private/src/common/IasDataProbeHelper.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | /** 7 | * @file IasDataProbeHelper.cpp 8 | * @date 2016 9 | * @brief 10 | */ 11 | 12 | 13 | #include "internal/audio/common/IasDataProbeHelper.hpp" 14 | // #define IAS_ASSERT() 15 | 16 | namespace IasAudio { 17 | 18 | namespace IasDataProbeHelper { 19 | 20 | IasDataProbe::IasResult processQueueEntry(IasProbingQueueEntry &entry, 21 | IasDataProbePtr* probe, 22 | uint32_t probingBufferSize) 23 | { 24 | std::atomic probingActive(false); 25 | return processQueueEntry(entry, probe, &probingActive, probingBufferSize); 26 | } 27 | 28 | IasDataProbe::IasResult processQueueEntry(IasProbingQueueEntry &entry, 29 | IasDataProbePtr* probe, 30 | std::atomic *probingActive, 31 | uint32_t probingBufferSize) 32 | { 33 | IAS_ASSERT(probingActive != nullptr); 34 | IasDataProbe::IasResult probeRes; 35 | 36 | if (entry.action == eIasProbingStart) 37 | { 38 | if (*probe == nullptr) 39 | { 40 | *probe = std::make_shared(); 41 | IAS_ASSERT(*probe != nullptr); 42 | if (entry.params.isInject) 43 | { 44 | 45 | probeRes = (*probe)->startInject(entry.params.name, 46 | entry.params.numChannels, 47 | entry.params.sampleRate, 48 | entry.params.dataFormat, 49 | entry.params.startIndex, 50 | probingBufferSize, 51 | entry.params.duration); 52 | } 53 | else 54 | { 55 | probeRes = (*probe)->startRecording(entry.params.name, 56 | entry.params.numChannels, 57 | entry.params.sampleRate, 58 | entry.params.dataFormat, 59 | entry.params.startIndex, 60 | probingBufferSize, 61 | entry.params.duration); 62 | } 63 | if(probeRes == IasDataProbe::eIasOk) 64 | { 65 | probingActive->store(true); 66 | } 67 | else 68 | { 69 | *probe = nullptr; 70 | return probeRes; 71 | } 72 | } 73 | else 74 | { 75 | return IasDataProbe::eIasAlreadyStarted; 76 | } 77 | } 78 | else 79 | { 80 | if(*probe != nullptr) 81 | { 82 | (*probe)->stop(); 83 | probingActive->store(false); 84 | *probe = nullptr; 85 | } 86 | } 87 | return IasDataProbe::eIasOk; 88 | } 89 | 90 | 91 | } 92 | } 93 | 94 | 95 | -------------------------------------------------------------------------------- /android/AudioCommon.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 Intel Corporation.All rights reserved. 2 | 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | include $(CLEAR_VARS) 6 | 7 | LOCAL_MODULE := libias-audio-common 8 | LOCAL_PROPRIETARY_MODULE := true 9 | LOCAL_MODULE_OWNER := intel 10 | LOCAL_MODULE_TAGS := optional 11 | LOCAL_CLANG := true 12 | LOCAL_HEADER_LIBRARIES += libutils_headers 13 | LOCAL_SRC_FILES := \ 14 | ../private/src/common/IasAlsaTypeConversion.cpp \ 15 | ../private/src/common/IasAudioCommonTypes.cpp \ 16 | ../private/src/common/IasAudioLogging.cpp \ 17 | ../private/src/common/IasDataProbe.cpp \ 18 | ../private/src/common/IasDataProbeHelper.cpp \ 19 | ../private/src/common/IasIntProcCondVar.cpp \ 20 | ../private/src/common/IasIntProcMutex.cpp \ 21 | ../private/src/common/IasFdSignal.cpp \ 22 | ../private/src/common/IasCommonVersion.cpp 23 | 24 | LOCAL_SRC_FILES += \ 25 | ../private/src/alsa_smartx_plugin/IasAlsaPluginShmConnection.cpp 26 | 27 | LOCAL_SRC_FILES += \ 28 | ../private/src/audiobuffer/IasMemoryAllocator.cpp \ 29 | ../private/src/audiobuffer/IasMetaDataFactory.cpp \ 30 | ../private/src/audiobuffer/IasAudioRingBuffer.cpp \ 31 | ../private/src/audiobuffer/IasAudioRingBufferTypes.cpp \ 32 | ../private/src/audiobuffer/IasAudioRingBufferResult.cpp \ 33 | ../private/src/audiobuffer/IasAudioRingBufferReal.cpp \ 34 | ../private/src/audiobuffer/IasAudioRingBufferMirror.cpp \ 35 | ../private/src/audiobuffer/IasAudioRingBufferFactory.cpp 36 | 37 | LOCAL_SRC_FILES += \ 38 | ../private/src/samplerateconverter/IasSrcController.cpp \ 39 | ../private/src/samplerateconverter/IasSrcFarrow.cpp \ 40 | ../private/src/samplerateconverter/IasSrcFarrowFirFilter.cpp \ 41 | ../private/src/samplerateconverter/IasSrcWrapper.cpp 42 | 43 | LOCAL_SRC_FILES += \ 44 | ../private/src/helper/IasCopyAudioAreaBuffers.cpp 45 | 46 | LOCAL_C_INCLUDES := \ 47 | $(LOCAL_PATH)/../public/inc \ 48 | $(LOCAL_PATH)/../private/inc \ 49 | bionic 50 | 51 | LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/../public/inc 52 | 53 | LOCAL_STATIC_LIBRARIES := \ 54 | libtbb \ 55 | libboost \ 56 | libboost_system \ 57 | libboost_filesystem 58 | 59 | LOCAL_SHARED_LIBRARIES := \ 60 | libias-android-pthread \ 61 | libcutils \ 62 | libasound \ 63 | libias-core_libraries-foundation \ 64 | libias-core_libraries-base \ 65 | libsndfile-1.0.27 \ 66 | libdlt \ 67 | liblog 68 | 69 | FD_SIGNAL_PATH := /run/smartx/ 70 | 71 | LOCAL_CFLAGS := $(IAS_COMMON_CFLAGS) \ 72 | -frtti -fexceptions -msse -msse2 -Werror -Wpointer-arith \ 73 | -DFD_SIGNAL_PATH=\"/mnt/eavb/misc$(FD_SIGNAL_PATH)\" 74 | 75 | ifeq ("$(shell [ $(ANDROID_VERSION) -eq $(ANDROID_M) ] && echo true)", "true") 76 | BOOST_SHARED_FOLDER := /mnt/eavb/misc/media/ 77 | else 78 | BOOST_SHARED_FOLDER := /mnt/eavb/misc/audioserver/ 79 | endif 80 | 81 | LOCAL_CFLAGS += \ 82 | -DBOOST_INTERPROCESS_SHARED_DIR_PATH=\"$(BOOST_SHARED_FOLDER)\" \ 83 | -DSHM_ROOT_PATH=\"$(BOOST_SHARED_FOLDER)\" 84 | 85 | include $(BUILD_SHARED_LIBRARY) 86 | -------------------------------------------------------------------------------- /public/inc/internal/audio/common/alsa_smartx_plugin/IasAlsaPluginIpc.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | /** 8 | * @file IasAlsaPluginIpc.hpp 9 | * @date Oct 5, 2015 10 | * @version 0.1 11 | * @brief Defines the IPC Protocol between the alsa smartx plugin and the smartx 12 | */ 13 | #ifndef IAS_ASLAPLUGINIPC_HPP_ 14 | #define IAS_ASLAPLUGINIPC_HPP_ 15 | 16 | #include "IasSmartXPluginIpcStructures.hpp" 17 | 18 | #define IAS_AUDIO_IPC_MESSAGE_SIZE 100 19 | #define IAS_AUDIO_IPC_QUEUE_SIZE 100 20 | 21 | #include "internal/audio/common/audiobuffer/IasAudioIpcProtocolHead.hpp" 22 | // ############################################################ 23 | // IPC ID Definition Section 24 | // Define any fixed size structure without heap memory here. 25 | // For Template Arguments a typedef is required 26 | // Example: ADD_IPC_ID(Ias::CLASS, 1234) 27 | 28 | 29 | /* 30 | * IPC Traffic between the Alsa SmartX Plugin and the SmartX . 31 | */ 32 | ADD_IPC_ID(IasAudioIpcPluginControl, 1); 33 | 34 | /* 35 | * Contains one floating point with one control type information. 36 | */ 37 | using IasAudioIpcPluginFloatData = IasAudio::IasAudioIpcPluginControlData; 38 | ADD_IPC_ID(IasAudioIpcPluginFloatData, 2); 39 | 40 | 41 | /* 42 | * Dummy function to avoid compiler warning "unused function" 43 | */ 44 | inline void dummyCallControl(){(void)GET_IPC_ID(IasAudioIpcPluginControl);}; 45 | 46 | 47 | /* 48 | * Dummy function to avoid compiler warning "unused function" 49 | */ 50 | inline void dummyCallFloat(){(void)GET_IPC_ID(IasAudioIpcPluginFloatData);}; 51 | 52 | /* 53 | * Contains one 32bit integer with one control type information. 54 | */ 55 | using IasAudioIpcPluginInt32Data = IasAudio::IasAudioIpcPluginControlData; 56 | ADD_IPC_ID(IasAudioIpcPluginInt32Data, 3); 57 | 58 | /* 59 | * Dummy function to avoid compiler warning "unused function" 60 | */ 61 | inline void dummyCallInt32(){(void)GET_IPC_ID(IasAudioIpcPluginInt32Data);}; 62 | 63 | /* 64 | * Contains the parameter data with one control type information. 65 | */ 66 | using IasAudioIpcPluginParamData = IasAudio::IasAudioIpcPluginControlData; 67 | ADD_IPC_ID(IasAudioIpcPluginParamData, 4); 68 | 69 | /* 70 | * Dummy function to avoid compiler warning "unused function" 71 | */ 72 | inline void dummyCallParam(){(void)GET_IPC_ID(IasAudioIpcPluginParamData);}; 73 | 74 | /* 75 | * Contains the response of a control, which is also represented by a control. 76 | */ 77 | using IasAudioIpcPluginControlResponse = IasAudio::IasAudioIpcPluginControlData; 78 | ADD_IPC_ID(IasAudioIpcPluginControlResponse, 5); 79 | 80 | /* 81 | * Dummy function to avoid compiler warning "unused function" 82 | */ 83 | inline void dummyCallResponse(){(void)GET_IPC_ID(IasAudioIpcPluginControlResponse);}; 84 | 85 | // END IPC ID Definition Section 86 | // ############################################################# 87 | 88 | #include "internal/audio/common/audiobuffer/IasAudioIpcProtocolTail.hpp" 89 | 90 | #endif /* IAS_ASLAPLUGINIPC_HPP_ */ 91 | -------------------------------------------------------------------------------- /public/inc/audio/common/audiobuffer/IasMetaDataFactory.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | /** 7 | * @file IasMetaDataFactory.hpp 8 | * @date 2015 9 | * @brief 10 | */ 11 | 12 | #ifndef IASMETADATAFACTORY_HPP_ 13 | #define IASMETADATAFACTORY_HPP_ 14 | 15 | 16 | #include "audio/common/IasAudioCommonTypes.hpp" 17 | #include "audio/common/audiobuffer/IasMetaData.hpp" 18 | 19 | namespace IasAudio { 20 | 21 | class IasMemoryAllocator; 22 | 23 | class IasMetaDataFactory 24 | { 25 | public: 26 | /** 27 | * @brief Constructor. 28 | * @param[in] memAlloc Pointer to memory allocator instance to use 29 | */ 30 | IasMetaDataFactory(IasMemoryAllocator *memAlloc); 31 | 32 | /** 33 | * @brief Destructor, virtual by default. 34 | */ 35 | virtual ~IasMetaDataFactory(); 36 | 37 | /** 38 | * Create meta data buffers 39 | * 40 | * @param[in] name Name of the meta data array 41 | * @param[in] nrBuffers The number of meta data buffers to create 42 | * @param[in,out] metaData The created buffers are returned via an array ptr 43 | * @return The result of creating the buffers 44 | * @retval cOk Ok 45 | * @retval cInvalidParam Invalid parameter 46 | * @retval cMemoryError Could not allocate memory 47 | */ 48 | IasAudioCommonResult create(const std::string &name, uint32_t nrBuffers, IasMetaData **metaData); 49 | 50 | /** 51 | * Destroy the previously created meta data buffers 52 | * @param[in] metaData Pointer to an array containing the meta data buffers 53 | * @return The result of destroying the buffers 54 | * @retval cOk Ok 55 | * @retval cInvalidParam Invalid parameter 56 | */ 57 | IasAudioCommonResult destroy(IasMetaData *metaData); 58 | 59 | /** 60 | * Find meta data buffers created by the server side 61 | * 62 | * @param[in] name Name of the meta data buffer object(s) 63 | * @param[in,out] nrBuffers Returns number of buffers in meta data array 64 | * @param[in,out] metaData Returns pointer to meta data buffer(s) 65 | */ 66 | IasAudioCommonResult find(const std::string &name, uint32_t *nrBuffers, IasMetaData **metaData) const; 67 | 68 | /** 69 | * Get the size in bytes required to allocate nrBuffers of meta data 70 | * @param[in] nrBuffers The number of meta data buffers 71 | * @return The size in bytes required to allocate nrBuffers of meta data 72 | */ 73 | static uint32_t getSize(uint32_t nrBuffers); 74 | 75 | private: 76 | /** 77 | * @brief Copy constructor, private unimplemented to prevent misuse. 78 | */ 79 | IasMetaDataFactory(IasMetaDataFactory const &other); 80 | 81 | /** 82 | * @brief Assignment operator, private unimplemented to prevent misuse. 83 | */ 84 | IasMetaDataFactory& operator=(IasMetaDataFactory const &other); 85 | 86 | // Member variables 87 | struct IasMetaDataFactoryInternal; // 21 | 22 | /* 23 | * Common 24 | */ 25 | #include "audio/common/IasAudioCommonTypes.hpp" 26 | 27 | namespace IasAudio { 28 | 29 | 30 | /** 31 | * @brief Function to convert between Ias and Alsa. Channel count from Ias to Alsa. 32 | * 33 | * @param in Ias Channel count to convert. 34 | * @return unsigned int Channel Count for Alsa. 35 | */ 36 | __attribute__ ((visibility ("default"))) unsigned int convertChannelCountIasToAlsa(const IasAudioCommonChannelCount& in); 37 | 38 | /** 39 | * @brief Function to convert between Ias and Alsa. Channel count from Alsa to Ias. 40 | * 41 | * @param in Alsa channel count value. 42 | * @return IasAudioCommonChannelCount Ias channel count value 43 | */ 44 | __attribute__ ((visibility ("default"))) IasAudioCommonChannelCount convertChannelCountAlsaToIas(const unsigned int& in); 45 | 46 | /** 47 | * @brief Function to convert between Ias and Alsa. Format(int16, int32, float) from Ias to Alsa. 48 | * 49 | * @param in Ias pcm format 50 | * @return snd_pcm_format_t Alsa pcm format. 51 | */ 52 | __attribute__ ((visibility ("default"))) snd_pcm_format_t convertFormatIasToAlsa(const IasAudioCommonDataFormat& in); 53 | 54 | /** 55 | * @brief Function to convert between Ias and Alsa. Format(int16, int32, float) from Alsa to Ias. 56 | * Since there are a very few formats in the Ias domain, there will be a lot of invalid returns. 57 | * 58 | * @param in Alsa pcm format. 59 | * @return IasAudio::IasAudioCommonDataFormat Ias pcm format. 60 | */ 61 | __attribute__ ((visibility ("default"))) IasAudioCommonDataFormat convertFormatAlsaToIas(const snd_pcm_format_t& in); 62 | 63 | 64 | /** 65 | * @brief Generates an access type out of the Ias data ordering and a enum mmap flag, 66 | * found in IasAudioCommonTypes. 67 | * 68 | * @param in The data layout, example: eIasAudioCommonInterleaved 69 | * @param isMmap Access type, example: eIasRwAccess 70 | * @return snd_pcm_access_t Alsa access type. 71 | */ 72 | __attribute__ ((visibility ("default"))) snd_pcm_access_t convertAccessTypeIasToAlsa(const IasAudioCommonDataLayout& in, const IasAudioCommonAccess& isMmap); 73 | 74 | /** 75 | * @brief Generates an access type out of the Ias data ordering, defaulting the access to eIasRwAccess. 76 | * 77 | * @param in The data layoutm example: eIasAudioCommonInterleaved 78 | * @return snd_pcm_access_t Alsa access type. 79 | */ 80 | __attribute__ ((visibility ("default"))) snd_pcm_access_t convertAccessTypeIasToAlsa(const IasAudioCommonDataLayout& in); 81 | 82 | 83 | /** 84 | * @brief Fills the alsa area with the base pointer, offset, and step size 85 | * 86 | * @param in IasAudioArea that contains the values. 87 | * @param out Alsa Channel Area, that contains less values. 88 | * @return void 89 | */ 90 | __attribute__ ((visibility ("default"))) void convertAreaIasToAlsa(const IasAudioArea& in, snd_pcm_channel_area_t* out); 91 | 92 | 93 | } 94 | 95 | #endif /* IASALSATYPECONVERSION_HPP_ */ 96 | -------------------------------------------------------------------------------- /public/inc/internal/audio/common/audiobuffer/IasAudioIpcMessageContainer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | /** 8 | * @file IasAudioIpcMessageContainer.hpp 9 | * @date Oct 5, 2015 10 | * @version 0.1 11 | * @brief Defines a the IPC Message Container. 12 | * WARNING: Use the IasAudioIpcProtocolHead.hpp and IasAudioIpcProtocolTail.hpp 13 | */ 14 | 15 | #ifndef IASAUDIOIPCMESSAGECONTAINER_HPP_ 16 | #define IASAUDIOIPCMESSAGECONTAINER_HPP_ 17 | 18 | #include "audio/common/IasAudioCommonTypes.hpp" 19 | 20 | namespace IasAudio { 21 | 22 | /** 23 | * IasIpcCrc 32 Bit value that can contain a CRC32 checksum. 24 | */ 25 | typedef uint32_t IasIpcCrc; 26 | 27 | /** 28 | * Class contains the IasIpcMessage serialized. 29 | */ 30 | class IasIpcMessageContainer 31 | { 32 | public: 33 | /** 34 | * Loads a class in the data package. Creates CRC32 sum and store the data in the data struct. 35 | * The id will stored in the id member. 36 | * 37 | * @param toSend Package that should be stored inside. 38 | * @return Return false if package to big, true is good 39 | */ 40 | template 41 | bool loadData(const C& toSend) 42 | { 43 | 44 | type = GET_IPC_ID(C); 45 | 46 | if(ias_safe_memcpy(data, IAS_AUDIO_IPC_MESSAGE_SIZE, &toSend, sizeof(C))) 47 | { 48 | return false; 49 | } 50 | 51 | boost::crc_32_type checksumGenerator; 52 | checksumGenerator.process_bytes(this, sizeof(IasIpcMessageContainer) - sizeof(IasIpcCrc)); 53 | crc = checksumGenerator.checksum(); 54 | 55 | return true; 56 | } 57 | 58 | /** 59 | * Gets the stored data. This function does not trigger a CRC check. Please use good before. 60 | * 61 | * @param toReceive Package that should be the destination of the internal data. 62 | * @return true if good, false if the structure does not match to the contained data. 63 | */ 64 | template 65 | bool getData(C* toReceive) 66 | { 67 | //Note: The Queue class has to decide if the data should be dropped. (Check for good) 68 | if(GET_IPC_ID(C) == type) 69 | { 70 | if(ias_safe_memcpy(toReceive, sizeof(C), data, sizeof(C))) 71 | { 72 | return false; 73 | } 74 | return true; 75 | } 76 | else 77 | { 78 | return false; 79 | } 80 | } 81 | 82 | /** 83 | * Checks if the contained package is the same type. 84 | * 85 | * @param checkFor Package that should be compared 86 | * @return true on a match 87 | */ 88 | template 89 | bool forecast() 90 | { 91 | return type == GET_IPC_ID(C); 92 | } 93 | 94 | /** 95 | * Calculates the CRC checksum and check if it is correct. 96 | * 97 | * @return true is good 98 | */ 99 | bool good() 100 | { 101 | boost::crc_32_type result; 102 | result.process_bytes(this, sizeof(IasIpcMessageContainer) - sizeof(IasIpcCrc)); 103 | return (crc == result.checksum()); 104 | } 105 | 106 | IasIpcId type; ///<< Type of the package that is in data array. 107 | 108 | private: 109 | char data[IAS_AUDIO_IPC_MESSAGE_SIZE]; ///< Data that contains the serialized structure. 110 | IasIpcCrc crc; ///< CRC32 Checksum from (type, data) 111 | 112 | }; 113 | 114 | } 115 | 116 | #endif /*IASAUDIOIPCMESSAGECONTAINER_HPP_*/ 117 | -------------------------------------------------------------------------------- /public/inc/audio/common/audiobuffer/IasMetaData.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | /** 7 | * @file IasMetaData.hpp 8 | * @date 2015 9 | * @brief 10 | */ 11 | 12 | #ifndef IASMETADATA_HPP_ 13 | #define IASMETADATA_HPP_ 14 | 15 | 16 | namespace IasAudio { 17 | 18 | class IasMetaData; 19 | typedef std::vector IasMetaDataVector; 20 | 21 | struct IasMetaDataHeader 22 | { 23 | static const uint32_t cMagicNumber = 0xABCD1234; //!< A magic number 24 | 25 | /** 26 | * Constructor 27 | */ 28 | IasMetaDataHeader() 29 | :mMagicNumber(cMagicNumber) 30 | ,mSize(sizeof(struct IasMetaDataHeader)) 31 | ,mChannelLayout(0) 32 | {} 33 | 34 | uint32_t mMagicNumber; //!< Magic number to recognize correct initialization 35 | uint32_t mSize; //!< Size of the whole meta data including user defined members 36 | uint32_t mChannelLayout; //!< Channel layout of the stream contained in the buffer for which this meta data is managed 37 | }; 38 | 39 | class __attribute__ ((visibility ("default"))) IasMetaData 40 | { 41 | public: 42 | /** 43 | * @brief Constructor. 44 | */ 45 | IasMetaData() 46 | :mAddr(NULL) 47 | ,mIndex(0) 48 | ,mMaxIndex(0) 49 | {} 50 | 51 | /** 52 | * @brief Destructor, virtual by default. 53 | */ 54 | virtual ~IasMetaData() 55 | {} 56 | 57 | /** 58 | * @brief Get the address of the user meta data buffer 59 | * 60 | * It has to be casted to the correct struct to obtain 61 | * the content. 62 | * @return The address of the user meta data struct 63 | */ 64 | inline void* getAddr() const { return mAddr; } 65 | 66 | /** 67 | * @brief Get the index of the user meta data buffer. 68 | * 69 | * Index count starts at zero. 70 | * @return The index of the buffer in the array. 71 | */ 72 | inline uint32_t getIndex() const { return mIndex; } 73 | 74 | /** 75 | * @brief Get the maximum index of all user meta data buffers. 76 | * 77 | * Index count starts at zero. 78 | * @return The maximum index of the array. 79 | */ 80 | inline uint32_t getMaxIndex() const { return mMaxIndex; } 81 | 82 | /** 83 | * @brief Initialize the members with the correct parameters 84 | * @param[in] addr The address of the user meta data buffer 85 | * @param[in] index The index of the user meta data buffer in the array 86 | * @param[in] maxIndex The maximum index of all user meta data buffers 87 | */ 88 | inline void setParams(void *addr, uint32_t index, uint32_t maxIndex) 89 | { 90 | mAddr = addr; 91 | mIndex = index; 92 | mMaxIndex = maxIndex; 93 | } 94 | 95 | private: 96 | /** 97 | * @brief Copy constructor, private unimplemented to prevent misuse. 98 | */ 99 | IasMetaData(IasMetaData const &other); 100 | 101 | /** 102 | * @brief Assignment operator, private unimplemented to prevent misuse. 103 | */ 104 | IasMetaData& operator=(IasMetaData const &other); 105 | 106 | // Member variables 107 | void *mAddr; //!< The address of the user meta data buffer 108 | uint32_t mIndex; //!< The index of the user meta data buffer in the array 109 | uint32_t mMaxIndex; //!< The maximum index of all user meta data buffers 110 | }; 111 | 112 | } //namespace IasAudio 113 | 114 | #endif /* IASMETADATA_HPP_ */ 115 | -------------------------------------------------------------------------------- /public/inc/internal/audio/common/audiobuffer/IasAudioRingBufferMirror.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | /** 7 | * @file 8 | */ 9 | 10 | #ifndef IASAUDIORINGBUFFERMIRROR_HPP_ 11 | #define IASAUDIORINGBUFFERMIRROR_HPP_ 12 | 13 | #include 14 | #include "audio/common/IasAudioCommonTypes.hpp" 15 | #include "internal/audio/common/IasAudioLogging.hpp" 16 | #include "internal/audio/common/audiobuffer/IasAudioRingBufferResult.hpp" 17 | 18 | // Forward declaration of snd_pcm_t (usually defined in alsa/asoundlib.h). 19 | typedef struct _snd_pcm snd_pcm_t; 20 | 21 | 22 | /*! 23 | * @brief namespace IasAudio 24 | */ 25 | namespace IasAudio { 26 | 27 | 28 | /*! 29 | * @brief Documentation for class IasAudioRingBufferMirror 30 | */ 31 | class __attribute__ ((visibility ("default"))) IasAudioRingBufferMirror 32 | { 33 | public: 34 | 35 | /*! 36 | * @brief Constructor. 37 | */ 38 | IasAudioRingBufferMirror(); 39 | 40 | /*! 41 | * @brief Destructor, virtual by default. 42 | */ 43 | virtual ~IasAudioRingBufferMirror(); 44 | 45 | IasAudioRingBufferResult init(uint32_t numChannels); 46 | 47 | IasAudioRingBufferResult setDeviceHandle(void* handle, uint32_t periodSize, uint32_t timeout_ms); 48 | void clearDeviceHandle(); 49 | 50 | void setNonBlockMode(bool isNonBlocking); 51 | 52 | IasAudioRingBufferResult updateAvailable(IasRingBufferAccess access, uint32_t* samples); 53 | 54 | IasAudioRingBufferResult beginAccess(IasAudioArea* area, uint32_t* offset, uint32_t* frames); 55 | 56 | IasAudioRingBufferResult endAccess(uint32_t offset, uint32_t frames); 57 | 58 | IasAudioRingBufferResult getDataFormat(IasAudioCommonDataFormat *dataFormat) const; 59 | 60 | IasAudioRingBufferResult getTimestamp(IasAudioTimestamp *audioTimestamp) const; 61 | 62 | /** 63 | * @brief Start the ALSA sink device explicitly 64 | * 65 | * This method is required to explicitly start an ALSA sink device when it was prefilled with a specific 66 | * amount of zeros, but with space for one or more full periods. 67 | * 68 | * If less than one period size space is left, than the method updateAvailable automatically starts the ALSA 69 | * sink device. 70 | */ 71 | void startDevice() const; 72 | 73 | private: 74 | /*! 75 | * @brief Copy constructor, private unimplemented to prevent misuse. 76 | */ 77 | IasAudioRingBufferMirror(IasAudioRingBufferMirror const &other); 78 | 79 | /*! 80 | * @brief Assignment operator, private unimplemented to prevent misuse. 81 | */ 82 | IasAudioRingBufferMirror& operator=(IasAudioRingBufferMirror const &other); 83 | 84 | int xrunRecovery(int err); 85 | 86 | snd_pcm_t* mDevice; 87 | uint32_t mNumChannels; 88 | bool mInitialized; 89 | bool mDeviceIsSet; 90 | std::atomic mAccessInProgress; 91 | bool mFirstLoop; //!< Flag, becomes false after first frame 92 | uint32_t mPeriodSize; //!< Period size, expressed in PCM frames 93 | int32_t mTimeout_ms; //!< Timeout [ms] for snd_pcm_wait, or -1 for infinity 94 | bool mNonBlockMode; //!< True if updateAvailable() shall not wait for free frames in output buffer 95 | uint64_t mNumTransmittedFrames; //!< Number of transmitted samples since start. 96 | IasAudioTimestamp mAudioTimestamp; //!< Current audio timestamp (pair of timestamp and numTransmittedFrames) 97 | DltContext *mLog; //!< The DLT log context 98 | }; 99 | 100 | } // namespace IasAudio 101 | 102 | #endif // SOURCES__AUDIO_COMMON_PRIVATE_SRC_AUDIOBUFFER_IASAUDIORINGBUFFERMIRROR_HPP_ 103 | -------------------------------------------------------------------------------- /private/src/common/IasAlsaTypeConversion.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | /** 7 | * @file IasAlsaTypeConversion.cpp 8 | * @date Oct 2, 2015 9 | * @version 0.1 10 | * @brief Connector that connects the Alsa callback functions with the 11 | * provided smartx ring buffers 12 | */ 13 | 14 | #include "internal/audio/common/IasAlsaTypeConversion.hpp" 15 | #include "internal/audio/common/IasAudioLogging.hpp" 16 | 17 | 18 | namespace IasAudio { 19 | 20 | static const std::string cClassName = "IasAlsaTypeConversion::"; 21 | #define LOG_PREFIX cClassName + __func__ + "(" + std::to_string(__LINE__) + "):" 22 | 23 | 24 | unsigned int convertChannelCountIasToAlsa(const IasAudioCommonChannelCount& in) 25 | { 26 | return in; 27 | } 28 | 29 | 30 | IasAudioCommonChannelCount convertChannelCountAlsaToIas ( const unsigned int& in ) 31 | { 32 | return in; 33 | } 34 | 35 | 36 | snd_pcm_format_t convertFormatIasToAlsa(const IasAudioCommonDataFormat& in) 37 | { 38 | switch(in) 39 | { 40 | case eIasFormatFloat32: 41 | return SND_PCM_FORMAT_FLOAT_LE; 42 | break; 43 | case eIasFormatInt16: 44 | return SND_PCM_FORMAT_S16_LE; 45 | break; 46 | case eIasFormatInt32: 47 | return SND_PCM_FORMAT_S32_LE; 48 | break; 49 | default: 50 | DltContext *logCtx = IasAudioLogging::registerDltContext("SXP", "SmartX Plugin"); 51 | DLT_LOG_CXX(*logCtx, DLT_LOG_ERROR, LOG_PREFIX, "Invalid data format:", static_cast(in)); 52 | return SND_PCM_FORMAT_UNKNOWN; 53 | } 54 | } 55 | 56 | 57 | IasAudioCommonDataFormat convertFormatAlsaToIas(const snd_pcm_format_t& in) 58 | { 59 | switch(in) 60 | { 61 | case SND_PCM_FORMAT_FLOAT_LE: 62 | return eIasFormatFloat32; 63 | break; 64 | case SND_PCM_FORMAT_S16_LE: 65 | return eIasFormatInt16; 66 | break; 67 | case SND_PCM_FORMAT_S32_LE: 68 | return eIasFormatInt32; 69 | break; 70 | default: 71 | DltContext *logCtx = IasAudioLogging::registerDltContext("SXP", "SmartX Plugin"); 72 | DLT_LOG_CXX(*logCtx, DLT_LOG_ERROR, LOG_PREFIX, "Invalid data format:", static_cast(in)); 73 | return eIasFormatUndef; 74 | } 75 | } 76 | 77 | 78 | snd_pcm_access_t convertAccessTypeIasToAlsa(const IasAudioCommonDataLayout& in, const IasAudioCommonAccess& isMmap) 79 | { 80 | if(isMmap == eIasAccessRw) 81 | { 82 | switch(in) 83 | { 84 | case eIasLayoutInterleaved: 85 | return SND_PCM_ACCESS_RW_INTERLEAVED; 86 | break; 87 | case eIasLayoutNonInterleaved: 88 | return SND_PCM_ACCESS_RW_NONINTERLEAVED; 89 | default: 90 | DltContext *logCtx = IasAudioLogging::registerDltContext("SXP", "SmartX Plugin"); 91 | DLT_LOG_CXX(*logCtx, DLT_LOG_ERROR, LOG_PREFIX, "Invalid data layout:", static_cast(in)); 92 | return SND_PCM_ACCESS_LAST; 93 | } 94 | } 95 | else 96 | { 97 | switch(in) 98 | { 99 | case eIasLayoutInterleaved: 100 | return SND_PCM_ACCESS_MMAP_INTERLEAVED; 101 | break; 102 | case eIasLayoutNonInterleaved: 103 | return SND_PCM_ACCESS_MMAP_NONINTERLEAVED; 104 | default: 105 | DltContext *logCtx = IasAudioLogging::registerDltContext("SXP", "SmartX Plugin"); 106 | DLT_LOG_CXX(*logCtx, DLT_LOG_ERROR, LOG_PREFIX, "Invalid data layout:", static_cast(in)); 107 | return SND_PCM_ACCESS_LAST; 108 | } 109 | } 110 | } 111 | 112 | 113 | snd_pcm_access_t convertAccessTypeIasToAlsa(const IasAudioCommonDataLayout& in) 114 | { 115 | return convertAccessTypeIasToAlsa(in, eIasAccessRw); 116 | } 117 | 118 | 119 | void convertAreaIasToAlsa(const IasAudioArea& in, snd_pcm_channel_area_t* out) 120 | { 121 | if(out) 122 | { 123 | out->addr = in.start; 124 | out->first = in.first; 125 | out->step = in.step; 126 | } 127 | else 128 | { 129 | DltContext *logCtx = IasAudioLogging::registerDltContext("SXP", "SmartX Plugin"); 130 | DLT_LOG_CXX(*logCtx, DLT_LOG_ERROR, LOG_PREFIX, "out == nullptr"); 131 | } 132 | } 133 | 134 | } 135 | -------------------------------------------------------------------------------- /public/inc/internal/audio/common/audiobuffer/IasAudioRingBufferFactory.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | /** 7 | * @file IasAudioRingBufferFactory.hpp 8 | * @date 2015 9 | * @brief 10 | */ 11 | 12 | #ifndef IASAUDIORINGBUFFERFACTORY_HPP_ 13 | 14 | #define IASAUDIORINGBUFFERFACTORY_HPP_ 15 | 16 | 17 | #include "audio/common/IasAudioCommonTypes.hpp" 18 | #include "internal/audio/common/IasAudioLogging.hpp" 19 | 20 | namespace IasAudio 21 | { 22 | 23 | const uint32_t maxNumRingBufChannels = 8; 24 | 25 | class IasAudioRingBuffer; 26 | class IasMemoryAllocator; 27 | class IasAudioSampleBuffer; 28 | class IasMetaData; 29 | 30 | using IasMemoryAllocatorMap = std::map; 31 | 32 | class __attribute__ ((visibility ("default"))) IasAudioRingBufferFactory 33 | { 34 | public: 35 | /** 36 | * @brief the function return the pointer to the factory. If not yet created, the factory will be created 37 | * 38 | * @returns pointer to the factory 39 | */ 40 | static IasAudioRingBufferFactory* getInstance(); 41 | 42 | /** 43 | * @brief function to create and init a ringbuffer 44 | * 45 | * @param[in] rinbuffer pointer where the created object is stored 46 | * @param[in] periodSize period size in samples 47 | * @param[in] numPeriods the number of periods 48 | * @param[in] numChannels number of channels per period 49 | * @param[in] dataFormat the format of the PCM samples (int16, int32, float32) 50 | * @param[in] dataLayout interleaved layout or de-interleaved 51 | * @param[in] shared flag to indicate if buffer shall be located in shared memory 52 | * @param[in] name the name of the shared memory 53 | * 54 | * @return cInitFailed FileDescriptor could not be created. 55 | */ 56 | IasAudioCommonResult createRingBuffer(IasAudioRingBuffer **ringbuffer, 57 | uint32_t periodSize, 58 | uint32_t numPeriods, 59 | uint32_t numChannels, 60 | IasAudioCommonDataFormat dataFormat, 61 | IasRingbufferType form, 62 | std::string name, 63 | std::string groupName = "ias_audio"); 64 | 65 | /** 66 | * @brief the function destroys a ringbuffer 67 | * 68 | * @param ringBuf pointer to the buffer that shall be destroyed 69 | */ 70 | void destroyRingBuffer(IasAudioRingBuffer* ringBuf); 71 | 72 | /** 73 | * @brief the function is used to find a ringbuffer in shared memory 74 | * 75 | * @param[in] name the name of the shared memory 76 | */ 77 | IasAudioRingBuffer* findRingBuffer(std::string name); 78 | 79 | /** 80 | * @brief the function is used to "lose" a ringbuffer which was previously retrieved by findRingBuffer 81 | * 82 | * Losing a ringbuffer is used on the client side to delete the ringbuffer instance, but not the shared memory associated with it. 83 | * 84 | * @param[in] ringBuf A pointer to the ringbuffer which has to be lost. 85 | */ 86 | void loseRingBuffer(IasAudioRingBuffer* ringBuf); 87 | 88 | private: 89 | /** 90 | * @brief destructor 91 | */ 92 | ~IasAudioRingBufferFactory(); 93 | 94 | /** 95 | * @brief constructor 96 | */ 97 | IasAudioRingBufferFactory(); 98 | 99 | 100 | /** 101 | * @brief copy constructor 102 | */ 103 | IasAudioRingBufferFactory( IasAudioRingBufferFactory const &other ); 104 | 105 | /** 106 | * @brief assign operator 107 | */ 108 | IasAudioRingBufferFactory& operator=(IasAudioRingBufferFactory const &other); 109 | 110 | IasAudioCommonResult createMirror(uint32_t numChannels); 111 | 112 | 113 | IasMemoryAllocatorMap mMemoryMap; //!< map where the allocated memories and the ringbuffer pointers are stored 114 | DltContext *mLog; //!< The DLT log context 115 | }; 116 | 117 | 118 | } 119 | #endif 120 | -------------------------------------------------------------------------------- /public/inc/internal/audio/common/helper/IasCopyAudioAreaBuffers.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | /** 7 | * @file IasCopyAudioAreaBuffers.hpp 8 | * @date 2015 9 | * @brief Fuction to copy between two audio (ring) buffers, which are desribed 10 | * by IasAudioArea structs. 11 | */ 12 | 13 | #ifndef IASCOPYAUDIOAREABUFFERS_HPP 14 | #define IASCOPYAUDIOAREABUFFERS_HPP 15 | 16 | 17 | #include "audio/common/IasAudioCommonTypes.hpp" 18 | 19 | 20 | namespace IasAudio { 21 | 22 | /** 23 | * @brief Fuction to copy between two audio (ring) buffers, which are desribed 24 | * by IasAudioArea structs. 25 | * 26 | * If the destination buffer expects more PCM frames than provided by the source buffer, 27 | * the remaining PCM frames are filled with sine waves (with non-contiguous phase). 28 | * This has to be changed later (i.e. the sine waves have to be replaced by zeros). 29 | * 30 | * @param[in] destinAreas Vector of audio areas that describe the buffer layout of the destination buffer. 31 | * @param[in] destinFormat Data format of the destination buffer. 32 | * @param[in] destinOffset Sample offset for the destination buffer. 33 | * @param[in] destinNumChannels Number of channels to be written to the destination buffer. 34 | * @param[in] destinChanIdx Starting channel index of destination area, where to put data 35 | * @param[in] destinNumFrames Number of frames to be written to the destination buffer. 36 | * @param[in] sourceAreas Vector of audio areas that describe the buffer layout of the source buffer. 37 | * @param[in] sourceFormat Data format of the source buffer. 38 | * @param[in] sourceOffset Sample offset for the source buffer. 39 | * @param[in] sourceNumChannels Number of channels to be read from the source buffer. 40 | * @param[in] sourceChanIdx Starting channel index of source area, where to get data from 41 | * @param[in] sourceNumFrames Number of frames to be read from the source buffer. 42 | */ 43 | 44 | __attribute__ ((visibility ("default"))) void copyAudioAreaBuffers(IasAudioArea const *destinAreas, 45 | IasAudioCommonDataFormat destinFormat, 46 | uint32_t destinOffset, 47 | uint32_t destinNumChannels, 48 | uint32_t destinChanIdx, 49 | uint32_t destinNumFrames, 50 | IasAudioArea const *sourceAreas, 51 | IasAudioCommonDataFormat sourceFormat, 52 | uint32_t sourceOffset, 53 | uint32_t sourceNumChannels, 54 | uint32_t sourceChanIdx, 55 | uint32_t sourceNumFrames); 56 | 57 | 58 | /** 59 | * @brief Fuction to fill zeros into an audio (ring) buffer, which is desribed 60 | * by an IasAudioArea struct. 61 | * 62 | * @param[in] destinAreas Vector of audio areas that describe the buffer layout of the destination buffer. 63 | * @param[in] destinFormat Data format of the destination buffer. 64 | * @param[in] destinOffset Sample offset for the destination buffer. 65 | * @param[in] destinNumChannels Number of channels to be written to the destination buffer. 66 | * @param[in] destinChanIdx Start channel index of destination 67 | * @param[in] destinNumFrames Number of frames to be written to the destination buffer. 68 | */ 69 | __attribute__ ((visibility ("default"))) void zeroAudioAreaBuffers(IasAudioArea const *destinAreas, 70 | IasAudioCommonDataFormat destinFormat, 71 | uint32_t destinOffset, 72 | uint32_t destinNumChannels, 73 | uint32_t destinChanIdx, 74 | uint32_t destinNumFrames); 75 | 76 | 77 | } //namespace IasAudio 78 | 79 | #endif // IASCOPYAUDIOAREABUFFERS_HPP 80 | -------------------------------------------------------------------------------- /public/inc/internal/audio/common/samplerateconverter/IasSrcWrapperBase.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | /* 7 | * IasSrcWrapperBase.hpp 8 | * 9 | * Created 2016 10 | * 11 | */ 12 | 13 | #ifndef IASSRCWRAPPERBASE_HPP_ 14 | #define IASSRCWRAPPERBASE_HPP_ 15 | 16 | 17 | #include "audio/common/IasAudioCommonTypes.hpp" 18 | 19 | namespace IasAudio{ 20 | 21 | 22 | class IasAudioLogging; 23 | 24 | /** 25 | * @brief The result values 26 | */ 27 | enum IasSrcWrapperResult{ 28 | eIasOk = 0, //!< no error occurred 29 | eIasFailed //!< operation failed 30 | }; 31 | 32 | /** 33 | * @brief The init paramter structure 34 | */ 35 | struct IasSrcWrapperParams 36 | { 37 | 38 | IasSrcWrapperParams() 39 | :inputFormat(eIasFormatUndef) 40 | ,outputFormat(eIasFormatUndef) 41 | ,inputSampleRate(0) 42 | ,outputSampleRate(0) 43 | ,numChannels(0) 44 | ,inputIndex(0) 45 | ,outputIndex(0) 46 | {} 47 | 48 | IasSrcWrapperParams(IasAudioCommonDataFormat inFormat, 49 | IasAudioCommonDataFormat outFormat, 50 | uint32_t inRate, 51 | uint32_t outRate, 52 | uint32_t nChannels, 53 | uint32_t inputIdx, 54 | uint32_t outputIdx) 55 | 56 | :inputFormat(inFormat) 57 | ,outputFormat(outFormat) 58 | ,inputSampleRate(inRate) 59 | ,outputSampleRate(outRate) 60 | ,numChannels(nChannels) 61 | ,inputIndex(inputIdx) 62 | ,outputIndex(outputIdx) 63 | {} 64 | 65 | IasAudioCommonDataFormat inputFormat; //!< input sample format 66 | IasAudioCommonDataFormat outputFormat; //!< output sample format 67 | uint32_t inputSampleRate; //!< input sample rate 68 | uint32_t outputSampleRate; //!< output sample rate 69 | uint32_t numChannels; //!< number of channels 70 | uint32_t inputIndex; //!< index of first input channel 71 | uint32_t outputIndex; //!< index of first output channel 72 | 73 | }; 74 | 75 | class __attribute__ ((visibility ("default"))) IasSrcWrapperBase 76 | { 77 | public: 78 | 79 | virtual ~IasSrcWrapperBase(){}; 80 | 81 | /** 82 | * @brief Init function of sample rate converter wrapper 83 | * 84 | * @params[in] params the init parameter structure 85 | * @params[in] inArea pointer to the input area 86 | * @params[in] outArea pointer to the output area 87 | * 88 | * @returns error code 89 | * @retval eIasOk all went well 90 | * @retval eIasFailed an error occurred 91 | */ 92 | virtual IasSrcWrapperResult init(IasSrcWrapperParams ¶ms, 93 | const IasAudioArea* inArea, 94 | const IasAudioArea* outArea) = 0; 95 | 96 | /** 97 | * @brief Process function of sample rate converter wrapper 98 | * 99 | * @params[out] numGeneratedSamples Number of generated samples by the sample rate converter 100 | * @params[out] numConsumedSamples Number of consumed samples by the sample rate converter 101 | * @params[in] lengthInputBuffers Number of samples provided to sample rate converter 102 | * @params[in] numOutputSamples The number of sample that still needs to be processed 103 | * @param[in] srcOffset The offset in the source buffer 104 | * @param[in] sinkOffset The offset in the sink buffer 105 | * 106 | * @returns error code 107 | * @retval eIasOk all went well 108 | * @retval eIasFailed an error occurred 109 | */ 110 | virtual IasSrcWrapperResult process(uint32_t *numGeneratedSamples, 111 | uint32_t *numConsumedSamples, 112 | uint32_t lengthInputBuffers, 113 | uint32_t numOutputSamples, 114 | uint32_t srcOffset, 115 | uint32_t sinkOffset) = 0; 116 | 117 | /** 118 | * @brief Reset function of sample rate converter wrapper 119 | * 120 | * @returns error code 121 | * @retval eIasOk all went well 122 | * @retval eIasFailed an error occurred 123 | */ 124 | virtual IasSrcWrapperResult reset() = 0; 125 | 126 | }; 127 | 128 | } 129 | 130 | #endif 131 | -------------------------------------------------------------------------------- /public/inc/internal/audio/common/alsa_smartx_plugin/IasAlsaHwConstraintsStatic.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | /** 8 | * @file IasAlsaHwConstraintsStatic.hpp 9 | * @date Sep 22, 2015 10 | * @version 0.1 11 | * @brief Defines a shared memory structure to exchange audio device constrains between processes. 12 | * 13 | */ 14 | 15 | #ifndef IASALSAHWCONSTRAINTS_HPP_ 16 | #define IASALSAHWCONSTRAINTS_HPP_ 17 | 18 | /* 19 | * System 20 | */ 21 | #include 22 | 23 | /* 24 | * Boost 25 | */ 26 | #include 27 | 28 | /* 29 | * Ias 30 | */ 31 | 32 | 33 | /* 34 | * Common 35 | */ 36 | #include "audio/common/IasAudioCommonTypes.hpp" 37 | 38 | namespace IasAudio { 39 | 40 | 41 | template 42 | using IasShmStaticVector = boost::container::static_vector; 43 | 44 | using IasAudioDataFormatVector = IasShmStaticVector; 45 | using IasAudioDataLayoutVector = IasShmStaticVector; 46 | using IasAudioChannelCount = IasShmStaticVector; 47 | using IasAudioSampleRateVector = IasShmStaticVector; 48 | using IasAudioPeriodSizeVector = IasShmStaticVector; 49 | using IasAudioPeriodCountVector = IasShmStaticVector; 50 | using IasAudioBufferSizeVector = IasShmStaticVector; 51 | 52 | struct IasAlsaHwConstraintsStatic 53 | { 54 | /** 55 | * The constructor needs an allocator from the specific shared memory. 56 | * It initializes allother 57 | * 58 | * @param void_allocator 59 | */ 60 | IasAlsaHwConstraintsStatic(): 61 | isValid(false) 62 | {} 63 | 64 | /** 65 | * Valid flag, if the structure should be used. 66 | */ 67 | bool isValid; 68 | 69 | /** 70 | * Struct contains the data formats as IasAudioCommonDataType 71 | */ 72 | struct 73 | { 74 | IasAudioDataFormatVector list; ///< List of the supported formats. 75 | } formats; 76 | 77 | /** 78 | * Struct contains the layout of the data as IasAudioCommonDataLayout, interleaved or non-interleaved. 79 | */ 80 | struct 81 | { 82 | IasAudioDataLayoutVector list; ///< List of the supported layouts. 83 | } access; 84 | 85 | /** 86 | * Struct contains the channel max/min count or the list of the supported counts. 87 | * Either the list is filled with values or the min/max is valid. 88 | */ 89 | struct 90 | { 91 | IasAudioChannelCount list; ///< List of the supported channel counts. 92 | IasAudioCommonChannelCount min; ///< Minimum channel count 93 | IasAudioCommonChannelCount max; ///< Maximum channel count 94 | } channels; 95 | 96 | /** 97 | * Struct contains the supported sample rates. Either the list is filled with values, 98 | * or the min/max is valid. 99 | */ 100 | struct 101 | { 102 | IasAudioSampleRateVector list; ///< List of the supported sample rates. 103 | uint32_t min; ///< Minimum sample rate 104 | uint32_t max; ///< Maximum sample rate 105 | } rate; 106 | 107 | /** 108 | * Struct the supported period sizes. Either the list is filled with values, 109 | * or the min/max is valid. 110 | */ 111 | struct 112 | { 113 | IasAudioPeriodSizeVector list; ///< List of the supported period sizes. 114 | uint32_t min; ///< Minimum period size 115 | uint32_t max; ///< Maximum period size 116 | } period_size; 117 | 118 | /** 119 | * Struct the supported period count. Either the list is filled with values, 120 | * or the min/max is valid. 121 | */ 122 | struct 123 | { 124 | IasAudioPeriodCountVector list; ///< List of the supported period counts. 125 | uint32_t min; ///< Minimum period count 126 | uint32_t max; ///< Maximum period count 127 | } period_count; 128 | 129 | /** 130 | * Struct the supported period count. Either the list is filled with values, 131 | * or the min/max is valid. 132 | */ 133 | struct 134 | { 135 | IasAudioBufferSizeVector list; ///< List of the supported buffer sizes. 136 | uint32_t min; ///< Minimum buffer size 137 | uint32_t max; ///< Maximum buffer size 138 | } buffer_size; 139 | 140 | }; 141 | 142 | } 143 | 144 | #endif /* IASALSAHWCONSTRAINTS_HPP_ */ 145 | -------------------------------------------------------------------------------- /public/inc/internal/audio/common/alsa_smartx_plugin/IasAlsaHwConstraintsDynamic.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | /** 8 | * @file IasAlsaHwConstraintsDynamic.hpp 9 | * @date Sep 22, 2015 10 | * @version 0.1 11 | * @brief Defines a shared memory structure to exchange audio device constrains between processes. 12 | * 13 | */ 14 | 15 | #ifndef IASALSAHWCONSTRAINTS_HPP_ 16 | #define IASALSAHWCONSTRAINTS_HPP_ 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | 23 | #include "audio/common/IasAudioCommonTypes.hpp" 24 | 25 | namespace IasAudio { 26 | 27 | /* 28 | * Define some type names for aesthetical reasons. 29 | * It is possible to use 'IasShmDynamicVector vectorName' as shared memory capable vector. 30 | * 31 | * Don't forget the constructor needs a const IasShmAllocator&. 32 | */ 33 | template 34 | using IasShmAllocator = boost::interprocess::allocator; 35 | 36 | 37 | template 38 | using IasShmDynamicVector = boost::interprocess::vector >; 39 | 40 | 41 | struct IasAlsaHwConstraintsDynamic 42 | { 43 | /** 44 | * The constructor needs an allocator from the specific shared memory. 45 | * It initializes allother 46 | * 47 | * @param void_allocator 48 | */ 49 | IasAlsaHwConstraintsDynamic(const IasShmAllocator& void_allocator): 50 | isValid(false), 51 | formats({IasShmDynamicVector(void_allocator)}), 52 | access({IasShmDynamicVector(void_allocator)}), 53 | channels({IasShmDynamicVector(void_allocator), 0, 0}), 54 | rate({IasShmDynamicVector(void_allocator), IasAudioCommonSampleRates(eIas_8000Hz), 55 | IasAudioCommonSampleRates(eIas_8000Hz)}), 56 | period_size({IasShmDynamicVector(void_allocator), 0, 0}), 57 | period_count({IasShmDynamicVector(void_allocator), 0, 0}), 58 | buffer_size({IasShmDynamicVector(void_allocator), 0, 0}) 59 | {} 60 | 61 | 62 | /** 63 | * Valid flag, if the structure should be used. 64 | */ 65 | bool isValid; 66 | 67 | /** 68 | * Struct contains the data formats as IasAudioCommonDataType 69 | */ 70 | struct 71 | { 72 | IasShmDynamicVector list; ///< List of the supported formats. 73 | } formats; 74 | 75 | /** 76 | * Struct contains the layout of the data as IasAudioCommonDataLayout, interleaved or non-interleaved. 77 | */ 78 | struct 79 | { 80 | IasShmDynamicVector list; ///< List of the supported layouts. 81 | } access; 82 | 83 | /** 84 | * Struct contains the channel max/min count or the list of the supported counts. 85 | * Either the list is filled with values or the min/max is valid. 86 | */ 87 | struct 88 | { 89 | IasShmDynamicVector list; ///< List of the supported channel counts. 90 | IasAudioCommonChannelCount min; ///< Minimum channel count 91 | IasAudioCommonChannelCount max; ///< Maximum channel count 92 | } channels; 93 | 94 | /** 95 | * Struct contains the supported sample rates. Either the list is filled with values, 96 | * or the min/max is valid. 97 | */ 98 | struct 99 | { 100 | IasShmDynamicVector list; ///< List of the supported sample rates. 101 | uint32_t min; ///< Minimum sample rate 102 | uint32_t max; ///< Maximum sample rate 103 | } rate; 104 | 105 | /** 106 | * Struct the supported period sizes. Either the list is filled with values, 107 | * or the min/max is valid. 108 | */ 109 | struct 110 | { 111 | IasShmDynamicVector list; ///< List of the supported period sizes. 112 | uint32_t min; ///< Minimum period size 113 | uint32_t max; ///< Maximum period size 114 | } period_size; 115 | 116 | /** 117 | * Struct the supported period count. Either the list is filled with values, 118 | * or the min/max is valid. 119 | */ 120 | struct 121 | { 122 | IasShmDynamicVector list; ///< List of the supported period counts. 123 | uint32_t min; ///< Minimum period count 124 | uint32_t max; ///< Maximum period count 125 | } period_count; 126 | 127 | /** 128 | * Struct the supported period count. Either the list is filled with values, 129 | * or the min/max is valid. 130 | */ 131 | struct 132 | { 133 | IasShmDynamicVector list; ///< List of the supported buffer sizes. 134 | uint32_t min; ///< Minimum buffer size 135 | uint32_t max; ///< Maximum buffer size 136 | } buffer_size; 137 | 138 | }; 139 | 140 | } 141 | 142 | #endif /* IASALSAHWCONSTRAINTS_HPP_ */ 143 | -------------------------------------------------------------------------------- /android/SmartXAlsaPlugin.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | # 5 | 6 | include $(CLEAR_VARS) 7 | 8 | LOCAL_MODULE := libasound_module_pcm_smartx 9 | LOCAL_PROPRIETARY_MODULE := true 10 | LOCAL_MODULE_OWNER := intel 11 | LOCAL_MODULE_TAGS := optional 12 | LOCAL_CLANG := true 13 | LOCAL_HEADER_LIBRARIES += libutils_headers 14 | LOCAL_REQUIRED_MODULES := \ 15 | 50-smartx.conf \ 16 | asound.rc 17 | 18 | LOCAL_SRC_FILES := \ 19 | ../private/src/alsa_smartx_plugin/IasAlsaSmartXPlugin.cpp \ 20 | ../private/src/alsa_smartx_plugin/IasAlsaSmartXConnector.cpp \ 21 | 22 | LOCAL_C_INCLUDES := \ 23 | $(LOCAL_PATH)/../public/inc \ 24 | $(LOCAL_PATH)/../private/inc/alsa_smartx_plugin \ 25 | bionic 26 | 27 | LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/../public/inc/ 28 | 29 | LOCAL_STATIC_LIBRARIES := \ 30 | libboost 31 | 32 | LOCAL_SHARED_LIBRARIES := \ 33 | libias-android-pthread \ 34 | libasound \ 35 | libias-audio-common \ 36 | libias-core_libraries-foundation \ 37 | libias-core_libraries-base \ 38 | libdlt \ 39 | liblog 40 | 41 | OPEN_ONCE_LOCK_PATH := /run/smartx/ 42 | 43 | LOCAL_CFLAGS := $(IAS_COMMON_CFLAGS) \ 44 | -frtti -fexceptions -Wall -Wno-unused-parameter -Wpointer-arith \ 45 | -fPIC -DPIC \ 46 | -DOPEN_ONCE_LOCK_PATH=\"/mnt/eavb/misc$(OPEN_ONCE_LOCK_PATH)\" 47 | 48 | ifeq ("$(shell [ $(ANDROID_VERSION) -eq $(ANDROID_M) ] && echo true)", "true") 49 | BOOST_SHARED_FOLDER := /mnt/eavb/misc/media/ 50 | else 51 | BOOST_SHARED_FOLDER := /mnt/eavb/misc/audioserver/ 52 | endif 53 | 54 | LOCAL_LDFLAGS := -Wl,-no-undefined -DBOOST_INTERPROCESS_SHARED_DIR_PATH=\"$(BOOST_SHARED_FOLDER)\" \ 55 | 56 | include $(BUILD_SHARED_LIBRARY) 57 | 58 | ####################################################################### 59 | # Build for configuration file 60 | # IasInstallFiles( "public/res" "usr/share/alsa/alsa.conf.d" "" base 50-smartx.conf IS_ABSOLUTE_DESTINATION ) 61 | ####################################################################### 62 | include $(CLEAR_VARS) 63 | LOCAL_MODULE := 50-smartx.conf 64 | LOCAL_PROPRIETARY_MODULE := true 65 | LOCAL_MODULE_OWNER := intel 66 | LOCAL_MODULE_TAGS := optional 67 | LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR)/usr/share/alsa/alsa.conf.d 68 | LOCAL_MODULE_CLASS := ETC 69 | LOCAL_SRC_FILES := ../public/res/$(LOCAL_MODULE) 70 | include $(BUILD_PREBUILT) 71 | 72 | ####################################################################### 73 | # asound.rc 74 | ####################################################################### 75 | include $(CLEAR_VARS) 76 | LOCAL_MODULE := asound.rc 77 | LOCAL_PROPRIETARY_MODULE := true 78 | LOCAL_MODULE_OWNER := intel 79 | LOCAL_MODULE_TAGS := optional 80 | LOCAL_MODULE_CLASS := ETC 81 | LOCAL_SRC_FILES := res/$(LOCAL_MODULE) 82 | include $(BUILD_PREBUILT) 83 | 84 | ####################################################################### 85 | # TESTS 86 | ####################################################################### 87 | 88 | ####################################################################### 89 | # alsa_smartx_plugin_tst 90 | ####################################################################### 91 | #include $(CLEAR_VARS) 92 | 93 | #LOCAL_C_INCLUDES := \ 94 | # $(LOCAL_PATH)/../public/inc \ 95 | # $(LOCAL_PATH)/../private/inc \ 96 | # bionic 97 | 98 | #LOCAL_SRC_FILES := \ 99 | # ../private/tst/alsa_smartx_plugin_tst/src/IasAlsaSmartXPluginTest.cpp 100 | 101 | #LOCAL_STATIC_LIBRARIES := \ 102 | # liblog \ 103 | # libtbb \ 104 | # libsndfile-1.0.27 \ 105 | # libboost 106 | 107 | #LOCAL_SHARED_LIBRARIES := \ 108 | # libias-android-pthread \ 109 | # libasound_module_pcm_smartx \ 110 | # libias-audio-common \ 111 | # libias-core_libraries-foundation \ 112 | # libias-core_libraries-test_support \ 113 | # libias-core_libraries-base \ 114 | # libdlt \ 115 | # libasound 116 | 117 | #LOCAL_CFLAGS := $(IAS_COMMON_CFLAGS) -Wall -Wextra -Werror -Werror \ 118 | # -Wpointer-arith -frtti -fexceptions 119 | 120 | #LOCAL_CLANG := true 121 | #LOCAL_MODULE := alsa_smartx_plugin_tst 122 | 123 | #include $(BUILD_NATIVE_TEST) 124 | 125 | ####################################################################### 126 | # alsa_smartx_connection_tst 127 | ####################################################################### 128 | 129 | #include $(CLEAR_VARS) 130 | 131 | #LOCAL_C_INCLUDES := \ 132 | # $(LOCAL_PATH)/../public/inc \ 133 | # $(LOCAL_PATH)/../private/inc \ 134 | # bionic 135 | 136 | #LOCAL_SRC_FILES := \ 137 | # ../private/tst/alsa_smartx_connection_tst/src/IasAlsaSmartXConnectionTest.cpp 138 | 139 | #LOCAL_STATIC_LIBRARIES := \ 140 | # liblog \ 141 | # libtbb \ 142 | # libsndfile-1.0.27 \ 143 | # libboost 144 | 145 | #LOCAL_SHARED_LIBRARIES := \ 146 | # libias-audio-common \ 147 | # libias-core_libraries-foundation \ 148 | # libias-core_libraries-test_support \ 149 | # libias-core_libraries-base \ 150 | # libdlt \ 151 | # libasound 152 | 153 | #LOCAL_CFLAGS := $(IAS_COMMON_CFLAGS) -Wall -Wextra -Werror -frtti \ 154 | # -Wpointer-arith -fexceptions 155 | 156 | #LOCAL_CLANG := true 157 | #LOCAL_MODULE := alsa_smartx_connection_tst 158 | 159 | #include $(BUILD_NATIVE_TEST) 160 | -------------------------------------------------------------------------------- /private/src/common/IasAudioLogging.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | /** 7 | * @file IasAudioLogging.cpp 8 | * @date 2012 9 | * @brief This is the implementation of the IasAudioLogging class. 10 | */ 11 | 12 | #include 13 | #include "internal/audio/common/IasAudioLogging.hpp" 14 | 15 | 16 | namespace IasAudio { 17 | 18 | IasAudioLogging::IasAudioLogging() 19 | { 20 | mMutex.lock(); 21 | mDltContextMap.clear(); 22 | mMutex.unlock(); 23 | } 24 | 25 | IasAudioLogging::~IasAudioLogging() 26 | { 27 | mMutex.lock(); 28 | DltContextMap::iterator dltContextMapEntryIt; 29 | for(dltContextMapEntryIt = mDltContextMap.begin(); dltContextMapEntryIt != mDltContextMap.end(); ++dltContextMapEntryIt) 30 | { 31 | DltContextMapEntry * dltContextMapEntry = (*dltContextMapEntryIt).second; 32 | if (dltContextMapEntry != NULL) 33 | { 34 | if(dltContextMapEntry->getDltContext() != NULL) 35 | { 36 | DLT_UNREGISTER_CONTEXT(*dltContextMapEntry->getDltContext()); 37 | delete(dltContextMapEntry->getDltContext()); 38 | } 39 | delete dltContextMapEntry; 40 | } 41 | } 42 | mDltContextMap.clear(); 43 | mMutex.unlock(); 44 | 45 | DLT_UNREGISTER_APP(); 46 | } 47 | 48 | IasAudioLogging* IasAudioLogging::audioLoggingInstance() 49 | { 50 | static IasAudioLogging theInstance; 51 | return &theInstance; 52 | } 53 | 54 | 55 | IasAudioLogging::DltContextMap & IasAudioLogging::getMap() 56 | { 57 | return audioLoggingInstance()->mDltContextMap; 58 | } 59 | 60 | std::mutex& IasAudioLogging::getMutex() 61 | { 62 | return audioLoggingInstance()->mMutex; 63 | } 64 | 65 | void IasAudioLogging::registerDltApp(bool enableConsoleLog) 66 | { 67 | DLT_REGISTER_APP("XBAR", "SmartXbar"); 68 | DLT_VERBOSE_MODE(); 69 | 70 | if(true == enableConsoleLog) 71 | { 72 | dlt_enable_local_print(); 73 | } 74 | } 75 | 76 | DltContext* IasAudioLogging::registerDltContext(const std::string context_id, 77 | const char * context_description) 78 | { 79 | DltLogLevelType lloglevel; 80 | DltContext *newContext = NULL; 81 | 82 | DltContextMap::iterator dltContextMapEntryIt; 83 | getMutex().lock(); 84 | dltContextMapEntryIt = getMap().find(context_id); 85 | if(dltContextMapEntryIt == getMap().end()) 86 | { 87 | DLT_VERBOSE_MODE(); 88 | DltContextMapEntry *dltContextMapEntry = new DltContextMapEntry(); 89 | 90 | dltContextMapEntryIt = getMap().find("global"); 91 | if(dltContextMapEntryIt != getMap().end()) 92 | { 93 | DltContextMapEntry * tmpdltContextMapEntry = (*dltContextMapEntryIt).second; 94 | lloglevel = tmpdltContextMapEntry->getDltLogLevel(); 95 | } 96 | else 97 | { 98 | lloglevel = dltContextMapEntry->getDltLogLevel(); 99 | } 100 | 101 | newContext = new DltContext(); 102 | dltContextMapEntry->setDltContext(newContext); 103 | 104 | // only log warnings and above, do not trace any messages 105 | DLT_REGISTER_CONTEXT_LL_TS( *newContext, context_id.c_str(), 106 | context_description, 107 | lloglevel, 108 | dltContextMapEntry->getDltTraceStatus()); 109 | getMap()[context_id] = dltContextMapEntry; 110 | } 111 | else 112 | { 113 | DltContextMapEntry * dltContextMapEntry = (*dltContextMapEntryIt).second; 114 | newContext = dltContextMapEntry->getDltContext(); 115 | if(NULL == newContext) 116 | { 117 | DLT_VERBOSE_MODE(); 118 | 119 | newContext = new DltContext(); 120 | dltContextMapEntry->setDltContext(newContext); 121 | 122 | // only log warnings and above, do not trace any messages 123 | DLT_REGISTER_CONTEXT_LL_TS( *newContext, context_id.c_str(), 124 | context_description, 125 | dltContextMapEntry->getDltLogLevel(), 126 | dltContextMapEntry->getDltTraceStatus()); 127 | } 128 | } 129 | getMutex().unlock(); 130 | return newContext; 131 | } 132 | 133 | DltContext * IasAudioLogging::getDltContext(const std::string contextId) 134 | { 135 | getMutex().lock(); 136 | DltContextMap::iterator dltContextMapEntryIt; 137 | dltContextMapEntryIt = getMap().find(contextId.c_str()); 138 | if(dltContextMapEntryIt != getMap().end()) 139 | { 140 | DltContextMapEntry * dltContextMapEntry = (*dltContextMapEntryIt).second; 141 | getMutex().unlock(); 142 | return(dltContextMapEntry->getDltContext()); 143 | } 144 | else 145 | { 146 | getMutex().unlock(); 147 | return registerDltContext(contextId, "dummy context description"); 148 | } 149 | } 150 | 151 | void IasAudioLogging::addDltContextItem(const std::string contextId, DltLogLevelType loglevel, DltTraceStatusType tracestatus) 152 | { 153 | DltContextMapEntry * dltContextMapEntry = new DltContextMapEntry(); 154 | 155 | dltContextMapEntry->setDltLogLevel(loglevel); 156 | dltContextMapEntry->setDltTraceStatus(tracestatus); 157 | dltContextMapEntry->setDltContext(NULL); 158 | getMutex().lock(); 159 | getMap()[contextId] = dltContextMapEntry; 160 | getMutex().unlock(); 161 | } 162 | 163 | 164 | } // namespace IasAudio 165 | -------------------------------------------------------------------------------- /private/src/common/IasIntProcCondVar.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | /** 7 | * @file IasIntProcCondVar.cpp 8 | * @date 2016 9 | * @brief 10 | */ 11 | 12 | #include 13 | #include "internal/audio/common/IasIntProcCondVar.hpp" 14 | #include "internal/audio/common/IasIntProcMutex.hpp" 15 | #include 16 | #include 17 | 18 | namespace IasAudio { 19 | 20 | IasIntProcCondVar::IasIntProcCondVar() 21 | :mInitResult(eIasNotInitialized) 22 | ,mNativeResult(0) 23 | { 24 | pthread_condattr_t condAttr; 25 | bool condAttrInitialized = false; 26 | int32_t nativeResult = pthread_condattr_init(&condAttr); 27 | if (nativeResult == 0) 28 | { 29 | condAttrInitialized = true; 30 | nativeResult = pthread_condattr_setpshared(&condAttr, PTHREAD_PROCESS_SHARED); 31 | if (nativeResult == 0) 32 | { 33 | nativeResult = pthread_condattr_setclock(&condAttr, CLOCK_MONOTONIC); 34 | if (nativeResult == 0) 35 | { 36 | nativeResult = pthread_cond_init(&mCondVar, &condAttr); 37 | if (nativeResult == 0) 38 | { 39 | mInitResult = eIasOk; 40 | } 41 | else 42 | { 43 | mInitResult = eIasCondInitFailed; 44 | } 45 | } 46 | else 47 | { 48 | mInitResult = eIasCondAttrSetclockFailed; 49 | } 50 | } 51 | else 52 | { 53 | mInitResult = eIasCondAttrSetpsharedFailed; 54 | } 55 | } 56 | else 57 | { 58 | mInitResult = eIasCondAttrInitFailed; 59 | } 60 | 61 | mNativeResult = nativeResult; 62 | 63 | if (condAttrInitialized == true) 64 | { 65 | pthread_condattr_destroy(&condAttr); 66 | } 67 | } 68 | 69 | IasIntProcCondVar::~IasIntProcCondVar() 70 | { 71 | if (mInitResult == eIasOk) 72 | { 73 | // Workaround: Reinitialization of condvar is done because the condvar might become invalid due to a dead client. 74 | // In that case pthread_cond_destroy() won't return and block forever! 75 | pthread_condattr_t condAttr; 76 | int32_t result = pthread_condattr_init(&condAttr); 77 | result = pthread_cond_init(&mCondVar, &condAttr); 78 | result = pthread_cond_destroy(&mCondVar); 79 | result = pthread_condattr_destroy(&condAttr); 80 | // We don't care about the result. Just to make Klocwork happy. 81 | (void) result; 82 | } 83 | mInitResult = eIasNotInitialized; 84 | } 85 | 86 | IasIntProcCondVar::IasResult IasIntProcCondVar::wait(IasIntProcMutex &mutex) 87 | { 88 | if (mInitResult != eIasOk) 89 | { 90 | return mInitResult; 91 | } 92 | const int32_t nativeResult = pthread_cond_wait(&mCondVar, mutex.nativeHandle()); 93 | mNativeResult = nativeResult; 94 | if (nativeResult != 0) 95 | { 96 | return eIasCondWaitFailed; 97 | } 98 | return eIasOk; 99 | } 100 | 101 | IasIntProcCondVar::IasResult IasIntProcCondVar::wait(IasIntProcMutex &mutex, uint64_t time_ms) 102 | { 103 | if (mInitResult != eIasOk) 104 | { 105 | return mInitResult; 106 | } 107 | 108 | std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now(); 109 | std::chrono::steady_clock::time_point then = now + std::chrono::milliseconds(time_ms); 110 | 111 | auto sec =std::chrono::time_point_cast(then); 112 | auto nsec =std::chrono::time_point_cast(then); 113 | 114 | struct timespec timespecValue; 115 | timespecValue.tv_sec = sec.time_since_epoch().count(); 116 | timespecValue.tv_nsec = (nsec.time_since_epoch().count() %1000000000ULL); 117 | 118 | const int32_t nativeResult = pthread_cond_timedwait(&mCondVar, mutex.nativeHandle(), ×pecValue); 119 | 120 | mNativeResult = nativeResult; 121 | if (nativeResult == 0) 122 | { 123 | return eIasOk; 124 | } 125 | else if (nativeResult == ETIMEDOUT) 126 | { 127 | return eIasTimeout; 128 | } 129 | else 130 | { 131 | return eIasCondWaitFailed; 132 | } 133 | } 134 | 135 | IasIntProcCondVar::IasResult IasIntProcCondVar::signal() 136 | { 137 | if (mInitResult != eIasOk) 138 | { 139 | return mInitResult; 140 | } 141 | const int32_t nativeResult = pthread_cond_signal(&mCondVar); 142 | mNativeResult = nativeResult; 143 | if (nativeResult != 0) 144 | { 145 | return eIasCondSignalFailed; 146 | } 147 | return eIasOk; 148 | } 149 | 150 | #define STRING_RETURN_CASE(name) case name: return std::string(#name); break 151 | #define DEFAULT_STRING(name) default: return std::string(name) 152 | 153 | __attribute__ ((visibility ("default"))) std::string toString(const IasIntProcCondVar::IasResult& type) 154 | { 155 | switch(type) 156 | { 157 | STRING_RETURN_CASE(IasIntProcCondVar::eIasOk); 158 | STRING_RETURN_CASE(IasIntProcCondVar::eIasInvalidParam); 159 | STRING_RETURN_CASE(IasIntProcCondVar::eIasNotInitialized); 160 | STRING_RETURN_CASE(IasIntProcCondVar::eIasCondAttrInitFailed); 161 | STRING_RETURN_CASE(IasIntProcCondVar::eIasCondAttrSetpsharedFailed); 162 | STRING_RETURN_CASE(IasIntProcCondVar::eIasCondAttrSetclockFailed); 163 | STRING_RETURN_CASE(IasIntProcCondVar::eIasCondInitFailed); 164 | STRING_RETURN_CASE(IasIntProcCondVar::eIasTimeout); 165 | STRING_RETURN_CASE(IasIntProcCondVar::eIasCondWaitFailed); 166 | STRING_RETURN_CASE(IasIntProcCondVar::eIasClockTimeNotAvailable); 167 | STRING_RETURN_CASE(IasIntProcCondVar::eIasCondSignalFailed); 168 | DEFAULT_STRING("Invalid IasIntProcCondVar::IasResult => " + std::to_string(type)); 169 | } 170 | } 171 | 172 | 173 | } /* namespace IasAudio */ 174 | -------------------------------------------------------------------------------- /private/src/common/IasIntProcMutex.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | /** 7 | * @file IasIntProcMutex.cpp 8 | * @date 2016 9 | * @brief 10 | */ 11 | 12 | #include 13 | #include "internal/audio/common/IasIntProcMutex.hpp" 14 | 15 | namespace IasAudio { 16 | 17 | IasIntProcMutex::IasIntProcMutex() 18 | :mInitResult(eIasNotInitialized) 19 | ,mNativeResult(0) 20 | { 21 | pthread_mutexattr_t mutexAttr; 22 | bool mutexAttrInitialized = false; 23 | int32_t nativeResult = pthread_mutexattr_init(&mutexAttr); 24 | if (nativeResult != 0) 25 | { 26 | mInitResult = eIasMutexAttrInitFailed; 27 | } 28 | else 29 | { 30 | mutexAttrInitialized = true; 31 | nativeResult = pthread_mutexattr_setpshared(&mutexAttr, PTHREAD_PROCESS_SHARED); 32 | } 33 | 34 | if (nativeResult != 0) 35 | { 36 | mInitResult = eIasMutexAttrSetpsharedFailed; 37 | } 38 | else 39 | { 40 | nativeResult = pthread_mutexattr_setrobust(&mutexAttr, PTHREAD_MUTEX_ROBUST); 41 | } 42 | 43 | if (nativeResult != 0) 44 | { 45 | mInitResult = eIasMutexAttrSetrobustFailed; 46 | } 47 | else 48 | { 49 | nativeResult = pthread_mutexattr_setprotocol(&mutexAttr, PTHREAD_PRIO_INHERIT); 50 | } 51 | 52 | if (nativeResult != 0) 53 | { 54 | mInitResult = eIasMutexAttrSetprotocolFailed; 55 | } 56 | else 57 | { 58 | nativeResult = pthread_mutex_init(&mMutex, &mutexAttr); 59 | } 60 | 61 | if (nativeResult != 0) 62 | { 63 | mInitResult = eIasMutexInitFailed; 64 | } 65 | else 66 | { 67 | mInitResult = eIasOk; 68 | } 69 | 70 | mNativeResult = nativeResult; 71 | 72 | if (mutexAttrInitialized == true) 73 | { 74 | pthread_mutexattr_destroy(&mutexAttr); 75 | } 76 | } 77 | 78 | IasIntProcMutex::~IasIntProcMutex() 79 | { 80 | if (mInitResult == eIasOk) 81 | { 82 | int32_t result = pthread_mutex_destroy(&mMutex); 83 | // We don't care about the result. Just to make Klocwork happy. 84 | (void)result; 85 | } 86 | mInitResult = eIasNotInitialized; 87 | } 88 | 89 | IasIntProcMutex::IasResult IasIntProcMutex::lock() 90 | { 91 | if (mInitResult != eIasOk) 92 | { 93 | return mInitResult; 94 | } 95 | int32_t nativeResult = pthread_mutex_lock(&mMutex); 96 | mNativeResult = nativeResult; 97 | if (nativeResult == 0) 98 | { 99 | return eIasOk; 100 | } 101 | else if (nativeResult == EOWNERDEAD) 102 | { 103 | nativeResult = pthread_mutex_consistent(&mMutex); 104 | mNativeResult = nativeResult; 105 | if (nativeResult == 0) 106 | { 107 | nativeResult = pthread_mutex_unlock(&mMutex); 108 | mNativeResult = nativeResult; 109 | } 110 | else 111 | { 112 | return eIasMutexLockFailed; 113 | } 114 | 115 | if (nativeResult == 0) 116 | { 117 | nativeResult = pthread_mutex_lock(&mMutex); 118 | mNativeResult = nativeResult; 119 | } 120 | else 121 | { 122 | return eIasMutexLockFailed; 123 | } 124 | } 125 | else 126 | { 127 | return eIasMutexLockFailed; 128 | } 129 | return eIasOk; 130 | } 131 | 132 | IasIntProcMutex::IasResult IasIntProcMutex::trylock() 133 | { 134 | if (mInitResult != eIasOk) 135 | { 136 | return mInitResult; 137 | } 138 | int32_t nativeResult = pthread_mutex_trylock(&mMutex); 139 | mNativeResult = nativeResult; 140 | if (nativeResult == 0) 141 | { 142 | return eIasOk; 143 | } 144 | else if (nativeResult == EOWNERDEAD) 145 | { 146 | nativeResult = pthread_mutex_consistent(&mMutex); 147 | mNativeResult = nativeResult; 148 | if (nativeResult == 0) 149 | { 150 | nativeResult = pthread_mutex_unlock(&mMutex); 151 | mNativeResult = nativeResult; 152 | } 153 | else 154 | { 155 | return eIasMutexLockFailed; 156 | } 157 | 158 | if (nativeResult == 0) 159 | { 160 | nativeResult = pthread_mutex_trylock(&mMutex); 161 | mNativeResult = nativeResult; 162 | } 163 | else 164 | { 165 | return eIasMutexLockFailed; 166 | } 167 | } 168 | else 169 | { 170 | return eIasMutexLockFailed; 171 | } 172 | return eIasOk; 173 | } 174 | 175 | IasIntProcMutex::IasResult IasIntProcMutex::unlock() 176 | { 177 | if (mInitResult != eIasOk) 178 | { 179 | return mInitResult; 180 | } 181 | const int32_t nativeResult = pthread_mutex_unlock(&mMutex); 182 | mNativeResult = nativeResult; 183 | if (nativeResult != 0) 184 | { 185 | return eIasMutexUnlockFailed; 186 | } 187 | return eIasOk; 188 | } 189 | 190 | 191 | #define STRING_RETURN_CASE(name) case name: return std::string(#name); break 192 | #define DEFAULT_STRING(name) default: return std::string(name) 193 | 194 | __attribute__ ((visibility ("default"))) std::string toString(const IasIntProcMutex::IasResult& type) 195 | { 196 | switch(type) 197 | { 198 | STRING_RETURN_CASE(IasIntProcMutex::eIasOk); 199 | STRING_RETURN_CASE(IasIntProcMutex::eIasNotInitialized); 200 | STRING_RETURN_CASE(IasIntProcMutex::eIasMutexAttrInitFailed); 201 | STRING_RETURN_CASE(IasIntProcMutex::eIasMutexAttrSetpsharedFailed); 202 | STRING_RETURN_CASE(IasIntProcMutex::eIasMutexAttrSetrobustFailed); 203 | STRING_RETURN_CASE(IasIntProcMutex::eIasMutexAttrSetprotocolFailed); 204 | STRING_RETURN_CASE(IasIntProcMutex::eIasMutexInitFailed); 205 | STRING_RETURN_CASE(IasIntProcMutex::eIasMutexLockFailed); 206 | STRING_RETURN_CASE(IasIntProcMutex::eIasMutexUnlockFailed); 207 | DEFAULT_STRING("Invalid IasIntProcMutex::IasResult => " + std::to_string(type)); 208 | } 209 | } 210 | 211 | 212 | 213 | } /* namespace IasAudio */ 214 | -------------------------------------------------------------------------------- /public/inc/internal/audio/common/IasIntProcCondVar.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | /** 7 | * @file IasIntProcCondVar.hpp 8 | * @date 2016 9 | * @brief 10 | */ 11 | 12 | #ifndef IASINTPROCCONDVAR_HPP_ 13 | #define IASINTPROCCONDVAR_HPP_ 14 | 15 | #include 16 | 17 | #include "audio/common/IasAudioCommonTypes.hpp" 18 | 19 | namespace IasAudio { 20 | 21 | class IasIntProcMutex; 22 | 23 | /** 24 | * @brief This class provides the functionality of a process shared condition variable 25 | */ 26 | class __attribute__ ((visibility ("default"))) IasIntProcCondVar 27 | { 28 | public: 29 | /** 30 | * @brief The result type for the IasIntProcCondVar methods 31 | */ 32 | enum IasResult 33 | { 34 | eIasOk, //!< Operation successful 35 | eIasInvalidParam, //!< Invalid parameter, e.g. mutex==nullptr 36 | eIasNotInitialized, //!< Not initialized 37 | eIasCondAttrInitFailed, //!< pthread_condattr_init failed 38 | eIasCondAttrSetpsharedFailed, //!< pthread_condattr_setpshared failed 39 | eIasCondAttrSetclockFailed, //!< pthread_condattr_setclock failed 40 | eIasCondInitFailed, //!< pthread_cond_init failed 41 | eIasTimeout, //!< Timeout while waiting for condition variable 42 | eIasCondWaitFailed, //!< pthread_cond_wait failed 43 | eIasClockTimeNotAvailable, //!< Clock time not available 44 | eIasCondSignalFailed, //!< pthread_cond_signal failed 45 | }; 46 | 47 | /** 48 | * @brief Constructor 49 | */ 50 | IasIntProcCondVar(); 51 | 52 | /** 53 | * @brief Destructor 54 | */ 55 | virtual ~IasIntProcCondVar(); 56 | 57 | /** 58 | * @brief Wait for the condition variable to be signaled 59 | * 60 | * @param[in] mutex The mutex to be used for the condition variable 61 | * 62 | * @returns The status of this call or the error that occurred during initialization 63 | * @retval eIasOk Condition variable was signaled 64 | * @retval eIasInvalidParam Mutex not initialized 65 | * @retval eIasNotInitialized Not initialized 66 | * @retval eIasCondAttrInitFailed pthread_condattr_init failed 67 | * @retval eIasCondAttrSetpsharedFailed pthread_condattr_setpshared failed 68 | * @retval eIasCondAttrSetclockFailed pthread_condattr_setclock failed 69 | * @retval eIasCondInitFailed pthread_cond_init failed 70 | * @retval eIasCondWaitFailed pthread_cond_wait failed 71 | */ 72 | IasResult wait(IasIntProcMutex &mutex); 73 | 74 | /** 75 | * @brief Wait for the condition variable to be signaled for a certain time 76 | * 77 | * @param[in] mutex The mutex to be used for the condition variable 78 | * @param[in] time_ms timespan to wait at maximum for a condition variable 79 | * 80 | * @returns The status of the method call 81 | * @retval eIasOk Condition variable was signaled before timeout 82 | * @retval eIasInvalidParam Mutex not initialized 83 | * @retval eIasNotInitialized Not initialized 84 | * @retval eIasCondAttrInitFailed pthread_condattr_init failed 85 | * @retval eIasCondAttrSetpsharedFailed pthread_condattr_setpshared failed 86 | * @retval eIasCondAttrSetclockFailed pthread_condattr_setclock failed 87 | * @retval eIasCondInitFailed pthread_cond_init failed 88 | * @retval eIasTimeout Timeout while waiting for condition variable 89 | * @retval eIasCondWaitFailed pthread_cond_wait failed 90 | * @retval eIasClockTimeNotAvailable Clock time not available 91 | */ 92 | IasResult wait(IasIntProcMutex &mutex, uint64_t time_ms); 93 | 94 | /** 95 | * @brief Signal the condition variable 96 | * 97 | * @returns The status of this call or the error that occurred during initialization 98 | * @retval eIasOk Condition variable was signaled 99 | * @retval eIasInvalidParam Mutex not initialized 100 | * @retval eIasNotInitialized Not initialized 101 | * @retval eIasCondAttrInitFailed pthread_condattr_init failed 102 | * @retval eIasCondAttrSetpsharedFailed pthread_condattr_setpshared failed 103 | * @retval eIasCondAttrSetclockFailed pthread_condattr_setclock failed 104 | * @retval eIasCondInitFailed pthread_cond_init failed 105 | * @retval eIasCondSignalFailed pthread_cond_signal failed 106 | */ 107 | IasResult signal(); 108 | 109 | /** 110 | * @brief Return the native result of the pthread function calls 111 | * 112 | * This can be used for debugging purposes 113 | * 114 | * @returns The native error code from all pthread function calls 115 | */ 116 | inline int32_t nativeResult() const { return mNativeResult; } 117 | 118 | private: 119 | /** 120 | * @brief Copy constructor, private unimplemented to prevent misuse. 121 | */ 122 | IasIntProcCondVar(IasIntProcCondVar const &other); 123 | 124 | /** 125 | * @brief Assignment operator, private unimplemented to prevent misuse. 126 | */ 127 | IasIntProcCondVar& operator=(IasIntProcCondVar const &other); 128 | 129 | IasResult mInitResult; 130 | pthread_cond_t mCondVar; 131 | std::atomic mNativeResult; 132 | }; 133 | 134 | /** 135 | * @brief Function to get a IasIntProcCondVar::IasResult as string. 136 | * @return Enum Member as string 137 | */ 138 | std::string toString(const IasIntProcCondVar::IasResult& type); 139 | 140 | 141 | } /* namespace IasAudio */ 142 | 143 | #endif /* IASINTPROCCONDVAR_HPP_ */ 144 | -------------------------------------------------------------------------------- /public/inc/internal/audio/smartx_test_support/IasWavComp.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | /** 6 | * @file IasWavComp.hpp 7 | * @brief Compare two audio (WAVE) files, by calculating the difference. 8 | * @date 2016 9 | */ 10 | 11 | #ifndef IASWAVCOMP_HPP_ 12 | #define IASWAVCOMP_HPP_ 13 | 14 | #include 15 | #include 16 | 17 | 18 | 19 | namespace IasAudio { 20 | 21 | 22 | /** 23 | * @brief Read and compare audio files. 24 | */ 25 | class __attribute__ ((visibility ("default"))) IasWavComp 26 | { 27 | public: 28 | IasWavComp(); 29 | ~IasWavComp(); 30 | 31 | /*! 32 | * @brief The return values of the methods. 33 | */ 34 | enum IasResult 35 | { 36 | eIasOk, // 16 | #include 17 | #include 18 | 19 | 20 | 21 | namespace IasAudio { 22 | 23 | /*! 24 | * @brief Documentation for class IasFilterEstimator. 25 | * 26 | * This class implements an estimator for unknown filter impulse responses based on the NLMS algorithm. 27 | */ 28 | class __attribute__ ((visibility ("default"))) IasFilterEstimator 29 | { 30 | public: 31 | /*! 32 | * @brief Return type of most class methods. 33 | */ 34 | enum IasResult 35 | { 36 | eIasOk = 0, //!< Success 37 | eIasInvalidParameter, //!< Invalid parameter 38 | eIasOutOfMemory, //!< Out of memory 39 | eIasInitFailed, //!< Program is not initialized 40 | eIasAlreadyInitialized, //!< Already initialized 41 | eIasCorruptedFile, //!< File already closed or currupted 42 | eIasIdentificationIncommplete //!< System has not been identified (system distance is worse than specified threshold) 43 | }; 44 | 45 | IasFilterEstimator(); 46 | ~IasFilterEstimator(); 47 | 48 | /*! 49 | * @brief Prepare the filter estimator for operation. 50 | * 51 | * @param [in] input .wav file with clean input signal. 52 | * @param [in] output .wav file with filtered signal. 53 | * @param [in] errorSignal .wav file to write the residual error to. 54 | * @param [in] impulseResponse .wav file to write the estimated IR to. 55 | * @param [in] filterLength filter length of the estimated filter. 56 | * @return Result enum variable giving information about how successful the function call was. 57 | * @retval eIasOk Function call was successful. 58 | * @retval eIasInvalidParameter At least one input parameter was invald. 59 | * @retval eIasOutOfMemory Couldn't allocate enough memory. 60 | * @retval eIasAlreadyInitialized The filter estimator is already initialized. 61 | */ 62 | IasResult startUp(const std::string& input, 63 | const std::string& output, 64 | const std::string& errorSignal, 65 | const std::string& impulseResponse, 66 | uint32_t filterLength); 67 | 68 | /*! 69 | * @brief Shut down the filter estimator and free memory. 70 | * 71 | * @return Result enum variable giving information about how successful the function call was. 72 | * @retval eIasOk Function call was successful. 73 | * @retval eIasCorruptedFile An audio file couldn't be closed. 74 | */ 75 | IasResult shutDown(); 76 | 77 | /*! 78 | * @brief Performs a least mean square algorithm to estimate the filter. 79 | * 80 | * @param [in] threshold Threshold in dB for the residual error. If the residual error 81 | * deceeds the threshold, the program stops. 82 | * @param [out] estimated True if the filter has been estimated and the residual error 83 | * is beneath the given threshold. False otherwise. 84 | * 85 | * @return Result enum variable giving information whether the function call was successful. 86 | * @retval eIasOk System identification has been completed. 87 | * @retval eIasInitFailed Filter estimator has to be initialized first. 88 | * @retval eIasInvalidParameter Threshold exceeds limits. 89 | * @retval eIasIdentificationIncommplete System identification has not been completed (system distance above threshold). 90 | */ 91 | IasResult lms(float threshold); 92 | 93 | private: 94 | /*! 95 | * @brief Updates the internal state and the IR. 96 | * 97 | * @param [in] xHat Output sample from estimated filter. 98 | * @param [in] xTilde Output sample from real filter. 99 | * @param [in] channel Current channel operated on. 100 | * @return Mean of squared errors. 101 | */ 102 | float updateSystem(float xHat, float xTilde, uint32_t channel); 103 | 104 | /*! 105 | * @brief Filters the input signal with the estimated filter. 106 | * 107 | * @param [in] channel Current channel operated on. 108 | * @return Fitler result. 109 | */ 110 | float filterInput(uint32_t channel); 111 | 112 | bool mIsInitialized; //!< Result variable set to true after initialization. 113 | 114 | uint32_t mFilterLength; //!< Filter length of the estimated filter. 115 | uint32_t mNumChannels; //!< Number of channels. 116 | float *mFilter; //!< Array storing all filter coefficients. 117 | 118 | SNDFILE *mInputFile; //!< Pointer to input file. 119 | SNDFILE *mOutputFile; //!< Pointer to output file. 120 | SNDFILE *mErrorFile; //!< Pointer to error file. 121 | SNDFILE *mIRFile; //!< Pointer to IR file. 122 | 123 | float *mInputBuffer; //!< Ring buffer storing the input signal. 124 | float *mOutputSample; //!< Array storing last output sample for each channel. 125 | uint32_t mInputWrite; //!< Input ring buffers current write position. 126 | 127 | float *mSysDist; //!< Stores the last 32 residual errors for averaging purposes. 128 | float mAlpha; //!< Stepwidth of the LMS algorithm. 1.0 in this case, since no noise is applied. 129 | }; 130 | 131 | 132 | /** 133 | * @brief Function to get a IasFilterEstimator::IasResult as string. 134 | * 135 | * @return String carrying the result message. 136 | */ 137 | __attribute__ ((visibility ("default"))) std::string toString(const IasFilterEstimator::IasResult& type); 138 | 139 | 140 | } // namespace IasAudio 141 | 142 | #endif // IAS_FILTER_ESTIMATOR_HPP_ 143 | -------------------------------------------------------------------------------- /public/inc/internal/audio/common/samplerateconverter/IasSrcWrapper.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | /** 7 | * @file IasSrcWrapper.hpp 8 | * @brief Wrapper class for sample rate converter based on Farrow's structure. 9 | * @date 2016 10 | */ 11 | 12 | #ifndef IASSRCWRAPPER_HPP_ 13 | #define IASSRCWRAPPER_HPP_ 14 | 15 | #include "internal/audio/common/samplerateconverter/IasSrcWrapperBase.hpp" 16 | 17 | #include "internal/audio/common/IasAudioLogging.hpp" 18 | #include "audio/common/IasAudioCommonTypes.hpp" 19 | #include "internal/audio/common/samplerateconverter/IasSrcFarrow.hpp" 20 | #include 21 | 22 | namespace IasAudio 23 | { 24 | 25 | template 26 | class __attribute__ ((visibility ("default"))) IasSrcWrapper : public IasSrcWrapperBase 27 | { 28 | 29 | public: 30 | 31 | /** 32 | * @brief The maximum allowed sample rate 33 | */ 34 | const uint32_t cMaxSampleRate = 96000; 35 | 36 | /** 37 | * @brief The minimum allowed sample rate 38 | */ 39 | const uint32_t cMinSampleRate = 8000; 40 | 41 | 42 | IasSrcWrapper(); 43 | 44 | ~IasSrcWrapper(); 45 | 46 | /** 47 | * @brief Init function of sample rate converter wrapper 48 | * 49 | * @params[in] params the init parameter structure 50 | * @params[in] inArea pointer to the input area 51 | * @params[in] outArea pointer to the output area 52 | * 53 | * @returns error code 54 | * @retval eIasOk all went well 55 | * @retval eIasFailed an error occurred 56 | */ 57 | virtual IasSrcWrapperResult init(IasSrcWrapperParams ¶ms, 58 | const IasAudioArea* inArea, 59 | const IasAudioArea* outArea); 60 | 61 | /** 62 | * @brief Process function of sample rate converter wrapper 63 | * 64 | * @params[out] numGeneratedSamples Number of generated samples by the sample rate converter. 65 | * For pull mode, this should be constant for every process call 66 | * as long as there are enough input samples available 67 | * @params[out] numConsumedSamples Number of consumed samples by the sample rate converter. For pull mode, 68 | * this number can vary from call to call depending on the ratio. 69 | * @params[in] numInputSamples Number of available input samples. In pull mode, if there are not enough, the number 70 | * of generated samples will be smaller than desired. 71 | * @params[in] numOutputSamples For pull mode, this is the desired number of generated output samples 72 | * @param[in] srcOffset The position in the inArea, where the data samples will be taken from 73 | * @param[in] sinkOffset The position in the outArea, where the data samples will be written to 74 | * 75 | * @returns error code 76 | * @retval eIasOk all went well 77 | * @retval eIasFailed an error occurred 78 | */ 79 | virtual IasSrcWrapperResult process(uint32_t *numGeneratedSamples, 80 | uint32_t *numConsumedSamples, 81 | uint32_t numInputSamples, 82 | uint32_t numOutputSamples, 83 | uint32_t srcOffset, 84 | uint32_t sinkOffset); 85 | 86 | /** 87 | * @brief Reset function of sample rate converter wrapper 88 | * 89 | * @returns error code 90 | * @retval eIasOk all went well 91 | * @retval eIasFailed an error occurred 92 | */ 93 | virtual IasSrcWrapperResult reset(); 94 | 95 | private: 96 | /*! 97 | * @brief Copy constructor, private unimplemented to prevent misuse. 98 | */ 99 | IasSrcWrapper(IasSrcWrapper const &other); 100 | 101 | /*! 102 | * @brief Assignment operator, private unimplemented to prevent misuse. 103 | */ 104 | IasSrcWrapper& operator=(IasSrcWrapper const &other); 105 | 106 | /** 107 | * @brief Function to check paramters for errors 108 | * 109 | * @param[in] params The init parameter structure 110 | * 111 | * @returns error code 112 | * @retval eIasOk all went well 113 | * @retval eIasFailed an error occurred 114 | */ 115 | IasSrcWrapperResult checkParams(IasSrcWrapperParams *params) const; 116 | 117 | DltContext* mLog; //!< The log object 118 | const IasAudioArea* mInArea; //!< pointer to input IasAudioArea 119 | const IasAudioArea* mOutArea; //!< pointer to output IasAudioArea 120 | IasAudioCommonDataFormat mInputFormat; //!< input data format 121 | IasAudioCommonDataFormat mOutputFormat; //!< output data format 122 | uint32_t mInputSampleRate; //!< input data sample rate 123 | uint32_t mOutputSampleRate; //!< output data sample rate 124 | uint32_t mNumChannels; //!< the number of channels 125 | uint32_t mInputIndex; //!< start index of first input channel in inputArea 126 | uint32_t mOutputIndex; //!< start index of first output channel in outputArea 127 | uint32_t mInputStride; //!< step size to get to next sample of same input channel 128 | uint32_t mOutputStride; //!< step size to get to next sample of same output channel 129 | IasSrcFarrow* mSrc; //!< the sample rate converter object 130 | const T1** mSrcInputBuffers; //!< the vector with input buffer pointers used by sample rate converter 131 | T2** mSrcOutputBuffers; //!< the vector with output buffer pointers used by sample rate converter 132 | const T1** mSrcInputBuffersStatic; //!< the vector with static part of input buffer pointers used by sample rate converter 133 | T2** mSrcOutputBuffersStatic; //!< the vector with static part of output buffer pointers used by sample rate converter 134 | }; 135 | 136 | } 137 | #endif 138 | -------------------------------------------------------------------------------- /CMakeLists.common.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 Intel Corporation. All rights reserved. 2 | # 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | #------------------------------------------------ 6 | # Common Settings 7 | #------------------------------------------------ 8 | 9 | #------------------------------------------------ 10 | # ias-audio-common 11 | #------------------------------------------------ 12 | add_library( ias-audio-common SHARED 13 | private/src/common/IasAudioCommonTypes.cpp 14 | private/src/common/IasAudioLogging.cpp 15 | private/src/common/IasAlsaTypeConversion.cpp 16 | private/src/common/IasDataProbe.cpp 17 | private/src/common/IasDataProbeHelper.cpp 18 | private/src/common/IasIntProcCondVar.cpp 19 | private/src/common/IasIntProcMutex.cpp 20 | private/src/common/IasFdSignal.cpp 21 | private/src/common/IasCommonVersion.cpp 22 | 23 | private/src/alsa_smartx_plugin/IasAlsaPluginShmConnection.cpp 24 | 25 | private/src/audiobuffer/IasMemoryAllocator.cpp 26 | private/src/audiobuffer/IasMetaDataFactory.cpp 27 | private/src/audiobuffer/IasAudioRingBuffer.cpp 28 | private/src/audiobuffer/IasAudioRingBufferTypes.cpp 29 | private/src/audiobuffer/IasAudioRingBufferResult.cpp 30 | private/src/audiobuffer/IasAudioRingBufferReal.cpp 31 | private/src/audiobuffer/IasAudioRingBufferMirror.cpp 32 | private/src/audiobuffer/IasAudioRingBufferFactory.cpp 33 | 34 | private/src/samplerateconverter/IasSrcController.cpp 35 | private/src/samplerateconverter/IasSrcFarrow.cpp 36 | private/src/samplerateconverter/IasSrcFarrowFirFilter.cpp 37 | private/src/samplerateconverter/IasSrcWrapper.cpp 38 | 39 | private/src/helper/IasCopyAudioAreaBuffers.cpp 40 | private/src/helper/IasIRunnable.cpp 41 | private/src/helper/IasThread.cpp 42 | ) 43 | 44 | set_target_properties( ias-audio-common PROPERTIES VERSION ${AUDIO_COMMON_VERSION_STRING} SOVERSION ${AUDIO_COMMON_VERSION_MAJOR} ) 45 | 46 | find_package(PkgConfig) 47 | 48 | target_compile_options( ias-audio-common PUBLIC -ffast-math ) 49 | target_compile_options( ias-audio-common PUBLIC --std=c++11 ) 50 | target_compile_options( ias-audio-common PUBLIC -msse ) 51 | target_compile_options( ias-audio-common PUBLIC -msse2 ) 52 | target_compile_options( ias-audio-common PUBLIC -O3 ) 53 | 54 | # for version header 55 | target_include_directories( ias-audio-common PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ) 56 | 57 | target_include_directories( ias-audio-common PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/private/inc ) 58 | 59 | target_include_directories( ias-audio-common PUBLIC 60 | $ 61 | $ ) 62 | 63 | 64 | include_directories( ${DLT_INCLUDE_DIRS} ) 65 | 66 | pkg_check_modules(ASOUND REQUIRED alsa) 67 | pkg_check_modules(SNDFILE REQUIRED sndfile) 68 | pkg_check_modules(DLT REQUIRED automotive-dlt) 69 | pkg_check_modules(DLT REQUIRED automotive-dlt-c++) 70 | 71 | 72 | target_link_libraries( ias-audio-common tbb ) 73 | target_link_libraries( ias-audio-common boost_system ) 74 | target_link_libraries( ias-audio-common boost_filesystem ) 75 | 76 | target_link_libraries( ias-audio-common ${ASOUND_LDFLAGS} ) 77 | target_link_libraries( ias-audio-common ${SNDFILE_LDFLAGS} ) 78 | target_link_libraries( ias-audio-common ${DLT_LDFLAGS} ) 79 | 80 | target_compile_options( ias-audio-common PUBLIC ${ASOUND_CFLAGS_OTHER}) 81 | target_compile_options( ias-audio-common PUBLIC ${SNDFILE_CFLAGS_OTHER}) 82 | target_compile_options( ias-audio-common PUBLIC ${DLT_CFLAGS_OTHER}) 83 | 84 | target_include_directories( ias-audio-common PUBLIC ${ASOUND_INCLUDE_DIRS}) 85 | target_include_directories( ias-audio-common PUBLIC ${SNDFILE_INCLUDE_DIRS}) 86 | target_include_directories( ias-audio-common PUBLIC ${DLT_INCLUDE_DIRS}) 87 | 88 | 89 | 90 | install( TARGETS ias-audio-common EXPORT ias-audio-common 91 | LIBRARY 92 | DESTINATION ${CMAKE_INSTALL_LIBDIR} 93 | COMPONENT Libraries 94 | ) 95 | install( DIRECTORY public/inc/ DESTINATION include/avbaudiomodules 96 | PATTERN "smartx_test_support" EXCLUDE ) 97 | install( EXPORT ias-audio-common DESTINATION ${CMAKE_INSTALL_LIBDIR}/ias-audio-common ) 98 | 99 | #------------------------------------------------ 100 | # alsa-smartx-plugin (libasound_module_pcm_smartx) 101 | #------------------------------------------------ 102 | add_library( asound_module_pcm_smartx MODULE 103 | private/src/alsa_smartx_plugin/IasAlsaSmartXPlugin.cpp 104 | private/src/alsa_smartx_plugin/IasAlsaSmartXConnector.cpp 105 | ) 106 | 107 | target_compile_options( asound_module_pcm_smartx PUBLIC --std=c++11 ) 108 | target_compile_options( asound_module_pcm_smartx PUBLIC -fPIC ) 109 | target_compile_options( asound_module_pcm_smartx PUBLIC -DPIC ) 110 | 111 | target_include_directories( asound_module_pcm_smartx PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/private/inc ) 112 | 113 | target_link_libraries( asound_module_pcm_smartx asound ) 114 | target_link_libraries( asound_module_pcm_smartx ${DLT_LDFLAGS} ) 115 | target_link_libraries( asound_module_pcm_smartx ias-audio-common ) 116 | 117 | install( TARGETS asound_module_pcm_smartx EXPORT asound_module_pcm_smartx 118 | LIBRARY 119 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/alsa-lib 120 | COMPONENT Libraries 121 | ) 122 | install( FILES public/res/50-smartx.conf DESTINATION share/alsa/alsa.conf.d ) 123 | install( EXPORT asound_module_pcm_smartx DESTINATION ${CMAKE_INSTALL_LIBDIR}/ias-audio-common ) 124 | 125 | #------------------------------------------------ 126 | # alsa-smartx--rate-plugin (libasound_module_rate_smartx) 127 | #------------------------------------------------ 128 | # ALSA rate plugin libasound_module_rate_smartx.so. 129 | # This plugin represents the interface between ALSA and the sample rate converter 130 | # provided by the SmartXBar. 131 | #------------------------------------------------ 132 | add_library( asound_module_rate_smartx MODULE 133 | private/src/samplerateconverter/IasAlsa.cpp 134 | ) 135 | 136 | target_compile_options( asound_module_rate_smartx PUBLIC --std=c++11 ) 137 | 138 | target_link_libraries( asound_module_rate_smartx ias-audio-common ) 139 | 140 | install( TARGETS asound_module_rate_smartx EXPORT asound_module_rate_smartx 141 | LIBRARY 142 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/alsa-lib 143 | COMPONENT Libraries 144 | ) 145 | install( EXPORT asound_module_rate_smartx DESTINATION ${CMAKE_INSTALL_LIBDIR}/ias-audio-common ) 146 | 147 | -------------------------------------------------------------------------------- /public/inc/internal/audio/common/samplerateconverter/IasSrcController.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | /** 7 | * @file IasSrcController.hpp 8 | * @brief Closed loop controller for adapting the conversion ratio 9 | * of an asynchronous sample rate converter (ASRC). 10 | * @date 2015 11 | * 12 | * The ASRC controller adapts the conversion ratio in order to 13 | * compensate for the clock skew between the input clock domain and 14 | * the output clock domain. 15 | 16 | * The combination of this component and the core sample 17 | * rate converter IasSrcFarrow results in an asynchronous 18 | * sample rare converter. 19 | */ 20 | 21 | #ifndef IASSRCCONTROLLER_HPP_ 22 | #define IASSRCCONTROLLER_HPP_ 23 | 24 | #include "audio/common/IasAudioCommonTypes.hpp" 25 | 26 | namespace IasAudio { 27 | 28 | /*! 29 | * @brief Struct with all configuration parameters of the ASRC controller. 30 | * 31 | * A detailled description for these parameters can be found in the document 32 | */ 33 | typedef struct { 34 | float mKp; //!< proportional action coefficient ("Proportionalbeiwert") 35 | float mTn; //!< resert time ("Nachstellzeit") / Blocklength 36 | float mCoeffLowPass; //!< recursive coefficient (a1) of the 1st order low-pass filter 37 | float mRatioMin; //!< lower limit for the adaptive conversion ratio 38 | float mRatioMax; //!< upper limit for the adaptive conversion ratio 39 | } IasSrcControllerConfigParams; 40 | 41 | 42 | /***************************************************************************** 43 | * @brief Class IasSrcController 44 | ***************************************************************************** 45 | */ 46 | 47 | 48 | class __attribute__ ((visibility ("default"))) IasSrcController 49 | { 50 | public: 51 | 52 | /** 53 | * @brief Result type of the class IasSrcController. 54 | */ 55 | enum IasResult 56 | { 57 | eIasOk, //!< Ok, Operation successful 58 | eIasInvalidParam, //!< Invalid parameter, e.g., out of range or NULL pointer 59 | eIasInitFailed, //!< Initialization of the component failed 60 | eIasNotInitialized, //!< Component has not been initialized appropriately 61 | eIasFailed, //!< other error 62 | }; 63 | 64 | 65 | /*! 66 | * @brief Constructor. 67 | */ 68 | IasSrcController(); 69 | 70 | /*! 71 | * @brief Destructor. 72 | */ 73 | ~IasSrcController(); 74 | 75 | /*! 76 | * @brief Init function. 77 | * 78 | * @returns Error code. 79 | * @retval eIasOk Initialization successful 80 | * @retval eIasInitFailed Initailization failed (component is already initialized) 81 | */ 82 | IasResult init(); 83 | 84 | 85 | /*! 86 | * @brief Declare the parameters of the associated jitter buffer. 87 | * 88 | * @returns Error code. 89 | * @retval eIasOk Initialization successful 90 | * @retval eIasInvalidParam Invalid parameters (must not be zero) 91 | */ 92 | IasResult setJitterBufferParams(uint32_t jitterBufferLength, 93 | uint32_t jitterBufferTargetLevel); 94 | 95 | /*! 96 | * @brief Reset function. 97 | */ 98 | void reset(); 99 | 100 | /*! 101 | * @brief Process function of the (A)SRC closed loop controller: 102 | * 103 | * This function executes the (A)SRC closed loop controller in order to update 104 | * the adaptive conversion ratio. Furthermore, the controller updates the flag 105 | * @a outputActive, which indicates whether or not the framework shall transmit 106 | * samples from the jitter buffer to the output. 107 | * 108 | * The adaptive conversion ratio, which is updated by this function, is normalized 109 | * to the nominal conversion ratio. A value of 1.0 means that the sample rate 110 | * converter shall apply the nominal conversion ratio. In general, we have: 111 | * \verbatim 112 | * 113 | * fs_in fs_in_nominal 114 | * ------ = conversionRatioAdaptive * ----------------- 115 | * fs_out fs_ out_nominal 116 | * 117 | * \endverbatim 118 | * 119 | * @param[out] ratioAdaptive Normalized conversion ratio. 120 | * @param[out] outputActive Flag indicating whether samples shall be 121 | * streamed from the jitter buffer to the output. 122 | * If outputActive is false, dummy samples shall 123 | * be generated instead. 124 | * @param[in] jitterBufferCurrentLevel Number of samples that are currently buffered 125 | * within the jitter buffer at the output of the 126 | * asynchronous sample rate converter. 127 | * 128 | * @returns Error code. 129 | * @retval eIasOk Operation successful 130 | * @retval eIasNotInitialized Component not initialized (missing call of init() or setJitterBufferParams()) 131 | */ 132 | IasResult process(float *ratioAdaptive, 133 | bool *outputActive, 134 | uint32_t jitterBufferCurrentLevel); 135 | 136 | protected: 137 | /* 138 | * member variables 139 | */ 140 | bool mIsInitialized; 141 | 142 | float mRatioAdaptive; // conversion ratio, adapted by this module 143 | float mOutputLowPassOld; // previous sample of the 1st order low-pass filter output signal 144 | float mOutputController; // output signal of the PI controller 145 | 146 | bool mOutputActive; 147 | 148 | uint32_t mJitterBufferLength; 149 | uint32_t mJitterBufferTargetLevel; 150 | float mInvJitterBufferTargetLevel; // 1.0 / mJitterBufferTargetLevel 151 | 152 | IasSrcControllerConfigParams mConfigParams; 153 | }; 154 | 155 | 156 | /** 157 | * @brief Function to get a IasSrcController::IasResult as string. 158 | * 159 | * @return String carrying the result message. 160 | */ 161 | __attribute__ ((visibility ("default"))) std::string toString(const IasSrcController::IasResult& type); 162 | 163 | 164 | } // namespace IasAudio 165 | 166 | #endif // IASSRCCONTROLLER_HPP_ 167 | -------------------------------------------------------------------------------- /public/inc/internal/audio/common/IasIntProcMutex.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | /** 7 | * @file IasIntProcMutex.hpp 8 | * @date 2016 9 | * @brief 10 | */ 11 | 12 | #ifndef IASINTPROCMUTEX_HPP_ 13 | #define IASINTPROCMUTEX_HPP_ 14 | 15 | #include 16 | 17 | #include "audio/common/IasAudioCommonTypes.hpp" 18 | 19 | 20 | namespace IasAudio { 21 | 22 | /** 23 | * @brief This class provides the functionality of a process shared mutex 24 | */ 25 | class __attribute__ ((visibility ("default"))) IasIntProcMutex 26 | { 27 | public: 28 | /** 29 | * @brief The result type for the IasIntProcMutex methods 30 | */ 31 | enum IasResult 32 | { 33 | eIasOk, //!< Operation successful 34 | eIasNotInitialized, //!< Not initialized 35 | eIasMutexAttrInitFailed, //!< pthread_mutexattr_init failed 36 | eIasMutexAttrSetpsharedFailed, //!< pthread_mutexattr_setpshared failed 37 | eIasMutexAttrSetrobustFailed, //!< pthread_mutexattr_setrobust failed 38 | eIasMutexAttrSetprotocolFailed, //!< pthread_mutexattr_setprotocol failed 39 | eIasMutexInitFailed, //!< pthread_mutex_init failed 40 | eIasMutexLockFailed, //!< pthread_mutex_lock failed 41 | eIasMutexUnlockFailed, //!< pthread_mutex_unlock failed 42 | }; 43 | 44 | /** 45 | * @brief Constructor 46 | */ 47 | IasIntProcMutex(); 48 | 49 | /** 50 | * @brief Destructor 51 | */ 52 | virtual ~IasIntProcMutex(); 53 | 54 | /** 55 | * @brief Lock the mutex 56 | * 57 | * @returns The status of this call or the error that occurred during initialization 58 | * @retval eIasOk Mutex was locked 59 | * @retval eIasNotInitialized Not initialized 60 | * @retval eIasMutexAttrInitFailed pthread_mutexattr_init failed 61 | * @retval eIasMutexAttrSetpsharedFailed pthread_mutexattr_setpshared failed 62 | * @retval eIasMutexAttrSetrobustFailed pthread_mutexattr_setrobust failed 63 | * @retval eIasMutexAttrSetprotocolFailed pthread_mutexattr_setprotocol failed 64 | * @retval eIasMutexInitFailed pthread_cond_init failed 65 | * @retval eIasMutexLockFailed pthread_mutex_lock failed 66 | */ 67 | IasResult lock(); 68 | 69 | /** 70 | * @brief Try to lock the mutex 71 | * 72 | * Return immediately without waiting for the mutex to be available. 73 | * 74 | * @returns The status of this call or the error that occurred during initialization 75 | * @retval eIasOk Mutex was locked 76 | * @retval eIasNotInitialized Not initialized 77 | * @retval eIasMutexAttrInitFailed pthread_mutexattr_init failed 78 | * @retval eIasMutexAttrSetpsharedFailed pthread_mutexattr_setpshared failed 79 | * @retval eIasMutexAttrSetrobustFailed pthread_mutexattr_setrobust failed 80 | * @retval eIasMutexAttrSetprotocolFailed pthread_mutexattr_setprotocol failed 81 | * @retval eIasMutexInitFailed pthread_cond_init failed 82 | * @retval eIasMutexLockFailed pthread_mutex_lock failed 83 | */ 84 | IasResult trylock(); 85 | 86 | /** 87 | * @brief Unlock the mutex 88 | * 89 | * @returns The status of this call or the error that occurred during initialization 90 | * @retval eIasOk Mutex was unlocked 91 | * @retval eIasNotInitialized Not initialized 92 | * @retval eIasMutexAttrInitFailed pthread_mutexattr_init failed 93 | * @retval eIasMutexAttrSetpsharedFailed pthread_mutexattr_setpshared failed 94 | * @retval eIasMutexAttrSetrobustFailed pthread_mutexattr_setrobust failed 95 | * @retval eIasMutexAttrSetprotocolFailed pthread_mutexattr_setprotocol failed 96 | * @retval eIasMutexInitFailed pthread_cond_init failed 97 | * @retval eIasMutexUnlockFailed pthread_mutex_unlock failed 98 | */ 99 | IasResult unlock(); 100 | 101 | /** 102 | * @brief Get the native handle of the mutex 103 | * 104 | * @returns The native handle of the mutex 105 | */ 106 | inline pthread_mutex_t* nativeHandle() { return &mMutex; } 107 | 108 | /** 109 | * @brief Return the native result of the pthread function calls 110 | * 111 | * This can be used for debugging purposes 112 | * 113 | * @returns The native error code from all pthread function calls 114 | */ 115 | inline int32_t nativeResult() const { return mNativeResult; } 116 | 117 | private: 118 | /** 119 | * @brief Copy constructor, private unimplemented to prevent misuse. 120 | */ 121 | IasIntProcMutex(IasIntProcMutex const &other); 122 | 123 | /** 124 | * @brief Assignment operator, private unimplemented to prevent misuse. 125 | */ 126 | IasIntProcMutex& operator=(IasIntProcMutex const &other); 127 | 128 | IasResult mInitResult; 129 | pthread_mutex_t mMutex; 130 | std::atomic mNativeResult; 131 | }; 132 | 133 | /** 134 | * @brief Function to get a IasIntProcMutex::IasResult as string. 135 | * @return Enum Member as string 136 | */ 137 | std::string toString(const IasIntProcMutex::IasResult& type); 138 | 139 | 140 | /** 141 | * @brief Lock guard according to RAII idiom for the IasIntProcMutex 142 | */ 143 | class __attribute__ ((visibility ("default"))) IasLockGuard 144 | { 145 | public: 146 | /** 147 | * @brief Constructor 148 | * 149 | * Locks the mutex given via parameter 150 | * 151 | * @param[in] mutex 152 | */ 153 | explicit IasLockGuard(IasIntProcMutex *mutex) 154 | :mMutex(mutex) 155 | { 156 | IasIntProcMutex::IasResult mutres = mMutex->lock(); 157 | IAS_ASSERT(mutres == IasIntProcMutex::eIasOk); 158 | (void)mutres; 159 | } 160 | 161 | /** 162 | * @brief Destructor 163 | * 164 | * Unlocks the mutex given to constructor as parameter 165 | */ 166 | ~IasLockGuard() 167 | { 168 | IasIntProcMutex::IasResult mutres = mMutex->unlock(); 169 | IAS_ASSERT(mutres == IasIntProcMutex::eIasOk); 170 | (void)mutres; 171 | } 172 | 173 | /** 174 | * @brief Delete copy constructor 175 | */ 176 | IasLockGuard(IasLockGuard const &) = delete; 177 | /** 178 | * @brief Delete assignment operator 179 | */ 180 | IasLockGuard& operator=(IasLockGuard const &) = delete; 181 | 182 | private: 183 | IasIntProcMutex *mMutex; 184 | }; 185 | 186 | } /* namespace IasAudio */ 187 | 188 | #endif /* IASINTPROCMUTEX_HPP_ */ 189 | -------------------------------------------------------------------------------- /private/src/common/IasAudioCommonTypes.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | /** 7 | * @file IasAudioCommonTypes.cpp 8 | * @date 2015 9 | * @brief 10 | */ 11 | 12 | #include "audio/common/IasAudioCommonTypes.hpp" 13 | 14 | 15 | namespace IasAudio { 16 | 17 | #define STRING_RETURN_CASE(name) case name: return std::string(#name); break 18 | #define DEFAULT_STRING(name) default: return std::string(name) 19 | 20 | __attribute__ ((visibility ("default"))) IasAudioCommonResult __attribute__((warn_unused_result)) ias_safe_memcpy(void * dest, size_t dest_size, const void * source, size_t source_size) 21 | { 22 | size_t copy_length = source_size; 23 | 24 | if ((NULL == dest) || (NULL == source)) 25 | { 26 | return eIasResultInvalidParam; 27 | } 28 | 29 | if (((char*)source < ((char*)dest + dest_size)) && ((char*)dest < ((char*)source + source_size))) 30 | { 31 | return eIasResultMemoryError; 32 | } 33 | if (dest_size < source_size) 34 | { 35 | copy_length = dest_size; 36 | } 37 | 38 | (void)memcpy(dest, source,copy_length); 39 | 40 | return eIasResultOk; 41 | } 42 | 43 | __attribute__ ((visibility ("default"))) std::string toString(const IasAudioPinLinkType& type) 44 | { 45 | switch(type) 46 | { 47 | STRING_RETURN_CASE(IasAudioPinLinkType::eIasAudioPinLinkTypeImmediate); 48 | STRING_RETURN_CASE(IasAudioPinLinkType::eIasAudioPinLinkTypeDelayed); 49 | DEFAULT_STRING("IasAudioPinLinkType::eIasAudioPinLinkTypeInvalid"); 50 | } 51 | } 52 | 53 | __attribute__ ((visibility ("default"))) std::string toString ( const IasAudioCommonDataLayout& type ) 54 | { 55 | switch(type) 56 | { 57 | STRING_RETURN_CASE(eIasLayoutNonInterleaved); 58 | STRING_RETURN_CASE(eIasLayoutInterleaved); 59 | STRING_RETURN_CASE(eIasLayoutUndef); 60 | DEFAULT_STRING("eIasLayoutInvalid"); 61 | } 62 | } 63 | 64 | __attribute__ ((visibility ("default"))) std::string toString ( const IasAudioCommonAccess& type) 65 | { 66 | switch(type) 67 | { 68 | STRING_RETURN_CASE(eIasAccessUndef); 69 | STRING_RETURN_CASE(eIasAccessMmap); 70 | STRING_RETURN_CASE(eIasAccessRw); 71 | DEFAULT_STRING("eIasAccessInvalid"); 72 | } 73 | } 74 | 75 | __attribute__ ((visibility ("default"))) std::string toString ( const IasAudioCommonDataFormat& type ) 76 | { 77 | switch(type) 78 | { 79 | STRING_RETURN_CASE(eIasFormatFloat32); 80 | STRING_RETURN_CASE(eIasFormatInt16); 81 | STRING_RETURN_CASE(eIasFormatInt32); 82 | STRING_RETURN_CASE(eIasFormatUndef); 83 | DEFAULT_STRING("eIasFormatInvalid"); 84 | } 85 | } 86 | 87 | __attribute__ ((visibility ("default"))) std::string toString(const IasPortDirection& type) 88 | { 89 | switch(type) 90 | { 91 | STRING_RETURN_CASE(eIasPortDirectionUndef); 92 | STRING_RETURN_CASE(eIasPortDirectionInput); 93 | STRING_RETURN_CASE(eIasPortDirectionOutput); 94 | DEFAULT_STRING("eIasPortDirectionInvalid"); 95 | } 96 | } 97 | 98 | __attribute__ ((visibility ("default"))) std::string toString(const IasDeviceType& type) 99 | { 100 | switch(type) 101 | { 102 | STRING_RETURN_CASE(eIasDeviceTypeUndef); 103 | STRING_RETURN_CASE(eIasDeviceTypeSource); 104 | STRING_RETURN_CASE(eIasDeviceTypeSink); 105 | DEFAULT_STRING("eIasDeviceTypeInvalid"); 106 | } 107 | } 108 | 109 | 110 | __attribute__ ((visibility ("default"))) int32_t toSize(const IasAudioCommonDataFormat& type) 111 | { 112 | switch(type) 113 | { 114 | case eIasFormatFloat32: 115 | case eIasFormatInt32: 116 | return 4; 117 | break; 118 | case eIasFormatInt16: 119 | return 2; 120 | break; 121 | case eIasFormatUndef: 122 | default: 123 | return -1; 124 | } 125 | } 126 | 127 | __attribute__ ((visibility ("default"))) std::string toString ( const IasAudioCommonResult& type ) 128 | { 129 | switch(type) 130 | { 131 | STRING_RETURN_CASE(eIasResultOk); 132 | STRING_RETURN_CASE(eIasResultInitFailed); 133 | STRING_RETURN_CASE(eIasResultInvalidParam); 134 | STRING_RETURN_CASE(eIasResultNotInitialized); 135 | STRING_RETURN_CASE(eIasResultMemoryError); 136 | STRING_RETURN_CASE(eIasResultTimeOut); 137 | STRING_RETURN_CASE(eIasResultCondWaitMutexOwn); 138 | STRING_RETURN_CASE(eIasResultCondWaitParam); 139 | STRING_RETURN_CASE(eIasResultUnknown); 140 | STRING_RETURN_CASE(eIasResultObjectNotFound); 141 | STRING_RETURN_CASE(eIasResultClockDomainRate); 142 | STRING_RETURN_CASE(eIasResultInvalidSampleSize); 143 | STRING_RETURN_CASE(eIasResultObjectAlreadyExists); 144 | STRING_RETURN_CASE(eIasResultInvalidShmPath); 145 | STRING_RETURN_CASE(eIasResultBufferEmpty); 146 | STRING_RETURN_CASE(eIasResultBufferFull); 147 | STRING_RETURN_CASE(eIasResultAlreadyInitialized); 148 | STRING_RETURN_CASE(eIasResultNotAllowed); 149 | STRING_RETURN_CASE(eIasResultAlsaError); 150 | STRING_RETURN_CASE(eIasResultCRCError); 151 | STRING_RETURN_CASE(eIasResultInvalidSegmentSize); 152 | DEFAULT_STRING("eIasResultInvalid"); 153 | } 154 | } 155 | 156 | __attribute__ ((visibility ("default"))) std::string toString ( const IasClockType& type ) 157 | { 158 | switch(type) 159 | { 160 | STRING_RETURN_CASE(eIasClockProvided); 161 | STRING_RETURN_CASE(eIasClockReceived); 162 | STRING_RETURN_CASE(eIasClockReceivedAsync); 163 | STRING_RETURN_CASE(eIasClockUndef); 164 | DEFAULT_STRING("eIasClockInvalid"); 165 | } 166 | } 167 | 168 | __attribute__ ((visibility ("default"))) std::string toString ( const IasRingbufferType& type ) 169 | { 170 | switch(type) 171 | { 172 | STRING_RETURN_CASE(eIasRingBufferShared); 173 | STRING_RETURN_CASE(eIasRingBufferLocalMirror); 174 | STRING_RETURN_CASE(eIasRingBufferLocalReal); 175 | STRING_RETURN_CASE(eIasRingBufferUndef); 176 | DEFAULT_STRING("eIasRingBufferInvalid"); 177 | } 178 | } 179 | 180 | __attribute__ ((visibility ("default"))) std::string toString ( const IasRingBufferAccess& type ) 181 | { 182 | switch(type) 183 | { 184 | STRING_RETURN_CASE(eIasRingBufferAccessRead); 185 | STRING_RETURN_CASE(eIasRingBufferAccessWrite); 186 | STRING_RETURN_CASE(eIasRingBufferAccessUndef); 187 | DEFAULT_STRING("eIasRingBufferAccessInvalid"); 188 | } 189 | } 190 | 191 | __attribute__ ((visibility ("default"))) std::string toString ( const IasAudioArea& type ) 192 | { 193 | return std::string("IasAudioArea:") + " .start=" + std::to_string((unsigned long)type.start) + 194 | ", .first=" + std::to_string(type.first) + ", .step=" + std::to_string(type.step) + 195 | ", .index=" + std::to_string(type.index) + ", .maxIndex=" + std::to_string(type.maxIndex); 196 | } 197 | 198 | #undef STRING_RETURN_CASE 199 | #undef DEFAULT_STRING 200 | 201 | } // namespace IasAudio 202 | -------------------------------------------------------------------------------- /public/inc/internal/audio/common/alsa_smartx_plugin/IasAlsaPluginShmConnection.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | 6 | */ 7 | 8 | /** 9 | * @file IasAlsaPluginShmConnection.hpp 10 | * @date Oct 7, 2015 11 | * @version 0.1 12 | * @brief Defines a strucuture that contains all the modules that 13 | * are needed for a connection between the smartx and the smartx Plugin. 14 | * 15 | */ 16 | #ifndef IAS_ALSAPLUGIN_SHMCONNECTION_HPP_ 17 | #define IAS_ALSAPLUGIN_SHMCONNECTION_HPP_ 18 | 19 | #include "audio/common/IasAudioCommonTypes.hpp" 20 | #include "internal/audio/common/IasFdSignal.hpp" 21 | 22 | 23 | namespace IasAudio 24 | { 25 | 26 | struct IasAlsaHwConstraintsStatic; 27 | class IasAudioIpc; 28 | class IasMemoryAllocator; 29 | class IasAudioRingBuffer; 30 | 31 | class __attribute__ ((visibility ("default"))) IasAlsaPluginShmConnection 32 | { 33 | public: 34 | /** 35 | * @brief Constructor inits the struct with invalid pointers. 36 | * 37 | */ 38 | IasAlsaPluginShmConnection(); 39 | 40 | /** 41 | * @brief Destructor, will delete the allocator if the class was the creator of it. 42 | * Will delete the AudioBuffer too if it was the creator. 43 | */ 44 | ~IasAlsaPluginShmConnection(); 45 | 46 | /** 47 | * @brief Creates a connection for offering to the IasAlsaSmartXConnector. Creates all needed structures. 48 | * 49 | * The group id of the shared memory files created in /dev/shm will be set to ias_audio as default value. It can 50 | * be overwritten to any valid group name of the executing process. In case the group does not exist, the creation 51 | * will fail. 52 | * 53 | * @param[in] connectionName Name of the connection, will be refered by the asound configuration of the smartx plugin. 54 | * @param[in] groupName Name of the group id of the created shared memory files in /dev/shm 55 | * @return IasAudio::IasAudioCommonResult cOk is good. 56 | */ 57 | IasAudioCommonResult createConnection ( const std::string& connectionName, const std::string& groupName = "ias_audio" ); 58 | 59 | /** 60 | * @brief Function to replace the old ring buffer or create a new one with the given parameters. 61 | * 62 | * @param[in] configStruct Configuration of the ring buffer. Not all values are needed only 63 | * period size, period number, channel number and format is used. 64 | * @return IasAudio::IasAudioCommonResult IasResultOk if good 65 | * @return IasAudio::IasAudioCommonResult Results are returned from the factory create function. 66 | */ 67 | IasAudioCommonResult createRingBuffer ( const IasAudioDeviceParamsPtr configStruct ); 68 | 69 | /** 70 | * @brief Function to search for a created connection. 71 | * 72 | * @param[in] connectionName Reference name for the connection. 73 | * @return IasAudio::IasAudioCommonResult 74 | */ 75 | IasAudioCommonResult findConnection ( const std::string& connectionName ); 76 | 77 | /** 78 | * @brief The connection gets destroyed if the class gets destructed. 79 | * 80 | */ 81 | //IasAudioCommonResult destroyConnection(const std::string& connectionName); 82 | 83 | /** 84 | * @brief Gets a pointer to the IPC connection. This IPC connection is 85 | * unidirectional. If the Structure was initialized with create the connection is 86 | * from smartx plugin to smartx. When initialized with find, the returned ipc is smartx 87 | * to smartx plugin. 88 | * 89 | * @return IasAudioIpc* Pointer to the IPC queue. 90 | */ 91 | inline IasAudioIpc* getInIpc() 92 | { 93 | return mInIpc; 94 | } 95 | 96 | /** 97 | * @brief Gets a pointer to the IPC connection. This IPC connection is 98 | * unidirectional. If the Structure was initialized with create the connection is 99 | * from smartx to smartx plugin. When initialized with find, the returned ipc is 100 | * smartx plugin to smartx. 101 | * 102 | * @return IasAudioIpc* Pointer to the IPC queue. 103 | */ 104 | inline IasAudioIpc* getOutIpc() 105 | { 106 | return mOutIpc; 107 | } 108 | 109 | /** 110 | * @brief Get a pointer to the hardware constraints, that belongs to this 111 | * connection. 112 | * 113 | * @return IasAlsaHwConstraintsStatic* Ponter to the Hardware Constraints structure. 114 | */ 115 | inline IasAlsaHwConstraintsStatic* getAlsaHwConstraints() 116 | { 117 | return mConstraints; 118 | } 119 | 120 | /** 121 | * @brief Verify if the update Flag is set. 122 | * Gets a pointer to the RingBuffer holding the sample areas for the different channels. 123 | * 124 | * @return IasAudioRingBuffer* Pointer to the RingBuffer Instance. 125 | */ 126 | IasAudioRingBuffer* verifyAndGetRingBuffer(); 127 | 128 | /** 129 | * @brief Gets a pointer to the RingBuffer holding the sample areas for the different channels. 130 | * 131 | * @return IasAudioRingBuffer* Pointer to the RingBuffer Instance. 132 | */ 133 | inline IasAudioRingBuffer* getRingBuffer() 134 | { 135 | return mRingBuffer; 136 | } 137 | 138 | private: 139 | 140 | /** 141 | * @brief Copy constructor, private unimplemented to prevent misuse. 142 | */ 143 | IasAlsaPluginShmConnection(IasAlsaPluginShmConnection const &other); 144 | 145 | /** 146 | * @brief Assignment operator, private unimplemented to prevent misuse. 147 | */ 148 | IasAlsaPluginShmConnection& operator=(IasAlsaPluginShmConnection const &other); 149 | 150 | 151 | DltContext *mLog; //!< DLT Log context 152 | IasAudioIpc *mInIpc; //!< IPC Connection from smartx to the alsa plugin. 153 | IasAudioIpc *mOutIpc; //!< IPC Connection from the alsa plugin to the smartx. 154 | IasAlsaHwConstraintsStatic *mConstraints; //!< Contains the Hardware constrains that are read by the Plugin. Valid flag must be set in the constraints. 155 | std::string mRingBufferName; //!< Name of the Ringbuffer 156 | IasAudioRingBuffer *mRingBuffer; //!< Instance of a Ringbuffer. 157 | bool *mUpdateAvailable; //!< Pointer to a central flag that marks if there was a change of the ringbuffer 158 | IasMemoryAllocator *mAllocator; //!< Allocator that allocates or find the instances of the connection. 159 | bool mIsCreator; //!< Bool flag if the class was the creator of the resources. If true, the class will delete the shm region in the destructor. 160 | IasFdSignal mFdSignal; //!< Signal buffer level changes using file descriptors. 161 | std::string mConnectionName; //!< The connection name. 162 | std::string mGroupName; //!< The group name. 163 | }; 164 | 165 | } 166 | 167 | #endif /* IAS_ALSAPLUGIN_SHMCONNECTION_HPP_ */ 168 | -------------------------------------------------------------------------------- /private/src/samplerateconverter/IasSrcController.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | /** 7 | * @file IasSrcController.cpp 8 | * @brief Closed loop controller for adapting the conversion ratio 9 | * of an asynchronous sample rate converter (ASRC). 10 | * @date 2015 11 | * 12 | * Closed loop controller for adapting the sample rate conversion ratio 13 | * in order to compensate for the clock skew between the input clock 14 | * domain and the output clock domain. 15 | * 16 | * The combination of this component and the core sample rate converter 17 | * IasSrcFarrow results in an asynchronous sample rare converter (ASRC). 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include "internal/audio/common/samplerateconverter/IasSrcController.hpp" 26 | 27 | #ifdef __linux__ 28 | #define MS_VC 0 29 | #else 30 | #define MS_VC 1 31 | #endif 32 | 33 | 34 | namespace IasAudio { 35 | 36 | static const IasSrcControllerConfigParams cConfigParamsDefault = { 37 | 0.008f, // mKp proportional action coefficient ("Proportionalbeiwert") 38 | 300.0f, // mTn = Tn / Tb resert time ("Nachstellzeit") / Blocklength 39 | 0.9f, // mCoeffLowPass 40 | 0.9f, // mRatioMin 41 | 1.1f, // mRatioMax 42 | }; 43 | 44 | 45 | /** 46 | * @brief Constructor 47 | * 48 | * All member variables that are not initialized by the constructor will be 49 | * initialized by the methods init() and reset(). The flag mIsInitialized 50 | * assures that the init() and reset() methods must be executed before the 51 | * process() method can be used. 52 | */ 53 | IasSrcController::IasSrcController() 54 | :mIsInitialized(false) 55 | ,mRatioAdaptive(0.0f) // the actual initializations are done by the init() method 56 | ,mOutputLowPassOld(0.0f) 57 | ,mOutputController(0.0f) 58 | ,mOutputActive(false) 59 | ,mJitterBufferLength(0) // the actual initializations are done by the setJitterBufferParams() method 60 | ,mJitterBufferTargetLevel(0) 61 | ,mInvJitterBufferTargetLevel(0) 62 | { 63 | // Fill the configuration parameter struct with default parameters. 64 | mConfigParams = cConfigParamsDefault; 65 | } 66 | 67 | 68 | /** 69 | * @brief Destructor 70 | */ 71 | IasSrcController::~IasSrcController() 72 | { 73 | } 74 | 75 | 76 | /** 77 | * @brief Init function 78 | */ 79 | IasSrcController::IasResult IasSrcController::init() 80 | { 81 | if (mIsInitialized) 82 | { 83 | return eIasInitFailed; 84 | } 85 | 86 | // Fill the configuration parameter struct with default parameters. 87 | mConfigParams = cConfigParamsDefault; 88 | 89 | mIsInitialized = true; 90 | 91 | // Call the reset function 92 | this->reset(); 93 | 94 | return eIasOk; 95 | } 96 | 97 | 98 | /** 99 | * @brief Declare the parameters of the associated jitter buffer. 100 | */ 101 | IasSrcController::IasResult IasSrcController::setJitterBufferParams(uint32_t jitterBufferLength, 102 | uint32_t jitterBufferTargetLevel) 103 | { 104 | if ((jitterBufferLength == 0) || (jitterBufferTargetLevel == 0)) 105 | { 106 | return eIasInvalidParam; 107 | } 108 | 109 | mJitterBufferLength = jitterBufferLength; 110 | mJitterBufferTargetLevel = jitterBufferTargetLevel; 111 | mInvJitterBufferTargetLevel = 1.0f / static_cast(jitterBufferTargetLevel); 112 | 113 | return eIasOk; 114 | } 115 | 116 | 117 | /** 118 | * @brief Reset function. 119 | */ 120 | void IasSrcController::reset() 121 | { 122 | mRatioAdaptive = 1.0f; 123 | mOutputLowPassOld = 0.0f; 124 | mOutputController = 0.0f; 125 | mOutputActive = false; 126 | } 127 | 128 | 129 | /** 130 | * @brief Process the controller in order to update the adaptive conversion 131 | * ratio. Furthermore, the controller updates the flag outputActive, 132 | * which indicates whether or not the framework shall transmit samples 133 | * from the jitter buffer to the output. 134 | */ 135 | IasSrcController::IasResult IasSrcController::process(float *ratioAdaptive, 136 | bool *outputActive, 137 | uint32_t jitterBufferCurrentLevel) 138 | { 139 | // Exit this function if it has not been initialized appropriately. 140 | if ((!mIsInitialized) || 141 | (mJitterBufferLength == 0) || 142 | (mJitterBufferTargetLevel == 0)) 143 | { 144 | return eIasNotInitialized; 145 | } 146 | 147 | // State machine for controlling mOutputActive depending on the current fill level 148 | if (jitterBufferCurrentLevel > mJitterBufferTargetLevel) 149 | { 150 | mOutputActive = true; 151 | } 152 | else if (jitterBufferCurrentLevel == 0) 153 | { 154 | mOutputActive = false; 155 | } 156 | 157 | if (mOutputActive) 158 | { 159 | // difference between the target fill level and current fill level 160 | float diff = (static_cast(jitterBufferCurrentLevel) - 161 | static_cast(mJitterBufferTargetLevel)) * mInvJitterBufferTargetLevel; 162 | 163 | // output signal of the 1st order low-pass filter 164 | float outputLowPass = (1.0f - mConfigParams.mCoeffLowPass) * diff + mConfigParams.mCoeffLowPass * mOutputLowPassOld; 165 | 166 | // PI Controller, according to Latzel "Einführung in die Digitalen Regelungen", eq. (3.2.45) 167 | mOutputController = (mOutputController 168 | + mConfigParams.mKp * (1.0f+0.5f/mConfigParams.mTn) * outputLowPass 169 | - mConfigParams.mKp * (1.0f-0.5f/mConfigParams.mTn) * mOutputLowPassOld); 170 | 171 | mOutputLowPassOld = outputLowPass; 172 | mRatioAdaptive = 1.0f + mOutputController; 173 | 174 | // Saturate mRatioAdaptive, such that the result is within the interval [mRatioMin...mRatioMax]. 175 | mRatioAdaptive = std::min(mRatioAdaptive, mConfigParams.mRatioMax); 176 | mRatioAdaptive = std::max(mRatioAdaptive, mConfigParams.mRatioMin); 177 | } 178 | 179 | *ratioAdaptive = mRatioAdaptive; 180 | *outputActive = mOutputActive; 181 | 182 | return eIasOk; 183 | } 184 | 185 | 186 | /* 187 | * Function to get a IasSrcController::IasResult as string. 188 | */ 189 | #define STRING_RETURN_CASE(name) case name: return std::string(#name); break 190 | #define DEFAULT_STRING(name) default: return std::string(name) 191 | std::string toString(const IasSrcController::IasResult& type) 192 | { 193 | switch(type) 194 | { 195 | STRING_RETURN_CASE(IasSrcController::eIasOk); 196 | STRING_RETURN_CASE(IasSrcController::eIasInvalidParam); 197 | STRING_RETURN_CASE(IasSrcController::eIasInitFailed); 198 | STRING_RETURN_CASE(IasSrcController::eIasNotInitialized); 199 | DEFAULT_STRING("Invalid IasSrcController::IasResult => " + std::to_string(type)); 200 | } 201 | } 202 | 203 | 204 | } // namespace IasAudio 205 | -------------------------------------------------------------------------------- /public/inc/internal/audio/common/IasAudioLogging.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Intel Corporation.All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | /** 7 | * @file IasAudioLogging.hpp 8 | * @date 2013 9 | * @brief The definition of the IasAudioLogging class. 10 | */ 11 | 12 | #ifndef IASAUDIOLOGGING_HPP_ 13 | #define IASAUDIOLOGGING_HPP_ 14 | 15 | #include 16 | #include 17 | #include 18 | //#include "audio/common/IasAudioCommonTypes.hpp" 19 | 20 | using namespace std; 21 | 22 | namespace IasAudio { 23 | 24 | /** 25 | * @class IasAudioLogging 26 | * 27 | * This class combines commonly used audio chain parameters that every component of the audio chain would need. 28 | * An instance of this environment class exists once per audio chain. 29 | */ 30 | class __attribute__ ((visibility ("default"))) IasAudioLogging 31 | { 32 | public: 33 | /** 34 | * @brief Destructor, virtual by default. 35 | */ 36 | virtual ~IasAudioLogging(); 37 | 38 | 39 | /*! 40 | * @brief Method to register the Application to dlt 41 | * 42 | * @returns void 43 | */ 44 | static void registerDltApp(bool enableConsoleLog); 45 | 46 | 47 | /*! 48 | * @brief Getter method to get a dlt context by a given name 49 | * 50 | * @param[in] contextId The context id that you want to get 51 | * @returns The dlt context 52 | */ 53 | static DltContext * getDltContext(const std::string contextId); 54 | 55 | /*! 56 | * @brief register a new dlt context 57 | * 58 | * @param[in] context_id Id of the context to register 59 | * @param[in] context_description Description to the context 60 | * @returns The dlt context 61 | */ 62 | static DltContext* registerDltContext(const std::string context_id, 63 | const char * context_description); 64 | 65 | /*! 66 | * @ brief add a context to the list only with a id, log level and trace status. this is needed to set the 67 | * log level for specific context at startup. these levels will be sued to register the context afterwards 68 | * @param[in] contextId Id of the context to add 69 | * @param[in] loglevel loglevel of the context to add 70 | * @param[in] tracestatus tracestatus of the context to add 71 | * @returns void 72 | */ 73 | static void addDltContextItem(const std::string contextId, DltLogLevelType loglevel, DltTraceStatusType tracestatus); 74 | 75 | /** 76 | * @brief Setter method for the log level 77 | * 78 | * @param[in] loglevel The global log level for the dlt. 79 | */ 80 | static void setDltLogLevel(DltLogLevelType loglevel); 81 | 82 | /** 83 | * @brief Getter method for the log level 84 | * 85 | * @returns The global dlt log level. 86 | */ 87 | static DltLogLevelType getDltLogLevel(); 88 | 89 | /** 90 | * @brief Setter method for the trace status 91 | * 92 | * @param[in] tracestatus The global trace status for the dlt. 93 | */ 94 | static void setDltTraceStatus(DltTraceStatusType tracestatus); 95 | 96 | /** 97 | * @brief Getter method for the log level 98 | * 99 | * @returns The global dlt log level. 100 | */ 101 | static DltTraceStatusType getDltTraceStatus(); 102 | 103 | 104 | private: 105 | 106 | /** 107 | * @brief Constructor. 108 | */ 109 | IasAudioLogging(); 110 | 111 | /*! 112 | * @brief Documentation for class DltContextMapEntry 113 | */ 114 | class DltContextMapEntry 115 | { 116 | public: 117 | /*! 118 | * @brief Constructor. 119 | */ 120 | inline DltContextMapEntry() 121 | :mDltTraceStatus(DLT_TRACE_STATUS_OFF) 122 | ,mDltLogLevel(DLT_LOG_ERROR) 123 | ,mDltContext(NULL) 124 | {}; 125 | 126 | /*! 127 | * @brief Destructor, virtual by default. 128 | */ 129 | virtual ~DltContextMapEntry(){}; 130 | 131 | /*! 132 | * @brief set the dlt trace status 133 | * @param dltTraceStatus trace status 134 | */ 135 | inline void setDltTraceStatus(DltTraceStatusType dltTraceStatus) { mDltTraceStatus = dltTraceStatus; } 136 | 137 | /*! 138 | * 139 | * @return The trace status 140 | */ 141 | inline DltTraceStatusType getDltTraceStatus() const { return mDltTraceStatus; } 142 | 143 | 144 | /*! 145 | * @brief set the dlt log level 146 | * @param dltTraceStatus trace status 147 | */ 148 | inline void setDltLogLevel(DltLogLevelType dltLogLevel) { mDltLogLevel = dltLogLevel; } 149 | 150 | /*! 151 | * 152 | * @return The log level 153 | */ 154 | inline DltLogLevelType getDltLogLevel() const { return mDltLogLevel; } 155 | 156 | /*! 157 | * @brief set the dlt context 158 | * @param dltTraceStatus trace status 159 | */ 160 | inline void setDltContext(DltContext * dltcontext) { mDltContext = dltcontext; } 161 | 162 | /*! 163 | * 164 | * @return The Dlt context 165 | */ 166 | inline DltContext * getDltContext() const { return mDltContext; } 167 | 168 | 169 | private: 170 | /*! 171 | * @brief Copy constructor, private unimplemented to prevent misuse. 172 | */ 173 | DltContextMapEntry(DltContextMapEntry const &other); 174 | 175 | /*! 176 | * @brief Assignment operator, private unimplemented to prevent misuse. 177 | */ 178 | DltContextMapEntry& operator=(DltContextMapEntry const &other); 179 | 180 | DltTraceStatusType mDltTraceStatus; //!< the global trace status 181 | DltLogLevelType mDltLogLevel; //!< the global log level 182 | DltContext *mDltContext; //!< the Dlt logging context 183 | 184 | 185 | }; 186 | typedef std::map DltContextMap; 187 | 188 | /** 189 | * @brief Copy constructor, private unimplemented to prevent misuse. 190 | */ 191 | IasAudioLogging(IasAudioLogging const &other); 192 | 193 | /** 194 | * @brief Assignment operator, private unimplemented to prevent misuse. 195 | */ 196 | IasAudioLogging& operator=(IasAudioLogging const &other); 197 | 198 | static IasAudioLogging *audioLoggingInstance(); 199 | 200 | // Member variables 201 | DltContextMap mDltContextMap; //!< A list of all Dlt contexts 202 | std::mutex mMutex; //!< Mutex to guard access to the context map 203 | 204 | //instance 205 | static DltContextMap & getMap(); 206 | static std::mutex& getMutex(); 207 | }; 208 | 209 | } //namespace IasAudio 210 | 211 | #endif /* IASAUDIOLOGGING_HPP_ */ 212 | -------------------------------------------------------------------------------- /CMakeLists.src_delivery.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 Intel Corporation. All rights reserved. 2 | # 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | # Specify a name for the source entity, suggestion is to use _source 6 | IasInitEntity( audio common_source "" ) 7 | # Define the path where the sources will be installed, you have to use //src 8 | IasSetEntityInstallPrefix( "audio/common/src" ) 9 | 10 | # This the copyright text for files which use '#' for commenting lines, e.g. CMakeLists 11 | string(REPLACE "\n" "\n# " numberSignCopyrightTag "${IAS_COPYRIGHT_TAG}") 12 | # This the copyright text for files which use '/* */' for commenting lines, e.g. C/C++ source and header files 13 | string(REPLACE "\n" "\n * " codeCopyrightTag "${IAS_COPYRIGHT_TAG}") 14 | set(codeCopyrightTag " *\n * ${codeCopyrightTag}" ) 15 | 16 | # This lists all files that use '#' for comments 17 | # Leave out all CMakeLists that will be exchanged by adapted version. For that, use the list below 18 | IasAddFiles(CMAKELISTS_INSTALL_FILES ${CMAKE_CURRENT_SOURCE_DIR} 19 | CMakeLists.common.txt 20 | ) 21 | 22 | # This lists all files that use '#' for comments and will be replaced by adapted files 23 | # This applies to all CMakeLists that make use of a generator (stub and skeleton side) 24 | IasAddFiles(CMAKELISTS_REPLACEMENT_FILES ${CMAKE_CURRENT_SOURCE_DIR}/private/res 25 | CMakeLists.txt 26 | ) 27 | 28 | # This list holds all header and source files (public and private) 29 | IasAddFiles(CODE_INSTALL_FILES ${CMAKE_CURRENT_SOURCE_DIR} 30 | 31 | PREFIX ./public/inc/internal/audio/common 32 | IasAlsaTypeConversion.hpp 33 | IasAudioLogging.hpp 34 | IasCommonVersion.hpp 35 | IasDataProbe.hpp 36 | IasDataProbeHelper.hpp 37 | IasFdSignal.hpp 38 | IasIntProcCondVar.hpp 39 | IasIntProcMutex.hpp 40 | PREFIX ./public/inc/internal/audio/common/helper 41 | IasCopyAudioAreaBuffers.hpp 42 | PREFIX ./public/inc/internal/audio/common/samplerateconverter 43 | IasSrcWrapperBase.hpp 44 | IasSrcController.hpp 45 | IasSrcFarrow.hpp 46 | IasSrcWrapper.hpp 47 | PREFIX ./public/inc/internal/audio/common/alsa_smartx_plugin 48 | IasAlsaHwConstraintsStatic.hpp 49 | IasSmartXPluginIpcStructures.hpp 50 | IasAlsaPluginShmConnection.hpp 51 | IasAlsaHwConstraintsDynamic.hpp 52 | IasAlsaPluginIpc.hpp 53 | PREFIX ./public/inc/internal/audio/common/audiobuffer 54 | IasAudioIpcProtocolMacro.hpp 55 | IasAudioRingBufferFactory.hpp 56 | IasAudioRingBuffer.hpp 57 | IasAudioRingBufferReal.hpp 58 | IasAudioRingBufferResult.hpp 59 | IasAudioIpcProtocolHead.hpp 60 | IasAudioRingBufferMirror.hpp 61 | IasAudioRingBufferTypes.hpp 62 | IasAudioIpcMessageContainer.hpp 63 | IasAudioIpc.hpp 64 | IasAudioIpcProtocolTail.hpp 65 | PREFIX ./public/inc/audio/common 66 | IasAudioCommonTypes.hpp 67 | PREFIX ./public/inc/audio/common/audiobuffer 68 | IasMetaDataFactory.hpp 69 | IasMemoryAllocator.hpp 70 | IasMetaData.hpp 71 | IasUserMetaDataFactory.hpp 72 | PREFIX ./public/res 73 | 50-smartx.conf 74 | PREFIX ./private/inc/samplerateconverter 75 | IasSrcFarrowConfig.hpp 76 | IasSrcFarrowFirFilter.hpp 77 | PREFIX ./private/inc/alsa_smartx_plugin 78 | IasAlsaSmartXConnector.hpp 79 | PREFIX ./private/src/helper 80 | IasCopyAudioAreaBuffers.cpp 81 | PREFIX ./private/src/common 82 | IasCommonVersion.cpp 83 | IasAudioLogging.cpp 84 | IasAudioCommonTypes.cpp 85 | IasFdSignal.cpp 86 | IasDataProbe.cpp 87 | IasIntProcMutex.cpp 88 | IasAlsaTypeConversion.cpp 89 | IasDataProbeHelper.cpp 90 | IasIntProcCondVar.cpp 91 | PREFIX ./private/src/samplerateconverter 92 | IasSrcFarrowFirFilter.cpp 93 | IasSrcFarrow.cpp 94 | IasAlsa.cpp 95 | IasSrcController.cpp 96 | IasSrcWrapper.cpp 97 | PREFIX ./private/src/samplerateconverter/coeffSrcFarrow 98 | IasSrcFarrow_coeff_12000Hz_to_48000Hz.h 99 | IasSrcFarrow_param_44100Hz_to_16000Hz.h 100 | IasSrcFarrow_coeff_32000Hz_to_48000Hz.h 101 | IasSrcFarrow_param_48000Hz_to_22050Hz.h 102 | IasSrcFarrow_coeff_48000Hz_to_24000Hz.h 103 | IasSrcFarrow_param_16000Hz_to_48000Hz.h 104 | IasSrcFarrow_param_48000Hz_to_48000Hz.h 105 | IasSrcFarrow_param_48000Hz_to_24000Hz.h 106 | IasSrcFarrow_coeff_48000Hz_to_16000Hz.h 107 | IasSrcFarrow_coeff_24000Hz_to_08000Hz.h 108 | IasSrcFarrow_coeff_48000Hz_to_22050Hz.h 109 | IasSrcFarrow_param_08000Hz_to_48000Hz.h 110 | IasSrcFarrow_param_22050Hz_to_48000Hz.h 111 | IasSrcFarrow_coeff_22050Hz_to_48000Hz.h 112 | IasSrcFarrow_coeff_48000Hz_to_08000Hz.h 113 | IasSrcFarrow_coeff_08000Hz_to_48000Hz.h 114 | IasSrcFarrow_param_24000Hz_to_48000Hz.h 115 | IasSrcFarrow_param_48000Hz_to_44100Hz.h 116 | IasSrcFarrow_param_24000Hz_to_08000Hz.h 117 | IasSrcFarrow_param_48000Hz_to_08000Hz.h 118 | IasSrcFarrow_param_24000Hz_to_16000Hz.h 119 | IasSrcFarrow_coeff_44100Hz_to_16000Hz.h 120 | IasSrcFarrow_param_44100Hz_to_48000Hz.h 121 | IasSrcFarrow_coeff_48000Hz_to_11025Hz.h 122 | IasSrcFarrow_coeff_24000Hz_to_48000Hz.h 123 | IasSrcFarrow_coeff_44100Hz_to_48000Hz.h 124 | IasSrcFarrow_coeff_24000Hz_to_16000Hz.h 125 | IasSrcFarrow_coeff_48000Hz_to_32000Hz.h 126 | IasSrcFarrow_param_48000Hz_to_11025Hz.h 127 | IasSrcFarrow_param_48000Hz_to_12000Hz.h 128 | IasSrcFarrow_coeff_48000Hz_to_48000Hz.h 129 | IasSrcFarrow_coeff_11025Hz_to_48000Hz.h 130 | IasSrcFarrow_param_48000Hz_to_16000Hz.h 131 | IasSrcFarrow_coeff_16000Hz_to_48000Hz.h 132 | IasSrcFarrow_param_12000Hz_to_48000Hz.h 133 | IasSrcFarrow_param_32000Hz_to_48000Hz.h 134 | IasSrcFarrow_coeff_48000Hz_to_44100Hz.h 135 | IasSrcFarrow_param_11025Hz_to_48000Hz.h 136 | IasSrcFarrow_coeff_48000Hz_to_12000Hz.h 137 | IasSrcFarrow_param_48000Hz_to_32000Hz.h 138 | PREFIX ./private/src/alsa_smartx_plugin 139 | IasAlsaSmartXConnector.cpp 140 | IasAlsaPluginShmConnection.cpp 141 | IasAlsaSmartXPlugin.cpp 142 | PREFIX ./private/src/audiobuffer 143 | IasAudioRingBufferReal.cpp 144 | IasAudioRingBufferMirror.cpp 145 | IasAudioRingBufferFactory.cpp 146 | IasAudioRingBufferResult.cpp 147 | IasMetaDataFactory.cpp 148 | IasAudioRingBufferTypes.cpp 149 | IasMemoryAllocator.cpp 150 | IasAudioRingBuffer.cpp 151 | ) 152 | 153 | # This holds all other files that do not need any replacement of the copyright header 154 | IasAddFiles(PLAIN_INSTALL_FILES ${CMAKE_CURRENT_SOURCE_DIR} 155 | 156 | PREFIX public/res 157 | 50-smartx.conf 158 | ) 159 | 160 | # 161 | # From here on comes the real installation of the files 162 | # 163 | # This is for the source files 164 | IasInstallFilesImpl( "${CMAKE_CURRENT_SOURCE_DIR}" "" "" base ${CODE_INSTALL_FILES} COPYRIGHT_TAG ${codeCopyrightTag}) 165 | 166 | # This is for the CMakeLists (COPYRIGHT_TAG must be handled differently than _normal_ source files) 167 | IasInstallFilesImpl( "${CMAKE_CURRENT_SOURCE_DIR}" "" "" base ${CMAKELISTS_INSTALL_FILES} COPYRIGHT_TAG ${numberSignCopyrightTag}) 168 | 169 | # This is to _overwrite_ cmake files and replace the COPYRIGHT_TAG 170 | IasInstallFilesImpl( "${CMAKE_CURRENT_SOURCE_DIR}/private/res" "" "" base ${CMAKELISTS_REPLACEMENT_FILES} COPYRIGHT_TAG ${numberSignCopyrightTag}) 171 | 172 | # This is for everything else 173 | IasInstallFilesImpl( "${CMAKE_CURRENT_SOURCE_DIR}" "" "" base ${PLAIN_INSTALL_FILES}) 174 | 175 | IasBuildEntity() 176 | --------------------------------------------------------------------------------