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

New Post: Change Default Audio Device?

$
0
0
yeah there is a way of opening it, you don't need NAudio to do it though.
Process.Start("control.exe", "mmsys.cpl,,1")
A bit ugly, but gets the job done

New Post: Can NAudio do real-time pitch?

$
0
0
there's no pitch shifter effect in NAudio I'm afraid. I tend to port one. Have a look in the source code for SuperPitch.cs in my skypefx project for an example. Or you could create a wrapper around SoundTouch

New Post: WaveFileWriter save as pcm

$
0
0
hi..
i am recording from my sound device.
iam using the WaveFileWriter to record the incoming data to a wav file.
it should be saved as pcm format
now i am doing the following
WaveFileWriter writer;
this.writer = new WaveFileWriter(this.outputFilePath, this.waveIn.WaveFormat);
this.bufferedWaveProvider = new BufferedWaveProvider(this.waveIn.WaveFormat);
// should be enough to buffer 1 minute in front
this.bufferedWaveProvider.BufferDuration = new TimeSpan(0, 1, 0);
this.bufferedWaveProvider.DiscardOnBufferOverflow = true;
this.waveIn.ShareMode = WaveInShareMode;
this.waveIn.StartRecording();
...
private void OnDataAvailable(object sender, WaveInEventArgs e)
        {
            try
            {
                if (saveToFile)
                {
                    this.writer.Write(e.Buffer, 0, e.BytesRecorded);
                }
            }

            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex.InnerException);
            }
        }
whereas the waveIn.WaveFormat looks like this:

this.waveIn.WaveFormat = {32 bit PCM: 48kHz 2 channels wBitsPerSample:32 dwChannelMask:3 subFormat:00000003-0000-0010-8000-00aa00389b71 extraSize:22}
AverageBytesPerSecond = 384000
BitsPerSample = 32
BlockAlign = 8
Channels = 2
Encoding = Extensible
ExtraSize = 22
SampleRate = 48000

now when i try to play the recorded wav file on my playback sound device, which has the following properties

MixFormat = {32 bit PCM: 48kHz 2 channels wBitsPerSample:32 dwChannelMask:3 subFormat:00000003-0000-0010-8000-00aa00389b71 extraSize:22}

i tried using the AudioFileReader but it gives an exception no driver calling acmformatsuggest

and if i try the MediaFoundationReader i get
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in NAudio.dll

Additional information: Exception from HRESULT: 0xC00D5212
at NAudio.MediaFoundation.IMFSourceReader.SetCurrentMediaType(Int32 dwStreamIndex, IntPtr pdwReserved, IMFMediaType pMediaType)
at NAudio.Wave.MediaFoundationReader.CreateReader(MediaFoundationReaderSettings settings)

and the wave file i recorded has the following properties:
Stereo, 48kHz 32-bit float
Can be downloaded here

if i use audacity to change the float to pcm, then it works.

so my question is
can i tell the writer to write directly to a pcm format?

iam setting the writer waveformat as you can see above, but still it is not working probably.

Any help is really appreciated

thanks in advance

Created Unassigned: media foundation dsp support [16467]

$
0
0
does currently naudio have interop/wrapper on Voice Capture DSP for Window Media Foundation,

https://msdn.microsoft.com/en-us/library/windows/desktop/ff819492(v=vs.85).aspx

New Post: Can NAudio do real-time pitch?

$
0
0
Thanks, but it is too complicated. Please, can you say me what part of code belongs of Pitch Adjust (cents)?

Commented Unassigned: media foundation dsp support [16467]

$
0
0
does currently naudio have interop/wrapper on Voice Capture DSP for Window Media Foundation,

https://msdn.microsoft.com/en-us/library/windows/desktop/ff819492(v=vs.85).aspx
Comments: sadly not but a wrapper would be a nice addition. Shame its only exposed as a DMO rather than an MFT, which may limit the platforms it can be used on

New Post: Can NAudio do real-time pitch?

$
0
0
there are sliders that control each of the parameters. Hopefully one day I'll find time to package this into an easier to use class

New Post: WaveFileWriter save as pcm

$
0
0
WASAPI uses the WAVEFORMATEXTENSIBLE wave format structure, which is not typically used in a WAV file. Instead, I would suggest creating a regular PCM / IEEE float wave format with WaveFormat.CreateIEEEWaveFormat() for example. There is a "ToStandardWaveFormat" method on the WaveFormatExtensible class in NAudio that will perform this conversion for you.

I should probably try to fix the AudioFileReader though for the future, as it doesn't actually need to do any conversion if it gets one of these files.

New Post: NAudio.MmException (Mp3FileReader)

$
0
0
Great, glad you found the solution. You also probably could have used MediaFoundationReader as well.

New Post: Master Volume Handling Example

$
0
0
Hi,

Thanks to you all and Mark for publishing and contributing to this great project.
I'm evaluating if I can use NAudio in one of my projects.
I mostly need to handle master volume changes.
Unfortunately I could not find any example doing such basic things.
So I modified the existing "Audio File Playback" demo and added a master volume slider to it.

Here is the patch.
I also added support for that editorconfig thing.

Is there a way to get notified when the default device changes?
Mark, how do you usually handle contributions such as this?

Cheers,
S.

New Post: Master Volume Handling Example

New Post: Master Volume Handling Example

New Post: ASIO Channel Broadcast Streaming

$
0
0
Hi friends,

My Sound Device: Focusrite Scarlett 18i20 (18 inputs 20 outputs)
I have a socket connection. This connection send to voice data on Broadcast.

I use to NAudio.dll and ASIO Driver. I connect my device and recorded wav sound file(ASIO) but i can't send asio live sound(Sample) on Socket.

//Declare
private Socket socket;
private IPEndPoint iep;

//My Socket Connection Config
socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 1);
iep = new IPEndPoint(IPAddress.Parse(host), port);

My Voice Stream Listener Program Decode(1 Channel(Mono) PCM 16Bit 8000 or 44100 SampleRate) c# and android platform code...

I need "GetAsInterleavedSamples" data convert to (PCM 16Bit 8000or41000 SampleRate Mono) data byte[] and send socket...

private void AsioAudioAvailable(object sender, AsioAudioAvailableEventArgs e)
{
socket.sendTo(byte[] buffer, EndPoint remoteEP); 
}

New Post: WaveFileWriter save as pcm

$
0
0
Mark, thank you sooo much... that did the trick...
i think this auto convserion is not requiered as long as you provide the format you want to read/write your file with.

p.s.: just for anyone having the same problem, the function mark meant is CreateIeeeFloatWaveFormat();

New Post: Looping audio to Skype using WasapiLoopbackCapture and Skype4com gives Whitenoise

$
0
0
Hello! I read the article posted on Coding4Fun where someone created a Skype-voicechanger and had an idea to loop my audio through skype, since I and my friends always have to put our microphones near headphones to make them hear funny songs etc that we share.. Anyway..

I thought that the best method would be to use the WasapiLoopbackCapture and write the buffer to a networkstream (like the article sort of did), but when I'm in a call and call start recording and change the output-device to a port. All my friends can hear is really loud whitenoise which doesn't seem to have any correlation to the audio I'm hearing in my headphones (ie the noise doesn't stop when I mute my volume etc).

What is it that I'm doing wrong here? Is there some kind of conversion in bitrates I have to do? I'm really new to audio and DSP so I'm not sure what to do.

Here is the class I created. I call loopSystemAudio to start recording and initializing the network sockets.

class Interceptor
{
    #region fields
    public TCallStatus currentCallStatus = TCallStatus.clsUnknown;
    public delegate void OnStatusChanged(object sender, TCallStatus oldStatus, TCallStatus newStatus);
    public event OnStatusChanged OnCallStatusChanged;

    public NAudio.Wave.WasapiLoopbackCapture capture;
    #endregion

    private const int micInPort = 667;
    private const int micOutPort = 668;
    private const int Protocol = 8;
    private Skype skype;
    private Call currentCall;


    NAudio.CoreAudioApi.MMDevice device;

    private NetworkStream outputDeviceStream;
    TcpServer outputDeviceServer;

    #region Public Methods
    public void loopSystemAudio()
    {


        outputDeviceServer = new TcpServer(micOutPort);
        outputDeviceServer.Connect += outputDeviceServer_Connect;
        outputDeviceServer.Disconnect += outputDeviceServer_Disconnect;
        outputDeviceServer.DataReceived += outputDeviceServer_DataReceived;

        capture.StartRecording();

        currentCall.InputDevice[TCallIoDeviceType.callIoDeviceTypePort] = micOutPort.ToString();
        currentCall.set_InputDevice(TCallIoDeviceType.callIoDeviceTypePort, micOutPort.ToString());
    }

    public void loopSkypeAudio(bool includeUserMic)
    {

    }

    #endregion


    #region Constructors
    public Interceptor()
    {
        skype = new Skype();
        skype.Attach(Protocol, false);
        _ISkypeEvents_Event events = (_ISkypeEvents_Event)skype;
        events.AttachmentStatus += events_AttachmentStatus;
        skype.CallStatus += skype_CallStatus;


        device = NAudio.Wave.WasapiLoopbackCapture.GetDefaultLoopbackCaptureDevice();
        capture = new WasapiLoopbackCapture(device);
        capture.ShareMode = NAudio.CoreAudioApi.AudioClientShareMode.Shared;
        capture.DataAvailable += capture_DataAvailable;
        capture.RecordingStopped += capture_RecordingStopped;
    }
    #endregion

    #region Private Methods
    void capture_RecordingStopped(object sender, StoppedEventArgs e)
    {
        Debug.WriteLine("Recording Stopped");
    }

    void capture_DataAvailable(object sender, WaveInEventArgs e)
    {
        outputDeviceStream.Write(e.Buffer, 0, e.BytesRecorded);
    }

    void outputDeviceServer_DataReceived(object sender, DataReceivedEventArgs e)
    {
        Debug.WriteLine(e.Buffer.Length.ToString());
    }

    void outputDeviceServer_Disconnect(object sender, EventArgs e)
    {
        Debug.WriteLine("OutputDeviceServer Disconnected");
    }

    void outputDeviceServer_Connect(object sender, ConnectedEventArgs e)
    {
        Debug.WriteLine("OutputDeviceServer Connected");
        outputDeviceStream = e.Stream;


    }
    void skype_CallStatus(Call pCall, TCallStatus Status)
    {
        currentCall = pCall;
    }

    void events_AttachmentStatus(TAttachmentStatus Status)
    {
        //throw new NotImplementedException();
    }
    #endregion
}
class SkypeBufferStream : WaveStream
{
    byte[] latestInBuffer;
    WaveFormat waveFormat;

    public SkypeBufferStream(int sampleRate)
    {
        waveFormat = new WaveFormat(sampleRate, 16, 2);
    }

    public override WaveFormat WaveFormat
    {
        get { return waveFormat; }
    }

    public override long Length
    {
        get { return 0; }
    }

    public override long Position
    {
        get
        {
            return 0;
        }
        set
        {
            throw new NotImplementedException();
        }
    }

    public void SetLatestInBuffer(byte[] buffer)
    {
        latestInBuffer = buffer;
    }

    public override int Read(byte[] buffer, int offset, int count)
    {
        if (offset != 0)
            throw new ArgumentOutOfRangeException("offset");
        if (buffer != latestInBuffer)
            Array.Copy(latestInBuffer, buffer, count);
        return count;
    }
}
class TcpServer : IDisposable
{
    TcpListener listener;
    public event EventHandler<ConnectedEventArgs> Connect;
    public event EventHandler Disconnect;
    public event EventHandler<DataReceivedEventArgs> DataReceived;

    public TcpServer(int port)
    {
        listener = new TcpListener(IPAddress.Loopback, port);
        listener.Start();
        ThreadPool.QueueUserWorkItem(Listen);
    }

    private void Listen(object state)
    {
        while (true)
        {
            using (TcpClient client = listener.AcceptTcpClient())
            {
                AcceptClient(client);
            }
        }
    }

    private void AcceptClient(TcpClient client)
    {
        using (NetworkStream inStream = client.GetStream())
        {
            OnConnect(inStream);
            while (client.Connected)
            {
                int available = client.Available;
                if (available > 0)
                {
                    byte[] buffer = new byte[available];
                    int read = inStream.Read(buffer, 0, available);
                    Debug.Assert(read == available);
                    OnDataReceived(buffer);
                }
                else
                {
                    Thread.Sleep(50);
                }
            }
        }
        OnDisconnect();
    }

    private void OnConnect(NetworkStream stream)
    {
        var connect = Connect;
        if (connect != null)
        {
            connect(this, new ConnectedEventArgs() { Stream = stream });
        }
    }

    private void OnDisconnect()
    {
        var disconnect = Disconnect;
        if (disconnect != null)
        {
            disconnect(this, EventArgs.Empty);
        }
    }

    private void OnDataReceived(byte[] buffer)
    {
        var execute = DataReceived;
        if (execute != null)
        {
            execute(this, new DataReceivedEventArgs() { Buffer = buffer });
        }
    }

    #region IDisposable Members

    public void Dispose()
    {
        listener.Stop();
    }

    #endregion
}
public class DataReceivedEventArgs : EventArgs
{
    public byte[] Buffer { get; set; }
}

public class ConnectedEventArgs : EventArgs
{
    public NetworkStream Stream { get; set; }
}
If there is anything more you need to know, feel free to ask me here =)

Thank you guys, and excuse my english(!)

Commented Issue: Assembly with strong name [11429]

$
0
0
Hello,

Could you please release NAudio as an assembly with a strong name so it can be installed in the GAC by running gacutil -i NAudio.dll?

Thanks.
Comments: There shouldn't be any problems, just open the project file in Visual Studio, in Properties find a Signing tab and create a new pair of keys, which should then be added to all projects - or to a common AssemblyInfo, if you have such one :-) Jokes aside, it'd be really nice to have a signed version in order to avoid fetching the source code for recompilation/resigning... Nuget does the job of getting the library, I'd rather not intervene with it :-)

New Post: NAudio ASIO

$
0
0
I using ASIO NAudio in a network application. I need float[] to byte[] for ASIO Record data.

asioOut.InitRecordAndPlayback(null, 1, 44100);
asioOut.AudioAvailable += AsioAudioAvailable;
asioOut.Play();

private void AsioAudioStreamAvailable(object sender, AsioAudioAvailableEventArgs e)
{
e.GetAsInterleavedSamples();

}

i need float[] (e) to byte[] (PCM16BIT)...

please help me...

New Post: Media Foundation 48kHz files?

$
0
0
OK, had a few minutes to spare so have made a SampleToWaveProvider24. It's in the latest NAudio source. Convert your 32 bit PCM file into 24 like this:
            using (var reader = new WaveFileReader(input))
            {
                var sp = reader.ToSampleProvider();
                var wp24 = new SampleToWaveProvider24(sp);
                WaveFileWriter.CreateWaveFile(output, wp24);
            }

New Post: Master Volume Handling Example

$
0
0
Which platforms is NAudio supporting? Are you talking about XP not supporting core audio or other non Microsoft platforms?

In any case having a demo/example of how to handle and manipulate various basic audio settings such as mute and volume sounds like a good idea to bring people to use NAudio even for such simple tasks.

New Post: Master Volume Handling Example

$
0
0
Yeah, NAudio does still support Window XP, although will be hoping to be able to drop that eventually. Also, many server OS editions of Windows come with a lot of Media Foundation turned off, so would want to check that is there.

But yes, definitely would be great to have a demo of this.
Viewing all 5831 articles
Browse latest View live


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