Home AMX User Forum AMX Technical Discussion

Parse string data to get volume level values

Hi Experts,

Is anyone know a way to parse the below string data to grab the volume level value?

Line 146 2022-09-17 (13:00:44):: sDSP_DATA =cv "IN1GAIN" "-11.0dB" -11 0.741667$0D$0A
Line 101 2022-09-17 (13:00:39):: sDSP_DATA =cv "IN1GAIN" "4.00dB" 4 0.866667$0D$0A

I need to get the volume level value of the input gain so I could update my volume bargraph. But, I am not sure how to accomplish this.

With getting the mute/unmute status of an input, I don't have problem using the find_string command.

if(find_string(sDSP_DATA ,'IN1GAINMute',1))
{
if(find_string(sDSP_DATA ,'muted',1))
{
nAudioInOutMuteStatus[2][6]=1;
}
if(find_string(sDSP_DATA ,'unmuted',1))
{
nAudioInOutMuteStatus[2][6]=0;
}
}

Could someone help me please ?
Thank you.

Comments

  • The separator seems to be a space. This assumes there will be no spaces in the parameters.
    You don't say what actual parameter holds the input gain, assumed it is '-11' and the '4' in the example
    Also, below a signed integer is used to store the gain. This can't hold fractions (ie. only -11, not -11.7) if fractions will occur use a float or multiply it by 10 or whatever will fit the format
    If you don't need any of the other parameters, just assign them to 'cTrash'

    This is one way of doing it. Used notepad ++ to make it, not tested at all...

    define_function fnParseData(CHAR sDSP_DATA[])
    {
        //example: sDSP_DATA =cv "IN1GAIN" "-11.0dB" -11 0.741667$0D$0A
    
        LOCAL_VAR CHAR cTrash[50]
        LOCAL_VAR CHAR cParamLabel[10]
        LOCAL_VAR CHAR cGainLabel[10] 
        LOCAL_VAR CHAR cGainVal[5] 
        LOCAL_VAR CHAR cUnknown[10] 
    
        LOCAL_VAR SINTEGER snGainVal
        LOCAL_VAR FLOAT fUnknown
    
        if(find_string(sDSP_DATA ,'IN1GAIN',1))
        {
        cTrash      = remove_string(sDSP_DATA,' ',1)       //remove upto and including the first space (cv )
        cParamLabel = remove_string(sDSP_DATA,' ',1)       //remove upto and including the second space ("IN1GAIN" )
        cGainLabel  = remove_string(sDSP_DATA,' ',1)       //remove upto and including the third space ("-11.0dB" )
        cGainVal    = remove_string(sDSP_DATA,' ',1)       //remove upto and including the fourth space (-11 )
        cUnknown    = remove_string(sDSP_DATA,"$0D,$0A",1) //remove upto and including the cr,lf (0.741667$0D$0A)
    
        set_length_string(cUnknown,(length_string(cUnknown) - 2)) //remove cr,lf
    
        snGainVal   = atoi(cGainVal)
        fUnknown    = atof(cUnknown)
        }
    }
    
  • John NagyJohn Nagy Posts: 1,734
    edited September 2022

    A side note to consider.
    Many programmers go through great pains and many lines of code to detect volume levels to display on a panel.
    More often than not, the device is behind rack doors in another room, never to be touched during normal operation, the volume set commands being sent exclusively by the NetLinx. So the flow is:
    1. System tells volume to go to 49.
    2. Device goes to 49.
    3. System asks device what the volume is.
    4. Device says 49.
    5. System parses and sends 49 to the touch panel bar graph and/or label.
    6. Panel shows the 49.

    Compare:
    1. System tells volume to go to 49, and simultaneously tells touch panel to show 49.

    Point being, why jump through hoops asking the device what you just told it to do? If it doesn't in fact do it, it's not likely to succeed in telling you either. And you'd notice the fail by your ears before reading the panel. Another upside - the panel changing when the command is issued demonstrates that the panel isn't offline, didn't miss the touch, and that the NetLinx program is operating, items you'd need to individually troubleshoot otherwise.

    This of course isn't practical if people are operating the device by manual or other non-NetLinx-controlled means, and/or you need to see the actual value from a different location than where the sound is heard. But seriously, consider the likelyhood of your volume reporting code resulting in a significant difference in the real world, compared to setting the panel and the device at the same time.

    You may now scowl at the impurity of such a suggestion.

  • Agree with @John Nagy That's the way I always do it. I usually let the touchpanel generate the level, you then only need a level_event to store the generated volume and get it to the DSP. The stored volume is then used when powering on the system and when a touchpanel comes online to update the level. No volume feedback other than what your ears tell you. in 95% of cases this is fine.

    Now the OP did say 'input gain', that's not the same as volume, but they probably meant that.

Sign In or Register to comment.