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

New Post: How to create waveform of full audio

$
0
0
MediaFoundationReader is an ISampleProvider so you can just pass it into a method like GetWaveForm as shown above

New Post: Detect Microphone in use by other application

$
0
0
Wow what a nice library. I get a list of all of the DataFlow.Capture devices. During a 6 second while loop, i record the highest MasterPeakValue for each microphone. if any of them are greater than X, i will assume that they are transcribing and mimic a mouse move to reset the clock on the screen saver.

New Post: High polyphony

$
0
0
Hi there,
is there a way to make Naudio able to play/loop up to ~8000 sample streams simultaneously or is c# just too slow?
I need this to create a virtual pipe organ and would like to stick to open-source content. This excludes libraries like BASS.

New Post: How to input more the one audio files to play it simultaneously for real time analysis with NAudio

$
0
0
Hello, the first I'm working with NAudio, so need your help

Same way as I got here real-time from default audio source, how can I get two audio wav or mp3 files, in this case must be direct inputs I guess, to play it both simultaneously with real-time value, same way as it shown below, but at the same time, to get current peaks value from each. What and how I have to use for this goal in my C# Windows Form Application. I was looking for in the sources here, but I found nothing, some examples does not works for me, seems need some setups, so to check everything, better get practical and direct advice

using NAudio.CoreAudioApi;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace XX_9_REAL_TIME_AUDIO
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            MMDeviceEnumerator enumerator = new MMDeviceEnumerator();
            var devices = enumerator.EnumerateAudioEndPoints(DataFlow.All, DeviceState.Active);
            comboBox1.Items.AddRange(devices.ToArray());
        }

        private void timer_Tick(object sender, EventArgs e)
        {
            if (comboBox1.SelectedItem != null)
            {
                var device = (MMDevice)comboBox1.SelectedItem;
                progressBar1.Value = (int) (Math.Round(device.AudioMeterInformation.MasterPeakValue * 100 + 0.5));


            }
        }
    }
}
Here I got wav file, but have no idea how to get real time value for analysis and how to play another one at the same time:

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

namespace NAudioTest
{
    class Program
    {
        static IWavePlayer waveout;
        static WaveStream outputStream;
        static string filename = null;

        static void Main(string[] args)
        {
            waveout = new WaveOutEvent();

            filename ="C:\\folder\\track.wav";

            outputStream = CreateInputStream(filename);

            try
            {
                waveout.Init(outputStream);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error while loading output");
                Console.WriteLine("Details: " + ex.Message);
                Console.ReadLine();
                return;
            }

            Console.WriteLine("Press [Enter] to start playback");
            Console.ReadLine();

            waveout.Play(); //this stops after 1 sec. should it play until i hit enter cause of the next line?

            Console.WriteLine("Press [Enter] to abort");
            Console.ReadLine();
            waveout.Dispose();
            Console.ReadLine();
        }


        static WaveStream CreateInputStream(string name)
        {
            WaveChannel32 inputStream;
            if (name.EndsWith(".wav"))
            {
                WaveStream readerStream = new WaveFileReader(name);
                if (readerStream.WaveFormat.Encoding != WaveFormatEncoding.Pcm)
                {
                    readerStream = WaveFormatConversionStream.CreatePcmStream(readerStream);
                    readerStream = new BlockAlignReductionStream(readerStream);
                }

                if (readerStream.WaveFormat.BitsPerSample != 16)
                {
                    var format = new WaveFormat(readerStream.WaveFormat.SampleRate, 16, readerStream.WaveFormat.Channels);
                    readerStream = new WaveFormatConversionStream(format, readerStream);
                }
                inputStream = new WaveChannel32(readerStream);
            }
            else
            {
                throw new InvalidOperationException("Invalid extension");
            }
            return inputStream;
        }
    }
}

New Post: How to input more the one audio files to play it simultaneously for real time analysis with NAudio

$
0
0
"Console.ReadLine" doesn´t block execution, so you almost instantly dispose the WaveOutEvent instance.

To analyze the samples simply extent "outputStream.ToSampleProvider" and pass it withevents to a "NotifyingSampleProvider". Then Init and play the NotifyingSampleProvider. NotifyingSampleProvider will then raise an event on each sample (pair).

New Post: How to input more the one audio files to play it simultaneously for real time analysis with NAudio

$
0
0
Hello, thank you for your feedback, as I've said I'm new, and it would be very helpful, if you can show me with given example how to do it following your instructions just for two file inputs real time for example, because I have tried as you said, but seems I'm doing something wrong.

New Post: Play several audios simultaneously with real-time analysis

$
0
0
Hello. In which direction I must go, if need two thing at the same time, play two (or several) audio files simultaneously and at the same time get Real-Time Analysis of both with actual Peak and RMS size value on display.

New Post: InteropServices.COMException 0x88890001 when trying to accessAudioCaptureClient, BufferSize etc

$
0
0
Hi.
I tried this with several audio devices, both capture and render and the result is the same for all of them:

Image

There are several properties of a device's AudioClient property I can't access - it just keeps throwing a System.Runtime.InteropServices.COMException ("Exception of HRESULT: 0x88890001")

I didn't even do anything advanced:
Dim devEnum As New NAudio.CoreAudioApi.MMDeviceEnumerator()
Dim deviceList As NAudio.CoreAudioApi.MMDeviceCollection = devEnum.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.Capture, NAudio.CoreAudioApi.DeviceState.Active)
Dim dev As NAudio.CoreAudioApi.MMDevice = devEnum.GetDevice(deviceList(0).ID)
All my audio devices are being listed by MMDeviceEnumerator and the MixingFormat property is recognized correctly.. Did I do anything wrong or is it a bug?

Operating System: Win7 Ultimate x64
Audio interfaces: Zoom G3X, Creative Sound Blaster X-Fi Xtreme Audio, ASUS Xonar D2
IDE: Visual Basic 2010 Express (.NET 4.0)
NAudio version: 1.7.3.0

New Post: PCM streaming with WASAPI

$
0
0
Does anyone have any guidance on this issue? I can't seem to get WasapiOutRT to take advantage of the BufferedWaveProvider.

New Post: Change Folder in which AudioFileReader plays files

$
0
0
Howdy,

How do I change the folder in which AudioFileReader plays a file from. Currently, I must place the file I want to play in the path: "C:\Users\VoodooSixTwo\Desktop\TestProject\bin\Debug". This works perfectly, however, I want to instead play a file from a folder in the bin folder (i.e. "C:\Users\VoodooSixTwo\Desktop\TestProject\bin\Debug\Sounds".

Is AudioFileReader hard coded to play files from the bin\Debug folder?

I am using the FireandForgetEngine and calling the action:
   FireAndForgetAudioSample.AudioPlaybackEngine.Instance.PlaySound("song.mp3");
Any assistance is greatly appreciated.

New Post: Change Folder in which AudioFileReader plays files

$
0
0
This is to do with the Working Directory that your application is running in, which by default will be bin\Debug. So you can just say "\Sounds\song.mp3" to get at files in a relative folder, or pass the full path into PlaySound.

New Post: PCM streaming with WASAPI

$
0
0
You seem to be trying to use a very low sample rate. WASAPI typically requires either 44.1kHz or 48kHz and IEEE float samples, so it's a little surprising that you get past Init successfully.

Playback will stop when BufferedWaveProvider returns 0 from Read, which shouldn't happen with a BufferedWaveProvider. So I would subscribe to the PlaybackStopped event of the WasapiOutRT and check the Exception property to see if there is a problem that is causing it to stop.

New Post: Play several audios simultaneously with real-time analysis

$
0
0
What you need to do is first of all use AudioFileReaders for each of the files, and then pass them into a MixingSampleProvider. Then, you would need to pass the MixingSampleProvider into a custom ISampleProvider whose Read method reads from the source, and performs any real-time analysis of the samples. You can see some basic examples of this in the NAudio demo projects.

New Post: InteropServices.COMException 0x88890001 when trying to accessAudioCaptureClient, BufferSize etc

$
0
0
That error code is AUDCLNT_E_NOT_INITIALIZED, which means that until you call Initialize on the AudioClient, you can't access all its properties.

New Post: Change Folder in which AudioFileReader plays files

$
0
0
Thanks,

After looking closely, the \ should be /. The following works perfectly.
 FireAndForgetAudioSample.AudioPlaybackEngine.Instance.PlaySound("/Sounds/song.mp3");
Great software you have assembled here.

New Post: How to stop a audio file from playing in FireAndForgetAudioSample?

$
0
0
I currently use the following to play a sound file:
FireAndForgetAudioSample.AudioPlaybackEngine.Instance.PlaySound("Sounds/sound.mp3");
This file is very long and I want to stop playing the file mid-way. How do I accomplish this?

Furthermore, Can I play other sound files after the "sound.mp3" file has been stopped?

Assistance is appreciated.

New Post: How to stop a audio file from playing in FireAndForgetAudioSample?

$
0
0
Well the whole point of fire and forget is that you "forget" about the file once you've started playing it. If you want to remember it, and control it, then create your own MixingSampleProvider and add and remove inputs as needed.

And yes, you can play other files after one has stopped, so long as your mixer is set up to always produce sound (i.e. silence) even when no inputs are connected

Commented Unassigned: COM Exception & UnRegisterEventClient [16499]

$
0
0
I'm receiving a COM error after my app exits if I call UnRegisterEventClient.

Here is a code snippet:
private Dictionary<uint, SessionsEventCallbacks.NAudioEventCallbacks> _sessionNotifications = new Dictionary<uint, SessionsEvents.NAudioEventCallbacks>();
// NAudioEventCallbacks inherits from IAudioSessionEventsHandler
...
private void OnSessionCreated(object sender, IAudioSessionControl newSession)
{
AudioSessionControl audioSession = new AudioSessionControl(newSession);
SessionsEvents.NAudioEventCallbacks notifications = new SessionsEventCallbacks.NAudioEventCallbacks();
notifications.contentCat = 0;
notifications.programType = 0;
notifications.processId = (int)audioSession.GetProcessID;
notifications.processName = Process.GetProcessById((int)audioSession.GetProcessID).ProcessName;
notifications.domain = string.Empty;
notifications.youtubeCategory = string.Empty;
notifications.audioSession = audioSession;
notifications.SessionEndedCallback = AudioStopped;

_sessionNotifications.Add((uint)notifications.processId, notifications);
audioSession.RegisterEventClient(notifications);
}

I call UnRegisterEventClient from AudioStopped.

Any help would be greatly appreciated!

Thanks,
Randall Deetz
Comments: thanks for reporting this issue and workaround. if you have a proposed fix for the library feel free to submit a PR at github

New Post: Speed and pitch (?)

New Post: High polyphony

$
0
0
C# is quite fast although is not going to be as fast as an audio engine written in optimized C++. The main issues here are how much work is required to generate the audio for the 8000 streams - is it pre-calculated or calcuated on the fly? Also, do you need low latency? Low latency can be a challenge due to garbage collection causing glitches in the audio.

I recommend you try and see, by mixing together a bunch of sounds (say using SignalGenerator class) and mixing them with MixingSampleProvider. You'll soon get an idea of what's possible on your hardware. Just be careful of your ears when making loud noises.
Viewing all 5831 articles
Browse latest View live


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