Reputation: 706
I'm trying out the new spatial audio functions in the AudioGraph 1.1 API and I have sound output from a file working without an emitter, but when I add an emitter to my node creation call it suddenly returns FormatNotSupported. I can't find any information via searching that has been any sort of helpful, probably because it's such a new API. Can anyone see if I'm doing something wrong or missing something? Following is my code:
private async void MainPage_Loaded(object sender, RoutedEventArgs args)
{
AudioGraphSettings settings = new AudioGraphSettings(AudioRenderCategory.Media);
var devices = await DeviceInformation.FindAllAsync();
CreateAudioGraphResult result = await AudioGraph.CreateAsync(settings);
if (result.Status != AudioGraphCreationStatus.Success)
{
return;
}
graph = result.Graph;
FileOpenPicker saveFilePicker = new FileOpenPicker();
saveFilePicker.FileTypeFilter.Add(".wav");
saveFilePicker.FileTypeFilter.Add(".wma");
saveFilePicker.FileTypeFilter.Add(".mp3");
StorageFile file = await saveFilePicker.PickSingleFileAsync();
if (file == null)
{
return;
}
AudioNodeEmitter emitter = new AudioNodeEmitter(AudioNodeEmitterShape.CreateOmnidirectional(),
AudioNodeEmitterDecayModel.CreateNatural(.1,1,10,100),
AudioNodeEmitterSettings.None);
emitter.Position = new Vector3(10, 0, 5);
CreateAudioDeviceOutputNodeResult deviceOutputNodeResult = await graph.CreateDeviceOutputNodeAsync();
var outputNode = deviceOutputNodeResult.DeviceOutputNode;
CreateAudioFileInputNodeResult fileInputNodeResult = await graph.CreateFileInputNodeAsync(file, emitter);
inputNode = fileInputNodeResult.FileInputNode;
inputNode.AddOutgoingConnection(outputNode);
graph.Start();
}
Upvotes: 1
Views: 221
Reputation: 16652
There is no problem with your code, problem is:
Audio node emitters can only process audio that is formatted in mono with a sample rate of 48kHz. Attempting to use stereo audio or audio with a different sample rate will result in an exception.
You can refer to the note part of Spatial audio.
To test this API, you may download this audio here.
Upvotes: 1