Linux multi-monitor fullscreen support
[ryzomcore.git] / nel / src / sound / driver / openal / buffer_al.h
blob218d2fe37e22454599f6336f3ac876798debed15
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2010 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
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"
25 namespace NLSOUND
28 /**
29 * OpenAL buffer
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
37 * \date 2001
39 class CBufferAL : public IBuffer
41 public:
42 /// Constructor
43 CBufferAL( ALuint buffername=0 );
44 /// Destructor
45 virtual ~CBufferAL();
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;
84 private:
85 /// Buffer name
86 ALuint _BufferName;
87 /// Buffer name as string
88 NLMISC::TStringId _Name;
89 /// Sample format
90 ALenum _SampleFormat;
91 /// Frequency
92 ALuint _Frequency;
93 /// Buffer data (as OpenAL keeps it's own data and doesn't publish it back), aligned 16 byte
94 uint8 *_DataAligned;
95 /// The actual pointer used for deletion.
96 uint8 *_DataPtr;
97 /// The capacity of the buffer
98 uint _Capacity;
99 /// The size of the data in the buffer
100 uint _Size;
101 /// Storage mode
102 IBuffer::TStorageMode _StorageMode;
103 /// Buffer loaded or not
104 bool _IsLoaded;
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.
114 #ifdef _MSC_VER
115 # pragma pack(push,1)
116 #endif
118 template <class T> struct TFrameStereo
120 T Channel1;
121 T Channel2;
123 #ifdef __GNUC__
124 __attribute__ ((packed))
125 #endif
128 #ifdef _MSC_VER
129 # pragma pack(pop)
130 #endif
133 } // NLSOUND
136 #endif // NL_BUFFER_AL_H
138 /* End of buffer_al.h */