Repository navigation
Conversation
|
Automated Claude review follows (not verified by me, I don't have time right now - but apparently you don't have access to LLM reviews): Bugs
Smaller issues
Design question for the author The delay is tied to the filter being reopened (AudioOutputSource::Open(), on output open or format change) and optionally to Reset(), not to the audio |
|
Thanks for posting the Clause review, it was very helpful. Commit ebe10e4 fixes the bugs and implements most of the suggestions reported in the Claude review, with the exception of the following items: copying the src data in FilterPCM() config ConfigBlock::GetDuration() "Add the missing , and includes, and remove the unused ." Missing test "design question for the author" There is a patch by @jkhabe included in #2588 (comment) which implements a start delay directly in the ALSA output plugin. So if you prefer that approach I will close this PR and perhaps @jkhabe or any other interested party will create a new PR based on that. |
I prefer amending the existing commit and force-pushing the PR branch. Tools like stgit can help with that. I want a PR branch to have properly separated commits, one commit for each aspect that gets changed. For a new plugin, that's just one commit, but if you need to do refactoring (e.g. sub-second support for ParseDuration()), make that a separate commit. But don't push fixup commits for unmerged commits.
No, it should be zero-copy as much as possible.
That would be a very useful feature to have, and indeed there's a TODO comment for exactly that. You can do this within this PR as a separate commit.
GitHub ate these XML tags when I copy'n'pasted it here:
Currently, there are no automated unit tests for filter plugins, but it would be good to have one. LLMs like to ask for unit tests when you ask them for a code review, and of course it's a good idea, but I'd accept a PR even if there's no unit test (as long as my own filter plugins don't lead by example).
I, too, found this comment hard to understand, so I asked Claude for a clarification; but first on your question where to put it: I think your idea to implement a filter plugin is good. It's abstract code that can be used in all plugins. The biggest problem here is that MPD's filters are difficult for users to configure. The configuration syntax is cumbersome, and I never put any effort in simplifying it. The comment is about when the PR's silence gets inserted, compared with when it is actually needed. What the device needs. An HDMI receiver or DAC drops samples when the audio stream starts from the device's point of view. In ALSA terms, that's the first
What the PR's filter reacts to. A filter can't see the device. It only sees its own lifetime:
So the filter infers "the stream (re)started" from these events, and they don't always match the device:
What I suggested instead. The output plugin knows exactly when it opens the device, drops the stream or resumes from pause. An ALSA output option, e.g.
It would also be configured where it belongs, in the audio_output block, instead of a separate filter block plus filters in each output. The trade-off: a filter works with every output plugin, while an output option would have to be added per plugin. Hence my question to the author: if #1312 |
ebe10e4 to
8b29d6a
Compare
MaxKellermann
left a comment
There was a problem hiding this comment.
First (human) look at the code.
| If this option is set to *no* in combination with **always_on** | ||
| set to *yes* then the ALSA device remains opened (but not | ||
| running) after playback stops. |
There was a problem hiding this comment.
Changes to ALSA documentation doesn't belong in this commit
There was a problem hiding this comment.
oops - this change wasn't meant for this branch. Will be removed in the next push.
| * - **delay_ms MS** | ||
| - The delay time in milliseconds. The default delay is 1000 ms. |
There was a problem hiding this comment.
Should be delay "1000ms", as suggested by Claude.
There was a problem hiding this comment.
This is on my todo list, I see it as a separate mini-project and will look at it when the other problems here have all been fixed.
| - Sets the loudness of the noise inserted during the delay, in | ||
| the range [0 - 255]. A value of 1 generates noise at -90.3 dBFS, | ||
| and 255 generates noise at -42.1 dBFS. Use the value 0 for | ||
| silence. The default value is 0. This option is ignored for DSD |
There was a problem hiding this comment.
This seemingly arbitrary range confuses me. Why 255 and why does 255 mean -42.1 dBFS? Why does 1 mean -90.3 dBFS?
There was a problem hiding this comment.
The range is arbitrary. There is no data available to indicate "correct" , "normal" or even "typical" values to be used here. The choice of [0-255] is simply so that the value fits in 8 bits. The mapping from "level" to dBFS is also arbitrary. Experiments with a small sample of affected systems indicated that approx -90dBFS was inaudible but effective at waking the device, so that guided the choice of lower bound. The actual values used are simply the result of using a simple bit-shift to convert "level" to amplitude. The algorithm and the documentation can all be changed if you have any thoughts on a more "logical" approach.
| silence. The default value is 0. This option is ignored for DSD | ||
| streams. | ||
| * - **on_reset yes|no** | ||
| - When yes, also delay the start when the filter is reset. |
There was a problem hiding this comment.
A start cannot be delayed if nothing is started. This wording is confusing.
There was a problem hiding this comment.
I will try to find better wording to describe this option in the next push.
| #include <utility> | ||
|
|
||
| /* To limit resource usage, the maximum delay buffer size is set to 300 KiB */ | ||
| static constexpr std::size_t DELAY_BUFFER_MAX_SIZE = 300 * 1024; |
There was a problem hiding this comment.
= 300_KiB; is simpler and you don't need to repeat it in the comment.
see util/ByteSizes.hxx.
There was a problem hiding this comment.
changed in my next push
| if (level > 0) | ||
| CreateNoise(buffer_frames, level); | ||
| else | ||
| PcmSilence({ delay_buffer.data(), delay_buffer.size() }, format.format); |
There was a problem hiding this comment.
{ delay_buffer.data(), delay_buffer.size() } -> delay_buffer
Why so complicated?
There was a problem hiding this comment.
Changed in the next push
| const bool negative = rng & 0x10000; | ||
|
|
||
| /* write the sample value to the byte array */ | ||
| switch (out_audio_format.format) { |
There was a problem hiding this comment.
Having the switch statement inside the loop will be very slow because it prevents both compiler and CPU from doing any optimizations.
There was a problem hiding this comment.
I've rewritten the CreateNoise function using templates and std::range::generate() which should resolve this issue. I am currently testing this change and will push when finished.
| switch (out_audio_format.format) { | ||
| case SampleFormat::S8: { | ||
| const std::int8_t val = negative ? -amplitude : amplitude; | ||
| std::memcpy(dest, &val, sizeof(val)); |
There was a problem hiding this comment.
Invoking memcpy() for each single byte is also pretty slow...
| AllocatedArray<std::byte> delay_buffer; | ||
| std::span<const std::byte> initial_data; | ||
| std::size_t delay_bytes_read; | ||
| bool on_reset; |
There was a problem hiding this comment.
Make fields const that will never be modified
There was a problem hiding this comment.
done in the next push
| { | ||
| auto next_chunk_size = std::min(delay_bytes - delay_bytes_read, delay_buffer.size()); | ||
| delay_bytes_read += next_chunk_size; | ||
| return std::span{delay_buffer.data(), next_chunk_size}; |
There was a problem hiding this comment.
std::span{delay_buffer}.first(next_chunk_size) is simpler and more robust.
There was a problem hiding this comment.
done in the next push
1296b8d to
0187149
Compare
|
Changes in today's push:
Issues still outstanding
|
|
Considering that one of the primary purposes of this filter is to produce an inaudible signal that wakes sleeping audio hardware, I feel that documenting its amplitude is particularly relevant. Personally, I think a comment along these lines of would be informative and useful to users: noise_level: Noise amplitude from 0 (silence) to 255. A value of 1 corresponds to approximately −90.3 dBFS peak amplitude for 16-bit and higher PCM formats. I'm still following your progress on this, and I appreciate all the work you're putting into it! |
A filter to insert a short prelude of silence or low-level noise at the start of a stream. Some devices drop samples at the start of playback as they perform a handshake protocol or power up idle circuits; and some require some non-zero samples before they begin their handshake. This issue is known to affect some HDMI devices, for example. Use this filter to ensure the samples dropped are not part of the first song. Closes MusicPlayerDaemon#2588 Closes MusicPlayerDaemon#1312 Co-authored-by: @jkhabe <jkhaberland@gmail.com>
0187149 to
062b560
Compare
A filter to insert a short prelude of silence or low-level noise at the start of a stream.
Some devices drop samples at the start of playback as they perform a handshake protocol or power up idle circuits; and some require some non-zero samples before they begin their handshake. This issue is known to affect some HDMI devices, for example.
Use this filter to ensure the samples dropped are not part of the first song.
Closes #2588
Closes #1312