zondag 8 november 2015

Room Correction using drc-fir, ladspa_dsp & PulseAudio

This is a combination of notes I kept. Please let me know if you run into problems. I've only loaded mono filters (one measurement) into ladspa_dsp.

In the time honored tradition of UNIX of "do one thing well", getting room correction up and running under Ubuntu will use a lot of different utilities and commands. This text will hopefully guide you through some decisions.

Room Correction is modifying the sound sent to your speakers so that when you hear the audio, it more closely matches the way it was stored. It emulates a 'flat' frequency response, by dropping the amplitude of frequencies that are overrepresented, to match the ones that not as loudly reproduced. It will also measure the series of after-shakes your speaker and stuff in your room makes, and try to correct for that.

Measuring we will do with `drc`. And the LADSPA plugin of  `dsp` will be used to apply the correction. By plugging it into PulseAudio all modern Linux programs can automatically make use of it.

Measuring only needs repeating when you move your speakers, or do large restructuring of the room. Strictly speaking when you take a book of a shelf, your room changes. So the correction would need to change. But you're not really going the hear the difference. A normal room easily has 6dB changes when you walk around.

So, don't sweat it. Probably most of the audio you'll hear is made worse sounding equipment. E.g. news being recorded with a smartphone, indie bands recording and mixing in their basement on second hand equipment sort of thrown in the room ;)

If you want a more hands-off automated approach I suggest plunking down about $1000 for a MiniDSP DDRC with Dirac Live. I read it works very well, and requires Windows or OS X to set up. But that's for someone else to use. Dirac Live is also more advanced, since it uses all speakers and takes multiple measurement locations into account. While `drc` only does per channel (speaker) and for one listening position. There are also things like Trinnov & Four Audio HD2, which appears to be priced a point that if you have to ask for it you can't afford it :P

I am going to assume you:
  • have a fresh Ubuntu 14.04 install
  • want to use MythTV, Chrome, mplayer and VLC
  • want only stereo playback (and not say an ambisonics decode of 5.1 surround placement)
  • want room correction that also does impulse correction, over just equalization
  • have a UMIK-1 calibrated microphone - $75
The UMIK-1 appears to be a nice USB calibration microphone. Be sure to note that there is apparently some clock synchronization 'problem' with using two sound cards during calibration measurements (one for speakers & one for mic). But people appear to be happy with this microphone. Also, 'at the same time' (clock in sync) is physically impossible. You are going to have some delay, due to the speed of sound in a air and electricity in cables. But YMMV.

We are going to:
  • generate a sound sweep from 20 HZ to 20KHz, using `glsweep`.
  • play the sweep over your speakers
  • record the sweep using the UMIK-1
  • convolute the file we played with the recording, using `lsconv`
  • create a filter, using `drc`
  • try the filter using `drc` and some MP3 file
  • apply this filter in real-time, using ladspa_dsp in PulseAudio.
The runtime setup:

Speakers - Amp - TV - HDMI - ALSA - PulseAudio + ladspa_dsp - {MythTV, mplayer, VLC, Chrome}

We first need to install some software for later use:

$ sudo apt-get install unar drc build-essential git libasound2-dev ladspa-sdk libfftw3-dev libmad0-dev sox libsndfile-dev

Measuring

Ubuntu does not ship with the `measure` utility script. So we download the source code file.

$ wget http://sourceforge.net/projects/drc-fir/files/drc-fir/3.2.1/drc-3.2.1.tar.gz
$ unar drc-3.2.1.tar.gz
$ cd drc-3.2.1

Plug in your UMIK-1. Set it as default recording device and unmute it. Place it where you want the sound to be optimal. Make sure non-monotonic noises such as ticking clocks are turned off. Also, pets are probably best kept outside of the room you are measuring, if only for the distress of the sweep sounds.

My speakers (Jamo SL-90) specify they work from 35Hz to 20KHz. I'm going to sweep that range (35 - 20000). Going outside of the range of your speakers may fix some of their problems. But could easily send very loud signals through them in the attempt to correct deficiencies. Burning out the voice coils in the process ("blown out speakers"), iff your amp is high enough power. Also, it will need more dramatic shaping.

Bookshelf speakers (±30cm height) usually drop off below 75Hz, so use that as a start if you have one of those. Anyways, we can't really hear below 20Hz so no need to go much below that.

As the upper range, do not go above half your bitrate. As the encoding will not be able do represent anything above that range. See: 24bit/192-kHz Music Downloads ...and why they make no sense

To see the command line syntax of the `measure` script:

$ bash ./source/contrib/Measure/measure

The measure script will play a sound and record "two" channels from the UMIK-1. Only the left channel is populated by the microphone (TODO: is it?). The right channel will collect (mostly the same) noise of the microphone's USB sound card. The noise will be removed from the measurement, and the "impulse reponse" will be calculated by also subtracting the inverse of the sweep that was played.

Run the `measure` script. First do it as a test-run to assess sound pressure. For the actual measurement you will probably want to leave the room and run this remotely or on a timer (e.g. `sleep`).

Disconnect your left channel. We will measure your right channel.

$ bash ./source/contrib/Measure/measure 16 44100 35 20000 45 2 default front:CARD=Microphone,DEV=0 outdev impulse-right.pcm

Disconnect your right channel, and plug in the left again. We will measure your left channel.

$ bash ./source/contrib/Measure/measure 16 44100 35 20000 45 2 default front:CARD=Microphone,DEV=0 impulse-left.pcm

Copy the 44100 Hz ERB psychoacoustics config, which is best tuned for home theater. It places more importance on sounds you can hear better. It also deemphasized strong correction side-effects that you would be able notice, when you are not in the exact measurement location (e.g. your left vs. your right ear).

$ cp /usr/share/drc/config/44.1\ kHz/erb-44.1.drc .
$ cp /usr/share/drc/target/44.1 kHz/pa-44.1.txt .

You'll probably want to change all the "StartFreq = 20" entries to your own speaker start frequency, e.g. 35Hz.

$ sed -i 's/StartFreq = 20/StartFreq = 35/' erb-44.1.drc

Download the calibration file of your microphone from miniDSP.

Change the microphone calibration to your own UMIK-1 (YOUR_CALIBRATION.txt):

$ sed -i 's/MCPointsFile = wm-61a.txt/MCPointsFile = YOUR_CALIBRATION.txt/' erb-44.1.drc

Copy the prepared config file to a left and right config.

$ cp erb-44.1.drc erb-44.1-left.drc
$ cp erb-44.1.drc erb-44.1-right.drc

Now we mangle the config a bit further so it takes the correct input.

$ sed -i 's/BCInFile = rs.pcm/BCInFile = impulse-left.pcm/' erb-44.1-left.drc
$ sed -i 's/BCInFile = rs.pcm/BCInFile = impulse-right.pcm/' erb-44.1-right.drc

$ sed -i 's/TCOutFile = rtc.pcm/TCOutFile = rtc-left.pcm/' erb-44.1-left.drc
$ sed -i 's/TCOutFile = rtc.pcm/TCOutFile = rtc-left.pcm/' erb-44.1-right.drc

$ sed -i 's/PSOutFile = rps.pcm/PSOutFile = rps-left.pcm/' erb-44.1-left.drc
$ sed -i 's/PSOutFile = rps.pcm/PSOutFile = rps-right.pcm/' erb-44.1-right.drc

Run the calibration:

$ drc erb-44.1-left.drc
$ drc erb-44.1-right.drc

Next we want to use the rps-left.pcm and rps-right.pcm with `dsp`. For this we will first need to combine them into a single WAVE sound file.

sox -t f32 -r 44100 -c 1 rps-left.pcm -t f32 -r 44100 -c 1 rps-right.pcm --channels 2 --combine merge output-stereo.wav 

Tip: ladspa_dsp needs it's  fir filter as WAVE file that matched your audio. PulseAudio uses 44.1kHz by default.
Tip: The UMIK-1 can only record at 16 bit
Tip: drc does not understand WAVE files, if you used .wav anywhere, it's wrong.
Tip: You might want to reduce the amount of output taps to say PSOutWindow = 2048 which seems to be the largest amount of taps for 'zero' delay in dsp. Be sure to note that 44100/2048 ~ 21. So it probably has less influence on base sounds (1 correction at 21 Hz) and long distance reflections (15.8m roundtrip ~ 8 meter speaker to wall).
Tip: You can download your miniDSP UMIK-1 calibration file from their site.

Applying the correction

Download the source of dsp:

$ git clone https://github.com/bmc0/dsp.git
$ ./configure

Check that it says "[ladspa_dsp] enabled fir.o (fftw3)". You'll at least need libasound2-devladspa-sdklibfftw3-dev, libmad0-dev & libsndfile-dev

$ make -j4
$ sudo make install

`dsp` and ladspa_dsp are now installed. As a test, use the effect "gain -20.0" (rather quiet playback):

$ dsp -v some.mp3 gain -20.0

Quit by pressing [q]. Say you want this effect system wide; you put "effects_chain=gain -20.0" in ~/.config/ladspa_dsp/config. And then load the ladspa_dsp in PulseAudio.

You will probably want to end up with an effect chain that reads something like: "effects_chain=gain -6.0 fir /home/henk/drc-3.2.1/output-stereo.wav"

The filter needs a little (-6.0 dB) headroom to stop clipping with the default calibration files. If you play an MP3 file using `drc` it will tell you how much over budget it went.

Loading the convolver in PulseAudio 

Along the lines of: System Wide DSP Guide

$ pacmd list-sinks | grep -A1 \* | grep name
name: alsa_output.pci-0000_00_14.2.analog-stereo

This is the 'master' variable, that we will use below.

$ pacmd describe-module module-ladspa-sink 

The command to load ladspa_dsp into Pulseaudio.

$ pacmd load-module module-ladspa-sink sink_name=dsp master=alsa_output.pci-0000_00_14.2.analog-stereo plugin=ladspa_dsp label=ladspa_dsp channels=2

If your ~/.config/ladspa_dsp/config is incorrect `pacmd` will only say "Module load failed."

To debug, run `pulseaudio -k && pulseaudio -vvvv`. It might say something like "dsp: error: failed to initialize effect: ..." when the `pacmd load-module` command is run and your config is broken.

Next we tell PulseAudio to use the room correction filter for all programs that you start until you reboot:

$ pacmd set-default-sink dsp

You can also set the default for all running programs using PulseAudio Volume Control (`pavucontrol`) on the Playback tab.

Tip: You need the channels=2 part if you want the correction to actually be applied to both channels. Try to increase it to 6 if you use 5.1 surround. I don't know the required ordering of the speakers in your reverb effect wav file.

Loading DSP by default

If you want to make this setting to survive reboots, you'll have to set it in ~/.config/pulse/default.pa:

.include /etc/pulse/default.pa

load-module module-ladspa-sink sink_name=dsp master=alsa_output.pci-0000_00_14.2.analog-stereo plugin=ladspa_dsp label=ladspa_dsp channels=2

set-default-sink dsp

zaterdag 10 januari 2015

DVBSky T680C on Mythbuntu 14.04

How to make it work. Download the firmware and driver from: http://www.dvbsky.net/Support_linux.html

The build_dvbc_x64.sh script changes the driver so it only shows supports DVB-C. This makes it DVB-C work in MythTV.
Code:
mkdir dvbsky
cd dvbsky

wget http://www.dvbsky.net/download/linux/dvbsky-firmware.tar.gz
sudo apt-get install unp && unp dvbsky-firmware.tar.gz
cd dvbsky-firmware
sudo ./copy-firmware.sh
cd ..

wget http://www.dvbsky.net/download/linux/media_build-bst-14-141106.tar.gz
unp media_build-bst-14-141106.tar.gz
cd media_build-bst-14
./build_dvbc_x64.sh
sudo make install 
sudo reboot
Had contact with 'stuartm' on #mythtv irc. He'll look at adding a C vs. T/T2 selector in MythTV 0.28
Some further info: http://ubuntuforums.org/showthread.php?t=2260221

dinsdag 30 december 2014

Broken Technotrend CT-3650

One of my TT CT-3650 is broken. The device still registers /dev/dvb/adapter0, but there's no ca0 (CAM), nor frontend0/frontend1 (DVB-C/T). Connecting to Windows also gives strange errors in the supplied tuner software. Took the board out of the casing, there's no real obvious damage.

I'm replacing them with DVBSky T680C. Technotrend's own replacement CT2-4650 needs kernel 3.18 to function, and I had trouble getting that up and running together with my Nvidia card. Apparently building an ubuntu kernel needs more than 6GB disk space of my system partition. I have not tried building v4l-dvb's media_build.git. Which might work, but I cannot test before ordering the hardware.

Informatie over digitale TV, na de fusie van Ziggo en UPC

Er is een overzicht van de veranderingen bij digitale TV van Ziggo.

Op de informatie pagina op de site van Ziggo zelf kan je je opgeven voor een SMS zodra de veranderingen zijn doorgevoerd.

Wat ik hier van al gemerkt heb is dat een maand of wat terug scannen met Netwerk ID '5555' beter ging dat met '8888'. En dat is nu weer terug gewisseld. Zal wel een test zijn geweest.

Voor mijzelf zou ik eens moeten kijken of m'n CI-niet-plus Sony TV het Netwerk ID 43192 voor regio Alkmaar toevallig beter begrijpt.

zondag 13 mei 2012

Linux 3.3.6

Aangezien m'n systeem nog steeds van tijd tot tijd bleef hangen bij het uitschakelen, nu maar geupdate naar Linux kernel 3.3.6 met deze handleiding: https://wiki.ubuntu.com/KernelTeam/GitKernelBuild

In menuconfig heb ik vooral gekeken of AMD64 wordt gebruikt,  en hier en daar wat 'low latency' zaken ingeschakeld die de interactiviteit kunnen bevorderen.

Na de reboot nvidia's driver geïnstalleerd (even alle 'failsafeX' instanties killen). Het backend gedeelte lijkt prima te werken. Frontend lijkt ook gewoon te draaien.

maandag 30 april 2012

USB bug in M2NPV-VM BIOS 1401

Sinds het in gebruik nemen van de TT CT3650 schakelt m'n backend computer niet altijd écht uit. Alles stopt wel, maar de computer blijft stroom krijgen. En start dan dus ook niet op tijd op, want staat niet uit.

Na wat zoeken kwam ik achter een bug in de BIOS in van m'n moederbord: http://marc.info/?l=linux-kernel&m=122131004618837&w=2

Gedowngrade naar 1201, en nu maar kijken of het weer optreed.

donderdag 26 april 2012

Wat je nodig hebt voor MythTV digitale TV bij Ziggo

Er mailde mij vandaag iemand met de vraag "Zou jij me kunnen vertellen wat ik het beste aan kan schaffen?"

Mijn reply:

Wat je nodig hebt is een grafische kaart die hardwarematig 1080p h.264 en MPEG2 kan weergeven. Om op de CPU video te decoderen heb je een vrij heftig systeem voor nodig, mijn AMD Athlon 64 X2 4000+ kan het nét niet aan op zichzelf. Dat hardwarematig video afspelen is voornamelijk met Nvidia's VDPAU PCI-Express kaarten: http://www.mythtv.org/wiki/VDPAU
 , ATI werkt eigenlijk niet, Intel GMA misschien. Maar er is ook CrystalHD: http://www.mythtv.org/wiki/Broadcom_Crystal_HD

Aan de opname kant: TV kaarten met DVB-C en een CI slot. In dat CI slot een 'Alphacrypt Classic' CAM, of de equivalente 'Panaccess MultiCrypt'. In de CAM dan een Ziggo smartcard. Het is theoretisch ook mogelijk om die Alphacrypt/MultiCrypt te vervangen door een Smargo kaartlezer en een 'softcam'. Die kan terzijnertijd (nu nog niet) vast ook een CI+ Irdeto2 systeem emuleren, dat kan de Alphacrypt niet. Maar de MythTV ontwikkelaars werken dat actief tegen, dus dat wordt dan een beetje houtje-touwtje oplossing waar je niet van af moet blijven want anders gaat het steeds stuk. Tot nu toe werkt m'n Alphacrypt, maar ik heb wel al een Smargo in huis. Ik heb liever dat ik gewoon kan updaten zonder al te veel hoofdbreken hoe ik het ook alweer oploste een half jaar terug.

Op zich heb je vrije keus in TV kaarten, moet wel werken met Linux. De enige USB DVB-C kaart met CI slot die geheel werkt onder Linux is de TT CT-3650. Ik heb die aangeschaft omdat ik ooit hoop m'n systeem fysiek wat kleiner te kunnen schalen. M'n externe frontends zijn al van die kleine Zotac kastjes. De CT-3650 werkt alleen met Linux kernel 3.2, of de meest recente LinuxTV media_build drivers: http://www.linuxtv.org/wiki/index.php/How_to_Obtain,_Build_and_Install_V4L-DVB_Device_Drivers

De 'Digital Devices Octopus' serie is ook interessant. Dat (mini) PCI-Express kaartje kan 8 apparaten aansturen, dus bijv 4 DVB-C/T tuners, en 4 CI sloten. Maar hoewel de woordvoerder van de fabrikant zegt dat alles werkt onder Linux, zijn er volgens mij alleen drivers voor hun satelliet (DVB-S/S2) ontvanger. Kán inmiddels veranderd zijn.

Daarnaast heeft mythtv-setup problemen met het vinden van alle kanalen. Ziggo heeft z'n eigen aangepaste DVB-C standaard verzonnen (vandaar "Ziggo Gecertificeerd" logos). Ik vul daarom de dtv_multiplex tabel in de database aan met de extra multiplexen die MythTV zelf niet gevonden heeft: http://gathering.tweakers.net/forum/list_messages/1340775/0
 . Daarna nogmaals laten zoeken, dan vind MythTV alle kanalen. Het heeft voorheen wel eens gewerkt, misschien werkt het al weer in MythTV 0.25.