Linux multi-monitor fullscreen support
[ryzomcore.git] / nel / src / sound / driver / xaudio2 / buffer_xaudio2.h
blob07957022c6d7aeb3eb24d7d6e6f2157e2fa03fba
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2008 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef NLSOUND_BUFFER_XAUDIO2_H
18 #define NLSOUND_BUFFER_XAUDIO2_H
20 #include "nel/sound/driver/buffer.h"
22 namespace NLSOUND {
23 class CSoundDriverXAudio2;
25 /**
26 * \brief CBufferXAudio2
27 * \date 2008-08-20 17:21GMT
28 * \author Jan Boon (Kaetemi)
29 * CBufferXAudio2 is an implementation of the IBuffer interface to run on XAudio2.
31 class CBufferXAudio2 : public IBuffer
33 protected:
34 // outside pointers
35 /// The sound driver that owns this buffer, used for stats. (artificial limit)
36 CSoundDriverXAudio2 *_SoundDriver;
38 // pointers
39 /// The sample data in this buffer. Aligned 16 byte.
40 uint8 *_DataAligned;
41 /// The actual pointer used for deletion.
42 uint8 *_DataPtr;
43 // instances
44 // XAudio2 buffer structure, could have one pre-configured
45 // here for optimization (looping state unknown).
46 // XAUDIO2_BUFFER _Buffer;
48 /// The capacity of the buffer
49 uint _Capacity;
50 /// The size of the data in the buffer
51 uint _Size;
52 /// The name of the buffer
53 NLMISC::TStringId _Name;
54 /// The sample format
55 TBufferFormat _Format;
56 /// The number of channels
57 uint8 _Channels;
58 /// Bits per sample
59 uint8 _BitsPerSample;
60 /// The sample frequency
61 uint _Frequency;
62 public:
63 CBufferXAudio2(CSoundDriverXAudio2 *soundDriver);
64 virtual ~CBufferXAudio2();
65 void release();
67 /// Returns a pointer to the PCM or ADPCM bytes.
68 inline const uint8 *getData() { return _DataAligned; }
69 /// Returns the sample format.
70 inline TBufferFormat getFormat() { return _Format; }
71 /// Returns the number of channels
72 inline uint8 getChannels() { return _Channels; }
73 /// Returns the bits per sample
74 inline uint8 getBitsPerSample() { return _BitsPerSample; }
75 /// Returns the sample rate.
76 inline uint getFrequency() { return _Frequency; }
78 /** Preset the name of the buffer. Used for async loading to give a name
79 * before the buffer is effectivly loaded.
80 * If the name after loading of the buffer doesn't match the preset name,
81 * the load will assert.
83 virtual void setName(NLMISC::TStringId bufferName);
84 /// Return the name of this buffer
85 virtual NLMISC::TStringId getName() const;
87 /// Set the sample format. (channels = 1, 2, ...; bitsPerSample = 8, 16; frequency = samples per second, 44100, ...)
88 virtual void setFormat(TBufferFormat format, uint8 channels, uint8 bitsPerSample, uint32 frequency);
89 /// Return the sample format information.
90 virtual void getFormat(TBufferFormat &format, uint8 &channels, uint8 &bitsPerSample, uint32 &frequency) const;
91 /// Set the storage mode of this buffer, call before filling this buffer. Storage mode is always software if OptionSoftwareBuffer is enabled. Default is auto.
92 virtual void setStorageMode(TStorageMode storageMode = IBuffer::StorageAuto);
93 /// Get the storage mode of this buffer.
94 virtual TStorageMode getStorageMode();
96 /// 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.
97 virtual uint8 *lock(uint capacity);
98 /// 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.
99 virtual bool unlock(uint size);
100 /// Copy the data with specified size into the buffer. A readable local copy is only guaranteed when OptionLocalBufferCopy is set. Returns true if ok.
101 virtual bool fill(const uint8 *src, uint size);
103 /// Return the size of the buffer, in bytes.
104 virtual uint getSize() const;
105 /// Return the duration (in ms) of the sample in the buffer.
106 virtual float getDuration() const;
107 /// Return true if the buffer is stereo (multi-channel), false if mono.
108 virtual bool isStereo() const;
109 /// Return true if the buffer is loaded. Used for async load/unload.
110 virtual bool isBufferLoaded() const;
112 }; /* class CBufferXAudio2 */
114 } /* namespace NLSOUND */
116 #endif /* #ifndef NLSOUND_BUFFER_XAUDIO2_H */
118 /* end of file */