PRINT "Welcone to Random Tones and Chords Generator v0.1b" INPUT "Please specify Chord possibility in % (25)"; uaw$
INPUT "Please set music time [sec] for generating WAV file:"; WAVLen
Right
= _MEM(RawMusic
()) 'mono signal, so both channels are the same
aw = 25
PRINT "Chords possibility:"; aw;
"%" bpm = 120
'interval 1 and 2 (semitones)
int1 = 4
int2 = 7
'interval possibility percent
'aw = 25
'tone minimum and maximum
tmin = 35
tmax = 47
'lengths min and max
lmin = 2
lmax = 4
'fill the tone names
f = ((2 ^ ((i - 49) / 12)) * 440)
'Select Case Int(i / 12)
' Case 0: tn(i) = tn(i) + "0"
'End Select
'DEBUG
'Print f; tn(i)
'If i > 24 Then Sleep
'delete all sharp tones
tn(i) = tn(i - 1)
fm(i) = fm(i - 1)
'DEBUG fm(49)="A"
'Print fm(49)
'fill the lengths
lm(i) = 2 ^ i / 2
'DEBUG
'Print lm(i)
'tones between tmin and tmax
i
= CINT((RND * (tmax
- tmin
)) + tmin
)
lr
= lm
(CINT(RND * (lmax
- lmin
)) + lmin
) 'Length out of the lenght fields between 2 and 4 L = 1 / lr * 60 / bpm * 4 'Lenght is parts of a second from the length fields multiplied by bpm
akk = 1
t = 0
PRINT "Length 1/";
LTRIM$(STR$(lr
));
" Tone:"; tn
(i
);
"+"; tn
(i
+ int1
);
"+"; tn
(i
+ 7) 'queue some sound
DO WHILE t
< L
'you may wish to adjust this sample1
= SIN(t
* fm
(i
) * ATN(1) * 8) / 3 * 2 sample1
= sample1
* EXP(-t
* L
) / 3 * 2
sample2
= SIN(t
* fm
(i
+ int1
) * ATN(1) * 8) / 3 * 2 sample2
= sample2
* EXP(-t
* L
) / 3 * 2 sample1 = (sample1 + sample2) / 2
'_SndRaw sample2
't = t + 1 / _SndRate
sample3
= SIN(t
* fm
(i
+ int2
) * ATN(1) * 8) / 3 * 2 sample3
= sample3
* EXP(-t
* L
) / 3 * 2 sample1 = (sample1 + sample3) / 2
'_SndRaw sample
't = t + 1 / _SndRate
RawMusic(rwi) = sample1
rwi = rwi + 1
PRINT "Sound generated, saving to file generated.wav" SAVESOUND8S Left, Right, "generated.wav"
SUB SAVESOUND8S
(Left
AS _MEM, Right
AS _MEM, file
AS STRING) 'Left and Right memory blocks contains value -1 to 1 (_SNDRAW compatible)
Size = OFFSET_to_I64(Left.SIZE) 'convertion is used for WAV file header, becuse offset value can not be used directly
size
AS LONG ' 4 bytes (file size) subchunksize
AS LONG ' 4 bytes (lo / hi), $00000010 for PCM audio format
AS INTEGER ' 2 bytes (0001 = standard PCM, 0101 = IBM mu-law, 0102 = IBM a-law, 0103 = IBM AVC ADPCM) channels
AS INTEGER ' 2 bytes (1 = mono, 2 = stereo) rate
AS LONG ' 4 bytes (sample rate, standard is 44100) ByteRate
AS LONG ' 4 bytes (= sample rate * number of channels * (bits per channel /8)) Block
AS INTEGER ' 2 bytes (block align = number of channels * bits per sample /8) Bits
AS INTEGER ' 2 bytes (bits per sample. 8 = 8, 16 = 16) subchunk2
AS STRING * 4 ' 4 bytes ("data") contains begin audio samples lenght
AS LONG ' 4 bytes Data block size
H8.chunk = "RIFF"
H8.size = 44 + Size / 2
H8.fomat = "WAVE"
H8.sub1 = "fmt "
H8.subchunksize = 16
H8.format = 1
H8.channels = 2
H8.rate = 44100
H8.ByteRate = 44100 * 2 * 8 / 8
H8.Block = 2
H8.Bits = 8
H8.subchunk2 = "data"
H8.lenght = Size / 2
size = Left.SIZE 'now this value is for memory size used by SINGLE ARRAY - WAV 8bit need 1 byte for 1 channel and 1 sample
'recalculate audiodata to file - byte - values
Recalc
= _MEMNEW(size
/ 2) 'this is value used by WAV - size is 4 byte per sample, we recording stereo (2 x 1 byte) therefore is this divided by 2
start& = 0: LRO& = 0
LeftChannel8 = 128 - RawLeft * 128
RightChannel8 = 128 - RawRight * 128
_MEMPUT Recalc
, Recalc.OFFSET
+ s&
, LeftChannel8
_MEMPUT Recalc
, Recalc.OFFSET
+ s&
+ 1, RightChannel8
s& = s& + 2
start& = start& + 4
'write audio data to file
_MEMGET Recalc
, Recalc.OFFSET
, WAVeRAW$
'erase memory
WAVeRAW$ = ""
Offset_to_i64 = num
OFFSET_to_I64 = num