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

New Post: Saving unsigned PCM 8 bit to Wav is Noisy

$
0
0
I'm afraid I do not know what the issue is here. Are you sure it's linear PCM. Also, bytes in a file are neither signed nor unsigned. They are just 8 bits of data, and whether you treat them as signed or unsigned is the decision of the reader of the file.

New Post: Using the WdlResamplingSampleProvider correctly

$
0
0

Thanks Mark,

You are saying that my reader.ToSampleProvider() won’t work because it will provide the WDLR only 8-bit byte samples and not floats?

Should I take the 8-bit byte array, cast it to float, then somehow turn that back into an ISampleSource? Not sure how to do that exactly.

New Post: Using the WdlResamplingSampleProvider correctly

$
0
0
sorry, my reply was confusing. ToSampleProvider should turn your incoming audio into 32 bit floating point samples, which should be fine. I still recommend resampling in much smaller blocks.

New Post: How can i save the captured sound into an array

$
0
0
Hi there,
I am new to C# and naudio. Currently i want to build a signal processing program. The capture frequency is 8K Hz.
Is there any way to capture the sound and store it in an array?
Any one can show me a sample of capturing the first 8000 samples and store it in an int array?

New Post: Midi piano roll control

$
0
0
Thanks mark .. :) it's working now

New Post: Using the WdlResamplingSampleProvider correctly

$
0
0

Gosh, Mark,

I tried breaking it up into more discrete steps to see where things go wrong. In the code below, neither wavFloatArray ends up with any resampled data. Both output arrays end up 2000 entries long filled with all zeros. If I execute reader.Read(..) I get the source file contents at 22050, 8-bit filled with data. But it’s not resampled, and not 32bit.

If I set a break and look at the contents of the ISampleProvider isp, it says waveFormat.bitspersample= 32bit (like you said, resampled from 8 bits to 32) 22kHz(original sample rate), but the sourceBuffer[] is all zeros except the first entry. And the buffer array size looks peculiar. The 22/8 array is 13235bytes, while the blank isp buffer is 5516. I might have expected 13k/4, but not that.

So basically, still can’t get from that to any other sample rate.

ISampleProvider isp = newPcm8BitToSampleProvider(reader);

var resampler1 = newWdlResamplingSampleProvider(isp, 8000);

wavFloatArray =newfloat[2000];

var result = resampler1.Read(wavFloatArray, 0, 2000);

var resampler2 = newWdlResamplingSampleProvider(reader.ToSampleProvider(), 8000);

float[] wavFloatArray2 = newfloat[2000];

var result2 = resampler2.Read(wavFloatArray2, 0, 2000);

New Post: Generate waveform from WAV

$
0
0
I have a WAV file for which I would like to generate a waveform graph which NAudio generates in the demo application i.e. AudioPlaybackDemo. The sample generates the graph at run time while the audio is been played.

What I would like is to get the exact same graph generated without playing it.

I tried the code here but it seems to be not accurate.

Any help is greatly appreciated.
Thanks

New Post: How to create waveform of full audio

$
0
0
@Shujee, could you provide a small piece of code which you used to generate the waveform?

Thanks

New Post: How to create waveform of full audio

$
0
0
Has been quite some time since I worked on that project. I just spent some time and tried to gather the pieces. It is part of a large project, so I can't provide a working solution off hand, but the following will hopefully take you a long way.
  private WaveOut playbackDevice = new WaveOut() { DesiredLatency = 100, NumberOfBuffers=2};

  public void Load(string fileName)
  {
        var fileStream = new WaveFileReader(fileName);

        var fileProvider = new WaveFileReader(fileStream);
        playbackDevice.Init(fileProvider);

        var SampleProvider = fileStream.ToSampleProvider();
        var Values = GetWaveForm(SampleProvider, fileStream.WaveFormat, fileStream.Length, fileStream.WaveFormat.SampleRate / 10);

        //Now you can do whatever you want (e.g. plot them) with the Values.
  }

  private List<MinMax> GetWaveForm(ISampleProvider provider, WaveFormat format, long length, int notificationCount)
    {
      int bufferSize = format.ConvertLatencyToByteSize((((WaveOut)playbackDevice).DesiredLatency + ((WaveOut)playbackDevice).NumberOfBuffers - 1) / ((WaveOut)playbackDevice).NumberOfBuffers);
      var buf = new float[bufferSize];
      int samplesRead = 0;
      int count = 0;

      List<MinMax> Values = new List<MinMax>((int)(length / notificationCount));

      float maxValue = 0, minValue = 0;
      while ((samplesRead = provider.Read(buf, 0, buf.Length)) > 0)
      {
        for (int n = 0; n < samplesRead; n += format.Channels)
        {
          maxValue = Math.Max(maxValue, buf[n]);
          minValue = Math.Min(minValue, buf[n]);
          count++;
          if (count >= notificationCount && notificationCount > 0)
          {
            Values.Add(new MinMax(minValue, maxValue));
            minValue = maxValue = count = 0;
          }
        }
      }

      return Values;
    }
You'll need to import NAudio.Wave and System.Collections.Generic namespaces into the module. Also this may have some compilation errors since I haven't tested, but fixing them should be trivial.

New Post: How to create waveform of full audio

$
0
0
Thanks for the quick response @Shujee. I was able to get rid of the compilation errors

I was wondering if you could guide me as to how would I plot the obtained values. Meaning the Min, Max value pairs that your function returns, how would I plot it on a graph? Should i take their averages or something like that?

I really don't have any theoretical knowledge as to how the audio is managed.

New Post: How to create waveform of full audio

$
0
0
The values returned by the function are Y-axis averages of left and right channels. The X-axis values would be the playback time itself. You could even use the loop counter as the X-axis value when you plot the graph.

Plotting itself is merely the process of placing a dot at each X,Y pair and then interconnecting all the points; much the same way as we do in manual (hand-drawn) charting. How you do this in code depends upon the platform/language you're using. In WinForms, you would use Graphics class methods such as DrawLine to plot it. In my case I was using WPF, so I used a PolyLine control and set its Points collection in a loop. The key here is that plotting these values has nothing whatsoever to do with NAudio. You need to know how to do basic drawing in the language/platform you're using.

Hope that gets you going.

New Post: Get ID of endpoint in MMDeviceEnumerator list

$
0
0
I may be missing something obvious, but how do I get the sound device "ID" from a list of devices. This code gets me a nice list of full (not truncated) sound device names:
Dim enumerator As New MMDeviceEnumerator()
For Each endpoint As MMDevice In enumerator.EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active)
       GsSoundList.Add(endpoint.FriendlyName.ToString)
Next
The problem is, the devices are not in order, so - for example - the first device in the list is not necessarily the device with an ID of 0. The following code (which truncates the device names) does seem to retrieve a list in the correct order:
Dim devicecount As Integer = NAudio.Wave.WaveOut.DeviceCount()

If devicecount > 0 Then
      For i As Integer = 0 To devicecount - 1
           GsSoundList.Add(NAudio.Wave.WaveOut.GetCapabilities(i).ProductName)
       Next i
End If
I guess I could get the truncated names and then look up the longer name, but that seems a bit of a kludge. Am I missing something?

Thanks,

Paul.

New Post: Get ID of endpoint in MMDeviceEnumerator list

$
0
0
I'm afraid these are two fundamentally different audio APIs. The MMDeviceEnumerator is the WASAPI view of things, the WaveOut devices list is the old winMM view of your devices. I've seen lots of ways of trying to match the two up over the years, including looking in the registry, but have never found something reliable. Can you use WasapiOut for your application?

Mark

New Post: Get ID of endpoint in MMDeviceEnumerator list

$
0
0
Many thanks for your prompt reply Mark. At least it seems I wasn't missing anything obvious! I will look into WasapiOut; for now it seems that getting both lists and matching up the device names works well enough, until I find two devices with the same first 32 characters in their names ;-)

Thanks again,

Paul.

New Post: ExecutionEngineException: SIGILL when attempting to parse m4a file

$
0
0
I am trying to use NAudio in Unity to read in different audio file formats and convert them to wav. I had no trouble reading in an mp3 file using Mp3FileReader or aif using AiffFileReader, but if I try to read in an m4a file using MediaFoundationReader or AudioFileReader, I get this SIGILL error. I'm not sure if this is Unity causing the error or if I'm just not using the correct reader to read in the m4a file.

The stack trace I get is:
System.Runtime.InteropServices.Marshal.QueryInterface (IntPtr pUnk, System.Guid& iid, System.IntPtr& ppv) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Runtime.InteropServices/Marshal.cs:716)
Mono.Interop.ComInteropProxy.GetProxy (IntPtr pItf, System.Type t) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/Mono.Interop/ComInteropProxy.cs:89)
(wrapper cominterop-invoke) NAudio.MediaFoundation.IMFSourceReader:SetStreamSelection (int,bool)
NAudio.Wave.MediaFoundationReader.CreateReader (NAudio.Wave.MediaFoundationReaderSettings settings)
NAudio.Wave.MediaFoundationReader..ctor (System.String file, NAudio.Wave.MediaFoundationReaderSettings settings)
NAudio.Wave.MediaFoundationReader..ctor (System.String file)
(wrapper remoting-invoke-with-check) NAudio.Wave.MediaFoundationReader:.ctor (string)
NAudio.Wave.AudioFileReader.CreateReaderStream (System.String fileName)
NAudio.Wave.AudioFileReader..ctor (System.String fileName)
(wrapper remoting-invoke-with-check) NAudio.Wave.AudioFileReader:.ctor (string)

New Post: How transfer system mic audio stream to attached external sound card mic audio stream

$
0
0
I am trying to attach USB device used for tele calling which have pnp sound controller for mic and speaker. Now i have two speaker and two mic for input output as shown in image below.
speakermic Now my motive is to transfer audio stream from system mic to external sound card mic and from external sound card speaker to system speaker.

What can be the possible solution that can be attained using c#.

I don't have knowledge about this, so don't know how to start.

New Post: MmException when trying to vonvert a vorbis stream to a pcmStream

$
0
0
I am trying to convert vorbis to wav and I am getting an exception, with the additional info "NoDriver calling acmFormatSuggest".
var reader = new VorbisWaveReader("song.ogg");
var converter = WaveFormatConversionStream.CreatePcmStream(reader);
var waveOut = new WaveOut();
waveOut.Init(reader);
waveOut.Play();
the CreatePcmStream method throws the exception.

New Post: MmException when trying to vonvert a vorbis stream to a pcmStream

$
0
0
What is the WaveFormat of VorbisWaveReader?

New Post: MmException when trying to vonvert a vorbis stream to a pcmStream

$
0
0
IeeeFloat, stereo, 32 bit, 44.1khz

I'm starting to realize that the problem is CreatePcmStream.

I need to get a pcm wavestream from the vorbiswavereader, and it does not have to run in real time in my app (i can load into memory, process, then return a wavestream if necessary)

what are the best options?

New Post: MmException when trying to convert a vorbis stream to a pcmStream

$
0
0
It should already be playable directly. Have you tried just passing the reader directly into WaveOut.Init?
Viewing all 5831 articles
Browse latest View live


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