Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
SoundEffectInstance.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 #if SILICONSTUDIO_PLATFORM_IOS
4 
5 using System;
6 using SiliconStudio.Core.Mathematics;
7 using SiliconStudio.Paradox.Audio.Wave;
8 
9 namespace SiliconStudio.Paradox.Audio
10 {
11  public partial class SoundEffectInstance
12  {
13  internal AudioVoice AudioVoice;
14 
15  internal override void UpdateLooping()
16  {
17  AudioVoice.SetLoopingPoints(0, int.MaxValue, 0, IsLooped);
18  }
19 
20  private SoundPlayState theoricPlayState;
21  public override SoundPlayState PlayState
22  {
23  get
24  {
25  if (theoricPlayState != SoundPlayState.Stopped && AudioVoice.DidVoicePlaybackEnd())
26  {
27  AudioVoice.Stop();
28  DataBufferLoaded = false;
29  PlayState = SoundPlayState.Stopped;
30  }
31 
32  return theoricPlayState;
33  }
34  internal set { theoricPlayState = value; }
35  }
36 
37  internal override void PlayImpl()
38  {
39  AudioVoice.Play();
40  }
41 
42  internal override void PauseImpl()
43  {
44  AudioVoice.Pause();
45  }
46 
47  internal override void StopImpl()
48  {
49  AudioVoice.Stop();
50  }
51 
52  internal override void ExitLoopImpl()
53  {
54  AudioVoice.SetLoopingPoints(0, int.MaxValue, 0, false);
55  }
56 
57  private void CreateVoice(WaveFormat waveFormat)
58  {
59  AudioVoice = new AudioVoice(AudioEngine, this, waveFormat);
60  }
61 
62  internal override void LoadBuffer()
63  {
64  AudioVoice.SetAudioData(soundEffect);
65  }
66 
67  private void PlatformSpecificDisposeImpl()
68  {
69  AudioVoice.Dispose();
70  }
71 
72  private void UpdatePitch()
73  {
74  // nothing to do here
75  // not supported.
76  }
77 
78  private void Apply3DImpl(AudioListener listener, AudioEmitter emitter)
79  {
80  var vectDirWorldBase = emitter.Position - listener.Position;
81  var baseChangeMat = Matrix.Identity;
82  baseChangeMat.Row2 = new Vector4(listener.Up, 0);
83  baseChangeMat.Row3 = new Vector4(listener.Forward, 0);
84  baseChangeMat.Row1 = new Vector4(Vector3.Cross(listener.Up, listener.Forward), 0);
85 
86  var vectDirListBase = Vector3.TransformNormal(vectDirWorldBase, baseChangeMat);
87  var azimut = 180f * (float)(Math.Atan2(vectDirListBase.X, vectDirListBase.Z)/Math.PI);
88  var elevation = 180f * (float)(Math.Atan2(vectDirListBase.Y, new Vector2(vectDirListBase.X, vectDirListBase.Z).Length())/Math.PI);
89  var distance = vectDirListBase.Length();
90 
91  ComputeDopplerFactor(listener,emitter);
92 
93  AudioVoice.Apply3D(azimut, elevation, distance / emitter.DistanceScale, MathUtil.Clamp((float)Math.Pow(2, Pitch) * dopplerPitchFactor, 0.5f, 2f));
94  }
95 
96  private void UpdateStereoVolumes()
97  {
98  // nothing to do here.
99  }
100 
101  private void Reset3DImpl()
102  {
103  AudioVoice.Reset3D();
104  }
105 
106  internal override void UpdateVolume()
107  {
108  AudioVoice.SetVolume(Volume);
109  }
110 
111  private void UpdatePan()
112  {
113  AudioVoice.SetPan(Pan);
114  }
115  }
116 }
117 
118 #endif
SiliconStudio.Paradox.Games.Mathematics.Vector2 Vector2
SoundPlayState
Current state (playing, paused, or stopped) of a sound implementing the IPlayableSound interface...
SiliconStudio.Core.Mathematics.Vector3 Vector3