惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
博客园 - 三生石上(FineUI控件)
爱范儿
爱范儿
Vercel News
Vercel News
aimingoo的专栏
aimingoo的专栏
The GitHub Blog
The GitHub Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
A
About on SuperTechFans
H
Hackread – Cybersecurity News, Data Breaches, AI and More
量子位
Hugging Face - Blog
Hugging Face - Blog
C
Check Point Blog
Engineering at Meta
Engineering at Meta
有赞技术团队
有赞技术团队
月光博客
月光博客
M
MIT News - Artificial intelligence
V
Visual Studio Blog
Stack Overflow Blog
Stack Overflow Blog
阮一峰的网络日志
阮一峰的网络日志
D
DataBreaches.Net
I
InfoQ
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Cloudflare Blog
雷峰网
雷峰网

Leo's Field

Don't nuke my docker network, nftables.service! - Leo's Field Sending Emails, with netcat - Leo's Field Use ZED with msmtp on Debian - Leo's Field Have fun with ZFS: Maintenance and Error Recovery - Leo's Field Have fun with ZFS: Tuning - Leo's Field Have fun with ZFS: Setting up storage pool - Leo's Field 2021 Recap: Seek - Leo's Field Deploying this site on CloudFlare Pages - Leo's Field Redesigning this blog - Leo's Field Homelab Project: 6 months in - Leo's Field Fix incompatible bytes library for actix-web and tokio - Leo's Field A Breif Look at Linux's Audio System - Leo's Field Build Fcitx5 IM module for proprietary software with its Qt library - Leo's Field Way to AOSC OS Maintainer: Advanced Techniques - Leo's Field Way to AOSC OS Maintainer: Basics - Leo's Field Have fun with ZFS: Introduction - Leo's Field Fix clipboard permission on Android 10 - Leo's Field MDR-7506 Detachable Cable Mod - Leo's Field Update firmware of a Crucial SSD with systemd-boot - Leo's Field Install Arch Linux, using a Sony Walkman - Leo's Field Coreboot, me_cleaner, Tianocore, ThinkPad X220 - Leo's Field Dark mode! - Leo's Field Links - Leo's Field Some notes about the creation of this blog - Leo's Field Hello, world! - Leo's Field About - Leo's Field
Record to MiniDisc with correct Track Marker on Linux - L...
Leo Shen · 2020-03-26 · via Leo's Field

If you want to use the method here, don't forget to adjust the commands accordingly so that it fits your sound card. You can find information via executing amixer -c CARD_ID.

So, I have to find a way to mute the sound output just before the audio stream is closed. The best way would be to find a simple command line audio player with the minimal number of code, since I don't want to view a huge codebase and potentially mess everything up. Fortunately, there's a program called ogg123, created by the awesome lads at Xiph.org Foundation1. This is a very basic audio player, which is desirable for this project.

After grabbing a copy of vorbis-tools (which contains ogg123), we can take a look. The main sound output codes are located at ogg123/audio.c. And surely, there is a function called void free_audio_devices. All we have to do should be add some codes to mute the output before the free process actually begins.

I can do it cleanly by using the user space library for ALSA, but that means I may have to investigate a good amount of hours into learning, and I'm kinda busy. So nah, I just hacked it.

Since we already know how to use amixer to mute the command, we can just use system() function (provided by stdlib.h) to execute a shell command. It is not expandable and flexible AT ALL, but it works and it does not kill my brain cells.

So, the free_audio_devices looks like this now:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
void free_audio_devices (audio_device_t *devices)
{
  audio_device_t *current;

  system("amixer -c 0 set 'IEC958',0 mute");

  while (devices != NULL) {
    current = devices->next_device;
    free (devices);
    devices = current;
  }
}

Then we can trigger make and compile the patched code. Since I don't want to use this version globally, I did not install it.

Then the updated script should look like this:

1
2
3
4
5
6
7
8
#!/bin/bash
while read file
do
	amixer -c 0 set 'IEC958',0 unmute
	sleep 1.1s
	/$SOMEWHERE/vorbis-tools-1.4.0/ogg123/ogg123 -d alsa --device-option dev:hw:0,1 "$file"
	sleep 1s
done <$1

Since now ogg123 is responsible to mute the output, we can save a line here.

And now it works! No more additional empty tracks, only accurate track data.