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

New Post: Sinus generating quasi real time - is it possible to know currently played sample

$
0
0
Hi

I would like to know the following process is possible or not:

those I know:
I can generate sinus in left and/or right channel and I can change amplitude during generating as in sinus wave generating sexample code (level * Math.Sin(wt - fi)) I count the samples for calculating the current sample.

Now, I generate 10 seconds samples in an object list and the overridden Read function uses that as sample source.... The amplitude changes in samples during this 10 seconds. Same amplitude is in 2 full periods of sinus and then increases. I know exactly which sample has how many amplitude (level) in samples.

The question:
I should stop playing samples if user press a button on keyboard and then I should know amplitude (level) of the actually played sample (not value). So I should know which sample is playing currently... then I would know to calculate the amplitude from current sample number.

How can I determine which sample was played in sample list when user pressed a button? What is the sample number of current played sample?

New Post: managing and playing a set of .wav files

$
0
0
I'd like to use NAudio for the following. I'd like to pre-load a set of .wav files (maybe 10-20) at startup and have them all ready to be played. Then, while the application is running, I'd like to play them at will. My desire to pre-load them is to ensure the .wav files are fully loaded from disk into memory and that there's no I/O required when it comes time to play a given file.

Is there a recommended way to do this with NAudio? It appears to me that the WaveFileReader() isn't going to actually read the data until its asked to play it.

Also, IIRC, the docs seemed to suggest that the WaveOutEvent.Init() call was opening the sound card, which makes me wonder if its wise to create a whole bunch of those (1 for each file) ahead of time.

Basically, I'm trying to figure out how to get all my sounds loaded in memory and ready to go and be able to trigger them on demand without worrying about any loading time.

EDIT: It appears that you can only use a player (like WaveOutEvent) once. After playing the sound file once, it doesn't do anything if you call Play() again. So I guess the intent is that you create a new player each time?

New Post: simple vb.net Naudio volume meter

$
0
0
I can't get the visual basic volume meter to work
I'm using windows 8 and 10 with visual studio 2013 and tried this code
after adding the reference naudio.dll and naudio core api to the project :
Imports NAudio
 Imports NAudio.CoreAudioApi

 Public Class Form1
 Private de As New MMDeviceEnumerator

 Private volume As Double
 Private volumelast As Double
 Private change As Double





 Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
 Dim device As MMDevice = de.GetDefaultAudioEndpoint(DataFlow.Capture, Role.Multimedia)
 volume = device.AudioMeterInformation.MasterPeakValue * 100

 Label1.Text = volume
 End Sub
 End Class 
I only get the value 0 in the label, and yes the mic is set as the default audio device.

New Post: simple vb.net Naudio volume meter

$
0
0
also yes the timer is set to true

New Post: professional Audio and DSP software engineering jobs

$
0
0
https://www.amazon.com/dp/B01MS8W9XI

4 of the projects in this book was for professional software engineer jobs.
This book will go through different projects that will teach the reader how to write software: to improve their singing, synthesize different guitar sounds, change the human brainwave, break glass, help people to relax and learn about many different sound engineering and DSP tools : DFT, FFT, High pass filter, low pass filter, fundamental frequency, Karplus-strong algorithm. In this book they will learn about: Isochronic tones, Binaural beats, and Monaural beats and how to code them. Then they will be able to come up with their own beats. They will learn about sound waves and a lot more.
There are very few books / websites that show people how to code DSP tools. There are a lot that show the theory but not many that show the application, so I think this Book would be very useful for high school students, college students, and inter level employees.

New Post: Waveform using WasapiLoopbackCapture WPF thread updating ui

$
0
0
has someone manage to implement and how??? 3 days trying to make it work please share you solution. Thanks guys...
already tried:
private readonly SynchronizationContext _syncContext = SynchronizationContext.Current;
{
_syncContext.Post(o => waveCanvas.Children.Clear(), null);
...
}
Polyline pl;
double plH = 0;
double plW = 0;

List<byte> totalbytes;
Queue<Point> displaypts;
Queue<Int32> displaysht;
long count = 0;
int numtodisplay = 2205;

public IWaveIn wi;

private void start()
{
    wi = new WasapiLoopbackCapture();
    wi.DataAvailable += new EventHandler<WaveInEventArgs>(wi_DataAvailable);

    //
    pl = new Polyline();
    pl.Stroke = Brushes.Blue;
    pl.Name = "waveform";
    pl.StrokeThickness = 2;
    pl.MaxHeight = SystemParameters.FullPrimaryScreenHeight;
    pl.MaxWidth = SystemParameters.FullPrimaryScreenWidth;

    plH = pl.MaxHeight;
    plW = pl.MaxWidth;

    displaypts = new Queue<Point>();
    totalbytes = new List<byte>();
    displaysht = new Queue<Int32>();
    //

    wi.StartRecording();
}

public void wi_DataAvailable(object sender, WaveInEventArgs e)
{
    if (e != null)
    {
        totalbytes.AddRange(e.Buffer);
        byte[] shts = new byte[4];

        for (int i = 0; i < e.BytesRecorded - 1; i += 100)
        {
            shts[0] = e.Buffer[i];
            shts[1] = e.Buffer[i + 1];
            shts[2] = e.Buffer[i + 2];
            shts[3] = e.Buffer[i + 3];
            if (count < numtodisplay)
            {
                displaysht.Enqueue(BitConverter.ToInt32(shts, 0));
                ++count;
            }
            else
            {
                displaysht.Dequeue();
                displaysht.Enqueue(BitConverter.ToInt32(shts, 0));
            }
        }

        waveCanvas.Children.Clear(); // Here updating ui from another thread
        pl.Points.Clear(); // Here updating ui from another thread

        Int32[] shts2 = displaysht.ToArray();
        for (Int32 x = 0; x < shts2.Length; ++x)
        {
            pl.Points.Add(Normalize(x, shts2[x]));  // Here updating ui from another thread
        }
        this.waveCanvas.Children.Add(pl);  // Here updating ui from another thread
    }
}

Point Normalize(Int32 x, Int32 y)
{
    Point p = new Point();
    p.X = 1.0 * x / numtodisplay * plW;
    p.Y = plH / 2.0 - y / (Int32.MaxValue * 1.0) * (plH / 2.0);
    return p;
}

New Post: Convert WMA to WAV ?

$
0
0
Hello, I am trying desperately to convert a WMA byte stream to a WAV, first I've tried this code:
    System.IO.File.WriteAllBytes("wmatemp.wma", data);
    WMAFileReader fileReader = new WMAFileReader("wmatemp.wma");
    WaveStream waveStream = WaveFormatConversionStream.CreatePcmStream(fileReader);
    WAV wav = new WAV(AudioMemStream(waveStream).ToArray());
But everytime I run the program, when it reaches the point where it has to create the fileReader, it crashes, without throwing exception, I found this error in the error log:
"The thread tried to read from or write to a virtual address for which it does not have the appropriate access."
My second attempt was with this code:
MemoryStream wmastream = new MemoryStream(data);
        StreamMediaFoundationReader fileReader = new StreamMediaFoundationReader(wmastream);
        
        WaveStream waveStream = WaveFormatConversionStream.CreatePcmStream(fileReader);
        WAV wav = new WAV(AudioMemStream(waveStream).ToArray());
At this point the program doesn't crash but it still throws an exception, that is
"Requestes feature is not implemented"
I would appreciate any type of help, thank you !

New Post: Waveform using WasapiLoopbackCapture WPF thread updating ui


New Post: Help with output device selection and multichannel output

$
0
0
Hello - Is there a demo for how to choose from the installed sound cards as the output device? Also I'm looking for a demo for outputting to specific channels. I have a 12-in 16-out soundcard and would like example code to for instance send a sine wave to output number 6. Thanks.

Created Unassigned: NAudio freezes on one specific mp3 file [16513]

$
0
0
NAudio is freezing on one specific mp3 file. All other files play ok. This same mp3 file plays fine in Windows Media Player. However, in NAudio, this one specific file freezes towards the end of the file. I have tried two versions of NAudio : 1.7.3 and 1.8.0 (latest) and both have the same freezing issue. I can provide the MP3 file for developer testing. Thank you.

Commented Unassigned: NAudio freezes on one specific mp3 file [16513]

$
0
0
NAudio is freezing on one specific mp3 file. All other files play ok. This same mp3 file plays fine in Windows Media Player. However, in NAudio, this one specific file freezes towards the end of the file. I have tried two versions of NAudio : 1.7.3 and 1.8.0 (latest) and both have the same freezing issue. I can provide the MP3 file for developer testing. Thank you.
Comments: Hi, thanks for reporting this issue. You're welcome to provide an MP3 for testing, but I can't make any promises about when I'll have time to investigate this specific issue. As a workaround you could try using MediaFoundationReader instead which might be more reliable.

Commented Unassigned: NAudio freezes on one specific mp3 file [16513]

$
0
0
NAudio is freezing on one specific mp3 file. All other files play ok. This same mp3 file plays fine in Windows Media Player. However, in NAudio, this one specific file freezes towards the end of the file. I have tried two versions of NAudio : 1.7.3 and 1.8.0 (latest) and both have the same freezing issue. I can provide the MP3 file for developer testing. Thank you.
Comments: Hi thank you for your message. Unfortunately we cannot afford to switch to MediaFoundationReader at this point in development and usage of NAudio. If you can please when you have an opportunity, I am attaching the actual sample mp3 file. This file plays all the way to the end with no problems using Windows Media Player. However, with NAudio, it NAudio freezes almost at the end of the file. I would really appreciate your concern to this. Thank You.

New Post: Sinus generating quasi real time - is it possible to know currently played sample

Commented Unassigned: NAudio freezes on one specific mp3 file [16513]

$
0
0
NAudio is freezing on one specific mp3 file. All other files play ok. This same mp3 file plays fine in Windows Media Player. However, in NAudio, this one specific file freezes towards the end of the file. I have tried two versions of NAudio : 1.7.3 and 1.8.0 (latest) and both have the same freezing issue. I can provide the MP3 file for developer testing. Thank you.
Comments: If you play this in the NAudio Demo app it seems you'll find that there is no problem playing it to the same point that Windows Media Player does. The only issue I noticed is that NAudio does not accurately work out how far through we are, probably due to changes to bitrate maybe. So long as you wait until WaveOut PlaybackStopped event is fired, you should hear everything.

Created Unassigned: Lag playback when using Icy-MetaData header [16514]

$
0
0
Hello. Firstly, I want to thank you for the excellent library.

I develop applications for listening to Internet radio. Faced with the problem that when you send a request with the title:

webRequest.Headers.Add ( "Icy-MetaData", "1");

Play lag at certain intervals, thus setting the parameter "Latency" for "DirectSoundOut" does not help. Play with this parameter, it does not eliminate the lag. If you remove the title, play clean and without any lag.

The code used as the basis of an example: https://naudio.codeplex.com/SourceControl/latest#NAudioDemo/Mp3StreamingDemo/MP3StreamingPanel.cs

Please help me find the problem. Maybe I'm doing something wrong. Perhaps this lag cause sent meta data? Then how to get them but will get rid of noise?

Commented Unassigned: NAudio freezes on one specific mp3 file [16513]

$
0
0
NAudio is freezing on one specific mp3 file. All other files play ok. This same mp3 file plays fine in Windows Media Player. However, in NAudio, this one specific file freezes towards the end of the file. I have tried two versions of NAudio : 1.7.3 and 1.8.0 (latest) and both have the same freezing issue. I can provide the MP3 file for developer testing. Thank you.
Comments: Thanks. It looks like it is something that should be corrected. I was able to do a workaround with your suggestion by also checking if playbackstate is stopped as you mentioned: private bool endOfStream() { try { // To check for end of file, check stream position // In addition, also check PlaybackState // Since NAudio does not accurately work out how far through we are, probably due to changes to bitrate if (fileWaveStream.Position >= fileWaveStream.Length || waveOut.PlaybackState == PlaybackState.Stopped) { return true; } else { return false; } } catch (Exception ex) { return true; // if we have an error mark as end of stream true } }

Commented Unassigned: NAudio freezes on one specific mp3 file [16513]

$
0
0
NAudio is freezing on one specific mp3 file. All other files play ok. This same mp3 file plays fine in Windows Media Player. However, in NAudio, this one specific file freezes towards the end of the file. I have tried two versions of NAudio : 1.7.3 and 1.8.0 (latest) and both have the same freezing issue. I can provide the MP3 file for developer testing. Thank you.
Comments: NAudio works out the length of an MP3 file by examining each frame and calculating how many samples it ought to decompress into. But sometimes (maybe due to corruption) that is wrong. Can be very hard to track down, so the solution you show is the right way to work around this.

New Post: Waveform using WasapiLoopbackCapture WPF thread updating ui

New Post: Sinus generating quasi real time - is it possible to know currently played sample

$
0
0
Divide by Math.Sin(wt - fi) and get the amplitude (=level) from your overridden read sampleprovider?

New Post: Plot by Time

$
0
0
Use NotifyingSampleProvider and plot the samples?
Viewing all 5831 articles
Browse latest View live


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