Post by bluatigro on Mar 30, 2020 10:03:48 GMT
it makes a file
and plays it [ but i do not think it is the good one ]
i m tring to create a composer program
first : start whit one note
and plays it [ but i do not think it is the good one ]
i m tring to create a composer program
first : start whit one note
'' bluatigro 30 mrt 2020
'' wav creator try JB2 version
'' WAV header
global chunkid ''RIFF
global chunksize
global format
global subchunk1id
global subchunk1size
global audioformat '' 1
global numchannels '' 1 = mono
global samplerate ''8000 41000
global byterate
global blockalign
global bitpersample ''8 16
global subchunk2id
global subchunk2size
'' WAV data
global numsamples ''1 sec
numsamples = 41000
global pi
pi = atn(1)*4
dim wavdata( numsamples )
chunkid = hexdec( "52494646" )''RIFF
format = hexdec( "57415645" )''WAVE
subchunk1id = hexdec( "666d7420" )''fmt
subchunk1size = 16
audioformat = 1
numchannels = 1 ''1 = mono 2 = stereo
samplerate = 41000
bitpersample = 16
blockalign = numchannels * bitpersample / 8
byterate = numsamples * numchannels * bitpersample / 8
subchunk2id = hexdec( "64617461" )''data
subchunk2size = numsamples * numchannels * bitpersample / 8
chunksize = _
4 + ( 8 + subchunk1size ) _
+ ( 8 + subchunk2size )
for i = 0 to numsamples
'' note A 1 sec
wavdata( i ) = int( sin( 440 * pi * 2 / samplerate ) _
* 256 * 127 + 256 * 128 )
next i
open "note_440_1000.wav" for output as #uit
print #uit , wav$()
close #uit
input "[ wav ready : push return ]" ; in$
playwave "note_440_1000.wav" , sync
print "[ game over ]"
end
function wav$()
uit$ = long$( chunkid ) _ ''RIFF
+ long$( chunksize ) _
+ long$( format ) _
+ long$( subchunk1id ) _
+ long$( subchunk1size ) _
+ short$( audioformat ) _ '' 1
+ short$( numchannels ) _ '' 1 = mono
+ long$( samplerate ) _ ''8000 41000
+ long$( byterate ) _
+ short$( lockalign ) _
+ short$( bitpersample ) _ ''8 16
+ long$( subchunk2id ) _
+ long$( subchunk2size )
for i = 0 to numsamples
uit$ = uit$ + short$( wavdata(i) )
next i
wav$ = uit$
end function
function long$( x )
a = int( x / 256 ^ 3 ) and 255
b = int( x / 256 ^ 2 ) and 255
c = int( x / 256 ) and 255
d = int( x ) and 255
long$ = chr$( a ) + chr$( b ) + chr$( c ) + chr$( d )
end function
function short$( x )
c = int( x / 256 ) and 255
d = int( x ) and 255
short$ = chr$( c ) + chr$( d )
end function