0
$\begingroup$

I've made use of autohotkey to write a script that plays audio files of piano keyboard notes when I press key-combos. At risk of digressing I will say a little about how it works. I hold one of i,k,m,j,n,h, or u to designate the octave, space if I want the note to be sharp, and finally press c,d,e,f,g,a, or b to play the respective note. I use Mathematica to generate 84 .wav files, one for each note/key-combo. The system works well except that the higher the note gets the louder it gets. I want to fix this in the note-generating script. My first idea is to multiply the sound wave by a scalar s between 0 and 1 (to adjust the volume), and set PlayRange to {-1,1} to make Mathematica respect the change in amplitude. But Mathematica seems to ignore the PlayRange option when the ListPlay object is being exported.

It works perfectly if the ListPlay object is not being exported, for example to produce a volume-adjusted A4:

<< Music`;

ListPlay[
Table[Sin[s A4 2 Pi t], {t, 0,
   3, 1/44100}], SampleRate -> 44100, PlayRange -> {-1, 1}]]

The problem is that this doesn't work in the batch export:

amplificationAdjust = 1.5;
vol = 50;
Scan[Export[TextString[#[[2]]] <> ".wav", 
ListPlay[
Table[ (84-#[[2]])^amplificationAdjust / 84^amplificationAdjust * vol * Sin[#[[1]] 2 Pi t], {t, 0,
   3, 1/44100}], SampleRate -> 44100, PlayRange -> {-1, 1}]] &, 
Table[{C1 2^(p/12), p}, {p, 0, 83}]]

The audio files are all the same volume as if I hadn't included the PlayRange option at all. Any ideas about how to make this work? Thanks!

$\endgroup$
  • 1
    $\begingroup$ Try Block[{Rescale = # &}, Export[...]] $\endgroup$ – Simon Woods Mar 26 '16 at 22:52
  • $\begingroup$ This worked! Thanks so much. Should this comment be made into an answer? $\endgroup$ – idonutunderstand Apr 23 '16 at 2:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.