1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2010 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef NL_BUFFER_AL_H
21 #define NL_BUFFER_AL_H
23 #include "nel/sound/driver/buffer.h"
31 * A buffer can be filled with data. An OpenAL buffer cannot be streamed in, i.e.
32 * isFillMoreSupported() returns false (instead, streaming would be implemented
33 * by buffer queueing).
35 * \author Olivier Cado
36 * \author Nevrax France
39 class CBufferAL
: public IBuffer
43 CBufferAL( ALuint buffername
=0 );
47 /// Return the buffer name (as an int)
48 inline ALuint
bufferName() { return _BufferName
; }
50 /** Preset the name of the buffer. Used for async loading to give a name
51 * before the buffer is effectivly loaded.
52 * If the name after loading of the buffer doesn't match the preset name,
53 * the load will assert.
55 virtual void setName(NLMISC::TStringId bufferName
);
56 /// Return the name of this buffer
57 virtual NLMISC::TStringId
getName() const;
59 /// Set the sample format. (channels = 1, 2, ...; bitsPerSample = 8, 16; frequency = samples per second, 44100, ...)
60 virtual void setFormat(TBufferFormat format
, uint8 channels
, uint8 bitsPerSample
, uint32 frequency
);
61 /// Return the sample format information.
62 virtual void getFormat(TBufferFormat
&format
, uint8
&channels
, uint8
&bitsPerSample
, uint32
&frequency
) const;
63 /// Set the storage mode of this buffer, call before filling this buffer. Storage mode is always software if OptionSoftwareBuffer is enabled. Default is auto.
64 virtual void setStorageMode(TStorageMode storageMode
= IBuffer::StorageAuto
);
65 /// Get the storage mode of this buffer.
66 virtual TStorageMode
getStorageMode();
68 /// Get a writable pointer to the buffer of specified size. Use capacity to specify the required bytes. Returns NULL in case of failure. It is only guaranteed that the original data is still available when using StorageSoftware and the specified size is not larger than the size specified in the last lock. Call setStorageMode() and setFormat() first.
69 virtual uint8
*lock(uint capacity
);
70 /// Notify that you are done writing to this buffer, so it can be copied over to hardware if needed. Set size to the number of bytes actually written to the buffer. Returns true if ok.
71 virtual bool unlock(uint size
);
72 /// Copy the data with specified size into the buffer. A readable local copy is only guaranteed when OptionLocalBufferCopy is set. Returns true if ok.
73 virtual bool fill(const uint8
*src
, uint size
);
75 /// Return the size of the buffer, in bytes.
76 virtual uint
getSize() const;
77 /// Return the duration (in ms) of the sample in the buffer.
78 virtual float getDuration() const;
79 /// Return true if the buffer is stereo (multi-channel), false if mono.
80 virtual bool isStereo() const;
81 /// Return true if the buffer is loaded. Used for async load/unload.
82 virtual bool isBufferLoaded() const;
87 /// Buffer name as string
88 NLMISC::TStringId _Name
;
93 /// Buffer data (as OpenAL keeps it's own data and doesn't publish it back), aligned 16 byte
95 /// The actual pointer used for deletion.
97 /// The capacity of the buffer
99 /// The size of the data in the buffer
102 IBuffer::TStorageMode _StorageMode
;
103 /// Buffer loaded or not
108 // TFrameStereo is used to access a sample pair of 8/16bit
109 // samples at once. To make sure the data is aligned properly
110 // the various compilers need some (unfortunately vendor
111 // specific hints) to pack the data as good as possible
112 // without adding alignment optimizations to it.
115 # pragma pack(push,1)
118 template <class T
> struct TFrameStereo
124 __attribute__ ((packed
))
136 #endif // NL_BUFFER_AL_H
138 /* End of buffer_al.h */