Hi Mark, I can switch to 1.6 also. I just didn't know that 1.6 is a release-build.
Thanks a lot!
Kay
Thanks a lot!
Kay
for (int n = 0; n < sampleCount; n+= 2)
{
buffer[offset + n] *= LeftVolume;
buffer[offset + n + 1] *= RightVolume;
}
public class VolumeSampleProvider : ISampleProvider
{
private ISampleProvider source;
private float volume;
public VolumeSampleProvider(ISampleProvider source)
{
this.volume = 1.0f;
public int Read(float[] buffer, int offset, int sampleCount)
{
int samplesRead = source.Read(buffer, offset, sampleCount);
for (int n = 0; n < sampleCount; n++)
{
buffer[offset + n] *= volume * .8F;
}
public float Volume
{
get { return volume; }
set { volume = value; }
}
and my i sample provider is:{
WaveFormat WaveFormat { get; }
int Read(float[] buffer, int offset, int count);
}
how i set left channel and write channel volume from this two class? public async void OpenFile(string filePath, PlaybackCallback callback)
{
var file = await StorageFile.GetFileFromPathAsync(filePath);
TrackInfo = new TrackInfo
{
MusicProperties = await file.Properties.GetMusicPropertiesAsync(),
Thumbnail = await file.GetThumbnailAsync(ThumbnailMode.SingleItem, 500)
};
_sampleAggregator = new SampleAggregator(4096);
_sampleAggregator.FftCalculated += (sender, args) =>
{
if (FftCalculated != null)
{
Window.Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
{
FftCalculated(sender, args);
});
}
};
var stream = await file.OpenAsync(FileAccessMode.Read);// .OpenReadAsync();
if (stream == null)
return;
using (stream)
{
//TODO: fix this!!!
var task = Task.Factory.StartNew(() =>
{
_activeStream = new MediaFoundationReader(stream);
_player = new WasapiOut(AudioClientShareMode.Shared, 200);
Task.WaitAll(new[] { _player.Init(CreateInputStream(_activeStream)) });
});
Task.WaitAll(new[] { task });
if (callback != null)
callback(true);
CanPlay = true;
}
}
private IWaveProvider CreateInputStream(IWaveProvider fileStream)
{
_filterSampleProvider = new FilterSampleProvider(fileStream, _filters, true, true);
_filterSampleProvider.SampleReady += (sender, args) =>
_sampleAggregator.Add(_filterSampleProvider.CurrentSample);
return new SampleToWaveProvider(_filterSampleProvider);
}
SampleAggrigator.cs (and FftEventArgs): public class SampleAggregator
{
public event EventHandler<FftEventArgs> FftCalculated;
private readonly Complex[] fftBuffer;
private readonly int m;
private int fftPos;
private float[] fftOutputBuffer;
public int FFTLength { get; set; }
public SampleAggregator(int fftLength = 1024)
{
if (!IsPowerOfTwo(fftLength))
{
throw new ArgumentException("FFT Length must be a power of two");
}
m = (int)Math.Log(fftLength, 2.0);
FFTLength = fftLength;
fftBuffer = new Complex[fftLength];
fftOutputBuffer = new float[fftLength];
}
bool IsPowerOfTwo(int x)
{
return (x & (x - 1)) == 0;
}
public void Add(float value)
{
if (FftCalculated != null)
{
fftBuffer[fftPos].X = (float)(value * FastFourierTransform.HammingWindow(fftPos, fftBuffer.Length));
fftBuffer[fftPos].Y = 0;
fftPos++;
if (fftPos >= fftBuffer.Length)
{
fftPos = 0;
// 1024 = 2^10
FastFourierTransform.FFT(true, m, fftBuffer);
for (int i = 0; i < fftBuffer.Length / 2; i++)
{
// Calculate actual intensities for the FFT results.
fftOutputBuffer[i] = (float)Math.Sqrt(fftBuffer[i].X * fftBuffer[i].X + fftBuffer[i].Y * fftBuffer[i].Y);
}
FftCalculated(this, new FftEventArgs(fftOutputBuffer));
}
}
}
}
public class FftEventArgs : EventArgs
{
[DebuggerStepThrough]
public FftEventArgs(float[] result)
{
this.Result = result;
}
public float[] Result { get; private set; }
}