Quantcast
Channel: NAudio
Viewing all 5831 articles
Browse latest View live

New Post: Release build of NAudio 1.5

$
0
0
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

New Post: 10 band Equalizer

$
0
0
Hi James,

I was able to modify the equalizer settings (BassTreble only using the Audacity effect as a baseline) while audio was playing. I was using the NAudio library and the bufferedWaveProvider coupled with the CircularBuffer to ensure continuous playback. The waveout device would then read from the last provider to playback the modified buffers.

Paul

New Post: DmoResamplerStream E_NOINTERFACE

$
0
0
I am already writing my own little audio libary to learn more about that topic. I am currently using it for my directsound wrapper. It works perfectly but you need to write a little postcompiler using libaries like Mono.Cecil

New Post: Mute linein

$
0
0
hi Markus, no there is no active development on the mixer API at the moment. It was one of the first bits of NAudio I did, back when I didn't have a clue about how to do P/Invoke, and hasn't turned out to be particularly useful to me, so it hasn't had much attention apart from a few occasional bugfixes. Another problem with the API is that since Windows Vista it has become very difficult to work out exactly which mixer control is which. But if you want to contribute a fix to the Mute control it would be greatly appreciated.

Mark

New Post: change left or Right channel volume.

$
0
0
I'd do this with a custom ISampleProvider, which would make it easy to multiply the samples by different left and right channel volumes as they came through. Look at the source code for VolumeSampleProvider for an example of mono volume modification. It wouldn't be too hard to change it for stereo - you'd just have LeftVolume and RightVolume and you'd alternate samples in the Read method:
for (int n = 0; n < sampleCount; n+= 2)
{
    buffer[offset + n] *= LeftVolume;
    buffer[offset + n + 1] *= RightVolume;
}

New Post: change left or Right channel volume.

$
0
0
I can set master volume for overall song.
like: volumesampleprovider class:
 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:
public interface ISampleProvider
{

    WaveFormat WaveFormat { get; }
    int Read(float[] buffer, int offset, int count);
}
how i set left channel and write channel volume from this two class?
my audioplaybackpanel class is:
this.setVolumeDelegate = (vol) => waveChannel.Volume = vol;
setVolumeDelegate(volumeSlider1.Volume);

I want to set left and right channel from this(audioplaybackpanel class)

New Post: How would I detect drum beats in a live stream?

$
0
0
I am working with a speed drummer, and need to detect each beat of a single drum. How would I do this using NAudio?

New Post: 10 band Equalizer

$
0
0
Thanks Paul, that looks like the way to tackle it.

Will be some modification to the way the WaveStream is handled. I'm glad that we have Mark's mp3 streaming demo !

Jim

New Post: 10 band Equalizer

$
0
0
Hi James,

Is there a way I could take a peek at the code. I am tasked to make a 27-band equalizer (similar to Audacity) and looking at a 10-band may help me along the way. We can take this offline if you wish, but don't know if there is a way to ping you without publishing my email address.

Paul

New Post: 10 band Equalizer

$
0
0
If you are making effects for NAudio, then I strongly recommend using ISampleProvider as your base class rather than WaveStream. It will make your life much simpler. I'm hoping to get some example effects into a future version of NAudio to show what I mean.

New Post: 10 band Equalizer

$
0
0
Thanks Mark for the tip.

Also I will take this opportunity to thank you for a great piece of work :)

brunp - I'm happy to post some code up and how I tackled it a bit later. The codes in a bit of a mess at the moment as I try to get it all working ! 27 Band wow ! What frequency range are you wanting to cover with that ?
I thought 20-20,000Hz as standard but I have had to get somebody with younger ears to confirm some of my tests ! I can't hear that range now !

Jim

New Post: Change Volume of Mp3 during play

$
0
0
Ahh interesting.. I will experiment with all options. I am using this with XNA for a game prototype. I am using XNA's default audio library to handle UI and game sounds, but I needed something else to allow users to customize their soundtrack and NAudio seems to be doing great in that aspect. I will post my results.

New Post: Custom sample provider FFT sample capture issue

$
0
0
Followed the WPF example and still have the same issue. I used the NAudio WPF example SampleAggrigator rather than my own. Although, I stripped out the volume code; didn't need it. The spectrum analyzer is now being fed by event rather than DispatcherTimer reading directly from the SampleAggrigator.

When I set a tracepoint; FftCalculated fired 8 times, stopped for a second, then fired 8 times, stopped for a second, and repeated this behavior.

Updated playback engine code:
    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; }
  }

New Post: Custom sample provider FFT sample capture issue

$
0
0
OK, what is likely happening is that your soundcard is using large buffers. So when a new buffer is filled up it reads enough from the source to do several FFTs. Your options are either to work with smaller buffers, or if you really must have 32 ms, then you could put each lot of FFT results into a queue and read from that queue each 32 ms. However, you'd need to make sure the FFT buffer wasn't being reused in that case (a new one for each FFT would be needed).

New Post: Change Volume of Mp3 during play

$
0
0
works pretty good! There is a little bit of a clipping noise when increasing volume but its not bad. One thing I noticed (or maybe its my ears) is that past a volume of 5 there seems to be no noticeable difference. It seems to take float values between 0.0 and 10.0 but again anything after 5 seems the same volume.

New Post: Change Volume of Mp3 during play

$
0
0
the difference between 5x and 10x should be 6dB, which is the same as the difference between 1x and 2x. However, by the time you've amplified that much, clipping may be reducing any further gains. A dynamic range compressor is really what you want for significant volume boosts.

New Post: Change Volume of Mp3 during play

$
0
0
Ok cool, that explains it. Since really this is being used as my BackGroundMusic player... I will create a proper ratio of volume values between 0 and 5 simulated visually as 0-9, and use the last volume values between 5.1 and 10 as simulated visually as 9-10... that way volume GUI slider will appear to operate much more properly to the user.

New Post: Custom sample provider FFT sample capture issue

$
0
0
I want the same buffer size across all devices no matter what the soundcard supports.

What buffer size do you recommend?

Where do I change it?

32ms refresh is not a necessity. It was the refresh rate I used with another audio playback library that did not support WinRT on an ARM processor.

New Post: change left or Right channel volume.

$
0
0
Just use the code I showed above, and add a LeftVolume and RightVolume property instead of the Volume one.

New Post: Custom sample provider FFT sample capture issue

$
0
0
How about if I figure out frames per second, grab the current frame every ~40ms (needs to be a rate that is invisible to the human eye when I render) and run an FFT on that instead of relying on the buffer?

Then my question would be: How do I get the current frame?
Viewing all 5831 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>