GithubHelp home page GithubHelp logo

Comments (14)

markheath avatar markheath commented on June 8, 2024 1

Might be worth looking at WasapiCapture now that it supports built-in resampling in NAudio 2.1.0

from naudio.

markheath avatar markheath commented on June 8, 2024

Not seen this myself. You might want to try WaveInEvent instead

from naudio.

Vort avatar Vort commented on June 8, 2024

@markheath, did you tried my test program with 1.7.3 version or newer?

from naudio.

markheath avatar markheath commented on June 8, 2024

sorry, haven't had a chance to try this myself. However, if I had an application that needed to stop and start recording frequently with small gaps, I would actually not use StopRecording and StartRecording. Instead I would just have a boolean flag saying whether I was currently recording and in my DataAvailable event I'd just ignore it if my flag wasn't set

from naudio.

Vort avatar Vort commented on June 8, 2024

that needed to stop and start recording frequently with small gaps

Gaps are small in this test program because it is easier to reproduce the problem in such way.

Instead I would just have a boolean flag

I was thinking about solution with data discarding, but it have some problems:

  1. It uses more system resources that is needed for such task. I know that overhead is low, but ideally it should be zero.
  2. User may want to disconnect recording device between transmissions.

sorry, haven't had a chance to try this myself

So this report is valid and should not be closed?
I was created it not because I can't think of some workaround.
Just because I wanted to help in making this library better.

from naudio.

markheath avatar markheath commented on June 8, 2024

OK thanks I see. I was just doing a cleanup of old stuff, sounds like this is a genuine bug, but not one I've had time to look at. Very happy to accept PRs for anyone who wants to tackle fixing this. One idea I've had for some time is that the WaveIn and WaveOut statuses need to include Starting and Stopping states which will make managing edge cases like restarting while we're still stopping much easier.

from naudio.

nathan-alden-sr avatar nathan-alden-sr commented on June 8, 2024

I just ran into this problem myself. If I record a short clip (say, a second or so) and then call StopRecording(), then StartRecording() very shortly thereafter, I get that exception.

from naudio.

markheath avatar markheath commented on June 8, 2024

thanks for reporting. If I were doing NAudio again from scratch I'd have some additional "starting" and "stopping" states on WaveIn, which I think would make it easier to code around issues where recording (and playback) start and stop very quickly. Remember with recording that you can always capture soundcard data without necessarily "recording" it to a file. This is quite a common approach, so starting recording is just flipping a boolean flag to say we want to keep captured audio. It might help in the short term until we can get this bug fixed.

from naudio.

nathan-alden-sr avatar nathan-alden-sr commented on June 8, 2024

@markheath Thanks. 👍 Nice little library. Took me no longer than 5 minutes to get it recording to a MemoryStream.

from naudio.

anthonyraymond avatar anthonyraymond commented on June 8, 2024

I found a workaround, definely not the best way to handle it but...

You have to create a new WaveIn and use use the same MemoryStream each time you want to record.

MemoryStream stream = waveIn.MemoryStream;
waveIn = new WaveIn();
waveIn.MemoryStream = stream;
waveIn.WaveFormat = new WaveFormat(44100, 1);
waveIn.DataAvailable += waveIn_DataAvailable;
waveIn.RecordingStopped += waveIn_RecordingStopped;

// record one time, then stop recording, then create a new WaveIn, and so on...

It's dirty, but it works.

from naudio.

markheath avatar markheath commented on June 8, 2024

not sure why you need a new instance of WaveIn here? Just start recording again and write to the same memory stream if you want

from naudio.

lixikun avatar lixikun commented on June 8, 2024

Do we have a solution for this Exception?
waveIn_RecordingStopped: exception=NAudio.MmException: WaveStillPlaying calling waveUnprepareHeader
в NAudio.MmException.Try(MmResult result, String function)
в NAudio.Wave.WaveInBuffer.Reuse()

from naudio.

Vort avatar Vort commented on June 8, 2024

// record one time, then stop recording, then create a new WaveIn, and so on...

@anthonyraymond thanks. I tried it and it works, but not for too long.
In my case (I don't use MemoryStream), program leaks handles with every reinitialization.
Which means that after some amount of start-stop cycles, not only your program can't start recording anymore, but any other program in the system.
After I added waveIn?.Dispose(); before waveIn = new WaveIn();, handle leak stopped.
But who knows what other surprises are still waiting with this solution.
(My comment is vaild for version 1.7.3. What is the behaviour of previous and later versions, I don't know)

from naudio.

rey-allan avatar rey-allan commented on June 8, 2024

Might be worth looking at WasapiCapture now that it supports built-in resampling in NAudio 2.1.0

This worked for me! Thanks for the suggestion!

from naudio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.