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

New Post: Sample Aggregation For WASAPI Loopback

$
0
0
After a bit of extra perseverance I have figured it out,

And it's as simple as:
 sample32 = BitConverter.ToSingle(buffer, index);
WASAPI Loopback's buffer byte array at DataAvailable contains 32 bit single-precision floats (not 16 bit shorts), so to get a sample value between 1f and -1f you need to use the following code before SampleAggregator:
       void waveIn_DataAvailable(object sender, WaveInEventArgs e)
        {
            byte[] buffer = e.Buffer;
            int bytesRecorded = e.BytesRecorded;
            WriteToFile(buffer, bytesRecorded);

            int bufferIncrement = (int)(this.waveIn.WaveFormat.BlockAlign / this.waveIn.WaveFormat.Channels);
            int bitsPerSample = this.waveIn.WaveFormat.BitsPerSample;

            for (int index = 0; index < e.BytesRecorded; index += bufferIncrement)
            {
                float sample32 = 0;

                if (bitsPerSample <= 16) // Presume 16-bit PCM WAV
                {
                    short sample16 = (short)((buffer[index + 1] << 8) | buffer[index + 0]);
                    sample32 = sample16 / 32768f;
                }
                else if (bitsPerSample <= 32) // Presume 32-bit IEEE Float WAV
                {
                    sample32 = BitConverter.ToSingle(buffer, index);
                }
                else
                {
                    throw new Exception(bitsPerSample + " Bits Per Sample Is Not Supported!");
                }

                // Clip Sample - Prevents Issues Elsewhere
                if (sample32 > 1.0f)
                    sample32 = 1.0f;
                if (sample32 < -1.0f)
                    sample32 = -1.0f;

                sampleAggregator.Add(sample32);
            }
        }
Hope this helps anyone else in future :)

Ollie

New Post: Sample Aggregation For WASAPI Loopback

$
0
0
yes, WASAPI normally works with 32 bit float. WAVEFORMATEXTENSIBLE is a bit of a pain to work with, but this seems to be Microsoft's preferred approach going forwards.

New Post: Using the PCM 16-bit Audio through PanningSampleProvider

$
0
0
for performance, I'd go with panning after basstreble, as panning will turn a mono input into a stereo output

New Post: Midifile with more than 16 Instruments at the same time

$
0
0
Have a look at the http://www.nerds.de/en/loopbe30.html or the (free 1 virtual midi device) this opens up to 30 virtual midi devices at the same time. You could split channels 16-31 to a virtual midi device and play it on it's 0-15 channels. Don't know if it would work; worth a try.

New Post: Using the PCM 16-bit Audio through PanningSampleProvider

$
0
0
I think I have a feeling that once I send the audio through the PanningSampleProvider which then creates a stereo signal from a mono signal, I must use something other than SampleToWaveProvider16 which I assume only works with Mono inputs?

What is the correct provider to convert it back into an appropriate WaveProvider?

Paul

New Post: Using the PCM 16-bit Audio through PanningSampleProvider

$
0
0
SampleToWaveProvider16 should work just fine with stereo

New Post: Using the PCM 16-bit Audio through PanningSampleProvider

$
0
0
The output after passing the audio stream through the PanningSampleProvider (eliminating my BassTrebleProvider from the equation), is not yielding me any valuable results. I get silence and when I try to pan, it seems like the tempo was reduced significantly....

Not sure why this would not work and I tried different panning strategies and no improvements. :-(

Paul

New Post: Using the PCM 16-bit Audio through PanningSampleProvider

$
0
0
Found out more info....can't seem to use the MonoToStereoProvider either. Seems like the conversion process from the mono to stereo is not working as expected. Not sure if the audio format is off.

When I open up the audio file in Audacity, I see Mono, 8000Hz, 32-bit float. Not sure if I am missing something because even when I use 32-bit version of the PCM to Sample Provider, I do not get clean audio....

Paul

New Post: Sample Aggregation For WASAPI Loopback

$
0
0
Through my own testing of WASAPI capture, the whole process of writing to file on DataAvailable callback seems slightly unreliable, recording 2-3 minutes worth of audio through the loopback interface and there will be a couple of glitches in the wave file where moments of audio have been missed (<500ms).

I presume this is because the the DataAvailable callback hasn't been executed in time (or at all) for that 100ms worth of data.

I have noticed that WaveIn allows you to supply a window handle for NAudio to post a message back, which might be more reliable. Is there a reason why this hasn't been implemented into the WASAPI classes?

New Post: Sample Aggregation For WASAPI Loopback

$
0
0
Do you think if a derivative of WasapiCapture.cs was created where if a WaveFileWriter was specified in advance, the whole write to file process was done immediately at the end of the ReadNextPacket function instead of at the start of the DataAvailable callback, this would workaround the issue?

I'm presuming here though that NAudio is capturing those missing packets in the first place...

Cheers,

Ollie

New Post: Sample Aggregation For WASAPI Loopback

Created Issue: Two Common Controller Constants Missing From MidiController Enum [16388]

$
0
0
It would be nice if the common controller values BankSelectMSB (0) and BankSelectLSB (32) were added to the MIdiContoller enum. The current workaround is to simply specify the integer values, but an enum entry would make things a lot clearer.

A complete list of controller values is available at:
http://www.midi.org/techspecs/midimessages.php#3

New Post: VST

$
0
0
Hi there and big thanks for the great library!!! It's awesome project.
Is there a demo how to use vst.net or other .net vst hosting provider inside NAudio?

I found only bits and pieces, but nothing really showing how. Would be cool and great to be able to load vst instrument or fx.

Best regards

Source code checked in, #c67202d6b55c

$
0
0
added in some more MIDI controller enums

Commented Issue: Two Common Controller Constants Missing From MidiController Enum [16388]

$
0
0
It would be nice if the common controller values BankSelectMSB (0) and BankSelectLSB (32) were added to the MIdiContoller enum. The current workaround is to simply specify the integer values, but an enum entry would make things a lot clearer.

A complete list of controller values is available at:
http://www.midi.org/techspecs/midimessages.php#3
Comments: good suggestion, I've added them and a few other common ones

Edited Issue: Two Common Controller Constants Missing From MidiController Enum [16388]

$
0
0
It would be nice if the common controller values BankSelectMSB (0) and BankSelectLSB (32) were added to the MIdiContoller enum. The current workaround is to simply specify the integer values, but an enum entry would make things a lot clearer.

A complete list of controller values is available at:
http://www.midi.org/techspecs/midimessages.php#3

New Post: VST

$
0
0
I've wanted to do this for ages, but still haven't got round to it unfortunately. I have a feeling that VST.NET might have an example of NAudio integration so you could look there.

New Post: Sample Aggregation For WASAPI Loopback

$
0
0
there is no windows callback becasue WASAPI does not have window callbacks like WaveOut/WaveIn does. NAudio is just a fairly thin wrapper around the WASAPI APIs. Perhaps audio is being missed because the DataAvailable event isn't being processed quickly enough. You could certainly experiment with your own copy of WasapiIn and see if writing and flushing after ReadNextPacket helps. Let us know how you get on.

New Post: Windows 8 WinRT Metro Style Support

$
0
0
Any news on the WinRT front?

In partucular I'm looking for a way to draw an audio graph from the MediaCapture microphone stream in C#.
Similar to yours here
Image

New Post: Using the PCM 16-bit Audio through PanningSampleProvider

$
0
0
figured out my problem....had to do with using the incorrect waveformat object for my provider. Since I was encapsulating all these listed providers (from my earlier) post in a master IWaveProvider object, I was using the waveformat object of the bufferedWaveReader instead of the final provider, so the difference was that my player was looking at the provider assuming it was 1 channel vs the 2 channels that was generated from the PanningSampleProvider.
Viewing all 5831 articles
Browse latest View live