Archive for the ‘Webtechnology’ Category

No Comments

Debugging Audio problems on a Raspberry Pi

Sunday, February 21st, 2021

A Raspberry Pi is a great small computer that can run 24 hours with no problem, and just consumes a few watts, so it’s a fine candidate for a modern flexible media player.

The default high quality sound output of a Raspberry Pi is HDMI, which is great for video, but not so great for classic stereo systems. The standard analogue out is near CD quality. Fine for system sounds and video calling, but not enough for HiFi. Remember the Pi is designed as a cheap computer for educational purposes.

HiFi audiophiles probably want to add a dedicated USB-DAC (you lose an USB port) or dedicated HAT like HiFiBerry or IQAudio.

ALSA and PulseAudio soundserver

Then we have the software thing. Raspbian always used Advanced Linux Sound Architecture (ALSA) as the driver and skipped the layer of PulseAudio, which is the default sound server that lays on top of ALSA in modern Debian and Ubuntu desktops.

Since the Pi400 was introduced, and marketed as a serious affordable desktop, the now renamed Raspberry Pi OS, started to offer PulseAudio as well in December 2020. The big win of PulseAudio, better support for Bluetooth and more programs can output sound at the same time. With ALSA output would be locked  by one program: you can’t mix.

Well with a caveat. Raspberry Pi OS with desktop is shipped with PulseAudio, but Raspberry Pi OS Lite is not shipped with PulseAudio, because shipping it with PulseAudio would make it a Raspberry Pi OS Medium. ;(

So Raspberry Pi OS Lite uses just ALSA, Raspberry Pi OS with desktop uses also ALSA, but on top of that the PulseAudio layer.

Debug audio on a Raspberry Pi

Check the hardware, it doesn’t matter in this step if you use PulseAudio or not.

Start with listing all audio outputs:

aplay -l

This should output something like:

**** List of PLAYBACK Hardware Devices ****
card 0: b1 [bcm2835 HDMI 1], device 0: bcm2835 HDMI 1 [bcm2835 HDMI 1]
Subdevices: 4/4
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3
card 1: Headphones [bcm2835 Headphones], device 0: bcm2835 Headphones [bcm2835 Headphones]
Subdevices: 4/4
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3
card 2: IQaudIODAC [IQaudIODAC], device 0: IQaudIO DAC HiFi pcm512x-hifi-0 [IQaudIO DAC HiFi pcm512x-hifi-0]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 3: DAC [USB AUDIO DAC], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0

Here you see the four outputs: HDMI output (0), analogue out (1),  IQAudio HAT  (2), and an USB-DAC (3)

To test your hardware, upload a test.wav file to your Pi (aplay can’t play mp3 files), and try the different outputs.

aplay -D plughw:0 test.wav # HDMI
aplay -D plughw:1 test.wav #headphones/audio out
aplay -D plughw:2 test.wav # iqaudio
aplay -D plughw:3 test.wav # USB DAC

Of course you need to have the outputs properly connected to an amplifier, monitor or headphone. Now you know your hardware is working OK.

Check for a faulty power supply

If you have hisses, or distortion, also always check your Raspberry Pi for throttling and a possible power or heating problem:

vcgencmd get_throttled
throttled=0x0

If you see a different output, that suggests you have a faulty power supply. Phone chargers typically are not stable PSU’s. Better use the official Raspberry Pi power supply. Also the quality of the cable really does matter.

If that is also OK, it’s just about configuring the right output in your software.

Configuring the Music Player Daemon

To set the IQAudio HAT as the default ALSA output in /etc/mpd.conf

audio_output {
type "alsa"
name "IQAudio"
device "hw:2" # set hw:3 for DAC out
}

To set PulseAudio as the default output:

audio_output { type "pulse" 
name "pulse audio" 
}

Do not edit boot/config.txt by default

In general there is no need to edit /boot/config.txt. Official HATS will configure automatically and the same goes for USB-DACS. Plug and play. You see older tutorials or manuals instructing you to edit /boot/config.txt for configuration. IMHO that is only needed in special cases. If you don’t know what you’re doing, don’t edit boot/config.txt.

1 Comment

Kdenlive video-editor and HW acceleration

Tuesday, February 16th, 2021

Trying out the latest and the greatest Kdenlive 20.12.2 on my Ubuntu laptop I was delighted that HW-acceleration was working out of the box on my AMD Ryzen 4000 laptop.

Rendering is nearly twice as fast with HW-acceleration on a AMD Ryzen 4800u, no additional graphics card installed.

Using Kdenlive on flatpak, installing and updating is a breeze.

Installing kdenlive

flatpak install kdenlive
 
Looking for matches…
Found similar ref(s) for ‘kdenlive’ in remote ‘flathub’ (system).
Use this remote? [Y/n]: y
Found ref ‘app/org.kde.kdenlive/x86_64/stable’ in remote ‘flathub’ (system).
Use this ref? [Y/n]: y
Skipping: org.kde.kdenlive/x86_64/stable is already installed

Updating flatpak apps

flatpak update
 
Looking for updates…
Nothing to do.

How to encode with HW-acceleration on your AMD Ryzen laptop for Kdenlive?

Try out these settings for rendering:

 

3 Comments

Using A Raspberry Pi Zero as a webcam without SD card

Thursday, January 7th, 2021

The covid lock-down is sentencing a lot of people to work from home. For that we need webcams, a new pc, better monitor  and other equipment. The Raspberry Pi 400 is  a great and affordable second desktop, it’s the fastest Pi available suited for desktop use. It lacks a camera connector, so you need a Zero to connect a camera board.

So what about reusing that old gadget that was collecting dust in the drawer: a small and cheap Raspberry Pi Zero. If you also happen to own a camera board for that little computer, here is a nice project showmewebcam to turn that cheap computer into a handy webcam. It uses a small Buildroot Linux version and boots really fast.

And now that project has been forked on Github: showmewebcam-usbboot. No SD-card needed. That project will let the Raspberry Pi Zero boot over USB!

If you don’t have a camera board. You can buy a clone version of the v1 board for a few dollars in China, or get a v2 board or for the best results the really great HQ-camera board.

Interested in photography, that High Quality camera board can do some really great macro-photography.

Cheap Raspberry Pi webcam

With the Raspberry Pi Zero costing about 5 euro, and a clone camera board around 3 euro on AliExpress, you can have a very nice and decent webcam for less then 10 euro’s. And that is a bargain. Remember you don’t need an SD card. So save on the hardware where you can.

How does it work?

How does the Pi boot then? Over USB, so you do need the usbboot/rpiboot tool. That is free and opensource software made by the Raspberry Pi organization, a program that makes the Raspberry P Zero boot by pushing the operating system over USB.

Let’s try it out. I’m using an Ubuntu desktop.

Step 1: download showmewebcam-usbboot

Download the latest release .

Unzip it. You will extract a directory called showmewebcam-usbboot.

Step 2: install usbboot/rpiboot

If you have already installed a version of this tool, you can of course skip this tool and jump to step 3.

Download the usbboot/rpiboot, unzip it and build it according to the instructions.

Step 3: Connect the raspberry Pi Zero

(with installed camera board) by putting the USB plug into the middle USB connector.

Step 4: boot the webcam

You can start the webcam by executing the rpiboot tool and pointing it to the unzipped showmewebcam-usbboot directory

sudo ~/usbboot/rpiboot -d ~/showmewebcam-usbboot

After about half a minute booting the Raspberry Pi Webcam will be ready.

How to use the Webcam on the PC

For a quick start, and when no other cam is connected, you can start the webcam with (Ubuntu):

mpv /dev/video0

On a laptop with a build-in webcam the command that you have to issue will be :

mpv /dev/video2

To control your cams on the PC, you need `v4l-utils` (apt install v4l-utils)

To set the resolution

v4l2-ctl --set-fmt-video=width=1280,height=720 -d /dev/video2

To list all video devices:

v4l2-ctl --list-devices

To list the specs of your video devices:

v4l2-ctl --list-formats-ext
ffmpeg -f v4l2 -list_formats all -i /dev/video2

A serial connection will also be available, so you can connect to the Webcam to control the settings and do debugging. That works exactly the same as in showmewebcam

Control the webcam

Finer control offers the camera-ctl tool on the Zero

Connect to the Zero:

sudo screen /dev/ttyACM0 115200 Start the tool # /usr/bin/camera-ctl
Showmewebcam-usbboot - Controlling the webcam with camera-ctl

Controlling the webcam with camera-ctl

Create a stereo webcam

The tool will let you boot more then one Raspberry Pi Zero from the same directory. Just connect the two Raspberry Pi Webcams and start the tool. One will boot, just execute the tool another time and the other one will boot.

The webcams will be available as /dev/video0 (you) and /dev/video2 (your cat) on your Pi400.

Now make that video call with your boss, and ask for a raise. Switch the webcam to your cat the moment you stopped speaking.

What can showmewebcam-usbboot do what showmewebcam can’t do?

Nothing. It can do the same with less hardware, because it doesn’t need an SD card. But is does need extra software, which can limit compatibility. It also boots slower.

It hasn’t been tested that much.

Have fun, try it out,  en let me now your thoughts!

Links:

No Comments

Running Raspberry Pi OS on a RPI Zero without SD card

Saturday, January 2nd, 2021

I’ve blogged before about how to boot a Raspberry Pi Zero over USB without an SD card, just powering it with an USB cable in the middle USB connector, and connecting at the same time.

This Christmas I tried it with a new Buster version and a trusty old Raspberry Pi Zero and following the tutorial it’s still running fine with the latest Raspberry Pi OS 2020-12-02-raspios-buster-armhf-lite.img.

Time for some improvements. Updating and upgrading was always possible, but not always successful: you could easily run into disk-space problems.

Default images are shipped/downloaded as small as possible and the default action of booting a Pi with a new image is resizing the root partition to claim all available space on the SD card.

We’re mounting over NFS and of course the resizing did not happen in our case. Luckily, otherwise your guest OS would end up with no space and the Pi would have a partition size of 1GB (or so).

But for upgrades we need more space than the default.

How to increase the image size of an mounted image over NFS?

The image I have downloaded is `2020-12-02-raspios-buster-armhf-lite.zip`, and we have to follow 4 simple steps.

Step 1: unpack it:

unzip 2020-12-02-raspios-buster-armhf-lite.zip 2020-12-02-raspios-buster-armhf-lite.img

Step 2: resize raw image:

Then use qemu-img (QEMU disk image utility) to resize the raw image.

sudo qemu-img resize 2020-12-02-raspios-buster-armhf-lite.img 3G

Here we resize it to 3G, that must be enough to install some extra programs, and download and install updates.

Step 3: set it up as loop device:

sudo losetup -P /dev/loop101 2020-12-02-raspios-buster-armhf-lite.img

These day I set it up as loop101 instead of loop0 as I did in the blogpost of 2018 to avoid conflicting loop devices. Snaps are also installed as loop devices.

Step 4: resize root partition

start gparted with the loop device to resize the root partition.

sudo gparted /dev/loop101

Normally gparted never shows loop devices, but it does when you explicitly start with a loop device.

Then simply push the slider to resize the image, and apply the changes and you’ve gained 900MB of disk-space.

More than enough to do updates and upgrades for years to come.

No Comments

Text with pattern the new way

Sunday, October 4th, 2020

In the past the only way to to get colored text, like from an image or gradient was to use SVG.

Nowadays pure CSS is enough.

Although a prefix with -webkit- is still needed for Safari and Blink browsers.

.post-2027 h1{
background-image: linear-gradient(
90deg,
#7383c1 0%,
#bed876 50%,
#e0b384 100%
);
background-clip: text;
-webkit-background-clip: text;
color: transparent;
width:max-content;
}
1 Comment

Why the upgrade from Ubuntu 18.04 LTS to Ubuntu 20.04 LTS is not available yet.

Wednesday, September 9th, 2020

Linux users of the Ubuntu 18.04 LTS (Long Term Support) are still waiting to upgrade their systems to 20.04. Normally at around the time the first point release of the new LTS distribution is released.

What is a point release?

These point releases include support for new hardware as well as rolling up all the updates published in that series to date. So a fresh install of a point release will work on newer hardware and will also not require a big download of additional updates. These include security updates and corrections for other high-impact bugs, with a focus on maintaining stability and compatibility with Ubuntu 20.04 LTS.

And 20.04.1 was released on August 6. But the problem is: not all flaws have been ironed out yet in 20.04.1. So at the moment you can’t be confident to get a smooth upgrade from 18.04 LTS. That’s why the upgrade is not yet available. Yes you can get a smooth install, but not a smooth upgrade.

Upgrade blocking bugs for 20.04

There are 2 blocking issues at the moment, and they must be solved first:

  1. eoan to focal upgrade hangs when lvm snapshot is present (bug 1876506) resolved
  2. grub-pc upgrade support (bug 1891680)

Here you can track the release status.

If you wanna take the risk, you can always force a upgrade with:

do-release-upgrade -d