{"id":4905,"date":"2019-06-18T01:11:38","date_gmt":"2019-06-17T23:11:38","guid":{"rendered":"https:\/\/demdlx704as001.ad.harman.com\/index.php\/section\/audio-object-example-templatewin32-cpp\/"},"modified":"2024-05-13T12:42:39","modified_gmt":"2024-05-13T10:42:39","slug":"audio-object-example-templatewin32-cpp","status":"publish","type":"post","link":"https:\/\/audioworx.transfunnel.co\/old\/?p=4905","title":{"rendered":"Example 2 &#8211; AwxAudioObjExtToolbox.cpp"},"content":{"rendered":"<pre>\/*!\r\n*   \\file      AwxAudioObjExtToolbox.cpp\r\n*   \\brief     AwxAudioObjExt Toolbox Source file\r\n*   \\details   Implements the AwxAudioObjExt signal design API\r\n*   \\details   Project    Extendable Audio Framework\r\n*   \\copyright Harman\/Becker Automotive Systems GmbH\r\n*   \r\n       2020\r\n*   \r\n       All rights reserved\r\n*   \\author    xAF Team\r\n*\/\r\n\r\n\/*!\r\n*   xaf mandataory includes to handle the toolbox related data\r\n*\/\r\n#include \"AwxAudioObjExtToolbox.h\"\r\n#include \"XafXmlHelper.h\"\r\n#include \"AudioObjectProperties.h\"\r\n#include \"AwxAudioObjExt.h\"\r\n#include \"XafMacros.h\"\r\n#include \"AudioObject.h\"\r\n\r\n\r\n\r\n\/\/ the revision number may be different for specific targets\r\n#define MIN_REQUIRED_XAF_VERSION            (RELEASE_U)\r\n\/\/ mode specific defines\r\n#define AUDIO_IN_OUT_MIN                    (1)\r\n#define AUDIO_IN_OUT_MAX                    (255)\r\n#define EST_MEMORY_CONSUMPTION_NA           (0)         \/\/ memory consuption not available\/measured\r\n#define EST_CPU_LOAD_CONSUMPTION_NA         (0.f) \/\/ cpu load not available\/measured\r\n#define CONTROL_GAIN_MAX                   (30.0f)\r\n#define CONTROL_GAIN_MIN                   (-128.0f)\r\n#define CONTROL_GAIN_IN_LABEL              \"Gain\"\r\n#define MAX_CONFIG_MIN_GAIN_dB              (-12.0f)\r\n#define MAX_CONFIG_MAX_GAIN_dB              (30.0f)\r\n#define MAX_GAIN_DEFAULT_GAIN_dB            (10.0f)\r\n\r\nCAwxAudioObjExtToolbox::CAwxAudioObjExtToolbox()\r\n{\r\n}\r\n\r\nCAwxAudioObjExtToolbox::~CAwxAudioObjExtToolbox()\r\n{\r\n}\r\n\r\nstatic CAudioObjectToolbox::additionalSfdVarDescription theVar;\r\nconst CAwxAudioObjExtToolbox::additionalSfdVarDescription* CAwxAudioObjExtToolbox::getAdditionalSfdVarsDescription(xUInt32 index)\r\n\r\n{\r\n    CAudioObjectToolbox::additionalSfdVarDescription* ptr = &amp;theVar;\r\n    static CAudioObjectToolbox::MinMaxDefault addVar1 = { MAX_CONFIG_MIN_GAIN_dB ,MAX_CONFIG_MAX_GAIN_dB ,MAX_GAIN_DEFAULT_GAIN_dB }; \/\/Min,max,default values for additional config variable\r\n    static CAudioObjectToolbox::MinMaxDefault addVar2 = { 0, 1, 0 }; \/\/Min,max,default values\r\n    \r\n    static CAudioObjectToolbox::addVarsSize m_AddtionalVarSize1[NUM_DIMENSION_VAR] =\r\n    {\r\n        \/\/ size, label, start index, increment\r\n        {1, \"Max Gain per channel(dB)\", 0, 1}\r\n    };\r\n    static CAudioObjectToolbox::addVarsSize m_AddtionalVarSize2[NUM_DIMENSION_VAR] =\r\n    {\r\n        \/\/ size, label, start index, increment\r\n        {1, \"Disable: 0\\nEnable  : 1\", 0, 1}\r\n    };\r\n\r\n     if (index == 0)\r\n     {\r\n       theVar.mP_Label = \"Max Gain per channel\";\r\n       theVar.m_DataType = xAF_FLOAT_32;\r\n       theVar.mP_RangeSet = &amp;addVar1;\r\n       theVar.m_Dimension = 1;\r\n       theVar.m_DataOrder = xAF_NONE;\r\n       \/\/size varies according to the number of channels\r\n       m_AddtionalVarSize1[0].m_Size = static_cast(m_NumAudioIn);\r\n       theVar.mP_MaddVarsSize = m_AddtionalVarSize1;\r\n     }\r\n     else if (index == 1)\r\n     {\r\n         theVar.mP_Label = \"Abstracted Tuning Memory\";\r\n         theVar.m_DataType = xAF_UCHAR;\r\n         theVar.mP_RangeSet = &amp;addVar2;\r\n         theVar.m_Dimension = 1;\r\n         theVar.m_DataOrder = xAF_NONE;\r\n         theVar.mP_MaddVarsSize = m_AddtionalVarSize2;\r\n     }\r\n     else\r\n     {\r\n         \/* Invalid index. Return NULL *\/\r\n         ptr = NULL;\r\n     }\r\n     return ptr;\r\n}\r\n\r\n\r\nconst CAudioObjectToolbox::tObjectDescription* CAwxAudioObjExtToolbox::getObjectDescription()\r\n{\r\n    static const CAudioObjectToolbox::tObjectDescription descriptions =\r\n    {\r\n        1, 1, 0, 0, \"AwxAudioObjExt\", \"Simple Object to start with for 3rd party\/external objects integration\", \"External\", AWX_EXT_NUM_ADD_VARS, AWX_EXT_NUM_MODES\r\n    };\r\n    return &amp;descriptions;\r\n}\r\n\r\n\r\nconst CAudioObjectToolbox::tModeDescription* CAwxAudioObjExtToolbox::getModeDescription(xUInt32 mode)\r\n{\r\n    static const CAudioObjectToolbox::tModeDescription modeDescription[AWX_EXT_NUM_MODES] =\r\n    {\r\n        {\"Gain\", \"No control input\", 0, 0, \"\", CFG_NCHANNEL},\r\n        {\"GainWithControl\", \"One gain control input pin gets added\", 0, 0, \"\", CFG_NCHANNEL},\r\n    };\r\n    return (mode &lt; (sizeof(modeDescription) \/ sizeof(tModeDescription))) ? &amp;modeDescription[mode] : static_cast&lt;tModeDescription*&gt;(NULL);\r\n}\r\n\r\n\r\nxAF_Error CAwxAudioObjExtToolbox::getObjectIo(ioObjectConfigOutput* configOut)\r\n{\r\n    if (static_cast(GAIN_WITH_CONTROL) == m_Mode)\r\n    {\r\n        configOut-&gt;numControlIn = 1;\r\n        configOut-&gt;numControlOut = 0;\r\n    }\r\n    else \r\n    {\r\n        configOut-&gt;numControlIn = 0;\r\n        configOut-&gt;numControlOut = 0;\r\n    }\r\n\r\n    return xAF_SUCCESS;\r\n}\r\n\r\n\r\nxUInt32 CAwxAudioObjExtToolbox::getXmlObjectTemplate(tTuningInfo* info, xInt8* buffer, xUInt32 maxLen)\r\n{\r\n    initiateNewBufferWrite(buffer, maxLen);\r\n    \r\n    \/\/ add your tuning parameters here in order to show up in the tuning tool\r\n    \/\/ the number of params specified here, depends on the number to be tuned in GTT\r\n    \/\/ in this example we are exposing the tuning parameters as arrays split into 2 subblocks\r\n\r\n    \/\/template 1\r\n    xSInt32 numAudioIn = static_cast(m_NumAudioIn);\r\n    xSInt32 blockID = info-&gt;Global_Object_Count; \/\/ uniq to this instance\r\n    xUInt32 id = 0;\r\n\r\n    for (xSInt32 i = 0; i &lt; numAudioIn; i++)\r\n    {\r\n        \/\/Max value for each channel to show up shall be specified by this function\r\n        xFloat32 gainval = getMaxGain(i);\r\n        xAFOpenLongXMLTag(\"Object\");\r\n        string templateName = string(\"\").append(\"AwxAudioObjExtTuneTemplate\").append(xAFIntToString(i + 1)).append(xAFIntToString(blockID));\r\n        xAFAddFieldToXMLTag(\"Key\", templateName.c_str());\r\n        xAFEndLongXMLTag();\r\n        xAFWriteQuickXmlTag(\"ExplorerIcon\", \"Object\");\r\n        xAFWriteXmlTag(\"StateVariables\", XML_OPEN);\r\n        xAFWriteStateVariable(\"Gain\",                   \/\/ name                \r\n            id,                                         \/\/ id\r\n            NULL,                                       \/\/ control law\r\n            \"dB\",                                       \/\/ unit type\r\n            DataTypes[xAF_FLOAT],                       \/\/ data type\r\n            -128.0,                                     \/\/ min\r\n            gainval,                                    \/\/ max\r\n            0.0,                                        \/\/ default\r\n            0u,                                         \/\/ offset\r\n            NULL,                                       \/\/ encode value\r\n            NULL,                                       \/\/ decode value\r\n            DataTypeConverters[xAF_FLOAT],              \/\/ bit converter\r\n            false                                       \/\/ disable streaming\r\n        );\r\n        id++;\r\n\r\n        xAFWriteStateVariable(\"Mute\",                    \/\/ name                \r\n            id,                                          \/\/ id\r\n            NULL,                                        \/\/ control law\r\n            NULL,                                        \/\/ unit type\r\n            DataTypes[xAF_UINT],                         \/\/ data type\r\n            0.0,                                         \/\/ min\r\n            1.0,                                         \/\/ max\r\n            0.0,                                         \/\/ default\r\n            4u,                                          \/\/ offset\r\n            NULL,                                        \/\/ encode value\r\n            NULL,                                        \/\/ decode value\r\n            DataTypeConverters[xAF_UINT],                \/\/ bit converter\r\n            false                                        \/\/ disable streaming\r\n        );\r\n        id++;\r\n\r\n        xAFWriteXmlTag(\"StateVariables\", XML_CLOSE);\r\n        xAFWriteXmlTag(\"Object\", XML_CLOSE);\r\n\r\n    }\r\n\r\n    \/\/template 2\r\n    \/\/It shall be shown up in the State Variable Explorer if through additional configuration \"Abstracted Tuning Memory\" is set to 1 or enabled.\r\n    if (static_cast(ENABLE_BLOCK) == m_EnMemory)\r\n    {\r\n        xAFOpenLongXMLTag(\"Object\");\r\n        xAFAddFieldToXMLTag(\"Key\", \"AwxAudioObjExtArrayTemplate\");\r\n        xAFEndLongXMLTag();\r\n        xAFWriteQuickXmlTag(\"ExplorerIcon\", \"Object\");\r\n        xAFWriteXmlTag(\"StateVariables\", XML_OPEN);\r\n        xAFWriteStateVariableBuffer(\/* name = *\/ \"FloatArray\",\r\n            \/* id = *\/ id,\r\n            \/* type = *\/ FLOATARRAY_SV,\r\n            \/* size = *\/ FLOAT_ARRAY_SIZE,\r\n            \/* streamIdx = *\/ id,\r\n            \/* minVal = *\/ -1000.0,\r\n            \/* maxVal = *\/ 1000.0,\r\n            \/* defaultVal = *\/ 0.0,\r\n            \/* offset = *\/ 0,\r\n            \/* isStreamable = *\/ false);\r\n        \r\n        xAFWriteXmlTag(\"StateVariables\", XML_CLOSE);\r\n        xAFWriteXmlTag(\"Object\", XML_CLOSE);\r\n    }\r\n    return finishWritingToBuffer();\r\n}\r\n\r\n\r\nxUInt32 CAwxAudioObjExtToolbox::getXmlFileInfo(tTuningInfo* info, xInt8* buffer, xUInt32 maxLen)\r\n{\r\n    initiateNewBufferWrite(buffer, maxLen);\r\n    xUInt32 hiqnetInc = 0u;\r\n    xUInt8  subBlock = 0u;\r\n    xSInt32 blockID = info-&gt;Global_Object_Count; \/\/ uniq to this instance\r\n\r\n    xAFWriteObject(info-&gt;Name, static_cast(info-&gt;Global_Object_Count), hiqnetInc, static_cast(info-&gt;HiQNetVal), 0);\r\n\r\n    xAFWriteXmlTag(\"Objects\", XML_OPEN);\r\n    xSInt32 numAudioIn = static_cast(m_NumAudioIn); \/\/ m_NumAudioIn == m_NumAudioOut\r\n    \r\n    xAFWriteXmlObjectContainer(\"Gains\", hiqnetInc, subBlock, PARAM_CATEGORY);\r\n    xAFWriteXmlTag(\"Objects\", XML_OPEN);\r\n    for(xSInt32 i = 0; i &lt; numAudioIn; i++)\r\n    {        \r\n        string templateName = string(\"\").append(\"AwxAudioObjExtTuneTemplate\").append(xAFIntToString(i+1)).append(xAFIntToString(blockID));\r\n        xAFWriteXmlObjectTemplateInstance(templateName.c_str(), string(\"Ch\").append(xAFIntToString(i+1)).c_str(), i * 8, 1 + i); \r\n        \/\/ 8 is related here to the internal memory layout where a \"state\/tuning\" is related to a block of N-bytes and withing this needs to be offset\r\n        hiqnetInc++;\r\n    }\r\n    xAFWriteXmlTag(\"Objects\", XML_CLOSE);\r\n    xAFWriteXmlTag(\"Object\", XML_CLOSE); \/\/gains\r\n\r\n    if (static_cast(ENABLE_BLOCK) == m_EnMemory)\r\n    {        \r\n        xAFWriteXmlObjectBlockOffset(\"AwxAudioObjExtArrayTemplate\", \"FloatArrayMemory\", subBlock, static_cast(info-&gt;HiQNetVal), hiqnetInc, PARAM_CATEGORY);\r\n        hiqnetInc++;\r\n    }\r\n    xAFWriteXmlTag(\"Objects\", XML_CLOSE);\r\n\r\n    xAFWriteXmlTag(\"Object\", XML_CLOSE);\r\n\r\n    return finishWritingToBuffer();\r\n}\r\n\r\n\r\nvoid CAwxAudioObjExtToolbox::createStaticMetadata()\r\n{\r\n    m_StaticMetadata.minReqXafVersion = static_cast(MIN_REQUIRED_XAF_VERSION);\r\n\r\n    setAudioObjectVersion(AWXAUDIOOBJEXT_VERSION_MAJOR, AWXAUDIOOBJEXT_VERSION_MINOR, AWXAUDIOOBJEXT_VERSION_REVISION);\r\n    setTuningVersion     (AWXAUDIOOBJEXT_TUNING_VERSION_MAJOR, AWXAUDIOOBJEXT_TUNING_VERSION_MINOR);\r\n\r\n    m_StaticMetadata.supDataFormats.push_back(xAF_DATATYPE_FLOAT);\r\n\r\n    \/\/creation\/release date\r\n    setCreationDate(2022, 8, 4);\r\n\r\n    \/\/Simple AO supports in-place computation\r\n    m_StaticMetadata.inPlaceComputationEnabled = true;\r\n    \/\/This flag allows to set whether the object dynamically updates its additional vars based on input params\r\n    m_StaticMetadata.isAddVarUpdateRequired = true;\r\n}\r\n\r\nvoid CAwxAudioObjExtToolbox::createDynamicMetadata(ioObjectConfigInput&amp; configIn, ioObjectConfigOutput&amp; configOut)\r\n{\r\n    metaDataControlDescription ctrlDesc;\r\n    \/\/ define audio in metadata\r\n    m_DynamicMetadata.audioIn.Min = AUDIO_IN_OUT_MIN;\r\n    m_DynamicMetadata.audioIn.Max = AUDIO_IN_OUT_MAX;\r\n\r\n    \/\/ define audio out metadata\r\n    m_DynamicMetadata.audioOut.Min = AUDIO_IN_OUT_MIN;\r\n    m_DynamicMetadata.audioOut.Max = AUDIO_IN_OUT_MAX;\r\n\r\n    switch (configIn.mode)\r\n    {\r\n        case static_cast(GAIN_WITH_CONTROL) :\r\n        \/\/ define control in min, max and label values for the control pin\r\n            \r\n        ctrlDesc.Min = CONTROL_GAIN_MIN;\r\n        ctrlDesc.Max = CONTROL_GAIN_MAX;\r\n        ctrlDesc.Label = CONTROL_GAIN_IN_LABEL;\r\n        m_DynamicMetadata.controlIn.push_back(ctrlDesc);\r\n        break;\r\n\r\n        default:\r\n        break;\r\n    }\r\n\r\n    m_DynamicMetadata.estMemory = EST_MEMORY_CONSUMPTION_NA;\r\n    m_DynamicMetadata.estMIPS = EST_CPU_LOAD_CONSUMPTION_NA;\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\/*! * \\file AwxAudioObjExtToolbox.cpp * \\brief AwxAudioObjExt Toolbox Source file * \\details Implements the AwxAudioObjExt signal design API * \\details Project Extendable Audio Framework * \\copyright Harman\/Becker Automotive Systems GmbH * 2020 * All rights reserved * \\author xAF Team *\/ \/*! * xaf mandataory includes to handle the toolbox related data *\/ #include &#8220;AwxAudioObjExtToolbox.h&#8221; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"0","ocean_second_sidebar":"0","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"0","ocean_custom_header_template":"0","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"0","ocean_menu_typo_font_family":"0","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"0","footnotes":"","ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"on","ocean_gallery_id":[]},"categories":[353],"tags":[],"coauthors":[165],"_links":{"self":[{"href":"https:\/\/audioworx.transfunnel.co\/old\/index.php?rest_route=\/wp\/v2\/posts\/4905"}],"collection":[{"href":"https:\/\/audioworx.transfunnel.co\/old\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/audioworx.transfunnel.co\/old\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/audioworx.transfunnel.co\/old\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/audioworx.transfunnel.co\/old\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4905"}],"version-history":[{"count":23,"href":"https:\/\/audioworx.transfunnel.co\/old\/index.php?rest_route=\/wp\/v2\/posts\/4905\/revisions"}],"predecessor-version":[{"id":28062,"href":"https:\/\/audioworx.transfunnel.co\/old\/index.php?rest_route=\/wp\/v2\/posts\/4905\/revisions\/28062"}],"wp:attachment":[{"href":"https:\/\/audioworx.transfunnel.co\/old\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4905"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/audioworx.transfunnel.co\/old\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4905"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/audioworx.transfunnel.co\/old\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4905"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/audioworx.transfunnel.co\/old\/index.php?rest_route=%2Fwp%2Fv2%2Fcoauthors&post=4905"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}