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

A jack zero latency post #217

Merged
merged 28 commits into from
May 9, 2021
Merged

A jack zero latency post #217

merged 28 commits into from
May 9, 2021

Conversation

daschuer
Copy link
Member

No description provided.

@Be-ing
Copy link
Contributor

Be-ing commented Mar 18, 2021

build failed


## What comes next?

There is a chance to get rid of the extra latency in these cases, and make Mixxx use the buffer provided by Jack/Pipewire. This requires that Mixxx becomes a native Jack or Pipewire application.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why PortAudio can't do this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PortAudio Is only software, so it can be refactored to do this. And than Mixxx also need to be refactored to work with the new PortAudio API.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would this need a new PortAudio API? If PortAudio doesn't add any extra latency with ALSA then it is IMO a major bug if it does with JACK.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you reported this bug upstream to PortAudio?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a bug. It is an intended implementation detail. I had a discussion on the Portaudio Mailing list 5 years ago or such.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot find the discussion in the PortAudio mailing list archive. If PortAudio does not add any latency with ALSA it should be possible to do the same with JACK.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this bug is not fixable without a major refactoring, it may be better to write a new PipeWire backend for PortAudio.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, of cause, but that is not that easy, because Portaudio has an abstraction of sound cards. While Jack has just ports.
Portaudio gaps through Jack to get back the soundcard. This is nice to have a common interface for all APIs but comes at a cost of latency.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or maybe it would be better to switch to cpal after all...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand how PortAudio's abstractions require adding latency. If they don't for ALSA, they should not for JACK.

@Be-ing
Copy link
Contributor

Be-ing commented Mar 18, 2021

I'm not sure our blog is the best place to put this. IMO it belongs in a PortAudio bug report.

@daschuer
Copy link
Member Author

The intention is to get rid of the Jack has zero latency myth.
I am under the impression you also get hooked on it. There is no need for regular Mixxx users to do the hassle of setting up Jack.

@Be-ing
Copy link
Contributor

Be-ing commented Mar 18, 2021

We already have it documented in the manual to not use JACK if it is not required.

@Be-ing
Copy link
Contributor

Be-ing commented Mar 18, 2021

The intention is to get rid of the Jack has zero latency myth.

JACK does have zero latency. PortAudio adds latency. That is a bug.

@daschuer
Copy link
Member Author

I'm not sure our blog is the best place to put this. IMO it belongs in a PortAudio bug report.

This blog post not a bug report, just proves the current latency situation and give some insights how to measure round trip latency.
The question if this is a bug or not is out of scope. But it gives an outlook that we have the chance to improve the situation.

We have list of pending bugs here:
https://bugs.launchpad.net/mixxx/+bugs?field.tag=jack

So hopefully this creates some momentum to improve the situation that Mixxx can start polished into the PipWire age.

content/news/XXXX-XX-XX-jack-zero-latency.md Outdated Show resolved Hide resolved
content/news/XXXX-XX-XX-jack-zero-latency.md Outdated Show resolved Hide resolved
content/news/XXXX-XX-XX-jack-zero-latency.md Outdated Show resolved Hide resolved
content/news/XXXX-XX-XX-jack-zero-latency.md Outdated Show resolved Hide resolved
content/news/XXXX-XX-XX-jack-zero-latency.md Outdated Show resolved Hide resolved
content/news/XXXX-XX-XX-jack-zero-latency.md Outdated Show resolved Hide resolved
@daschuer
Copy link
Member Author

@Holzhaus thank you :-)

@daschuer
Copy link
Member Author

The batch commit button was grayed out for some reasons.

The file is prefixed with xxx but the date is set. How is this handled?

With this picture we can verify that Mixxx actually has the same buffer size in both cases. When pressing pause. It fades this signal out over one buffer length these is equal in both cases.
The peaks in the recorded right channel is the sound of the mouse click. You can only barely see the recorded sine wave.

![Screenshot of audacity showing the fade out]({static}/images/news/fadeoutcompare.png)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 minor nits:

  • You could run audacity on the command line with LANG=C to make the user interface english
  • I think audacity has a dark mode that you can use to make the screenshots fit better into the general theme of our website.

@Be-ing
Copy link
Contributor

Be-ing commented Mar 18, 2021

@@ -0,0 +1,44 @@
title: "Has JACK zero latency?"
authors: Daniel Schürmann
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add yourself to the AUTHORS_METADATA dict in the pelicanconf.py: https://github.com/mixxxdj/website/blob/website/pelicanconf.py#L158

Then run tools/update_avatars.py. It will automatically fetch your profile picture from github and add it to the source tree (don't forget to git add it).

Something like:

AUTHOR_METADATA = {
    # ...
    "daschuer": {
        "name": "Daniel Schürmann", 
        "github": "daschuer",
        "discourse": "daschuer", 
        "tagline": "Mixxx Core Developer", 
    },
}

The author information including the avatar will be displayed below the post.

content/news/XXXX-XX-XX-jack-zero-latency.md Outdated Show resolved Hide resolved
content/news/XXXX-XX-XX-jack-zero-latency.md Outdated Show resolved Hide resolved
@daschuer daschuer force-pushed the zeroLatency branch 2 times, most recently from 298d27f to daf5c71 Compare March 18, 2021 23:18
@ishitatsuyuki
Copy link

I came from RustAudio/cpal#560 and uh, this blog post does not explain anything.

The question if this is a bug or not is out of scope.

It's not OK because it attributes what is apparently a PortAudio flaw to JACK's fault. There's a problem with how it is written. Also, it doesn't give enough information to make this actionable. Please at least link to the PortAudio mailing list discussion which you think is the cause.

@daschuer
Copy link
Member Author

Thank you @ishitatsuyuki, for looking into this.

I came from RustAudio/cpal#560 and uh, this blog post does not explain anything.

This blog post was only intended to document the current situation and the way I have gathered the information. Do you recommend any changes?
I am happy to improve it.

It's not OK because it attributes what is apparently a PortAudio flaw to JACK's fault.

Is it? It is written from the Mixxx perspective where the user hast the choice between Jack and ALSA API.

Please propose a change that this post becomes OK to you.

Also, it doesn't give enough information to make this actionable.

I have no yet a action to improve the situation. This is just a finding. And the acting from the user perspective is: Use ALSA API.

Please at least link to the PortAudio mailing list discussion which you think is the cause.

I cannot find it after a quick search. I will try again.

I would be interesting to see the same graphs with CPAL. Can you share them at RustAudio/cpal#560

May be we can use them for a follow up post do document the current state with CPAL.

@ishitatsuyuki
Copy link

ishitatsuyuki commented Mar 20, 2021

This blog post was only intended to document the current situation and the way I have gathered the information. Do you recommend any changes?
I am happy to improve it.

You quote the JACK zero latency claim in the beginning of the post. This makes it look like you're attacking the claim.

Edit: After reading the post again, I think this one is actually fine.

The conclusion is also too generalized. You should emphasize that the problem is specific to Mixxx. I think you should write like "For now, we recommend using Mixxx with the ALSA backends even if you are running JACK. The same applies to PipeWire as Mixxx uses JACK protocol to connect to it."

Finally, you claim that "This requires that Mixxx becomes a native Jack or Pipewire application" without any investigation into the PortAudio internals. The claim is unprofessional at best, and dubious at worst.

I would be interesting to see the same graphs with CPAL.

Your blog post doesn't describe the exact method used to take the recording. The software used is probably Audacity, but how did you record the output buffers (in particular when using ALSA directly)? Did you use a loopback?

If what we want to know is whether a library's abstraction adds latency, then I think a good idea is to reimplement something like the jack_iodelay tool with that library. I'll try doing that and report the results.

@Be-ing
Copy link
Contributor

Be-ing commented Mar 20, 2021

I agree that it's not fair to imply that JACK is the problem here when the problem is PortAudio.

@Be-ing
Copy link
Contributor

Be-ing commented Mar 20, 2021

May be we can use them for a follow up post do document the current state with CPAL.

This would not be appropriate for our blog. Our blog is for communicating with Mixxx users. It is not a discussion forum for considering the technical challenges Mixxx faces; that is what we have Zulip for.

@daschuer
Copy link
Member Author

daschuer commented Mar 20, 2021

Thank you @ishitatsuyuki, I will update the blog post with your suggestions.

Your blog post doesn't describe the exact method used to take the recording.

I have played a 440 Hz sine wave with Mixxx on the left channel and the microphone input on the right channel. The feedback loop was closed via air. Than I use the recording feature of Mixxx to record the result. Audacity is used vor visualize the results and to compare the recordings.

I don't think you can use jack_iodelay directly because it does not use CPAL but the approach in general will work.

@Holzhaus
Copy link
Member

May be we can use them for a follow up post do document the current state with CPAL.

This would not be appropriate for our blog. Our blog is for communicating with Mixxx users. It is not a discussion forum for considering the technical challenges Mixxx faces; that is what we have Zulip for.

I agree that it's not the right place for discussion, but I don't think that was @daschuer's intention. I think it's interesting for our users to follow the development progress and how we tackle obstacles and challenges. Your build infrastructure blog post is an example of that.

@Be-ing
Copy link
Contributor

Be-ing commented Mar 20, 2021

I have played a 440 Hz sine wave with Mixxx on the left channel and the microphone input on the right channel. The feedback loop was closed via air. Than I use the recording feature of Mixxx to record the result.

How did you do this considering Mixxx cannot record separate channels, only a single stereo mix?

@Be-ing
Copy link
Contributor

Be-ing commented Mar 20, 2021

I think it's interesting for our users to follow the development progress and how we tackle obstacles and challenges. Your build infrastructure blog post is an example of that.

Yes, I agree. But that post was made after we had a solution to show, not to start a discussion.

@daschuer
Copy link
Member Author

I have played a 440 Hz sine wave with Mixxx on the left channel and the microphone input on the right channel. The feedback loop was closed via air. Than I use the recording feature of Mixxx to record the result.

How did you do this considering Mixxx cannot record separate channels, only a single stereo mix?

Via the balance effect. I have added it to the blog.

@daschuer
Copy link
Member Author

May be we can use them for a follow up post do document the current state with CPAL.

This would not be appropriate for our blog. Our blog is for communicating with Mixxx users. It is not a discussion forum for considering the technical challenges Mixxx faces; that is what we have Zulip for.

Yes right. May be we can reference the results as an amendment, to this if it contains user relevant Info.

daschuer and others added 19 commits May 9, 2021 01:47
Co-authored-by: Jan Holthuis <holthuis.jan@googlemail.com>
Co-authored-by: Jan Holthuis <holthuis.jan@googlemail.com>
Co-authored-by: Jan Holthuis <holthuis.jan@googlemail.com>
Co-authored-by: Jan Holthuis <holthuis.jan@googlemail.com>
Co-authored-by: Jan Holthuis <holthuis.jan@googlemail.com>
Co-authored-by: Jan Holthuis <holthuis.jan@googlemail.com>
Co-authored-by: Jan Holthuis <holthuis.jan@googlemail.com>
Co-authored-by: Jan Holthuis <holthuis.jan@googlemail.com>
Co-authored-by: ronso0 <ronso0@mixxx.org>
Co-authored-by: ronso0 <ronso0@mixxx.org>
Co-authored-by: ronso0 <ronso0@mixxx.org>
Co-authored-by: ronso0 <ronso0@mixxx.org>
Co-authored-by: ronso0 <ronso0@mixxx.org>
@Holzhaus
Copy link
Member

Holzhaus commented May 8, 2021

Please rebase on latest website, maybe it's already been fixed.

Nope, the update_avatars,py script is just out of date. I'll remove it, because it's obsolete.

You can just build the page locally and it automatically fetches the avatar to the right directory:

(venv) $ pelican
WARNING: Feeds generated without SITEURL set properly may not be valid
WARNING: Missing avatar for author 'Daniel Schürmann', expected /home/jan/Projects/mixxx-website/content/images/avatars/daschuer.png
WARNING: Downloaded missing avatar to: /home/jan/Projects/mixxx-website/content/images/avatars/daschuer.png
Done: Processed 140 articles, 1 draft, 9 pages, 0 hidden pages and 0 draft pages in 3.06 seconds.
(venv) $ git status
On branch test
Untracked files:
  (use "git add <file>..." to include in what will be committed)
	content/images/avatars/daschuer.png

nothing added to commit but untracked files present (use "git add" to track)

@daschuer
Copy link
Member Author

daschuer commented May 8, 2021

The issue persists after rebase.

@Holzhaus
Copy link
Member

Holzhaus commented May 8, 2021

The issue persists after rebase.

Sorry, that comment was wrong, try this please: #217 (comment)

@Holzhaus
Copy link
Member

Holzhaus commented May 8, 2021

Nope, the update_avatars,py script is just out of date. I'll remove it, because it's obsolete.

#240

@Holzhaus
Copy link
Member

Holzhaus commented May 9, 2021

In short, run these commands:

$ python3 -m venv venv                    # Create a virtual environment named "venv"
$ source venv/bin/activate                # Activate the virtual environment
(venv) $ pip install -r requirements.txt  # Install requirements to build website into the venv
(venv) $ pelican                          # Build website
(venv) $ deactivate                       # Leave virtual environment
$ git add content/images/avatars

Next time you want to build the website:

$ source venv/bin/activate                # Activate the virtual environment
(venv) $ pelican                          # Build website

@Holzhaus
Copy link
Member

Holzhaus commented May 9, 2021

Thank you!

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

Successfully merging this pull request may close these issues.

5 participants