'Dav SAV to WAV utility
FileName$ = "drummachine.sav"
y = 1
x = 0
'converse from 1D array to 2D array (uncompatible with QB64 logic, IS NOT POSSIBLE read Sounds() direct with GET for the same data order!)
IF x
= 32 THEN y
= y
+ 1: x
= 0 x = x + 1
Sounds(x, y) = s1(a)
PRINT "Loading DAV's SAV file..." PRINT "Buttons:"; buttons
'test
PRINT "Loaded sounds data table. Press key..."
PRINT "Loading WAV samples"
FOR LoadSamples
= 1 TO 16 Sample$ = "wavsamples\" + s$ + ".wav"
Samples(LoadSamples) = WAVtoRAW(Sample$)
PRINT "Loaded sample: "; s$
PRINT "Total track time:";
3 + 32 * (60 / 4 / tempo
);
"seconds (3 seconds added extra to end)."
'DATA samples order MUST be in the same order as in drummachine.bas on left (from top to bottom)
Samples:
DATA "crash","ride","hhopen","hhclosed","tomhigh","tommid","tomlow","snare","kick","cowbell","shaker","tamb","vibraslap","gong","triangleshort","clave"
'Insert samples to time track
DelayTime = 60 / 4 / tempo
FOR x
= 1 TO 32 ' column's TimeTrack(x, y) = DelayTime * x
PRINT "Time track done. Creating WAV content..."
lenght& = 44100 * TimeTrack(column, row) ' calculate lenght for track in BYTES: Time lenght * sample rate (44100 is used also in WAV header)
IF Sounds
(column
, row
) = 1 THEN FOR SearchVolume
= 1 TO row
READ vol
'INFO for DAV: This is the same as your SUB PLAYBEAT. status1: is for "1" values
IF Sounds
(column
, row
) = 2 THEN FOR SearchVolume
= 1 TO row
READ vol
'INFO for DAV: This is the same as your SUB PLAYBEAT. status1: is for "2" values
RAWCOPY Samples(row), newsound(), lenght&, vol ' copy sounds to correct places (in time) to array (if on this places is sound, is content
END IF ' mixed in SUB RAWCOPY, RAWCOPY in this program is updated!)
RealLenght newsound(), DelayTime * 32 + 3 ' (32 samples + 3 seconds lenght extra)
PRINT "Done. Saving file drummachine.wav... (16 bit stereo, 44100)" SAVESOUND16S newsound(), "drummachine.wav"
PRINT "Operation comleted. SAV file is now saved as WAV music file."
'DAV, here you can reset VOLUME values (if sound in WAV for sample is too loud, or too silent)
'values are rewrited from original DAV's drummachine.bas program
status1: '1 in sav table
DATA 6,5,5,1,9,9,9,1,1,.3,.6,1,.1,.1,.3,.6 status2: '2 in sav table
DATA .2,.2,.15,.2,.1,.1,.1,.1,.1,.2,.1,.1,.05,.03,.3,.02
FUNCTION WAVtoRAW
(file$
) ' Function load WAV file (this just 16bit, stereo format) and load it to array as RAW. subchunksize
AS LONG ' 4 bytes (lo / hi), $00000010 for PCM audio format
AS STRING * 2 ' 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
block = H.Block
RATE = H.rate
chan = H.channels
bits = H.Bits
SEEK #ch
, Find_data_area
(file$
)
OTP
(OTP_Size
).Offset_Start
= UBOUND(outputsound
) + 1
lef = lefi / 65535
righ = righi / 65535
IF RATE
> 44100 THEN frekvence
= RATE
ELSE frekvence
= 44100
FOR plll
= 1 TO frekvence
/ RATE
OutputSound(oss + plll).Left = lef
OutputSound(oss + plll).Right = righ
OTP
(OTP_Size
).Offset_End
= UBOUND(outputsound
) WAVtoRAW = OTP_Size
Find_data_area
= INSTR(1, D$
, "data") + 8
SoundLenghtInBytes = OTP(handle).Offset_End - OTP(handle).Offset_Start
OTPS = OTP(handle).Offset_Start
FOR rc
= position
TO position
+ SoundLenghtInBytes
IF arr
(rc
).Left
THEN OutLeft
= (arr
(rc
).Left
+ (OutputSound
(OTPS
).Left
) * Volume
) / 1 ELSE OutLeft
= OutputSound
(OTPS
).Left
* Volume
IF arr
(rc
).Right
THEN OutRight
= (arr
(rc
).Right
+ (OutputSound
(OTPS
).Right
) * Volume
) / 1 ELSE OutRight
= OutputSound
(OTPS
).Right
* Volume
IF OutLeft
> .75 THEN OutLeft
= .9 IF OutLeft
< -.75 THEN OutLeft
= -.9
IF OutRight
> .75 THEN OutRight
= .9 IF OutRight
< -.75 THEN OutRight
= -.9
arr(rc).Left = OutLeft
arr(rc).Right = OutRight
OTPS = OTPS + 1
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
H16.chunk = "RIFF"
H16.size
= 44 + UBOUND(arr
) * 4 'two channels, it create 16 bit, stereo wav file, one sample use 2 bytes to one channel
H16.fomat = "WAVE"
H16.sub1 = "fmt "
H16.subchunksize = 16
H16.format = 1
H16.channels = 2
H16.rate = 44100
H16.ByteRate = 44100 * 2 * 16 / 8
H16.Block = 4
H16.Bits = 16
H16.subchunk2 = "data"
LeftChannel = arr(audiodata).Left * 32768
RightChannel = arr(audiodata).Right * 32768