Skip to content

Conversation

@robertdorn83
Copy link
Collaborator

@robertdorn83 robertdorn83 commented Apr 8, 2025

Added support for KHR_audio_emitter extension
Based on glTF PR
Spec > Readme

Current Features:

  • Supported mimeTypes: wav, mp3, ogg
  • Runtime Import
  • Editor Export
  • Editor Import - as extracted audio files in a sub folder (because Unity/FMOD can't handle AudioClips as sub Assets currently, we're in discussion with Unity about that)

Supported Parameters:

  • Gain
  • Loop
  • autoPlay
  • Global/Positionial Emitters (AudioSource.spatialBlend < 0.5 is global, >= 0.5 is positional)

Work in Progress:

  • additional Parameters for positional emitters, also separate deserialization of KHR_PositionalAudioEmitter class
  • runtime export (would require runtime media recording and encoding)

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 17 out of 26 changed files in this pull request and generated 1 comment.

Files not reviewed (9)
  • Runtime/Plugins/GLTFSerialization/Extensions/KHR_audio_emitter.cs.meta: Language not supported
  • Runtime/Plugins/GLTFSerialization/Extensions/KHR_audio_emitterFactory.cs.meta: Language not supported
  • Runtime/Scripts/Plugins/Audio.meta: Language not supported
  • Runtime/Scripts/Plugins/Audio/TempAssignClip.cs.meta: Language not supported
  • Runtime/Scripts/Plugins/AudioExport.cs.meta: Language not supported
  • Runtime/Scripts/Plugins/AudioImport.cs.meta: Language not supported
  • Samples~/KHR_audio.meta: Language not supported
  • Samples~/KHR_audio/AudioSourceScriptableObject.cs.meta: Language not supported
  • Samples~/KHR_audio/KHRAudioSchemas.cs.meta: Language not supported
Comments suppressed due to low confidence (2)

Runtime/Scripts/Plugins/AudioExport.cs:150

  • The property 'Name' is used in the KHR_AudioSource initialization. Please ensure that the KHR_AudioSource schema has a corresponding property definition for 'Name' or remove it if not required.
Name = audioSourceId.Clip.name

Runtime/Scripts/Plugins/AudioExport.cs:185

  • The variable 'ermitterId' appears to be a misspelling of 'emitterId'. Renaming it will improve code readability and consistency.
var ermitterId = ProcessAudioSource(false, positionalSources.ToArray(), exporter, gltfRoot);

Comment on lines 234 to 256
var audioClipRequest = UnityWebRequestMultimedia.GetAudioClip(tempFile, GetAudioTypeForMimeType(audio.mimeType));
audioClipRequest.SendWebRequest();
while (!audioClipRequest.isDone)
{
// Wait for the request to complete
}

if (audioClipRequest.result != UnityWebRequest.Result.Success)
{
Debug.LogError($"Cannot load audio clip for mimeType {audio.mimeType}: {audioClipRequest.error}");
continue;
}

AudioClip clip = DownloadHandlerAudioClip.GetContent(audioClipRequest);
if (clip == null || clip.samples == 0)
{
Debug.LogError($"Cannot load audio clip for mimeType {audio.mimeType}");
continue;
}

clip.name = $"audio_{index:D3}";

_audioClips.Add(index, clip);
Copy link

Copilot AI Apr 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a busy-wait loop to wait for the UnityWebRequest to complete may block the main thread. Consider using a coroutine or async/await pattern to handle asynchronous operations more efficiently.

Suggested change
var audioClipRequest = UnityWebRequestMultimedia.GetAudioClip(tempFile, GetAudioTypeForMimeType(audio.mimeType));
audioClipRequest.SendWebRequest();
while (!audioClipRequest.isDone)
{
// Wait for the request to complete
}
if (audioClipRequest.result != UnityWebRequest.Result.Success)
{
Debug.LogError($"Cannot load audio clip for mimeType {audio.mimeType}: {audioClipRequest.error}");
continue;
}
AudioClip clip = DownloadHandlerAudioClip.GetContent(audioClipRequest);
if (clip == null || clip.samples == 0)
{
Debug.LogError($"Cannot load audio clip for mimeType {audio.mimeType}");
continue;
}
clip.name = $"audio_{index:D3}";
_audioClips.Add(index, clip);
StartCoroutine(LoadAudioClipCoroutine(tempFile, audio.mimeType, index));

Copilot uses AI. Check for mistakes.
@hybridherbst hybridherbst force-pushed the feature/KHR_audio_emitter branch from b9729a1 to 638db77 Compare April 15, 2025 14:04
@robertdorn83 robertdorn83 force-pushed the feature/KHR_audio_emitter branch from 638db77 to 071063d Compare May 15, 2025 07:07
@robertdorn83 robertdorn83 merged commit ef29060 into dev May 15, 2025
1 check passed
@hybridherbst hybridherbst deleted the feature/KHR_audio_emitter branch June 12, 2025 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants