I've been playing around a little with Oleg Kobchenko's media/wav

In its current implementation, it relys on
https://docs.microsoft.com/en-us/windows/win32/multimedia/the-playsound-function
which means that it does not adequately support osx nor linux
machines. Finding and supporting equivalent mechanisms there would be
interesting.

But, anyways, here's a brief introduction:

   load'media/wav'
   lq=: [: <. 0.5 + 255 * ]
   normalize=: (% >./)@(- <./)
   4 wavplay wavmake lq normalize 1 o. 2p1*440*normalize i.11000

This will play one second of 440 Hz --
https://en.wikipedia.org/wiki/A_(musical_note)

The default sample rate used by this playback mechanism is 11000
samples per second.

The normalize verb transforms a numeric list so that its minimum value
is 0 and its maximum value is 1.

The lq verb translates a 0..1 floating point or fractional list to a
0..255 numeric list. And, 4 wavplay wavmake on the result of lq sends
the sequence as an audio sample to be played by the computer's sound
system.

If I wanted to be a little fancier, I might also want to disable a
potential ending "click" that can arise when a sound sample ends with
a non-neutral voltage value and no corresponding sound sample follows
it. And, maybe while I am at that, I should make it so that repeated
applications of lq perform its transformation only once.

softend=: ,  2#{: (+ * * i.@|) 128 - {:
lqsoft=:  softend@lq^:(1 >: >./)

Now I can throw in a one second "envelope" on my note

A=: normalize 1 o. 2p1*440*normalize i.11000
envelope=: normalize (* ^@-) 15*normalize i.11000
play=: 4 wavplay wavmake

   play lqsoft envelope*A

There's a lot more that can be done here -- assembling and scheduling
different notes, introducing beats and resonances, etc. etc. I've
barely scratched the surface of what can be done. And, of course,
different machines will introduce their own quirks, and we each have
our own various ideas of what sounds good.

Still... possibly of interest to some people here?

Thanks,

-- 
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to