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

New Post: waveout get notification after elapsed time

$
0
0
Where is the Read call? Keep in mind, that you have to read from the NotifyingSampleProvider and not from the AudioFileReader.

Your approach is a good start, but I wouldn´t recommend you to fire an event on each sample. Better check if the time is greater or equal of the time you want to wait and only then raise the event.

The reason your code fails I believe, could have several reasons:

1) you fire events with an samplerate of 44100 and stereo channel count of 2 = 88200 times per second.
Not very performant I think, the frequent event processing might be an issue.

2) you probably have the false configuration for your WaveOut object. I recommend 150 (ms) latency and 3 buffers, what gave me the closest results for my media player so far. With this configuration the Read method of the sampleprovider requests 4410 samples, which is enough to display an fft with 4096 samples in real time.

-> So it really depends on your application. If you want a small duration for more precision the buffers would automatically have to be smaller, as the read method anyway reads a full package of samples into your buffer. But for low latency beyond 75ms you should use Asio or DirectSound, as the WaveOut crackles then (with my computer).

New Post: waveout get notification after elapsed time

$
0
0
First of all, thanks for your help!
Here is my full Code:
    public class TimeElapsedAudioFileReader : AudioFileReader
    {
        public event Action<TimeSpan> Elapsed;
        public NotifyingSampleProvider Nsp  { get; set; }
        public ETimeSpan SignalTime         { get; set; }

        public TimeElapsedAudioFileReader(string filename) : base(filename)
        {
            Nsp = new NotifyingSampleProvider(this.ToSampleProvider());
            Nsp.Sample += _nsp_Sample;
        }

        private bool _triggered = false;

        private void _nsp_Sample(object sender, SampleEventArgs e)
        {
            if (_triggered)
                return;
            if (this.CurrentTime >= SignalTime.BaseSpan)
            {
                _triggered = true;
                if (Elapsed != null)
                    Elapsed(this.CurrentTime);
            }
        }

        public override int Read(byte[] buffer, int offset, int count)
        {
            return base.Read(buffer, offset, count);
        }

        public void Reset()
        {
            this.Position = 0;
            _triggered = false;
        }
    }
And here how i Init the WaveOutEvent Object:
 private void InitAudioFile()
        {
            try {   
                _source = new TimeElapsedAudioFileReader(_app.Settings.AudioFilePath);
                _source.Elapsed += _audioreader_Elapsed;
                _waveout.DesiredLatency = 150;
                _waveout.NumberOfBuffers = 15;
                _waveout.Init(_source.Nsp);
                
            }
            catch (System.Exception ex)
            {
                ExceptionHandler.HandleException(ex, "Error while Initializing Audiofile", this);
            }
        }
Do I Need to override the Read Method as well?
With this Waveout Settings i can reach a precision to 1/100 of a second but not a 1/1000

New Post: waveout get notification after elapsed time

$
0
0
This code you provided should work. To increase accuracy you may want to try a latency ~ 50ms with directsound or asio.

Number of buffers also has some influence on how many samples are read on each calling, but don´t ask me how exactly, better look at the source code then.

For an accuracy of 1/1000 s you´d have to read 44 samples (SampleRate/1000) on each calling for "Read". Therefore you´d need a extremely low latency as well as small buffers.

For more details Mark could probably tell more.

New Post: Capture headset (sound in and out)

$
0
0
I basically need to capture a conversation - the sound played on the headphones, as well as the headset microphone. This then needs to be encoded to GSM610, then sent across the network to a monitor. The network methods is not a problem - I have done that already. I can capture the speaker sound or the mic and encode. I do not seem to understand how to get the mixing and resampling done. Any guidance would be welcome.

New Post: Naudio circular buffer?

$
0
0
I have previously used a circular capture buffer to sample audio using DirectSound. Is that functionality available in Naudio? Ideally I would like a 5 second circular buffer that I can "dip" into every 200mS. Occasionally the interval might be longer. Obviously I would need a pointer to the data that has arrived since the last time I checked it. In DirectSound I can use "GetCurrentPosition" of the capture buffer. Does Naudio support anything like that?

Many thanks.

Paul.

New Post: Naudio circular buffer?

$
0
0
NAudio offers a "BufferedWaveProvider" for that task, which behind the scenes used a circular buffer.
This class got improved some time ago and should be thread-safe now if I remember correctly.

New Post: Capture headset (sound in and out)

$
0
0
You need to choose a common sample rate (e.g. 16kHz or 8kHz), and resample the audio captured to that. NAudio comes with several resamplers. The MediaFoundationResampler is the most powerful. I'd buffer up a certain amount of audio from both inputs and then resample and mix them with an IMixingSample provider. Then go to 16 bit and into a GSM encoder. It is quite a complicated bit of code to write, and I'm afraid I don't have a simple sample to hand, but that's the basic approach I'd take.

New Post: Is it not working in webservice ?

$
0
0
This dll works fine in a winform application.

But if I used it in webservice, it dosen't work at all. There is no exception but there is no sound.

here is my code, and the mp3 file exists.
    [WebMethod(Description = "Play Test")]
    public string Test()
    {
        WaveOut waveOutDevice = new WaveOut();

        AudioFileReader audioFileReader = new AudioFileReader("D:\\Web\\bin\\Music\\Thunderstruck.mp3");
        waveOutDevice.DeviceNumber = 0;
        waveOutDevice.Init(audioFileReader);
        waveOutDevice.Play();

        return "Success";
    }

Can naudio works in webservice or I just didn't get the right method ?

New Post: Capture headset (sound in and out)

New Post: Naudio circular buffer?

$
0
0
Many thanks for that Freefall. I will look into the BufferedWaveProvider.

New Post: Is it not working in webservice ?

$
0
0
OK, a number of issues here

First, and most important, you do understand that this will attempt to play sound on the web server, NOT the client calling the web service?

Second, WaveOut needs a dispatcher thread which you don't have here. WaveOutEvent creates its own thread to do audio processing

Third, Play is not blocking. It simply starts playback. So the minute you leave this method, waveOutDevice will become available for garbage collection. You'd need to sleep until you receive the PlaybackStopped event.

Commented Unassigned: Error with Stoprecording [16491]

$
0
0
Hi,

I developed a routine to produce sound with NAudio. When I stop the recording, I get the following error message:

INVALIDHANDLE CALLING WAVEINSTOP

Anyone know why?

Thx.

Here is my code:

Friend Sub StartCapture()
Try
_WaveInDevice = New WaveInEvent()
_WaveInDevice.DeviceNumber = 0
_WaveInDevice.WaveFormat = New WaveFormat(8000, 16, 1)
_WaveInDevice.NumberOfBuffers = 2
_WaveInDevice.BufferMilliseconds = 60
_WaveInDevice.StartRecording()
NbPaquetsAudioParPTT = 0
RaiseEvent OnDisplayMessage("Microphone opening...")
Catch Ex As Exception
RaiseEvent OnError("NaudioMicro", "StartCapture", Ex.Message, Ex.StackTrace)
End Try
End Sub

Friend Sub StopCapture()
Try
If _WaveInDevice IsNot Nothing Then
_WaveInDevice.StopRecording()
_WaveInDevice.Dispose()
_WaveInDevice = Nothing
End If
Catch Ex As Exception
RaiseEvent OnError("NaudioMicro", "StopCapture", Ex.Message, Ex.StackTrace)
End Try
End Sub

Private Sub _WaveInDevice_DataAvailable(ByVal sender As Object, ByVal e As NAudio.Wave.WaveInEventArgs) Handles _WaveInDevice.DataAvailable
NbPaquetsAudioParPTT += 1
RaiseEvent OnCaptured(e.Buffer, NbPaquetsAudioParPTT)
End Sub
































Comments: subscribe to RecordingStopped and dispose in there. StopRecording requests that recording stops, but it hasn't actually finished doing everything yet,

New Post: Is there a way to select/switch sample rates of a USB device with naudio?

$
0
0
First, this is NOT a question about sample rate conversion. It is about programmatically selecting the sample rate and bit depth of a USB sound device as one could do manually through the Windows sound dialog on the Advanced tab (see jpeg). I have a need to create a .NET app that, hopefully, could use naudio to play wav files using wasapi and be able to switch the sample rate before playing the next wav file. I would also like to be able to select a USB device from the list of available devices, as the USB devices themselves will be added and removed from the list of available devices (by means such as changing the device product ID done by a separate process that's already worked out).

Is it possible to do this with naudio? If not, does anyone know any way to do this?

New Comment on "Documentation"

$
0
0
we have been using naudio since 3-4 years, works pretty well for us. now we need to support our application in other browser other than IE. I tried to play the audio but nothing works. can you please let us know, will this supports other browser as well.?

New Post: Is there a way to select/switch sample rates of a USB device with naudio?

$
0
0
If you open a WASAPI device in exclusive mode then you can specify the sample rate the device uses.
I don't know any other way to do this, but maybe if you browse the WASAPI documentation you can find something.

Commented Unassigned: Audible Glitch when Clicking on Certain GUI Elements [16477]

$
0
0
There is an audible glitch when clicking on certain GUI elements such as the window title bar. The audio will momentarily pause. This issue can be easily reproduced with the Signal Generator demo.

System:
Surface Pro 3
Windows 8.1
Visual Studio 2013
Comments: Glitches can be due to the audio processing getting interrupted, or discontinuities in volume level. I suspect the first is what you are hearing when you click the title bar (maybe a garbage collect happens), and the second is what you hear when changing volume. One way round this is to not do sudden volume movements, but smoothly ramp the volume multiplier to the target value. You'd need to write a custom sample provider to do this though.

New Post: Edit Metadata

$
0
0
Unfortunately this is not a feature of NAudio, but I think you can do this with the Windows shell object.

New Post: Playing a decrypted mp3 file from the clipboard

$
0
0
Well none of that code uses NAudio. You could try putting the decrypted audio into a MemoryStream and then passing that into Mp3FileReader and playing it with WaveOutEvent.

New Post: using a scroll bar to navigate true the mp3 file playing..in VB.NET

$
0
0
There not many visual basic vb.net examples I can find...yet, I need the vb.net version...

I am trying to play mp3 and i like to use a progress bar that moves along with the playing time.
And I would like to be able to use the same progress bar to skip tru the song.

On my form application I got this so far:
Imports System.Data.OleDb
Imports NAudio.Wave

..
Public waveOut As WaveOut = New WaveOut
..
Public Sub Play_Sound(songname As String)
   On Error Resume Next 
    Dim mp3Reader As Mp3FileReader = New Mp3FileReader(songname)

    If waveOut.PlaybackState = PlaybackState.Playing Then
        waveOut.Stop()
        mp3Reader.Close()
    Else
        waveOut.Init(mp3Reader)
        waveOut.Play()

    End If
        SongLengthlabel.Text = mp3Reader.TotalTime.ToString("hh\:mm\:ss")

End Sub
..
When I call this code, with the mp3's filename the song plays: Play_Sound("c:\test.mp3")

Than to test i put the following code under a button:
     Dim test
    test = waveOut.GetPosition
    MsgBox(test)

Now the questions:
  1. the getposition returns a large number what does this represent and how can i convert it to actual time.
    the .ToString("hh\:mm\:ss") function like i used for the songlenthlabel, doesn't work here.
    1. How can I move the position of a mp3 playing to another position...in other words how to use the progress bar.
I did find an example in c# but simply converting the code doesn't work for me..
  1. Maybe I am getting this all wrong and you know of a better way?
Thanks

New Post: Capture headset (sound in and out)

$
0
0
markheath wrote:
You need to choose a common sample rate (e.g. 16kHz or 8kHz), and resample the audio captured to that. NAudio comes with several resamplers. The MediaFoundationResampler is the most powerful. I'd buffer up a certain amount of audio from both inputs and then resample and mix them with an IMixingSample provider. Then go to 16 bit and into a GSM encoder. It is quite a complicated bit of code to write, and I'm afraid I don't have a simple sample to hand, but that's the basic approach I'd take.
Any example of doing voice conversation recording would be nice.

Using WdlResamplingSampleProvider direct from WasapiLoopbackCapture or WaveIn works quite well.

Some of the issues I have run into:
  1. The event buffers provided by WaveInEventArgs are the same. There does not seem to be separate buffers for each device. Or I do not know where they are.
  2. I can capture speaker OR mic, not both at the same time. Seems my original message was misread.
  3. The outputs are in float format. This needs to be converted to byte for transfer over the network. WaveBuffer seems to only go one way, and can't convert float to byte.
Viewing all 5831 articles
Browse latest View live


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