BrawlCrate v0.41
Wii File Editor
Loading...
Searching...
No Matches
Public Member Functions | Properties | List of all members
BrawlLib.Internal.Audio.BufferData Struct Reference

Public Member Functions

void Fill (IAudioStream stream, bool loop)
 

Properties

int SampleOffset [get]
 
int SampleLength [get]
 
int DataOffset [get]
 
int DataLength [get]
 
IntPtr Part1Address [get]
 
int Part1Length [get]
 
int Part1Samples [get]
 
IntPtr Part2Address [get]
 
int Part2Length [get]
 
int Part2Samples [get]
 
bool IsSplit [get]
 

Member Function Documentation

◆ Fill()

void BrawlLib.Internal.Audio.BufferData.Fill ( IAudioStream  stream,
bool  loop 
)
inline
36 {
37 int blockAlign = stream.BitsPerSample * stream.Channels / 8;
38 int samplePos = stream.SamplePosition;
39 int sampleCount = _sampleLength;
40 int samplesRead;
41 bool end = false;
42
43 loop = loop && stream.IsLooping;
44 int lastSample = loop ? stream.LoopEndSample : stream.Samples;
45
46 VoidPtr blockAddr = _part1Address;
47 int blockRemaining = _part1Samples;
48
49 while (sampleCount > 0)
50 {
51 //Get current block sample count
52 int blockSamples = Math.Min(blockRemaining, sampleCount);
53
54 //Fill zeros
55 if (end)
56 {
57 Memory.Fill(blockAddr, (uint) (blockSamples * blockAlign), 0);
58 }
59 else
60 {
61 //Do we extend within last sample range?
62 if (samplePos <= lastSample && lastSample < samplePos + blockSamples)
63 {
64 blockSamples = lastSample - samplePos;
65 end = true;
66 }
67
68 samplesRead = stream.ReadSamples(blockAddr, blockSamples);
69 samplePos += samplesRead;
70
71 if (samplesRead < blockSamples)
72 {
73 blockSamples = samplesRead;
74 end = true;
75 }
76 else if (loop && end)
77 {
78 stream.Wrap();
79 if (samplePos == stream.SamplePosition)
80 {
81 samplePos = -1;
82 break;
83 }
84
85 samplePos = stream.SamplePosition;
86 end = false;
87 }
88 }
89
90 blockAddr += blockSamples * blockAlign;
91 blockRemaining -= blockSamples;
92
93 //Wrap to second buffer
94 if (blockRemaining <= 0)
95 {
96 blockAddr = _part2Address;
97 blockRemaining = _part2Samples;
98 }
99
100 sampleCount -= blockSamples;
101 }
102 }

Property Documentation

◆ DataLength

int BrawlLib.Internal.Audio.BufferData.DataLength
get

◆ DataOffset

int BrawlLib.Internal.Audio.BufferData.DataOffset
get

◆ IsSplit

bool BrawlLib.Internal.Audio.BufferData.IsSplit
get

◆ Part1Address

IntPtr BrawlLib.Internal.Audio.BufferData.Part1Address
get

◆ Part1Length

int BrawlLib.Internal.Audio.BufferData.Part1Length
get

◆ Part1Samples

int BrawlLib.Internal.Audio.BufferData.Part1Samples
get

◆ Part2Address

IntPtr BrawlLib.Internal.Audio.BufferData.Part2Address
get

◆ Part2Length

int BrawlLib.Internal.Audio.BufferData.Part2Length
get

◆ Part2Samples

int BrawlLib.Internal.Audio.BufferData.Part2Samples
get

◆ SampleLength

int BrawlLib.Internal.Audio.BufferData.SampleLength
get

◆ SampleOffset

int BrawlLib.Internal.Audio.BufferData.SampleOffset
get

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