Exemplo n.º 1
0
 public void OnAudioDataReceived(float[] data, int numChannels)
 {
     if (AudioDataReceived != null)
     {
         AudioFrameData frameData = new AudioFrameData(data, numChannels);
         AudioDataReceived(frameData);
     }
 }
 public void OnAudioDataReceived(float[] data, int numChannels)
 {
     if (AudioDataReceived != null)
     {
         AudioFrameData frameData = new AudioFrameData(data, numChannels);
         AudioDataReceived(frameData);
     }
 }
 private void OnAudioDataReceived(AudioFrameData frameData)
 {
     this.audio.clip.SetData(frameData.AudioData, this.writeBoundary);
     this.writeBoundary += frameData.AudioData.Length;
     if (readBoundary + minBufferLength <= writeBoundary && !audio.isPlaying)
     {
         this.audio.Play();
     }
 }
 private void OnAudioDataReceived(AudioFrameData frameData)
 {
     this.audio.clip.SetData(frameData.AudioData, this.writeBoundary);
     this.writeBoundary += frameData.AudioData.Length;
     if (readBoundary + minBufferLength <= writeBoundary && !audio.isPlaying)
     {
         this.audio.Play();
     }
 }
 public void EncodeData(AudioFrameData frameData)
 {
     short[] shortData = new short[frameData.AudioData.Length];
     Util.ConvertToShortArray(frameData.AudioData, shortData);
     Byte[] encodedBytes = new Byte[shortData.Length * 2];
     int numEncodedBytes = encoder.Encode(shortData, 0, encoder.FrameSize, encodedBytes, 0, encodedBytes.Length);
     int difference = encodedBytes.Length - numEncodedBytes;
     Debug.Log("Wasted bytes: " + difference);
     byte[] trimmedBytes = new byte[numEncodedBytes];
     Buffer.BlockCopy(encodedBytes, 0, trimmedBytes, 0, numEncodedBytes);
     OnAudioFrameEncoded(trimmedBytes, numEncodedBytes);
 }
Exemplo n.º 6
0
 public void OnAudioDataReceived(float[] data, int numChannels)
 {
     if (AudioDataReceived != null)
     {
         AudioFrameData frameData = new AudioFrameData(data, numChannels);
         AudioDataReceived(frameData);
     }
     if (!printedToFile)
     {
         Util.PrintToFile(data, "received" + Util.CurrentTimeStamp);
         printedToFile = true;
     }
 }
Exemplo n.º 7
0
    public void EncodeData(AudioFrameData frameData)
    {
        short[] shortData = new short[frameData.AudioData.Length];
        Util.ConvertToShortArray(frameData.AudioData, shortData);
        Byte[] encodedBytes    = new Byte[shortData.Length * 2];
        int    numEncodedBytes = encoder.Encode(shortData, 0, encoder.FrameSize, encodedBytes, 0, encodedBytes.Length);
        int    difference      = encodedBytes.Length - numEncodedBytes;

        Debug.Log("Wasted bytes: " + difference);
        byte[] trimmedBytes = new byte[numEncodedBytes];
        Buffer.BlockCopy(encodedBytes, 0, trimmedBytes, 0, numEncodedBytes);
        OnAudioFrameEncoded(trimmedBytes, numEncodedBytes);
    }
Exemplo n.º 8
0
    public void SendAudioDataToRemote(AudioFrameData audioFramedata)
    {
        foreach (NetworkPlayer remoteTarget in this.remoteTargets)
        {
            if (remoteTarget.ipAddress == "unassigned")
            {
                throw new InvalidOperationException("No remote target set for audio tunnel.");
            }
            int length;
            byte[] bytes = encodedBytes(audioFramedata, out length);

            networkView.RPC("ReadAudioData_Remote", remoteTarget, bytes, audioFramedata.NumChannels, length);
        }
    }
    public void SendAudioDataToRemote(AudioFrameData audioFramedata)
    {
        foreach (NetworkPlayer remoteTarget in this.remoteTargets)
        {
            if (remoteTarget.ipAddress == "unassigned")
            {
                throw new InvalidOperationException("No remote target set for audio tunnel.");
            }
            int    length;
            byte[] bytes = encodedBytes(audioFramedata, out length);

            networkView.RPC("ReadAudioData_Remote", remoteTarget, bytes, audioFramedata.NumChannels, length);
        }
    }
Exemplo n.º 10
0
    private byte[] encodedBytes(AudioFrameData audioFramedata, out int length)
    {
        byte[] recordedBytes = Util.ToByteArrayBlockCopy(audioFramedata.AudioData);

        int numOfShortsToSend = (recordedBytes.Length / 2) - (recordedBytes.Length / 2) % encoder.FrameSize;

        short[] data = new short[numOfShortsToSend];
        Buffer.BlockCopy(recordedBytes, 0, data, 0, numOfShortsToSend * 2);
        byte[] encodedData = new byte[numOfShortsToSend * 2];

        // note: the number of samples per frame must be a multiple of encoder.FrameSize
        Debug.Log("recordedBytes: " + recordedBytes.Length +
                  " data: " + data.Length +
                  " encodedData: " + encodedData.Length +
                  " numOfBytesToSend: " + numOfShortsToSend * 2 +
                  " framesize: " + encoder.FrameSize);
        length = encoder.Encode(data, 0, data.Length, encodedData, 0, encodedData.Length);
        return encodedData;
    }
Exemplo n.º 11
0
    private byte[] encodedBytes(AudioFrameData audioFramedata, out int length)
    {
        byte[] recordedBytes = Util.ToByteArrayBlockCopy(audioFramedata.AudioData);

        int numOfShortsToSend = (recordedBytes.Length / 2) - (recordedBytes.Length / 2) % encoder.FrameSize;

        short[] data = new short[numOfShortsToSend];
        Buffer.BlockCopy(recordedBytes, 0, data, 0, numOfShortsToSend * 2);
        byte[] encodedData = new byte[numOfShortsToSend * 2];

        // note: the number of samples per frame must be a multiple of encoder.FrameSize
        Debug.Log("recordedBytes: " + recordedBytes.Length +
                  " data: " + data.Length +
                  " encodedData: " + encodedData.Length +
                  " numOfBytesToSend: " + numOfShortsToSend * 2 +
                  " framesize: " + encoder.FrameSize);
        length = encoder.Encode(data, 0, data.Length, encodedData, 0, encodedData.Length);
        return(encodedData);
    }
 public void OnAudioDataReceived(float[] data, int numChannels)
 {
     if (AudioDataReceived != null)
     {
         AudioFrameData frameData = new AudioFrameData(data, numChannels);
         AudioDataReceived(frameData);
     }
     if (!printedToFile)
     {
         Util.PrintToFile(data, "received" + Util.CurrentTimeStamp);
         printedToFile = true;
     }
 }