Skip to content

Adds boot sound playback during system startup#99

Merged
manvith12 merged 1 commit intomainfrom
make-a-sound
May 7, 2025
Merged

Adds boot sound playback during system startup#99
manvith12 merged 1 commit intomainfrom
make-a-sound

Conversation

@manvith12
Copy link
Copy Markdown
Contributor

@manvith12 manvith12 commented May 7, 2025

This change introduces a boot sound feature to provide auditory feedback when the system starts.

Key modifications include:

  • A new systemd service (boot-sound.service) is created to manage and play the sound. This service is configured to run early in the boot process, after essential sound drivers are loaded but before the full desktop environment, ensuring timely audio feedback.
  • The livecd-sound script is updated to unmute specific audio controls ("Master", "PCM") and play the startup sound (startup.wav) immediately after minimal sound card initialization.
  • A startup.wav sound file is added.
  • The ISO build script (build_iso.sh) is modified to include the new service in basic.target.wants and ensure the livecd-sound script has execute permissions.

Summary by CodeRabbit

  • New Features
    • Added a boot sound that plays early during system startup.
  • Improvements
    • Sound is initialized and unmuted automatically on the first suitable sound card.
    • Boot sound playback is now more reliable and occurs sooner in the startup process.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented May 7, 2025

Walkthrough

A boot sound feature was introduced by adding a new systemd service (boot-sound.service) that runs early in the startup process. The service ensures the sound card is initialized and unmutes it before playing a startup sound. The build script was updated to set executable permissions and adjust service activation to an earlier boot target.

Changes

File(s) Change Summary
configs/airootfs/etc/systemd/system/boot-sound.service New systemd service unit file added to initialize and unmute sound, then play a boot sound early in the boot process. Configured to run after sound card initialization but before most other services.
configs/airootfs/etc/systemd/system/basic.target.wants/boot-sound.service,
configs/airootfs/etc/systemd/system/multi-user.target.wants/boot-sound.service
Empty service unit symlink files created in respective systemd target directories to enable the service at boot.
configs/airootfs/usr/local/bin/livecd-sound The unmute_all_cards() function now unmutes and sets volume for only the first valid non-pcsp sound card, then immediately plays a startup sound, rather than configuring all cards.
scripts/build_iso.sh Ensures livecd-sound is executable and updates the systemd target for enabling boot-sound.service from multi-user.target.wants to basic.target.wants, creating the necessary directories and symlinks during ISO build.

Sequence Diagram(s)

sequenceDiagram
    participant systemd
    participant boot-sound.service
    participant livecd-sound
    participant sound_card

    systemd->>boot-sound.service: Start after sysinit.target, before basic.target
    boot-sound.service->>livecd-sound: Execute with --unmute
    livecd-sound->>sound_card: Unmute and set volume on first valid card
    livecd-sound->>sound_card: Play startup sound
Loading

Poem

🐇
Early in the morning, as the system wakes anew,
A gentle sound is played, a greeting just for you.
The rabbit set the volume, unmuted with great care,
Now every boot is cheerful, with music in the air!
🎶✨

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (5)
configs/airootfs/etc/systemd/system/multi-user.target.wants/boot-sound.service (1)

1-1: Enable under the correct target
The PR goal is to play the boot sound early (before basic.target), yet this link lives under multi-user.target.wants. Consider moving (or duplicating) it into basic.target.wants and removing it here to ensure proper boot ordering.

configs/airootfs/usr/local/bin/livecd-sound (2)

163-174: Optimization with a potential edge case

The change optimizes the sound initialization process by focusing on essential controls ("Master" and "PCM") for just the first valid sound card instead of applying numerous settings to all cards. This is a good performance improvement for boot time.

However, there's a potential issue: the function assumes the first numeric card ID is the correct one for audio playback. On systems with multiple sound cards, this might not select the card connected to speakers.

Consider adding a fallback mechanism if the first card doesn't produce audible output. For example:

 unmute_all_cards() {
     # Set only the essential controls for sound playback
     for card in $(list_non_pcsp_cards); do
         if is_numeric "$card"; then
             unmute_and_set_level "$card" "Master" "80%"
             unmute_and_set_level "$card" "PCM" "80%" 
             # Play sound immediately after minimal setup
-            play_on_card "$card" /usr/share/livecd-sounds/startup.wav &
-            break
+            if play_on_card "$card" /usr/share/livecd-sounds/startup.wav; then
+                # Successfully played on this card
+                break
+            fi
+            # If we reach here, try the next card
         fi
     done
 }

169-171: Consider adding error handling for sound playback

The script plays a sound immediately but doesn't handle potential failures in the audio playback.

Add simple error handling to log issues if sound playback fails:

-# Play sound immediately after minimal setup
-play_on_card "$card" /usr/share/livecd-sounds/startup.wav &
+# Play sound immediately after minimal setup
+if ! play_on_card "$card" /usr/share/livecd-sounds/startup.wav &> /dev/null &; then
+  systemd-cat -t "livecdsound" printf "Failed to play startup sound on card: %s\n" "$card"
+fi
scripts/build_iso.sh (1)

26-30: Add error checking for the boot sound configuration

While the changes are good, consider adding error checking to verify that the boot sound components are properly set up.

Add verification similar to other checks in the script:

# Add this to your build_iso.sh before creating the symlink
chmod +x configs/airootfs/usr/local/bin/livecd-sound

# Change from multi-user.target.wants to basic.target.wants
mkdir -p "$CONFIG_DIR/airootfs/etc/systemd/system/basic.target.wants"
ln -sf /etc/systemd/system/boot-sound.service "$CONFIG_DIR/airootfs/etc/systemd/system/basic.target.wants/boot-sound.service"

+# Verify boot sound setup
+if [ ! -x "$CONFIG_DIR/airootfs/usr/local/bin/livecd-sound" ]; then
+    echo -e "${RED}Error: livecd-sound script is not executable${NC}"
+    exit 1
+fi
+
+if [ ! -f "$CONFIG_DIR/airootfs/etc/systemd/system/boot-sound.service" ]; then
+    echo -e "${RED}Error: boot-sound.service file is missing${NC}"
+    exit 1
+fi
configs/airootfs/etc/systemd/system/boot-sound.service (1)

13-13: Consider a more precise sleep command

While the sleep command works, systemd provides a more precise timer unit that could be used instead.

You could replace the sleep command with a systematic delay:

-ExecStartPre=/usr/bin/sleep 0.5
+ExecStartPre=/bin/sh -c 'systemd-analyze log-level debug && echo "Waiting for sound hardware initialization..."'

Or keep the sleep but add a descriptive message:

-ExecStartPre=/usr/bin/sleep 0.5
+ExecStartPre=/bin/sh -c '/usr/bin/sleep 0.5 && echo "Sound hardware initialization delay complete"'
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d338716 and 58ba65c.

⛔ Files ignored due to path filters (1)
  • configs/airootfs/usr/share/livecd-sounds/startup.wav is excluded by !**/*.wav
📒 Files selected for processing (5)
  • configs/airootfs/etc/systemd/system/basic.target.wants/boot-sound.service (1 hunks)
  • configs/airootfs/etc/systemd/system/boot-sound.service (1 hunks)
  • configs/airootfs/etc/systemd/system/multi-user.target.wants/boot-sound.service (1 hunks)
  • configs/airootfs/usr/local/bin/livecd-sound (1 hunks)
  • scripts/build_iso.sh (1 hunks)
🔇 Additional comments (5)
configs/airootfs/usr/local/bin/livecd-sound (1)

170-170:

Details

✅ Verification successful

Verify sound file path exists

The code references /usr/share/livecd-sounds/startup.wav, but we should ensure this path exists and the file is available.


🏁 Script executed:

#!/bin/bash
# Check if the sound file directory and startup.wav exist
if [ ! -d "configs/airootfs/usr/share/livecd-sounds" ]; then
  echo "ERROR: Directory /usr/share/livecd-sounds does not exist in the build configuration"
  exit 1
fi

if [ ! -f "configs/airootfs/usr/share/livecd-sounds/startup.wav" ]; then
  echo "ERROR: startup.wav sound file not found in the build configuration"
  echo "Please ensure the file is added at configs/airootfs/usr/share/livecd-sounds/startup.wav"
  exit 1
else
  echo "Found startup.wav sound file"
  # Check if it's a valid WAV file
  file "configs/airootfs/usr/share/livecd-sounds/startup.wav"
fi

Length of output: 350


No action needed: startup.wav is present

The directory configs/airootfs/usr/share/livecd-sounds and the file startup.wav both exist in the build configuration, so the referenced path is valid.

scripts/build_iso.sh (2)

26-26: Good addition of executable permission

Setting executable permissions on the livecd-sound script is essential for the boot-sound service to function correctly.


29-30: Appropriate target change for earlier boot sound

Changing from multi-user.target.wants to basic.target.wants is appropriate for a boot sound service, as it will trigger the sound earlier in the boot process. This aligns well with the service's WantedBy=basic.target directive.

configs/airootfs/etc/systemd/system/boot-sound.service (2)

1-19: Well-structured service for early boot sound

The systemd service is well-designed for early boot sound playback:

  • Proper dependency ordering ensures it runs after sound drivers are loaded but before basic.target
  • DefaultDependencies=no allows it to start earlier in the boot process
  • Pattern matching for sound devices is a good approach to handle various hardware configurations
  • Timeout setting prevents hanging if there are issues

8-9: Robust sound card dependency handling

The pattern matching approach for sound card devices is excellent, as it handles systems with different sound hardware configurations and ensures the service waits for sound drivers to be loaded without waiting for the full sound.target.

@@ -0,0 +1 @@
/etc/systemd/system/boot-sound.service No newline at end of file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Missing service unit definition
This file appears to be only a symlink placeholder without the actual boot-sound.service unit file. The service cannot execute without a unit definition containing [Unit], [Service], and [Install] sections. Please add the full unit file at configs/airootfs/etc/systemd/system/boot-sound.service.

@@ -0,0 +1 @@
/etc/systemd/system/boot-sound.service No newline at end of file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Enable boot-sound.service via a symlink instead of a plain file
Systemd expects entries in the *.wants directories to be symbolic links to the actual unit file. A plaintext file containing the path will be ignored. Replace this file with a symlink pointing to ../boot-sound.service.

Proposed fix (in your build script or overlay manifest):

# Remove the incorrect plaintext file
rm configs/airootfs/etc/systemd/system/basic.target.wants/boot-sound.service

# Create the correct relative symlink
ln -s ../boot-sound.service configs/airootfs/etc/systemd/system/basic.target.wants/boot-sound.service

@manvith12 manvith12 merged commit 78c0640 into main May 7, 2025
5 checks passed
@manvith12 manvith12 self-assigned this May 7, 2025
@manvith12 manvith12 linked an issue May 7, 2025 that may be closed by this pull request
@manvith12 manvith12 deleted the make-a-sound branch May 8, 2025 04:58
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.

Replace mkinitcpio.conf with Ferrari-specific hooks

1 participant