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

New Post: Recording to or Converting to Flac

$
0
0

NAudio includes no build in FLAC conversion. It can record from the microphone though. You could call a command-line tool to convert WAV to FLAC afterwards perhaps

Mark


New Post: Split mp3 at the point where just after the mp3 played the specified word

$
0
0

Hello,

I am new to here and fresh to split mp3.

My purpose is to split mp3 at the point where just after the mp3 played the specified word.

For example, there are many time that broadcaster say "This is " in a mp3,  then my program with some audio library would split the whole mp3 to many small mp3 which are started at "This is".

Is NAudio a good library to match my requirement?

Thank you.

New Post: Stop or Dispose methods hang if USB device undocked while playing wav file

$
0
0

We are using NAudio to play sound through a USB device and have a problem where the Stop or Dispose methods for out WaveOut object hangs. It seems the problem only happens if the user undocks the USB device while WaveOut is playing a wav file. We are getting no exceptions being throw for us to catch and handle this event.

We have simplified our threading model, but this has not solved anything and still find that NAudio deadlocks on us, with the callback method holding onto a lock. It seems to hold onto the lock because its call to the winmm.dll waveOutWrite method call hangs, or never returns, or throws an exception because the device is not there anymore.

Any suggestions would be appreciated.

Mark

New Post: Stop or Dispose methods hang if USB device undocked while playing wav file

$
0
0

are you using function callbacks? and are you using the very latest NAudio (build from source)?

I fixed a deadlock with function callbacks a while back, and there is also WaveOutEvent which is the preferred option going forwards instead of function callbacks

 

Mark

New Post: Stop or Dispose methods hang if USB device undocked while playing wav file

$
0
0

Mark,

 

We have a version on the DLL of 1.5.3.0 and the following code causes the problem we have...

 

 

ManualResetEvent stopped = new ManualResetEvent(false);

 

private void playsound(string fileName)

{ 

 

  using (WaveOut waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback()))

  {

 

 

 

 

 

 

 

  waveOut.PlaybackStopped += new EventHandler(waveOut_PlaybackHasStopped);

  waveOut.DeviceNumber = 0;

  waveOut.DesiredLatency = 200;

  waveOut.Init(inputStream);

  waveOut.Play(); 

 

  for (; ; )

 

 

      break;

    if (maxPlaySeconds > 0 && DateTime.Now.CompareTo(quitTime) >= 0)

     }

   }

 

  }

// DeadLock at this point. 

} 

 

 

private void waveOut_PlaybackHasStopped(object sender, EventArgs e)

{

  stop.Set();

}

 

 -mjl

    {

       break;

  { 

 

 

    if(stop.WaitOne(100))

New Post: Stop or Dispose methods hang if USB device undocked while playing wav file

$
0
0

I got my solution to work. Changed from the WaveOut class to the WaveOutEvent class, in the WaveOutEvent class the call to the WinMM.Dll waveOutWrite method would throw and exception instead of deadlocking. I ammended the code for WaveOutEvent to catch the MMException being thrown, this catch is in the PlaybackThread method and the handler has the following

catch(MmException ex)

{

buffer = null;

playbackState = PlaybackState.Stopped;

System.Diagnostics.Debug.WrtieLine(ex); // so a debugger can view this is happend and to be able to log using trace listeners.

}

 

If I did not catch the exception there I would get an unhandled error which is not caught by the application general exception error and my appliation would crash and be unloaded from memory.

 

Mark

New Post: start new thread for playback/recording ?

$
0
0

Hi,

when using NAudio in a WPF Apllication, for which host apis does it make sense to start each new playback in a new thread  (Create the IWavePlayer, call Init(), and Play() ) ?

I could see WASAPI already starts in a new thread, but whats with WaveOut, DirectSound and ASIO ? And for recording with WaveIn ?

thanks

henrik

New Post: start new thread for playback/recording ?

$
0
0

For DirectSound we create a thread. ASIO callbacks come from a thread controlled by the soundcard driver. WaveOut has several callback models. Window uses the GUI thread to handle callbacks, WaveOutEvent creates its own thread, and Function callbacks come on threads created by the driver.

Mark


New Post: VolumeMeter

$
0
0

Im having Problem Adding Volume Meter  on WaveOut

 i wish to detect  sending sound  end  receving sound  similar  to Control  Volume   i did try any  way buth no sucses   on volume   setings i did  this  wich it  work  fine

 

     var waveOut = new WaveOut();
                            waveOut.Volume = volumeSlider1.Volume;
                            fWaveOutsByClient.Add(Transuser, fastEnumerator);
                            waveProvider = new BufferedWaveProvider(codec.RecordFormat);
                         
                            waveOut.Init(waveProvider);

                            waveOut.Play();
                            UnlimitedThreadPool.Run
                            (
                                () =>
                                {
                                    try
                                    {
                                        while (true)
                                        {
                                            byte[] encoded = fastEnumerator.GetNext();

                                            if (encoded == null)
                                                return;
                                             waveOut.Volume = volumeSlider1.Volume;
                                            byte[] decoded = codec.Decode(encoded, 0, encoded.Length);
                                         
                                            waveProvider.AddSamples(decoded, 0, decoded.Length);
                                        }
                                    }
                                    catch
                                    {
                                    }
                                }
                            );

                        }

{

}

}

);

}

New Post: Panning control classes

$
0
0

I've started working on an audio project that plays multiple clips simultaneously.  I've modeled my code very much based on the "Audio File Playback" portion of the Demo App which is working quite well.

WaveStream -> SampleChannel -> MeteringSampleProvider -> SampleToWaveProvider -> IWavePlayer

My question is this: where in the 'chain' would I access panning control?  Would I need to insert a new object somewhere in the chain?  I only seem to find panning methods in the WaveChannel32 class but am not sure how to incorporate it.

Any advice or sample code using the panning features would be greatly appreciated...

 

 

Thanks,

Ryan

New Post: Panning control classes

$
0
0

SampleChannel shows how you can connect together a whole load of simpler ISampleProvider implementors and make them available in a simple class. I may add in a PanningSampleProvider at some point, maybe in the place of the MonoToStereoSampleProvider that is already in there. Depending on your output format from WaveStream you might be already able to insert the PanningSampleProvider in there.

Mark

New Post: ASIO drivers

$
0
0

Hi,

I've been trying, without much success, to get ASIO working, using a Blackmagic Intensity video capture care which offers ASIO drivers. I'm using only four source files from NAudio: ASIODriver, ASIODriverExt, ASIOSampleConvertor (sic), and ASIOStructures. I commented out the SampleConvertor method as it isn't referred to elsewhere in those four files, and caused a huge dependency tree around WaveFormat.

I have it working to the point where I can GetASIODriverByName() and interrogate the device for channel numbers and names, selected and available sample rates, etc. There are a few glitches, including the fact that it claims to have zero inputs and eight outputs, but it seems to be working to some degree.

I can call init() with IntPtr.Zero as SysRef (basically the HWND argument). I'm writing a console app and don't have a HWND to give it, but all accounts state that zero should be fine here and the driver does not complain.

I can't get it to accept a createBuffers() call. Here's what I'm doing, where drv is the ASIODriver instance:

 

                drv.init(IntPtr.Zero);

                ASIOBufferInfo buf = new ASIOBufferInfo();
                buf.isInput = true;
                buf.channelNum = 0;
                buf.pBuffer0 = Marshal.AllocHGlobal(960 * 16);
                buf.pBuffer1 = Marshal.AllocHGlobal(960 * 16);

                ASIOCallbacks cbs = new ASIOCallbacks();
                cbs.pbufferSwitch = new ASIOCallbacks.ASIOBufferSwitchCallBack(BufferSwitched);
                

                IntPtr bufptr = Marshal.AllocHGlobal(Marshal.SizeOf(buf));
                Marshal.StructureToPtr(buf, bufptr, false);

                drv.createBuffers(bufptr, 1, 960 * 16, cbs);

Buffer sizes are hardcoded for convenience while experimenting, would of course be dynamically calculated ordinarily.

Running that causes this:

Error code [ASE_InvalidParameter] while calling ASIO method <createBuffers>, DeckLink ASIO Driver open Failure!

The C# wrapper seems to expose an awful lot of COM interop to the user - I'd be happy to help in any way I can with improving things, but can anyone suggest what might be going on here?

I appreciate it may also be a fault in the Blackmagic driver, but I can't really tell from here.

Best,

HF

New Post: Recording into WaveStream and wave form

$
0
0

Hi, I'm new to NAudio. Unfortunately I didn't find any documentation, just couple oof articles and you tube videos showing how to do things.

What I want to do is record voice and show its waveform. I want to view volume meter as well and be able to change the volume of microphone. In the end I want to write the recorded stream to database. So far I was able to show the waveform and volume meter, but I would like to do this in a different way.

To show volume meter I draw on panel(I don't know how to use NAudio.Gui.VolumeMeter). To show waveForm I use NAudio.Gui.WaveFormPainter, but I would like to use NAudio.Gui.WaveViewer. But this control requires wave stream and I don't have any idea how to record to wave stream.

So far my code looks like that:

//this is one class

private WaveIn input = null;
private WaveFileWriter waveWriter = null;

public void StartRecord(int DeviceIndex, int sampleRate, int bits, int channels, string FileName)
{
   CloseAll(); ///disposes input and waveWriter

   input = new WaveIn();
   input.DeviceNumber = DeviceIndex;
   input.WaveFormat = new WaveFormat(sampleRate, bits, channels);
   input.DataAvailable += new EventHandler<WaveInEventArgs>(input_DataAvailable);
   waveWriter = new WaveFileWriter(FileName, input.WaveFormat);

   input.StartRecording();
   
}

private void input_DataAvailable(object sender, WaveInEventArgs e)
{
    if (waveWriter == null) return;
            
    if (OnVolumePeak != null) //onVolumePeak is my event
    {
        float max = 0;

        for (int index = 0; index < e.BytesRecorded; index += 2)
        {
            short sample = (short)((e.Buffer[index+1]<<8) | (e.Buffer[index]) );
            float sample16 = sample / 16384f;

            max = Math.Max(sample16, max);
        }

        OnVolumePeak(this, max);

    }
    waveWriter.WriteData(e.Buffer, 0, e.BytesRecorded);
    waveWriter.Flush();
}

//and part of code from another class:
public void OnVolumePeak(object Sender, float max)
{
    waveformPainter.AddMax(max); //paint waveForm 
    int vu = (int)Math.Round(max*100);
    if(vu > 100) vu = 100;
    PaintPB(vu);
}

//this one paints my volume meter
private void PaintPB(int value)
{
    Graphics gr = vmPanel.CreateGraphics();
    gr.Clear(this.BackColor);
            
    gr.FillRectangle(Brushes.Green, 0, 100 - value, vmPanel.Width, vmPanel.Height);
}

 

I would like to use WaveViewer instead of WaveFormPainter, but I don't know how. I would also like to add volume control, but I don't know how. I have seen .Net Voice Recorder, but I didn't find source code anywhere. Just some parts here: http://channel9.msdn.com/coding4fun/articles/NET-Voice-Recorder which is not enough for me. Can someone help me? Because I try to do this for about a week.

New Post: Recording into WaveStream and wave form

$
0
0

Hi, the source code for Voice Recorder is available here:

voicerecorder.codeplex.com

New Post: Recording into WaveStream and wave form

$
0
0

No, I can't find source there.

This is list of all files in the download:

GalaSoft.MvvmLight.dll
GalaSoft.MvvmLight.Extras.dll
GalaSoft.MvvmLight.Extras.xml
GalaSoft.MvvmLight.xml
NAudio.dll
System.Windows.Interactivity.dll
System.Windows.Interactivity.xml
VoiceRecorder.application
VoiceRecorder.Audio.dll
VoiceRecorder.Audio.pdb
VoiceRecorder.Core.dll
VoiceRecorder.Core.pdb
VoiceRecorder.exe
VoiceRecorder.exe.config
VoiceRecorder.exe.manifest
VoiceRecorder.pdb
VoiceRecorder.vshost.application
VoiceRecorder.vshost.exe
VoiceRecorder.vshost.exe.config
VoiceRecorder.vshost.exe.manifest

plus some directories with I think language resources: System.Windows.Interactivity.resources.dll


New Post: Recording into WaveStream and wave form

$
0
0

click the tab that says Source Code

New Post: Recording into WaveStream and wave form

$
0
0

Ofcourse. I was there earlier but somehow I didn't see download ;) THX.

New Post: Using NAudio.GUI.WaveViewer

$
0
0

Hi, can someone tell me how to use WaveViewer? I don't think I'm using it properly.

I want to record voice and show its waveform while recording. Now I am using waveFormPainter, but this control "erases" waveform while scrolling.
So I want to use waveViewer which I think shows all the wave and scrollbar if needed(?).

So far I'm doing something like VoiceRecorder. While recording, I'm showing the waveform using WaveFormPainter. When recording is finished I want to show all the wave in WaveViewer. Unfortunately VoiceRecorder is WPF application(and my is windows form) and it doesn't use WaveViewer.

So now I'm adding every read buffer to memory stream:

private void input_DataAvailable(object sender, WaveInEventArgs e)
{   
    //some code here

    memStream.Write(e.Buffer, 0, e.BytesRecorded);
}

 

and then after the recording is stopped I do something like that:

rawSource = new RawSourceWaveStream(memStream, input.WaveFormat);
waveViewer.WaveStream = rawSource;

 

The wave is showed, but... I noticed some things. This waveform was completely different than this one in waveFormPainter. I noticed that this is connected with SamplesPerPixel property of WaveViewer. So I tried some values and it occured that 2048 gives me rather the same waveform(why?). BUT. When this wave form is longer than control width it is being scaled I thing, so it looks completely different again ;)
I expected WaveViever to give me the same waveform as waveFormPainter and scrollbar if needed. So am I doing something wrong, or just this control works like that?

 

New Post: Recording into WaveStream and wave form

$
0
0

 For  get Volume

// in the   volumeslider property

privite void  volumeSlider1_VolumeChanged(object sender,EventArg e)

if (this.waveOut != null)

{

this.WaveOut.Volume =volumeSlider.Volume;

}

}

 to  recive

var waveOut = new WaveOut();

waveOut.Volume=volumeSlider1;

wave

 

New Post: Start/End Position to play subclip?

$
0
0

Hi folks,

I've been asked to allow playback of a sub section of an audio file.  I need to allow a Start/End Position to be set and probably to toggle looped playback.


I'm new to NAudio and have started looking at the source and demos but if anyone can give me a heads up on how I should get started it would be great.

So far the closest I can find to what I want to do is in a tutorial linked from the Documentation for playing multiple samples at once.

It doesn't do exactly what I want but I'm assuming, based on it, that I need to create my own implementation of WaveStream that overrides Read to return bytes between a set Start/End Position.

 

Any/all feedback would be appreciated.

 

Jon

Viewing all 5831 articles
Browse latest View live


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