Re: Sound with Mathematica
- To: mathgroup at smc.vnet.net
- Subject: [mg16310] Re: Sound with Mathematica
- From: "P.J. Hinton" <paulh>
- Date: Sun, 7 Mar 1999 01:05:39 -0500
- Organization: "Wolfram Research, Inc."
- Sender: owner-wri-mathgroup at wolfram.com
On 5 Mar 1999 JBFOUAD at bouyguestelecom.fr wrote: > I am living in France and I am working with some friends at the > university about making a dialer (use of DTMF frequencies) with > mathematica for windows. > > When we use the "Play" function in mathematica (which produce a sound at > a certain frequency), it also produces a graphic. How can we obtain the > sound without printing the graphic (only the sound). We don't know if > there is an option which can delete the graphic. The playing of the sound is handled by the notebook front end. It receives the sound as a Mathematica PostScript string, which it then renders on screen as a graphic. It is necessary to have the Graphic in a notebook so that the front end can play it. Note, however, that the notebook that holds the graphic need not be the evaluation notebook. Here is a snippet of code that pastes the PostScript string as a cell in a very small notebook to play it. Afterwards, the notebook is discarded. hiddenSoundDisplay[sndObject_Sound] := Module[{nb}, nb = NotebookCreate[WindowSize -> {0.1, 0.1}]; NotebookWrite[nb, Cell[GraphicsData["PostScript", DisplayString[sndObject]]]]; SelectionMove[nb, All, Notebook]; FrontEndTokenExecute["SoundPlay"]; NotebookClose[nb, Interactive -> False] ] You can then use this as follows: Play[Sin[200 Pi t], {t, 0, 1}, DisplayFunction -> hiddenSoundDisplay] To make this function the default so that you don't have to specify it as an option to sound-generating functions, you can do this: $SoundDisplayFunction = hiddenSoundDisplay Note that the front end does not support the token "SoundPlay" for windows that have the option Visible -> False, so it is impossible to prevent at least a miniscule window from popping up. -- P.J. Hinton Mathematica Programming Group paulh at wolfram.com Wolfram Research, Inc. http://www.wolfram.com/~paulh/ Disclaimer: Opinions expressed herein are those of the author alone.