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

New Post: BadDeviceId calling waveInOpen when running NAudioTutorial5

$
0
0

what device Id are you passing in?


New Post: Repeated Start/StopRecording does not work

$
0
0

OK, might be something strange going on with the emulated soundcard then. You ought to be able to do both at once.

Source code checked in, #4b03a028f309

$
0
0
some code cleanup, removing half-complete GUI controls, marking some others as obsolete

Source code checked in, #920e758340dc

New Post: How receive sysex?

$
0
0

Mark please can please publish  some code exmaple about how pikcup sysex events?
I wnat receive sysex, no send.

Best regards!

New Post: WaveOutEvent stops playing sound after some hours of playing

$
0
0

Sorry for delay. it's a little time consuming to catch the problem because it happens after lots of hours.

I did some tests. The PlaybackThread in WaveOutEvent is still alive, but the Read function of BufferedWaveProvider doesn't call.

I write my initialization code, may it helps:

BufferedWaveProvider waveProvider;

WaveFormat wf = new WaveFormat(8000, 16, 1);

waveProvider = new BufferedWaveProvider(wf);
waveProvider.DiscardOnBufferOverflow = true;

WaveProviderToWaveStream wpws = new  WaveProviderToWaveStream(waveProvider);


WaveOffsetStream wos = new WaveOffsetStream(wpws);

waveChan32 = new WaveChannel32(wos);

WaveMixerStream32 mixer;

mixer = new WaveMixerStream32();
mixer.AutoStop = false;

mixer.AddInputStream(chan);

I just should say that I add about 30 waveProvider in my mixer and the Read function of none of them will call after this problem.

New Post: Playing multi-channel audio from WAV file using Naudio

New Post: WaveOutEvent stops playing sound after some hours of playing

$
0
0

I found a new thing. When the problem occurs, the Read function of WaveMixerStream32 is calling but the Read function of WaveChannel32 (which should call from WaveMixerStream32) is not calling. Before the problem, it calls correctly.

Please help


New Post: Corrupt WAV header

$
0
0

Hi im trying to create a 24-bit WAVE file following the last example given by Mark here:

Sound Code: How to Use WaveFileWriter

The wave data generates as it should by the loop, but the resulting wavfile is only OK to open in VLC, all other programs flags for corrupt wave file header. (WaveLab 6, MediaPlayer, Quicktime, etc.)

Any suggestions why the header could be corrupt? (this is true for both 16/24-bit wave files)

Regards Jonas

New Post: Detect which input device has audio

$
0
0

Hello,

I'm writing a program that reads from line-in device. However, some computers only have a mic port. Moreover, if there are two ports, a person may by mistake plug into the mic port instead of line-in port. I want my program to be resilient and read wave data from the device where there is music data coming in. How can I do that ?  I guess I need to do silence detection. How would I do that ? This is my sample code:

        
private void on_data(object sender, NAudio.Wave.WaveInEventArgs e) {
     if (waveWriter == null) return;
     waveWriter.WriteData(e.Buffer, 0, e.BytesRecorded);
     waveWriter.Flush();
}

Somewhere in this code I have to do silence detection.

Is there any other way to solve this, without doing silence detection? Does NAudio have some filters that I could use out of the box?

New Post: Control volume of two mp3 files

$
0
0

Hello Mark,

thank you for creating this avesome possibility to play audio files.

I am currently working on a project that has to "fade" between two mp3 files. To accomplish that I created an array of two WaveOut´s in order to play the two files simultaneously and increase the volume of the first WaveOut respectively decrease the volume of the second.

Obviously I misunderstood the use of WaveOut - Setting the volume of one of the WaveOut-Objects leads into changing the "master"-volume of the program.

Is there any way to change the volume of the "streams" ?

This is my current code (VB 2010):

 

Option Strict Off
Option Explicit On
Imports Microsoft.Win32
Imports NAudio
Imports NAudio.Wave

Module globPlayFile
    Public Player(2) As WaveOut
    Public Stream(2) As WaveStream
    Public volumeStream(2) As WaveChannel32
    Public inputStream(2) As WaveChannel32
    Public mainOutputStream(2) As WaveStream
    Public Function MP3_Play(ByVal sFile As String, ByVal sIndex As Short) As Boolean
        'On Error Resume Next
        If Not Player(sIndex) Is Nothing Then
            Player(sIndex).Dispose()
            Player(sIndex) = Nothing
        End If

        If Not Stream(sIndex) Is Nothing Then
            Stream(sIndex).Dispose()
            Stream(sIndex) = Nothing
        End If
        mainOutputStream(sIndex) = CreateInputStream(sFile, sIndex)
        Player(sIndex) = New WaveOut()
        Player(sIndex).Init(mainOutputStream(sIndex))
        Player(sIndex).Play()
    End Function
    Private Function CreateInputStream(ByVal fileName As String, ByVal sIndex As Short) As WaveStream
        Stream(sIndex) = New Mp3FileReader(fileName)
        inputStream(sIndex) = New WaveChannel32(Stream(sIndex))
        volumeStream(sIndex) = inputStream(sIndex)
        Return volumeStream(sIndex)
    End Function

    Public Sub MP3_SetVolume(ByVal sIndex As Short, ByVal nVolume As Single)
        'On Error Resume Next
        If Not Player(sIndex) Is Nothing Then
            Player(sIndex).Volume = nVolume
        End If
    End Sub
End Module

 

Now I am using a timer to increase the volume of one WaveOut (via MP3_SetVolume) while deresing the volume of the other one.

Thank you in advance!

Greetings from Germany!

Sebastian

New Post: Control volume of two mp3 files

$
0
0

Hi,

I am getting closer. Another discussion entry gave me the idea of changing the Volume on the input streams. Now I can handle the volume of the two MP3-files seperately.

Unfortunately this brings me to another Problem: When I init the second WaveOut, I get a short mute on all other playing MP3-Files. This delay is just a split second but you can hear the short moment of silence.

Any idea how to remove this error?

Thank you in advance!

Sebastian

Imports NAudio
Imports NAudio.Wave
Public Class Form1
    Public Player(2) As WaveOut
    Public Stream(2) As WaveStream
    Public volumeStream(2) As WaveChannel32
    Public inputStream(2) As WaveChannel32
    Public mainOutputStream(2) As WaveStream
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        OpenFileDialog1.Title = "Choose MP3 file to play!"
        OpenFileDialog1.ShowDialog()
    End Sub
    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        OpenFileDialog2.Title = "Choose MP3 file to play!"
        OpenFileDialog2.ShowDialog()
    End Sub
    Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
        Player(1).Play()
        Button3.Enabled = False
        Button5.Enabled = True
    End Sub
    Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click
        Player(2).Play()
        Button4.Enabled = False
        Button6.Enabled = True
    End Sub
    Private Sub Button5_Click(sender As System.Object, e As System.EventArgs) Handles Button5.Click
        If Not Player(1) Is Nothing Then
            Player(1).Stop()
            Player(1).Dispose()
            Player(1) = Nothing
        End If

        If Not Stream(1) Is Nothing Then
            Stream(1).Dispose()
            Stream(1) = Nothing
        End If

        If Not volumeStream(1) Is Nothing Then
            volumeStream(1).Dispose()
            volumeStream(1) = Nothing
        End If

        If Not inputStream(1) Is Nothing Then
            inputStream(1).Dispose()
            inputStream(1) = Nothing
        End If

        If Not mainOutputStream(1) Is Nothing Then
            mainOutputStream(1).Dispose()
            mainOutputStream(1) = Nothing
        End If
        Button5.Enabled = False
        Button1.Enabled = True
    End Sub
    Private Sub Button6_Click(sender As System.Object, e As System.EventArgs) Handles Button6.Click
        If Not Player(2) Is Nothing Then
            Player(2).Stop()
            Player(2).Dispose()
            Player(2) = Nothing
        End If

        If Not Stream(2) Is Nothing Then
            Stream(2).Dispose()
            Stream(2) = Nothing
        End If

        If Not volumeStream(2) Is Nothing Then
            volumeStream(2).Dispose()
            volumeStream(2) = Nothing
        End If

        If Not inputStream(2) Is Nothing Then
            inputStream(2).Dispose()
            inputStream(2) = Nothing
        End If

        If Not mainOutputStream(2) Is Nothing Then
            mainOutputStream(2).Dispose()
            mainOutputStream(2) = Nothing
        End If
        Button6.Enabled = False
        Button2.Enabled = True
    End Sub
    Private Sub OpenFileDialog1_FileOk(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
        mainOutputStream(1) = CreateInputStream(OpenFileDialog1.FileName.ToString, 1)
        Player(1) = New WaveOut()
        Player(1).Init(mainOutputStream(1))
        Button3.Enabled = True
        Button1.Enabled = False
    End Sub
    Private Sub OpenFileDialog2_FileOk(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog2.FileOk
        mainOutputStream(2) = CreateInputStream(OpenFileDialog2.FileName.ToString, 2)
        Player(2) = New WaveOut()
        Player(2).Init(mainOutputStream(2)) 'This leads into the short silence on the track playing on Player(1)
        Button4.Enabled = True
        Button2.Enabled = False
    End Sub
    Private Function CreateInputStream(ByVal fileName As String, ByVal sIndex As Short) As WaveStream
        Stream(sIndex) = New Mp3FileReader(fileName)
        inputStream(sIndex) = New WaveChannel32(Stream(sIndex))
        volumeStream(sIndex) = inputStream(sIndex)
        Return volumeStream(sIndex)
    End Function
    Private Sub TrackBar1_ValueChanged(sender As Object, e As System.EventArgs) Handles TrackBar1.ValueChanged
        If Not inputStream(1) Is Nothing Then
            Dim tmpVolume As Single
            tmpVolume = TrackBar1.Value / 100
            inputStream(1).Volume = tmpVolume
        End If
    End Sub
    Private Sub TrackBar2_ValueChanged(sender As Object, e As System.EventArgs) Handles TrackBar2.ValueChanged
        If Not inputStream(2) Is Nothing Then
            Dim tmpVolume As Single
            tmpVolume = TrackBar2.Value / 100
            inputStream(2).Volume = tmpVolume
        End If
    End Sub
End Class

New Post: Understand if someone (human) is speaking in real time

$
0
0

Hi,

i wanna know if is possible to understand if someone (human) is speaking in real time with NAudio?

Is it possible using "waveIn" with NAudio 1.4?

Thanks a lot,

Enrico

New Post: Multiple WaveOut Objects

$
0
0

Hi dj,

how did you build the timeline component? Do you render the waveform for each seperate audio file first?

Regards,

Per

New Post: Multiple WaveOut Objects

$
0
0
percramer wrote:

Hi dj,

how did you build the timeline component? Do you render the waveform for each seperate audio file first?

Regards,

Per


Per - I built a custom reusable control (timeline obj). Since my app isn't an audio app and it's memory intensive for other objects, I had to limit the amout of memory used for audio and waveform data by sampling larger chunks. The control takes a list of audio peaks (ints) in it's constructor and renders these in the control's paint method. Depending on the zoom level, there is a calculation done to determin the X location of the line in a loop.

Rendering (painting) waveform data uses a lot of memory so it's also important to note that the render loop has a check for visablity. Since the list of ints is in order, you can exit the loop after you reach a point where the line location is out of bounds of the viewable area of the control.

 

Hope this helps,

Dj


New Post: Understand if someone (human) is speaking in real time

New Post: Detect which input device has audio

$
0
0

this is a similar question to this one. The basic answer is that you would analyse the audio in short blocks, calculating a decibel level. You probably shouldn't detect for perfect silence (which would be all samples zero), but you could check that a block of audio for say 20ms didn't go over a set threshold.

New Post: Control volume of two mp3 files

$
0
0

that's strange. Could it be the garbage collector kicking in momentarily perhaps? An alternative approach is to have just one WaveOut and mix the MP3s to be sent to it in software. This is a more complicated solution in terms of code though.

New Post: G729 Support

$
0
0

NAudio can use whatever ACM codecs are on your system, if you use the correct WaveFormat header in conjunction with WaveFormatConversionStream. You can use the NaudioDemo application to look at what codecs are installed.

Mark

New Post: Windows 8 WinRT Metro Style Support

$
0
0

hi Tom,

I do accept patches but please read these notes about submitting patches. NAudio currently builds against .NET 2.0, and maintaining backwards compatibility is important. There would only be a certain subset of NAudio that would apply with WinRT in any case, so I could imagine a separate project just bringing in fewer files might be possible. I have got VS2012 installed on my dev PC myself now, so I may get the chance at some point to experiment with how WinRT and NAudio can be combined.

Mark

Viewing all 5831 articles
Browse latest View live


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