/// <summary> /// Regenerates a AudioClip from the complete audio structure stored /// on the data structure. /// </summary> /// <param name="id">Identifier of the clip received to regenerate.</param> private void RegenerateClipFromReceivedData(uint id) { Debug.Log("Regenerating clip from received data."); AudioStruc clipS = msgData[id]; msgData.RemoveStream(id); AudioClip clip = AudioClip.Create("Received clip with ID " + id, clipS.samples, clipS.channels, clipS.frequency, false); clip.SetData(clipS.data, 0); lastCapturedClip = clip; }
/// <summary> /// Saves on the data structure the data contained in a chunk. /// </summary> /// <param name="row">Image's chunk message.</param> private void SaveChunk(AudioChunkMessage row) { AudioStruc clipStruc = msgData[row.id]; for (int i = 0; i < row.data.Length && i < row.size && clipStruc.samplesReceived < clipStruc.data.Length; i++) { clipStruc.data[i + row.order * clipStruc.chunkSize] = row.data[i]; clipStruc.samplesReceived += 1; } msgData[row.id] = clipStruc; Debug.Log(clipStruc.samplesReceived + "/" + clipStruc.data.Length + " samples currently recived for ID " + row.id + "."); }
/// <summary> /// Processes the header messages received on the client. /// </summary> /// <param name="header">Clip's header message.</param> private void OnAudioHeaderReceived(AudioHeaderMessage header) { AudioStruc clipS = new AudioStruc(header.samples, header.channels, header.frequency, header.chunkSize); msgData.RecoverEarlyChunks(header, clipS, SaveChunk); if (msgData.CheckTimestamp(header)) { StartCoroutine( msgData.WaitTillReceiveAllTheStream( header, (uint id) => msgData[id].samplesReceived < msgData[id].data.Length, streamTimeout)); } }