Saturday, 9 November 2013

Listen tracks from youtube in mpd

I don't have my collection of music in the office. Last.fm no longer offers its great radio.

Luckily, there are tons of tracks on youtube.
Luckily, I use linux and incredibly powerful mpd player, so I don't have to keep youtube open

Suppose, you want to listen to some vocal trance on youtube.

Use youtube-dl to determine what formats are available
$ youtube-dl -f http://www.youtube.com/watch?v=HS5fHWmzqIg
[youtube] Setting language
[youtube] HS5fHWmzqIg: Downloading video webpage
[youtube] HS5fHWmzqIg: Downloading video info webpage
[youtube] HS5fHWmzqIg: Extracting video information
Available formats:
22      :       mp4     [720x1280]
18      :       mp4     [360x640]
43      :       webm    [360x640]
5       :       flv     [240x400]
36      :       3gp     [240x320]
17      :       3gp     [144x176]
136     :       mp4     [720p] (DASH Video)
135     :       mp4     [480p] (DASH Video)
134     :       mp4     [360p] (DASH Video)
133     :       mp4     [240p] (DASH Video)
160     :       mp4     [192p] (DASH Video)
141     :       m4a     [256k] (DASH Audio)
172     :       webm    [256k] (DASH Audio)
140     :       m4a     [128k] (DASH Audio)
171     :       webm    [128k] (DASH Audio)
139     :       m4a     [48k] (DASH Audio)

There are 5 audio formats for this video. 141th has highest bitrate. So all we have to do, is to get real URL for this format and feed it to mpd
$ mpc add `youtube-dl -f141 -g http://www.youtube.com/watch?v=HS5fHWmzqIg`

That's all, track from youtube is already in your mpd playlist. Enjoy!

Thursday, 7 November 2013

Saturday, 23 March 2013

Eliminate LED screen flicker with Intel i915

Step-by-step solution

Disclaimer
Actions described here may cause damage to your hardware. Do at your own risk.
  1. Install Intel GPU tools
  2. Read reference clock value with command
    # intel_reg_read 0xC6204
    and put the value in the box below
  3. Type desired PWM frequency in the box below
    Hz
  4. Click
  5. In your terminal execute
    # intel_reg_write 0xC8254 0x7a107a1
Finally, to make things permanent, run this command on system startup. I use systemd so here is what I have
pwmfrequency@.service
[Unit]
Description=LED PWM frequency 

[Service]
Type=oneshot
ExecStart=/usr/bin/intel_reg_write 0xc8254 %I

[Install]
WantedBy=graphical.target
Enable service on startup
# systemctl enable pwmfrequency@0x7a107a1

Background

PWM modulation frequency of LED backlight in laptops with Intel i915 GPU may be controlled by GPU itself (sometimes it is not the case though). So adjustment of PWM modulation frequency becomes possible by write to special HW register.

In i915 (at least, in Sandy Bridge) PWM modulation frequency is controlled by value of the 4 upper bytes of the register 0xC8254. According to the Intel HD Graphics programmer's reference manual the value of these 4 bytes
represents the period of the PWM stream in PCH display raw clocks multiplied by 128.
PCH display raw clock frequency is held in another register 0xC6204 and by default it equals to 125 MHz (0x7D).
Resulting PWM modulation frequency can be calculated by formula
fPWM = regC6204 / 128 / regC8254{7:4}
For example, for reference clock frequency equal to 125 MHz and value of the regC8254 equal to 0x12281228 (default on my Thinkpad X220) PWM modulation frequency will be equal to approximately 200 Hz.

See also