System Audio output is delayed

Hi,

I am experiencing long delays when outputting sounds like MP4 and WAV to the system audio consumer. System audio in my case is the mini jack out.

When I start CasparCG the delay from PLAY to actualling playing in the speakers is typically really low (<500ms) - but after a while, the delay from command PLAY and CLEAR is up to 7-8 seconds.

Yes - even the CLEAR command is delayed. So if I want to stop an audio playing on channel 7 it sometimes takes 7 seconds.

There is no delay on the video outputs.

Can anyone suggest a solution/workaround?

Here is my config file:

<configuration>

<log-level></log-level>

<paths>

<media-path>/opt/Falcon/media/</media-path>

<log-path>log/</log-path>

<data-path>data/</data-path>

<font-path>font/</font-path>

<template-path>/opt/Falcon/graphics/</template-path>

</paths>

<lock-clear-phrase>secret</lock-clear-phrase>

<channels>

<channel>

<video-mode>1080p5000</video-mode>

<consumers>

<decklink>

<device>1</device>

<key-device>0</key-device>

<embedded-audio>true</embedded-audio>

<latency>low</latency>

<keyer>default</keyer>

<key-only>false</key-only>

<buffer-depth>3</buffer-depth>

</decklink>

</consumers>

</channel>

<channel>

<video-mode>1080p5000</video-mode>

<consumers>

<decklink>

<device>2</device>

<key-device>0</key-device>

<embedded-audio>true</embedded-audio>

<latency>low</latency>

<keyer>default</keyer>

<key-only>false</key-only>

<buffer-depth>3</buffer-depth>

</decklink>

</consumers>

</channel>

<channel>

<video-mode>1080p5000</video-mode>

<consumers>

<decklink>

<device>3</device>

<key-device>0</key-device>

<embedded-audio>true</embedded-audio>

<latency>low</latency>

<keyer>default</keyer>

<key-only>false</key-only>

<buffer-depth>3</buffer-depth>

</decklink>

</consumers>

</channel>

<channel>

<video-mode>1080p5000</video-mode>

<consumers>

<decklink>

<device>4</device>

<key-device>0</key-device>

<embedded-audio>true</embedded-audio>

<latency>low</latency>

<keyer>default</keyer>

<key-only>false</key-only>

<buffer-depth>3</buffer-depth>

</decklink>

</consumers>

</channel>

<channel>

<video-mode>1080p5000</video-mode>

<consumers>

<decklink>

<device>5</device>

<key-device>0</key-device>

<embedded-audio>true</embedded-audio>

<latency>normal</latency>

<keyer>external</keyer>

<key-only>false</key-only>

<buffer-depth>5</buffer-depth>

</decklink>

</consumers>

</channel>

<channel>

<video-mode>1080p5000</video-mode>

<consumers>

<decklink>

<device>6</device>

<key-device>0</key-device>

<embedded-audio>true</embedded-audio>

<latency>normal</latency>

<keyer>external</keyer>

<key-only>false</key-only>

<buffer-depth>5</buffer-depth>

</decklink>

</consumers>

</channel>

<channel>      

<consumers>

<system-audio>

<channel-layout>stereo</channel-layout>

<latency>200</latency>

</system-audio>

</consumers>

</channel>    

</channels>

<controllers>

<tcp>

<port>5250</port>

<protocol>AMCP</protocol>

</tcp>

</controllers>

<amcp>

<media-server>

<host>localhost</host>

<port>8000</port>

</media-server>

</amcp>

<flash>

<buffer-depth>auto</buffer-depth>

<enabled>false</enabled>

</flash>

<html>

<remote-debugging-port>0</remote-debugging-port>

<enable-gpu>false</enable-gpu>

</html>

<ffmpeg>

<producer>

<auto-deinterlace>interlaced</auto-deinterlace>

<threads>4</threads>

</producer>

</ffmpeg>

<ndi>

<auto-load>false</auto-load>

</ndi>

<osc>

<default-port>6250</default-port>

<disable-send-to-amcp-clients>false</disable-send-to-amcp-clients>

<predefined-clients />

</osc>

</configuration>

For a better overview I reposte you config properly formated:

<configuration>
	<log-level/>
	<paths>
		<media-path>/opt/Falcon/media/</media-path>
		<log-path>log/</log-path>
		<data-path>data/</data-path>
		<font-path>font/</font-path>
		<template-path>/opt/Falcon/graphics/</template-path>
	</paths>
	<lock-clear-phrase>secret</lock-clear-phrase>
	<channels>
		<channel>
			<video-mode>1080p5000</video-mode>
			<consumers>
				<decklink>
					<device>1</device>
					<key-device>0</key-device>
					<embedded-audio>true</embedded-audio>
					<latency>low</latency>
					<keyer>default</keyer>
					<key-only>false</key-only>
					<buffer-depth>3</buffer-depth>
				</decklink>
			</consumers>
		</channel>
		<channel>
			<video-mode>1080p5000</video-mode>
			<consumers>
				<decklink>
					<device>2</device>
					<key-device>0</key-device>
					<embedded-audio>true</embedded-audio>
					<latency>low</latency>
					<keyer>default</keyer>
					<key-only>false</key-only>
					<buffer-depth>3</buffer-depth>
				</decklink>
			</consumers>
		</channel>
		<channel>
			<video-mode>1080p5000</video-mode>
			<consumers>
				<decklink>
					<device>3</device>
					<key-device>0</key-device>
					<embedded-audio>true</embedded-audio>
					<latency>low</latency>
					<keyer>default</keyer>
					<key-only>false</key-only>
					<buffer-depth>3</buffer-depth>
				</decklink>
			</consumers>
		</channel>
		<channel>
			<video-mode>1080p5000</video-mode>
			<consumers>
				<decklink>
					<device>4</device>
					<key-device>0</key-device>
					<embedded-audio>true</embedded-audio>
					<latency>low</latency>
					<keyer>default</keyer>
					<key-only>false</key-only>
					<buffer-depth>3</buffer-depth>
				</decklink>
			</consumers>
		</channel>
		<channel>
			<video-mode>1080p5000</video-mode>
			<consumers>
				<decklink>
					<device>5</device>
					<key-device>0</key-device>
					<embedded-audio>true</embedded-audio>
					<latency>normal</latency>
					<keyer>external</keyer>
					<key-only>false</key-only>
					<buffer-depth>5</buffer-depth>
				</decklink>
			</consumers>
		</channel>
		<channel>
			<video-mode>1080p5000</video-mode>
			<consumers>
				<decklink>
					<device>6</device>
					<key-device>0</key-device>
					<embedded-audio>true</embedded-audio>
					<latency>normal</latency>
					<keyer>external</keyer>
					<key-only>false</key-only>
					<buffer-depth>5</buffer-depth>
				</decklink>
			</consumers>
		</channel>
		<channel>
			<consumers>
				<system-audio>
					<channel-layout>stereo</channel-layout>
					<latency>200</latency>
				</system-audio>
			</consumers>
		</channel>
	</channels>
	<controllers>
		<tcp>
			<port>5250</port>
			<protocol>AMCP</protocol>
		</tcp>
	</controllers>
	<amcp>
		<media-server>
			<host>localhost</host>
			<port>8000</port>
		</media-server>
	</amcp>
	<flash>
		<buffer-depth>auto</buffer-depth>
		<enabled>false</enabled>
	</flash>
	<html>
		<remote-debugging-port>0</remote-debugging-port>
		<enable-gpu>false</enable-gpu>
	</html>
	<ffmpeg>
		<producer>
			<auto-deinterlace>interlaced</auto-deinterlace>
			<threads>4</threads>
		</producer>
	</ffmpeg>
	<ndi>
		<auto-load>false</auto-load>
	</ndi>
	<osc>
		<default-port>6250</default-port>
		<disable-send-to-amcp-clients>false</disable-send-to-amcp-clients>
		<predefined-clients/>
	</osc>
</configuration>

What I see is, that you use an individual channel for audio. That is weird. The best way to keep audio and video in sync is to use the audio coming from the Decklink either via audio outs (if the card supports it) or embedded audio.

Another way to keep it more in sync (you need to test if it drifts away over time) is to use config-nodes like this one:

		<channel>
			<video-mode>1080p5000</video-mode>
			<consumers>
				<decklink>
					<device>1</device>
					<key-device>0</key-device>
					<embedded-audio>true</embedded-audio>
					<latency>low</latency>
					<keyer>default</keyer>
					<key-only>false</key-only>
					<buffer-depth>3</buffer-depth>
				</decklink>
				<system-audio>
					<channel-layout>stereo</channel-layout>
					<latency>200</latency>
				</system-audio>
			</consumers>
		</channel>

Where you add the audio directly to the channel.

Totally agree it would be more stable to use a decklink output for this and deembed the sound.

But the customer wants it the other way - he wants to use the mini jack output only :slight_smile:

There is no video - so no sync with video is needed. It is a pure audio player.

But there is a “dynamic/random” delay - and thats wierd :slight_smile:

Why are there six video channels, when you only use the audio? Would it then not be a better idea to use a random audio player software for this, instead of Caspar?

Caspars system-audio is more meant for a testing, than actually using (as it is also in a way for the screen consumer).

There a good reason behind this build :slight_smile:

The other decklink outputs are being used for video. And we want to explore making another channel for system audio only. It’s working quite fine - it’s just drifting randomly.

The question is not to change the workflow and build - I just want to know, if there is anything we can do about the drift in the system audio channel :slight_smile:

I see. Hmmm. I actually don’t know. You maybe could try different Caspar server versions to check if they do the same. Sometimes newer (or older) versions behave differently.

Maybe you could add an extra Decklink card and use that as audio only. But that may fail because of missing extra PCIe lanes…

I’m sorry I do not have a direct answer, but I hope the thoughts below may help isolate the issue for you.

  1. Does the DIAG tool show any significant canges for the audio-only channel between the inital processing and when you are seeing the control delay?

  2. When the problem is happening, is there any worthwhile information revealed by setting

    LOG LEVEL TRACE
    One small caveat - once TRACE mode is set you may find it difficult to stop the trace output without a CasparCG server reboot.

  3. How much spare computation capacity is available? Does the slow response start only after playing complex actions in the video channels?

  4. Are all items sent to the audio-only channel pure audio? Even though you have not defined a consumer for the video, the channel has the channel mixer module initialised and the video mode is set, by default, to PAL.

    So if the sources have video at non-PAL sizes or rates it is possible that there is a hidden standards convert process using compute resources even though the video result is never sent to a video consumer. If there are video clips used just for their audio, it may be appropriate to set the channel definition to match the standard video modes as this should avoid the standards convert operations.

  5. Will you ever need to look at the OSC status data for the audio channel with some other application? If so, note that there is no OSC data for the audio-only channel unless it is playing media. When the media stops, so does the OSC status report(s). If there is a video consumer attached the OSC status is continuous.

  6. Maybe try two instances of the server code - one running the video channels and the second managing the audio-only channel.

I agree with @didikunz that the audio out from the system audio route has, thus far, been mostly used for testing, but I note your actions are somewhat constrained by your client’s requests. At some future date there is a potential problem that Windows could play an alert/alarm note that will be mixed with your audio channel output. Probably not what your client wants.

When CasparCG server 2.4.0 was released it included the ability to set an audio device that is not the default Windows sound output device. If the client wants the audio channel output via the standard jack, it may be worth installing a cheap USB sound device that is used as the system sounds device, leaving the audio jack for the audio only channel. The target audio output device has to be set in the casparcg.config file as a stand alone section. The syntax is (even though we want a consumer):

<system-audio>
   <producer>
      <default-device-name>name goes here</default-device-name>
   </producer>
</system-audio>

During server startup the console displays the names of all the audio devices it found by enumeration, and reports if it could open your named device.

The final note is that you can remove the and tags inside the tags. The code to process these values was removed when server version 2.2 was released, as this version was the first to implement audio pass-through. But the sample configuration layout in the distributed casparcg.config did not get edited until server 2.5.0 was issued.