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

New Post: Convolution

$
0
0
Ok. I've got convolution to "work". It's really slow through / unusable for samples longer than few seconds because of that. Or maybe its because of AudioFileReader reading the whole file into memory.

I've used 2x AudioFileReader for the sound and the impulse response.

Then I've made two float arrays for those with a fixed size of 88200 (first 2 seconds of the sound) and 44100 (the size of the impulse response).

I wrote the convolution to another float array (convolution result) and then
writer.WriteSamples(convolutionResult, 0, 88200);
out to a file.

The sample is weird through. Sounds amplified its 4 seconds in length instead of 2 (88200). Something wrong with the float array sizes?

Created Unassigned: performance degradation at WaveFileWriter.Write () [16473]

$
0
0
naudio 1.7.3, WaveFileWriter class,
method override void Write(byte[] data, int offset, int count)
if (outStream.Length + count > UInt32.MaxValue)
throw new ArgumentException("WAV file too large", "count");
this causes drammatical performance degradation for byte by byte writing, especially when output stream is located at network location.
Someone who uses Write() shall be conscious of file system limitations, IMHO this is not good place to do this, it should be before use of Write() method

Edited Unassigned: performance degradation at WaveFileWriter.Write () [16473]

$
0
0
naudio 1.7.3, WaveFileWriter class,
method override void Write(byte[] data, int offset, int count)
if (outStream.Length + count > UInt32.MaxValue)
throw new ArgumentException("WAV file too large", "count");
this causes drammatical performance degradation (checking stream length) for byte by byte writing, especially when output stream is located at network location.
Someone who uses Write() shall be conscious of file system limitations, IMHO this is not good place to do this, it should be before use of Write() method

New Post: USB headsets: how to associate WaveIn/WaveOut device numbers with USB DevicePath?

$
0
0
i've got multiple USB headsets (i.e. mic and headphones) on my computer. these headsets also include a push-to-talk (PTT) button. to get device numbers and names, i use these loops:
            for (int n = 0; n < WaveIn.DeviceCount; n++) {
                var capabilities = WaveIn.GetCapabilities(n);
                list_of_input_devices.Add(capabilities.ProductName);
            }

            for (int n = 0; n < WaveOut.DeviceCount; n++) {
                var capabilities = WaveOut.GetCapabilities(n);
                list_of_output_devices.Add(capabilities.ProductName);
            }
i also have another step that gets the DevicePath for the USB PTT part of the headset; i.e.
DevicePath = "\\\\?\\hid#vid_047f&pid_faa1&mi_03#8&23e2c66b&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}"
for my application, i now need a way to create a "headset" object which associates a WaveIn devicenumber, a WaveOut devicenumber, and a PTT device path.

is there any way in naudio to figure out which USB DevicePath corresponds to a WaveIn and WaveOut devicenumber ?

many thanks.

New Post: Record audio using microphone

$
0
0
Hi,

I would like to create an application to record the sound using a microphone.
In my application, when the microphone receive the sound, the label will show the value of amplitude.
I read the discussion here to get some idea to create my application.

However, I don't understand about some point.
Below are the codes that I got from the link:
private bool ProcessData(WaveInEventArgs e)
{
    bool result = false;

    bool Tr = false;
    double Sum2 = 0;
    int Count = e.BytesRecorded / 2;
    for (int index = 0; index < e.BytesRecorded; index += 2)
    {
        double Tmp = (short)((e.Buffer[index + 1] << 8) | e.Buffer[index + 0]);
        Tmp /= 32768.0;
        Sum2 += Tmp * Tmp;
        if (Tmp > AudioThresh)
            Tr = true;
    }
    Sum2 /= Count;  
}
May I know,
  1. Is it true the sample in 16bits?
  2. What is the value of Sum2 refer to? is it the value is refer to the amplitude of the sine wave of the audio?
  3. Why we need to multiply with (Tmp*Tmp)?
I need some advice about this matter.

Thank you.

New Comment on "Documentation"

$
0
0
Hi Mark, I am a software developer in windows Platform , I am making one application "which is having some .mp3,.wav files " and my expectation is to compare the music file with each other. It means that , here i capture one music file from Mic (With Noise) and i need to compare the two music files. For that if u have any solution . I already made one algo for that but that is not working some critical situation. Can u give any solution . Thank u . Debabrata Ghosh. debu_mca07@hotmail.com

New Post: Live pitch change -15 and +30 at the same time?

$
0
0
I need help with my script i want to change my voice in a audio loop back w and i want my computer to recognice it as a new microphone. And i want to change my voice in a way that it plays 2 times the same output but with different pitches at the same time. Any ideas?

New Post: Problem with NAUDIO and REALTEK

$
0
0
that doesn't sound good. have you checked you have the latest realtek drivers? There can be problems with them. Also, what callback mechanism are you using? Can you try with WaveoutEvent instead?

New Post: Live pitch change -15 and +30 at the same time?

$
0
0
well for the pitch shifting part, you would need a pitch shifter algorithm. Unfortunately there isn't one in NAudio, but you can find an example of one in the code for Skype Voice Changer (skypefx.codeplex.com). You'd run your audio through two instances of this in parallel and mix the outputs together.

New Post: Convolution

$
0
0
The ImpulseResponseConvolution is one of the oldest bits in NAudio, and to be honest, it should probably be removed from the library. It doesn't really handle the issues around mono / stereo impulses and inputs. And I have a feeling that most commerical software that does convolution does it all in the frequency domain (FFT first, convolve, then inverse FFT).

New Post: Record audio using microphone

$
0
0
  1. Not necessarily, but if you're using WaveIn, 16 bit is the default
  2. It's the sum of squares -
  3. It's a simply way of getting all positive values (because samples can go negative).

New Post: Reproduction of multiple sound cards

$
0
0
Not easily I'm afraid. The easiest way would be to just play the same thing out of both soundcards separately. However, you will struggle to get perfect syncrhonization

New Post: "AcmNotPossible calling acmFormatSuggest" on certain MP3 files, why?

$
0
0
Maybe it is invalidly detecting an MP3 frame in the album art, which can happen. Have you tried playing it using MediaFoundationReader instead?

New Post: How To Play WaveFormViewer like Waveform Painter(at the time of recording in data available) While Playing an Audio in Naudio

$
0
0
Hi to all,

I want to play WaveFormViewer like Waveform Painter(at the time of Recording) While Playing an Audio in Naudio. Please give me the examples

New Post: Problem with NAUDIO and REALTEK

$
0
0
Hi,

Yes I try with the latest REALTEK drivers. I have the same problem with another computer with REALTEK. It seems that WaveOut dislike the desactivation of the driver.
I'm using WaveOut like this :

_WaveOutDevice = new WaveOut(WaveCallbackInfo.FunctionCallback())

I will try with WaveOutEvent ASAP.

Thank you for your answer

New Post: Problem with NAUDIO and REALTEK

$
0
0
yes, avoid function callbacks. They are often the cause of deadlocks.

New Post: MP3 to WAV stream

$
0
0
Hello guys,

I am using NAudio to mixing two audio files together. I have 2 MP3s which I convert to WAV and then mix them together. However the converting function requires WAV to be saved into harddrive.
Is there any solution which can provide me with WAV stream or someting else, but in memory only?

Current conversion is:
using (Mp3FileReader reader = new Mp3FileReader(mp3File)) {
                WaveFileWriter.CreateWaveFile(outputFile, reader);
            }
I would like to give my program 2 input MP3s and save one final mixed WAV.

New Post: naudio seekbar

$
0
0
Greetings;

I'm trying to do the same here. But thats not working for me.
I can Make the TrackBar to Auto Slide During Track Play but Cannot Seek.
Can anyone help me out understanding what i'm doing wrong?
nAudio Class:

        #region Member Variables
        public WaveOutEvent WOE;
        public AudioFileReader AFR;
        #endregion

 #region [TrackBar]
        /* TrackBar Time and Position*/
        public int trkBar_lenght;
        public int trkBar_Lenght { get { return trkBar_lenght; } set { trkBar_lenght = value; } }

        public int trkBar_curTime;
        public int trkBar_CurTime { get { return trkBar_curTime; } set { trkBar_curTime = value; } }

        public int trkBar_curPos;
        public int trkBar_CurPos { get { return trkBar_curPos; } set { trkBar_curPos = value; } }

        public string curTime;
        public string CurTime { get { return curTime; } set { curTime = value; } }

        public void Set_CurTime()
        {
            if (WOE == null) { curTime = "00:00"; }
            else if (WOE != null) 
            { 
                curTime = AFR.CurrentTime.ToString("mm\\:ss");
                trkBar_curTime = (int)AFR.CurrentTime.TotalSeconds;
            }
        }

        public string trk_lenght;
        public string trk_Lenght { get { return trk_lenght; } set { trk_lenght = value; } }

        public void Set_Lenght()
        {
            if (WOE == null) { trk_lenght = ""; }
            else if (WOE != null) 
            { 
                trk_lenght = AFR.TotalTime.ToString("mm\\:ss");
                trkBar_lenght = (int)AFR.TotalTime.TotalSeconds;
            }
        }

        #endregion

Main Form:

        private void trkBar_Scroll(object sender, EventArgs e)
        {
            NAUDIO.trkBar_CurTime = trkBar.Value;
        }

        private void trkBar_ValueChanged(object sender, EventArgs e)
        {
            trkBar.Minimum = 0;
            trkBar.Maximum = NAUDIO.trkBar_Lenght;
        }

        private void tmr_TrkTime_Tick(object sender, EventArgs e)
        {
            trkBar.Value = NAUDIO.trkBar_CurTime;

            NAUDIO.Set_CurTime();
            txt_CurrTime.Text = NAUDIO.CurTime;
            txt_trkLenght.Text = NAUDIO.trk_Lenght;
        }

New Post: Audio file locked by WaveViewer

$
0
0
Hello,

I have a .wav audio file that I want to show in windows form and simultaneously add to the video, that I create in my C# aplication, but when I try to add audio into videa an exception is thrown saying that the audio file is locked by another proces.

How can I unlock the audio file used by WaveViewer?

New Post: Unable to load wave file from embedded resource...

$
0
0
Hi!

I am trying to embed the wave files into the DLL by embedding them.

Everything works fine and I get the UnmanagedMemoryStream. But then it all goes bad.

I was trying to follow your example for fire and forget game sounds. This is version 137325 of my tries:
        public CachedSound(UnmanagedMemoryStream audioFileStream)
        {
            using (var audioFileReader = new WaveFileReader(audioFileStream))
            {
                WaveFormat = audioFileReader.WaveFormat;

                var wholeFile = new List<float>((int)(audioFileReader.Length / 4));
                var readBuffer = new byte[4];
                int samplesRead;

                while ((samplesRead = audioFileReader.Read(readBuffer, 0, readBuffer.Length)) > 0)
                {
                    wholeFile.Add(BitConverter.ToSingle(readBuffer, 0));
                }

                AudioData = wholeFile.ToArray();
            }
        }
The ISampleProvider uses float arrays, but the WaveFileReader can only read byte[]. So what I need is a function that can read an UnmanagedMemoryStream and put the correct sample data into a float[] for the ISampleProvider to read it and supply it to the mixer.

Again, this above is my latest version, which as you can see is already very desperate as it reads float by float. Thats because I tried to see if the problem is with endianess, but it isnt.

The float array I get out of this has lots of NaNs, and if I go the other endian its the same. So the data is corrupt the way I read it.

I also tried lots of other ways to read the data (including RawWaveStream), and the exact same wave files work perfectly fine if I use this below routine (from the blog) and place the file into the directory:
        public CachedSound(string audioFileName)
        {
            using (var audioFileReader = new AudioFileReader(audioFileName))
            {
                WaveFormat = audioFileReader.WaveFormat;
                var wholeFile = new List<float>((int)(audioFileReader.Length / 4));
                var readBuffer = new float[audioFileReader.WaveFormat.SampleRate * audioFileReader.WaveFormat.Channels];
                int samplesRead;

                while ((samplesRead = audioFileReader.Read(readBuffer, 0, readBuffer.Length)) > 0)
                {
                    wholeFile.AddRange(readBuffer.Take(samplesRead));
                }

                AudioData = wholeFile.ToArray();
            }
        }
So why can I read the file from the harddisk but not embed it into the DLL?

Any ideas welcome... ;)

Thx!
Viewing all 5831 articles
Browse latest View live


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