TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
sawass sawass
NA
36
23.6k
explain of a class.
Jun 7 2011 4:57 AM
Hi,
Is
someone can
help me
what
is the
role
of this class
:
public class MeteringStream : WaveStream
{
public WaveStream SourceStream { get; private set; }
public int SamplesPerNotification { get; set; }
float[] maxSamples;
int sampleCount;
public event EventHandler<StreamVolumeEventArgs> StreamVolume;
MeteringStream(WaveStream sourceStream) :
this(sourceStream, sourceStream.WaveFormat.SampleRate / 10)
{
}
public MeteringStream(WaveStream sourceStream, int samplesPerNotification)
{
SourceStream = sourceStream;
if (sourceStream.WaveFormat.BitsPerSample != 32)
throw new ArgumentException("Metering Stream expects 32 bit floating point audio", "sourceStream");
maxSamples = new float[sourceStream.WaveFormat.Channels];
this.SamplesPerNotification = samplesPerNotification;
}
public override WaveFormat WaveFormat
{
get { return SourceStream.WaveFormat; }
}
public override long Length
{
get { return SourceStream.Length; }
}
public override long Position
{
get { return SourceStream.Position; }
set { SourceStream.Position = value; }
}
public override int Read(byte[] buffer, int offset, int count)
{
int bytesRead = SourceStream.Read(buffer, offset, count);
ProcessData(buffer, offset, bytesRead);
return bytesRead;
}
private void ProcessData(byte[] buffer, int offset, int count)
{
int index = 0;
while (index < count)
{
for (int channel = 0; channel < maxSamples.Length; channel++)
{
float sampleValue = Math.Abs(BitConverter.ToSingle(buffer, offset + index));
maxSamples[channel] = Math.Max(maxSamples[channel], sampleValue);
index += 4;
}
sampleCount++;
if (sampleCount >= SamplesPerNotification)
{
RaiseStreamVolumeNotification();
sampleCount = 0;
Array.Clear(maxSamples, 0, maxSamples.Length);
}
}
}
private void RaiseStreamVolumeNotification()
{
if (StreamVolume != null)
{
StreamVolume(this, new StreamVolumeEventArgs() { MaxSampleValues = (float[])maxSamples.Clone() });
}
}
}
public class StreamVolumeEventArgs : EventArgs
{
public float[] MaxSampleValues { get; set; }
}
and the internal class StreamVolumeEventArgs : EventArgs
Thanks in advance.
Reply
Answers (
6
)
Pass BSTR from C++ to C#
Problem when addinag a RibbonLabel to the Ribbon in word 2007