Tag: DSP

ep-413 DSP week 9



Building a Max patch that displays, transforms, and responds to internet data.

building materials
  • Max (6.1.7 or newer)
  • Soundflower –

Both available from Cycling 74 http://cycling74.com/

The Max patch is based on a tutorial by dude837 called “Automatic Silly Video Generator”


The patch at the download link in the video is broken – but the javascript code for the Max js object is intact. You can download the entire patch from the Max-projects archive: https://github.com/tkzic/max-projects folder: maxvine

Internet API’s

API’s (application programming interfaces) provide methods for programs (other than web browsers) to access Internet data. Any app that access data from the web uses an API.

Here is a link to information about the Vine API: https://github.com/starlock/vino/wiki/API-Reference

For example, if you copy this URL into a web browser address bar, it will return a block of data in JSON format about the most popular videos on Vine: https://api.vineapp.com/timelines/popular

HTTP requests

An HTTP request transfers data to or from a server. A web browser handles HTTP requests in the background. You can also write programs that make HTTP requests. A  program called “curl” runs http requests from the terminal command line. Here are examples: http://reactivemusic.net/?p=5916

Response data

Data is usually returned in one of 3 formats:

  • JSON
  • XML
  • HTML

JSON is the preferred method because its easy to access the data structure.

Max HTTP requests

There are several ways to make HTTP requests in Max, but the best method is the js object: Here is the code that runs the GET request for the Vine API:

function get(url)
    var ajaxreq = new XMLHttpRequest();
    ajaxreq.open("GET", url);
    ajaxreq.onreadystatechange = readystatechange;

function readystatechange()
    var rawtext = this._getResponseKey("body");
    var body = JSON.parse(rawtext);
    outlet(0, body.data.records[0].videoUrl);


The function: get() formats and sends an HTTP request using the URL passed in with the get message from Max. When the data is returned to Max, the readystatechange() function parses it and sends the URL of the most popular Vine video out the left outlet of the js object.

Playing Internet audio/video files in Max

The qt.movie object will play videos, with the URL passed in by the read message.

Unfortunately, qt.movie sends its audio to the system, not to Max. You can use Soundflower, or a virtual audio routing app, to get the audio back into Max.

Audio from video


Video from audio


Other Internet API examples in Max

There is a large archive of examples here: Internet sensors: http://reactivemusic.net/?p=5859

We will look at more of these next week. Here is simple Max patch that uses the Soundcloud API: http://reactivemusic.net/?p=17430

Gokce Kinayoglu has written a java external for Max called Searchtweet: http://cycling74.com/toolbox/searchtweet-design-patches-that-respond-to-twitter-posts/

Many API’s require complex authentication, or money, before they will release their data. We will look ways to access these API’s from Max next week.


There are API services that consolidate many API’s into one API. For example:

Scaling data

Look at the Max tutorial (built in to Max Help) called “Data : data scaling” It contains most of what you need to know to work with streams of data.


Using the Vine API patch that we built during the class as a starting point: Build a better app.

Ideas to explore:

  • Is it possible to run several API requests simultaneously?
  • Recording? Time expansion? Effects that evolve over time?
  • Generate music from motion, data, and raw sound?
  • Make a video respond to your instrument or voice?
  • Design a better user interface or external controller?
  • Will this idea work in Max For Live?
  • How would you make adjustments to the loop length, or synchronize a video to other events?
  • Make envelopes to change the dynamic shape?
  • Destruction? Abstraction?
  • Find or write a Max URL streaming object?
  • What about using a different API or other data from the Vine API?

This project will be due in 2-3 weeks. But for next week please bring in your work in progress, and we will help solve problems.


Sox resampler library

“One-dimensional sample-rate conversion library”

By robs




Installation guide: http://sourceforge.net/p/soxr/code/ci/master/tree/INSTALL

How configure CMAKE for 32 bit architecture on Mac OS: http://stackoverflow.com/questions/5334095/cmake-multiarchitecture-compilation

Note: this command allowed building static libs for 32 bit:

<span style="color: #000000;">$ cmake -DCMAKE_OSX_ARCHITECTURES=i386 -DBUILD_SHARED_LIBS:BOOL=OFF ..</span>


local files in: tkzic/soxr-0.1.1-Source/


Engine of time.

from Wikipedia




Traveling along the outer edge of the circle, the distance goes from 0 to 2*PI radians, then starts over again. In degrees it would be 0 to 360. A clock goes from 0 to 12. In Max and Pd the phasor~ objects are normalized to run from 0.0 to 1.0. Think of flattening out the edge of the circle to a straight line.

The phasor as input to a sine or cosine function generates one  cycle of a wave for each revolution – as shown in the above animation. For example, cosine would go from 0 to 1 to 0 to -1 to 0.

If you graph the phasor value, it looks like a sawtooth wave – rising in a ramp from 0.0 to 1.0 then falling straight down to 0.0 to start again.

With waves, the distance around the circle represents time (or phase), the projected cosine value represents amplitude.

In science…

“A phasor can be considered a vector rotating about the origin in a complex plane. The cosine function is the projection of the vector onto the real axis. Its amplitude is the modulus of the vector, and its argument is the total phase \omega t+\theta. The phase constant \thetarepresents the angle that the vector forms with the real axis at t = 0.”


In art…

“And the seasons they go round and round 
And the painted ponies go up and down 
We’re captive on the carousel of time 
We can’t return we can only look 
Behind from where we came 
And go round and round and round 
In the circle game.”

-Joni Mitchell

(These lyrics happen at about 4:40 in the video…)


Heterodyne filter in Max

Multiply by an analytic signal to detect the frequency of a sine wave.

When the frequencies match, the sum of the real and imaginary parts will be positive.



max-projects on Github: https://github.com/tkzic/max-projects

folder: heterodyne-filter

patch: heterodyne-test3.maxpat


Spectral freeze in Max

By Jean Francois-Charles

Freeze sounds with Max MSP Jitter using FFT and Inverse FFT. For this video to be really useful, you will need to download the free Max/MSP/Jitter patches on http://www.cycling74.com/share.html
To get more “under the hood” insight, download the free article “A Tutorial for Spectral Sound Processing with Max/MSP and Jitter” http://www.mitpressjournals.org/doi/pdf/10.1162/comj.2008.32.3.87

note: local patches in tkzic/jfcharles/


An interactive granular synthesizer.

By Chris Carlson


Installed on Mac OS 10.9.2.

Modified the makefile to point to the Macports version of /opt/local/lib/libsndfile.dylib and /opt/local/include/sndfile.h

Using some of the Max/MSP example sound files.

The app seg faults on load, randomly. If you keep trying, it eventually comes up.