BrawlCrate v0.41
Wii File Editor
Loading...
Searching...
No Matches
Public Member Functions | Properties | List of all members
BrawlLib.Internal.Audio.AudioBuffer Class Referenceabstract
Inheritance diagram for BrawlLib.Internal.Audio.AudioBuffer:

Public Member Functions

virtual void Dispose ()
 
abstract void Play ()
 
abstract void Stop ()
 
abstract BufferData Lock (int offset, int length)
 
abstract void Unlock (BufferData data)
 
void Seek (int samplePos)
 
void Reset ()
 
virtual void Update ()
 
virtual void Fill ()
 
virtual void Fill (IAudioStream source, int samples, bool loop)
 

Properties

AudioProvider Owner [get]
 
IAudioStream Source [get]
 
WaveFormatTag Format [get]
 
int Frequency [get]
 
int Channels [get]
 
int BitsPerSample [get]
 
int SampleLength [get]
 
int DataLength [get]
 
int BlockAlign [get]
 
int WriteOffset [get]
 
int ReadOffset [get]
 
int WriteSample [get]
 
int ReadSample [get]
 
bool Loop [get, set]
 
abstract int Volume [get, set]
 
abstract int Pan [get, set]
 

Member Function Documentation

◆ Dispose()

virtual void BrawlLib.Internal.Audio.AudioBuffer.Dispose ( )
inlinevirtual
87 {
88 if (_owner != null)
89 {
90 _owner._buffers.Remove(this);
91 _owner = null;
92 }
93
94 GC.SuppressFinalize(this);
95 }

◆ Fill() [1/2]

virtual void BrawlLib.Internal.Audio.AudioBuffer.Fill ( )
inlinevirtual
172 {
173 //This only works if a source has been assigned!
174 if (_source == null)
175 {
176 return;
177 }
178
179 //Update read position
180 Update();
181
182 //Get number of samples available for writing.
183 int sampleCount = ((_readOffset <= _writeOffset ? _readOffset + _dataLength : _readOffset) - _writeOffset) /
184 _blockAlign / 8;
185
186 //Fill samples
187 Fill(_source, sampleCount, _loop);
188 }
virtual void Update()
Definition: AudioBuffer.cs:119
virtual void Fill()
Definition: AudioBuffer.cs:171

◆ Fill() [2/2]

virtual void BrawlLib.Internal.Audio.AudioBuffer.Fill ( IAudioStream  source,
int  samples,
bool  loop 
)
inlinevirtual
191 {
192 int byteCount = samples * _blockAlign;
193
194 //Lock buffer and fill
195 BufferData data = Lock(_writeOffset, byteCount);
196 try
197 {
198 data.Fill(source, loop);
199 }
200 finally
201 {
202 Unlock(data);
203 }
204
205 //Advance offsets
206 _writeOffset = (_writeOffset + byteCount) % _dataLength;
207 _writeSample = source.SamplePosition;
208 }
abstract void Unlock(BufferData data)
abstract BufferData Lock(int offset, int length)

◆ Lock()

abstract BufferData BrawlLib.Internal.Audio.AudioBuffer.Lock ( int  offset,
int  length 
)
pure virtual

◆ Play()

abstract void BrawlLib.Internal.Audio.AudioBuffer.Play ( )
pure virtual

◆ Reset()

void BrawlLib.Internal.Audio.AudioBuffer.Reset ( )
inline
115 {
116 _readOffset = _writeOffset = PlayCursor;
117 }

◆ Seek()

void BrawlLib.Internal.Audio.AudioBuffer.Seek ( int  samplePos)
inline
104 {
105 _readOffset = _writeOffset = PlayCursor;
106 _readSample = _writeSample = samplePos;
107
108 if (_source != null)
109 {
110 _source.SamplePosition = samplePos;
111 }
112 }

◆ Stop()

abstract void BrawlLib.Internal.Audio.AudioBuffer.Stop ( )
pure virtual

◆ Unlock()

abstract void BrawlLib.Internal.Audio.AudioBuffer.Unlock ( BufferData  data)
pure virtual

◆ Update()

virtual void BrawlLib.Internal.Audio.AudioBuffer.Update ( )
inlinevirtual
120 {
121 //Get current sample offset.
122 int sampleOffset = PlayCursor / _blockAlign;
123 //Get current byte offset
124 int byteOffset = sampleOffset * _blockAlign;
125 //Get sample difference since last update, taking into account circular wrapping.
126 int sampleDifference = ((byteOffset < _readOffset ? byteOffset + _dataLength : byteOffset) - _readOffset) /
127 _blockAlign;
128 //Get byte difference
129 //int byteDifference = sampleDifference * _blockAlign;
130
131 //If no change, why continue?
132 if (sampleDifference == 0)
133 {
134 return;
135 }
136
137 //Set new read offset.
138 _readOffset = byteOffset;
139
140 //Update looping
141 if (_source != null)
142 {
143 if (_loop && _source.IsLooping)
144 {
145 int start = _source.LoopStartSample;
146 int end = _source.LoopEndSample;
147 int newSample = _readSample + sampleDifference;
148
149 if (newSample >= end && _writeSample < _readSample)
150 {
151 _readSample = start + (newSample - start) % (end - start);
152 }
153 else
154 {
155 _readSample = Math.Min(newSample, _source.Samples);
156 }
157 }
158 else
159 {
160 _readSample = Math.Min(_readSample + sampleDifference, _source.Samples);
161 //if (_readSample >= _source.Samples)
162 // Stop();
163 }
164 }
165 else
166 {
167 _readSample += sampleDifference;
168 }
169 }
int LoopStartSample
Definition: IAudioStream.cs:13
int Samples
Definition: IAudioStream.cs:9
int LoopEndSample
Definition: IAudioStream.cs:14
bool IsLooping
Definition: IAudioStream.cs:12

Property Documentation

◆ BitsPerSample

int BrawlLib.Internal.Audio.AudioBuffer.BitsPerSample
get

◆ BlockAlign

int BrawlLib.Internal.Audio.AudioBuffer.BlockAlign
get

◆ Channels

int BrawlLib.Internal.Audio.AudioBuffer.Channels
get

◆ DataLength

int BrawlLib.Internal.Audio.AudioBuffer.DataLength
get

◆ Format

WaveFormatTag BrawlLib.Internal.Audio.AudioBuffer.Format
get

◆ Frequency

int BrawlLib.Internal.Audio.AudioBuffer.Frequency
get

◆ Loop

bool BrawlLib.Internal.Audio.AudioBuffer.Loop
getset
67 {
68 get => _loop;
69 set => _loop = value;
70 }

◆ Owner

AudioProvider BrawlLib.Internal.Audio.AudioBuffer.Owner
get

◆ Pan

abstract int BrawlLib.Internal.Audio.AudioBuffer.Pan
getset
79{ get; set; }

◆ ReadOffset

int BrawlLib.Internal.Audio.AudioBuffer.ReadOffset
get

◆ ReadSample

int BrawlLib.Internal.Audio.AudioBuffer.ReadSample
get

◆ SampleLength

int BrawlLib.Internal.Audio.AudioBuffer.SampleLength
get

◆ Source

IAudioStream BrawlLib.Internal.Audio.AudioBuffer.Source
get

◆ Volume

abstract int BrawlLib.Internal.Audio.AudioBuffer.Volume
getset
78{ get; set; }

◆ WriteOffset

int BrawlLib.Internal.Audio.AudioBuffer.WriteOffset
get

◆ WriteSample

int BrawlLib.Internal.Audio.AudioBuffer.WriteSample
get

The documentation for this class was generated from the following file: