A world in dk(decay/denmark) » Programming http://rotand.dk Just another pointless weblog Sat, 30 Nov 2013 21:03:48 +0000 en-US hourly 1 https://wordpress.org/?v=4.3.18 DTMF dialer got new features http://rotand.dk/2009/06/27/dtmf-dialer-got-new-features/ http://rotand.dk/2009/06/27/dtmf-dialer-got-new-features/#comments Sat, 27 Jun 2009 17:14:29 +0000 http://rotand.dk/blog/?p=198 I got a comment from a reader who used my DTMF dialer but missed a feature.

It was the ability to change what prefix to remove. As i live in Denmark, whenever i make a call on a land-line there is no reason to dial +45, which is the danish country code. Actually the plus is converted into 00 as well.

But Eli needed the prefix 08 to be removed.

And i guess that there are a lot of other prefixes that could be removed and + shouldn’t always be converted to 00. So I decided to implement this feature.

Whats new

  • It now remembers your settings
  • It possible to choose a prefix to remove
  • its possible to decide what + should be replaced by.
  • I slapped a GPL V3 license on it

The files

dtmfdialer jad file

dtmfdialer jar file

dtmfdialer source code

Unfortunately it wasn’t just a 5 min hack. There were two major challenges.

Persistence

In J2me access to the filesystem is restricted and requires all sorts of security permissions, but every application has access to a “RecordStore”. The RecordStore (RMS) only allows byte[] to be stored, so you have to marshall/unmarshall every piece of data at quite a low level. I haven’t persisted any data in the first version, as this is indeed tedious to work with. But not having persistence for a prefix remover functionality wouldn’t be of any use. You would have to enter the same data every time you used the application and then it would be faster to just edit the number to call.

Netbeans mobility pack

It was supposed to be so eays.

But the floweditor somehow did mess up and didn’t generate the code, so the flow diagram and the sourcecode were out of sync, and i didn’t see any way to “resync”/”regenerate code/diagram”. This was cause for a lot of frustrations.

Originally i made it with netbeans so compiling and editing the generated code were best done in netbeans. But if i ever were to mess with it again i would seriosly consider “porting” it to J2me Polish or just “vanillia” j2me. As i really really don’t like the netbeans editor.

update : Eli found a bug in the prefix substitution, i fixed and uploaded the new version (June 27, 2009, 21:17)

]]>
http://rotand.dk/2009/06/27/dtmf-dialer-got-new-features/feed/ 0
CLI voip calls http://rotand.dk/2009/05/03/cli-voip-calls/ http://rotand.dk/2009/05/03/cli-voip-calls/#comments Sun, 03 May 2009 08:13:27 +0000 http://rotand.dk/blog/?p=178 front1
Sometimes it would be nice to use a script call somebody and play a message.
I “needed” a wake-up-call system and since I use a voip-phone and have access to a server. I thought i would be quite nifty if I could have the server call me. Furthermore i would like to be able to script calls, so for instance the calendar could call me with reminders rather than sending an email.

I googled around but weren’t able to find such a utility. But i did find cli-sip client pjsua, based on pjsip. Its posible to use it in conjunction with a shell script.

Scripting

jacob@vps:~./control.sh sip:108329@foobar.com "wake up you lazy bastard!"
Is the basic usage i wanted to have. In order to get this functionality there are two steps.

Generating wav file

I ust use text2wave, from festival, which is available as a package on ubuntu.
echo $2 | text2wave - -o message.wav

$2 to use the second argument, and pipe it to text2wave. Let text2wave read sdtin and output a file message.wav

Call and play the wav file

pjsua_app --config-file=test.conf --play-file message.wav $1
Here the magic is in the conf file. Its a rather straightforward to use, and the documentation is good.

# we don't want the host's audio device
--null-audio
# SIP parameters
--realm domain.com
--registrar sip:number@domain.dk # DNS SRV, or FQDN

--username USERNAME
--password PASS
# default of 55 will be rejected as being too short by sipX
--reg-timeout 3600
# auto-answer all calls with "200 OK"
--auto-answer 200
# automatically loop incoming RTP to outgoing RTP
--auto-loop
# mix WAV file into the audio stream

--auto-play
--auto-loop
--duration=60

This is based on a config file i found somewhere, can’t remember where. There a a lot of other options, pjsua handles nat quite nicely as well. It was easy to test it at my homebox, behind a router, just be sure to set an external ip address.

Now this will call and play the message, but it wont stop pjsua. It will just sit around waiting for someone to call. I couldn’t find any nice way to handle this, but since pjsua reads stdin for commands, it possible to pipe commands to it.
echo "sleep 60000 q" | pjsua_app --config-file=test.conf --play-file message.wav $1
So sleep for 60 seconds, then accept the next input from stdin, the “q”uit command.

Generally this configuration is set for 1 minute, it might be necessary to tweak this.

Frustrations

There is/were a bug in the tarball, that meant that it wouldn’t run if it couldn’t find a soundcard, since it should run on a vps this is quite annoying. But in the svn version its solved, so if you want to do something like this, use the svn version. Other than this installation is straightforward.

When working with cron, remember to use full paths. In the control.sh script the better solution were to add a cd working directory, in order to have all the paths correct. This were quite annoying to debug, as the script would run from the shell. And just fail when added to the crontab. Furthermore mails from crontab were delayed, so i couldn’t see the output. I did get someone to look over my shoulder and spot the bug.

]]>
http://rotand.dk/2009/05/03/cli-voip-calls/feed/ 2
Collection of Processing.org hacks http://rotand.dk/2009/02/27/collection-of-processingorg-hacks/ http://rotand.dk/2009/02/27/collection-of-processingorg-hacks/#comments Fri, 27 Feb 2009 20:07:06 +0000 http://rotand.dk/blog/?p=74 Its been quite a while since I last posted anything.

That doesn’t mean that i haven’t been coding small hacks, just that i haven’t posted them. But now is probably a good time to show some of the stuff.

As the title suggest it has something to do with processing.org. I have been using processing on and off for some time. Its is really nice when you want to make a quick hack, or as its called in processing a “sketch”.

In no particular order here is some of the fun stuff made using processing.

General remarks

The following sketches and their sourcecode have served as small hacks, hence don’t expect nice comments or optimal algorithms…

shrinkImage

It is possible to remove the line from a picture representing the least amount of information. The algorithm evaluates every pixels “weight” as the absolute difference between the different color channels (r,g,b). And then finds the “lightest path” from the bottom to the top.

This means that “prominent features” won’t be removed or change size when shrinking the image. Here the definition of “prominent features” is high difference in colors between the neighboring pixels.

Have a look at shrinkImage

Room for optimizations :

Eventhough its quite quick at calculating the weights and finding the lightest path, it does so in every iteration. Letting it use a bit more memory and just recalculate the changes when removing a line should speed it up. I found a huge speedup when just having an array with the weights from the last and current line, when calculation the path, so not only would saving all weights require a bit more memory it would also slow down the first calculation. But I’m sure it would give a significant speed up in the next iterations, and a lot of +-1 frustrations 😉

helloFoo

There a some quick getting to know processing hacks, this is one off the. helloFoo

One of the very cool things about processing is the ability to use openGL, so originally this sketch uses openGL. But applets and openGL isn’t exactly the best combination. It can be done, but since it doesn’t work for me (firefox, linux openJDK JRE) i just converted it to standard java graphics. And the effort required to do this, is remove an import and don’t say setup(400,400, OPENGL) but just setup(400,400). This is trivially true the other way around. If you want to use openGL its quite easy.

The sketch is just bouncing balls, when going away from openGL I reduced the size and number of balls, in order to get a decent animation speed.

FooIII

Again used openGl originally FooIII

Some satellites rotating around some satellites rotating around some ….

sndHello

yes sketches tend to have silly names : sndHello

From Clifford Pickovers  book : Computers, Pattern, Chaos, and Beauty – graphics from an unseen world (p 39 section 4.3 snowflakes from   sound)
Draw symmetrically and in “polar form” the fft of the sound, hence creating snowflakes based on the sound.
Music by David Rovics
Choppy sound I had some problems with the sound when run as an applet. You might have better luck using the jar directly or by downloading the sourcecode and running it with processing

Slit-scanning

The former applet relied on an external library for the sound, ther are quite a few libraries available. I did use GSvideo to hook up my crappy webcam and do some video effects. I experimented with slit-scanning in different ways.Unfortunately this won’t run as an applet and it might only run on Linux.

By creating a cube of the images, where the z-axis represents time, its possible to play back different parts of the movie from different layers in time. Which makes for some quite interesting and dizzing effects.

For example a time buble where playback is delayed around a “bulge in the timespace continuum” :s (a video of some guy playing with it (timebuble1.avi) some sourcecode for a similar effect where the mouse pointer moves the buble (TimeCube.pde) another more “traditional slitscan” (CamWarpTime.pde) .

In general there is plenty of room to fiddle with the code, there a functions like selectSlice or initQueues where its decided how to slice time. its great fun to play with..

]]>
http://rotand.dk/2009/02/27/collection-of-processingorg-hacks/feed/ 0
Matrix Multiplication http://rotand.dk/2008/06/14/matrix-multiplication/ http://rotand.dk/2008/06/14/matrix-multiplication/#comments Sat, 14 Jun 2008 16:03:46 +0000 http://rotand.dk/blog/?p=69 Who would have thought that matrix multiplication could be beautiful ?

linear tranformation by matrix multiplication

The very short desctiption :

inspiration from an example of homogeneous coordinates in my linear algebra book and lectures about lineartransforms.

There is a jar, with sourcecode, if you want to se it “live” or twiddle with it.

tegneri

]]>
http://rotand.dk/2008/06/14/matrix-multiplication/feed/ 4
Strange Attractor Wars http://rotand.dk/2008/04/08/strange-attractor-wars/ http://rotand.dk/2008/04/08/strange-attractor-wars/#comments Mon, 07 Apr 2008 22:10:04 +0000 http://rotand.dk/blog/2008/04/08/strange-attractor-wars/ Strange Attractors are quite pretty.

I made have generated quite some random attractors.

Now I need to find the most beautiful ones, and I need your help!

I have created a voting system, where 3 attractors line up and you select the best one. The votes are then accumulated and and overall top 10 is generated.

Strange Attractor wars

It is heavily inspired by kittenwars.com.

I have been hacking away on this far to long. But expect an article with more details on Strange attractors and probably more features in the “war” application. (like top 100, biggest looser, most victorious etc).

Now just go and make some votes :)

]]>
http://rotand.dk/2008/04/08/strange-attractor-wars/feed/ 5
Flash development http://rotand.dk/2008/02/09/flash-development/ http://rotand.dk/2008/02/09/flash-development/#comments Fri, 08 Feb 2008 21:21:13 +0000 http://rotand.dk/blog/2008/02/09/flash-development/ A course Im taking requires that we use flash and we are left to using specific workstations at school or download a 30 day trial for the 6-7 week project. And well either way we are supposed to be using a proprietary piece of software from Adobe.

The first flash assignment were to create a picture slide show, with captions and a soundtrack. Using the Adobe flash gui its very easy, drag and drop “programming”.

But as Richard Stallman says “its not a matter of convenience, but of ethics”. So I went looking for replacements. In another course I had no problems using octave instead of matlab, so should this be any different? Yes, unfortunately it seems that its very difficult to get the needed features in free software, well at least in the given timeframe.

HaXe is able to compile to swf, as well as doing a lot of other nifty stuff. I just learnt about it recently from this video.

I didn’t manage to make the entire assignment, (yet?) in haxe, but i did make this :
flash presentation(5MB+)

UPDATE

I did manage to add sound and captions.

So how did I do it?

Well first of all i installed haxe and swfmill. Haxe is able to use the actionsscript api and swfmill can create resources so your are able to refference them in you haxe code.Here is the recipe i used to create this slideshow.

1. create a xml file for swfmill, in order to create a resources for the haxe code.This i something like

 <movie width="480" height="480" framerate="25">
   <frame>
      <library><clip id="img1" import="library/newton001Slide_.png"/>

unfortunately swfmill isn’t able to add sound to a library, so that had to be loaded directly from a file. I had some trouble getting it to function on the server but i think that adding “-D network-sandbox” to the haxe compilation might have done something. ???

2. run swfmill, thats swfmill simple slides.xml slides.swf

now i had linkage names for the image files, and could add them to the movieClip.

3. Create file SlideShow.hx

The main part. The basic haxe syntax is pretty straightforward, but since it uses the actionscript api it were mostly a question of getting a hang of actionscript. I did however strugle a bit with making a anonymous function, for the sounds onLoad. I used “static inline function sndStart(succes){…}” , its a wee bit diffrent than what i would do in java. but it works.

3. compile.

make a “make file” for haxe, compile.hxml

-swf test.swf
-main SlideShow
-swf-lib slides.swf
-swf-header 480:480:25:FFFFFF
-D network-sandbox

The last part -D is a conditional flag and as far as i can tell it shouldn’t do anything, but a saw it in Fmp3PlayerHx and when i added it the sound seemed to work from the server, using a URL :s :s

4. run haxe compile.hxml

5. display the pretty result. (try not to go crazy when wordpress decides to help you format the html code….), at first i tried embedding the flash in this post, but wordpress kept on changing the code, apparently if you add code and have newlines between the tags it throws in a couple og <p> tags …..

Now its on a separate page, then you don’t have to download the 5 mb flash file just to view the page, and I can use wordpress with out getting too frustrated.

sourcecode slideShow.hx

The music is “the free software song” this version is by Jono Bacon , and I personally prefer it to the version by Richard Stallman

]]>
http://rotand.dk/2008/02/09/flash-development/feed/ 2
xonix mobile edition http://rotand.dk/2007/07/28/xonix-mobile-edition/ http://rotand.dk/2007/07/28/xonix-mobile-edition/#comments Sat, 28 Jul 2007 02:29:49 +0000 http://rotand.dk/blog/2007/07/28/xonix-mobile-edition/ Having toyed around with J2ME for the freeVibes, I got a bit hooked on coding for the mobile phone.

So I started to recreate the classic oldskool game Xonix, it’s a game I really like. So simple and addictive. It’s not the first time I’m coding it, I have made it as an applet about a year ago (Xonix applet). As well as being a fun game to play I find it a fun game to code too. Though I have had my share of frustrations. The basic functionality is a fillalgorithm, that has to fill an area on both sides of the line / trail you make with the ‘pilot’. This has to be fast and efficient – nobody likes a game where you have to wait for updates.

xonix screenshot

When I first made the game i found a neat fill-algorithm. (flood fill wikipedia). So it should have been a piece of cake to implement it in J2me, its java… I deliberately choose not to reuse old code, as I feared it would be horrible ugly. And a course in datastructures and algorithms should have given me some tools to make a better / cleaner implementation. Then the woes began. J2ME, has no ArrayList it has vector and a stack, and the are not generic so no typecasting. I made a version using Vector, but somehow i managed to use all the memory. When I look back I have a nagging suspicion that the Vector isn’t to blame – but rather me that somehow feed it to much data. No matter what it was I got rid of the Vector and started using arrays, and using indexing like in images or c-“double”arrays (index = x + y * WIDTH). Finally it could fit in memory.

And then I started looking for graphics, a nice game really depends on nice sprites – much more than a beautiful algorithm. I couldn’treally find any and its quite painful, at least for me, to make sprites. It gets real ugly, real fast – hmm no it gets real ugly real slow, because i’m no good at creating graphics. Well the frustrations grew and I ending up abandoning the project. The basic gameplay works, but is buggy and as mentioned the graphics sucks.

xonix screenshot 2

All in all it was quite fun programming, and some day i might give it another go.

]]>
http://rotand.dk/2007/07/28/xonix-mobile-edition/feed/ 0
another one bites the bits http://rotand.dk/2007/05/27/another-one-bites-the-bits/ http://rotand.dk/2007/05/27/another-one-bites-the-bits/#comments Sun, 27 May 2007 19:33:18 +0000 http://rotand.dk/blog/?p=3 Well it was ment to happen.

Everybody has one, so now I have to join in, with another pointless blog.

I will primarily use it to show off :

  • Code – i like programming
  • Weird links
  • I intend to stay away from political and personal rants.
]]>
http://rotand.dk/2007/05/27/another-one-bites-the-bits/feed/ 1