Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading/Playing an audio file in Unity #257

Open
cdraudio opened this issue Mar 22, 2018 · 9 comments
Open

Loading/Playing an audio file in Unity #257

cdraudio opened this issue Mar 22, 2018 · 9 comments
Labels

Comments

@cdraudio
Copy link

I'm currently having trouble loading/playing back an audio file in Unity.

I have a simple patch (link below) based on the js "loading samples" example. Originally I compiled and tested it in Wwise and everything worked as expected. I've now tried to integrate essentially the same patch in Unity and I'm not getting any audio when playing the scene.

https://enzienaudio.com/h/cdraudio/UnitySampTest_03/

  • The AudioLib.dll settings should be correct

audiolibdllsettings

  • The .cs file is attached to a cube
  • 'Play on awake' is selected

hvcubeaudiosource

  • Added a 'Load Sample' script (HvLoadSample.cs) containing the following:

`using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class HvLoadSample : MonoBehaviour {

public AudioClip clip;
private Hv_UnitySampTest_03_AudioLib _audio;

void Start ()
{
    _audio = GetComponent<Hv_UnitySampTest_03_AudioLib>();
    _audio.FillTableWithMonoAudioClip("myTable", clip);
}

}
`

I would be expecting the sample to play once the scene launches but I'm getting nothing. Not sure if I've missed a step somewhere or if there's a different method of setting the table size that should be used in Unity instead of the [r setTableSize-myTable]?

@diplojocus
Copy link
Contributor

diplojocus commented Mar 26, 2018

@cdraudio sorry yeah that javascript example is slightly out of date, the [r setTableSize-myTable] is being handled manually in the js part of the example.

Try using this looper patch here: https://enzienaudio.com/h/enzienaudio/looper/

It's very similar to what you have, though the sample loader script looks like this:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LooperController : MonoBehaviour {

  public AudioClip clip;
  private Hv_looper_AudioLib looper;

    void Start () {
        looper = GetComponent<Hv_looper_AudioLib>();

        // expecting a stereo file
        float[] buffer = new float[clip.samples];

        // fill the left channel
        clip.GetData(buffer, 0);
        looper.FillTableWithFloatBuffer("channelL", buffer);

        // fill the right channel
        clip.GetData(buffer, 1);
        looper.FillTableWithFloatBuffer("channelR", buffer);

        // update the table size parameter
        looper.SetFloatParameter(Hv_looper_AudioLib.Parameter.Tablesize, clip.samples);
    }
}

Note the looper.SetFloatParameter at the end is notifying the patch of the buffer length. I don't think was happening in your code so you'll never hear anything.

@diplojocus
Copy link
Contributor

I've actually been working on a nice feature to auto expose an AudioClip interface in the Unity inspector for tables within the patch. Stay tuned!

@diplojocus
Copy link
Contributor

I’ve pushed an update to the unity target on the dev channel of heavy to support @hv_table. If you have a table object declared like: [table dogwoof 0 @hv_table], in the unity inspector it’ll auto generate an AudioClip interface to drag and drop samples that will be loaded when the game starts

@cdraudio
Copy link
Author

Thanks for the reply. I'll try that out now.

@diplojocus
Copy link
Contributor

hey @cdraudio did you managed to get it working?

@cdraudio
Copy link
Author

Sorry for the late reply @diplojocus. Yeah, got the script and patch working fine though I've ran into a couple other issues. I can open a separate thread for them, though one that relates to this was an issue with 3D positioning of the audio source. Volume attenuation works fine but there's no panning. Noticed this was brought up in #112. Was this ever resolved or should I look into the work arounds mentioned in the thread?

@kretopi
Copy link

kretopi commented Jun 21, 2018

What about stereo file? I've tried load stereo but channels left and right was same. When I've separated it in DAW and made left and right channel, then load them, it play correctly. I wonder is there a way to load stereo file, divided it to left and right channel and then load them to 2 tables?

@diplojocus
Copy link
Contributor

Currently it will load the first channel (left) of a stereo file into the table. Your method of separating the files into individual channels sounds correct. You could probably create a batch script to automate splitting the bounces from your DAW.

Pd doesn't really have a concept of stereo when patching as you can have as many channels as you want.

@kretopi
Copy link

kretopi commented Jun 21, 2018

@diplojocus ok, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants