New Post: Saving unsigned PCM 8 bit to Wav is Noisy
New Post: Using the WdlResamplingSampleProvider correctly
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
New Post: How can i save the captured sound into an array
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
New Post: Using the WdlResamplingSampleProvider correctly
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
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
Thanks
New Post: How to create waveform of full audio
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
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
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
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
Mark
New Post: Get ID of endpoint in MMDeviceEnumerator list
Thanks again,
Paul.
New Post: ExecutionEngineException: SIGILL when attempting to parse 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
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
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
New Post: MmException when trying to vonvert a vorbis stream to a pcmStream
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?