How do we identify a tune (melody) from a music piece amidst the sound made by many instrument that may be playing different notes at the same time? Several of human survival skills helps us to group related items (tune) and identify pattern from chaos:
(1) Proximity - related item is likely to be close to each other. Music usually uses notes that are close (1 or 2 steps up of down) in a melody. Notes in a melody also has temporal proximity. The notes flow one after another in succession
(2) Similarity - notes in a melody is usually carried by a same musical instrument like voice or piano
(3) Continuity - power to connecting the dots. Following the note flow, one can "predict" the following notes that made up a melody, even if the melody is carried by multiple instruments successively.
(4) Common fate - melody and accompaniment flows in different note pitch level, different trend (one going up and the other going down) and different rhythm.
Saturday, October 28, 2017
Sunday, October 22, 2017
Sensory Disonance
A note entering an ear causes the ear drum to vibrate. The in turn stimulate a patch of hairs in the cochlea in the inner year. Different frequency will stimulate a different cochlea patch. When several notes is heard, multiple cochlea patches are stimulated. Patches for 2 semitone may have overlapped area. The brain would need to work herder to identify them. This biologically caused us to sense the sound combination of 2 semitone as dissonant.
Interestingly, this same condition may appear to tones that are greater than semitones in the lower frequency range. In other words, chords in lower frequency range did not sound as smooth as the same chord in a higher frequency range. That's why musician does not play chord with bass instruments.
Object Serialization
Serialization is to make an object persistent across session. An object exists in memory of a program instance (e.g. Javascript). Once the program terminated, memory is released and the object ceases to exist. To preserve am object across different program instances, the object must be stored in an persistent media (disk). The object memory layout is converted to string and kept on disk.
JSON2 library contains routine to serialize a JavaScript object (stringify) and to recreate the object in memory from a serialize object (parse).
JSON
In addition to using "new" keyword, JavaScript Object can also be created directly from literal values. For example,
Obj1 = {“member1” : “this is member 1”, “member2” : “2”, member 3 : 3, member4 : Obj2};
Or using array notation:
Obj1 = [“this is member 1”, “member2”, 3, Obj2];
JSON is derived from the literal form of the Object in Javascript. The possible JSON value can be a string, number, object, array, true, false and null.
HttpServlet
As most servlet is written to handle request delivered by http protocol, the HttpServlet extends the GenericServlet and provide methods specially created to handle http requests.
HttpServlet defines doGet and doPut methods which can be overridden by the real servlet to process the request. doGet and doPut eventually returns to the Servlet service method. There are more "do" methods for the other http request types such as "head" etc.
HttpServlet also defines 2 new objects, httpRequest and httpResponse to be used in place of the ServletRequest and ServletResponse objects.
HttpServlet defines doGet and doPut methods which can be overridden by the real servlet to process the request. doGet and doPut eventually returns to the Servlet service method. There are more "do" methods for the other http request types such as "head" etc.
HttpServlet also defines 2 new objects, httpRequest and httpResponse to be used in place of the ServletRequest and ServletResponse objects.
JavaScirpt Objects
A JS object is basically an associative array containing a series of key-value pair. To create a JS object, use the new keyword. For example,
Var obj1 = new Object();
Obj1.member1 = “this is member 1”;
Obj1.member2 = 3
Another way to create members of an object is to use square bracket (array?) notation:
Obj1[“member1”] = “this is member 1”
The square bracket notation has an advantage that it can use character not allowed for variable name because the member name is specified as string. For example, Obj1[“1”] works as single digit 1 is not allowed in variable name. Obj1.1 will flag as error by JS.
Array can be generalized (viewed alternatively) as an object with numeric keys (0, 1, 2, ..).
Subscribe to:
Posts (Atom)