2007-11-13 18:02:18 -08:00
|
|
|
#ifndef _AL_BUFFER_H_
|
|
|
|
#define _AL_BUFFER_H_
|
|
|
|
|
2012-09-14 02:42:36 -07:00
|
|
|
#include "alMain.h"
|
2007-11-13 18:02:18 -08:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2011-05-05 22:36:26 -07:00
|
|
|
/* User formats */
|
2010-12-03 22:33:41 -08:00
|
|
|
enum UserFmtType {
|
2012-01-10 00:41:05 -08:00
|
|
|
UserFmtByte = AL_BYTE_SOFT,
|
|
|
|
UserFmtUByte = AL_UNSIGNED_BYTE_SOFT,
|
|
|
|
UserFmtShort = AL_SHORT_SOFT,
|
|
|
|
UserFmtUShort = AL_UNSIGNED_SHORT_SOFT,
|
|
|
|
UserFmtInt = AL_INT_SOFT,
|
|
|
|
UserFmtUInt = AL_UNSIGNED_INT_SOFT,
|
|
|
|
UserFmtFloat = AL_FLOAT_SOFT,
|
|
|
|
UserFmtDouble = AL_DOUBLE_SOFT,
|
2018-01-19 19:28:23 -08:00
|
|
|
UserFmtMulaw = 0x10000000,
|
|
|
|
UserFmtAlaw,
|
2012-01-10 00:58:07 -08:00
|
|
|
UserFmtIMA4,
|
2014-03-04 22:44:30 -08:00
|
|
|
UserFmtMSADPCM,
|
2010-11-27 15:33:33 -08:00
|
|
|
};
|
2010-12-03 22:33:41 -08:00
|
|
|
enum UserFmtChannels {
|
2016-04-25 18:56:59 -07:00
|
|
|
UserFmtMono = AL_MONO_SOFT,
|
|
|
|
UserFmtStereo = AL_STEREO_SOFT,
|
|
|
|
UserFmtRear = AL_REAR_SOFT,
|
|
|
|
UserFmtQuad = AL_QUAD_SOFT,
|
|
|
|
UserFmtX51 = AL_5POINT1_SOFT, /* (WFX order) */
|
|
|
|
UserFmtX61 = AL_6POINT1_SOFT, /* (WFX order) */
|
|
|
|
UserFmtX71 = AL_7POINT1_SOFT, /* (WFX order) */
|
2018-01-19 19:28:23 -08:00
|
|
|
UserFmtBFormat2D = 0x20000000, /* WXY */
|
|
|
|
UserFmtBFormat3D, /* WXYZ */
|
2010-11-27 15:33:33 -08:00
|
|
|
};
|
|
|
|
|
2017-01-18 07:13:23 -08:00
|
|
|
ALsizei BytesFromUserFmt(enum UserFmtType type);
|
|
|
|
ALsizei ChannelsFromUserFmt(enum UserFmtChannels chans);
|
|
|
|
inline ALsizei FrameSizeFromUserFmt(enum UserFmtChannels chans, enum UserFmtType type)
|
2010-11-28 12:53:35 -08:00
|
|
|
{
|
2010-12-03 22:33:41 -08:00
|
|
|
return ChannelsFromUserFmt(chans) * BytesFromUserFmt(type);
|
2010-11-28 12:53:35 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-27 15:33:33 -08:00
|
|
|
/* Storable formats */
|
2010-11-26 23:42:30 -08:00
|
|
|
enum FmtType {
|
2018-01-19 20:10:31 -08:00
|
|
|
FmtUByte = UserFmtUByte,
|
2010-12-03 22:33:41 -08:00
|
|
|
FmtShort = UserFmtShort,
|
|
|
|
FmtFloat = UserFmtFloat,
|
2018-01-17 08:49:49 -08:00
|
|
|
FmtMulaw = UserFmtMulaw,
|
|
|
|
FmtAlaw = UserFmtAlaw,
|
2010-11-26 23:42:30 -08:00
|
|
|
};
|
|
|
|
enum FmtChannels {
|
2011-03-16 05:47:07 -07:00
|
|
|
FmtMono = UserFmtMono,
|
2010-12-03 22:33:41 -08:00
|
|
|
FmtStereo = UserFmtStereo,
|
2011-03-16 05:47:07 -07:00
|
|
|
FmtRear = UserFmtRear,
|
|
|
|
FmtQuad = UserFmtQuad,
|
|
|
|
FmtX51 = UserFmtX51,
|
|
|
|
FmtX61 = UserFmtX61,
|
|
|
|
FmtX71 = UserFmtX71,
|
2014-10-31 17:18:45 -07:00
|
|
|
FmtBFormat2D = UserFmtBFormat2D,
|
|
|
|
FmtBFormat3D = UserFmtBFormat3D,
|
2010-11-26 23:42:30 -08:00
|
|
|
};
|
2013-07-23 00:13:15 -07:00
|
|
|
#define MAX_INPUT_CHANNELS (8)
|
2010-11-26 23:42:30 -08:00
|
|
|
|
2017-01-18 07:13:23 -08:00
|
|
|
ALsizei BytesFromFmt(enum FmtType type);
|
|
|
|
ALsizei ChannelsFromFmt(enum FmtChannels chans);
|
|
|
|
inline ALsizei FrameSizeFromFmt(enum FmtChannels chans, enum FmtType type)
|
2010-11-28 12:53:35 -08:00
|
|
|
{
|
2010-11-29 19:48:18 -08:00
|
|
|
return ChannelsFromFmt(chans) * BytesFromFmt(type);
|
2010-11-28 12:53:35 -08:00
|
|
|
}
|
|
|
|
|
2010-11-26 23:42:30 -08:00
|
|
|
|
2013-10-07 05:41:41 -07:00
|
|
|
typedef struct ALbuffer {
|
2010-09-22 17:19:35 -07:00
|
|
|
ALvoid *data;
|
2009-10-22 08:53:59 -07:00
|
|
|
|
2011-10-03 10:07:50 -07:00
|
|
|
ALsizei Frequency;
|
|
|
|
ALenum Format;
|
|
|
|
ALsizei SampleLen;
|
|
|
|
|
2010-11-28 12:53:35 -08:00
|
|
|
enum FmtChannels FmtChannels;
|
2010-11-29 15:19:39 -08:00
|
|
|
enum FmtType FmtType;
|
2016-05-21 03:27:51 -07:00
|
|
|
ALuint BytesAlloc;
|
2009-10-22 08:53:59 -07:00
|
|
|
|
2010-12-03 22:33:41 -08:00
|
|
|
enum UserFmtChannels OriginalChannels;
|
|
|
|
enum UserFmtType OriginalType;
|
2011-10-01 19:52:07 -07:00
|
|
|
ALsizei OriginalSize;
|
2014-03-03 17:05:08 -08:00
|
|
|
ALsizei OriginalAlign;
|
2010-05-12 01:36:09 -07:00
|
|
|
|
2017-01-18 07:13:23 -08:00
|
|
|
ALsizei LoopStart;
|
|
|
|
ALsizei LoopEnd;
|
2010-05-13 02:03:48 -07:00
|
|
|
|
2014-09-03 15:40:15 -07:00
|
|
|
ATOMIC(ALsizei) UnpackAlign;
|
|
|
|
ATOMIC(ALsizei) PackAlign;
|
Add an extension to alter the block alignment for buffer unpack/pack ops
This is for unpacking (reading, e.g. alBufferData) and packing (writing, e.g.
alGetBufferSamplesSOFT) operations. The alignments are specified in sample
frames, with 0 meaning the default (65 for IMA4, 1 otherwise). IMA4 alignment
must be a multiple of 8, plus 1 (e.g. alignment = n*8 + 1), otherwise an error
will occur during (un)packing. Chenging the block alignment does not affect
already-loaded sample data, only future unpack/pack operations... so for
example, this is perfectly valid:
// Load mono IMA4 data with a block alignment of 1024 bytes, or 2041 sample
// frames.
alBufferi(buffer, AL_UNPACK_BLOCK_ALIGNMENT_SOFT, 2041);
alBufferData(buffer, AL_FORMAT_MONO_IMA4, data, data_len, srate);
alBufferi(buffer, AL_UNPACK_BLOCK_ALIGNMENT_SOFT, 0);
2014-03-04 05:16:45 -08:00
|
|
|
|
2012-04-19 22:14:02 -07:00
|
|
|
/* Number of times buffer was attached to a source (deletion can only occur when 0) */
|
|
|
|
RefCount ref;
|
2009-10-22 08:53:59 -07:00
|
|
|
|
2011-09-11 03:57:40 -07:00
|
|
|
RWLock lock;
|
|
|
|
|
2012-04-19 22:14:02 -07:00
|
|
|
/* Self ID */
|
|
|
|
ALuint id;
|
2007-11-13 18:02:18 -08:00
|
|
|
} ALbuffer;
|
|
|
|
|
2014-06-29 02:04:05 -07:00
|
|
|
ALbuffer *NewBuffer(ALCcontext *context);
|
2014-06-30 00:10:40 -07:00
|
|
|
void DeleteBuffer(ALCdevice *device, ALbuffer *buffer);
|
2014-06-29 02:04:05 -07:00
|
|
|
|
2016-05-10 23:42:44 -07:00
|
|
|
inline void LockBuffersRead(ALCdevice *device)
|
|
|
|
{ LockUIntMapRead(&device->BufferMap); }
|
|
|
|
inline void UnlockBuffersRead(ALCdevice *device)
|
|
|
|
{ UnlockUIntMapRead(&device->BufferMap); }
|
|
|
|
inline void LockBuffersWrite(ALCdevice *device)
|
|
|
|
{ LockUIntMapWrite(&device->BufferMap); }
|
|
|
|
inline void UnlockBuffersWrite(ALCdevice *device)
|
|
|
|
{ UnlockUIntMapWrite(&device->BufferMap); }
|
|
|
|
|
2013-11-04 13:51:19 -08:00
|
|
|
inline struct ALbuffer *LookupBuffer(ALCdevice *device, ALuint id)
|
2016-05-10 23:42:44 -07:00
|
|
|
{ return (struct ALbuffer*)LookupUIntMapKeyNoLock(&device->BufferMap, id); }
|
2013-11-04 13:51:19 -08:00
|
|
|
inline struct ALbuffer *RemoveBuffer(ALCdevice *device, ALuint id)
|
2016-05-10 23:42:44 -07:00
|
|
|
{ return (struct ALbuffer*)RemoveUIntMapKeyNoLock(&device->BufferMap, id); }
|
2013-11-04 13:51:19 -08:00
|
|
|
|
2009-08-15 09:14:08 -07:00
|
|
|
ALvoid ReleaseALBuffers(ALCdevice *device);
|
2007-11-13 18:02:18 -08:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|