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

New Post: midi in problem: Object reference not set to an instance of an object.

$
0
0

Please tellme if can reproduce the test.

Bets regards.


New Post: Play specific channel in a multichannel WMA file- c#

$
0
0

  Hi,

We have a c# project in .Net framework 4.0. In the recording session, we create a multichannel WMA file (6-8 channels).
The user should be able to play any channel (one or more) they want. How can I play only one specific channel from a multichannel WMA file or WAV using NAudio ?.

I am using Window 7 and the NAudio version is 1.3

Thanks in advance for your help!

New Post: Get every frequency in music file

$
0
0

how can I get frequency music ? 

I'm little confused about byte.....Does it mean byte as frequency ? 

New Post: Get every frequency in music file

$
0
0

You can determine the frequencies present in audio  by using an FFT. It's not an easy topic for beginners though, as you need to understand some DSP.

Read my Autotune article for more information:

http://channel9.msdn.com/coding4fun/articles/AutotuneNET

New Post: Play specific channel in a multichannel WMA file- c#

$
0
0

Read this article to understand how to route audio to different outputs:

http://mark-dot-net.blogspot.co.uk/2012/01/handling-multi-channel-audio-in-naudio.html

I'm not sure if the WMA support in NAudio will work with multi-channels. You'll just have to try it. Also, not all output driver models will support being opened with multiple channels.

I also recommend updating to the very latest NAudio code.

New Post: Get every frequency in music file

$
0
0

Is it possible in NAudio to do echo data hiding ?

Echo daa hiding like hide data in the frequency  of song.

New Post: Creating custom sound (Wave)

$
0
0

here's how to generate a sine wave:

http://mark-dot-net.blogspot.co.uk/2009/10/playback-of-sine-wave-in-naudio.html

for more complex sounds, you would mix together multiple frequencies.

New Post: Creating custom sound (Wave)


New Post: midi in problem: Object reference not set to an instance of an object.

$
0
0

Mark sorry for insist, i know you handle the projetc in your free times.
Please asap you cna take a look on this, i borken my head trying to figure checkingthe source code f your lib why this happen but no idea yet.
Thankyou!

New Post: midi in problem: Object reference not set to an instance of an object.

$
0
0

hi GrobotoX. I'm afraid I don't have a lot of time to look into individual problems. I did try to set up your system, but I didn't get an error when clicking on the go to win1 button

New Post: is it possible to record to mp3 file directly?

$
0
0

As I said, I plan to write a tutorial at some point, but you can find instructions on using stdin in C# by searching on StackOverflow

New Post: Get every frequency in music file

$
0
0

do you mean echo suppression? NAudio does not have an echo suppression algorithm I am afraid

New Post: midi in problem: Object reference not set to an instance of an object.

$
0
0

LOL!
Mark you helpme in anyway!
After see you cnat reproduce this test i dicover the version of midi loopbe1 i have installed no is the latest and that is what cause the problem.
After install the latest version the smae i send to you problem stoped!!  :)
Awesome!

Thankyou man!

New Post: Is possibe setup multiple MIDI IN OUT DEVICES? HOW

$
0
0

Mark Is possibe setup multiple MIDI IN OUT DEVICES? HOW?

The example in the cde only show how select one device in or out.
How can select multile devices in and out?

New Post: waveIn_DataAvailable handler is not triggered from windows service or console application !

$
0
0

Hi Mark,

I have the same problem but i couldn't find the release 1.5.8. could you give me the link please?

 


New Post: ASIO input

$
0
0

[quote]Did you perhaps grab the un-hacked file by accident?[/quote]

What d'you think I am, some sort of idi...

...oh yeah, I am an idiot. Sorry, folks, my bad.

Anyway, here it is. I did just test this out and it is working, at least in the context of my own code. The purpose of this change, by the way, was to write an SMPTE timecode decoder. This is also working, and if there's any interest in naudio being able to decode SMPTE timecode, I might be persuaded to donate it.

using System;

namespace NAudio.Wave.Asio
{

    /// 

    /// ASIODriverCapability holds all the information from the ASIODriver.
    /// Use ASIODriverExt to get the Capabilities
    /// 

    internal class ASIODriverCapability
    {
        public String DriverName;  
      
        public int NbInputChannels;
        public int NbOutputChannels;

        public int InputLatency;
        public int OutputLatency;

        public int BufferMinSize;
        public int BufferMaxSize;
        public int BufferPreferredSize;
        public int BufferGranularity;

        public double SampleRate;

        public ASIOChannelInfo[] InputChannelInfos;
        public ASIOChannelInfo[] OutputChannelInfos;
    }

    /// 

    /// Callback used by the ASIODriverExt to get wave data
    /// 

    internal delegate void ASIOFillBufferCallback(IntPtr[] InputBufferChannels, IntPtr[] OutputBufferChannels);

    /// 

    /// ASIODriverExt is a simplified version of the ASIODriver. It provides an easier
    /// way to access the capabilities of the Driver and implement the callbacks necessary 
    /// for feeding the driver.
    /// Implementation inspired from Rob Philpot's with a managed C++ ASIO wrapper BlueWave.Interop.Asio
    /// http://www.codeproject.com/KB/mcpp/Asio.Net.aspx
    /// 
    /// Contributor: Alexandre Mutel - email: alexandre_mutel at yahoo.fr
    /// 
    /// ASIO input hacked in by: Phil Rhodes
    /// This is currently extremely basic and breaks the previous API in several
    /// places. See http://naudio.codeplex.com/discussions/284258
    /// 
    /// Changes are particularly in CreateBuffers and BufferSwitchCallback.
    /// 
    /// The underlying driver in ASIODriver.cs does not seem to need changes to
    /// support input.
    /// 
    /// 

    internal class ASIODriverExt
    {
        private ASIODriver driver;
        private ASIOCallbacks callbacks;
        private ASIODriverCapability capability;
        public ASIOBufferInfo[] BufferInfos;
        private bool isOutputReadySupport;
        private IntPtr[] CurrentOutputBuffers;
        private IntPtr[] CurrentInputBuffers;
        private int nbOutputChannels;
        private ASIOFillBufferCallback BuffersReadyCallback;
        private int bufferSize;
        private int channelOffset;

        /// 

        /// Initializes a new instance of the  class based on an already
        /// instantiated ASIODriver instance.
        /// 

        /// A ASIODriver already instantiated.
        public ASIODriverExt(ASIODriver driver)
        {
            this.driver = driver;

            if (!driver.init(IntPtr.Zero))
            {
                throw new ApplicationException(driver.getErrorMessage());
            }

            callbacks = new ASIOCallbacks();
            callbacks.pasioMessage = AsioMessageCallBack;
            callbacks.pbufferSwitch = BufferSwitchCallBack;
            callbacks.pbufferSwitchTimeInfo = BufferSwitchTimeInfoCallBack;
            callbacks.psampleRateDidChange = SampleRateDidChangeCallBack;

            BuildCapabilities();
        }

        /// 

        /// Allows adjustment of which is the first output channel we write to
        /// 

        /// Channel offset
        public void SetChannelOffset(int channelOffset)
        {
            if (channelOffset + nbOutputChannels <= Capabilities.NbOutputChannels)
            {
                this.channelOffset = channelOffset;
            }
            else
            {
                throw new ArgumentException("Invalid channel offset");
            }
       }

        /// 

        /// Gets the driver used.
        /// 

        /// The ASIOdriver.
        public ASIODriver Driver
        {
            get { return driver; }
        }

        /// 

        /// Starts playing the buffers.
        /// 

        public void Start()
        {
            driver.start();
        }

        /// 

        /// Stops playing the buffers.
        /// 

        public void Stop()
        {
            driver.stop();
        }

        /// 

        /// Shows the control panel.
        /// 

        public void ShowControlPanel()
        {
            driver.controlPanel();
        }

        /// 

        /// Releases this instance.
        /// 

        public void ReleaseDriver()
        {
            try
            {
                driver.disposeBuffers();
            } catch (Exception ex)
            {
                Console.Out.WriteLine(ex.ToString());
            }
            driver.ReleaseComASIODriver();
        }

        /// 

        /// Determines whether the specified sample rate is supported.
        /// 

        /// The sample rate.
        /// 
        /// 	true if [is sample rate supported]; otherwise, false.
        /// 
        public bool IsSampleRateSupported(double sampleRate)
        {
            return driver.canSampleRate(sampleRate);
        }

        /// 

        /// Sets the sample rate.
        /// 

        /// The sample rate.
        public void SetSampleRate(double sampleRate)
        {
            driver.setSampleRate(sampleRate);
            // Update Capabilities
            BuildCapabilities();
        }

        /// 

        /// Gets or sets the fill buffer callback.
        /// 

        /// The fill buffer callback.
        public ASIOFillBufferCallback FillBufferCallback
        {
            get { return BuffersReadyCallback; }
            set { BuffersReadyCallback = value; }
        }

        /// 

        /// Gets the capabilities of the ASIODriver.
        /// 

        /// The capabilities.
        public ASIODriverCapability Capabilities
        {
            get { return capability; }
        }

        /// 

        /// Creates the buffers for playing.
        /// 

        /// The number of outputs channels.
        /// if set to true [use max buffer size] else use Prefered size
        public int CreateBuffers(int nbInputChannelsArg, int nbOutputChannelsArg, bool useMaxBufferSize)
        {
            if (nbOutputChannelsArg <= 0 || nbOutputChannelsArg > capability.NbOutputChannels)
            {
                throw new ArgumentException(String.Format(
                                                "Invalid number of channels {0}, must be in the range [1,{1}]",
                                                nbOutputChannelsArg, capability.NbOutputChannels));
            }

            // each channel needs a buffer info
            nbOutputChannels = nbOutputChannelsArg;
            // Ask for maximum of output channels even if we use only the nbOutputChannelsArg
            int nbTotalChannels = capability.NbInputChannels + capability.NbOutputChannels;
            BufferInfos = new ASIOBufferInfo[nbTotalChannels];
            CurrentOutputBuffers = new IntPtr[nbOutputChannelsArg];
            CurrentInputBuffers = new IntPtr[nbInputChannelsArg];
            // and do the same for output channels
            // ONLY work on output channels (just put isInput = true for InputChannel)
            int totalIndex = 0;
            for (int index = 0; index < capability.NbInputChannels; index++, totalIndex++)
            {
                BufferInfos[totalIndex].isInput = true;
                BufferInfos[totalIndex].channelNum = index;
                BufferInfos[totalIndex].pBuffer0 = IntPtr.Zero;
                BufferInfos[totalIndex].pBuffer1 = IntPtr.Zero;
            }

            for (int index = 0; index < capability.NbOutputChannels; index++, totalIndex++)
            {
                BufferInfos[totalIndex].isInput = false;
                BufferInfos[totalIndex].channelNum = index;
                BufferInfos[totalIndex].pBuffer0 = IntPtr.Zero;
                BufferInfos[totalIndex].pBuffer1 = IntPtr.Zero;
            }

            if (useMaxBufferSize)
            {
                // use the drivers maximum buffer size
                bufferSize = capability.BufferMaxSize;
            }
            else
            {
                // use the drivers preferred buffer size
                bufferSize = capability.BufferPreferredSize;
            }

            unsafe
            {
                fixed (ASIOBufferInfo* infos = &BufferInfos[0])
                {
                    IntPtr pOutputBufferInfos = new IntPtr(infos);

                    // Create the ASIO Buffers with the callbacks

                    driver.createBuffers(pOutputBufferInfos, nbTotalChannels, bufferSize, ref callbacks);
                }
            }

            // Check if outputReady is supported
            isOutputReadySupport = (driver.outputReady() == ASIOError.ASE_OK);
            
            return bufferSize;
        }

        /// 

        /// Builds the capabilities internally.
        /// 

        private void BuildCapabilities()
        {
            capability = new ASIODriverCapability();

            capability.DriverName = driver.getDriverName();

            // Get nb Input/Output channels
            driver.getChannels(out capability.NbInputChannels, out capability.NbOutputChannels);

            capability.InputChannelInfos = new ASIOChannelInfo[capability.NbInputChannels];
            capability.OutputChannelInfos = new ASIOChannelInfo[capability.NbOutputChannels];

            // Get ChannelInfo for Inputs
            for (int i = 0; i < capability.NbInputChannels; i++)
            {
                capability.InputChannelInfos[i] = driver.getChannelInfo(i, true);
            }

            // Get ChannelInfo for Output
            for (int i = 0; i < capability.NbOutputChannels; i++)
            {
                capability.OutputChannelInfos[i] = driver.getChannelInfo(i, false);
            }

            // Get the current SampleRate
            capability.SampleRate = driver.getSampleRate();


            // Get Latencies
            driver.getLatencies(out capability.InputLatency, out capability.OutputLatency);

            // Get BufferSize
            driver.getBufferSize(out capability.BufferMinSize, out capability.BufferMaxSize, out capability.BufferPreferredSize, out capability.BufferGranularity);
        }

        /// 

        /// Callback called by the ASIODriver on fill buffer demand. Redirect call to external callback.
        /// 

        /// Index of the double buffer.
        /// if set to true [direct process].
        private void BufferSwitchCallBack(int doubleBufferIndex, bool directProcess)
        {

            for (int i = 0; i < capability.NbInputChannels; i++)
            {
                CurrentInputBuffers[i] = BufferInfos[i + channelOffset].Buffer(doubleBufferIndex);
            }

            for (int i = 0; i < nbOutputChannels; i++)
            {
                CurrentOutputBuffers[i] = BufferInfos[i + channelOffset + capability.NbInputChannels].Buffer(doubleBufferIndex);
            }

            if (BuffersReadyCallback != null)

                BuffersReadyCallback(CurrentInputBuffers, CurrentOutputBuffers);

            if (isOutputReadySupport)
                driver.outputReady();            
        }

        /// 

        /// Callback called by the ASIODriver on event "Samples rate changed".
        /// 

        /// The sample rate.
        private void SampleRateDidChangeCallBack(double sRate)
        {
            // Check when this is called?
            capability.SampleRate = sRate;
        }

        /// 

        /// Asio message call back.
        /// 

        /// The selector.
        /// The value.
        /// The message.
        /// The opt.
        /// 
        private int AsioMessageCallBack(ASIOMessageSelector selector, int value, IntPtr message, IntPtr opt)
        {
            // Check when this is called?
            switch (selector)
            {
                case ASIOMessageSelector.kAsioSelectorSupported:
                    ASIOMessageSelector subValue = (ASIOMessageSelector)Enum.ToObject(typeof(ASIOMessageSelector), value);
                    switch (subValue)
                    {
                        case ASIOMessageSelector.kAsioEngineVersion:
                            return 1;
                        case ASIOMessageSelector.kAsioResetRequest:
                            return 0;
                        case ASIOMessageSelector.kAsioBufferSizeChange:
                            return 0;
                        case ASIOMessageSelector.kAsioResyncRequest:
                            return 0;
                        case ASIOMessageSelector.kAsioLatenciesChanged:
                            return 0;
                        case ASIOMessageSelector.kAsioSupportsTimeInfo:
//                            return 1; DON'T SUPPORT FOR NOW. NEED MORE TESTING.
                            return 0;
                        case ASIOMessageSelector.kAsioSupportsTimeCode:
//                            return 1; DON'T SUPPORT FOR NOW. NEED MORE TESTING.
                            return 0;
                    }
                    break;
                case ASIOMessageSelector.kAsioEngineVersion:
                    return 2;
                case ASIOMessageSelector.kAsioResetRequest:
                    return 1;
                case ASIOMessageSelector.kAsioBufferSizeChange:
                    return 0;
                case ASIOMessageSelector.kAsioResyncRequest:
                    return 0;
                case ASIOMessageSelector.kAsioLatenciesChanged:
                    return 0;
                case ASIOMessageSelector.kAsioSupportsTimeInfo:
                    return 0;
                case ASIOMessageSelector.kAsioSupportsTimeCode:
                    return 0;
            }
            return 0;            
        }

        /// 

        /// Buffers switch time info call back.
        /// 

        /// The asio time param.
        /// Index of the double buffer.
        /// if set to true [direct process].
        /// 
        private IntPtr BufferSwitchTimeInfoCallBack(IntPtr asioTimeParam, int doubleBufferIndex, bool directProcess)
        {
            // Check when this is called?
            return IntPtr.Zero;   
        }
    }
}

 

 

New Post: Play and Record simultaneously problem

$
0
0

Hi all,
I'm not an audio programming expert, but I'm trying to write a C# project using NAudio since some days.

My needs are just to play a sound and to record another sound. Simultaneously. But I met some problems.

Pressing a button application plays my simple mono-frequency sound by a WaveOut using a WaveProvider.

Then I press another button to start recording (using a WaveIn instance)... but here my problems start, because trying to record, audio playback stops.

These are some other tries I made:

1. If I put play/record code inside two classes (separated from main gui class) and try to work using a new thread for each button click (one for play and one for record), then recording doesn't start (breakpoint inside WaveIn.DataAvailable is never reached).

2. If I put play code inside a new thread, but I left recording code inside main gui class, then gui freezes (the only way to stop that is to define an upper limit to the number of buffer readings... but I wouldn't to my gui freezes for a while).

Do you have any idea to help me?
There is something I'm ignoring?
What's the best way to proceed to achieve my goal?

Any suggestion'll be really appreciated.

Thanks

New Post: ASIO input

$
0
0

Thanks for the update Hfuy! You're right there's not too much added here, I will try your changes in my code and see if I can't get the ASIO input working.

 

Cheers!

Mark

New Post: ASIO input

$
0
0

Hi Hfuy,

  Thank you for the update, how to implement this function BuffersReadyCallback(CurrentInputBuffers, CurrentOutputBuffers). It would be really helpful if you post the all the dependent function implementations. How to give a specific Input channel number for recording , I am not clear with this things any ideas would be helpful.

 

Thanks in advance

New Post: ASIO input

$
0
0

Sorry about the formatting in this, this forum software is an absolute nightmare!

Anyway, there are a couple of stages to this.

First, enumerate the available ASIO devices:

string[] names = ASIODriver.GetASIODriverNames();
foreach(string name in names){
	ASIODriver d = ASIODriver.GetASIODriverByName(name);
	// Make visible names of ASIO drivers and figure out which one you want
}

 

Pick the one you want (assuming you want the first listed):

int WhichAsioDevice = 0;

ASIODriver drv = ASIODriver.GetASIODriverByName(ASIODriver.GetASIODriverNames()[WhichAsioDevice]);

 

Get an ASIODriverExt instance for it:

 

ASIODriverExt drvx = new ASIODriverExt(drv);

 



Set up and start:

 

ASIOFillBufferCallback cbk = new ASIOFillBufferCallback(BufFeeder); // See below

drvx.FillBufferCallback = cbk;

drvx.CreateBuffers(drvx.Capabilities.NbInputChannels, drvx.Capabilities.NbOutputChannels, false);
drvx.Start();


Here's the buffer feeder (and, now, reader) callback:

 

private static void BufFeeder(IntPtr[] InputBufferChannels, IntPtr[] OutputBufferChannels)
	int InputChannel = 3; // This happens to be the back panel line input on my PC
	unsafe
	 {
		Int32* InBuf = (Int32*)InputBufferChannels[InputChannel];
		// Do something with 512 bytes of *InBuf
	}
}

 

That should be enough to get you going!


HF

Viewing all 5831 articles
Browse latest View live


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