Message Boards Message Boards

How I made a laser sound effect

Heres a youtube video of the laser sound.

 Definitions: 
T[f_, mf_, M_] := SawtoothWave[f t + M/(mf + .001)*SawtoothWave[mf*t]]
c = 1/3
r = 44100

A laser example (note you can press play repeatedly and have a starship battle):
LaserA = Table[ 4*Sin[55/(t + .0001) ]*T[22.5 t, 55/16, 55/8]*Exp[-t/(c/14)], {t, 0, 5 c, 1/r}]
ListPlay[LaserA, SampleRate -> 44100]
Example 2:
LaserB = Table[ 4*Sin[55/(t + .0001) ]*T[22.5 t, 0, 0]*Exp[-t/(c/13)], {t, 0, 8 c, 1/r}]
ListPlay[LaserB, SampleRate -> 44100]
Example 3: laser with slower initial chirp
RelaxedLaser = Table[ 4*Sin[165/(t + .0001)]*T[44 t, 4, 8]*Exp[-t/(c/20)], {t, 0, 8 c, 1/r}]
ListPlay[RelaxedLaser, SampleRate -> 44100]
POSTED BY: Allen Majewski
2 Replies
Welcome to Wolfram Community! Cool experiment, Allen! I attempt below to compress your result in something smaller and exploratory. Your sound effects are much higher quality. Mine are cheaper, because I am trying to make them work faster via an app where you can explore space of possible sound parameters. Kind of like a musical instrument. Well, you can take it from here if you want and make it better. Click different parts of the plain to produce slightly different sounds. Warning: dragging will produce a very long sequence of sounds.
T[f_, mf_, M_] := SawtoothWave[f t + M/(mf + 10^-8)*SawtoothWave[mf*t]];
Laser[x_, y_] := Table[Sin[x^1.1/t]*T[x t, y, y]*Exp[-x t], {t, 10^-8, .1, 1/44100}];

Manipulate[EmitSound[ListPlay[Laser[p[[1]], p[[2]]]]];
Graphics[Point[p], PlotRange -> {{10, 100}, {0, 200}}, AspectRatio -> 1, ImageSize -> 100 {1, 1}]
, {{p, {22, 3}}, Locator}, FrameMargins -> 0, AppearanceElements -> None]

POSTED BY: Vitaliy Kaurov
This is fantastic.  I appreciate your efforts to add a user interface, and think your code is quite excellent - you clearly understood the way the function works and kept its essential qualities together.

It would take some experimentation here to optimize this app.  I have, in my original implementation, 5 free parameters which yield the waveform, plus one extra (r) for the sample rate.  In retrospect my code is sloppy because I'm certain the most important parameter for the sound effect is the constant you called x, which is the frequency numerator of Sin[ x / (t + 1e-8].  You are correct to let this be directly manipulated and to correlate it with what I originally called f.

In general, for a simple user interface with fewer user inputs, keeping all the input constants as integer multiples of one another is a good fail safe guess.
POSTED BY: Allen Majewski
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract