Possibly more complicated than you're looking for, but I added some
comments to an old (and not very good) counterpoint melody generator and
pushed it here:
https://github.com/mlochbaum/JSound/blob/master/counterpoint.ijs

The repository as a whole has tools for synthesis and mixing as well as
a function to write a .wav file. With these I can turn a melody into an
actual sound, and then a playable file:

   load '~user/Sound/synth.ijs ~user/Sound/counterpoint.ijs'
   ]m =. 17 (melody-]) _7          NB. 7 notes, mixolydian mode centered at 0
0 2 0 5 4 2 0 _3 _1 _3 2 0 _1 2 6 2 0
   l =. <.F * (%2) * 60%110        NB. Eight notes (two per beat) at 110 BPM
   s =. sine l # m trans note 'd'  NB. Turn into a sine wave
   s =. ((#m) rep 0.1^I l) * s     NB. Exponential envelope
   'a.wav' writewav~ (-:max) * s   NB. Write to file at half max volume

The function play writes a file and immediately plays it. It requires
the aplay command which comes with Linux but I expect it would be easy
to write a version for another operating system.

   play (-:max) * s

Marshall

On Sat, Mar 28, 2020 at 05:27:46PM -0400, Devon McCormick wrote:
> Hi -
> has anyone done work with generating music or musical phrases in J?  I'm
> helping someone develop a music training game that starts by generating
> sounds with a particular key, tempo, and phrase length.  The idea is to
> help students to train their ears by testing them on their ability to play
> back a randomly-generated musical phrase.
> 
> I've told my collaborator that I think the generation part should be
> relatively straightforward but I am not schooled in music, so I'm not sure
> how to start.
> I'm guessing that the second part of comparing the user's response to the
> generated phrase will be more difficult but I'd like to get any kind of
> start I can.
> 
> Does anyone have any ideas about this?
> 
> Thanks,
> 
> Devon
> 
> -- 
> 
> Devon McCormick, CFA
> 
> Quantitative Consultant
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to