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

New Post: Wasapi Loopback Recording -> Heavy noise/distortion

$
0
0
Hey all,

i'm trying to write a simple stereo-mix substitute in c#, but can't seem to get it working even remotely.
public void StartRecording()
        {
            recthread = new Thread( () =>
                {
                    
                    var cap = new WasapiLoopbackCapture();
                    startlabel:
                        var title = _helper.TrackTitle;
                        var artist = _helper.Artist;

                    if (title == "" || artist == "" || _helper.isPlayingAds)
                    {
                        Thread.Sleep(10);
                        goto startlabel;
                    }
                    
                        var writer = new WaveFileWriter(artist + " - " + SanitizeFilename(title,'-') + ".wav",
                                                       cap.WaveFormat);
                        cap.DataAvailable += (sender, args) =>
                            {
                                writer.Write(args.Buffer, 0, args.BytesRecorded);
                            };
                    
                        cap.StartRecording();
                        uint currentpos = _helper.CurrentTime;
                    while(_helper.Artist==artist && _helper.TrackTitle == title){
                        Thread.Sleep(5);
                        while(currentpos == _helper.CurrentTime)
                            Thread.Sleep(1);
                    }
                    cap.StopRecording();
                    writer.Flush();
                    writer.Close();
                    goto startlabel;
                    
                });
            recthread.Start();
        }
As you can see,nothing special going on there, but still i can't manage to get out what i hear when i captured the sound.

Any idea?

Shouldn't matter at all, but just to mention it: i'm running it in parallels on a macbook (i7,good enough for this easy task normally)

Thanks already for your ideas and @mark for this awesome lib :)

EDIT:

i tried it with different WaveFormat options. If i use what i posted here, it basically works, but "stutters".

Viewing all articles
Browse latest Browse all 5831

Trending Articles



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