fb:porticula NoPaste
Töne des MPF1 erzeugen
Uploader: | Volta |
Datum/Zeit: | 04.03.2010 12:36:58 |
'als Windows Console compilieren
#INCLUDE "windows.bi"
#INCLUDE ONCE "win/mmsystem.bi"
CONST samplerate = 8000
CONST volume = 32000
CONST channels = 1
CONST bitrate = 16
DIM SHARED AS INTEGER nsamples ,bytespersec,secs,datenlaenge,wavlaenge,zaehler
DIM SHARED AS SHORT wdaten
DIM SHARED AS BYTE PTR wavbuffer
SUB writeimpulse(nimpulse AS INTEGER,khz AS INTEGER)
khz*=1000 ' khz->hz
DIM AS INTEGER size=samplerate/(2*khz)
FOR i AS INTEGER=1 TO nimpulse
' high pegel
FOR h AS INTEGER=1 TO size
CAST(SHORT PTR,wavbuffer)[nsamples\2] = volume
nsamples+=2
NEXT
' low pegel
FOR l AS INTEGER=1 TO size
CAST(SHORT PTR,wavbuffer)[nsamples\2] = -volume
nsamples+=2
NEXT
NEXT
END SUB
'????????????????
SUB lobit
writeimpulse(8,2) ' 8 * 2 khz.
writeimpulse(2,1) ' 2 * 1 khz.
END SUB
SUB hibit
writeimpulse(4,2) ' 4 * 2 khz.
writeimpulse(4,1) ' 4 * 1 khz.
END SUB
SUB writebyte(bits AS UBYTE)
lobit ' start BIT
FOR i AS INTEGER = 0 TO 7
IF (bits AND 1) THEN hibit ELSE lobit
bits SHR = 1
NEXT
hibit ' STOP BIT
END Sub
SUB startsync
writeimpulse(4000,1) ' 4 sec. 1 khz.
END SUB
SUB midsync
writeimpulse(4000,2) ' 2 sec. 2 khz.
END SUB
SUB endsync
writeimpulse(4000,2) ' 2 sec. 2 khz.
END SUB
nochmal:
bytespersec=channels*bitrate/8*samplerate
secs=CINT(datenlaenge*8+7*8)*0.006+10
wavlaenge=bytespersec*secs+44
wavbuffer = ALLOCATE(wavlaenge)
CAST(UINTEGER PTR,wavbuffer)[0] = CVI("RIFF")
CAST(UINTEGER PTR,wavbuffer)[4\4] = 36+bytespersec*secs
CAST(UINTEGER PTR,wavbuffer)[8\4] = CVI("WAVE")
CAST(UINTEGER PTR,wavbuffer)[12\4] = CVI("fmt ")
CAST(UINTEGER PTR,wavbuffer)[16\4] = 16
CAST(SHORT PTR,wavbuffer)[20\2] = 1
CAST(SHORT PTR,wavbuffer)[22\2] = channels
CAST(UINTEGER PTR,wavbuffer)[24\4] = samplerate
CAST(UINTEGER PTR,wavbuffer)[28\4] = bytespersec
CAST(SHORT PTR,wavbuffer)[32\2] = bitrate\8*channels '<- SHORT!! und \ statt /
CAST(SHORT PTR,wavbuffer)[34\2] = bitrate
CAST(UINTEGER PTR,wavbuffer)[36\4] = CVI("data") 'data hier klein geschrieben!
CAST(UINTEGER PTR,wavbuffer)[40\4] = bytespersec*secs
nsamples = 44
startsync
' 2 BYTE filename lo hi
wdaten=1
writebyte(LOBYTE(wdaten))
writebyte(HIBYTE(wdaten))
' 2 BYTE start address lo hi
wdaten=&h1800
writebyte(LOBYTE(wdaten))
writebyte(HIBYTE(wdaten))
' 2 BYTE END address lo hi
wdaten=&h1800+datenlaenge-1
writebyte(LOBYTE(wdaten))
writebyte(HIBYTE(wdaten))
midsync
endsync
PRINT "0 = Ende ";"1 = Spielen ";"2 = neue Datei"
DO
INPUT zaehler
IF zaehler=1 THEN
PlaySound(wavbuffer, 0, SND_MEMORY OR SND_NODEFAULT)'testen
ENDIF
IF zaehler=2 THEN
DEALLOCATE(wavbuffer)
GOTO nochmal
ENDIF
IF zaehler=0 THEN
EXIT DO
ENDIF
LOOP
DEALLOCATE(wavbuffer)