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

New Post: WaveOut.Pause() call creating deadlock

$
0
0
Calling Pause() and Play() a few times (3-4 times in many cases) creates a deadlock for me. Digging down the problem I found that there are two threads, one in the Pause() function and the other in the Callback(), both trying to acquire lock on waveOutLock, thus creating a deadlock.

I see that this issue has been raised several times before. On one such occasion the proposed solution was to simply move the following line in the Pause() function ABOVE the lock statement:
     playbackState = PlaybackState.Paused;
I read that the author of Naudio accepted this solution and said he was going to incorporate this into NAudio. But as of the current version this line is still BELOW the lock statement, thus causing the deadlock. Was this change ever incorporated and then reverted back for some reason? (I just checked and it DOES solve my problem).

New Post: Real Time Spectrum

$
0
0
there is a basic spectrum analyzer demo in the NAudio WPF demo which should get you pointed in the right direction. It takes the FFT of every block of 1024 samples to do this.

New Post: Receiving SysEx Messages

$
0
0
I'm afraid I haven't tried this myself. I believe the MIDI.NET project might have support for this.

New Post: Output Wav(*.wav) file to microphone input

$
0
0
I'm afraid this is not possible directly in Windows. The workaround is to use a virtual audio device that creates virtual inputs and outputs that you can connect together, so you can play sound into one device and it appear as the input on another. Here's an example of software that can do this. Otherwise you have to physically connect a soundcard output to an input with a cable.

New Post: Redundant old versions source

$
0
0
thanks, we will delete it in a future version of NAudio

New Post: Calling WmaWriter.Write in data available event causes recording from microphone to stop

$
0
0
I'm surprised it's not available in Windows 8.1. Are you using one of the N or K versions of Windows perhaps?

Commented Unassigned: Range for PitchWheelChangeEvent.Pitch should be 0-16383 [16485]

$
0
0
I think I found a small bug in NAudio.Midi.PitchWheelChangeEvent:

The Pitch property accepts values up to (and including) 16384.
If, however, I create the event with that maximum value, the bit-shifting part in GetAsShortMessage() comes out as 0:
```
Console.Write( ((16384 & 0x7f) << 8) + (((16384 >> 7) & 0x7f) << 16) ); //-> 0
```

I believe the maximum value should actually be 16383.

(The reason I noticed this is because the Mackie Control I work with uses PitchWheel events for its faders and when I programmatically move the fader to its top position, it always goes to the bottom.)
Comments: yes I think you're right. Will try to get this sorted

New Post: Calling WmaWriter.Write in data available event causes recording from microphone to stop

$
0
0
As far as I can tell, I am not using the N or K version of Windows. I read that the Windows Media Format 11 SDK was merged into the "Windows SDK" for Windows 7. I installed the Windows SDK for Windows 8.1, I searched and see no Windows Media Format SDK in the Windows 8.1 SDK, and the IWMWriter COM object or corresponding GUID did not get installed in the Registry. Maybe I am looking in the wrong place? Or Maybe I should not expect to see IWMWriter GUID 96406BD4-2B2B-11D3-B36B-00C04F6108FF anywhere? My problem is this code causes an immediate recording stopped event:

void _microphone_DataAvailable(object sender, WaveInEventArgs e)
    {
        _micAudioBuffer.AddSamples(e.Buffer, 0, e.BytesRecorded);
        int mixedBytesRead = _mixerOutputConverter.Read(mixedBuffer, 0, e.BytesRecorded / micToMixerRatio);
        _wmaWriter.Write(mixedBuffer, 0, mixedBytesRead);
    }
Please see the entire code in my first post.

New Post: Playing a decrypted mp3 file from the clipboard

$
0
0
Hello!
I have this project in VB that in my intention should play a decrypted mp3 file from the clipboard with AxWindowsMediaPlayer1. I tried to find this information in internet but nothing... I don't want to think that it is impossible!
The Form needs 3 Buttons, 1 Label, 1 Windows Media Player... Of course you should change the mp3 file address to test.
Here's the code:

Imports System.Security.Cryptography
Imports System.IO
Imports System.Text

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim rij As New RijndaelManaged()
    rij.KeySize = 256
    rij.BlockSize = 256
    rij.IV = New [Byte]() {24, 23, 35, 83, 77, 35, 28, 34, 94, 25, 45, 2, 73, 26, 27, 78, 12, 23, 35, 83, 57, 35, 28, 34, 94, 25, 45, 22, 73, 26, 27, 78}
    Dim pwd As Byte() = New Byte(31) {}
    UTF8Encoding.UTF8.GetBytes("123abc").CopyTo(pwd, 0)
    Dim cs As New CryptoStream(File.OpenRead("C:\Users\User\Desktop\aa.mp3"),
  rij.CreateEncryptor(pwd, rij.IV), CryptoStreamMode.Read)
    Dim s As Stream = File.OpenWrite("C:\Users\User\Desktop\bb.mp3")
    cs.CopyTo(s)
    s.Flush()
    s.Close()
    cs.Close()
    Label1.Text = "Crypted!"
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Dim rij As New RijndaelManaged()
    rij.KeySize = 256
    rij.BlockSize = 256
    rij.IV = New [Byte]() {24, 23, 35, 83, 77, 35, 28, 34, 94, 25, 45, 2, 73, 26, 27, 78, 12, 23, 35, 83, 57, 35, 28, 34, 94, 25, 45, 22, 73, 26, 27, 78}
    Dim pwd As Byte() = New Byte(31) {}
    UTF8Encoding.UTF8.GetBytes("123abc").CopyTo(pwd, 0)
    Dim mp3Bytes() As Byte
    Using cs As New CryptoStream(File.OpenRead("C:\Users\User\Desktop\bb.mp3"), rij.CreateDecryptor(pwd, rij.IV), CryptoStreamMode.Read)
        Using ms As New MemoryStream
            cs.CopyTo(ms)
            mp3Bytes = ms.GetBuffer
        End Using
    End Using
    Label1.Text = "Decrypted!"

    Clipboard.Clear()            'clear the clipboard
    Clipboard.SetAudio(mp3Bytes) 'set the mp3 audio file bytes to the clipboard
    If Clipboard.ContainsAudio Then
        Dim btsFromClipboard() As Byte = {}
        Using cbstrm As Stream = Clipboard.GetAudioStream
            ReDim btsFromClipboard(CInt(cbstrm.Length) - 1)
            cbstrm.Read(btsFromClipboard, 0, CInt(cbstrm.Length))
        End Using

        'Now I would like to play the mp3 audio file directly from the clipboard

        AxWindowsMediaPlayer1.Ctlcontrols.play() ' ???? I don't know how to go on

    End If

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    End
End Sub
End Class

New Post: Edit Metadata

$
0
0
Hello,
I am looking to just edit the Title and Album Artist of an existing .wma file programmatically in C# or VB.net.

Any help would be appreciated.

Thanks
David

New Post: Clicking noise while changing volume/pan

$
0
0
Hi, Im using the NAudio driver in an multi-track loop application I'm building.
Incidentally, I'm using a customized class implementing ISampleProvider, which is a sort of combination of a pan provider and volume provider in the same class, and also adds a "Normalizing" factor to normalize the audio.
(Each track has its own instance of this "CustomSampleProvider", and each is then added to a MixingSampleProvider, which is used to initialize a WaveOut which is then played.)

Essentially, it all works fine, except for one little issue which is audible clicking sounds only when the values for volume or pan are changed (values being provided by a slider and rotating knob).
To be clear, the clicks only occur while the slider or knob is being adjusted. Once the new values are set, there is no more noise.

I'm sure my PC is not the problem (my system is Win7 on a i7-2600 3.6GHz machine)
Now , I thought it might be my customized code, or something to do with the GUI, but then I tried using the NAudio FadeInOutSampleProvider as is, and I find I'm getting the same clicking during programmed fade ins/fade outs (for example, 2 seconds or longer).

My CustomSampleProvider Read method simply does this:
     buffer(System.Math.Max(System.Threading.Interlocked.Increment(outIndex), outIndex - 1)) = lpan * Me.sourceBuffer(n) * (m_volume * NormFactor)
            buffer(System.Math.Max(System.Threading.Interlocked.Increment(outIndex), outIndex - 1)) = rpan * Me.sourceBuffer(n) * (m_volume * NormFactor)
(in other words, nothing too fancy, just multiplying by a pan factor, volume factor and normalizing factor)

Any ideas why the clicking occurs when the values are being changed?

Michael

Commented Unassigned: Audible Glitch when Clicking on Certain GUI Elements [16477]

$
0
0
There is an audible glitch when clicking on certain GUI elements such as the window title bar. The audio will momentarily pause. This issue can be easily reproduced with the Signal Generator demo.

System:
Surface Pro 3
Windows 8.1
Visual Studio 2013
Comments: Ah, I think this is the problem I'm encountering when changing pan or volume (clicking, or "glitching"). But i get the same clicks if volume is changed programmatically, so maybe not strictly a GUI issue? (Has this issue been addressed?, or is it unavoidable perhaps?)

New Post: Clicking noise while changing volume/pan

$
0
0
Addendum:
Don't know if this is related, but I just found that I'm getting the same clicks if I move the form (WinForm) at all during playback. Maybe it is a GUI issue...?

New Post: Volume Range of WaveOut

$
0
0
Hi,
What is the maximum and minimum volume range I can increase or decrease for WaveOut device?

Created Unassigned: Error with Stoprecording [16491]

$
0
0
Hi,

I developed a routine to produce sound with NAudio. When I stop the recording, I get the following error message:

INVALIDHANDLE CALLING WAVEINSTOP

Anyone know why?

Thx.

Here is my code:

Friend Sub StartCapture()
Try
_WaveInDevice = New WaveInEvent()
_WaveInDevice.DeviceNumber = 0
_WaveInDevice.WaveFormat = New WaveFormat(8000, 16, 1)
_WaveInDevice.NumberOfBuffers = 2
_WaveInDevice.BufferMilliseconds = 60
_WaveInDevice.StartRecording()
NbPaquetsAudioParPTT = 0
RaiseEvent OnDisplayMessage("Microphone opening...")
Catch Ex As Exception
RaiseEvent OnError("NaudioMicro", "StartCapture", Ex.Message, Ex.StackTrace)
End Try
End Sub

Friend Sub StopCapture()
Try
If _WaveInDevice IsNot Nothing Then
_WaveInDevice.StopRecording()
_WaveInDevice.Dispose()
_WaveInDevice = Nothing
End If
Catch Ex As Exception
RaiseEvent OnError("NaudioMicro", "StopCapture", Ex.Message, Ex.StackTrace)
End Try
End Sub

Private Sub _WaveInDevice_DataAvailable(ByVal sender As Object, ByVal e As NAudio.Wave.WaveInEventArgs) Handles _WaveInDevice.DataAvailable
NbPaquetsAudioParPTT += 1
RaiseEvent OnCaptured(e.Buffer, NbPaquetsAudioParPTT)
End Sub

































New Post: Creating noise gate

$
0
0
Hi, I've been trying to use naudio to create a noise gate. I saw there was a method called SimpleGate, but I haven't been able to use it. Inside DSP I only get access to BiQuadFilter, Complex, EnvelopeGenerator, FourierTransform and ImpulseResponseConvolution.

Is the SimpleGate method still available? If not, I can try to implement the noise gate but is there a way of getting the float samples back to a way that I can feed them into a filer?

Thanks

New Post: Clicking noise while changing volume/pan

New Post: play/write audio to file after filtering

$
0
0
Hi,
So I'm implementing a filter to audio that I'm reading from a file. I got the filter part working, but now I need to play the filtered audio and write it into a new file and I'm not sure how to implement that part.

Here's where I have my float buffer with the filtered samples.
    public float[] bandPassFilter(int totalSamples, float[] floatSamples, int sampleRate)
    { 
        float centerFrequency = (2900 + 330) / 2;
        float q = 0.71f;

        BiQuadFilter filter = BiQuadFilter.BandPassFilterConstantPeakGain(sampleRate,centerFrequency, q);

        float[] filteredSamples = new float[totalSamples];

        for (int i=0; i<totalSamples; i++)
        {
            filteredSamples[i] = filter.Transform(floatSamples[i]);
        }

        return filteredSamples;
    }
Thanks.

New Post: Clicking noise while changing volume/pan

$
0
0
why are you doing interlocked increments in your Read method. Taking many thousands of locks every second is not going to perform well. I'd also copy the NormFactor into a local variable to save repeated property gets.

Updated Wiki: Home

$
0
0

NAudio Overview

IMPORTANT The latest NAudio source code can now be found on GitHub. For now, CodePlex remains the place to access documentation, discussions and downloads.

NAudio is an open source .NET audio and MIDI library, containing dozens of useful audio related classes intended to speed development of audio related utilities in .NET. It has been in development since 2002 and has grown to include a wide variety of features. While some parts of the library are relatively new and incomplete, the more mature features have undergone extensive testing and can be quickly used to add audio capabilities to an existing .NET application. NAudio can be quickly added to your .NET application using NuGet.

NAudio demo project showing an MP3 file playing:
naudiodemo.png

NAudio WPF Project showing waveform visualisation and spectrum analyser:
NAudioWPF.png

Latest News

For the latest news and more documentation on NAudio, visit Mark Heath's blog.
  • 24 Nov 2014 NAudio 1.7.2 Released with lots of minor enhancements and bugfixes
  • 4 Nov 2013Programming Audio with NAudio training course released on Pluralsight
  • 29 Oct 2013 NAudio 1.7 Released. Read the release notes
  • 26 Oct 2012 NAudio 1.6 Released. Read the release notes
  • 9 Sep 2012 ASIO Recording Support added
  • 19 Dec 2011 NAudio 1.5 Released. Read the release notes
  • 20 Apr 2011 NAudio 1.4 Released. Read the release notes
  • 15 Apr 2011 NAudio demo now shows how to select output devices (for WaveOut, DirectSound, WASAPI and ASIO), and can play 8 bit, 16 bit, 24 bit, and 32 bit float WAV files. Fixed a longstanding ASIO issue.
  • 7 Nov 2010 Major improvements to Mp3FileReader
  • 10 Oct 2009 Version 1.3 Released. Read the release notes
  • 20 Sep 2009 We are getting close to feature complete for 1.3. Last chance to get in any feedback on the API
  • 26 Aug 2009 WPF Waveform drawing demo project including FFT added
  • 28 Feb 2009 Lots of new stuff is being added and planned, so do check out the Source Code tab to have a sneak peak at what's coming in 1.3
  • 26 June 2008 Version 1.2 Released. Read the release notes

NAudio Features

  • Play back audio using a variety of APIs
    • WaveOut
    • DirectSound
    • ASIO
    • WASAPI (Windows Vista and above)
  • Decompress audio from different Wave Formats
    • MP3 decode using ACM or DMO codec
    • AIFF
    • G.711 mu-law and a-law
    • ADPCM
    • G.722
    • Speex (using NSpeex)
    • SF2 files
    • Decode using any ACM codec installed on your computer
  • Record audio using WaveIn, WASAPI or ASIO
  • Read and Write standard .WAV files
  • Mix and manipulate audio streams using a 32 bit floating mixing engine
  • Extensive support for reading and writing MIDI files
  • Full MIDI event model
  • Basic support for Windows Mixer APIs
  • A collection of useful Windows Forms Controls
  • Some basic audio effects, including a compressor

Projects Using NAudio

NAudio currently is used to support a number of audio related utilities, some of which may be moved to be hosted on CodePlex in the future. If you have used NAudio for a project, please get in touch so we can post it here.
  • Skype Voice Changer - Modify your voice with audio effects while talking on Skype
  • .NET Voice Recorder - Record your voice, save to MP3, and visualise the waveform using WPF. Now includes autotune
  • Pree - Record spoken word without the need for editing.
  • MIDI File Mapper - Utility for mapping MIDI drum files for use on other samplers
  • MIDI File Splitter - Split MIDI files up at their markers
  • SharpMod - managed port of MikMod, can play mod files in both WinForms and Silverlight
  • NVorbis - Fully managed Vorbis decoder, with support for NAudio
  • Practice# - Windows tool for practicing playing an instrument with playback music. Includes FLAC playback support and an equaliser for NAudio.
  • WPF Sound Visualization Library - beautiful waveform and spectrum analyzer code written for WPF, comes with NAudio sample
  • Q2Cue - application for running audio cues in a theatrical or other performance related settings
  • TuneBlade - Stream Windows' audio to AirPlay receivers
  • Teachey Teach - utility to help English language conversation teachers generate feedback for students
  • Sound Mill - an audio player, list organizer and automation manager
  • Bravura Studio - a modular, extensible application and platform for creating and experimenting with music and audio.
  • musiX
  • SIPSorcery - .NET softphone framework
  • Squiggle - A free open source LAN Messenger
  • Helix 3D toolkit - Multi-format audio player
  • airphone-tv - A revival of axStream to implement control through the iPhone
  • JamNet - a Silverlight drum sample player
  • Jingle Jim - Jingle Software (German language)
  • All My Music
  • iSpy - Open Source Camera Security Software
  • RadioTuna - Online internet radio player
  • Fire Talk New - chat program
  • AVR Audio Guard - utility to fix a HDMI related issue
  • Locutor da Hora - Educational app simulating a radio studio
  • uAudio - Audio player component for Unity3D

More Info

For more information, please visit the NAudio Documentation Wiki

Donate

NAudio is a free open source project that is developed in personal time. You can show your appreciation for NAudio and support future development by donating.
Donate
Viewing all 5831 articles
Browse latest View live


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