3

I need help writing a conkyrc file. It (should) call a lua script, which reads a FIFO pipe of PCM data generated by MPD. This FIFO is used to generate visualization in NCMPCPP but I'd rather it go to a bar graph on my desktop. And yeah, I'm aware that it would need to be updated pretty fast in order to look good. I'm hoping that instead of a full spectral analysis, I can do a simpler visualization that doesn't require an expensive FFT or wavlets... just something I can pipe into a graph showing activity of music at the moment.

[edit] Progress made, albeit with a lot of fudge factor...

my conkyrc file

lua_load /home/adam/Programming/myWork/conky/mpd.lua
update_interval .05
TEXT
HERP DEE DERP DEE DERP DEE DUUUR
${lua_bar fifo_func}

My lua file

do
-- configuration
local interval = 5 

-- local variables protected from the evil outside world
local next_update
local buf 
local int = 0
local colour = 0
local function update_buf()
    buf = os.time()
end

local f = assert(io.open("/tmp/mpd.fifo", "rb"))
local block = 2048 * 2 --2048 samples, 2 bytes per sample
local list = {}

function conky_fifo_func()

    local bytes = f:read(block) --read a sample of block bytes
    local power = 0

    for i = 0, 2047 do  
        --j = string.byte(bytes, 2*i, 2*i+1) --extract 2 bytes
        j = string.format("%u", string.byte(bytes, i*2, i*2+1))
        power = power + math.abs(j-(256/2))
        --io.write(j..'\n')
    end
    r=((power/10000)-20) * 15
    io.write(r .. '\n')
    return r
end

-- returns a percentage value that loops around
function conky_int_func()
    int = int + 1
    return int % 100
end
end

Based on the NCMPCPP source code, the FIFO is an array of 2048 16bit ints

Dharman
  • 30,962
  • 25
  • 85
  • 135
adamwong246
  • 795
  • 9
  • 15

0 Answers0