# Generate an audio file which makes rhythmic buzzer sounds

I will perform an experiment which consists of deadlift trials during 5 minutes. To control the rhythm of this fatiguing exercise, I would like to generate a sound file which gives a buzzer noise every 7.5 seconds.

In Mathematica's documentation,

Play[Sin[440 2 Pi t], {t, 0, 1}]


can generate a 1-second buzzer noise. But how do I generate a 6.5-second silence and merge the noise-silence together, and repeat them as much as we want?

• What have you tried? Where did you get stuck? Generating a buzz (did you look at Play)? Stitching it together with a stretch of silence? Proceed step by step and ask specific questions. – Szabolcs Oct 3 '17 at 9:24
• Thank you, I can now generate a buzzer. This question gets more specific now. – Tough Kid Oct 3 '17 at 9:38
• With AudioJoin. – Szabolcs Oct 3 '17 at 9:49
• Here's something to think about: what do you think would you get if you multiplied your sinusoid with a square wave with appropriate amplitude and period? – J. M.'s torpor Oct 3 '17 at 10:06

Here's one possibility:

Make a 1 second beep with harmonics:

Play[Sum[1/k Sin[k 400 2 Pi t], {k, 1, 4}], {t, 0, 1}]


Modulate it with another sine wave if you want to make it sound rougher:

beep = Play[Sum[1/k Sin[k 400 2 Pi t] (0.75 + 0.25 Sin[60 2 Pi t]), {k, 1, 4}], {t, 0, 1}]


Add 6.5 seconds of silence for a total of 7.5 seconds

au = AudioJoin[{beep, AudioGenerator["Silence", 6.5]}]


Repeat this 40 times for 5 minutes of data.

result = AudioJoin@ConstantArray[au, 40]

Export["result.wav", result]

• Thank you very much. What a pity that my MMA is a student version (available as long as I am a student), The version of 10.4.1 can not be updated to have AudioGenerator and AudioJoin functions. – Tough Kid Oct 3 '17 at 12:54
• @ToughKid Create the data directly then, with Table, and use ListPlay (or SampledSoundList) – Szabolcs Oct 3 '17 at 12:59
• Thanks very much, SampledSoundList do the job. I've done it this way. Export["Beep.mp3", Sound[SampledSoundList[ Flatten[ConstantArray[ Join[Table[Sin[2 [Pi] 500 t], {t, 0, 1, 1./2000}], ConstantArray[0, 13000]], 100]], 2000]]] – Tough Kid Oct 3 '17 at 14:02

First make a $440 \text{ Hz}$ wave ($1 \text{ s}$):

a = Audio @ Play[Sin[440 2 Pi t], {t, 0, 1}];


Add $6.5 \text{ s}$ silence:

b = AudioPad[a, 6.5]


Join them. Repeat b for $5\times 60/7.5=40$ times.

au = AudioJoin[Table[b, Round[5*60/7.5]]];
AudioPlot[au, AspectRatio -> 1/10] Thanks to @Szabolcs 's answer and idea of SampledSoundList, I've done it in this way. I post it out for those who have not the lastest version of MMA.

Export["C:\\Users\\Wei\\Downloads\\Beep2.mp3",
Sound[
SampledSoundList[
Flatten[
ConstantArray[
Join[
Table[Sin[2 \[Pi] 500 t], {t, 0, 1, 1./2000}],
ConstantArray[0, 13000]
],
200]
],
2000
]
]
]


Here's an implementation of the idea I gave in the comments. Piecewise[] is quite convenient to use here when using Play[]:

With[{n = 6},
Play[Piecewise[{{Sin[440 2 Pi t], 0 <= Mod[t, 15/2] <= 1}}, 0],
{t, 0, 15 n/2}, SampleRate -> 8192]]


For the Audio[] version:

With[{n = 6},
ts = TimeSeries[Transpose[{FoldList[Plus, 0, PadRight[{}, 2 n, {1, 13/2}]],
PadRight[{}, 2 n + 1, {440, 0}]}]];
AudioGenerator[{"Sin", ts}]]