Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. int chunk = currentChunk;
  2. int numSamples = Math.Min(numSamplesPerChunk * bytesPerSample, fileContent.Length - chunk * (numSamplesPerChunk * bytesPerSample));
  3. byte[] samples = new byte[numSamples];
  4. Array.Copy(fileContent, chunk * numSamplesPerChunk * bytesPerSample, samples, 0, samples.Length);
  5. float[] floatSamples = new float[samples.Length / bytesPerSample];
  6. for (int i = 0; i < floatSamples.Length; i++)
  7. {
  8. short valueShort = BitConverter.ToInt16(samples, i*bytesPerSample);
  9. float valueFloat = valueShort / (float)short.MaxValue;
  10. floatSamples[i] = valueFloat;
  11. }
  12. "a".Trim();
  13.  
  14. UnityThread.executeInUpdate(() => {
  15. AudioClip audioClip = AudioClip.Create("useless", samples.Length / bytesPerSample, 1, 48000, false);
  16. audioClip.SetData(floatSamples, 0);
  17.  
  18. AudioSource.clip = audioClip;
  19. AudioSource.Play();
  20. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement