Wednesday, April 22, 2015

Web Audio

Good source of web audio features

http://labs.music.baidu.com/demo/audiolab/?p=0
http://labs.music.baidu.com/demo/interactions/visualization/
Getting Started with Web Audio API
Web Audio API - High-level JavaScript API for processing and synthesizing audio
http://www.sitepoint.com/5-libraries-html5-audio-api/
http://codegeekz.com/10-javascript-audio-libraries-for-developers/
http://www.smartjava.org/content/exploring-html5-web-audio-visualizing-sound
http://ianreah.com/2013/02/28/Real-time-analysis-of-streaming-audio-data-with-Web-Audio-API.html
https://blog.groupbuddies.com/posts/39-tutorial-html-audio-capture-streaming-to-node-js-no-browser-extensions

https://nusofthq.com/blog/recording-mp3-using-only-html5-and-javascript-recordmp3-js/
https://github.com/icatcher-at/MP3RecorderJS
https://github.com/akrennmair/libmp3lame-js

http://www.patrick-wied.at/blog/how-to-create-audio-visualizations-with-javascript-html
http://www.schillmania.com/projects/soundmanager2/demo/360-player/canvas-visualization.html
http://www.sitepoint.com/3-breakthrough-ways-to-visualize-html5-audio/

Audio: visualization
http://readwrite.com/2008/03/13/the_best_tools_for_visualization


Programming with sound - Introduction

http://blogs.msdn.com/b/dawate/archive/2009/06/22/intro-to-audio-programming-part-1-how-audio-data-is-represented.aspx

Digital audio:
- stereo: 2 channels, for left/right ear
- mono: 1 channel only.
- sampling rate: ~ 44,100/sec, 44.1k Hz. Number of points/second. Other rate: 8/48/96/192K Hz.
- fundamental frequency: Number of oscillations of the wave per sec. 440 Hz - Concert A. 261.25 Hz - Concert C. Higher frequency == higher pitch.
- decibel: amplitude of the wave
- bit depth/bits per sample: 8-bit/16-bit waveform - use 8/16 samples for a waveform. The larger, the better quality.
- multiple tones: sound in real world is overlap of multiple sine waves/tones.

http://blogs.msdn.com/b/dawate/archive/2009/06/23/intro-to-audio-programming-part-2-demystifying-the-wav-format.aspx

- wave format: maybe the most basic sound format. Developed by Microsoft and IBM.
- uncompressed. but cannot go over 4GB, since file size header field is 32-bit unsigned int.
- chunks
- header
- format chunk
- data chunk
- making a wave file.

http://blogs.msdn.com/b/dawate/archive/2009/06/24/intro-to-audio-programming-part-3-synthesizing-simple-wave-audio-using-c.aspx

http://blogs.msdn.com/b/dawate/archive/2009/06/25/intro-to-audio-programming-part-4-algorithms-for-different-sound-waves-in-c.aspx


Pure Data

http://puredata.info/

Pure Data (aka Pd) is an open source visual programming language. Pd enables musicians, visual artists, performers, researchers, and developers to create software graphically, without writing lines of code. Pd is used to process and generate sound, video, 2D/3D graphics, and interface sensors, input devices, and MIDI. Pd can easily work over local and remote networks to integrate wearable technology, motor systems, lighting rigs, and other equipment. Pd is suitable for learning basic multimedia processing and visual programming methods as well as for realizing complex systems for large-scale projects.

Pd is free software and can be downloaded in different versions.

http://en.wikipedia.org/wiki/List_of_audio_programming_languages


Programming with sound - Overview

http://forum.devmaster.net/t/what-is-sound-programming/20773


Unlike most other things, it's real-time stuff (we're talking 0.02ms stuff here, as oposed to video's 17ms; and nobody cares if you miss a frame here or there, but audio must be flawless), and you have to deal with latencies and all sort of fun stuff like that.


Again, it looks simple and the concepts are pretty easy, but for some reason it always ends up being tricky. Thus, most people end up using libraries like FMOD, and *still* end up having issues here and there.

Also, if you want to synthesize audio, there is indeed a whole lot of interesting mathematics and theory you won't see much in other places.


I like to lump "sound programming" into 3 broad (sometimes overlapping) categories.

1) Sound Implementation programmer. This sounds like what you probalby think of. That's the programmer (often an intern ;0) whose job is to sprinkle the code with calls like "PlaySound(SNDTag, Parameters); through the game. (it can be quite a bit more than that, of course). Sound Implementation is usually, but not always, pretty straightforward

2) Sound Engine/Tool programmer. These programmers write the high-level sound engines that perform things like real-time streaming, data file parsing, etc. That requires pretty good knowledge of real-time and system programming. They may need to write entire (friendly and robust) User interfaces that a sound designer or composer will use when creating content. They are the essential link between content and code in content-driven audio development systems.

3) low-level audio signal processing programmer. These programmers typically need to know assembly language like the back of their hands as well as the complex mathematics behind the processing of audio. FFTs, DFT's, MLTs, IIR, FIR filters, data compression/decompression algorithms. That's pretty heavy stuff. And there's a ton of stuff going on out there. People do entire PhD dissertations on things like physical modelling of sound, real-time analysis of music, or environmental modeling..

So there's a lot of "meaty" stuff in game audio programming-- way more so than it may seem on the surface. Video game music and sound design still need a lot of specialized code to make it work
Brian Schmidt
Executive Director
www.GameSoundCon.com5


http://stackoverflow.com/questions/4801690/i-want-to-learn-audio-programming

- analogue sound: magnetic tape.. complex numbers, fourier transformation.
- sampled sound: CD, mp3, Ogg vorbis.. DSP.
- synthesized sound: sound + instrument type.

A programmer's guide to sound (1997)


Tuesday, April 21, 2015

Create daemon in Java

This can be a windows service or a unix daemon. The implementation might be different depending on platform. So I'm starting to do some research.


1. Apache Commons Daemon [1]

Apache Commons Daemon is a good alternative. It has Procrun [2] for windows services, and Jsvc [3] for unix daemons. It uses less restrictive Apache license, and Apache Tomcat uses it as a part of itself to run on Windows and Linux! To get it work is a bit tricky, but there is an exhaustive article [4] with working example. With Apache Commons Daemon you can now have a custom executable name and icon! You can also get a custom Windows tray monitor with your own name and icon!

Jsvc is a set of libraries and applications for making Java applications run on UNIX more easily.
Jsvc allows the application (e.g. Tomcat) to perform some privileged operations as root (e.g. bind to a port < 1024), and then switch identity to a non-privileged user.It can run on Win32 via the Cygwin emulation layer, however Win32 users may prefer to use procrun instead.

Procrun is a set of applications that allow Windows users to wrap (mostly) Java applications (e.g. Tomcat) as a Windows service. The service can be set to automatically start when the machine boots and will continue to run with no user logged onto the machine.


2. Java Service Wrapper (JSW) [download]

See short introduction in [5]. Also an implementation of it: YAJSW - Yet Another Java Service Wrapper [6]. Cons (?): community version cannot be run on a server.


References:

[1] http://commons.apache.org/daemon/
[2] http://commons.apache.org/daemon/procrun.html
[3] http://commons.apache.org/daemon/jsvc.html
[4] Java as Windows Service with Apache Commons Daemon
[5] Running Java Applications as a Windows Service
[6] YAJSW - Yet Another Java Service Wrapper 
[7] http://stackoverflow.com/questions/68113/how-to-create-a-windows-service-from-java-app
[8] Creating a Java Daemon (System Service) for Debian using Apache Commons Jsvc


Greasemonkey

Greasemonkey can do some interesting tricks on a webpage.

Greasemonkey scripts (Javascript) can alter web page elements, add a div or box to the page, trigger button click events and others.

For example, here is a script that adds a checkbox before the link tag for ever <li> element:


// ==UserScript==
// @name       script name
// @namespace  http://my.homepage/
// @version    0.1
// @description  add marking checkbox.
// @match      http://matched_website.com

// @match      https://matched_website.com
// ==/UserScript==

function changhandler(event) {
    if (event.target.checked) {
        localStorage[event.target.name] = true;
    } else {
        localStorage.removeItem(event.target.name);
    }
}

[].forEach.call(
    document.getElementById('main').getElementsByTagName('li'),
    function(e) {
        var checkBox = document.createElement('input');
        checkBox.type = 'checkbox';
        checkBox.name = e.getElementsByTagName('a')[0].innerHTML;
        checkBox.checked = localStorage[e.getElementsByTagName('a')[0].innerHTML];
        checkBox.addEventListener('change', changhandler, false);
        oj.insertBefore(checkBox, null);
    }
);


[1] http://en.wikipedia.org/wiki/Greasemonkey

Sunday, April 12, 2015

Create animated and transparent GIF image

Gifsicle: Very useful tool to manipulate gif, and create animated gif:

http://www.lcdf.org/gifsicle/


== How to make an existing animated gif loop repeatedly ==

Solution involving the Terminal [1]:
  1. Download the sources of Gifsicle
  2. Unpack the sources and go to the unpacked directory
  3. Do ./configure --disable-gifview --disable-gifdiff
  4. Do make
  5. Do cd src
  6. And finally do ./gifsicle -bl /path/to/image.gif
Note: to install, after step 4, do: sudo make install

Solutions using GUI tools (I didn't test any them !):
  1. You can try GifBuilder (requires Rosetta to work with Snow Leopard).
  2. Pixen also seems to be a Gif Editor.

[1] http://superuser.com/questions/159212/how-do-i-make-an-existing-animated-gif-loop-repeatedly
[2] http://blog.iharder.net/2009/10/22/gif-create-animated-gifs-with-mac-os-x-preview-app/
[3] http://osxdaily.com/2013/01/27/make-a-transparent-image-png-or-gif-easily-with-preview-for-mac-os-x/
[4] http://osxdaily.com/2010/01/24/convert-images-in-mac-os-x-jpg-to-gif-psd-to-jpg-gif-to-jpg-bmp-to-jpg-png-to-pdf-and-more/ 

Monday, April 6, 2015

Compress javascript a.js into a.min.js

Compress javascript a.js into a.min.js can be done on this site: http://jscompress.com/

Perl - extend lib path

See: http://www.perlhowto.com/extending_the_library_path

This is useful when you want to use personal lib for perl modules, which is not on perl path (@INC) and cannot be found.

3 methods are mentioned.

1) The non-invasive method is to use -I switch:

perl -I /home/path/lib -I /usr/another/lib script.pl

2) add path to environment:

# unix, bourne shell
PERL5LIB=/home/path/lib:/usr/another/path/lib; export PERL5LIB


3) add path to perl code:

#!/usr/bin/perl
use lib "/home/path/lib";
use lib "/usr/another/lib";

use MyCustomModule;

General Game Playing

General Game Playing is a course given by Stanford on the application of AI in computer games.

The course material is available here: http://logic.stanford.edu/ggp/chapters/


Blog Archive

Followers