Using Manipulate to vary the frequency of a sound produced by SoundNote[]

I think that varying a parameter of a sound continuously, while it is being played is not possible in Mathematica. A workaround is to use an external program. ChucK is a real-time audio programming language that can run many threads ("shreds") concurrently, and allows dynamically adding/removing shreds from the system. We can create shreds that vary parameters from within Mathematica.

Here's a working, continuously adjustable solution based on ChucK:

First, you need to download the chuck binary and put it some place accessible. I put it in ~/bin.

Then I wrote this chuck script, and put it in ~/chuck:

/* snd.ck */

public class MyState {
    static int freq;
}

500 => MyState.freq;

SinOsc s => dac;

while (true) {
    MyState.freq => s.freq;
    50::ms => now;
}

Then I started a chuck host from a terminal using chuck --loop.

Finally, I did this in Mathematica:

(* this will start playing the sound by adding the above defined shred *)

SetDirectory["~/chuck"]
Run["~/bin/chuck + snd.ck"]

(* we'll use this script to adjust the static MyState.freq variable in chuck *)
script = FileNameJoin[{$TemporaryDirectory, "adjust.ck"}]

Manipulate[
 Export[script, IntegerString[s] <> " => MyState.freq;", "String"];
 Run["~/bin/chuck + " <> script];
 s,
 {{s, 440}, 200, 1000, 1}
]

Kill chuck from the terminal to stop the sound. Of course there are better ways to do stop/start the sound, without killing chuck, but I was lazy. (You'd need to add/remove shreds that perform a specific task.) This is just a simple example showing how to control ChucK from within Mathematica, using sliders.


The reason you are getting error messages is because you need to constrain the values of the SoundNote to integers. For instance:

 Manipulate[EmitSound[Sound[SoundNote[n, 3]]], {n, 1, 10, 1}]

works fine.


There is a nice Wolfram demonstration

http://demonstrations.wolfram.com/BeatFrequencyOfSoundWaves/

that lets you listen to beat frequencies of sine waves. You will need to edit the .cdf in order to listen to any beat frequencies near the octave.