I have downloaded the Port.dll (for Windows XP) that can be found here: http://www.b-kainka.de/download.htm
Barney did an excelent work making an include file for this dll. It can be found here: http://www.ionicwind.com/forums/index.php/topic,1986.0.html
Many of the functions I tried work fine, but I can't make the one I wanted most work: It's the SOUNDIN() function that fills a buffer with the data colected by the sound card from the microphone input.
The problem seems to be that the SOUNDIN() requires a string that names the buffer, and Ebasic MEMORY is a non-string variable.
Here is a recorder/player that does not work. BE CAREFUL, because clicking the "record" buttom freezes the system. The "play" buttom works fine, but plays some unknown chunk of memory.
$USE "Port.lib"
DECLARE IMPORT, SOUNDIN(STRING sBuffer, INT iSize) ' sBuffer is a string variable!?!!
DECLARE IMPORT, SOUNDOUT(STRING sBuffer, INT iSize)
MEMORY Buffer 'This Buffer is a MEMORY space called Buffer
INT a
DIALOG d1
CONST BUTTON_1 = 1
CONST BUTTON_2 = 2
CREATEDIALOG d1,0,0,235,140,0x80C80080,0,"Recorder-Player",&d1_handler
CONTROL d1,@BUTTON,"record",32,33,70,20,0x50000000,BUTTON_1
CONTROL d1,@BUTTON,"play",129,33,70,20,0x50000000,BUTTON_2
ALLOCMEM Buffer,1,1000
SHOWDIALOG d1
WAITUNTIL d1 = 0
FREEMEM Buffer
END
SUB d1_handler
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW d1
CASE @IDCLOSEWINDOW
CLOSEDIALOG d1,@IDOK
CASE @IDCONTROL
SELECT @CONTROLID
CASE BUTTON_1
IF @NOTIFYCODE = 0
SOUNDIN("Buffer",5000) ' This "Buffer" is not the MEMORY space
' but removing the quotes ("") gives a 'no appropiate conversion exist' compiling error!
' the program freezes here if the record button is clicked
ENDIF
CASE BUTTON_2
IF @NOTIFYCODE = 0
SOUNDOUT("Buffer",5000) 'Some sound is played and the program doesn't freeze
ENDIF
ENDSELECT
ENDSELECT
RETURN
ENDSUB
Could anyone point a way of linking a MEMORY buffer with the SOUNDIN() funtion?
You defined buffer as a MEMORY type variable.
Soundin/out expects a variable of type STRING.
I would try defining buffer as
def buffer[1000] as istring
and see if that works.
Also, I'm assuming the second parameter passed to soundin/out (size) is the size of the string being passed.
If I'm correct then that number should be the same as the size of "buffer".
def buffer[1000] as istring
soundin(buffer,Len(buffer))
I'm just guessing here.
Larry
When digitizing a sound, you have to take samples of this sound at regular intervals. The sampling frequency should be at least twice the frequency of the sound you are going to digitize. You have not set any sampling rate in your code. But from Barney's include file I see that it should be possible to do so before calling sound in. I guess that the Eektor magazine has printed an article describing how to use the functions of Port.dll. So the first thing to do is obviously to study that article.
Maybe you also can find some tips here: http://www.acarsd.org/libacarsd.html . They are using the sound cards for decoding digital transmissions from passing airplanes. Their free programming library has very good documentation on using the sound input.
By searching the internet I found a link to an Elektor book describing how to use the routines found in Port.dll: http://www.hjberndt.de/book/pcsen1.html
@Larry: Thank you so much! Such a simple solution, yet I would never figure it out by myself. It works! I just recorded my voice using the code above with the changes you propose, using a istring[100000].
@Egil: Thank you for the acard link. I'll study it. I guess since I did not set a sampling rate, the system assumed a default, because it worked. I am aware of that book, but it would cost me over 100 US dollars to buy it from here (Brazil), too much for my hobby. Everytime I try to access an Elektor page, in any language, it redirects me to the portuguese Elektor page, in which I could not find any info on port.dll.
This page http://www.mikrocontroller.net/topic/4080 has a link (search for a "port.zip" link) to a zip file that has an old port.dll and the dll documentation. The documentation is in german, but (unless you are german) 'google translate' gives a pretty understandable translation.
Im quite happy to finally have a direct access to the soundcard hardware. I have been trying for over a month.
Glad you made it Andre. Looking forward to see your code. When I become a little more confident with windows programming I will try to do my own DSP routines for weak signal reception. But I still have a long way to go.
Good luck with your project!
PS
By the way, I am Norwegian, but for several years I used to work in Brazil, based in Porto Alegre, servicing and calibrating dataloggiers and control equipment onboard norwegian LPG tankers. Nice place!
What a coincidence, I was born in Porto Alegre and my current personal project is a datalogger! Nice city indeed, it's a pity I don't live there anymore. I'm in Rio now.
The preliminary code for the datalogger is in the "Roundtable" forum. Hope to add direct souncard sampling routines soon.
Good luck with your project. Keep us informed.