I have a custom Audio DAC device. It has own controller inside and knows how to work with a certain byte stream. There is a library I'm trying to use: Audio Graph. I generate some data in memory and send it like so:
private unsafe AudioFrame GenerateAudioData(byte[] data)
{
uint bufferSize = 7000000;
AudioFrame frame = new Windows.Media.AudioFrame(bufferSize);
using (AudioBuffer buffer = frame.LockBuffer(AudioBufferAccessMode.Write))
using (IMemoryBufferReference reference = buffer.CreateReference())
{
byte* dataInBytes;
uint capacityInBytes;
((IMemoryBufferByteAccess)reference).GetBuffer(out dataInBytes, out capacityInBytes);
for (int i = 0; i < bufferSize; i += 4)
{
dataInBytes[i] = data[i];
dataInBytes[i + 1] = data[i + 1];
dataInBytes[i + 2] = data[i + 2];
dataInBytes[i + 3] = data[i + 3];
}
}
return frame;
}
Here my audio graph settings:
AudioGraphSettings settings = new AudioGraphSettings(AudioRenderCategory.Other)
{
EncodingProperties = AudioEncodingProperties.CreatePcm(44100, 2, 16),
AudioRenderCategory = AudioRenderCategory.Other,
DesiredRenderDeviceAudioProcessing = AudioProcessing.Raw
};
The problem is that something modify my stream and physical device doesn't recieve exactly the same data. On sound it is not noticeable, but I need to deliver the same bytes to the endpoint device. Using WASAPI I don't have such problem. Also it would be better if I get an exclusive access to my device. It is highly undesirable that the system sounds/alerts/notifications are mixed with my audio stream.
Thanks in advance!