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

New Post: How to use FFT?

$
0
0
Hi Mark,

In your article, this code:
float sample = ((oldIndex < 0) ? prevBuffer[frames + 
            corr += (sample * buffer[i]);
it shows errors,
"Cannot implicitly convert type 'float' to 'int'. An explicit conversion exists (Are you missing a cast?)"
"Syntax error, ']' expected"

Any idea?

New Post: DirectX and ASIO Recording

$
0
0
Hi all,

I've been reading through the source and demos and I'm looking for a few things. I may just be missing them, so if I am can you point me in the right direction?
  1. ASIO recording with mixer playback. i.e. multiple samples played while recording.
  2. DirectX recording... ok, basically the same thing as the ASIO question. I don't see any DX recording at all.
Excellent API you've developed.

Thanks,
Tony

New Post: Adpcm to WAV

$
0
0
Hi,

I'm trying to convert an IMA Adpcm stream into a WAV stream.
This is my latest attempt:
            var bytes = File.ReadAllBytes(@"c:\temp\bytes.bin");
            using (var stream = new MemoryStream(bytes))
            {
                RawSourceWaveStream rawStream = new RawSourceWaveStream(stream, new ImaAdpcmWaveFormat(8000, 1, 4));
                WaveFormatConversionStream convertStream = new WaveFormatConversionStream(new WaveFormat(8000, 16, 1), rawStream);
                var buffer = new byte[640];
                convertStream.Read(buffer, 0, buffer.Length);
            }
This attempt has failed because the WaveFormatConversionStream is trying to create an AcmStream which in turn doing sourceBufferSize -= (sourceBufferSize % sourceFormat.BlockAlign);
Since ImaAdpcmWafeFormat initializes BlockAlign to be 0, I get DivisionByZeroException.
I fixed that by doing this: sourceBufferSize -= sourceFormat.BlockAlign != 0 ? (sourceBufferSize % sourceFormat.BlockAlign) : 0;
So I passed this line.
Now it fails while calling acmStreamOpen with the error: "AcmNotPossible calling acmStreamOpen".
I don't understand why. When I enumerate my codecs I see the Microsoft IMA ADPCM CODEC and the following:
===========================================
Format 0: 8.000 kHz, 4 Bit, Mono
  FormatTag: DviAdpcm, Support Flags: Codec
  WaveFormat: DviAdpcm 8000Hz Channels: 1 Bits: 4 Block Align: 256, AverageBytesPerSecond: 4055 (32.4 kbps), Extra Size: 2
  Extra Bytes:
  F9 01 
===========================================
Which is exactly the format of my stream.

How can I make this conversion to work?

Thank you,
Joe.

New Post: Ima Adpcm to PCM

$
0
0
Hi,

I am trying to convert an Ima Adpcm stream into a PCM stream.
My latest attempt looks as follows:
            var bytes = File.ReadAllBytes(@"c:\temp\bytes.bin");
            using (var stream = new MemoryStream(bytes))
            {
                RawSourceWaveStream rawStream = new RawSourceWaveStream(stream, new ImaAdpcmWaveFormat(8000, 1, 4));
                WaveFormatConversionStream convertStream = new WaveFormatConversionStream(new WaveFormat(8000, 16, 1), rawStream);
                var buffer = new byte[640];
                convertStream.Read(buffer, 0, buffer.Length);
            }
This implementations has two problems:
  1. The WaveFormatConversionStream is trying to create an AcmStream internally and its Ctor throws a DivisionByZero exception because the ImaAdpcm BlockAlign value is zero.
  2. If I fix that, I get "AcmNotPossible calling acmStreamOpen" from the acmStreamOpen call.
When I enumerate the codec on my machine I see this:
Long Name: Microsoft IMA ADPCM CODEC
Short Name: Microsoft IMA ADPCM
Driver ID: 5370400
FormatTags:
 ===========================================
   Format 0: 8.000 kHz, 4 Bit, Mono
      FormatTag: DviAdpcm, Support Flags: Codec
      WaveFormat: DviAdpcm 8000Hz Channels: 1 Bits: 4 Block Align: 256, AverageBytesPerSecond: 4055 (32.4 kbps), Extra Size: 2
      Extra Bytes:
      F9 01 
   ===========================================
I tried setting the BlockAlign to be 256 and the AvgBPS to 4055 (because the default ImaAdpcm set them to zero) and I still get the same error.

How can I convert my stream into PCM?

Thank you,
Joe.

New Post: DirectX and ASIO Recording

$
0
0
ASIO recording is a fairly new addition. I usually use the BufferedWaveProvider to playback while recording. However, the ASIO model is quite unique, and it would be nicer if NAudio had the support to let you process the in buffer, and write to the out buffer all within a single callback.

DirectX recording isn't done. I mostly recommend people use WaveIn & WaveOut as they are the best tested and most mature parts of the framework. The current DirectSound implementation was contributed by someone else and I have had very little to do with it.

Mark

New Post: How to use FFT?

$
0
0
well all the code is in the .NET voice recorder application, and that definitely compiles. I would suspect that line has been truncated somehow. I'd have a look at the source code itself.

New Post: Pitch Detection

$
0
0
well in Autotune.net I use an FFT for pitch detection. There are other (and possibly better) ways, but for an explanation of how to use FFT with NAudio, read this article:
http://channel9.msdn.com/coding4fun/articles/AutotuneNET You will need some patience if you are new to DSP, as I found it took me a long time to understand FFTs.

New Post: Ima Adpcm to PCM

$
0
0
the ImaAdpcmWaveFormat class was never finished. Needs to have everything set up correctly. Probably it is just the samples per block you need to set up (505 I think)

New Post: Find a fairly precise frequency of wave

New Post: WaveViewer produces different views depending on function to load file

$
0
0
Hello,

when loading an audio file via NAudio.Wave.AudioFileReader the waveform does not match the waveform loaded when using NAudio.Wave.WaveFileReader or NAudio.Wave.Mp3FileReader:

Image

This makes it difficult to compare the waveforms of different file types.
What is the difference between WaveFileReader and AudioFileReader loading a wave file?

New Post: Network Chat Multi-Client Program

$
0
0
you can ask the BufferedWaveProvider how much data it has queued. This is how the Network streaming demo works - goes into auto-pause when there is not enough..

New Post: Ima Adpcm to PCM

$
0
0
I tried filling out the missing parts in a debugger, but acmStreamOpen still fails.
Is there a way to debug this call (maybe enable tracing)?
I used exactly the values as they appear above in the driver format details and it still gave me the same error.

New Post: Ima Adpcm to PCM

$
0
0
only thing left to try is to use WaveFormatConversionStream.ConvertToPcm. That uses acmFormatSuggest to let the codec suggest a PCM format it can decode to (although your PCM format looks right to me). If that doesn't work, then the either codec is lying about what waveformat it accepts, or you still haven't got something right. Did you set up samplesPerBlock?

New Post: Ima Adpcm to PCM

$
0
0
I actually called AcmStream.SuggestPcmFormat and it gave me the same error.
Yes, I've set the samplesPerBlock and the blockAlign and the AvgBytesPerSec...
Is there anything else I can try?

New Post: Ima Adpcm to PCM

$
0
0
you need to view the bytes in a hex editor. Create an instance of the ImaWavbeFormat, copy it into a byte array (I think Buffer.BlockCopy can do this), and then byte by byte check it is identical to the WaveFormat returned by the ACM.

New Post: WaveViewer produces different views depending on function to load file

$
0
0
AudioFileReader returns IEEE floating point whilse Mp3FileReader and WaveFileReader will return PCM (probably 16 bit). I expect that the waveform drawing code is expecting 16 bit samples.

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

$
0
0
Is it possible? The number of channels that is returned is "1", but it is still PCM audio and it appears that when I plug in the PanningSampleProvider, the output is complete garbage. I do not get any audio.

Suggestions?

Paul

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

$
0
0
panning sample provider takes a sample provider as an input. Sample providers are 32 bit float. Use Pcm16ToSampleProvider to get there

New Post: Sample Aggregation For WASAPI Loopback

$
0
0
I'm currently building a visual application that will capture internal audio using NAudio and the WASAPI Loopback device.

Referring to the code of your other .Net VoiceRecorder sample application, which allows you to display a real-time peak indicator through the Sample Aggregator mechanism. Now this code has been developed around one set WaveFormat (1 channel 16bit PCM @ 44.1KHz ) and seems to do the job nicely.

I'm trying to adapt this approach to be used with uncertain format of WASAPI Loopback to display a peak value in my application, in my system preferences for the playback device (Win 7) my system is set to 2 channel 16bit @ 44.1KHz, but I don't seem to be having much luck getting this working correctly (the silent output wont sit at 0 for example).

In this situation is the WaveFormat returned by WasapiLoopbackCapture actually:

AverageBytesPerSecond 352800
BitsPerSample 32
BlockAlign 8
Channels 2
Extensible
ExtraSize 22
SampleRate 44100

or is this just a generic format output by default?

Do you have any advice/insights that would help in a situation like this?

P.S. Anything I record using WASAPI Loopback to WAV cannot be played by any of the NAudio demos, an acmFormatSuggest exception is thrown.

Thanks,

Ollie

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

$
0
0
I already have a Pcm16ToSampleProvider within the same provider within the provider chain, however, I will likely move it a little earlier and prior to passing the audio through the BassTreble provider I generated. I am not sure if order of provider's have an affect on audio, but I figure I will give that a try.

Originally, I had had the following chain:

--> BufferedWaveReader
--> Pcm16ToSampleProvider
--> BassTrebleProvider
--> SampleToWaveProvider16 (I think that is the name, I don't have the code in front of me).

This set up works perfectly....and I placed the PanningSampleProvider inbetween the BaseTrebleProvider and the last one. I will test to see how the works moving it one step earlier.

Paul
Viewing all 5831 articles
Browse latest View live


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