Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
SoundEffect.iOS.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 
4 #if SILICONSTUDIO_PLATFORM_IOS
5 
6 using System;
7 using MonoTouch.UIKit;
8 using SiliconStudio.Core;
9 using SiliconStudio.Core.Mathematics;
10 using SiliconStudio.Paradox.Audio.Wave;
11 
12 namespace SiliconStudio.Paradox.Audio
13 {
14  public partial class SoundEffect
15  {
16  // need to convert the audio data to 44100Hz because having several input of different sampling rate in not working on iOS < 7.0
17  private void AdaptAudioDataImpl()
18  {
19  if(UIDevice.CurrentDevice.CheckSystemVersion(7, 0)) // input of different sampling rate work properly on iOS >= 7.0
20  return;
21 
22  if(WaveFormat.SampleRate >= AudioVoice.AudioUnitOutputSampleRate) // down sampling is not supported
23  return;
24 
25  // allocate the new audio buffer
26  var sampleRateRatio = WaveFormat.SampleRate / (float)AudioVoice.AudioUnitOutputSampleRate;
27  var newWaveDataSize = (int)Math.Floor(WaveDataSize / sampleRateRatio);
28  var newWaveDataPtr = Utilities.AllocateMemory(newWaveDataSize);
29 
30  // up-sample the audio data
31  if (Math.Abs(sampleRateRatio - 0.5f) < MathUtil.ZeroTolerance)
32  UpSampleByTwo(WaveDataPtr, newWaveDataPtr, newWaveDataSize, WaveFormat.Channels, false);
33  else
34  UpSample(WaveDataPtr, newWaveDataPtr, newWaveDataSize, sampleRateRatio, WaveFormat.Channels, false);
35 
36  // update the wave data buffer
37  Utilities.FreeMemory(nativeDataBuffer);
38  nativeDataBuffer = newWaveDataPtr;
39  WaveDataPtr = newWaveDataPtr;
40  WaveDataSize = newWaveDataSize;
41  WaveFormat = new WaveFormat(AudioVoice.AudioUnitOutputSampleRate, WaveFormat.Channels);
42  }
43 
44  private void DestroyImpl()
45  {
46  }
47  }
48 }
49 
50 #endif