MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Mathematica, sounds and placing graphics

  • To: mathgroup at
  • Subject: [mg32892] Re: Mathematica, sounds and placing graphics
  • From: "Enrico Luciano" <e.luciano at>
  • Date: Mon, 18 Feb 2002 05:22:16 -0500 (EST)
  • References: <a4focs$j5j$>
  • Sender: owner-wri-mathgroup at

Dear Sirs,
 I found the answer myself (with a little help from the past, as you'll see)
and I write it down for someone with my same need.

I've done some research on the MatheGroup Mailinglist Archive and I found a
message from P.J. hinton written on 1999, who says:

------- Original Message Start --------

On 5 Mar 1999 JBFOUAD at 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] :=
    nb = NotebookCreate[WindowSize -> {0.1, 0.1}];
      Cell[GraphicsData["PostScript", DisplayString[sndObject]]]];
    SelectionMove[nb, All, Notebook];
    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 Research, Inc.        
Disclaimer: Opinions expressed herein are those of the author alone.

------- Original Message End --------

This didn't worked in my case. the sound simply doesn't plays... Do hear
something I had to erase the "NotebookClose[nb, Interactive -> False]" line
in the code...

But this was an unpayable hint, so I modified the code as follows and it
worked. I can finally hear sound and place the graphics where I want:

    Cell[TextData["Grafico"], "Output", Evaluatable -> False,
      CellTags -> {"suono"}]];

Showmygraph[sndObject_Sound] := Module[{nb},
    nb = EvaluationNotebook[];
    NotebookFind[nb, "suono", All, CellTags];
    SelectionMove[nb, All, Cell];
        GraphicsData["PostScript", DisplayString[sndObject]],
        CellTags -> {"suono"}
    SelectionMove[nb, All, Notebook];

and then:

outputsound = Miscellaneous`Audio`FrequencyModulation[fc, {fm, pd}, t];
Show[outputsound, DisplayFunction -> ShowMygraph];

Here it is.

Enjoy if you need!

Bye, Enrico

  • Prev by Date: Re: Mathematica for Mac OS X vs. 9?
  • Next by Date: Re: Partitions
  • Previous by thread: Mathematica, sounds and placing graphics
  • Next by thread: maximal entropy method