10 #ifndef __XMA2DEFS_INCLUDED__
11 #define __XMA2DEFS_INCLUDED__
138 #define XMA_OUTPUT_SAMPLE_BYTES 2u
139 #define XMA_OUTPUT_SAMPLE_BITS (XMA_OUTPUT_SAMPLE_BYTES * 8u)
142 #define XMA_BYTES_PER_PACKET 2048u
143 #define XMA_BITS_PER_PACKET (XMA_BYTES_PER_PACKET * 8u)
146 #define XMA_PACKET_HEADER_BYTES 4u
147 #define XMA_PACKET_HEADER_BITS (XMA_PACKET_HEADER_BYTES * 8u)
150 #define XMA_SAMPLES_PER_FRAME 512u
153 #define XMA_SAMPLES_PER_SUBFRAME 128u
156 #define XMA_READBUFFER_MAX_PACKETS 4095u
157 #define XMA_READBUFFER_MAX_BYTES (XMA_READBUFFER_MAX_PACKETS * XMA_BYTES_PER_PACKET)
160 #define XMA_WRITEBUFFER_MAX_BYTES (31u * 256u)
163 #define XMA_WRITEBUFFER_BYTE_ALIGNMENT 256u
166 #define XMA_MIN_SUBFRAMES_TO_DECODE 1u
167 #define XMA_MAX_SUBFRAMES_TO_DECODE 8u
168 #define XMA_OPTIMAL_SUBFRAMES_TO_DECODE 4u
171 #define XMA_MAX_LOOPCOUNT 254u
172 #define XMA_INFINITE_LOOP 255u
185 #define WAVE_FORMAT_XMA2 0x166
219 #ifndef WAVE_FORMAT_XMA
220 #define WAVE_FORMAT_XMA 0x0165
224 #ifndef XMA_SPEAKER_LEFT
225 #define XMA_SPEAKER_LEFT 0x01
226 #define XMA_SPEAKER_RIGHT 0x02
227 #define XMA_SPEAKER_CENTER 0x04
228 #define XMA_SPEAKER_LFE 0x08
229 #define XMA_SPEAKER_LEFT_SURROUND 0x10
230 #define XMA_SPEAKER_RIGHT_SURROUND 0x20
231 #define XMA_SPEAKER_LEFT_BACK 0x40
232 #define XMA_SPEAKER_RIGHT_BACK 0x80
304 #endif // #ifndef WAVE_FORMAT_XMA
337 return (
DWORD)(pPacket[0] >> 2);
342 return ((
DWORD)(pPacket[0] & 0x3) << 13) |
343 ((
DWORD)(pPacket[1]) << 5) |
344 ((
DWORD)(pPacket[2]) >> 3);
349 return (
DWORD)(pPacket[2] & 0x7);
354 return (
DWORD)(pPacket[3]);
374 #define XMA_BITS_IN_FRAME_LENGTH_FIELD 15
377 #define XMA_FINAL_FRAME_MARKER 0x7FFF
387 #ifndef XMA2DEFS_ASSERT
389 #define XMA2DEFS_ASSERT ASSERT
391 #define XMA2DEFS_ASSERT(a)
404 __in_ecount(nBlockCount)
const DWORD* pSeekTable,
405 DWORD nDesiredSample,
406 __out
DWORD* pnBlockContainingSample,
407 __out
DWORD* pnSampleOffsetWithinBlock
410 DWORD nPreviousTotalSamples = 0;
412 DWORD nTotalSamplesSoFar;
418 for (nBlock = 0; nBlock < nBlockCount; ++nBlock)
420 nTotalSamplesSoFar = pSeekTable[nBlock];
421 if (nTotalSamplesSoFar > nDesiredSample)
423 *pnBlockContainingSample = nBlock;
424 *pnSampleOffsetWithinBlock = nDesiredSample - nPreviousTotalSamples;
427 nPreviousTotalSamples = nTotalSamplesSoFar;
438 __in_bcount(nBitPosition / 8 + 3)
439 __in
const BYTE* pPacket,
444 DWORD nBytePosition = nBitPosition / 8;
445 DWORD nBitOffset = nBitPosition % 8;
449 nRegion = (
DWORD)(pPacket[nBytePosition+0]) << 8 |
450 (
DWORD)(pPacket[nBytePosition+1]);
451 return (nRegion >> (1 - nBitOffset)) & 0x7FFF;
455 nRegion = (
DWORD)(pPacket[nBytePosition+0]) << 16 |
456 (
DWORD)(pPacket[nBytePosition+1]) << 8 |
457 (
DWORD)(pPacket[nBytePosition+2]);
458 return (nRegion >> (9 - nBitOffset)) & 0x7FFF;
468 __in_bcount(nXmaDataBytes)
const BYTE* pXmaData,
474 const BYTE* pCurrentPacket;
475 DWORD nPacketsExamined = 0;
476 DWORD nFrameCountSoFar = 0;
478 DWORD nFrameBitOffset;
491 if (pCurrentPacket + XMA_BYTES_PER_PACKET > pXmaData + nXmaDataBytes)
501 nFramesToSkip = nDesiredFrame - nFrameCountSoFar;
507 while (nFramesToSkip--)
514 return (
DWORD)(pCurrentPacket - pXmaData) * 8 + nFrameBitOffset;
532 __in_bcount(nXmaDataBytes)
const BYTE* pXmaData,
537 const BYTE* pLastPacket;
538 DWORD nBytesToNextPacket;
539 DWORD nFrameBitOffset;
540 DWORD nFramesInLastPacket;
556 if (pLastPacket + nBytesToNextPacket + XMA_BYTES_PER_PACKET > pXmaData + nXmaDataBytes)
560 pLastPacket += nBytesToNextPacket;
567 pLastPacket -= nBytesToNextPacket;
575 while (--nFramesInLastPacket)
582 return (
DWORD)(pLastPacket - pXmaData) * 8 + nFrameBitOffset;
594 __in_bcount(nXmaDataBytes)
const BYTE* pXmaData,
597 DWORD nDesiredSample,
598 __out
DWORD* pnBitOffset,
600 __out
DWORD* pnSubFrame
612 *pnBitOffset = nBitOffset;
613 *pnSubFrame = nSubFrame;
628 DWORD dwXmaRate = 48000;
630 if (dwGeneralRate <= 24000) dwXmaRate = 24000;
631 else if (dwGeneralRate <= 32000) dwXmaRate = 32000;
632 else if (dwGeneralRate <= 44100) dwXmaRate = 44100;
645 DWORD dwStandardMask = 0;
656 return dwStandardMask;
681 #define XMASWAP2BYTES(n) ((WORD)(((n) >> 8) | (((n) & 0xff) << 8)))
682 #define XMASWAP4BYTES(n) ((DWORD)((n) >> 24 | (n) << 24 | ((n) & 0xff00) << 8 | ((n) & 0xff0000) >> 8))
690 pXma2Format->wfx.wFormatTag =
XMASWAP2BYTES(pXma2Format->wfx.wFormatTag);
691 pXma2Format->wfx.nChannels =
XMASWAP2BYTES(pXma2Format->wfx.nChannels);
692 pXma2Format->wfx.nSamplesPerSec =
XMASWAP4BYTES(pXma2Format->wfx.nSamplesPerSec);
693 pXma2Format->wfx.nAvgBytesPerSec =
XMASWAP4BYTES(pXma2Format->wfx.nAvgBytesPerSec);
694 pXma2Format->wfx.nBlockAlign =
XMASWAP2BYTES(pXma2Format->wfx.nBlockAlign);
695 pXma2Format->wfx.wBitsPerSample =
XMASWAP2BYTES(pXma2Format->wfx.wBitsPerSample);
696 pXma2Format->wfx.cbSize =
XMASWAP2BYTES(pXma2Format->wfx.cbSize);
697 pXma2Format->NumStreams =
XMASWAP2BYTES(pXma2Format->NumStreams);
698 pXma2Format->ChannelMask =
XMASWAP4BYTES(pXma2Format->ChannelMask);
699 pXma2Format->SamplesEncoded =
XMASWAP4BYTES(pXma2Format->SamplesEncoded);
700 pXma2Format->BytesPerBlock =
XMASWAP4BYTES(pXma2Format->BytesPerBlock);
701 pXma2Format->PlayBegin =
XMASWAP4BYTES(pXma2Format->PlayBegin);
702 pXma2Format->PlayLength =
XMASWAP4BYTES(pXma2Format->PlayLength);
703 pXma2Format->LoopBegin =
XMASWAP4BYTES(pXma2Format->LoopBegin);
704 pXma2Format->LoopLength =
XMASWAP4BYTES(pXma2Format->LoopLength);
705 pXma2Format->BlockCount =
XMASWAP2BYTES(pXma2Format->BlockCount);
718 #endif // #ifndef __XMA2DEFS_INCLUDED__
#define XMA_PACKET_HEADER_BITS
#define XMA_SPEAKER_RIGHT_SURROUND
__inline DWORD GetStandardChannelMaskFromXmaMask(BYTE bXmaMask)
typedef HRESULT(WINAPI *LPD3DXIMTSIGNALCALLBACK)(CONST D3DXVECTOR2 *uv
__inline HRESULT GetXmaBlockContainingSample(DWORD nBlockCount, __in_ecount(nBlockCount) const DWORD *pSeekTable, DWORD nDesiredSample, __out DWORD *pnBlockContainingSample, __out DWORD *pnSampleOffsetWithinBlock)
#define SPEAKER_FRONT_CENTER
#define SPEAKER_BACK_LEFT
#define SPEAKER_BACK_RIGHT
#define XMA_SAMPLES_PER_FRAME
__inline DWORD GetXmaPacketFrameCount(__in_bcount(1) const BYTE *pPacket)
__inline DWORD GetXmaSampleRate(DWORD dwGeneralRate)
#define SPEAKER_FRONT_RIGHT
#define XMA_SAMPLES_PER_SUBFRAME
__inline DWORD GetXmaPacketFirstFrameOffsetInBits(__in_bcount(3) const BYTE *pPacket)
struct XMA2WAVEFORMATEX * PXMA2WAVEFORMATEX
#define SPEAKER_SIDE_LEFT
#define XMA_SPEAKER_RIGHT
__inline DWORD GetLastXmaFrameBitPosition(__in_bcount(nXmaDataBytes) const BYTE *pXmaData, DWORD nXmaDataBytes, DWORD nStreamIndex)
#define XMA2DEFS_ASSERT(a)
struct XMA2PACKET XMA2PACKET
__inline DWORD GetXmaFrameLengthInBits(__in const BYTE *pPacket, DWORD nBitPosition)
#define XMA_SPEAKER_LEFT_SURROUND
#define XMA_SPEAKER_RIGHT_BACK
XMASTREAMFORMAT XmaStreams[1]
__inline HRESULT LocalizeXma2Format(__inout XMA2WAVEFORMATEX *pXma2Format)
__inline DWORD GetXmaPacketSkipCount(__in_bcount(4) const BYTE *pPacket)
struct XMA2WAVEFORMATEX XMA2WAVEFORMATEX
struct XMA2STREAMFORMAT XMA2STREAMFORMAT
struct XMASTREAMFORMAT XMASTREAMFORMAT
XMA2STREAMFORMAT Streams[1]
BYTE XmaData[XMA_BYTES_PER_PACKET-sizeof(DWORD)]
struct XMAWAVEFORMAT XMAWAVEFORMAT
#define SPEAKER_LOW_FREQUENCY
__inline BYTE GetXmaChannelMaskFromStandardMask(DWORD dwStandardMask)
#define XMA_SPEAKER_LEFT_BACK
typedef DWORD(WINAPI *XInputGetState_t)(DWORD dwUserIndex
struct XMA2WAVEFORMAT XMA2WAVEFORMAT
#define SPEAKER_SIDE_RIGHT
#define XMA_SPEAKER_CENTER
#define XMA_BYTES_PER_PACKET
__inline HRESULT GetXmaDecodePositionForSample(__in_bcount(nXmaDataBytes) const BYTE *pXmaData, DWORD nXmaDataBytes, DWORD nStreamIndex, DWORD nDesiredSample, __out DWORD *pnBitOffset, __out DWORD *pnSubFrame)
#define SPEAKER_FRONT_LEFT
__inline DWORD GetXmaPacketMetadata(__in_bcount(3) const BYTE *pPacket)
__inline DWORD GetXmaFrameBitPosition(__in_bcount(nXmaDataBytes) const BYTE *pXmaData, DWORD nXmaDataBytes, DWORD nStreamIndex, DWORD nDesiredFrame)