1
Programs / Re: Random Melodies and Chords (first complete and second rewrite - Bug Question)
« on: September 25, 2021, 07:55:23 am »Hi.
Repair row 18 in your last source code as:
DIM RawMusic(_CEIL(_SNDRATE * VAL(uWAVLen$))) AS SINGLE
Ah, now I see, when I press enter, the uWAVLen gets a DIM(0).
Now I put the DIM after the check.
Also, I implemented Pauses (5%)?
Code: QB64: [Select]
- 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 (120):"; uWAVLen
- Input "Please set BPM (120):"; ubpm$
- Input "Please set Pauses possibility in % (5):"; up$
- WAVLen = 120
- aw = 25
- bpm = 120
- Print "BPM:"; bpm
- pperc = 5
- '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
- Next i
- 'delete all sharp tones
- tn(i) = tn(i - 1)
- fm(i) = fm(i - 1)
- Next i
- 'DEBUG fm(49)="A"
- 'Print fm(49)
- 'fill the lengths
- lm(i) = 2 ^ i / 2
- 'DEBUG
- 'Print lm(i)
- Next i
- 'tones between tmin and tmax
- 'Pauses
- L = 1 / lr * 60 / bpm * 4 'Lenght is parts of a second from the length fields multiplied by bpm
- akk = 1
- t = 0
- 'queue some sound
- sample1 = (sample1 + sample2) / 2
- '_SndRaw sample2
- 't = t + 1 / _SndRate
- sample1 = (sample1 + sample3) / 2
- '_SndRaw sample
- 't = t + 1 / _SndRate
- _SndRaw sample1
- RawMusic(rwi) = sample1
- rwi = rwi + 1
- Print "Sound generated, saving to file generated.wav"
- _Delay .5
- SAVESOUND8S Left, Right, "generated.wav"
- _MemFree Left
- _MemFree Right
- Erase RawMusic
- Size = OFFSET_to_I64(Left.SIZE) 'convertion is used for WAV file header, becuse offset value can not be used directly
- Type head8
- ch = FreeFile
- 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
- s& = s& + 2
- start& = start& + 4
- 'write audio data to file
- 'erase memory
- _MemFree Recalc
- WAVeRAW$ = ""
- Close ch
- Offset_to_i64 = num
- _MEMFREE m
- OFFSET_to_I64 = num
- _MemFree m