Hello guys,
I’m trying to build a small working example using monogame, fmod with coreapi and resonanceaudio
in C# to get play one audio in 3d and with HRTF, but.
I got start all things fine. I created a small assembly with the c# fmod headers (to carry all of them in a dll) and the rest of things are in the game Class of the project.
I can without problems load the engine, load the resonanse pluygin, create the DSP and load and play the sound, but the sound ears without the spatialized effect; I based my code on a previous example that I saw on this forum, but it was in c++ and from middle 2018.
I don’t know if the resonance audio properties or similar things had been changed to this date; I can’t find any documentation about the parameters of resonance plugin, or which is the correct way to use it with core (or lowlevel api. All the documentation talks about the studio version.
Well, this is the code of my main class:
Can you detect something bad?
Thanks for your help
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using FMOD;
using System;
namespace game1_with_fmod_wrapper
{
/// <summary>
/// This is the main type for your game.
/// </summary>
public class Game1 : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
FMOD.System fmod;
ChannelGroup masterChannel;
ChannelGroup world3DChannel;
uint raHandle;
uint ralistenerHandle;
uint raSourceHandle;
DSP listenerDSP;
VECTOR listenerPos = new VECTOR { x = 10, y = 0, z = -5 };
VECTOR listenerVel = new VECTOR { x = 0, y = 0, z = 0 };
VECTOR listenerForward = new VECTOR { x = 0, y = 0, z = 1 };
VECTOR listenerUp = new VECTOR { x = 0, y = 1, z = 0 };
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{
// TODO: Add your initialization logic here
FMOD.Factory.System_Create(out fmod);
fmod.init(1024, INITFLAGS.NORMAL,(IntPtr)OUTPUTTYPE.AUTODETECT);
fmod.getMasterChannelGroup(out masterChannel);
fmod.createChannelGroup("world", out world3DChannel);
FMOD.RESULT ldpluginresult = fmod.loadPlugin("plugins/resonanceaudio.dll", out raHandle);
fmod.getNestedPlugin(raHandle, 0, out ralistenerHandle);
fmod.getNestedPlugin(raHandle, 2, out raSourceHandle);
fmod.createDSPByPlugin(ralistenerHandle, out listenerDSP);
world3DChannel.addDSP(FMOD.CHANNELCONTROL_DSP_INDEX.TAIL,listenerDSP);
fmod.set3DNumListeners(1);
fmod.set3DListenerAttributes(0,ref listenerPos, ref listenerVel, ref listenerForward, ref listenerUp);
base.Initialize();
}
/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
Sound jumpsound;
fmod.createSound("grito.wav", MODE._3D| MODE.LOOP_NORMAL, out jumpsound);
Channel jumpchannel;
fmod.playSound(jumpsound, world3DChannel,paused: true,channel: out jumpchannel);
fmod.createDSPByPlugin(raSourceHandle, out DSP sourceDSP);
jumpchannel.addDSP(FMOD.CHANNELCONTROL_DSP_INDEX.TAIL, sourceDSP);
VECTOR pos = new VECTOR { x = 30, y = 0, z = 0 };
VECTOR vel = new VECTOR { x = 0, y = 0, z = 0 };
jumpchannel.set3DAttributes(ref pos, ref vel);
jumpchannel.setPaused(false);
// TODO: use this.Content to load your game content here
}
/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// game-specific content.
/// </summary>
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
fmod.release();
}
/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
// TODO: Add your update logic here
fmod.update();
base.Update(gameTime);
}
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
// TODO: Add your drawing code here
base.Draw(gameTime);
}
}
}
Thanks again!