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

New Post: Try this Reverb ISampleProvider

$
0
0
Well, consider also the delay of processing. Playback will need to wait until first FFT pack has arrived, so there is a delay of:

DelayInSeconds = FFTSize / SampleRate

With my chosen settings:

DelayInSeconds = 4096 / (44100 1/s) = 0,093 s = 93 ms

It can be heard at the start of playback and is of course an unwanted side effect caused by the algorithm. Nevertheless, it´s not a big deal for me personally.

New Post: Try this Reverb ISampleProvider

$
0
0
Hi Mark, just wondering if you gave the Reverb ISampleProvider a try after I made the fixes? Any thoughts?

markheath wrote:
this is awesome. looking forward to giving it a try. thanks for sharing

Created Unassigned: Noise reduction [16498]

$
0
0
when I record audio there is lots of unnecessary sounds recorded .. this will we the nice feature .. to reduce noise

Commented Unassigned: Noise reduction [16498]

$
0
0
when I record audio there is lots of unnecessary sounds recorded .. this will we the nice feature .. to reduce noise
Comments: I'm afraid NAudio doesn't include a noise reduction algorithm at the moment. It's something I'd be glad to include if anyone submitted

New Post: How to improve FFT results accuracy ?

$
0
0
Hey I'm trying to apply harmonic product spectrum to FFT result. But when I try to downsample I'm getting "cannot implicitly convert float to naudio.dsp.complex" because the X value (Real part) is a float. How can I solve this?
      public Complex[] Downsample(Complex[] data, int n)
        {
            Complex[] array = new Complex[Convert.ToInt32(Math.Ceiling(data.Length * 1.0 / n))];
            for (int i = 0; i < array.Length; i++)
            {
                array[i] = data[i * n].X; //Here .. It was originally __data[i * n].Re;__
__            }
            return array;
        }

New Post: Try this Reverb ISampleProvider

$
0
0
not yet, am on my holidays, but its on the list of things to do when I get back to work!

New Post: Try this Reverb ISampleProvider

New Post: Try this Reverb ISampleProvider

$
0
0
I tested my shifter today in C# and the problem also ocurred what you described as clicking. Finally I realized, that I forgot to remove the "static" keywords also inside the local variables. Then it´s working perfectly, like it did in VB (where I didn´t forget that).

The reason for clicking is, that with static buffers left and right samples are mixed together in a random way.

I created a new github repistory (https://github.com/Freefall63/NAudio-Pitchshifter, where I show the shifter working in realtime in C#.

Another test would be welcome.

And Mark could include it in NAudio after holiday if he wants to.

New Post: PCM streaming with WASAPI

$
0
0
Hello

I'm trying to create a proof of concept function for a Windows App that streams PCM data from a buffer. I've looked at some of the examples and the BufferedWaveProvider seems like the correct WaveProvider to use in this scenario. Below is my attached code. My main issue is that the tone isn't repeating itself. For some reason I can't get the tone to play longer than the latency parameter passed into WasapiOutRT. Could anyone point out where the flaw is? If you need other information, please let me know.

Thanks!
        private async void playSineWav()
        {
            int sampleRate = 8000;
            int numSecs = 1;
            byte[] soundBuf = new byte[sampleRate * 2 * numSecs]; //X seconds of sample data (16 bit)
            //create sine wave
            short[] sineWav = new short[sampleRate];
            int freq = 500;
            for (int i = 0; i < sampleRate; i++)
            {
                double x = 32767 * Math.Sin(2 * Math.PI * freq * i / sampleRate);   //make data into a short
                sineWav[i] = (short)x;
            }
            //repeat sine wave and place in buffer
            for (int i = 0; i < numSecs; i++)
            {
                Buffer.BlockCopy(sineWav, 0, soundBuf, sampleRate * 2 * i, sampleRate*2);
            }
            do
            {

                if (medEl == null)
                {
                    medEl = new NAudio.Win8.Wave.WaveOutputs.WasapiOutRT(NAudio.CoreAudioApi.AudioClientShareMode.Shared, 200);
                    NAudio.Wave.WaveFormat fmt = new NAudio.Wave.WaveFormat(sampleRate/2, 16, 1);
                    wp = new NAudio.Wave.BufferedWaveProvider(fmt);
                    wp.BufferDuration = TimeSpan.FromSeconds(10);
                    wp.AddSamples(soundBuf, 0, sampleRate *2* 1);
                    await medEl.Init(wp);
                    medEl.Play();
                }

                if (wp.BufferLength - wp.BufferedBytes >= 16000)
                {
                    wp.AddSamples(soundBuf, 0, sampleRate * 2 * numSecs);
                    System.Diagnostics.Debug.WriteLine("adding");
                }
                else
                {
                    await System.Threading.Tasks.Task.Delay(500);
                    System.Diagnostics.Debug.WriteLine("waiting");
                }

            } while (medEl.PlaybackState != NAudio.Wave.PlaybackState.Stopped);

New Post: Convert mp4 to WAV stream

$
0
0
I have an MP4 audio file to which I have a public URL (audio file contains voice message that was recorded by Facebook Messenger mobile application). I am trying to convert this mp4 file to WAV stream (running on Windows 10 Home) using this code:
using (MediaFoundationReader reader = new MediaFoundationReader(url))
{
    ResamplerDmoStream resampledReader;
    using (resampledReader = new ResamplerDmoStream(reader,
                        new WaveFormat(16000, 16, 1)))
    {
        //save to file just to verify that conversion was done OK
        voiceToFile(resampledReader);
     }
}
The following is the implementation of voiceToFile method
private static void voiceToFile(Stream audio)
{
    byte[] b;

    using (BinaryReader br = new BinaryReader(audio))
    {
        b = br.ReadBytes((int)audio.Length);
     }
     
     File.WriteAllBytes("c:\\fbaudio_" + Guid.NewGuid().ToString() + ".wav", b);
}
The WAV file created cannot be played by any player. Please advise what could be the reason for this.

New Post: Try this Reverb ISampleProvider

$
0
0
Freefall, I'll give this revised code a retest as soon as time permits. Thanks for posting.

New Post: Convert mp4 to WAV stream

$
0
0
I´d try a different Resampler, perhaps your DMO can´t resample that Waveformat.

Or you don´t have MediaFoundation installed.

And you should use the Read method to fill into a buffer instead of reading all at once. I don´t know, if then the Audio is Resampled correctly or at all.

Created Unassigned: COM Exception & UnRegisterEventClient [16499]

$
0
0
I'm receiving a COM error after my app exits if I call UnRegisterEventClient.

Here is a code snippet:
private Dictionary<uint, SessionsEventCallbacks.NAudioEventCallbacks> _sessionNotifications = new Dictionary<uint, SessionsEvents.NAudioEventCallbacks>();
// NAudioEventCallbacks inherits from IAudioSessionEventsHandler
...
private void OnSessionCreated(object sender, IAudioSessionControl newSession)
{
AudioSessionControl audioSession = new AudioSessionControl(newSession);
SessionsEvents.NAudioEventCallbacks notifications = new SessionsEventCallbacks.NAudioEventCallbacks();
notifications.contentCat = 0;
notifications.programType = 0;
notifications.processId = (int)audioSession.GetProcessID;
notifications.processName = Process.GetProcessById((int)audioSession.GetProcessID).ProcessName;
notifications.domain = string.Empty;
notifications.youtubeCategory = string.Empty;
notifications.audioSession = audioSession;
notifications.SessionEndedCallback = AudioStopped;

_sessionNotifications.Add((uint)notifications.processId, notifications);
audioSession.RegisterEventClient(notifications);
}

I call UnRegisterEventClient from AudioStopped.

Any help would be greatly appreciated!

Thanks,
Randall Deetz

Commented Unassigned: COM Exception & UnRegisterEventClient [16499]

$
0
0
I'm receiving a COM error after my app exits if I call UnRegisterEventClient.

Here is a code snippet:
private Dictionary<uint, SessionsEventCallbacks.NAudioEventCallbacks> _sessionNotifications = new Dictionary<uint, SessionsEvents.NAudioEventCallbacks>();
// NAudioEventCallbacks inherits from IAudioSessionEventsHandler
...
private void OnSessionCreated(object sender, IAudioSessionControl newSession)
{
AudioSessionControl audioSession = new AudioSessionControl(newSession);
SessionsEvents.NAudioEventCallbacks notifications = new SessionsEventCallbacks.NAudioEventCallbacks();
notifications.contentCat = 0;
notifications.programType = 0;
notifications.processId = (int)audioSession.GetProcessID;
notifications.processName = Process.GetProcessById((int)audioSession.GetProcessID).ProcessName;
notifications.domain = string.Empty;
notifications.youtubeCategory = string.Empty;
notifications.audioSession = audioSession;
notifications.SessionEndedCallback = AudioStopped;

_sessionNotifications.Add((uint)notifications.processId, notifications);
audioSession.RegisterEventClient(notifications);
}

I call UnRegisterEventClient from AudioStopped.

Any help would be greatly appreciated!

Thanks,
Randall Deetz
Comments: I'm noticing that after calling UnRegisterEventClient, if I change audioSessionEventCallback to null in the debugger, the problem goes away.

New Post: Detect Microphone in use by other application

$
0
0
I need to detect when the microphone is in use by another application. Can the naudio library used to detect this? I was thinking of 'listening' for x seconds, determine the level to indicate if it is in use or not

If I try to record in order to detect will the other application still be recording?

Thank you..Jim

New Post: Try this Reverb ISampleProvider

$
0
0
Thanks. Only thing missing with the shifter is a limiter processing afterwards, I´m not happy with my obligatory linear downscaling. Actually, I use the "FastAttackCompressor1175" Effect for this from the SkypeFx Project by Mark (which isn´t still what I wanted, but better than linear scaling). The best Limiter that is known to me is the FL Studio "Fruity Limiter", which is a genious Multiband Compressor. Too bad that it isn´t open source.

Do you guys know any good open source compressor that could be ported to .NET?

New Post: How to create waveform of full audio

$
0
0
you can use MediaFoundationReader to access the audio from a video file

New Post: Detect Microphone in use by other application

$
0
0
I'm afraid I don't know of a way to tell whether another application is using the microphone. But usually it is possible for more than one application to record at the same time.

New Post: Detect Microphone in use by other application

$
0
0
Thank you. I will pursue that. The problem I am trying to solve is that we have a screen saver that activates every minute and that cannot be changed. Doctors are dictating using Nuance Dragon. I was planing on writing a process that wakes up every 50 seconds, records 5 to 7 seconds, figure out if something is actually there to record (volume level perhaps) and if so send a key stroke to the computer to reset the clock on the screen saver

New Post: How to create waveform of full audio

$
0
0
@markheath, could you share some piece of code as a reference point for me? Thanks
Viewing all 5831 articles
Browse latest View live


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