What I'm currently doing is while recording I get the bytes from the data received event and encode the bytes with a codec. The codecs I have set up to currently use are ALaw, G722, GSM, etc (like in the NetworkChatDemo)
The code used to start recording
If waveIn Is Nothing Then
waveIn = New WaveIn
waveIn.DeviceNumber = 0
waveIn.BufferMilliseconds = 100
waveIn.WaveFormat = codec.RecordFormat
waveIn.StartRecording()
End If
The code used to work with the recorded bytes
Private Sub OnDataAvailable(ByVal sender As Object, ByVal e As WaveInEventArgs) Handles waveIn.DataAvailable
Dim encoded As Byte() = codec.Encode(e.Buffer, 0, e.BytesRecorded)
...
//Send encoded audio over UdpClient
End Sub
This is working well for me but I'd like to add support for the AAC format. So I'd like to achieve the same result as in the above DataReceived event, a byte array of encoded AAC audio which I can send over udp, from MediaFoundationEncoder.EncodeToAac(...)
or another class/function I am not aware of within NAudio. As far as I can tell, MediaFoundationEncoder.EncodeToAac(...)
only encodes audio to a file and not a byte array. It also doesn't accept a byte array as a parameter. Is there a way to achieve what I want or does NAudio only let me work with an AAC file after it has been fully recorded and saved?