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

New Post: Issues Adding Audio Device names to a List view

$
0
0

I got it working, the issue was with the way I was doing this.. and I'm still somewhat new to this so bear with me.  I was trying to add device details to another column in the listview control, and since I realized I didn't REALLY need those details, that they should be omitted.  once I removed the Subitem clause from the ListViewItem format, it worked fine.


New Post: Playing gsm phone call

$
0
0

the buffer will be constantly emptied by the playback. It has a maximum size anyway, so once it has emptied you'll just play silence. For it to work smoothly you need audio to be coming in as fast as you are playing it.

New Post: Problem with large wave file playback

$
0
0

Just wanted to update this thread. I resolved the issue and it seems I wasn't disposing the DirectSound device which resulted in the fast playback. Again, thanks for the help.

New Post: Playing gsm phone call

$
0
0

Got it work using BufferedWaveProvider. Is there a good way to determine the WaveOut DesiredLatency?

Modem is set to send size of 20ms frames.

55ms was the best latency I achieved for smooth playing but can't say is it working good for every computer.

New Post: CreateWaveFile and it's progress

New Post: Playing gsm phone call

$
0
0

As a general rule, the higher the latency, the smoother the playback will be. 200ms is a value I often use unless I have a really important reason why it should be lower.

New Post: NAudio and Live Sample Processing

$
0
0

yes, you could do this no problem with your own IWaveProvider (or ISampleProvider)

New Post: Problem with large wave file playback

$
0
0

glad you got it working in the end


New Post: Playing gsm phone call

$
0
0

A little off-topic.

Sometimes I got exception  when I try to start playign incoming voice

Unhandled exception: InvalidHandle calling waveOutPrepareHeader    
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)   
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)

 

This is very hard to repeat because it comes randomly.

Code is something like : modem sents serial port data "call ready" in my serial port eventhandler I initalize the waveoutevent and that recorder and start playing ( code above ).

I tried to create the waveout device only once not every time I start a new call but in after a sometime the waveout doesn't play nothing or the voice is almost silence.Creating a new waveoutevent instance fix this.

Created Issue: drumsamplepatternprovider array clear [16362]

$
0
0
In this section of Read:

if (samplesRead < count)
{
Array.Clear(buffer, offset + samplesRead, count - samplesRead);
samplesRead = count;
}

buffer is being Cleared as a byte[] at runtime, but the next 2 parameters are sample based (ie off by factor of 4).

Read parameter signature is a float[] so this does confuse me a bit. i worked around by ()*4 the 2nd 2 params.

Commented Issue: drumsamplepatternprovider array clear [16362]

$
0
0
In this section of Read:

if (samplesRead < count)
{
Array.Clear(buffer, offset + samplesRead, count - samplesRead);
samplesRead = count;
}

buffer is being Cleared as a byte[] at runtime, but the next 2 parameters are sample based (ie off by factor of 4).

Read parameter signature is a float[] so this does confuse me a bit. i worked around by ()*4 the 2nd 2 params.
Comments: good spot, the WaveBuffer hack confuses Array.Clear, so it isn't really safe to use in this fuction. I'll replace it with a for loop setting the values to 0.

Source code checked in, #9f3f6c740665

$
0
0
resolving issue 16362 - drumsamplepatternprovider should not use Array.Clear

Commented Issue: drumsamplepatternprovider array clear [16362]

$
0
0
In this section of Read:

if (samplesRead < count)
{
Array.Clear(buffer, offset + samplesRead, count - samplesRead);
samplesRead = count;
}

buffer is being Cleared as a byte[] at runtime, but the next 2 parameters are sample based (ie off by factor of 4).

Read parameter signature is a float[] so this does confuse me a bit. i worked around by ()*4 the 2nd 2 params.
Comments: I've checked in a fix. Please let me know if it works for you. thanks

Source code checked in, #7440e40466e3

$
0
0
attempting to improve transiton between tempos

Source code checked in, #4736799dfbff

$
0
0
drum pattern sequencer demo has smoother transition between tempos

Source code checked in, #e504bcf90778

$
0
0
added ASIO recording capability with example in NAudioDemo. Thanks to hfuy for some example code in the forums

New Post: ASIO input

$
0
0

Just wanted to say that I've checked in ASIO recording, basing a lot of the code off Hfuy's implementation, so thanks very much for sharing

New Post: Updated WaveformPainter

$
0
0

Hello, I have extended the NAudio.Gui.WaveformPainter class to support colored samples. This way you can colorize the waveform. I use it for displaying RX/TX audio in my voip app's waveform.

It should work the same as before, but I added an new AddMax(float,Color) function. Changed some variables such as List<float> samples to also hold color information.

Would be nice to see this updated in NAudio, thanks!

WaveformPainter

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace NAudio.Gui
{
    /// <summary>
    /// Windows Forms control for painting audio waveforms, coloring support added by Brandon Hansen, KG6YPI
    /// </summary>
    public partial class WaveformPainter : Control
    {
        Pen foregroundPen;
        List<KeyValuePair<float, Color>> samples = new List<KeyValuePair<float, Color>>(1000);

        int maxSamples;
        int insertPos;

        /// <summary>
        /// Constructs a new instance of the WaveFormPainter class
        /// </summary>
        public WaveformPainter()
        {
            this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint |
                ControlStyles.OptimizedDoubleBuffer, true);
            InitializeComponent();
            OnForeColorChanged(EventArgs.Empty);
            OnResize(EventArgs.Empty);
        }

        /// <summary>
        /// On Resize
        /// </summary>
        protected override void OnResize(EventArgs e)
        {
            maxSamples = this.Width;
            base.OnResize(e);
        }

        /// <summary>
        /// On ForeColor Changed
        /// </summary>
        /// <param name="e"></param>
        protected override void OnForeColorChanged(EventArgs e)
        {
            foregroundPen = new Pen(ForeColor);
            base.OnForeColorChanged(e);
        }

        /// <summary>
        /// Add Max Value.
        /// </summary>
        /// <param name="maxSample"></param>
        public void AddMax(float maxSample)
        {
            if (maxSamples == 0)
            {
                // sometimes when you minimise, max samples can be set to 0
                return;
            }
            if (samples.Count <= maxSamples)
            {
                samples.Add(new KeyValuePair<float, Color>(maxSample, foregroundPen.Color));
            }
            else if (insertPos < maxSamples)
            {
                samples[insertPos] = new KeyValuePair<float, Color>(maxSample, foregroundPen.Color);
            }
            insertPos++;
            insertPos %= maxSamples;

            this.Invalidate();
        }

        /// <summary>
        /// Add Max Value with specified Color.
        /// </summary>
        /// <param name="maxSample"></param>
        /// <param name="color"></param>
        public void AddMax(float maxSample, Color color)
        {
            if (maxSamples == 0)
            {
                // sometimes when you minimise, max samples can be set to 0
                return;
            }
            if (samples.Count <= maxSamples)
            {
                samples.Add(new KeyValuePair<float, Color>(maxSample, color));
            }
            else if (insertPos < maxSamples)
            {
                samples[insertPos] = new KeyValuePair<float, Color>(maxSample, color);
            }
            insertPos++;
            insertPos %= maxSamples;

            this.Invalidate();
        }

        /// <summary>
        /// On Paint
        /// </summary>
        protected override void OnPaint(PaintEventArgs pe)
        {
            base.OnPaint(pe);

            KeyValuePair<float, Color> _sample;
            for (int x = 0; x < this.Width; x++)
            {
                _sample = GetSample(x - this.Width + insertPos);
                float lineHeight = this.Height * _sample.Key;
                float y1 = (this.Height - lineHeight) / 2;
                pe.Graphics.DrawLine(new Pen(_sample.Value), x, y1, x, y1 + lineHeight);
            }
        }

        KeyValuePair<float,Color> GetSample(int index)
        {
            if (index < 0)
                index += maxSamples;
            if (index >= 0 & index < samples.Count)
                return samples[index];

            return new KeyValuePair<float, Color>(0, foregroundPen.Color);
        }
    }
}

New Post: Question about MP3 Streaming

$
0
0

Hello there,

I am currently working developing an app during my free time to control my speakers via Windows phone (basic stuff like picking from a list of mp3s stored in my hard drive and the play them straight away).

It worked great until I decided to split the computer application in two (a server and client), the server handles the communication with the phone and passes the data into a slave machine (like a laptop).  I took the same approach given in the NAudio.MP3 Stream, sending individual mp3 frames via TCP (will move into UDP once I get the hang of it) to the client and then decompressing the via format and associating it with a DirectSoundOut.

Overwriting the file that is being played/pausing/resuming works fine but I am having trouble implementing a loop song feature, since DirectSoundOut object never changes it state to stopped (I assume this has to do with the fact that BufferedWaveProvider is a open stream with no termination) I am unable to detect that the song has finished and that I can reuse the buffer without having to redownload the MP3.

My code to handle the incoming MP3frames is as follow:

 

        private void StreamMP3()
        {
            try
            {
                Byte[] buffer = new byte[65536];
                Mp3Frame frame = null;
                Int32 CArtistID = -1;
                Int32 CSongID = -1;

                while (true)
                {
                    if (CArtistID != ArtistID || CSongID != SongID)
                    {

                        CArtistID = ArtistID;
                        CSongID = SongID;

                        DisposeObjects();

                        this.SoundOut = new DirectSoundOut();
                        this.SoundOut.PlaybackStopped += SoundOut_PlaybackStopped;
                    }


                Waiting:

                    if (FrameCounter >= FrameList.Count)
                    {
                        Thread.Sleep(250);
                        goto Waiting;
                    }

 
                    frame = FrameList[FrameCounter];

                    if (frame != null)
                    {
                        if (bufferedWaveProvider != null && bufferedWaveProvider.BufferLength - bufferedWaveProvider.BufferedBytes < bufferedWaveProvider.WaveFormat.AverageBytesPerSecond / 4)
                            Thread.Sleep(500);

                        if (decompressor == null)
                        {
                            WaveFormat waveFormat = new Mp3WaveFormat(frame.SampleRate, frame.ChannelMode == ChannelMode.Mono ? 1 : 2, frame.FrameLength, frame.BitRate);
                            decompressor = new AcmMp3FrameDecompressor(waveFormat);
                            this.bufferedWaveProvider = new BufferedWaveProvider(decompressor.OutputFormat);
                            this.bufferedWaveProvider.BufferDuration = TimeSpan.FromSeconds(100);

                            int decompressed = decompressor.DecompressFrame(frame, buffer, 0);
                            bufferedWaveProvider.AddSamples(buffer, 0, decompressed);

                            this.volumeProvider = new VolumeWaveProvider16(bufferedWaveProvider);

                            SoundOut.Init(volumeProvider);
                            SoundOut.Play();

                        }
                        else
                        {
                            int decompressed = decompressor.DecompressFrame(frame, buffer, 0);
                            bufferedWaveProvider.AddSamples(buffer, 0, decompressed);
                        }

                        FrameCounter++;
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }

 

 

I would like to ask what would be the best approach to achieve my goal as I am kind of clueless right now and been looking online for days.

Thanks for reading!

 

Alex

Updated Wiki: Home

$
0
0

NAudio Overview

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.
  • 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.

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>