3 * Copyright (c) 2007-2010 SlimDX Group
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
\r
6 * of this software and associated documentation files (the "Software"), to deal
\r
7 * in the Software without restriction, including without limitation the rights
\r
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
9 * copies of the Software, and to permit persons to whom the Software is
\r
10 * furnished to do so, subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in
\r
13 * all copies or substantial portions of the Software.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
\r
24 #include <xaudio2.h>
\r
26 #include "../VersionConfig.h"
\r
27 #include "../Utilities.h"
\r
28 #include "../DataStream.h"
\r
30 #include "AudioBuffer.h"
\r
32 using namespace System;
\r
33 using namespace System::Runtime::InteropServices;
\r
39 XAUDIO2_BUFFER AudioBuffer::ToUnmanaged()
\r
41 XAUDIO2_BUFFER result;
\r
43 result.Flags = static_cast<UINT32>( Flags );
\r
44 result.AudioBytes = AudioBytes;
\r
45 result.PlayBegin = PlayBegin;
\r
46 result.PlayLength = PlayLength;
\r
47 result.LoopBegin = LoopBegin;
\r
48 result.LoopLength = LoopLength;
\r
49 result.LoopCount = LoopCount;
\r
50 result.pContext = Context.ToPointer();
\r
52 DataStream^ dataStream;
\r
53 array<Byte>^ bytes = Utilities::ReadStream( AudioData, AudioBytes, &dataStream );
\r
55 if( bytes == nullptr )
\r
56 result.pAudioData = reinterpret_cast<BYTE*>( dataStream->PositionPointer );
\r
60 handle = GCHandle::Alloc( bytes, GCHandleType::Pinned );
\r
62 #if SLIMDX_XAUDIO2_VERSION < 23
\r
63 result.pAudioData = reinterpret_cast<const BYTE*>( handle.AddrOfPinnedObject().ToPointer() );
\r
65 result.pAudioData = reinterpret_cast<BYTE*>( handle.AddrOfPinnedObject().ToPointer() );
\r
72 void AudioBuffer::Destruct()
\r
74 if( handle.IsAllocated )
\r