Sure, you're welcome to submit a pull request (over at Github of course) to add in GetWaveOutEndpointId. Obviously though we can't require that users have access to any MMDevice functions though, since NAudio still supports Windows XP.
↧
New Post: Device Name Truncation with WaveOut.GetCapabilities
↧
New Post: WaveForm Length in Pixels
Hello,
does anyone know how I can calculate the length of a waveform (in pixels) in the NAudio WaveViewer?
Thanks and best regards
does anyone know how I can calculate the length of a waveform (in pixels) in the NAudio WaveViewer?
Thanks and best regards
↧
↧
New Post: WaveForm Length in Pixels
well it has a SamplePerPixel value, so you can calculate it from the length of the file
↧
New Post: Different lengths of the same file (in .wav and .mp3)
how different are they?
They won't be identical, since MP3s can't have an exact length in terms of samples like a WAV file can
They won't be identical, since MP3s can't have an exact length in terms of samples like a WAV file can
↧
Commented Unassigned: MemoryAllocationError calling waveInOpen [16472]
Hello,
I use NAudio for professional project to communicate with radios. Randomly, the DLL crashes at start of the Micro capture.
Someone would have an idea?
Thank you in advance.
Here is my code:
Imports NAudio.Wave
Imports System.Runtime.InteropServices
Public Class NaudioMicro
Implements IDisposable
Protected Disposed As Boolean = False
#Region "Déclarations"
'Autorisation d'exporter le flux Audio
Private Transmit As Integer = 0
'Indique que le recorder est en mode capture
Private IsCapturing As Integer = 0
'Recorder Naudio
Private WithEvents _WaveInDevice As WaveIn
#End Region
#Region "Constructor"
''' <summary>
''' Simple New without Data
''' </summary>
''' <remarks>The selection of Peiker Microphone is automatic !</remarks>
Public Sub New()
Dim DeviceInfoI As WaveInCapabilities
Try
'1. Détection automatique du Micro Peiker
Dim DeviceNumber As Integer = -1
For I As Integer = 0 To WaveIn.DeviceCount - 1
DeviceInfoI = WaveIn.GetCapabilities(I)
If Val("&H" & Strings.Left(DeviceInfoI.ProductGuid.ToString, 2)) > 0 Then
If InStr(DeviceInfoI.ProductName, "PTC USB", CompareMethod.Text) > 0 Then
DeviceNumber = I
Exit For
End If
End If
Next
'2. Configuration du Recorder avec Micro Peiker
If DeviceNumber >= 0 Then
_WaveInDevice = New WaveIn()
_WaveInDevice.DeviceNumber = DeviceNumber
_WaveInDevice.WaveFormat = New NAudio.Wave.WaveFormat(8000, 16, 1)
_WaveInDevice.BufferMilliseconds = 60
End If
Catch Ex As Exception
Finally
IsCapturing = 0
End Try
End Sub
#End Region
#Region "Event"
Friend Event OnDeliverySpeechData(ByVal SpeechData() As Byte)
#End Region
#Region "Commandes"
''' <summary>
''' Start Recording
''' </summary>
''' <remarks></remarks>
Private Sub CaptureStart()
If _WaveInDevice Is Nothing Then
Return
End If
If IsCapturing = 0 Then
IsCapturing = 1
_WaveInDevice.StartRecording()
End If
End Sub
''' <summary>
''' Stop Recording
''' </summary>
''' <remarks></remarks>
Private Sub CaptureStop()
If _WaveInDevice Is Nothing Then
Return
End If
If IsCapturing = 1 Then
IsCapturing = 0
_WaveInDevice.StopRecording()
Transmit = 0
End If
End Sub
''' <summary>
''' Start transmission of audio stream
''' </summary>
''' <remarks></remarks>
Friend Sub StartCapture()
Transmit = 1
If IsCapturing = 0 Then
CaptureStart()
End If
End Sub
''' <summary>
''' Stop transmission of audio stream
''' </summary>
''' <remarks></remarks>
Friend Sub StopCapture()
Transmit = 0
If IsCapturing = 1 Then
CaptureStop()
End If
End Sub
#End Region
#Region "Processus_internes"
''' <summary>
''' Fonction CallBack de l'enregistreur
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub _WaveInDevice_DataAvailable(ByVal sender As Object, ByVal e As NAudio.Wave.WaveInEventArgs) Handles _WaveInDevice.DataAvailable
If Transmit = 1 Then
If e.BytesRecorded > 0 Then
If My.Settings.SendSpeechDirect = 1 Then
Dim AIOPCMFrame As New _D25AIOPCMFRAME
AIOPCMFrame.sz = e.Buffer.Length
AIOPCMFrame.m_aFrame = Marshal.AllocHGlobal(e.Buffer.Length)
Marshal.Copy(e.Buffer, 0, AIOPCMFrame.m_aFrame, e.Buffer.Length)
Call Appels.DiffusionMicro(AIOPCMFrame)
If LoopBack = 1 Then
If IHM.PlayBackJingleInProgress = 0 Then
If My.Settings.AudioEmbeded = 0 Then
Players.Player(0).PlayPacket(e.Buffer)
Else
LocalPlayer.PlayPacket(e.Buffer)
End If
End If
End If
Else
RaiseEvent OnDeliverySpeechData(e.Buffer)
End If
End If
End If
End Sub
#End Region
#Region "IDisposable Support"
Protected Overridable Overloads Sub Dispose(ByVal disposing As Boolean)
If Not Me.Disposed Then
If disposing Then
If _WaveInDevice IsNot Nothing Then
_WaveInDevice.StopRecording()
_WaveInDevice.Dispose()
_WaveInDevice = Nothing
End If
End If
End If
Me.Disposed = True
End Sub
' Do not change or add Overridable to thse methods.
' Put cleanup code in Dispose(Byval disposing as boolean).
Public Overloads Sub Dispose() Implements IDisposable.Dispose
Dispose(True)
GC.SuppressFinalize(Me)
End Sub
Protected Overrides Sub Finalize()
Dispose(False)
MyBase.Finalize()
End Sub
#End Region
End Class
Comments: sounds like an out of memory issue
↧
↧
New Post: Spectrogram operations
the best way to learn how to do this is to look at the examples in the NAudio Demo project
↧
New Post: Device Name Truncation with WaveOut.GetCapabilities
I solved this a different way which does not require the DllImport or Marshalling. (maybe be more efficient, not sure)
First You need to do a simple check that the computer is running Windows Vista Or Higher
I create a collection of MMDeviceCollection objects.
Each object has these properties
C# Partial Code snippet
First You need to do a simple check that the computer is running Windows Vista Or Higher
I create a collection of MMDeviceCollection objects.
Each object has these properties
- FriendlyName (which is the full device name, not limited to 32 characters)
-
ID (in this format {0.0.0.00000000}.{73d4795c-5a20-4a6d-80ef-6b86e31ea1f1} , note the GUID is included)
- so then you can just parse out the GUID and can match it to the GUID from the WaveOut.GetCapabilities snippet above
C# Partial Code snippet
MMDeviceEnumerator DevEnum = new MMDeviceEnumerator();
MMDeviceCollection devCollection = DevEnum.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.Active);
string guidStr;
string friendName = "";
int j = 0;
foreach (var item in devCollection)
{
devId = item.ID; // format {0.0.0.00000000}.{73d4795c-5a20-4a6d-80ef-6b86e31ea1f1};
int dotFour = devId.LastIndexOf(".") + 1;
guidStr = devId.Substring(dotFour);
friendName = item.FriendlyName;
// now you have GUID and full device name, call a method to populate your device list as needed
}
↧
New Post: Reproduction of multiple sound cards
hi,
First, I apologize for my English.
I'll be right down to it. I should make to reproduce the audio tracks on different sound cards with a single player.
I asked myself if it was possible, and if you can get some advice about it.
Many thanks,
Pstariell
First, I apologize for my English.
I'll be right down to it. I should make to reproduce the audio tracks on different sound cards with a single player.
I asked myself if it was possible, and if you can get some advice about it.
Many thanks,
Pstariell
↧
New Post: Different lengths of the same file (in .wav and .mp3)
mp3 will be longer in most cases, right? Maybe it'll be easier if i write what kind of operation i have in mind:
I wanted to create phase/polarity inversion - simply by multiplying every sample by '-1' (the same way as mixing is adding the samples). To check it, i tried to load the same file twice, then invert the phase of one reader and mix it together - the result should be silence. It didn't work that way.
I tried also with loading the files in different format, in mp3 and wav (they should, at least partially, cancel each other out). That's where my initial question came from, but now i see it doesn't work even on the same .wav file.
The sample of the code is below. I used AudioFileReader for both files and WaveFileWriter.
Thanks in advance
I wanted to create phase/polarity inversion - simply by multiplying every sample by '-1' (the same way as mixing is adding the samples). To check it, i tried to load the same file twice, then invert the phase of one reader and mix it together - the result should be silence. It didn't work that way.
I tried also with loading the files in different format, in mp3 and wav (they should, at least partially, cancel each other out). That's where my initial question came from, but now i see it doesn't work even on the same .wav file.
The sample of the code is below. I used AudioFileReader for both files and WaveFileWriter.
firstBuffer = new float[firstInputReader.WaveFormat.SampleRate * 2];
secondBuffer = new float[secondInputReader.WaveFormat.SampleRate * 2];
int firstBytesRead = 0;
int secondBytesRead = 0;
do
{
//reading:
firstBytesRead = firstInputReader.Read(firstBuffer, 0, firstBuffer.Length);
secondBytesRead = secondInputReader.Read(secondBuffer, 0, secondBuffer.Length);
//processing:
for (int i = 0; i < firstBuffer.Length; i++)
{
firstBuffer[i] /= 2; //volume rescaling
// mixing together with 1st input (which is multiplied by -1, i.e. phase inverted)
firstBuffer[i] += secondBuffer[i]*-1;
}
//writting:
writer.WriteSamples(firstBuffer, 0, firstBytesRead);
} while (firstBytesRead > 0);
writer.Dispose();
Could you help me with these basic operations? Or maybe there's build in functionality which helps with phase invertion (similar to mixing and MixingSampleProvider)?Thanks in advance
↧
↧
New Post: Where is the WasapiLoopbackCapture class?
Hi
I just downloaded the last naudio from github.
I am trying to modify the naudio demo to capture what windows plays.
I tried the following code which I saw here and there on the internet.
"The type or namespace name 'WasapiLoopbackCapture' could not be found (are you missing a using directive or an assembly reference?)"
So I am wondering if WasapiLoopbackCapture class was removed or even never existed in the first place.
Is there a workaround?
Any help will be greatly appreciated.
Thanks for advance.
I just downloaded the last naudio from github.
I am trying to modify the naudio demo to capture what windows plays.
I tried the following code which I saw here and there on the internet.
waveIn = new NAudio.Wave.WasapiLoopbackCapture();
I also triedwaveIn = new WasapiLoopbackCapture();
But I always get the following error."The type or namespace name 'WasapiLoopbackCapture' could not be found (are you missing a using directive or an assembly reference?)"
So I am wondering if WasapiLoopbackCapture class was removed or even never existed in the first place.
Is there a workaround?
Any help will be greatly appreciated.
Thanks for advance.
↧
New Post: Where is the WasapiLoopbackCapture class?
Not sure why you're seeing this. WasapiLoopbackCapture is here
↧
New Post: Where is the WasapiLoopbackCapture class?
markheath wrote:
Thank you for your prompt reply.
Not sure why you're seeing this. WasapiLoopbackCapture is hereI am sorry, it seems that I checked out a wrong version from github.
Thank you for your prompt reply.
↧
New Post: "AcmNotPossible calling acmFormatSuggest" on certain MP3 files, why?
Some of my MP3s will throw this exception every time I try to play them:
NAudio.MmException: AcmNotPossible calling acmFormatSuggest
bei NAudio.Wave.Compression.AcmStream.SuggestPcmFormat(WaveFormat compressedFormat)
bei NAudio.Wave.AcmMp3FrameDecompressor..ctor(WaveFormat sourceFormat)
bei NAudio.Wave.Mp3FileReader.CreateAcmFrameDecompressor(WaveFormat mp3Format)
bei NAudio.Wave.Mp3FileReader..ctor(Stream inputStream, FrameDecompressorBuilder frameDecompressorBuilder)
bei NAudio.Wave.Mp3FileReader..ctor(Stream inputStream)
bei NAudio.Wave.Mp3FileReader..ctor(String mp3FileName)
bei NAudio.Wave.AudioFileReader.CreateReaderStream(String fileName)
bei NAudio.Wave.AudioFileReader..ctor(String fileName)
Why is that?↧
↧
New Post: Doppler Effect Simulation
I'm supposed to simulate the Doppler effect.
I have to change the volume according to the distance from the moving source.
If I understand it right then this is currentVolume = fullVolume/(distance ^ 2) because of the cone effect.
The Doppler part is divided into two. The source is moving to the observer and moving away from the observer.
That's done with pitch shifting, but NAudio does not support it at this moment, am I right?
How am I supposed to implement the Doppler effect in NAudio?
I have to change the volume according to the distance from the moving source.
If I understand it right then this is currentVolume = fullVolume/(distance ^ 2) because of the cone effect.
The Doppler part is divided into two. The source is moving to the observer and moving away from the observer.
That's done with pitch shifting, but NAudio does not support it at this moment, am I right?
How am I supposed to implement the Doppler effect in NAudio?
↧
New Post: Convolution
Are there any examples for convolution in NAudio? How to use the class ImpulseResponseConvolution?
↧
New Post: Change Volume While Playing
How? :)
afr = new AudioFileReader(open.FileName);
wod = new WaveOut();
I've tried changing the volume property on both. While changing the volume on the AudioFileReader works on the next play, changing it on the output device has no effect at all.↧
New Post: Change Volume While Playing
You can use a VolumeSampleProvider to do this.
Here's an example from my project:
Here's an example from my project:
aReader = new AudioFileReader(file);
vsp = new VolumeSampleProvider(aReader.ToSampleProvider());
waveOutDevice.Init(vsp);
waveOutDevice.Play();
You can then set vsp.Volume while the song is playing.↧
↧
New Post: Playing sound with AsioOut very noisy and distortion
I'm trying to take the sound from one AsioOut Input and put it to an output. My first try was to save it in a wave file, that's no problem.
When i pass the bytes from the input into the BufferedWaveProvider which is passed to the AsioOut output object at initialisation i get a very high distortion on my audio signal.
Poorly i can't figure out whats wrong while playing the signal, because the signal in the recorded wave file is ok.
That's my initialisation of all objects
P.S. when i try to play a mp3 or wave file with the AudioFileReader and pass the reader ti the asioOut output object instead of BufferedWaveProvider there are no problems while playing.
When i pass the bytes from the input into the BufferedWaveProvider which is passed to the AsioOut output object at initialisation i get a very high distortion on my audio signal.
Poorly i can't figure out whats wrong while playing the signal, because the signal in the recorded wave file is ok.
That's my initialisation of all objects
int nSource = int.Parse(txtSourceChannel.Text);
int nDest = int.Parse(txtDestChannel.Text);
buffer = new BufferedWaveProvider(wFormat);
buffer.DiscardOnBufferOverflow = true;
input = new AsioOut(cmbAsioDrivers.SelectedItem.ToString());
input.InputChannelOffset = nSource;
input.InitRecordAndPlayback(buffer, 1, 44100);
input.AudioAvailable += asioOut_AudioAvailable;
input.PlaybackStopped += input_PlaybackStopped;
output = new AsioOut(cmbAsioDrivers.SelectedItem.ToString());
output.ChannelOffset = 1;
output.Init(buffer);
this.wavWriter = new WaveFileWriter(@"D:\test.wav", new WaveFormat(44100, 24, 1));
input.Play();
output.Play();
Thats the data available event handler of the asioOut input objectprivate readonly byte[] value24 = new byte[3];
void asioOut_AudioAvailable(object sender, AsioAudioAvailableEventArgs e)
{
float[] samples = new float[e.SamplesPerBuffer];
byte[] buf = new byte[e.SamplesPerBuffer];
for (int i = 0; i < e.InputBuffers.Length; i++)
{
Marshal.Copy(e.InputBuffers[i], buf, 0, e.SamplesPerBuffer);
Marshal.Copy(buf, 0, e.OutputBuffers[i], e.SamplesPerBuffer);
}
int count = e.GetAsInterleavedSamples(samples);
//wavWriter.WriteSamples(samples, 0, samples.Length); //works, result is ok
for (int s = 0; s < count; s++)
{
byte[] bytes = BitConverter.GetBytes((Int32)(Int32.MaxValue * samples[s]));
//Array.Copy(buf, s * 4, bytes, 0, 4);
buffer.AddSamples(bytes, 0, 4);
value24[0] = bytes[1];
value24[1] = bytes[2];
value24[2] = bytes[3];
wavWriter.Write(value24, 0, 3);
}
//buffer.AddSamples(buf, 0, buf.Length);
e.WrittenToOutputBuffers = true;
}
When i try to copy the input buffer to the output buffer of the same asioOut input object i can hear the signal very low and there is some distortion on the signal to (like a flanger effect).P.S. when i try to play a mp3 or wave file with the AudioFileReader and pass the reader ti the asioOut output object instead of BufferedWaveProvider there are no problems while playing.
↧
New Post: Change Volume While Playing
Thank you!
For everyone else, reading this sometime, the VolumeSampleProvider is located under:
For everyone else, reading this sometime, the VolumeSampleProvider is located under:
NAudio.Wave.SampleProviders.VolumeSampleProvider
↧
New Post: Problem with NAUDIO and REALTEK
Hi,
I have an issue with WaveOut and REALTEK. When I disconnect speakers, the audio driver are automaticaly desactivated and the audio playback stop but the PlaybackStopped event is not raised. The PlaybackState property has Play value but a call to Stop() freeze my application.
How to handle this ?
Thank you
I have an issue with WaveOut and REALTEK. When I disconnect speakers, the audio driver are automaticaly desactivated and the audio playback stop but the PlaybackStopped event is not raised. The PlaybackState property has Play value but a call to Stop() freeze my application.
How to handle this ?
Thank you
↧