sure, you call "StartRecording", but every time a buffer of audio is available (DataAvailable event), you examine the value of each sample. If the volume is greater than a particular threshold, you write the recorded buffer to your WAV file, if not, you simply discard it.
New Post: Question about the Framework (record only when dB high enough)
Commented Issue: What could cause a "InvalidParameter calling acmStreamClose" MmException? [16384]
Sad thing, I can't reproduce this on my machine and I have no hardware information about the users machine.
Here is the stacktrace:
at NAudio.Wave.Compression.AcmStream.Dispose(Boolean disposing)
at NAudio.Wave.AcmMp3FrameDecompressor.Dispose()
at NAudio.Wave.Mp3FileReader.Dispose(Boolean disposing)
at System.IO.Stream.Close()
at System.IO.Stream.Dispose()
at NAudio.Wave.WaveChannel32.Dispose(Boolean disposing)
at System.IO.Stream.Close()
at System.IO.Stream.Dispose()
at Espera.Core.Audio.LocalAudioPlayer.Dispose()
You can find the source code of the class here:
https://github.com/flagbug/Espera/blob/master/Espera/Espera.Core/Audio/LocalAudioPlayer.cs
Since I have no hardware information, nor information on what files this exception occurs, do you have any idea what goes wrong here?
Cheers,
Dennis
Comments: Unlikely, but I will add additional checks to be sure. If my users get this exception in the next version of my software, I'll report back. Cheers, Dennis
New Post: Question about the Framework (record only when dB high enough)
markheath wrote:sure, you call "StartRecording", but every time a buffer of audio is available (DataAvailable event), you examine the value of each sample. If the volume is greater than a particular threshold, you write the recorded buffer to your WAV file, if not, you simply discard it.
Thank you, man. That's all I had to know
New Post: Question about the Framework (record only when dB high enough)
Do you know how the bytes are sorted? I mean I got to record sound to a .mp3 (there is a less space consuming file type? quality is no issue) but I want to know how the bytes are sorted in the 'buffer' array
Buffer = [MostSig-1,LessSig-1,MostSig-2,LessSig-2,MostSig-3,LessSig-3, ... ] Is it like this? Or how does it work?
Thank you.
New Post: Playing output from self made MP3 Decoder
Thanks for all the respones,
i really like that.
So its bug killing time, i think i will use NLayer to see where it goes wrong. I dont know how yet, existing decoders are really well optimised making it harder to follow what is going on where. But i will not give up.
Thanks again :)
New Post: Voice Activated Switch
Hi Everyone,
I have to implement a sound recorder, that activates with sound and deactivates with silence. It is known as voice activated switch.
Is there anyone that has implemented this kind of algorithm before?
I have finished normal sound recording function, and for this time I have to implement this.
I have used NAudio library for all sound operations.
I will specify the level of sound that will be accepted and the software will wait for this level for start recording, then after if the level decreases below that level, apllication should save this part as a .wav file, and again starts to wait for the next sound, and it will continue like this.
If someone can help me, I will be appreciated.
Thanks.
Created Issue: WaveStillPlaying calling waveUnprepareHeader [16385]
I am occasionally getting a NAudio.MmException "WaveStillPlaying calling waveUnprepareHeader" from NAudio.Wave.WaveInBuffer.Reuse().
I am using nAudio 1.5.4.
Any thoughts on what causes it, and how I can resolve it?
Created Issue: System.NullReferenceException in NAudio.Wave.WaveOutEvent.PlaybackThread() [16386]
I am occasionally getting a System.NullReferenceException from NAudio.Wave.WaveOutEvent.PlaybackThread()
I am using nAudio 1.5.4.
Any thoughts on what causes it, and how I can resolve it?
Created Issue: NAudio.MmException - WaveStillPlaying calling waveOutWrite [16387]
I am occasionally getting a NAudio.MmException from NAudio.Wave.WaveOutBuffer.WriteToWaveOut()
I am using nAudio 1.5.4.
Any thoughts on what causes it, and how I can resolve it?
New Post: NAudio Error question
Ok so I have one last question, I hope you dont mind:
so now I have a timer which update every 10 miliseconds, after the timer starts i do this :
waveOutDevice.Dispose();
SoundMixer.waveData.Clear();
SoundMixer.ClearMixer();
after I have intersection I add WaveStream data into global list which store all the sounds:
SoundMixer.waveData.Add(placeToPress.ChannelStream);
then I set the channelStream.Position = 0;
when I want to play it I use this :
SoundMixer.AddToMixer();
waveOutDevice.Init(SoundMixer.MixerPlay()); //this return SampleToWaveProvider
waveOutDevice.Play();// waveOutDevice is DirectSoundOut.
If I add Thread.Sleep(100); after the whole code I can hear sound,but before this I cant hear nothing, any idea how to do this working
without sleep method ?
New Post: NAudio Error question
you're disposing the waveOutDevice every 10ms? It needs to be kept alive. Really you should open it once and keep it open for the whole duration of your playback.
New Post: NAudio Error question
well I removed the Dispose() line but I can hear sound only if I add Thread.Sleep at the end of the timer. :)
Commented Issue: AddTrack [16336]
{{
MidiEventCollection collection = new MidiEventCollection(1, PulsesPerQuarterNote);
collection.AddTrack();
collection.AddEvent(new NoteEvent(1, 1, MidiCommandCode.NoteOn, 60, 100), 0);
collection.AddEvent(new NoteEvent(300, 1, MidiCommandCode.NoteOff, 60, 0), 0);
collection.AddTrack();
collection.AddEvent(new NoteEvent(1, 2, MidiCommandCode.NoteOn, 60, 100), 1);
collection.AddEvent(new NoteEvent(300, 2, MidiCommandCode.NoteOff, 60, 0), 1);
collection.AddTrack();
collection.AddEvent(new NoteEvent(1, 3, MidiCommandCode.NoteOn, 60, 100), 3);
collection.AddEvent(new NoteEvent(300, 3, MidiCommandCode.NoteOff, 60, 0), 3);
collection.PrepareForExport();
}}
After running AddTrack() for the first time, the Tracks property of collection increments to 1.
then after running AddEvent(..., 0), the Tracks property of collection increments to 2, but the notes are added to Track 1.
I would have expected the noteEvents to be added to Track 0 as specified as a parameter in the AddEvent(...., 0) method.
is there no Track 0?
Also, I would not have expected the Tracks property to increment when using AddEvent.
Proceeding, AddTrack is run a second time, the Tracks property increments to 3. (this behavior seems expected)
Running AddEvent(...,1) twice specifying destination Track as 1 results in 2 more note events added to Track 1 (this behavior seems expected).
Then AddTrack is run a third time, the Tracks property increments to 4. (this seems expected)
Running AddEvent(...,3) twice specifying destination Track as 3 results in 2 notes added to Track 3 (this seems expected).
After running prepare for export, there are only 2 tracks instead of 3 (as intended).
And there are 2 notes that I tried to put on track 0 that wound up on track 1.
Is this a bug? or am I missing some details of the usage?
Thanks for looking into it.
Comments: There is no Track 0. (The collection may be number 0-15 or whatever, but the track numbers go 1-16) Using 0 just puts the events on the first available track.
New Post: NAudio Error question
The idea is you create just one device, and only call Init and Play once. Then in your timer, you add inputs to the mixer. Also, starting sounds every 10ms is pretty heavy-duty. You'll be playing 100 sounds after just 1 second unless they are very short.
New Post: Question about the Framework (record only when dB high enough)
In a WAV file the bytes are little endian (intel byte order) and are interleaved left channel, right channel. In an MP3 file, you cannot access the samples directly. To make MP3, you record as WAV and then convert to MP3 using something like lame.exe
Mark
Commented Issue: System.NullReferenceException in NAudio.Wave.WaveOutEvent.PlaybackThread() [16386]
I am occasionally getting a System.NullReferenceException from NAudio.Wave.WaveOutEvent.PlaybackThread()
I am using nAudio 1.5.4.
Any thoughts on what causes it, and how I can resolve it?
Comments: I am not disposing the player, but I am stopping playback using Stop() on WaveOutEvent. The application plays wav files in response to events occuring - and if a 'higher priority' event occurs, the current playback is stopped, and the new wav file is played instead. It all happens very quickly, so I expect that the issue is related to load/speed.
Commented Issue: System.NullReferenceException in NAudio.Wave.WaveOutEvent.PlaybackThread() [16386]
I am occasionally getting a System.NullReferenceException from NAudio.Wave.WaveOutEvent.PlaybackThread()
I am using nAudio 1.5.4.
Any thoughts on what causes it, and how I can resolve it?
Comments: are you calling Init twice on the same instance of WaveOutEvent?
New Post: Compare two different audio samples in real-time (karaoke)
Hi zassadgh, did you found a solution for the comparison?
New Post: Sample audio input for square waves
you can examine the value of each sample, by handling the DataAvailable property of WaveIn. This comes as a byte array, so if it was 16 bit samples, you'd use BitConverter.ToInt16 on each pair to get the sample value. Then implement your own logic to determine whether you are currently in a low or high level.
New Post: Sample audio input for square waves
Could you show some sudo code as I'm not sure about the bitconverter on each pair. Many thanks.