[SOLVED] DSP output script

Programming applications for making music on Linux.

Moderators: MattKingUSA, khz

Post Reply
User avatar
AnthonyCFox
Established Member
Posts: 393
Joined: Mon Apr 22, 2013 3:50 pm
Been thanked: 1 time

[SOLVED] DSP output script

Post by AnthonyCFox »

I'd like to have the dsp always visible, like I do with cpu load. Preferably something I can plug into Conky, so I can see it in my i3 status bar.

I tried

Code: Select all

${execp jack_cpu_load}
but in Conky that just shows

Code: Select all

Jack: JackClient::SetupDriverSync driver sem in flush mode
and nothing else.

From here http://linux-audio.4202.n7.nabble.com/s ... 31211.html I got this:

Code: Select all

jack_cpu_load|cut -d" " -f2
which is supposed to show dsp. But, when I made a shell script with it and ran it in the terminal it outputs

Code: Select all

JackClient::SetupDriverSync
JackPosixSemaphore::Connect
JackPosixSemaphore::Connect
Clock
JackLibClient::Open
JackClient::Activate
JackClient::ClientNotify
JackClient::kActivateClient
This looks like one of those awk/sed kinda things that are out of my league.

Does anyone here know how to make this work?
Last edited by AnthonyCFox on Mon Jan 27, 2014 3:31 am, edited 1 time in total.
War, crime, disease, starvation, extreme poverty; these are serious things.
Music? Not so serious. Have some fun! :D
User avatar
AnthonyCFox
Established Member
Posts: 393
Joined: Mon Apr 22, 2013 3:50 pm
Been thanked: 1 time

Re: DSP output script

Post by AnthonyCFox »

Okay, I've been doing some more research on this.

In the shell, when I pipe jack_cpu_load through sed, or cut, no matter what options I use it stops printing just before the lines I want to see.

Code: Select all

jack_cpu_load | sed -n 8p
will print

Code: Select all

Jack: JackClient::kActivateClient name = jack_cpu_load ref = 4
The very next line should read something like

Code: Select all

jack DSP load 0.294772
which is what I'm looking for, but when I run

Code: Select all

jack_cpu_load | sed -n 9p
which should print that line, there is nothing. Just a cursor, until I hit ctl-c and kill it.
War, crime, disease, starvation, extreme poverty; these are serious things.
Music? Not so serious. Have some fun! :D
Thad E Ginathom
Established Member
Posts: 369
Joined: Fri Sep 23, 2011 1:03 pm

Re: DSP output script

Post by Thad E Ginathom »

I used to do sed and awk and stuff, but it is a long time ago.

Looking at your stuff, cut seems the most promising. cut -d " " -f4 really should work.

But it doesn't.

1. Let's output jack_cpu_load to a file...

Code: Select all

$ jack_cpu_load >xxx
^Csignal received, exiting ...
2. Let's see what we have in the file...

Code: Select all

$ cat xxx
jack DSP load 0.381236
jack DSP load 0.390884
jack DSP load 0.354795
jack DSP load 0.371873
jack DSP load 0.373283
jack DSP load 0.371836
jack DSP load 0.366441
3. Let's try the cut command with that data...

Code: Select all

$ cat xxx | cut -d " " -f4
0.381236
0.390884
0.354795
0.371873
0.373283
0.371836
Looks good! So surely this has to work...

Code: Select all

$ jack_cpu_load | cut  -f4
:evil: Nothing! Just the same result as you got.

Is there some problem with jack_cpu_load writing to a pipe? Let's try the simplest thing I can think of

Code: Select all

$ jack_cpu_load | cat
Deadly silence again. Somehow there does seem to be something wrong with jack_cpu_load writing to a pipe.

I don't know how that can be. I suppose the next thing to do would be to try named pipes, which I don't remember how to do.
User avatar
AnthonyCFox
Established Member
Posts: 393
Joined: Mon Apr 22, 2013 3:50 pm
Been thanked: 1 time

Re: DSP output script

Post by AnthonyCFox »

Thanks for trying Thad.

I got some help from stackexchange and it turns out to be a buffering issue. Between that and some hammering away on google; and trial and error; I came up with this:

Code: Select all

stdbuf -i0 -o0 -e0 jack_cpu_load | sed -n 's/[A-Za-z]*//g;s/ //g;s/.\{4\}$//;9,$p'
It's the output I'm looking for in the terminal. But I don't know how to make it work in conky, yet. I tried

Code: Select all

${execp dsp.sh}
and nothing shows. I think it's the buffering. I'm pretty sure that every time conky refreshes, it runs the script; but it happens too fast to get any output from it.

Oh well. Back to Google.
War, crime, disease, starvation, extreme poverty; these are serious things.
Music? Not so serious. Have some fun! :D
User avatar
AnthonyCFox
Established Member
Posts: 393
Joined: Mon Apr 22, 2013 3:50 pm
Been thanked: 1 time

Re: DSP output script

Post by AnthonyCFox »

I ended up back on stackexchange again for more lessons on buffering. Actually, 90% of this was done for me, I didn't know anything about buffers, but I did figure out the sed stuff on my own. :P

Code: Select all

stdbuf -oL jack_cpu_load | grep --line-buffered "jack DSP load" | stdbuf -oL cut -d' ' -f4 | stdbuf -oL sed -e 's/.\{4\}$//' | while read line; do echo "$line" > /tmp/buffer; done &
EDIT: I've changed this a little due to concerns about disk space and questions as to whether the output was accurate. More thanks to stackexchange!

So if anyone wants to see their DSP load in Conky, put the above in a shell script and have that autostart when you log in. Then add

Code: Select all

${tail /tmp/buffer 1 1}
to your .conkyrc and you've got it. :D

I just want the number, but you can use it in a meter object in Conky also. And, if anyone wants to use this to build an applet or widget, please do! I'm sure someone will appreciate it.
Last edited by AnthonyCFox on Mon Jan 27, 2014 6:16 pm, edited 1 time in total.
War, crime, disease, starvation, extreme poverty; these are serious things.
Music? Not so serious. Have some fun! :D
Thad E Ginathom
Established Member
Posts: 369
Joined: Fri Sep 23, 2011 1:03 pm

Re: [SOLVED] DSP output script

Post by Thad E Ginathom »

ok, good, glad you got there. : ).

stdbuf is entirely new to me. Digging for the brain cells that would be able to fluently read the sed command would be like archaeology. Ashamed to admit that I used to do actually clever stuff with sed, awk, shell, etc for a living, over ten years ago.

Actually, solving stuff like this is all part of the fun of the Unix/Linux world. It can even get addictive!
User avatar
AnthonyCFox
Established Member
Posts: 393
Joined: Mon Apr 22, 2013 3:50 pm
Been thanked: 1 time

Re: [SOLVED] DSP output script

Post by AnthonyCFox »

Thad E Ginathom wrote:Actually, solving stuff like this is all part of the fun of the Unix/Linux world. It can even get addictive!
I wish that I could have come up with more of the solution on my own but I'm very grateful for stackexchange. I'm glad I did this though, this is something that should exist. I know I'm not the first person to tackle it, I saw a couple people trying to work it out in my searches.
War, crime, disease, starvation, extreme poverty; these are serious things.
Music? Not so serious. Have some fun! :D
Post Reply