Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
DynamicSoundEffectInstance.Windows.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_WINDOWS
4 
5 using System;
6 using System.Runtime.InteropServices;
7 using System.Threading;
8 
9 using SharpDX.XAudio2;
10 
11 namespace SiliconStudio.Paradox.Audio
12 {
13  public partial class DynamicSoundEffectInstance
14  {
15 
16  private void SubmitBufferImpl(byte[] buffer, int offset, int byteCount)
17  {
18  var gcHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
19  submittedBufferHandles.Enqueue(new SubBufferDataHandles(gcHandle));
20 
21  var audioBuffer = new AudioBuffer
22  {
23  AudioDataPointer = gcHandle.AddrOfPinnedObject()+offset,
24  AudioBytes = byteCount,
25  };
26 
27  SourceVoice.SubmitSourceBuffer(audioBuffer, null);
28 
29  Interlocked.Increment(ref pendingBufferCount);
30  Interlocked.Increment(ref internalPendingBufferCount);
31  }
32 
33  private void InitializeDynamicSound()
34  {
35  SourceVoice.BufferEnd += OnBufferEnd;
36  }
37 
38  private void OnBufferEnd(IntPtr context)
39  {
40  OnBufferEndCommon();
41  }
42 
43  private void ClearBuffersImpl()
44  {
45  SourceVoice.FlushSourceBuffers();
46  }
47 
48 
49  /// <summary>
50  /// A list of all the data handles lock for one subBuffer.
51  /// </summary>
52  private class SubBufferDataHandles
53  {
54  private GCHandle handle;
55 
56  public SubBufferDataHandles(GCHandle handle)
57  {
58  this.handle = handle;
59  }
60 
61  public void FreeHandles()
62  {
63  handle.Free();
64  }
65 
66  public int HandleCount { get { return 1; } }
67  };
68  }
69 }
70 
71 #endif