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

New Post: How to code circullar buffer to create a delay and used the wavein for micrcophone and output to speaker?

$
0
0

How to code circullar buffer to create a delay and used the wavein for micrcophone input and output to speaker?

 

 public NAudio.Wave.WaveIn input = null;
        public NAudio.Wave.DirectSoundOut waveout = null;
        public NAudio.Wave.WaveInProvider wavein = null;
       
        private void button1_Click(object sender, EventArgs e)
        {

            WaveIn input = new NAudio.Wave.WaveIn();
            input.WaveFormat = new NAudio.Wave.WaveFormat(44100, 2);
            IWaveProvider wavein = new NAudio.Wave.WaveInProvider(input);
       
            waveout = new NAudio.Wave.DirectSoundOut();
            waveout.Play();
         
     
           

        }

 

Any answer Guys? :)   


New Post: How to code circullar buffer to create a delay and used the wavein for micrcophone and output to speaker?

$
0
0

put the audio received into a BufferedWaveProvider and play from that.

New Post: Newbie: Kinect service ==>Byte array to speaker

$
0
0

to play audio recieved over the network with NAudio, you create a BufferedWaveProvider, and add bytes to that as they become available. Then just pass the buffered wave provider into an instance of WaveOutEvent (please avoid using WaveOut with function callbacks)

New Post: WaveFloatTo16Provider class: Only PCM supported

$
0
0

yes, you're right that's a bug. thanks for pointing it out.

Source code checked in, #d26bc035efa6

$
0
0
fixed some incorrect exception messages (thanks to alylero)

New Post: What gets installed via Nuget

$
0
0

I have been using Naudio for a while now, so I decided to get on board with Nuget. I got the latest version of Nuget, removed my manual references to Naudio in my solution, then I used the Package Manager Console to install Naudio. Unfortunately, my solution now doesn't build because the Nuget package doesn't appear to include the Windows Media Format stuff. Did I miss a step?

Also, it appears that Nuget just gives you the binaries, so if you want to debug into the Naudio stuff (to find a bug - for example), you have to link to an Naudio solution. Is that the right/best way to do it?

 

Thanks,

eejake52

New Post: NullReferenceException in WaveOutEvent

$
0
0

I'm having trouble with WaveOutEvent. I'm not sure if it is a bug or just my code, so for now I'm just raising a Discussion, not an Issue.

I'm using WaveOutEvent in an ASP.Net web application. It's a simple application that plays a list of songs. When one song ends, WaveOutEvent throws a PlayBackStopped event. I catch that, dispose the WaveOutEvent object; then create a new WaveOutEvent object, filereader, etc. It usually works, but about 1 time in 5, I get a NullReferenceException in WaveOutEvent.cs. See the offending statement (in yellow hightlight) on the attached screen shot. NB - I can make it happen at will, just by putting a breakpoint in RaisePlaybackStoppedEvent(). So, just by hitting the breakpoint and continuing, I get the error; or about 1 time in 5, without the breakpoint, I get the error. I can't figure out which variable is triggering the null reference, and I will concede that I don't understand the lambda operator, but my hypothesis is that 'this' is from another thread, which sometimes goes null depending on which thread runs first.

Also, this all arose because I am trying to Dispose of the object and create a new one, for each song. When I keep the same object, the problem does not occur (but as Mark pointed out, it will leak memory).

If anyone can help me sort this out, I'd be grateful.

Jake

Class usage:

    Public Sub PlayFile(ByRef fileName As String)       ' play one file
        Dim fileExt As String
        waveOutDevice = New WaveOutEvent()
        fileExt = fileName.Substring(fileName.LastIndexOf("."c))
        Select Case fileExt.ToLower                     ' pick the appropriate file reader
            Case ".aif", ".aiff"
                fReader = New AiffFileReader(fileName)
            Case ".mp3"
                fReader = New Mp3FileReader(fileName)
            Case ".wma"
                fReader = New WMAFileReader(fileName)
            Case Else
                Debug.WriteLine("WebAudio: Invalid File Extension: " + fileExt)
                Return
        End Select
        mainOutputStream = New WaveChannel32(fReader)       ' tie the file reader to the output stream
        mainOutputStream.PadWithZeroes = False              ' need this to detect eof
        waveOutDevice.Init(mainOutputStream)                ' tie output stream to output device
        waveOutDevice.Play()
    End Sub

Exception Detail:

System.NullReferenceException was unhandled
  Message=Object reference not set to an instance of an object.
  Source=System.Web
  StackTrace:
       at System.Web.HttpApplication.ThreadContext.Enter(Boolean setImpersonationContext)
       at System.Web.HttpApplication.OnThreadEnterPrivate(Boolean setImpersonationContext)
       at System.Web.AspNetSynchronizationContext.CallCallbackPossiblyUnderLock(SendOrPostCallback callback, Object state)
       at System.Web.AspNetSynchronizationContext.CallCallback(SendOrPostCallback callback, Object state)
       at System.Web.AspNetSynchronizationContext.Post(SendOrPostCallback callback, Object state)
       at NAudio.Wave.WaveOutEvent.RaisePlaybackStoppedEvent() in C:\Users\Gavin\Documents\Visual Studio Projects\NAudio\NAudio\Wave\WaveOutputs\WaveOutEvent.cs:line 280
       at NAudio.Wave.WaveOutEvent.PlaybackThread() in C:\Users\Gavin\Documents\Visual Studio Projects\NAudio\NAudio\Wave\WaveOutputs\WaveOutEvent.cs:line 130
       at NAudio.Wave.WaveOutEvent.b__0(Object state) in C:\Users\Gavin\Documents\Visual Studio Projects\NAudio\NAudio\Wave\WaveOutputs\WaveOutEvent.cs:line 94
       at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(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.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
       at System.Threading.ThreadPoolWorkQueue.Dispatch()
       at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
  InnerException: 


Screen shot:

Ooops - can't do attachments in Discussion.

Offending statement is line #280 in WaveOutEvent.cs

Breakpoint at line #271 in WaveOutEvent.cs

 

New Post: Dsp Truespeech Play Stream

$
0
0

How to play a dsp group truespeech data from a stream of 32 bytes. 


New Post: Read and Write Same Wave File

$
0
0

Hi All

Just starting out with NAudio and wondering if some people can point me in the right direction for being able to record audio from a sound card line input - to wave file, while simultaneously being able to play back that same file (maybe minutes later) through the sound card speaker out. 

I've seen many examples of writing to memory and immediately playing back the sound through the speakers, however, I want to write to disk, and then play back the wave file (while it is still recording)... 

Basically a time delay program...

Any pointers would be greatly appreciated...

Ash

New Post: Can I use the NAudio in a web page?

$
0
0

I'm trying to make a connection (IPEndPoint) where I capture the UDP stream to play on a player (Media Player)?

How can I do that?

Thank you in advance!

New Post: Can I use the NAudio in a web page?

$
0
0

If you mean running NAudio on the client side in the browser, then no, I'm afraid that is not possible

New Post: Read and Write Same Wave File

$
0
0

I have written code that can do this, but it is not easy. A valid WAV file includes the length of the data chunk early on, but since the length is unknown, you'll need custom reader code. I also found that appending to a file on one thread while reading from it on another is fraught with difficulty. I ended up creating a long blank WAV file, and have one thread overwriting the samples in it while another played back from it. You might find it easier not to use a WAV file at all, and just have a raw PCM audio data file.

New Post: Dsp Truespeech Play Stream

$
0
0

use the RawSourceWaveStream, passing in your stream and creating a TrueSpeechWaveFormat object

New Post: What gets installed via Nuget

$
0
0

Yes, the NuGet package doesn't include Windows Media. For next NAudio I'll either add another NuGet package, or move the Windows Media code into the main DLL.

And yes to debug NAudio it is best to simply connect to the source code.

Mark

New Post: AcmStreamHeader dispose was not called

$
0
0

did you remember to dispose your WaveStream when you finished playing?


New Post: NullReferenceException in WaveOutEvent

$
0
0

can you copy the offending line, as I think the line numbers may not match my copy WaveOutEvent. What version of NAudio are you using?

New Post: API for Position Reporting

$
0
0

Hi, sorry for slow response. It would be good to have a standardised approach to reporting position, but I would want it to be implemented on most if not all of the IWavePlayers if the method is to be introduced to IWavePlayer. Also, since IWavePlayer only takes an IWaveProvider, position really is just a function of how many samples have been played and cannot necessarily be related to the position within an input file. What was your proposed method signature for this feature?

New Post: NullReferenceException in WaveOutEvent

$
0
0
markheath wrote:

can you copy the offending line, as I think the line numbers may not match my copy WaveOutEvent. What version of NAudio are you using?

I have NAudio 1.5 from 12/18/2011.

As mentioned in another thread, I am still trying to work out how to get the latest sources; in one swoop. What is the recommended procedure?

Thanks,

Jake

Here is the code, from WaveOutEvent.cs, with the line #'s added. Line 271 is where I put a breakpoint, and 280 is the statement that crashes.

 

        private void RaisePlaybackStoppedEvent()
        {
271         EventHandler handler = PlaybackStopped;
            if (handler != null)
            {
                if (this.syncContext == null)
                {
                    handler(this, EventArgs.Empty);
                }
                else
                {
280                 this.syncContext.Post(state => handler(this, EventArgs.Empty), null);
                }
            }
        }

 

New Post: NullReferenceException in WaveOutEvent

$
0
0

Hmmm, I was expecting SyncContext to be null in your case. Not really much of a web developer, so it might be a question for StackOverflow. To download the latest source code, click "Source Code" above, and then "Download".

New Post: NullReferenceException in WaveOutEvent

$
0
0

That appears to work, viz:

        private void RaisePlaybackStoppedEvent(Exception e)
        {
            var handler = PlaybackStopped;
            if (handler != null)
            {
//                if (this.syncContext == null)
//                {
                    handler(this, new StoppedEventArgs(e));
//                }
//                else
//                {
//                    this.syncContext.Post(state => handler(this, new StoppedEventArgs(e)), null);
//                }
            }
        }

I've tried it over 30 passes with no errors. I'll leave it run all afternoon, but it looks good!

Viewing all 5831 articles
Browse latest View live


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