So, jetzt funktioniert es.
Alle Daten werden korrekt übertragen als Wav zum MPF1, bzw werden auch als wav abgespeichert.
Code: Alles auswählen
SetCurrentDirectory(GetPathPart(ProgramFilename()))
Global *tonspeicher.l,*datspeicher.l,tonlaenge.l,datlaenge.l,bytespersec.l
Global uni_w.u,lobyte.c,hibyte.c,secs.f
Global samplerate.l,bitrate.l,channels.l,volume.l,n_samples.l,n_dat.l,zaehler.l
Declare w_impulse(n_impulse.l,khz.l)
Declare bit_0()
Declare bit_1()
Declare w_byte(byte_bits.c)
Declare a_sync()
Declare m_sync()
Declare e_sync()
Declare vn_spann()
Procedure w_impulse(n_impulse.l,khz.l)
Protected n_size.l,i.l,h.l,l.l
khz * 1000
n_size=samplerate/(2*khz)
For i=1 To n_impulse
; hipegel
For h=1 To n_size
PokeW(*tonspeicher+n_samples,volume)
n_samples + 2
Next
; lopegel
For h=1 To n_size
PokeW(*tonspeicher+n_samples,-volume)
n_samples + 2
Next
Next
EndProcedure
Procedure bit_0()
w_impulse(8,2) ; 8 * 2 khz
w_impulse(2,1) ; 2 * 1 khz
EndProcedure
Procedure bit_1()
w_impulse(4,2) ; 4 * 2 khz
w_impulse(4,1) ; 4 * 1 khz
EndProcedure
Procedure w_byte(byte_bits.c)
Protected i.l
bit_0()
For i=0 To 7
If (byte_bits & (1<<i))
bit_1()
Else
bit_0()
EndIf
Next i
bit_1()
EndProcedure
Procedure a_sync()
w_impulse(4000,1) ; 4 sec 1khz
EndProcedure
Procedure m_sync()
w_impulse(4000,2) ; 2 sec 2khz
EndProcedure
Procedure e_sync()
w_impulse(4000,2) ; 2 sec 2khz
EndProcedure
Procedure vn_spann()
Protected i.l
For i=1 To 100
PokeW(*tonspeicher+n_samples,0)
n_samples + 2
Next
EndProcedure
InitSprite()
InitSound()
OpenWindow(0,0,0,800,600,"sound-test",#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0),10,10,350,300,0,0,0)
text1=TextGadget(#PB_Any, 10,380,200,20, "Taste-Q")
ClearScreen(RGB(128,128,128))
OpenFile(0,"dice2.bin")
datlaenge=Lof(0)
*datspeicher= AllocateMemory(datlaenge)
ReadData(0, *datspeicher, datlaenge)
CloseFile(0)
samplerate = 8000
bitrate = 16
channels = 1
volume=32000
bytespersec = channels*bitrate/8*samplerate
secs=(datlaenge*8+7*8)*0.006+10
tonlaenge=bytesperSec*secs+44
*tonspeicher= AllocateMemory(tonlaenge)
Repeat
Event.l = WaitWindowEvent(2)
If GetAsyncKeyState_(#VK_Q)
SetGadgetText(text1,"erstelle")
PokeS(*tonspeicher,"RIFF")
PokeL(*tonspeicher+4,36+bytespersec*secs)
PokeS(*tonspeicher+8,"WAVE")
PokeS(*tonspeicher+12,"fmt ")
PokeL(*tonspeicher+16,16)
PokeW(*tonspeicher+20,1)
PokeW(*tonspeicher+22,channels)
PokeL(*tonspeicher+24,samplerate )
PokeL(*tonspeicher+28,bytespersec)
PokeW(*tonspeicher+32,bitrate/8*channels)
PokeW(*tonspeicher+34,bitrate)
PokeS(*tonspeicher+36,"data")
PokeL(*tonspeicher+40,bytespersec*secs)
n_samples=44
vn_spann()
a_sync()
uni_w=1 ;filenummer 2byte
lobyte=uni_w & $00ff
hibyte=uni_w & $ff00/256
w_byte(lobyte)
w_byte(hibyte)
uni_w=$1800 ;startadresse $1800 2byte
lobyte=uni_w & $00ff
hibyte=uni_w & $ff00/256
w_byte(lobyte)
w_byte(hibyte)
uni_w=$1800+datlaenge-1 ;endadresse $1800+datlaenge 2byte
lobyte=uni_w & $00ff
hibyte=uni_w & $ff00/256
w_byte(lobyte)
w_byte(hibyte)
uni_w=0
For zaehler=0 To datlaenge-1 ;programmdaten zur checksumme
uni_w= uni_w+PeekB(*datspeicher+zaehler)
Next
lobyte=uni_w & $00ff ;checksumme 1byte
w_byte(lobyte)
m_sync()
For zaehler=0 To datlaenge-1 ;programmdaten
lobyte = PeekB(*datspeicher+zaehler)
w_byte(lobyte)
Next
e_sync()
CreateFile(0, "wavtest.wav")
WriteData(0,*tonspeicher,tonlaenge)
CloseFile(0)
SetGadgetText(text1,"Datei und Speicher")
EndIf
If GetAsyncKeyState_(#VK_S)
CatchSound(0, *tonspeicher)
PlaySound(0)
EndIf
Until Event = #PB_Event_CloseWindow
End