@all
Ich habe nun versucht, die PORT.DLL mithilfe von Prototype zu deklarieren. Leider habe ich einen Speicherzugriff auf 0 und
kann den Fehler nicht finden. Vielleicht kann einer von euch mir hierzu weiterhelfen, da ich mit Prototype noch nicht
so richtig mit klarkomme. Ich hatte zuerst einfach nur das OPENCOM so wie in der PB-Hilfe unter Prototype ausprobiert und das funktionierte soweit auch.
Aber, das mit der Procedure, um es in einem Rutsch auszuführen, klappt irgendwie nicht.
[EDIT]
Problem konnte ich nun beheben. Somit läßt sich die Port.DLL einfach mit Prototype
einsetzen.
Die aktuelle Port.dll, welche auch unter Vista (32-Bit) funktionieren soll, kann man sich hier
herunterladen:
http://www.b-kainka.de/port.zip
Code: Alles auswählen
;Autor Falko Lünsmann
;Port.DLL von B.Kainka unter Vista32 angewandt.
;Bitte die neuste PORT.DLL laden
;
;--> http://www.b-kainka.de/port.zip
;
;Darum diese nun mithilfe von Prototyp, was zumindest bei mir funktioniert :).
;
;Um den Sound in eine WAV-Datei zu speichern zu können, habe ich mir
;von jemanden aus dem englischen Forum, der das ganze in Directsound programmiert hatte,
;einige Zeilen geborgt. Sorry
;;chris319
;5/25/2008
;
;-- Wav-Format Konstanten und Strukturen
#CHANNELS = 1 ; Wenn ihr hier 2 angebt, wird das eine lustige Mickimausstimme :)
#SAMPLE_RATE = 22050
#BIT_DEPTH = 16 ;8, 16 oder 24 Bits
#WAVE_FORMAT_PCM = $0001
#SECONDS = 6
Global my_wfe.WAVEFORMATEX ;THE FAMILIAR WAVEFORMATEX STRUCTURE
my_wfe\wFormatTag = #WAVE_FORMAT_PCM
my_wfe\nChannels = #CHANNELS ;dwPrimaryChannels;
my_wfe\nSamplesPerSec = #SAMPLE_RATE ;dwPrimaryFreq;
my_wfe\wBitsPerSample = #BIT_DEPTH ;dwPrimaryBitRate;
my_wfe\nBlockAlign = (my_wfe\wBitsPerSample / 8 * my_wfe\nChannels)
my_wfe\nAvgBytesPerSec = (my_wfe\nSamplesPerSec * my_wfe\nBlockAlign)
my_wfe\cbSize = 0
;-- Ende WAV-Format ...
;Definiere die Port.dll-funktionen als Prototype
;
;Portbefehle:
;
Prototype ProtoINPORT(PortAddr.w);Lesen eines Ports
Prototype.l ProtoOUTPORT(PortAddr.w,Daten.b)
;
;Serielle Schnittstelle
;
Prototype.l ProtoOPENCOM(string.s);bei Fehler = 0
Prototype.l ProtoCLOSECOM(); bei Fehler = 0
Prototype.w ProtoREADBYTE(); bei Fehler -1 sonst empfangene Bytes
Prototype ProtoSENDBYTE(Wert.w)
Prototype.w ProtoDSR();Lesen..Rückgabe: Zustand der Leitung (1/0)
Prototype.w ProtoCTS();Lesen..Rückgabe: Zustand der Leitung (1/0)
Prototype.w ProtoRI(); Lesen..Rückgabe: Zustand der Leitung (1/0)
Prototype.w ProtoDCD();Lesen..Rückgabe: Zustand der Leitung (1/0)
Prototype ProtoRTS(Wert.w);Wert(0..1)..Rückgabe: keine
Prototype ProtoTxD(Wert.w);Wert(0..1)..Rückgabe: keine
Prototype ProtoDTR(Wert.w);Wert(0..1)..Rückgabe: keine
Prototype.w ProtoTIMEOUT(Wert.w);Zeit in Millisekunden(1..65535)..Rückgabe: vorige Zeit in Millisekunden
;
;Soundcard
;
Prototype.l ProtoSOUNDIS() ;Rückgabe: (0 oder -1 bzw. True oder false)
Prototype ProtoSOUNDCAPIN();Rückgabe: nichts .. keine Parameter
Prototype.l ProtoSOUNDCAPOUT();Rückgabe: nichts .. keine Parameter
Prototype ProtoSOUNDIN(*Buffer,Size.l);Parameter: Speicher und Speichergrösse in Bytes
Prototype ProtoSOUNDOUT(*Buffer,Size.l) ;Speicher und Speichergrösse
Prototype.l ProtoSOUNDGETRATE();Rückgabe Abtastfrequenz in Samples/S, z.B. 11025
Prototype.l ProtoSOUNDSETRATE(Rate.l);Parameter: Abtastfrequenz in Samples/S..Rückgabe vorherige Abtastfreq...
Prototype.w ProtoSOUNDGETBYTES();Rückgabe: 1 oder 2. Ein Byte entspricht 8 Bits/Sample. Zwei Bytes entsprechen 16Bit/Sample
Prototype.w ProtoSOUNDSETBYTES(Bytes.l);Parameter 1 o. 2. Siehe SOUNDGETBYTES..Rückgabe: vorige Bytes/Sample
Prototype.b ProtoSOUNDBUSY(); Ist Soundkarte gerade beschäftigt? Rückgabe: 0 oder 1
;
;Joystick
;
Prototype.l ProtoJOYX(); Rückgabe: Position als Zahlenwert
Prototype.l ProtoJOYY(); Rückgabe: Position als Zahlenwert
Prototype.l ProtoJOYZ(); Rückgabe: Position als Zahlenwert
Prototype.l ProtoJOYR(); Rückgabe: Position als Zahlenwert
Prototype.l ProtoJOYU(); Rückgabe: Position als Zahlenwert
Prototype.l ProtoJOYV(); Rückgabe: Position als Zahlenwert
Prototype.l ProtoJOYBUTTON();Tastenabfrage
Prototype.l ProtoJOYSTICK(X.l,Y.l,Z.l,R.l,U.l,V.l,B.l);Gesamtabfrage des Joystick.. Parameter: 7Variablen
;
;Zeitroutinen
;
Prototype ProtoDELAYMS(ms.w);Verzögerung in Millisekunden
Prototype ProtoTIMINIT();Setzt den Millisekundenzeiger auf Null
Prototype.l ProtoTIMEREAD();Rückgabe Millisekunden als Zahlenwert
Prototype ProtoDELAYUS(us.w);Verzögerung in Mikrosekunden
Prototype ProtoTIMINITUS();Setzt den Mikrosekunden-Zeitzähler auf Null
Prototype.l ProtoTIMEREADUS();Rückgabe: Mikrosekunden als Zahlenwert
Prototype ProtoREALTIME(d.w);Höchste Prirorität setzen.. Parameter 0 oder 1
Procedure.l InitPort()
Shared DLL.l
DLL = OpenLibrary(#PB_Any,"PORT.DLL")
;Debug DLL
If DLL
Global INPORT.ProtoINPORT=GetFunction(DLL,"INPORT")
Global OUTPORT.ProtoOUTPORT=GetFunction(DLL,"OUTPORT")
Global OPENCOM.ProtoOPENCOM=GetFunction(DLL,"OPENCOM")
Global CLOSECOM.ProtoCLOSECOM=GetFunction(DLL,"CLOSECOM")
Global READBYTE.ProtoREADBYTE=GetFunction(DLL,"READBYTE")
Global SENDBYTE.ProtoSENDBYTE=GetFunction(DLL,"SENDBYTE")
Global DSR.ProtoDSR=GetFunction(DLL,"DSR")
Global CTS.ProtoCTS=GetFunction(DLL,"CTS")
Global RI.ProtoRI=GetFunction(DLL,"RI")
Global DCD.ProtoDCD=GetFunction(DLL,"DCD")
Global RTS.ProtoRTS=GetFunction(DLL,"RTS")
Global TxD.ProtoTxD=GetFunction(DLL,"TxD")
Global DTR.ProtoDTR=GetFunction(DLL,"DTR")
Global TIMEOUT.ProtoTIMEOUT=GetFunction(DLL,"TIMEOUT")
Global SOUNDIS.ProtoSOUNDIS=GetFunction(DLL,"SOUNDIS")
Global SOUNDCAPIN.ProtoSOUNDCAPIN=GetFunction(DLL,"SOUNDCAPIN")
Global SOUNDCAPOUT.ProtoSOUNDCAPOUT=GetFunction(DLL,"SOUNDCAPOUT")
Global SOUNDIN.ProtoSOUNDIN=GetFunction(DLL,"SOUNDIN")
Global SOUNDOUT.ProtoSOUNDOUT=GetFunction(DLL,"SOUNDOUT")
Global SOUNDGETRATE.ProtoSOUNDGETRATE=GetFunction(DLL,"SOUNDGETRATE")
Global SOUNDSETRATE.ProtoSOUNDSETRATE=GetFunction(DLL,"SOUNDSETRATE")
Global SOUNDSETBYTES.ProtoSOUNDSETBYTES=GetFunction(DLL,"SOUNDSETBYTES")
Global SOUNDGETBYTES.ProtoSOUNDGETBYTES=GetFunction(DLL,"SOUNDGETBYTES")
Global SOUNDBUSY.ProtoSOUNDBUSY=GetFunction(DLL,"SOUNDBUSY")
Global JOYX.ProtoJOYX=GetFunction(DLL,"JOYX")
Global JOYY.ProtoJOYY=GetFunction(DLL,"JOYY")
Global JOYZ.ProtoJOYZ=GetFunction(DLL,"JOYZ")
Global JOYR.ProtoJOYR=GetFunction(DLL,"JOYR")
Global JOYU.ProtoJOYU=GetFunction(DLL,"JOYU")
Global JOYV.ProtoJOYV=GetFunction(DLL,"JOYV")
Global JOYBUTTON.ProtoJOYBUTTON=GetFunction(DLL,"JOYBUTTON")
Global JOYSTICK.ProtoJOYSTICK=GetFunction(DLL,"JOYSTICK")
Global DELAYMS.ProtoDELAYMS=GetFunction(DLL,"DELAY")
Global TIMINIT.ProtoTIMINIT=GetFunction(DLL,"TIMINIT")
Global TIMEREAD.ProtoTIMEREAD=GetFunction(DLL,"TIMEREAD")
Global DELAYUS.ProtoDELAYUS=GetFunction(DLL,"DELAYUS")
Global TIMINITUS.ProtoTIMINITUS=GetFunction(DLL,"TIMINITUS")
Global TIMEREADUS.ProtoTIMEREADUS=GetFunction(DLL,"TIMEREADUS")
Global REALTIME.ProtoREALTIME=GetFunction(DLL,"ProtoREALTIME")
ProcedureReturn 1
Else
ProcedureReturn 0
EndIf
EndProcedure
ProcedureDLL PORTDLL_End()
Shared DLL.l
FreeLibrary_(DLL)
EndProcedure
If InitPort()
;If OPENCOM("COM2,19200,N,8,1");In Windows 95/98 funktioniert dieses auch
If OPENCOM("COM1: baud=19200 data=8 parity=N stop=1")
MessageRequester("Ausgabe","Herzlichen Glückwunsch, COM1 ist vorhanden")
CLOSECOM()
Else
MessageRequester("Ausgabe","Versuche einen anderen COMPort")
EndIf
Else
MessageRequester("Warnung","Die Port.DLL konnte nicht geöffnet werden!")
EndIf
;Debug SOUNDIS()
SOUNDSETRATE(#SAMPLE_RATE);Abtasfrequenz hier einstellen
SOUNDSETBYTES(2); 1 setzt 8Bit und 2 natürlich 16Bit Soundausgabe. Für 16Bit muss die SOUNDIN und SOUNDOUT durch 2 geteilt werden
If SOUNDIS()
Frame.l=#SAMPLE_RATE*#SECONDS ;*3 steht für 3Sekunden Aufnahme
*MySound=AllocateMemory(Frame)
MessageRequester("Aufnahme","Aufnahme beginnen?")
SOUNDIN(*MySound,Frame/2); Liest die Soundkartendaten als 8-Bit (BYTE) oder 16-Bit (WORD) darum hier /2 ein
CreateFile(0,"Test.wav")
;---WAV HEADER
subchunk1size.l = SizeOf(WAVEFORMATEX)
subchunk2size.l = Frame
chunksize = 4 + (8 + SizeOf(WAVEFORMATEX)) + (8 + subchunk2size)
my_WFE\cbSize = 0
chunksize = chunksize + my_WFE\cbSize
my_WFE\wFormatTag = #WAVE_FORMAT_PCM
;---WRITE WAV HEADER
WriteString(0, "RIFF") ; 4 bytes
WriteLong(0, chunksize) ; 4 bytes
WriteString(0, "WAVE") ; 4 bytes
WriteString(0, "fmt ") ; 4 bytes
WriteLong(0, subchunk1size) ; 4 bytes
WriteData(0, my_WFE, SizeOf(WAVEFORMATEX))
WriteString(0, "data", #PB_Ascii) ; 4 bytes
WriteLong(0, subchunk2size) ; 4 bytes
;---END OF FILE HEADER
;
;----Sounddaten nach dem WAV-Header
WriteData(0,*MySound,Frame)
;----Ende Sounddaten
CloseFile(0)
MessageRequester("Aufnahme","Aufnahme abspielen?")
SOUNDOUT(*MySound,Frame/2);da 16Bit-Words anstelle von 8Bits sind, muss durch /2 die Anzahl der Frames halbiert werden.
;Debug SOUNDGETRATE()
SOUNDCAPOUT();Messageboxausgabe der SOUNDausgangseinstellungen
SOUNDCAPIN() ;Messageboxausgabe der SOUNDausgangseinstellungen
EndIf
End
Damit man wie hier aus diesem Beispiel den aufgenommenen Sound auch
als lesbares Format schreiben kann, habe ich dazu im folgenden, gefundenen
Link einige Sourceschnipsel für den WAV-Header eingesetzt.
Hierzu Dank an chris319 (Englisches Purebasic Forum)
http://forums.purebasic.com/english/vie ... df#p245365
Eine genaue Beschreibung zum WAV-Header findet man hier:
https://ccrma.stanford.edu/courses/422/ ... aveFormat/
[/EDIT]
Gruß, Falko