resonance-audio / resonance-audio-web-sdk

Resonance Audio SDK for Web
https://resonance-audio.github.io/resonance-audio/
Apache License 2.0
200 stars 56 forks source link

Playing Ambisonic File with Resonace Audio Web SDK #12

Open prioleaud opened 6 years ago

prioleaud commented 6 years ago

Hi, This is my first time using Resonance Audio Web SDK and I'm unsure of how to play an ambisonic file with resonance audio. I followed the tutorial to play a monophonic file and changed "resonanceAudioScene.output.connect(audioContext.destination)" to "resonanceAudioScene.ambisonicOutput.connect(audioContext.destination)" and then I changed removed all the code for creating an audio input source.

So I remove: let source = resonanceAudioScene.createSource(); audioElementSource.connect(source.input); source.setPosition(-0.707, -0.707, 0);

And replaced it with:

audioElementSource.connect(resonanceAudioScene.ambisonicInput); //to add the Ambisonic soundfield.

Am I going about this correctly? Or am I missing something? Thanks for your help.

brianchirls commented 6 years ago

@prioleaud Have you tried Omnitone? That might be a more appropriate solution.

prioleaud commented 6 years ago

@brianchirls No I haven't tried it. Thanks for the suggestion! In what way, do you think it will be better suited?

noahneumark commented 6 years ago

Since Resonance Audio is powered by Omnitone, is there a way to access the Omnitone object from Resonance Audio, or do you have to load it separately? It would be great if there was some documentation on creating an ambisonic node and connecting it to the audioContext.

noahneumark commented 6 years ago

It seems as though all nodes created with cxt.createMediaElementSource() are one channel mono. I'm not sure how to feed the ambisonic input a 4-channel file. That seems to be the issue. Furthermore, it seems that regular single source nodes are converted to mono as well even if your

noahneumark commented 6 years ago

Okay I figured it out...

Live site: https://noahneumark.github.io/aframe-resonance-audio/

Code: https://github.com/noahneumark/spatial_audio

jwarchol commented 6 years ago

Thanks @noahneumark, just found this thread as I'm trying to do the same thing. Looking at your commits on your project, this seems more complicated than it should be. Appreciate you sharing this.

noahneumark commented 6 years ago

My component kit is complicated because it has far more features than just being an ambisonic player. That said, if you are just trying to implement playing ambisonic files, you need to include a function that does this (from resonance-audio-room component):

  connectBuffer() {

    //Create 4 channel splitter
    this.splitter = this.resonanceAudioContext.createChannelSplitter(4);

    //Connect bufferNode to splitter
    this.bufferNode.connect(this.splitter)

    //Create merger as ambisonicSourceNode
    this.ambisonicSourceNode = this.resonanceAudioContext.createChannelMerger()

    //Connect splitter to ambisonicSourceNode
    this.splitter.connect(this.ambisonicSourceNode, 0, 0)
    this.splitter.connect(this.ambisonicSourceNode, 1, 1)
    this.splitter.connect(this.ambisonicSourceNode, 2, 2)
    this.splitter.connect(this.ambisonicSourceNode, 3, 3)

    //Setup ambisonicInput to receive source
    this.resonanceAudioScene.ambisonicInput.channelInterpretation = "discrete"
    this.resonanceAudioScene.ambisonicInput.channelCountMode = "clamped-max"
    this.resonanceAudioScene.ambisonicInput.channelCount = 4

    //Connect ambisonicSourceNode to ambisonicInput
    this.ambisonicSourceNode.connect(this.resonanceAudioScene.ambisonicInput)

    //Set up
    this.resonanceAudioScene.ambisonicInput.gain.value = this.data.gain

    if (this.data.loop) {
      this.bufferNode.loop = true
    }
    if (this.data.autoplay && this.resonanceAudioContext.state === "running") {
      this.bufferNode.start()
    }
    this.connectedSrc = true
  }

Let me know if you have any questions about this.

hoch commented 5 years ago

As suggested by @brianchirls, you'd be better off using Omnitone if the goal is to simply play an ambisonic media. (FOA, SOA, TOA).

@prioleaud Please feel free to follow up or close the issue if needed.

jwarchol commented 5 years ago

At least some of the other Resonance implementations, iOS for example, seem to have playing sound fields as a feature. The confusion here is that the web SDK doesn't, though it seems to include internals to do so.

As for why not just using Omnitone, the reason is to combine sound fields with dynamically spatialize sounds.

hoch commented 5 years ago

@jwarchol That makes sense. Thanks for the clarification. So the solution is to expose the Omnitone decoder as a part of API?

jwarchol commented 5 years ago

Perhaps. I think @prioleaud's original notion of doing something like audioElementSource.connect(resonanceAudioScene.ambisonicInput); feels good, if that sort of an interface is possible.