{"id":4903,"date":"2019-06-18T01:07:07","date_gmt":"2019-06-17T23:07:07","guid":{"rendered":"https:\/\/demdlx704as001.ad.harman.com\/index.php\/section\/audioobject-example-template-cpp\/"},"modified":"2024-05-13T12:42:03","modified_gmt":"2024-05-13T10:42:03","slug":"audioobject-example-template-cpp","status":"publish","type":"post","link":"https:\/\/audioworx.transfunnel.co\/old\/?p=4903","title":{"rendered":"Example 1 &#8211; AwxAudioObjExt.cpp"},"content":{"rendered":"<pre>\/*!\r\n*   \\file      AwxAudioObjExt.cpp\r\n*   \\brief     Simple example Audio object for building outside from the xAF repo- Source file\r\n*   \\details   Implements a simple example fucntionality\r\n*   \\details   Project    Extendable Audio Framework\r\n*   \\copyright Harman\/Becker Automotive Systems GmbH\r\n*   \r\n       2022\r\n*   \r\n       All rights reserved\r\n*   \\author    xAF Team\r\n*\/\r\n\r\n\/*!\r\n*   xaf mandataory includes\r\n*\/\r\n#include \"AwxAudioObjExt.h\"\r\n#include \"XafMacros.h\"\r\n#include \"vector.h\"\r\n\r\nVERSION_STRING_AO(AwxAudioObjExt, AWXAUDIOOBJEXT);\r\nAO_VERSION(AwxAudioObjExt, AWXAUDIOOBJEXT);\r\n\r\n\/** here you can add all required include files required for    \r\n    the core functionality of your objects\r\n**\/\r\n\r\n#define MAX_CONFIG_MIN_GAIN_dB              (0.0f)\r\n#define MAX_CONFIG_MAX_GAIN_dB              (30.0f)\r\n#define MAX_GAIN_DEFAULT_GAIN_dB            (10.0f)\r\n#define CONTROL_GAIN_MIN                    (-128.0f)\r\n#define GAINDB_CONVERSION_FACTOR             (0.05f)\r\n\r\nCAwxAudioObjExt::CAwxAudioObjExt()\r\n    : m_Coeffs(NULL)\r\n    , m_Params(NULL), m_MemBlock(NULL), m_EnMemory(DISABLE_BLOCK)\r\n{\r\n}\r\n\r\nCAwxAudioObjExt::~CAwxAudioObjExt()\r\n{\r\n}\r\n\r\nvoid CAwxAudioObjExt::init()\r\n{   \r\n    m_Params = static_cast&lt;xFloat32*&gt;(m_MemRecPtrs[PARAM]);\r\n    m_Coeffs = static_cast&lt;xFloat32*&gt;(m_MemRecPtrs[COEFF]);\r\n\t\r\n\tif (ENABLE_BLOCK == m_EnMemory)\r\n\t{\r\n\t\tm_MemBlock = static_cast&lt;xFloat32*&gt;(m_MemRecPtrs[FLOATARRAY]);\r\n\t}\r\n\tif (static_cast(GAIN_WITH_CONTROL) == m_Mode)\r\n\t{\r\n\t\tm_NumControlIn = 1;\r\n\t\tm_NumControlOut = 0;\r\n\t}\r\n\telse\r\n\t{\r\n\t\tm_NumControlIn = 0;\r\n\t\tm_NumControlOut = 0;\r\n\t}\r\n}\r\n\r\nvoid CAwxAudioObjExt::assignAdditionalConfig()\r\n{\r\n\txInt8*  addVars8Ptr = reinterpret_cast&lt;xInt8*&gt;(m_AdditionalSFDConfig);\r\n\t\/\/Assigning additional configuration variable \"Abstracted Tuning Memory\".\r\n\tif (static_cast&lt;void*&gt;(NULL) != m_AdditionalSFDConfig)\r\n\t{\r\n\t\tm_EnMemory = addVars8Ptr[m_NumAudioIn * sizeof(xFloat32)];\r\n\t}\r\n}\r\n\r\nxFloat32 CAwxAudioObjExt::getMaxGain(xSInt32 index)\r\n{\r\n\txFloat32*  addVars32Ptr = reinterpret_cast&lt;xFloat32*&gt;(m_AdditionalSFDConfig);\r\n\txFloat32 value = addVars32Ptr[index];\r\n\treturn value;\r\n}\r\n\r\nxInt8* CAwxAudioObjExt::getSubBlockPtr(xUInt16 subBlock)\r\n{\r\n    xInt8* ptr = NULL;\r\n  \r\n    \/\/ this is just an example of how memory could be split by an AO developer. There is no strict rule\r\n    \/\/ how memory has to be split for each subblock\r\n    \r\n    switch(subBlock)\r\n    {\r\n        case 0:\r\n        ptr = reinterpret_cast&lt;xInt8*&gt;(m_Params);\r\n        break;\r\n\r\n        case 1:\r\n        ptr = reinterpret_cast&lt;xInt8*&gt;(m_MemBlock);\r\n        break;\r\n        \r\n        default:\r\n        \/\/ by default we will return a null ptr, hence wrong subBlock was provided\r\n        break;\r\n    }\r\n\r\n    return ptr;\r\n}\r\n\r\nxSInt32 CAwxAudioObjExt::getSubBlockSize(xUInt16 subBlock)\r\n{\r\n    xSInt32 subBlockSize = 0;\r\n    \r\n    \/\/ this is just an example of how memory could be split by an AO developer. There is no strict rule\r\n    \/\/ how memory has to be split for each subblock\r\n    switch(subBlock)\r\n    {\r\n        case 0:\r\n        subBlockSize = static_cast(sizeof(xFloat32)) * static_cast(m_NumAudioIn) * NUM_PARAMS_PER_CHANNEL;\r\n        break;\r\n\r\n        case 1:\r\n        subBlockSize = (nullptr != m_MemBlock) ? (static_cast(sizeof(xFloat32)) * FLOAT_ARRAY_SIZE) : 0;\r\n        break;\r\n        \r\n        default:\r\n        \/\/ by default we will return a null ptr, hence wrong subBlock was provided\r\n        break;\r\n    }\r\n    return subBlockSize;\r\n}\r\n\r\nvoid CAwxAudioObjExt::calc(xAFAudio** inputs, xAFAudio** outputs)\r\n{\r\n\tif (static_cast(ENABLE_BLOCK) == m_EnMemory)\r\n\t{\r\n\t\txSInt32 numAudioIn = static_cast(m_NumAudioIn);\r\n\t\tfor (xSInt32 i = 0; i &lt; numAudioIn; i++)\r\n\t\t{\r\n\t\t\t\/\/ for example if m_MemBlock[0] is to mute all channels\r\n\t\t\txFloat32 factor = m_Coeffs[i] * m_MemBlock[0];\r\n\t\t\tscalMpy(factor, inputs[i], outputs[i], static_cast(m_BlockLength));\r\n\t\t}\r\n\t}\r\n\telse\r\n\t{\r\n\t\txSInt32 numAudioIn = static_cast(m_NumAudioIn);\r\n\t\tfor (xSInt32 i = 0; i &lt; numAudioIn; i++)\r\n\t\t{\r\n\t\t\tscalMpy(m_Coeffs[i], inputs[i], outputs[i], static_cast(m_BlockLength));\r\n\t\t}\r\n\t}\r\n}\r\n\r\nvoid CAwxAudioObjExt::calcGain(xSInt32 channelIndex, xFloat32 gainIndB)\r\n{\r\n\txFloat32 maxGainIndB = getMaxGain(channelIndex);\r\n\r\n\tLIMIT(gainIndB, CONTROL_GAIN_MIN, maxGainIndB);\r\n\tm_Params[channelIndex * NUM_PARAMS_PER_CHANNEL] = gainIndB;\r\n\r\n\txUInt32* mutePtr = reinterpret_cast&lt;xUInt32*&gt;(&amp;m_Params[(channelIndex * NUM_PARAMS_PER_CHANNEL) + 1u]);\r\n\r\n\tm_Coeffs[channelIndex] = (0 == *mutePtr) ? powf(MAX_GAIN_DEFAULT_GAIN_dB, gainIndB * GAINDB_CONVERSION_FACTOR) : 0.f;\r\n}\r\n\r\nvoid CAwxAudioObjExt::tuneXTP(xSInt32 subBlock, xSInt32 offsetBytes, xSInt32 sizeBytes, xBool shouldAttemptRamp)\r\n{\r\n\tif(0 == subBlock)\r\n\t{\r\n\t\txUInt32 channelu = static_cast(offsetBytes) &gt;&gt; 2u;\r\n\t\txSInt32 channel = static_cast(channelu) \/ NUM_PARAMS_PER_CHANNEL;\r\n\t\twhile (sizeBytes &gt; 0)\r\n\t\t{\r\n\t\t\tcalcGain(channel, m_Params[channel * NUM_PARAMS_PER_CHANNEL]);\r\n\t\t\tsizeBytes -= static_cast(NUM_PARAMS_PER_CHANNEL * sizeof(xFloat32));\r\n\t\t\tchannel++;\r\n\t\t}\r\n\t}\r\n\telse if(1 == subBlock)\r\n\t{ \/\/ handle float array related here\r\n\t  \/\/ values are available in m_MemBlock\r\n\t}\r\n\telse\r\n\t{\r\n\t}\r\n} \r\n\r\nxSInt32 CAwxAudioObjExt::controlSet(xSInt32 index, xFloat32 value)\r\n{\r\n\tif ((0 == index) &amp;&amp; (static_cast(GAIN_WITH_CONTROL) == m_Mode))\r\n\t{\r\n\t\txSInt32 numAudioIn = static_cast(m_NumAudioIn);\r\n\t\tfor (xSInt32 i = 0; i &lt; numAudioIn; i++)\r\n\t\t{\r\n\t\t\tcalcGain(i, value);\r\n\t\t}\r\n\t}\r\n\treturn 0;\r\n}\r\n\r\nxUInt32 CAwxAudioObjExt::getSize() const\r\n{\r\n    return sizeof(*this);\r\n}\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\/*! * \\file AwxAudioObjExt.cpp * \\brief Simple example Audio object for building outside from the xAF repo- Source file * \\details Implements a simple example fucntionality * \\details Project Extendable Audio Framework * \\copyright Harman\/Becker Automotive Systems GmbH * 2022 * All rights reserved * \\author xAF Team *\/ \/*! * xaf mandataory includes *\/ [&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\/4903"}],"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=4903"}],"version-history":[{"count":22,"href":"https:\/\/audioworx.transfunnel.co\/old\/index.php?rest_route=\/wp\/v2\/posts\/4903\/revisions"}],"predecessor-version":[{"id":28059,"href":"https:\/\/audioworx.transfunnel.co\/old\/index.php?rest_route=\/wp\/v2\/posts\/4903\/revisions\/28059"}],"wp:attachment":[{"href":"https:\/\/audioworx.transfunnel.co\/old\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4903"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/audioworx.transfunnel.co\/old\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4903"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/audioworx.transfunnel.co\/old\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4903"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/audioworx.transfunnel.co\/old\/index.php?rest_route=%2Fwp%2Fv2%2Fcoauthors&post=4903"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}