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

New Post: unhandled exception

$
0
0

Hi Mark

further to my last message about my program using WASAPI, my program seems to crash at random, maybe once or twice a day and the following error appears in the event log:

Application: AVR Audio Switch Fix.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ArgumentException
Stack:
   at System.IO.UnmanagedMemoryStream.Read(Byte[], Int32, Int32)
   at NAudio.Wave.WaveFileReader.Read(Byte[], Int32, Int32)
   at NAudio.Wave.SampleProviders.Mono16SampleChunkConverter.LoadNextChunk(NAudio.Wave.IWaveProvider, Int32)
   at NAudio.Wave.WaveChannel32.Read(Byte[], Int32, Int32)
   at NAudio.Wave.ResamplerDmoStream.Read(Byte[], Int32, Int32)
   at NAudio.Wave.WasapiOut.FillBuffer(NAudio.Wave.IWaveProvider, Int32)
   at NAudio.Wave.WasapiOut.PlayThread()
   at System.Threading.ThreadHelper.ThreadStart_Context(System.Object)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.ThreadHelper.ThreadStart()

 

i'm using a non targeted "catch" command but it's not being caught, and even with a specific catch command for system.argumentexception it still crashes. Can you tell from this why it's crashing?

Thanks

Marc


New Post: change frequency at runtime

$
0
0

just create a property that changes the field frequency. Thats all.

New Post: midi in problem: Object reference not set to an instance of an object.

$
0
0

 

 

 

 

void midiIn_MessageReceived(object sender, MidiInMessageEventArgs e)

{

 

string message = e.MidiEvent.ToString();

}

 

 

System.NullReferenceException was unhandled
  Message=Object reference not set to an instance of an object.
  StackTrace:
       at window6.SliderBarKnob1.<>c__DisplayClass2.<midiIn_MessageReceived>b__0() in C:\Users\Gr.xaml.cs:line 179
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.DispatcherOperation.InvokeImpl()
       at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
       at System.Threading.ExecutionContext.runTryCode(Object userData)
       at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Windows.Threading.DispatcherOperation.Invoke()
       at System.Windows.Threading.Dispatcher.ProcessQueue()
       at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
       at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
       at System.Windows.Application.RunDispatcher(Object ignore)
       at System.Windows.Application.RunInternal(Window window)
       at System.Windows.Application.Run(Window window)
       at System.Windows.Application.Run()
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:

 

 

 

 some times when reciv midi, no idea what message is coming, have this problem.
If you know what cause this, can tellme how can skip this problem with a example?

THK!

 

 

New Post: Copying files and "file is being used by another process" problem.

$
0
0

No, all explorer windows are closed. When I try to delete it from Windows, I get error message saying that this file is being used by vshost32.exe

New Post: NAudio in a non GUI thread

$
0
0

My program uses Naudio.Wave.WaveOut to play out audio on a USB audio device. If the USB audio device is removed during playback to GUI playback panel is no longer updated. Any interaction with the playback panel result in the whole program to freeze. My approach was to move all the Naudio.Wave.WaveOut functionality into its own thread (BackgroundWorker to be presice) so that if playback bombs out it will not influence the GUI thread in a negative manner. However, try as I may (wasting almost 2 days) I just could not get audio to play out using  Naudio.Wave.WaveOut from a non GUI thread. I also tried WaveOutEvent without luck. All I got was one callback with stopped state after issuing play.

 

Is there something fundamental about WaveOut and WaveOutEvent that it will only work in a GUI thread? Also I want to add that WaveOut is way more robust than WaveOutEvent if you really hammer a play/pause button.

New Post: NAudio in a non GUI thread

$
0
0

WaveOutEvent is what you should be using if you don't want audio on the GUI thread. I fairly recently added some code in to handle removing USB audio devices so make sure you are working with the very latest NAudio (I have some preview builds on nuget)

 

 

New Post: NAudio in a non GUI thread

$
0
0

Yes, I did use the very latest code, naudio_60216c3b9380,  and in a  non GUI thread WaveOutEvent was not working for me.

New Post: NAudio in a non GUI thread

$
0
0

what about if you run NAudio demo? does playback work as normal in that with WaveOutEvent selected?


New Post: unhandled exception

$
0
0

what are you actually playing from - a file on the disk or some kind of memory buffer?

New Post: unhandled exception

$
0
0

i'm playing a wav file from my resources, wouldn't mind playing from a buffer instead since the wav is silent anyway but can't work out how to create a wave in memory. Saw some reference to nullwavestream or something in an naudio post on here but it doesn't seem to exist

i think i fixed the crash anyway - hasn't happened in days. Before i was resetting the stream.position to 0 if it got above 65000 because i thought a variable i was using to record the position might overflow, but it never seems to so i'm just letting it go on forever, so it might have been something to do with that.

New Post: ASIO input

$
0
0

Hi Hfuy

 

First of all, thanks very much for the response! I was a bit confused though. I have an unchanged version of NAudio 1.5 and when I compare the code you posted with my ASIODriverExt.cs in araxis merge I see that they are 100 percent identical. Did you perhaps grab the un-hacked file by accident?

 

Thanks for your time!

New Post: NAudio in a non GUI thread

$
0
0

In NAudio Demo (x64), using AudioPlaybackPanel with the Ouptut driver set to 'WaveOut' and the callback Mechanism set to 'Event' playback does work. WaveOutEvent is used but it is defined within the scope of AudioPlaybackPanel. My initial thought was that Playback was happening on the GUI thread. On closer examination I realised that playback is indeed happening in it own thread. Removing the USB audio device during playback did result in a stop event in which e.Message was not null. So all is well with the demo.

 

Removing the USB audio device during playback does not in all cases result in a stop event. My program is capable of recording and playback independently and both can happen at the same time. When the USB audio device is removed the playback stop event never fires (probably because WaveIn bombs first and no further clean-up is scheduled).

 

I guess if either the recording or playback bombs that both are no longer functional. 

New Post: NAudio Recording Performance

$
0
0

Hi,

    Is there any way to record from specific channel using ASIO , please let me know if any sample code is available.

    My requirement is to record from Channel 1L and Channel 1R .

Thanks in advance. 

New Post: When playback ends

$
0
0

Hi ,

  I am using NAudio playbak for playing I am playing some noise file. This is loop play or single play  I hear a really bad buzz at
the loop edge , ho to resolve this any ideas.

 

Thanks in advance

New Post: Using WaveOutEvent to playback in a cycle

$
0
0

When using WaveOutEvent to endlessly playback audio between a start and end marker only works reliably if waveStream.CurrentTime is re-winded to start marker when it reaches the end marker.

Stopping playback on reaching the end marker, re-winding waveStream.CurrentTime and then issuing Play is not robust. Sometimes issuing Play no audio is played even though the PlaybackState is 'Playing'.

Normal play-out (without the use of start and end marker) is also problematic. On reaching the end of playback the stop event is fired which is used to rewind the wavestream to 0. On issuing the next Play (manually clicking on a button) no audio is played even though the PlaybackState is 'Playing'. After another pause/play cycle play-out is working again.

In your demo program no rewinding takes place as issuing a play freshly creates a new waveout which would neatly mask this issue.

Any ideas?


New Post: NAudio in a non GUI thread

$
0
0

I would expect both WaveIn and WaveOut to report errors on the USB device being removed. I can't understand why you wouldn't get a playback stopped event.

New Post: NAudio audio conference

$
0
0

   I have 2 WPF applications and I'm trying to build an audio conference system between them. I followed the NetworkChat example and it works, at leas in one direction but I have 3 big problems. First, an annoying background sound is present and at first I thought it's my old laptop to blame, but then I used an i5 laptop and it's still the same. Second, I can hear the voice clearly, but on the receiving end it echoes indefinitely and third, a high pitching sound goes off at random times and I have to stop the transmission, it's unbearable. Any suggestions? I really need to solve this. I use the NarrowBand Speex  codec, as in the example. Thanks.

This is my code:

//recording:
private void StartAudioStreaming()
        {
            if (!connected)
            {
                IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), int.Parse("7081"));
                int inputDeviceNumber = 1;
                this.codec = new NarrowBandSpeexCodec();
                Connect(endPoint, inputDeviceNumber, codec);               
            }           
        }

        private void Connect(IPEndPoint endPoint, int inputDeviceNumber, INetworkChatCodec codec)
        {
            waveIn = new WaveIn();
            waveIn.BufferMilliseconds = 50;
            waveIn.DeviceNumber = inputDeviceNumber;
            waveIn.WaveFormat = codec.RecordFormat;
            waveIn.DataAvailable += waveIn_DataAvailable;
            waveIn.StartRecording();

            udpSender = new UdpClient();                        
            udpSender.Client.Bind(endPoint);
            udpSender.Connect(endPoint);

            connected = true;
        }

void waveIn_DataAvailable(object sender, WaveInEventArgs e)
        {
            byte[] encoded = codec.Encode(e.Buffer, 0, e.BytesRecorded);
            udpSender.Send(encoded, encoded.Length);
        }     

 
   // Playback:
   public void StartAudioStreaming()
        {
            if (!connected)
            {
                IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse("client.ip"), int.Parse("7081"));
                int inputDeviceNumber = 1;
                this.codec = new NarrowBandSpeexCodec();
                Connect(endPoint, inputDeviceNumber, codec);                
            }         
        }

        private void Connect(IPEndPoint endPoint, int inputDeviceNumber, INetworkChatCodec codec)
        {          
            udpListener = new UdpClient();                   
            udpListener.Client.Bind(endPoint);            

            waveOut = new WaveOut();
            waveProvider = new BufferedWaveProvider(codec.RecordFormat);
            waveOut.Init(waveProvider);
            waveOut.Play();

            connected = true;
            ListenerThreadState state = new ListenerThreadState() { Codec = codec, EndPoint = endPoint };
            ThreadPool.QueueUserWorkItem(this.ListenerThread, state);
        }


    private void ListenerThread(object state)
        {
            ListenerThreadState listenerThreadState = (ListenerThreadState)state;
            IPEndPoint endPoint = listenerThreadState.EndPoint;
            try
            {
                while (connected)
                {
                    byte[] b = this.udpListener.Receive(ref endPoint);
                    byte[] decoded = listenerThreadState.Codec.Decode(b, 0, b.Length);
                    waveProvider.AddSamples(decoded, 0, decoded.Length);
                }
            }
            catch (SocketException)
            {
                // Thrown when disconnecting
            }
        }      

     The device number 1 is ok (it appears I have 2 microphones and it doesn't work with 0)

 

 

New Post: Using WaveOutEvent to playback in a cycle

$
0
0

I also experience the problem with the next Play command resulting in PlaybackState == Playing but the audio file is not actually playing.  I am using an event timer to track the progress of the audio file.  If CurrentTime.Ticks is not incrementing, try again.  This happens occasionally and stops my player.  For now I just issue a command to try the track again.

                if (_ticks == AudioRoutines.FileWaveStream.CurrentTime.Ticks && AudioRoutines.Waveplayer.PlaybackState==PlaybackState.Playing)
                {
                    if (_ticks == AudioRoutines.FileWaveStream.TotalTime.Ticks) return;
                    PlayOrderListIndex = PlayOrderListIndex - 1;
                    if (PlayOrderListIndex < 0) PlayOrderListIndex = 0;
                    TrackTimer.Stop();
                    PlayNexttrack();
                    return;
                }
                _ticks = AudioRoutines.FileWaveStream.CurrentTime.Ticks;

New Post: Using WaveOutEvent to playback in a cycle

$
0
0

Modifying WaveOutEvent.Play() as follows resolved this issue (for me):

        public void Play()       

{           

if (playbackState == PlaybackState.Stopped)           

{               

playbackState = PlaybackState.Playing;

ThreadPool.QueueUserWorkItem((state) => PlaybackThread(), null);

                callbackEvent.Set(); // kicking the thread here can only be good            <=========Line Added========

}

else if (playbackState == PlaybackState.Paused)

{

                Resume();

                callbackEvent.Set(); // give the thread a kick

}

        }

 

So Mark if you agree make it part of the official code.

Created Issue: WaveFileChunkReader.ReadWaveHeader assumes that the stream supports position/seek [16354]

$
0
0
I am using this class to read a wave stream but the derived stream class that I am using that contains the wave does not support setting the Postion (CanSeek == false).
public void ReadWaveHeader(Stream stream)
{ ...
while (stream.Position <= stopPosition - 8)
{...
stream.Position += chunkLength; //This line throws an expection.
}
...
}
Is it posible to use another metholody to read the wave that is not based on Postion? or is there another alternative?
Viewing all 5831 articles
Browse latest View live


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