Control Audio Mixer Atem

Ask software engineering and SDK questions for developers working on Mac OS X, Windows or Linux.
  • Author
  • Message
Offline

manuca72

  • Posts: 1
  • Joined: Wed Oct 24, 2018 7:26 pm
  • Real Name: emmanuel Casert

Control Audio Mixer Atem

PostWed Oct 24, 2018 8:13 pm

Hi,
I'm trying to develop a control panel for my ATEM TVS switcher. This would run on a mini-pc with a touchscreen monitor.( see GUI screenshot attached) I have also a custom control panel hardware based on arduino and connected through USB to the mini-PC.
This control panel sends button pressed events and position value of 4 sliders. These sliders are intended to control the Video transition (T-Bar), the master program audio volume and 2 audio channel volume.
Some other buttons provide basic function like AUTO, CUT, transition MIX, WIPE, DIP. Feedback from the software allows buttons leds to goes on and off, and provides external Tally leds control.

I have almost successfully implemented everything now, except the audio input volume control. There is my pain point since a couple of days... I didn't find any sample source c# code that does this job.

Master volume control works fine as it gets controlled directly by
IBMDSwitcherAudioMixer m_audiomixer;
m_audiomixer = (BMDSwitcherAPI.IBMDSwitcherAudioMixer)m_switcher;

m_audiomixer.GetProgramOutGain(out Curgain); for feedback
and m_audiomixer.SetProgramOutGain(out Curgain);for setting

I could not find a way to control AudioInput the same way. I have managed to create a monitoring chain using the ugly iterator process :
IBMDSwitcherAudioInputIterator AinputIterator = null;
IntPtr AinputIteratorPtr;
Guid AinputIteratorIID = typeof(IBMDSwitcherAudioInputIterator).GUID;
m_audiomixer.CreateIterator(ref AinputIteratorIID, out AinputIteratorPtr);
if (AinputIteratorPtr != null)
{
AinputIterator =(IBMDSwitcherAudioInputIterator)Marshal.GetObjectForIUnknown(AinputIteratorPtr);
}
if (AinputIteratorPtr != null)
{

IBMDSwitcherAudioInput Ainput;

AinputIterator.Next(out Ainput);
while (Ainput != null)
{

AudioInputMonitor m_audioInputMonitor = new AudioInputMonitor(Ainput);
Ainput.AddCallback(m_audioInputMonitor);
m_audioInputMonitor.GainChanged += new SwitcherEventHandler(OnAInputGainChanged);
m_audioInputMonitor.IsMixedInChanged += new SwitcherEventHandler(OnIsMixedInChanged);
m_audioInputMonitors.Add(m_audioInputMonitor);

AinputIterator.Next(out Ainput);
}
}

This triggers my OnAInputGainChanged and OnIsMixedInChanged functions but how can I know which channel gain or MixedIn has changed ? I've tried to run an iterator but it looks to take too much time and the function reruns before it has been completed.
The eventhandler should at least pass the InputID so a command like audio_mixer.input(InputID).GetGain (out Gain) would return the changed value in only one step.

Could you provide a working sample c# source code that controls the audio mixer ( and set sliders position feedback) ? This would really help me !
Thanks in advance !
Emmanuel
Attachments
panel.png
softpanel
panel.png (143.69 KiB) Viewed 1980 times
Offline

Ian Morrish

  • Posts: 580
  • Joined: Sun Jan 18, 2015 9:24 pm
  • Location: New Zealand

Re: Control Audio Mixer Atem

PostFri Oct 26, 2018 8:39 pm

For audio input control, I have done it for setting values and just use polling to read back the current state. Example below is just setting volume with Midi device, but I have X-Touch mini with motorized faders reading back the levels. I tried using callback events but this was not easy with PowerShell so I just stick with a timer that reads the values every second to update the slider positions.
https://ianmorrish.wordpress.com/2016/07/09/atem-audio-input-mixer-support-added/

Regards,
Ian Morrish
Video Integrated Scripting Environment
(Windows PowerShell with ATEM driver + more)
https://ianmorrish.wordpress.com
Offline

Cameron Nichols

Blackmagic Design

  • Posts: 442
  • Joined: Mon Sep 04, 2017 4:05 am

Re: Control Audio Mixer Atem

PostWed Oct 31, 2018 5:44 am

Hi Emmanuel,

I would pass your IBMDSwitcherAudioInput as an argument as EventArgs. This is how I would define the IBMDSwitcherAudioInputCallback callback class:

Code: Select all
    public class AudioInputEventArgs : EventArgs
    {
        public readonly IBMDSwitcherAudioInput audioInput;

        public AudioInputEventArgs(IBMDSwitcherAudioInput audioInput)
        {
            this.audioInput = audioInput;
        }
    }

    class AudioInputCallback : IBMDSwitcherAudioInputCallback
    {
        private IBMDSwitcherAudioInput audioInput;

        public event EventHandler<AudioInputEventArgs> GainChangedHandler;
        public event EventHandler<AudioInputEventArgs> IsMixedInChangedHandler;

        public AudioInputCallback(IBMDSwitcherAudioInput audioInput)
        {
            this.audioInput = audioInput;
        }

        ~AudioInputCallback()
        {
            Disable();
        }

        public void Enable()
        {
            audioInput.AddCallback(this);
        }

        public void Disable()
        {
            audioInput.RemoveCallback(this);
        }

        void IBMDSwitcherAudioInputCallback.LevelNotification(double left, double right, double peakLeft, double peakRight)
        {
            throw new NotImplementedException();
        }

        void IBMDSwitcherAudioInputCallback.Notify(_BMDSwitcherAudioInputEventType eventType)
        {
            switch (eventType)
            {
                case _BMDSwitcherAudioInputEventType.bmdSwitcherAudioInputEventTypeGainChanged:
                    GainChangedHandler?.Invoke(this, new AudioInputEventArgs(audioInput));
                    break;

                case _BMDSwitcherAudioInputEventType.bmdSwitcherAudioInputEventTypeIsMixedInChanged:
                    IsMixedInChangedHandler?.Invoke(this, new AudioInputEventArgs(audioInput));
                    break;

                default:
                    //throw new NotImplementedException();
            }
        }
    }

In your main code, you then register as a subscriber to GainChangedHandler and IsMixedInChangedHandler.

Regards
Cameron

Return to Software Developers

Who is online

Users browsing this forum: Google [Bot] and 16 guests