0

HD1025 Mix audio to analog out playing 2 videoclips at same time

We have a HD1025 splilted into2 zones a Left one and a Right one and having 2 videoclips (1 in each zone) which shall play when GPIO are triggered.

That works fine to play the Left and Right video when GPIO are triggered

We have analog audio out 3.5mm and want the Left channel to play audio from the left videoplayer and the Right channel to play audio from the Right video.

Please advise how to do that as brightscript.

videoFile_Loop_L = "Lights_Logo.mp4"
videoFile_Person_L = "Crashtest.mp4"
videoFile_Loop_R = "Lights_Logo.mp4"
videoFile_Person_R = "Crashtest.mp4"
 
 
mode=CreateObject("roVideoMode")
mode.SetMode("1920x1080x60p")
 
EnableZoneSupport(true)
EnableAudioMixer(true)
 
p = CreateObject("roMessagePort")
 
vL=CreateObject("roVideoPlayer")
vL.SetViewMode(0) ' loop off=0 loop on=1
l=CreateObject("roRectangle", 0, 0, 960, 1080)
vL.SetRectangle(l)
vL.SetPort(p)
vL.SetUserData("Left")
vL.SetAudioOutput(0)
 
vR=CreateObject("roVideoPlayer")
vR.SetViewMode(0) ' loop off=0 loop on=1
r=CreateObject("roRectangle", 960, 0, 960, 1080)
vR.SetRectangle(r)
vR.SetPort(p)
VR.SetUserData("Right")
vR.SetAudioOutput(0)
 
gpio = CreateObject("roGpioControlPort")
gpio.SetPort(p)
gpio.EnableInput(0)
gpio.EnableInput(1)
 
 
vL.PlayFile(videoFile_Loop_L)
vR.PlayFile(videoFile_Loop_R)
 
Print "Main loop"
 
main_loop:
 
  msg = wait(0,p)
print "msg_a: ";msg
                 print "type: ";type(msg)
'-------------check for GPIO---------
                 
if gpio.IsInputActive(0) Then 
print "Gpio 0"
                 vL.StopClear()
                 vL.PlayFile(videoFile_Person_L) 
endif
 
if gpio.IsInputActive(1) Then 
print "Gpio 1"
                 vR.StopClear()
vR.PlayFile(videoFile_Person_R) 
endif
                 
 
'-------------end video----------
        if type(msg) = "roVideoEvent" then
                if msg.GetInt() = 8 then 
'                        sourceID = msg.GetSourceIdentity()
                        sourceID = msg.GetUserData()
                        print sourceID
                        if sourceID = "Left"
                            vL.PlayFile(videoFile_Loop_L)
                            print "Video L finished playing"
                else if sourceID = "Right"
                    vR.PlayFile(videoFile_Loop_R)
                    print "Video R finished playing"
                endif
                
                print "End_Of_File"
                        
                endif
        endif
                                        
 
'----------end messageport-----------   
        
 
GoTo main_loop

 

5 comments

  • 0
    Avatar
    Denial

    Hello,

    Audio Output:
    vL.SetAudioOutput(0): Sets the left video player's audio to output on the left channel (channel 0).
    vR.SetAudioOutput(1): Sets the right video player's audio to output on the right channel (channel 1).
    Removed Redundant Code:     progressive agent login
    The sourceID = msg.GetSourceIdentity() line is commented out as it's not used in this implementation.
    Explanation:

    Audio Output Channels: By setting SetAudioOutput(0) for the left video player and SetAudioOutput(1) for the right one, you explicitly assign their audio streams to the corresponding left and right channels of the 3.5mm audio output.

    Audio Mixing:

    EnableAudioMixer(true) is crucial. This enables the audio mixer within the BrightScript environment, allowing the simultaneous output of audio from both video players to the separate channels.
    Note:

    This solution assumes your 3.5mm audio output supports stereo audio.
    Adjust the audio output channel numbers if your hardware or audio setup requires different assignments.

  • 0
    Avatar
    Jan Jakobsen

    Hello Denial

    Thank you I tried to look into you suggestions but it does not seem to fix the problem.

    I do have the

    EnableAudioMixer(true) 

    vL.SetAudioOutput(0)
    vR.SetAudioOutput(1)

    I still only have the vL audio (L+R )channels on 3.5mm out and nothing from vR 

    According to the BrightScript Reference Manual:

    SetAudioOutput(audio_output As Integer) As Boolean
    Configures the audio output of the roAudioPlayer object. This method accepts the following values:
    0: Analog audio
    1: USB audio
    2: Digital audio, stereo PCM
    3: Digital audio, raw AC3
    4: Onboard analog audio with HDMI mirroring raw AC3


    SetAudioMode(audio_mode As Integer) As Boolean
    Sets the audio mode of the roAudioPlayer object. This method accepts the following values:
    0: AC3 Surround
    1: AC3 mixed down to stereo
    2: No audio
    3: Left
    4: Right

    Options 0 and 1 only apply to video files, while options 2, 3, and 4 apply to all audio sources.

     

  • 0
    Avatar
    Cage Nut

    I love a good riddle!

    Please keep us posted and share your wins.

  • 1
    Avatar
    Jan Jakobsen

    Just following up.

    It was working in BrightAuthor but I needed to have it to work as a stanalone script.

    So some analysis of the BrightAuthor autorun.brs and I find that a audio routing needs to be set up in the beginning

    So after inserted this in my script in the beginning  just after EnableAudioMixer(true)

        ' Create the audio routing configuration
        audio_routing = {
            mode: "prerouted",   ' Enable prerouted mode for mixed audio
            autolevel: "on",     ' Normalize volume levels
            pcmonly: "true"      ' Ensure PCM-only audio support
        }

           ' initialize audio configuration
        audioConfiguration = CreateObject("roAudioConfiguration")

        audioConfiguration.ConfigureAudio(audio_routing)

    I do miss some official documentation for this routing stuff, but now it works!

     

     

     

  • 0
    Avatar
    Bright Scripters

    Good job!

    Thanks for sharing!

Please sign in to leave a comment.