BGC Tools
Public Member Functions | Data Fields | Properties | Private Attributes
BGC.Audio.SimpleAudioClip Class Reference

Simplest implementation of a samplebuffer-based stream. More...

Inheritance diagram for BGC.Audio.SimpleAudioClip:
Inheritance graph
[legend]
Collaboration diagram for BGC.Audio.SimpleAudioClip:
Collaboration graph
[legend]

Public Member Functions

 SimpleAudioClip (float[] samples, int channels)
 
override int Read (float[] data, int offset, int count)
 Copy count samples into the Data buffer, starting at offset. More...
 
override void Seek (int position)
 Seek to the indicated position in the stream More...
 
override void Reset ()
 Sets this internal state of this stream to the initial state More...
 
override IEnumerable< double > GetChannelRMS ()
 The RMS amplitude of each channel More...
 
- Public Member Functions inherited from BGC.Audio.BGCStream
void Initialize ()
 Perform any calculations necessary to prepare the Stream More...
 

Data Fields

override int TotalSamples => Samples.Length
 
override int ChannelSamples => Samples.Length / Channels
 
override int Channels => _channels
 
- Data Fields inherited from BGC.Audio.BGCAudioClip
float Duration => ChannelSamples / SamplingRate
 
override float SamplingRate => 44100f
 

Properties

int Position [get, set]
 
int RawPosition [get, private set]
 
float [] Samples [get]
 
- Properties inherited from BGC.Audio.BGCStream
abstract int Channels [get]
 
abstract int TotalSamples [get]
 
abstract int ChannelSamples [get]
 
abstract float SamplingRate [get]
 
- Properties inherited from BGC.Audio.IBGCStream
int Channels [get]
 The number of underlying Channels of this BGCStream More...
 
int TotalSamples [get]
 The total number of Samples of this BGCStream More...
 
int ChannelSamples [get]
 The number of Samples of each channel for this BGCStream More...
 
float SamplingRate [get]
 The sampling rate of the Stream More...
 

Private Attributes

readonly int _channels
 
int RemainingChannelSamples => RemainingTotalSamples / Channels
 
int RemainingTotalSamples => GeneralMath.Clamp(Samples.Length - RawPosition, 0, Samples.Length)
 
IEnumerable< double > _channelRMS = null
 

Additional Inherited Members

- Protected Member Functions inherited from BGC.Audio.BGCStream
virtual void _Initialize ()
 
- Protected Attributes inherited from BGC.Audio.BGCStream
bool initialized = false
 

Detailed Description

Simplest implementation of a samplebuffer-based stream.

Definition at line 10 of file SimpleAudioClip.cs.

Constructor & Destructor Documentation

◆ SimpleAudioClip()

BGC.Audio.SimpleAudioClip.SimpleAudioClip ( float []  samples,
int  channels 
)
inline

Definition at line 31 of file SimpleAudioClip.cs.

32  {
33  Samples = samples;
34  _channels = channels;
35  }

Member Function Documentation

◆ GetChannelRMS()

override IEnumerable<double> BGC.Audio.SimpleAudioClip.GetChannelRMS ( )
inlinevirtual

The RMS amplitude of each channel

Implements BGC.Audio.BGCStream.

Definition at line 60 of file SimpleAudioClip.cs.

61  {
62  if (_channelRMS == null)
63  {
64  double[] rms = new double[Channels];
65 
66  for (int i = 0; i < TotalSamples; i++)
67  {
68  rms[i % Channels] += Samples[i] * Samples[i];
69  }
70 
71  for(int i = 0; i < Channels; i++)
72  {
73  rms[i] = Math.Sqrt(rms[i] / ChannelSamples);
74  }
75 
76  _channelRMS = rms;
77  }
78 
79  return _channelRMS;
80  }
IEnumerable< double > _channelRMS

◆ Read()

override int BGC.Audio.SimpleAudioClip.Read ( float []  data,
int  offset,
int  count 
)
inlinevirtual

Copy count samples into the Data buffer, starting at offset.

Returns
The number of samples copied

Implements BGC.Audio.BGCStream.

Definition at line 37 of file SimpleAudioClip.cs.

References BGC.Mathematics.GeneralMath.Clamp().

38  {
39  //Just directly copy samples
40  int copyLength = Math.Min(RemainingTotalSamples, count);
41 
42  Array.Copy(
43  sourceArray: Samples,
44  sourceIndex: RawPosition,
45  destinationArray: data,
46  destinationIndex: offset,
47  length: copyLength);
48 
49  RawPosition += copyLength;
50 
51  return copyLength;
52  }
Here is the call graph for this function:

◆ Reset()

override void BGC.Audio.SimpleAudioClip.Reset ( )
virtual

Sets this internal state of this stream to the initial state

Implements BGC.Audio.BGCStream.

◆ Seek()

override void BGC.Audio.SimpleAudioClip.Seek ( int  position)
virtual

Seek to the indicated position in the stream

Implements BGC.Audio.BGCStream.

Field Documentation

◆ _channelRMS

IEnumerable<double> BGC.Audio.SimpleAudioClip._channelRMS = null
private

Definition at line 59 of file SimpleAudioClip.cs.

◆ _channels

readonly int BGC.Audio.SimpleAudioClip._channels
private

Definition at line 25 of file SimpleAudioClip.cs.

◆ Channels

override int BGC.Audio.SimpleAudioClip.Channels => _channels

Definition at line 26 of file SimpleAudioClip.cs.

Referenced by BGC.Tests.TestOverlapAdd.TestPhaseVocoding().

◆ ChannelSamples

override int BGC.Audio.SimpleAudioClip.ChannelSamples => Samples.Length / Channels

Definition at line 21 of file SimpleAudioClip.cs.

◆ RemainingChannelSamples

int BGC.Audio.SimpleAudioClip.RemainingChannelSamples => RemainingTotalSamples / Channels
private

Definition at line 28 of file SimpleAudioClip.cs.

◆ RemainingTotalSamples

int BGC.Audio.SimpleAudioClip.RemainingTotalSamples => GeneralMath.Clamp(Samples.Length - RawPosition, 0, Samples.Length)
private

Definition at line 29 of file SimpleAudioClip.cs.

◆ TotalSamples

override int BGC.Audio.SimpleAudioClip.TotalSamples => Samples.Length

Definition at line 20 of file SimpleAudioClip.cs.

Property Documentation

◆ Position

int BGC.Audio.SimpleAudioClip.Position
getset

Definition at line 13 of file SimpleAudioClip.cs.

◆ RawPosition

int BGC.Audio.SimpleAudioClip.RawPosition
getprivate set

Definition at line 18 of file SimpleAudioClip.cs.

◆ Samples

float [] BGC.Audio.SimpleAudioClip.Samples
get

Definition at line 23 of file SimpleAudioClip.cs.

Referenced by BGC.Tests.TestOverlapAdd.TestPhaseVocoding().


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