Archive for the ‘perl’ Category

New zeekat website design

Thursday, May 9th, 2013

This week, I re-implemented my main website. The text on the old one needed to be revised heavily (in fact I removed almost all of it except a short bio and some longer articles) and I wanted to experiment with a more colorful look. I need to revise the stylesheet a bit more to give a better experience on small screens (mobile), but so far I’m pleased with the result.

The new site html is generated completely by emacs’ org-mode project publishing functionality (the old one used a custom bunch of perl scripts generating from HTML snippets and perl POD documents). This hopefully means it’ll be easier to add and revise content, and it also provides nice syntax highlighting for any code snippets I put in my articles.

The whole switchover was pretty smooth, especially once I wrote a bit of elisp to roughly prepare conversion from POD formatting to org:


(defun pod2org
(point mark)
"Rougly convert region from pod syntax to org-mode"
(interactive "r")
(replace-regexp "C<\\([^>]+\\)>" "=\\1=" nil point mark)
(replace-regexp "I<\\([^>]+\\)>" "/\\1/" nil point mark)
(replace-regexp "B<\\([^>]+\\)>" "*\\1*" nil point mark)
(replace-regexp "^=head1 \\(.*\\)" "* \\1" nil point mark)
(replace-regexp "^=head2 \\(.*\\)" "** \\1" nil point mark)
(replace-regexp "^=head3 \\(.*\\)" "*** \\1" nil point mark)
(replace-regexp "^=head4 \\(.*\\)" "**** \\1" nil point mark)
(replace-regexp "^=head5 \\(.*\\)" "***** \\1" nil point mark))

Very basic, but pretty useful.

Now, I’m considering replacing WordPress for this blog with org-mode too. That probably requires a bit more investigation. I want to keep at least the tags/categories feature and related rss feeds, and I’m not sure if that’s available for org at the moment.

perl audio modules get reviewed

Thursday, December 13th, 2007

Jonathan Stowe wrote a short piece on a demo he gave on making music with perl and includes code and mp3. He’s been using my Audio::SndFile and Audio::LADSPA modules and was kind enough to also write some positive reviews on them.

Audio::LADSPA review, Audio::SndFile review.

Lisp, functies, macros en expressieve code

Tuesday, October 30th, 2007

Ik ben jaren geleden al eens begonnen aan een Perl module om (onder andere) modulaire synthesizers te emuleren. En dat werkte wel, maar mooi was het niet:

Maak wat processors….

    my $net = Audio::LADSPA::Network->new();
    my $sine = $net->add_plugin( label => 'sine_fcac' );
    my $delay = $net->add_plugin( label => 'delay_5s' );
    my $play = $net->add_plugin('Audio::LADSPA::Plugin::Play');

verbind ze met mekaar en zet parameters…

    $net->connect($sine,'Output',$delay,'Input');
    $net->connect($delay,'Output',$play,'Input');
    
    $sine->set('Frequency (Hz)' => 440); # set freq
    $sine->set(Amplitude => 1);   # set amp

    $delay->set('Delay (Seconds)' => 1); # 1 sec delay
    $delay->set('Dry/Wet Balance' => 0.2); # balance - 0.2

en draaien maar!

    for ( 0 .. 100 ) {
        $net->run(100);
    }

Allemaal leuk, maar veel te veel typ werk en behoorlijk complex.

Op vakantie heb ik laatst Practical Common Lisp doorgelezen en dan ga je natuurlijk denken dat dat beter kan als je functies gebruikt ipv complexe objecten en dat het er in Lisp veel beter uit kan zien.

Dat is dus ook zo :-)

; ik ga hier processors gebruiken
(with-processors
    ; maak een paar processors
    ((sine (sine-processor))   
     (delay (delay-processor))
     (m (stream-mixer))
     (mlt (stream-mult)))
  (with-audio-stream stream 0 1 ()  ; gebruik 1 audio output
    (dotimes (i 400)
      (write-audio stream
		   (<- m         ; output van m
		       :input-1 (<- sine :frequency 0.1)
		       :factor-1 0.2   ; specificeer vaste parameter
		       :input-2 (<- ^sine)  ; uitvoer van sine processor hierboven
		       :factor-2 0.0)))))

Ik gebruik

(<- ... )

als een macro die de juiste output van een processor selecteerd:
:output bij default, anders scrijf je

(<- :andere-output processor .... )

En definieren van een processor is ook erg versimpeld:

(defprocessor mult-processor
    ((output :stream)) 
    ((input :stream) (factor :scalar))
    ()
  (dotimes (i *num-frames*)
    (setf (aref output i) (* (aref input i) factor))))