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

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

$
0
0
I recommend to retrieve position information rather from source than from hardware using this code:
'Current time:
CurrentLenLabel.Text = New DateTime(mp3Reader.CurrentTime.Ticks).ToString("HH:mm:ss")

'Total time:
TotalLenLabel.Text = New DateTime(mp3Reader.TotalTime.Ticks).ToString("HH:mm:ss") 

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

$
0
0
Yes, Freefall, but the problem is that I put the declaration of mp3reader in "Public Sub Play_Sound(songname As String)"
So after exiting this sub...the instance mp3reader is no longer accessable.

New Post: Capture headset (sound in and out)

$
0
0
1) the buffer for each device can be found in the eventargs "e.buffer", if they´re equal you might record the same device twice ;)
2) as far as I know, you can record many devices at the same time
3) you can recieve the bytes of your float data using the method described here. Anyway, you should create a BufferedWaveprovider for each device and put your recorded data into them. Then create a MixingWaveprovider and add all BufferedWaveproviders as input. Finally, on a looped background thread, create a buffer and read the data from the MixingWaveprovider into it. Then you can resample as I mentioned above and send the bytes over network.

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

$
0
0
What you search for, is an event that fires On playback position change. I use this code to raise a change when each sample is read:
'Declare on top:
Public WithEvents notify as NotifyingSampleProvider = Nothing
Public mp3Reader As Mp3FileReader = Nothing

'In your playback code:
Public Sub Play_Sound(songname As String)

    mp3Reader = New Mp3FileReader(songname)
    notify = New NotifyingSampleProvider(mp3Reader.ToSampleProvider)

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

End Sub

'Use the notify event to update your playback position with each processed sample.
'This Event is the most accurate and fires at your Mp3FileReader´s samplerate (usually 44100 times per second).
'For performance reasons you should better count for some samples till update,
'or your Form will redraw the labels 44100 times per second (overkill cpu waste)

Private SampleCounter as Integer = 0
Private Sub notify_Sample(ByVal sender As Object, ByVal e As NAudio.Wave.SampleEventArgs)
   SampleCounter += 1
   
   'For example wait 1024 samples till updating again.
   if SampleCounter >= 1024 then
     
     SampleCounter = 0

     'Current time:
     CurrentLenLabel.Text = New DateTime(mp3Reader.CurrentTime.Ticks).ToString("HH:mm:ss")

     'Total time:
     TotalLenLabel.Text = New DateTime(mp3Reader.TotalTime.Ticks).ToString("HH:mm:ss") 

   End If
End Sub

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

$
0
0
Thanks Freefall,
Publicly declaring the mp3Reader does help me with some issues..thanks..However the code you give above is not working as the
Private Sub notify_Sample(.....) sub routine is never called uppon.. I put i breakpoint inside the sub to verify that it is not called uppon.
What am i missing?

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

$
0
0
Ah sry, I forgot to add the handler there.

Change this:
Private Sub notify_Sample(ByVal sender As Object, ByVal e As NAudio.Wave.SampleEventArgs)
To this:
Private Sub notify_Sample(ByVal sender As Object, ByVal e As NAudio.Wave.SampleEventArgs) handles notify.Sample

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

$
0
0
Thanks man! That fixed it... Thanks for your help, not many VB examples out there..most is C#

In addition to your code i was able to add a slider that follows the time progress
'to follow the the timeline with a moving slider
TrackPosition.Minimum = 0
TrackPosition.Maximum = mp3Reader.TotalTime.TotalSeconds
TrackPosition.Value = mp3Reader.CurrentTime.TotalSeconds

Than....I run into the next question..
I can move the slider by hand to another position in time...how can i make the song that is playing follow..
I tried

mp3Reader.Position = TrackPosition.Value
But that just restarts the song from the beginning and it does not move in time
any suggestions?

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

$
0
0
Got it al to work
here is my working code.
'Declare on top:
Imports NAudio.Wave
Imports NAudio.Wave.SampleProviders
'Declare on top in class mainapp ( for my case)
Public waveOut As WaveOut = New WaveOut
Public WithEvents notify as NotifyingSampleProvider = Nothing
Public mp3Reader As Mp3FileReader = Nothing


Public Sub Play_Sound(songname As String)

    mp3Reader = New Mp3FileReader(songname)
    notify = New NotifyingSampleProvider(mp3Reader.ToSampleProvider)

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

End Sub

'Use the notify event to update your playback position with each processed sample.
'This Event is the most accurate and fires at your Mp3FileReader´s samplerate (usually 44100 times per second).
'For performance reasons you should better count for some samples till update,
'or your Form will redraw the labels 44100 times per second (overkill cpu waste)

Private SampleCounter as Integer = 0
Private Sub notify_Sample(ByVal sender As Object, ByVal e As NAudio.Wave.SampleEventArgs) handles notify.Sample
   SampleCounter += 1
   
   'For example wait 1024 samples till updating again.
   if SampleCounter >= 1024 then
     
     SampleCounter = 0

     'Current time:
     CurrentLenLabel.Text = New DateTime(mp3Reader.CurrentTime.Ticks).ToString("HH:mm:ss")

     'Total time:
     TotalLenLabel.Text = New DateTime(mp3Reader.TotalTime.Ticks).ToString("HH:mm:ss") 
'trackposition is the name of the slider(trackbar)
            TrackPosition.Minimum = 0
            TrackPosition.Maximum = mp3Reader.TotalTime.TotalMilliseconds
            TrackPosition.Value = mp3Reader.CurrentTime.TotalMilliseconds

   End If
End Sub

'Than i added an event that runs when the position of the slider is changed manualy:
    Private Sub Button6_Click_1(sender As Object, e As EventArgs) Handles Button6.Click
       'before changing the position of the mp3, convert milliseconds to ticks... 1ms is approx 176.4 ticks
        mp3Reader.Position = TrackPosition.Value * 176.4
    End Sub

The one concern i have, the number I use to convert millisecs to ticks..is that approx the same on every machine or does it vary with speed ...? because than i have a problem when i distribute it....

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

$
0
0
Actually there is an easier way. But as it seems you want to try to program a full audio player, I recommend you look at the source code of mine.

Although the article is outdated by far (v61, newest version is v108), you find all the basics in there. Also written in VB .NET.

New Post: Audio Watermarking

$
0
0
HI,

I would like to use naudio to add audio water mark on some mp3 files. Can you please help me with the approach i should take to achieve this.

Regards

New Post: Audio Watermarking

$
0
0
NAudio does not support the modifying of mp3 files for metadata, watermarks, tags or frame.

It just uses external codecs to play the audio frames inside.

New Post: Get Device which caused AudioEndpointVolume.OnVolumeNotification

$
0
0
Is it possible to get the device which caused the OnVolumeNotification-Event?
Or is it a global handler for all devices?

New Post: Get Device which caused AudioEndpointVolume.OnVolumeNotification

$
0
0
Sorry for that.
I see that the handle is part of the device itself.

New Post: Audio Watermarking

$
0
0
Can you suggest any other library that do that, using .Net and C#. I would greatly appreciate your help.

New Post: Audio Watermarking

$
0
0
The only way i know, is to mix two mp3 files with wav as step between:
Mp3Reader A ->ToSampleProvider -|
                                |->MixingSampleProvider -> Wave Writer -> Mp3 Encoder
Mp3Reader B ->ToSampleProvider -|
NAudio offers all that functionality, except the Mp3 Encoder.

New Post: Audio Watermarking

$
0
0
Hey Free Fall,

Thanks for such input, can you please provide me with some code. I would be very thankful.

New Post: Clicking noise when concatenating/joining two or more WAV files

$
0
0
Hey folks,

I am working on a project where I need to join several WAV files. My Code works totally fine,
but you hear clearly a clicking noise between two joined WAV files.

I am an audio engineer. When I work, with e.g. consecutive samples in a DAW (Digital Audio Workstation) and I want to prevent this clicking noise between two WAV samples then I have to create a crossover fade (basically this is a fadeout on the first sample and a fade in on the next sample).

Therefore my question would be if I can create such a crossover fade while concatenating two WAV files.

I provide my C# code below how I concatenate WAV files. This works for WAV files which are in the same "format". I found this piece of Code on (http://stackoverflow.com/questions/6777340/how-to-join-2-or-more-wav-files-together-programatically).

Thank you for advice and a solution.

Best regards,
Alex
public static void Concatenate(string outputFile, IEnumerable<string> sourceFiles)
{
    byte[] buffer = new byte[1024];
    WaveFileWriter waveFileWriter = null;

    try
    {
        foreach (string sourceFile in sourceFiles)
        {
            using (WaveFileReader reader = new WaveFileReader(sourceFile))
            {
                if (waveFileWriter == null)
                {
                    // first time in create new Writer
                    waveFileWriter = new WaveFileWriter(outputFile, reader.WaveFormat);
                }
                else
                {
                    if (!reader.WaveFormat.Equals(waveFileWriter.WaveFormat))
                    {
                        throw new InvalidOperationException("Can't concatenate WAV Files that don't share the same format");
                    }
                }

                int read;
                while ((read = reader.Read(buffer, 0, buffer.Length)) > 0)
                {
                    waveFileWriter.WriteData(buffer, 0, read);
                }
            }
        }
    }
    finally
    {
        if (waveFileWriter != null)
        {
            waveFileWriter.Dispose();
        }
    }

}

Created Unassigned: Clicking noise when concatenating/joining two or more WAV files [16492]

$
0
0
Hey folks,

I am working on a project where I need to join several WAV files. My Code works totally fine,
but you hear clearly a clicking noise between two joined WAV files. That is an huge issue.

I am an audio engineer. When I work, with e.g. consecutive samples in a DAW (Digital Audio Workstation) and I want to prevent this clicking noise between two WAV samples then I have to create a crossover fade (basically this is a fadeout on the first sample and a fade in on the next sample).

Therefore my question would be if I can create such a crossover fade while concatenating two WAV files.

I provide my C# code below how I concatenate WAV files. This works for WAV files which are in the same "format". I found this piece of Code on (http://stackoverflow.com/questions/6777340/how-to-join-2-or-more-wav-files-together-programatically).

Thank you for advice and a solution.

Best regards,
Alex

```
public static void Concatenate(string outputFile, IEnumerable<string> sourceFiles)
{
byte[] buffer = new byte[1024];
WaveFileWriter waveFileWriter = null;

try
{
foreach (string sourceFile in sourceFiles)
{
using (WaveFileReader reader = new WaveFileReader(sourceFile))
{
if (waveFileWriter == null)
{
// first time in create new Writer
waveFileWriter = new WaveFileWriter(outputFile, reader.WaveFormat);
}
else
{
if (!reader.WaveFormat.Equals(waveFileWriter.WaveFormat))
{
throw new InvalidOperationException("Can't concatenate WAV Files that don't share the same format");
}
}

int read;
while ((read = reader.Read(buffer, 0, buffer.Length)) > 0)
{
waveFileWriter.WriteData(buffer, 0, read);
}
}
}
}
finally
{
if (waveFileWriter != null)
{
waveFileWriter.Dispose();
}
}

}
```

Created Unassigned: Waveinputs missing from Visual Studio 2015 NuGet?? [16493]

$
0
0
Hi, I can't find waveinputs after installing nuget package. For example:

int waveInDevices = NAudio.Wave.WaveInputs.WaveIn.DeviceCount

Returns: Type or namespace name does not exist in namespace "Naudio.Wave"

New Post: Speed and pitch (?)

$
0
0
Does anyone know how to make a class that implements IWaveProvider with the ability to change the speed and pitch of the music you play?
Viewing all 5831 articles
Browse latest View live