Forum

Results 1 to 4 of 4

Hybrid View

  1. #1
    Join Date
    July 2016
    Posts
    2

    Unity C# SDK: onEditPlaybackVoiceDataEvent

    I have been trying to use the onEditPlaybackVoiceDataEvent event to add a simple band-pass filter between two players voices in Unity.
    (The context is that these two players are talking over a phone and hence the voice quality is lower than if they were next to each other in game)

    I have managed to get a print() to work however I cant find any way to actually modify the voice data at all.
    I think I am meant to modify short[] samples, but I am not entirely sure.

    Code:
    void OnStartLocalPlayer(){
         TeamSpeakCallbacks.onEditPlaybackVoiceDataEvent += onEditPlaybackVoiceDataEvent;
    }
    
    private static void onEditPlaybackVoiceDataEvent(uint64 serverConnectionHandlerID, anyID clientID, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex=3)] short[] samples, int sampleCount, int channels){
         print( "something" );
         // the above print is working as intended
         // I have then been making changes to samples but it has no effect
    }
    If anyone has managed to alter voice data using onEditPlaybackVoiceDataEvent in C# then can you send over an example?

  2. #2
    Join Date
    May 2016
    Location
    Idar-Oberstein
    Posts
    163
    Did you test this with something simple along the lines of
    Code:
    for (int i = 0; i < samples.Length; i++)
      samples[i] = 0;
    ?

    I wouldn't be completely surprised if the marshalling was wrongly not copying it back, though.
    Our C# dev will be looking into it.

  3. #3
    Join Date
    July 2016
    Posts
    2
    Yeah I tried that expecting the sound to cut out all together, but there was no effect in game.

  4. #4
    Join Date
    May 2016
    Location
    Idar-Oberstein
    Posts
    163
    Hi Psiku,
    I didn't have time to test this yet, however that the current Marshalling is wrong is a given, as at the veryl least the samples size is incorrect.
    Could you please try by replacing in TeamSpeakCallbacks.cs
    Code:
    [MarshalAs(UnmanagedType.LPArray, SizeParamIndex=2)] short[]
    and
    Code:
    [MarshalAs(UnmanagedType.LPArray, SizeParamIndex=3)] short[]
    to
    Code:
    IntPtr
    .

    Assuming your dsp would be mono, usage might end up looking (leaving dsp management for channel count out)
    Code:
    private static void onEditPlaybackVoiceDataEvent(uint64 serverConnectionHandlerID, anyID clientID, IntPtr samples, int sampleCount, int channels){
         short[] left = new short[sampleCount];
         short[] right = new short[sampleCount];
         // deinterleave
         for (int i = 0; i < sampleCount*channels; ++i) {
            if (i%2==0)
              left[i] = samples[i];
            else
              right[i] = samples[i];
         }
         // do sth. with mono buffers
         // interleave and put back
         for(int i = 0; i < sampleCount; ++i) {
           samples[i*channels] = left[i];
           samples[1+i*channels] = right[i];
         }
    }
    Now, this ofc only with channels == 2, the snippet's only trying to make a point about interleaving, the fact that samples size is actually sampleCount*channels unlike the Marshalling suggests and to put modified mono sample buffers back. There're likely some embarrassing c# mistakes in there, too - I just wrote it down shot from the hip and am not doing c# usually.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. 3D Voice in Unity SDK not working
    By ehill in forum Game Engines
    Replies: 3
    Last Post: April 11th, 2017, 05:20 PM
  2. [Evaluation] Unity client ERROR_unable_to_bind_network_port
    By 8600862 in forum Client Support
    Replies: 2
    Last Post: June 17th, 2016, 11:31 AM
  3. Unity Integration possible?
    By DonSlaughter in forum Linux
    Replies: 0
    Last Post: May 7th, 2016, 04:59 AM
  4. unity 3d 3.3
    By moghazy in forum Client Support
    Replies: 0
    Last Post: July 11th, 2011, 09:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •