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

Stream that stores the left and right channels as separate arrays More...

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

Public Member Functions

 InterlacingAudioClip (float[] leftSamples, float[] rightSamples)
 
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 ChannelSamples => LSamples.Length
 
override int TotalSamples => Channels * LSamples.Length
 
override int Channels => 2
 
- Data Fields inherited from BGC.Audio.BGCAudioClip
float Duration => ChannelSamples / SamplingRate
 
override float SamplingRate => 44100f
 

Properties

int Position [get, private set]
 
int RawPosition = 0 [get, set]
 Simulated raw sample position More...
 
float [] LSamples [get]
 
float [] RSamples [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

int RemainingChannelSamples => Math.Max(0, LSamples.Length - Position)
 
int RemainingTotalSamples => Channels * RemainingChannelSamples
 
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

Stream that stores the left and right channels as separate arrays

Definition at line 10 of file InterlacingAudioClip.cs.

Constructor & Destructor Documentation

◆ InterlacingAudioClip()

BGC.Audio.InterlacingAudioClip.InterlacingAudioClip ( float []  leftSamples,
float []  rightSamples 
)
inline

Definition at line 34 of file InterlacingAudioClip.cs.

35  {
36  LSamples = leftSamples;
37  RSamples = rightSamples;
38  }

Member Function Documentation

◆ GetChannelRMS()

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

The RMS amplitude of each channel

Implements BGC.Audio.BGCStream.

Definition at line 61 of file InterlacingAudioClip.cs.

62  {
63  if (_channelRMS == null)
64  {
65  double rmsL = 0.0;
66  double rmsR = 0.0;
67 
68  for (int i = 0; i < ChannelSamples; i++)
69  {
70  rmsL += LSamples[i] * LSamples[i];
71  rmsR += RSamples[i] * RSamples[i];
72  }
73 
74  rmsL = Math.Sqrt(rmsL / ChannelSamples);
75  rmsR = Math.Sqrt(rmsR / ChannelSamples);
76 
77  _channelRMS = new double[2] { rmsL, rmsR };
78  }
79 
80  return _channelRMS;
81  }

◆ Read()

override int BGC.Audio.InterlacingAudioClip.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 40 of file InterlacingAudioClip.cs.

References BGC.Mathematics.GeneralMath.Clamp().

41  {
42  int copyLength = Math.Min(RemainingTotalSamples, count);
43 
44  for (int i = 0; i < copyLength / 2; i++)
45  {
46  data[offset + 2 * i] = LSamples[Position + i];
47  data[offset + 2 * i + 1] = RSamples[Position + i];
48  }
49 
50  RawPosition += copyLength;
51 
52  return copyLength;
53  }
int RawPosition
Simulated raw sample position
Here is the call graph for this function:

◆ Reset()

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

Sets this internal state of this stream to the initial state

Implements BGC.Audio.BGCStream.

◆ Seek()

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

Seek to the indicated position in the stream

Implements BGC.Audio.BGCStream.

Field Documentation

◆ _channelRMS

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

Definition at line 60 of file InterlacingAudioClip.cs.

◆ Channels

override int BGC.Audio.InterlacingAudioClip.Channels => 2

Definition at line 29 of file InterlacingAudioClip.cs.

◆ ChannelSamples

override int BGC.Audio.InterlacingAudioClip.ChannelSamples => LSamples.Length

Definition at line 23 of file InterlacingAudioClip.cs.

◆ RemainingChannelSamples

int BGC.Audio.InterlacingAudioClip.RemainingChannelSamples => Math.Max(0, LSamples.Length - Position)
private

Definition at line 31 of file InterlacingAudioClip.cs.

◆ RemainingTotalSamples

int BGC.Audio.InterlacingAudioClip.RemainingTotalSamples => Channels * RemainingChannelSamples
private

Definition at line 32 of file InterlacingAudioClip.cs.

◆ TotalSamples

override int BGC.Audio.InterlacingAudioClip.TotalSamples => Channels * LSamples.Length

Definition at line 24 of file InterlacingAudioClip.cs.

Property Documentation

◆ LSamples

float [] BGC.Audio.InterlacingAudioClip.LSamples
get

Definition at line 26 of file InterlacingAudioClip.cs.

◆ Position

int BGC.Audio.InterlacingAudioClip.Position
getprivate set

Definition at line 12 of file InterlacingAudioClip.cs.

◆ RawPosition

int BGC.Audio.InterlacingAudioClip.RawPosition = 0
getset

Simulated raw sample position

Definition at line 18 of file InterlacingAudioClip.cs.

◆ RSamples

float [] BGC.Audio.InterlacingAudioClip.RSamples
get

Definition at line 27 of file InterlacingAudioClip.cs.


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