Post by bluatigro on Mar 30, 2020 3:12:06 GMT -5
error :
i can not find the wav file
i want to write a composer program
first i need to create 1 note
the code gives a short sound but i do not think that is myne note A
i can not find the wav file
i want to write a composer program
first i need to create 1 note
the code gives a short sound but i do not think that is myne note A
'' bluatigro 30 mrt 2020
'' wav creator try
''create wav struct
struct wav _
, chunkid as long _ ''RIFF
, chunksize as long _
, format as long _
, subchunk1id as long _
, subchunk1size as long _
, audioformat as short _ '' 1
, numchannels as short _ '' 1 = mono
, samplerate as long _ ''8000 41000
, byterate as long _
, blockalign as short _
, bitpersample as short _ ''8 16
, subchunk2id as long _
, subchunk2size as long
global numsamples ''1 sec
numsamples = 41000
global pi
pi = atn(1)*4
dim wavdata( numsamples )
wav.chunkid.struct = hexdec( "52494646" )''RIFF
wav.format.struct = hexdec( "57415645" )''WAVE
wav.subchunk1id.struct = hexdec( "666d7420" )''fmt
wav.subchunk1size.struct = 16
wav.audioformat.struct = 1
wav.numchannels.struct = 1 ''1 = mono 2 = stereo
wav.samplerate.struct = numsamples
wav.bitpersample.struct = 16
wav.blockalign.struct = wav.numchannels.struct _
* wav.bitpersample.struct / 8
wav.byterate.struct = numsamples _
* wav.numchannels.struct * wav.bitpersample.struct / 8
wav.subchunk2id = hexdec( "64617461" )''data
wav.subchunk2size = numsamples _
* wav.numchannels.struct * wav.bitpersample.struct / 8
wav.chunksize.struct = _
4 + ( 8 + wav.subchunk1size.struct ) _
+ ( 8 + wav.subchunk2size.struct )
for i = 0 to numsamples
'' note A
wavdata( i ) = int( sin( 440 * pi * 2 / wav.samplerate.struct ) _
* 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$( wav.chunkid.struct ) _ ''RIFF
+ long$( wav.chunksize.struct ) _
+ long$( wav.format.struct ) _
+ long$( wav.subchunk1id.struct ) _
+ long$( wav.subchunk1size.struct ) _
+ short$( wav.audioformat.struct ) _ '' 1
+ short$( wav.numchannels.struct ) _ '' 1 = mono
+ long$( wav.samplerate.struct ) _ ''8000 41000
+ long$( wav.byterate.struct ) _
+ short$( wav.blockalign.struct ) _
+ short$( wav.bitpersample.struct ) _ ''8 16
+ long$( wav.subchunk2id.struct ) _
+ long$( wav.subchunk2size.struct )
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