Hi everyone,
I’m facing an issue when using a custom Opus codec with FMOD in my Unity c# test project. I am playing multiple stems at the same time, and I need to be able to seek to different positions in these stems at the same time. The problem occurs when seeking the stems to a new position (e.g., 25000 PCM samples), where FMOD provides an incorrect position that actually ahead of the requested position for some of the stems.
This issue only happens when using the custom Opus codec, and not when using other codecs. Additionally, the issue is only present when using createStream
, and not when loading .opus sounds with createSound
.
I’ve tried pausing all stems before seeking and then resuming playback, but the issue persists. I’ve also tried using system.lockDSP and unlock, before and after seeking but this just reduces the possibility of the issue happening. I have also verified that the incorrect position is being passed to the codec callback for some stems by logging/debugging the position values in the SetPosition callback as shown in the following screenshots:
- Callback being passed the correct position
- Callback being passed a position that’s ahead of the one requested in the C# code
Here is the relevant C# test code:
`using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FMODUnity;
using System.IO;
using System;
using System.Runtime.InteropServices;
public class TestFMODOpus : MonoBehaviour
{
List<FMOD.Sound> sounds = new List<FMOD.Sound>();
FMOD.ChannelGroup channelGroup;
List<FMOD.Channel> channels = new List<FMOD.Channel>();
FMOD.System system;
// Start is called before the first frame update
void Start()
{
system = FMODUnity.RuntimeManager.CoreSystem;
system.getMasterChannelGroup(out channelGroup);
}
public void LoadAudioFromFolder(string folderPath)
{
if (Directory.Exists(folderPath))
{
string[] opusFiles = Directory.GetFiles(folderPath, "*.opus");
foreach (string opusFile in opusFiles)
{
LoadAudio(opusFile);
}
foreach (FMOD.Channel channel in channels)
{
channel.setPosition(125 * 48000, FMOD.TIMEUNIT.PCM); //6,000,000 PCM
}
foreach (FMOD.Channel channel in channels)
{
channel.setPaused(false);
}
}
else
{
Debug.LogError("Folder path not found: " + folderPath);
}
}
private void LoadAudio(string path)
{
FMOD.RESULT result;
FMOD.Sound sound;
// Load the sound from the provided path
result = system.createStream(path, FMOD.MODE.DEFAULT | FMOD.MODE.ACCURATETIME, out sound);
result = system.playSound(sound, channelGroup, true, out FMOD.Channel channel);
channels.Add(channel);
if (result != FMOD.RESULT.OK)
{
Debug.LogError("FMOD Error: " + result + " - Failed to load sound: " + path);
return;
}
sounds.Add(sound);
}
void releaseSounds()
{
foreach (FMOD.Sound sound in sounds)
{
sound.release();
}
}
void OnDestroy()
{
releaseSounds();
}
}`
Could you please provide guidance on how to resolve this issue, or let me know if there is a potential bug within the FMOD API that might be causing this problem? I can also send the opus codec code if needed.
Thank you in advance for your assistance.
(I apologize if the topic is duplicated, the spam filter catched the first post and I can’t find it nowhere even after it supposedly being released by an admin.)