3 #if SILICONSTUDIO_PLATFORM_ANDROID
6 using System.Runtime.InteropServices;
8 using SiliconStudio.Core;
9 using SiliconStudio.Core.Mathematics;
10 using SiliconStudio.Paradox.Audio.Wave;
12 namespace SiliconStudio.
Paradox.Audio
14 public partial class SoundEffect
16 internal byte[] WaveDataArray;
18 private GCHandle pinnedWaveData;
20 private unsafe
void AdaptAudioDataImpl()
22 var isStereo = WaveFormat.Channels == 2;
25 var sampleRateRatio = Math.Min(1, WaveFormat.SampleRate / (float)SoundEffectInstance.SoundEffectInstanceFrameRate);
26 var newWaveDataSize = (int)Math.Floor(WaveDataSize / sampleRateRatio) * (isStereo ? 1 : 2);
27 WaveDataArray =
new byte[newWaveDataSize];
29 fixed (byte* pNewWaveData = WaveDataArray)
32 if (Math.Abs(sampleRateRatio - 1f) < MathUtil.ZeroTolerance && !isStereo)
33 DuplicateTracks(WaveDataPtr, (IntPtr)pNewWaveData, newWaveDataSize);
34 else if (Math.Abs(sampleRateRatio - 0.5f) < MathUtil.ZeroTolerance)
35 UpSampleByTwo(WaveDataPtr, (IntPtr)pNewWaveData, newWaveDataSize, WaveFormat.Channels, !isStereo);
37 UpSample(WaveDataPtr, (IntPtr)pNewWaveData, newWaveDataSize, sampleRateRatio, WaveFormat.Channels, !isStereo);
41 pinnedWaveData = GCHandle.Alloc(WaveDataArray, GCHandleType.Pinned);
42 WaveDataPtr = pinnedWaveData.AddrOfPinnedObject();
43 WaveDataSize = newWaveDataSize;
46 Utilities.FreeMemory(nativeDataBuffer);
47 nativeDataBuffer = IntPtr.Zero;
50 private void DestroyImpl()
52 pinnedWaveData.Free();