Announcement

Collapse
No announcement yet.

Audio Listener UDK

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Audio Listener UDK

    Hi,

    I'v been using these forums for quite some while and it is time for me to post a question about the "AudioListener" in UDK.
    I know that the listener is connected to the Camera but I have failed to extract it and put it on the Player Pawn.
    I have been searching for a solution on this forum and beyond but I failed to get a positive result.

    Thank you in advance

    #2
    So,

    I decided to pick this item up again and discovered where to look and what item I should
    alter to give the results I want. This is what I have found:

    Found inside: UTGameViewportClient

    Code:
    local AudioDevice AD;
    PC = GetALocalPlayerController(); //Added PlayerLocation
    
    AD = class'Engine'.static.GetAudioDevice();
    `log (AD.Listeners[0].Location); //Added log
    I'v found this stuff inside the UTGameViewportClient class (bit obvious, if I think of it now),
    the Listeners array stores a Location Vector which nicely prints out the value of my
    mouse/camera movement. But now my problem is how to give it a new location which
    normally isn't a problem, except the Listener Class does not store a SetLocation or a other
    function which helps me achieve this, in fact it only stores few variables in this native struct:

    Found inside: AudioDevice

    Code:
    struct native Listener
    {
    	var const PortalVolume PortalVolume;
    	var vector Location;
    	var vector Up;
    	var vector Right;
    	var vector Front;
    	var vector Velocity;
    };
    I'v tried several things but failed to achieve my goal. which where: DynamicLoad and spawning
    a new AudioDevice overriding the old location with a new location. (but i do not think this is the
    right approach because it is not a actor (which I am more familiar with)).

    It would be very thankful if someone can enlighten me.

    -BopM

    Comment


      #3
      Maybe AD.Listener[0].Location = xyz... I guess that's too easy and probably doesn't work, can you override the Location with a custom vector instead of using AD.listener.location?

      Comment


        #4
        wait nevermind you said you did that too... sh sorry man

        Comment


          #5
          What about spawning the audio listeners into a parent actor class and then transforming the actor position?

          nevermind what about spawning a player cam with invisible player that moves around and captures audio while the main player is captured as a render target from another camera? I don't know if any of these work just brainstorming.

          Comment


            #6
            Thank you for input Garner and maybe you are right, perhaps I need to create a other cam on the player and disable the listener on the default one.
            I will keep you updated!

            Comment


              #7
              Got it to work (Kind of...)

              I have managed to alter the location of the listeners array which was a less complicated
              than I was trying to do most of my day.. uhmz. Anyway I have deleted the const and
              native words inside the AudioDevice:

              Code:
              struct native Listener
              {
              	var const PortalVolume PortalVolume;
              	var vector Location;
              	var vector Up;
              	var vector Right;
              	var vector Front;
              	var vector Velocity;
              };
              
              var native const array<Listener> Listeners;
              At this point I could alter the Location of the listener. I also figured out that the location
              must be determent inside the UTGameViewportClient. This is because the listener get his location
              at this point (Please correct me if I'm wrong, this worked for me).

              This is how my event PostRender looks (inside the UTGameViewportClient class)
              Code:
              event PostRender(Canvas Canvas)
              {
              	local int i;
              	local ETransitionType OldTransitionType;
              	
              	//NEEDED LOCALS ==========
              	local AudioDevice AD;
              	local PlayerController PC;
              	local Pawn P;
              	//========================
              		
              	OldTransitionType = Outer.TransitionType;
              	if (Outer.TransitionType == TT_None)
              	{
              		for (i = 0; i < Outer.GamePlayers.length; i++)
              		{
              			if (Outer.GamePlayers[i].Actor != None)
              			{
              				// count as loading if still using temp locally spawned PC on client while waiting for connection
              				if (Outer.GamePlayers[i].Actor.WorldInfo.NetMode == NM_Client && Outer.GamePlayers[i].Actor.Role == ROLE_Authority)
              				{
              					Outer.TransitionType = TT_Loading;
              					break;
              				}
              			}
              		}
              	}
              	
              	//ATTACH LISTENER TO PLAYER ========================	
              		//FETCHING THE INFORMATION
              		AD = class'Engine'.static.GetAudioDevice();
              		if (PC == None)
              		{
              			PC = class'Engine'.static.GetCurrentWorldInfo().GetALocalPlayerController();
              		}
              		if (P == None && PC != None)
              		{
              			P = PC.Pawn;
              		}
              	
              		//APPLYING
              		if (AD != None && PC != None && P != None)
              		{
              			AD.Listeners[0].Location = P.Location;
              			`log ("= Player Location Successfully fetched =: "$ AD.Listeners[0].Location);
              		}
              	//=================================================
              		
              		
              	Super.PostRender(Canvas);
              
              	Outer.TransitionType = OldTransitionType;
              }
              So I got it to work, the only thing now is to alter the other variables
              because the mouse-movement creates a strange left right panning of the sound.
              But It is attached!

              Let you guys know if there is more!

              - BopM

              Comment


                #8
                Hey, this is great !
                Works fine, thanks !

                Comment


                  #9
                  For future reference, it works better if the code in PostRender in the UTGameViewportClient class by BopM is placed in the Tick event.
                  Code:
                  /**
                   * Called every frame to allow the game viewport to update time based state.
                   * @param	DeltaTime - The time since the last call to Tick.
                   */
                  event Tick(float DeltaTime)
                  {
                  	//NEEDED LOCALS ==========
                  	local AudioDevice AD;
                  	local PlayerController PC;
                  	local Pawn P;
                  	//========================
                  	//ATTACH LISTENER TO PLAYER ========================
                  		//FETCHING THE INFORMATION
                  		AD = class'Engine'.static.GetAudioDevice();
                  		if (PC == None)
                  		{
                  			PC = class'Engine'.static.GetCurrentWorldInfo().GetALocalPlayerController();
                  		}
                  		if (P == None && PC != None)
                  		{
                  			P = PC.Pawn;
                  		}
                  
                  		//APPLYING
                  		if (AD != None && PC != None && P != None)
                  		{
                  			AD.Listeners[0].Location = P.Location;
                  	//		`log ("= Player Location Successfully fetched =: "$ AD.Listeners[0].Location);
                  		}
                  	//=================================================
                  //END OF CHANGE LOCATION
                  }

                  Comment

                  Working...
                  X