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

New Post: Can't make spectrum to work - VB 2010

$
0
0

Ok, the issue was solved but now I want to create the wave..

I read that I need to read until the end but didn't understand. I check the codes, even the WPF one, but still. I'm working with VB 2010 and maybe I can't understand exactly

mp3Reader = New Mp3FileReader(archivo)
waveChannel = New SampleChannel(mp3Reader, True)

Dim frame As Mp3Frame
Dim x As Integer = 1

While x < 50 ' just 50 for test
     frame = mp3Reader.ReadNextFrame()

     WaveformPainter1.AddMax( ???? )

      x = x + 1
End While

New Post: WaveIn.Device not giving proper result if audio service is stopped

$
0
0

Sir You wrote:

waveIn device count just returns the number of devices that Windows reports (using the waveInGetNumDevs function).

Sir,
But how Windows showing audio device properly in audio settings dialog. why we are not able to enumerate it. is windows using any other library for it.

Sir,
if we use separate application domain only to load and unload NAudio Library and if we found that audio service is stopped then we can show an dialog to user to start audio service and according user action we can load NAidio Library in corresponding application domain [NAudio Domain ] and other domain will communicate with NAudio Domain to enumerate audio device, also capture audio from device..

is it possible..??

Thanks.

New Post: WaveOut FFT spectrum

$
0
0

I'm afraid I haven't got an example of drawing spectrum in WinForms. You'd need to do it using the Graphics object in the Paint method.

New Post: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

$
0
0

access violation relates to memory corruption. It could be something strange with the way you do threading, or a bug somewhere in NAudio (are you using the latest version?), or even a problem with your soundcard drivers. Tracking them down is hard. I usually try to create the simplest program possible that exhibits the problem.

New Post: Play(or convert to .wav) 3ga audio file.

New Post: Play(or convert to .wav) 3ga audio file.

$
0
0

You could only do this if you have an ACM codec that can decode 3ga. I have not come across one, but you might be able to find one. Having done so, you'd then need to query the codec to work out what WaveFormat it accepts as an input.

Mark

New Post: Play(or convert to .wav) 3ga audio file.

$
0
0

Hi markheath,

Can you guide me the way through some quick links or samples.

--Anudeep

New Post: Play(or convert to .wav) 3ga audio file.


New Post: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

$
0
0

I ran into the same problem. Looks like it occurs if you create and destroy waveOutEvent player continuously.
Could not trace the root cause though.
My requirement was to play a succession of wav files. Creating, initing with file provider, playing, destroying a waveplayer in a cycle seemed the obvious solution. But alas.
I ended up solving the problem in another way: creating a SwitchingWaveProvider, which wraps actual providers, which can be changed at runtime. Create a player once and init once with this provider. Keep switching providers on this front provider. Probably one of the mixing providers could have done the trick too, but could'nt find one for 16 bit format.
Here is SwitchingWaveProvider.cs code. Include if it seems useful

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using NAudio.Wave;
using NAudio.Utils;

namespace NAudio.Wave
{
    /// <summary>
    /// Facade for a real wave provider which can be switched at runtime
    /// </summary>
    public class SwitchingWaveProvider : IWaveProvider
    {
        private WaveFormat waveFormat;
        private IWaveProvider srcProvider = null;
        private object lockObj = new object();

        /// <summary>
        /// Creates a new switching WaveProvider
        /// </summary>
        /// <param name="waveFormat">WaveFormat</param>
        public SwitchingWaveProvider(WaveFormat waveFormat)
        {
            this.waveFormat = waveFormat;
        }

        /// <summary>
        /// Gets the WaveFormat
        /// </summary>
        public WaveFormat WaveFormat
        {
            get { return waveFormat; }
        }

        /// <summary>
        /// Switch input source to new provider
        /// </summary>
        public bool SwitchWaveProvider(IWaveProvider newProvider)
        {
            if ((newProvider != null) &&
                !this.waveFormat.Equals(newProvider.WaveFormat))
                return false;

            lock (lockObj)
            {
                srcProvider = newProvider;
            }
            return true;
        }

        /// <summary>
        /// Reads from source WaveProvider
        /// </summary>
        public int Read(byte[] buffer, int offset, int count) 
        {
            int readCount = 0;
            lock (lockObj)
            {
                if (srcProvider != null)
                {
                    readCount = srcProvider.Read(buffer, offset, count);
                }
            }

            if (readCount < count)
            {
                int strt = offset + readCount;
                int end = offset + count;
                for (int i = strt; i < end; i++)
                    buffer[i] = 0;
            }

            return count;
        }
    }
}

New Post: Getting device's DeviceNumber from MMDeviceCollection

$
0
0

Hi Mark, et al,

I'm having trouble getting the correct DeviceNumber when iterating devices with MMDeviceCollection.

MMDeviceCollection does not expose the device's DeviceNumber. And using the collection item's index does not establish the correct DeviceNumber (as in the code snippet below).

Any thoughts on how to get a correct device number from a MMDeviceCollection? And I want to use MMDeviceCollection rather than WaveOut.GetCapabilities(deviceId) because I can get the device full name (not truncated) and the device GUID from the MMDeviceCollection.

int deviceCount = WaveOut.DeviceCount;
                MMDeviceEnumerator DevEnum = new MMDeviceEnumerator();
                MMDeviceCollection devEnum = DevEnum.EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active);

                string[] devName = new string[deviceCount];

                int[] deviceNumber = new int[deviceCount];
                int j = 0;
                foreach (var item in devEnum)
                {
                    devName[j] = item.FriendlyName;
                    deviceNumber[j] = j;
                    j++;
                }

                WaveOut outputDeviceWaveOut = new WaveOut();
                outputDeviceWaveOut.DeviceNumber = deviceNumber[2];

New Post: Network Chat Multi-Client Program

$
0
0

Hello,

I've been working on expanding the Network Chat demo to allow multiple clients to connect to the host computer and voice chat. Seeing that I need to keep track of the clients and the audio data sent over, I created a Client struct that keeps track of who the client is and their BufferedWaveProvider object data.

For the host, I add their BufferedWaveProvider object to a MixingSampleProvider, which then I used that to create a IWaveProvider object. Finally, I used the IWaveProvider for my WaveOut object and use that to play audio.

For my Recieve method that I'm using to obtain audio data, I check to see whether or not the data came from the host or another client. If it's from the host, I just add the data to the host's BufferedWaveProvider object. Otherwise, I need to check to see if the client is connecting to the host IP for the first time. If it is, I create a new Client object with it's own BufferedWaveProvider object and add it to my MixingSampleProvider. Finally, I pull the correct Client object based on its IP address, add the data to its BufferedWaveProvider, and then update the BufferedWaveProvider so that it has the added sample data.

When I applied this logic to actual code and tested it, the audio from the host's mic works correctly. When a client connects to the host's IP from another computer, the audio gets choppy. I can hear what's being said from the client, but it's delayed by a few seconds.

Perhaps my logic isn't correct when trying to receive and play what's been sent over by clients. What could be causing the choppy audio?

Thanks

New Post: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

$
0
0

One thing to try is making sure you don't Dispose WaveOutEvent until after the PlaybackStopped event has been fired. Otherwise the background thread could be making calls into the driver at the same time as it is being closed.

New Post: Getting device's DeviceNumber from MMDeviceCollection

$
0
0

WaveOut and MMDeviceEnumerator use completely different audio APIs. I wouldn't expect the device numbers to match at all.

Mark

New Post: Getting device's DeviceNumber from MMDeviceCollection

$
0
0

Ok, thanks Mark.
It looks like the only api to associate a device name to the DeviceNumber is the WaveOut.GetCapabilities(deviceId). As you have been telling me. :-)

I looked thru the WAVEOUTCAPS structure. Microsoft doesn't give you much to work with there.

I'll have to cross my fingers that the first 32 chars of the device name are unique for all sound cards -- although that gets iffy when the user has multiple, identical usb soundcard adapters.

New Post: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

$
0
0

Yes, that would certainly spoil your day.
I ran into a couple of more issues: media not playing after a few Play/Stop cycles, garbled output sometimes. The core issue seems to be that we don't wait for play thread to exit at Stop. That results in multiple play threads at times if you do Play/Start very fast. And also the issue that you mentioned. I fixed it by a ManualResetEvent which tracks if play thread is off or not. Below is the waveOutEvent changes I ended up with. It also includes setting callbackEvent when creating a new play thread. This fixed no media problem:

private ManualResetEvent playThreadOff; // <----- declare this class var

this.playThreadOff = new ManualResetEvent(true); // <------ init in contructor

public void Play()
        {
            if (playbackState == PlaybackState.Stopped)
            {
                callbackEvent.Set();      // <---- Kick thread
                playThreadOff.WaitOne(); // <---------wait for previous thread, if any to end
                playThreadOff.Reset(); // <-------- Play thread is now on
                playbackState = PlaybackState.Playing;
                callBackEvent.Set(); // <------- set again if it was reset by any previous thread
                ThreadPool.QueueUserWorkItem((state) => PlaybackThread(), null);
            }
            else if (playbackState == PlaybackState.Paused)
            {
                Resume();
                callbackEvent.Set(); // give the thread a kick
            }
        }

private void PlaybackThread()
        {
            Exception exception = null;
            try
            {
                DoPlayback();
            }
            catch (Exception e)
            {
                exception = e;
            }
            finally
            {
                playbackState = PlaybackState.Stopped;
                playThreadOff.Set(); <----------- Thread going off
                // we're exiting our background thread
                RaisePlaybackStoppedEvent(exception);
            }
        }

public void Stop()
        {
            if (playbackState != PlaybackState.Stopped)
            {
                // in the call to waveOutReset with function callbacks
                // some drivers will block here until OnDone is called
                // for every buffer
                playbackState = PlaybackState.Stopped; // set this here to avoid a problem with some drivers whereby 
                MmResult result;
                lock (waveOutLock)
                {
                    result = WaveInterop.waveOutReset(hWaveOut);
                }
                if (result != MmResult.NoError)
                {
                    throw new MmException(result, "waveOutReset");
                }
                callbackEvent.Set(); // give the thread a kick, make sure we exit
                playThreadOff.WaitOne(); // <---------------------wait for play thread to exit
            }
        }

New Post: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

$
0
0

markheath wrote:

access violation relates to memory corruption. It could be something strange with the way you do threading, or a bug somewhere in NAudio (are you using the latest version?), or even a problem with your soundcard drivers. Tracking them down is hard. I usually try to create the simplest program possible that exhibits the problem.

Thanks sir,

Yes i am using latest NAudio.
i'll create simplest program to play audio file and i'll update you if i got same exception..

New Post: network streaming

New Post: network streaming

$
0
0

NAudio and Practise Sharp are both open source projects. Click "Source Code" above to get the NAudio. To get practise sharp source code, go to its home page, and you can download the latest source from there.

New Post: WaveOut FFT spectrum

$
0
0

:( Too bad. I have no clue how to start... I thought that you would have an exmple for winforms as you provide the dsp class. Would be fantastic if you would show the usage with an winforms example!

New Post: Which version of NAudio should I use to introduce the "effects and effectstream" code used for the Skype Voice changer

$
0
0

ok.....something doesn't make sense. Does NAudio 1.6 have an effects engine? How would you integrate a single bass/treble equalizer effect? Is it all based on the ISampleProvider framework?

Paul

Viewing all 5831 articles
Browse latest View live


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