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

New Post: compress audio input

$
0
0
there is no uniform way to do this with the waveIn APIs, which is unfortunate. The mixer APIs in theory can let you get at the microphone gain, but in practice this can be really hard to do. This is because soundcards have lots of inputs of various kinds each with different capabilities.

New Post: Get data from a playing wav file

$
0
0
please read this article for a detailed explanation of how to convert between audio formats with NAudio.

New Post: How to use NAudio with video file !

$
0
0
I use VS2012 but only because there is now a Windows 8 store app in the solution. You can make your own VS2010 solution and add all the csproj except the Windows 8 store app one and it should work just fine.

New Post: Create 16bit Wav with data section zeroed

$
0
0
No real need to go to a SampleProvider in this instance. Just pass your NullWaveStream into CreateWaveFile.

NAudio does not include support for overwriting an existing WAV file though so you'd need your own custom code for that.

New Post: Echo produced when modifying tempo

$
0
0
this is probably a question for the Soundtouch developers

New Post: Create 16bit Wav with data section zeroed

$
0
0
I've done this and I do use my own code to write the existing WAV file, but for some reason I get a resulting wav which never contains the audio I record but instead just a "pop/click" noise followed by maybe .5 second of silence.

I know this is asking a lot, but I'd really appreciate a tip if you have one. If not, no problem. Here is what I have:

// Create my wav container
// In this case 47 minutes long, 1 channel, 44100, 16bit
  WaveFormat wform = new WaveFormat(44100, 16, 1);
            WaveStream wstream = new NullWaveStream(wform, 248724044);
            
            WaveFileWriter.CreateWaveFile(pFilename,wstream);
// Record some audio to a stream
 waveIn = new WaveIn
                {
                    WaveFormat = new WaveFormat(44100, 1),
                    NumberOfBuffers = 3,
                    BufferMilliseconds = 100
                };
ms = new MemoryStream();
 waveIn.DataAvailable += WaveIn_DataAvailable;
waveIn.RecordingStopped += waveIn_RecordingStopped;
ms.Position = 0;
waveIn.StartRecording();


        private void WaveIn_DataAvailable(object sender, WaveInEventArgs e)
        {
            ms.Write(e.Buffer, 0, e.BytesRecorded);
}
// Stop recording
waveIn.StopRecording();
 byte[] bytes = ms.ToArray();
// convert bytes to 16bit (short)
for (int i = 0; i < bytes.Count() - 1; i += 2)
            {
                var sample = (short) (bytes[i + 1] << 8 | bytes[i + 0]);
                double d = sample*ratio;
                var shrt = (short) Math.Round(d);
                bytes[i + 1] = (byte) ((shrt & 0xFF00) >> 8);
                bytes[i + 0] = (byte) (shrt & 0x00FF);
                //Debug only - use it to verify conversion 
                //short res = (short)(bytes[i + 1] << 8 | bytes[i + 0]);
            }
// write to the wav file we created
FileStream fs = File.Open(narration_filename, FileMode.Open, FileAccess.Write, FileShare.ReadWrite);
 var binwriter = new BinaryWriter(fs);
double samples_per_millisecond = (1*44100)/1000.0; //channels*sampling rate/1000
var offset = (long) (TiradeOffsetMilliseconds*samples_per_millisecond*(16/8));
if (offset%2 > 0)// odd offset
                {
                    
                    offset = offset - offset%2;
                }
 //44 bytes is the length of .wav file header
//https://ccrma.stanford.edu/courses/422/projects/WaveFormat/
            binwriter.Seek((int) (44 + offset), SeekOrigin.Begin);
binwriter.Write(bytes);

            binwriter.Flush();

            fs.Flush();

            // binwriter.BaseStream.Dispose();

            binwriter.Close();
            
            fs.Dispose();

            fs.Close();

 private void waveIn_RecordingStopped(object sender, EventArgs e)
        {
            if (waveIn != null)
            {
                waveIn.Dispose();
            }
            waveIn = null;
        }

New Post: Get data from a playing wav file

$
0
0
Would it not work with your needs to read the bytes out of the wav file in to a stream and then send those bytes to your server?
Ok it work thank you
please read this article for a detailed explanation of how to convert between audio formats with NAudio.
I managed to convert it with the WaveFormatConversionStream Method

New Post: Getting end of stream error when reading a stream using WavFileReader

$
0
0
I am downloading a wav file from an http server, copying it to a memorystream and then trying to open it for conversion via WavFileReader.

When I do this, I get a "can't read past end of stream" exception. If I write the bytes (using WriteAllBytes) to a file and then open using WavFileReader passing in a filename, it works just fine. The file is encoded at 13kbps (I can provide the file upon request).

what am I doing wrong? At this point, I'm thinking of writing the file out to a tmp file and then just making sure I delete it.

New Post: Create 16bit Wav with data section zeroed

$
0
0
Just an update I ended up writing out my own WAV header and got it to work. Honestly I'm still pretty confused as to what I was doing wrong, but one thing I did notice about naudio's wav file headers is that the data seems to be offset by a few bytes and that could interfere with the chunk bytes. If anyone is interested I can take a couple screenshots from a hex editor.

New Post: Using a low-pass filter...

$
0
0
Using NAudio I am capturing microphone samples in order to play them back on a remote machine. In some cases I'd like to apply a low-pass filter. How can this done with NAudio?

Ideally I would like to apply the filter based on end user input on the playback machine (maybe via a "enable/disable low-pass filter" button).

It appears as though I need to use...
var myFilter = BiQuadFilter.LowPassFilter (x, y, z);
myFilter.Transform (inBuffer, outBuffer);
However, it isn't clear how/where I insert this transformation prior to playback.

New Post: Using a low-pass filter...

$
0
0
This is more or less a guess, I'm sure there is a better way but this is what I would start with.
If you just need a stream of bytes to apply your filter to, you can capture them with WaveIn eventhandler to a MemoryStream then send it to myFilter.Transform as the inBuffer.

YourWaveIn.DataAvailable += WaveIn_DataAvailable;

MemoryStream ms = new MemoryStream();
 private void WaveIn_DataAvailable(object sender, WaveInEventArgs e)
        {
//use WaveInEventArgs to write buffer to ms
//then send ms to some function that converts to float[]
//then send float[] to myFilter
}

Created Unassigned: Trying to change volume [16395]

$
0
0
Im pretty new to Naudio, and im trying to change the volume of my DirectSoundOut

When i try to change it nothing happens even if i pause and play the song again

dim stream As NAudio.Wave.BlockAlignReductionStream = Nothing
dim output As DirectSoundOut = New DirectSoundOut()

Public Sub volume(ByVal vol_in As Single)
output.Volume = vol_in
End Sub

Created Unassigned: Occasional AccessViolation in WDMAUD.DRV [16396]

$
0
0
Under load, I am getting an occasional AccessViolation in WDMAUD.DRV, and my application is crashing.

Closed Unassigned: read mp3 to URL [16394]

$
0
0
Can Naudio read this mp3 url?
http://players.creacast.com/creacast/sudtirol1a/playlist.pls



Regards
Alex
Comments: recommendation is to extract URL from pls file

Edited Issue: read mp3 to URL [16394]

$
0
0
Can Naudio read this mp3 url?
http://players.creacast.com/creacast/sudtirol1a/playlist.pls



Regards
Alex

Commented Unassigned: Occasional AccessViolation in WDMAUD.DRV [16396]

$
0
0
Under load, I am getting an occasional AccessViolation in WDMAUD.DRV, and my application is crashing.

Comments: Please provide more information, including what you were doing with NAudio, what OS you are using, what version of NAudio you are using, and the stack trace if available when the exception occurs

New Post: Add intential sound delay to sync up with sampling?

$
0
0
I looked at the SampleAggregator as an example and did the same thing-

I use a NotifyingSampleProvider's ".sample" property to create FFT data for analysis.

Everything works great, but the analysis finishes a bit behind the actual sound (duh).

Is there a way to allow the sound processing to continue at its normal rate (so NotifyingSampleProvider's samples arrive normally) but to delay the actual sound OUTPUT behind that a bit, so that my analysis syncs up better with the sound?


Sorry if it's a confusing question - please let me know if I need to provide any more information.

New Post: Add intential sound delay to sync up with sampling?

$
0
0
Nevermind, I was looking for "DesiredLatency".
var inputStream = CreateInputStream(fileName);
                WaveOut useMeInstead = new WaveOut();
                useMeInstead.DesiredLatency = desiredLatency;
                useMeInstead.Init(new SampleToWaveProvider(inputStream));
                playbackDevice = useMeInstead;

Commented Unassigned: Occasional AccessViolation in WDMAUD.DRV [16396]

$
0
0
Under load, I am getting an occasional AccessViolation in WDMAUD.DRV, and my application is crashing.

Comments: OS: Windows XP SP3 32bit (we have seen this issue on Windows 7 too though) nAudio is being used to record from the sound card (to Wav file) using WaveIn (default constructor) - capture format is WaveFormat(8000, 1); nAudio version 1.6 I don't have a stack trace at present - trying to retrieve one using Windbg.... (crash occurs under overnight load test) Test scenario is to * record a file (few seconds (3?)) * stop recording * wait a short while (few seconds) * start recording * repeat!

Commented Unassigned: Occasional AccessViolation in WDMAUD.DRV [16396]

$
0
0
Under load, I am getting an occasional AccessViolation in WDMAUD.DRV, and my application is crashing.

Comments: Thanks for the extra info. That doesn't sound like it would load the computer heavily at all. Are you using the same WaveIn object for each recording, or creating a new one? Are any codecs involved in the process or are you writing PCM to the WAV file? One possible cause of these errors is the garbage collector moving something that shouldn't be moved. I feel fairly confident that all such instances have been found and fixed over the years in NAudio, but I guess it is possible that something which ought to be pinned isn't being.
Viewing all 5831 articles
Browse latest View live


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