Page 1 of 2
How to record sounds from a mike ?
Posted: Tue Jun 10, 2003 4:17 pm
by Denis
Hi all,
It is a question sending on the french forum but without answer.
The problem is to record sounds from a mike and then to read this record. I have no really idea. Is there a way to catch sound with the sound card and then to encode ( or not) it to reduce size ?
Thanks for Help.
Denis
Posted: Tue Jun 10, 2003 5:05 pm
by Polo
a mic
I answer in french : Je ne sais pas

/I don't know
Posted: Tue Jun 10, 2003 5:05 pm
by Polo
But I would love to know, I'm interested in that !
Posted: Tue Jun 10, 2003 6:35 pm
by El_Choni
I found this in my HD, but I'm sure I didn't code it. It must be old, it still used InitGadget():
Code: Select all
Global buffer$
buffer$=Space(256)
Procedure MCI(command.s)
result=MciSendString_(command,@buffer$,256,0)
ProcedureReturn result
EndProcedure
;---------------------------------------------------------------------
clip.s="C:\Test.wav" ;file to save to disk
alignment=4
bits=16 ;16bit wave file
channels=2 ;1=mono 2=stero
samples=44100 ;44.1kHz sample rate
reclength=5 ;length of audio to record (this example records 5 seconds)
If OpenWindow(0,10,10,200,100,#PB_Window_SystemMenu,"Record Audio")=0:End:EndIf
If CreateGadgetList(WindowID())=0:End:EndIf
TextGadget(0,10,10,100,20,"")
MCI("open new type waveaudio alias recsound")
MCI("set recsound time format ms")
MCI("set recsound alignment "+Str(alignment)+" bitspersample "+Str(bits)+" samplespersec "+Str(samples)+" channels "+Str(channels)+" bytespersec "+Str(samples*alignment) )
MCI("record recsound")
While elapsed < reclength*1000
MCI("status recsound position")
elapsed=Val(buffer$)
SetGadgetText(0,"Recorded: "+Str(elapsed/1000)+" secs.")
Delay(20)
Wend
MCI("save recsound "+clip)
MCI("close recsound")
End
Record Sound?
Posted: Tue Jun 10, 2003 6:38 pm
by ppjm99
If you mean manually you can use windows accessories sound recorder to create a .wav file and then get a .mp3 encoder to compress it just as you would music.
If you mean programatically then you should investigate these api calls:
Declare Function waveInOpen Lib "winmm.dll" (lphWaveIn As Long, ByVal uDeviceID As Long, lpFormat As WAVEFORMAT, ByVal dwCallback As Long, ByVal dwInstance As Long, ByVal dwFlags As Long) As Long
Declare Function waveInPrepareHeader Lib "winmm.dll" (ByVal hWaveIn As Long, lpWaveInHdr As WAVEHDR, ByVal uSize As Long) As Long
Declare Function waveInReset Lib "winmm.dll" (ByVal hWaveIn As Long) As Long
Declare Function waveInStart Lib "winmm.dll" (ByVal hWaveIn As Long) As Long
Declare Function waveInStop Lib "winmm.dll" (ByVal hWaveIn As Long) As Long
Declare Function waveInUnprepareHeader Lib "winmm.dll" (ByVal hWaveIn As Long, lpWaveInHdr As WAVEHDR, ByVal uSize As Long) As Long
Declare Function waveInClose Lib "winmm.dll" (ByVal hWaveIn As Long) As Long
Declare Function waveInGetDevCaps Lib "winmm.dll" Alias "waveInGetDevCapsA" (ByVal uDeviceID As Long, lpCaps As WAVEINCAPS, ByVal uSize As Long) As Long
Declare Function waveInGetNumDevs Lib "winmm.dll" () As Long
Declare Function waveInGetErrorText Lib "winmm.dll" Alias "waveInGetErrorTextA" (ByVal err As Long, ByVal lpText As String, ByVal uSize As Long) As Long
Declare Function waveInAddBuffer Lib "winmm.dll" (ByVal hWaveIn As Long, lpWaveInHdr As WAVEHDR, ByVal uSize As Long) As Long
I did a google on 'sound record vb' to find this, looks like it is fairly involved, definitely not a ten minute job.
Record Sound
Posted: Tue Jun 10, 2003 6:40 pm
by ppjm99
I think el choni's approach is definitely easier
Posted: Tue Jun 10, 2003 8:17 pm
by Denis
@El_Choni
Thanks for this code. I will investigate. Just a question. I'm too young in PB (less one year) and i don't know the command InitGadget(). What about it ?
Hope we'll see you back on the french forum.
@ppjm99
Thanks too, may be this code will help some of us.
@Polo
Are you French-speaking ?
Denis
Posted: Tue Jun 10, 2003 9:16 pm
by El_Choni
i don't know the command InitGadget(). What about it ?
In old PB versions, it had to be used in order to use gadgets, fortunately it's not needed any more and it doesn't exist any more, so forget all about it (I don't want to be accused of confusing other users

)
Posted: Wed Jun 11, 2003 12:23 pm
by Polo
Denis => Comment tu as deviné ?
Re: How to record sounds from a mike ?
Posted: Wed Jun 11, 2003 12:56 pm
by PB
> The problem is to record sounds from a mike and then to read this
> record. I have no really idea.
Code: Select all
Procedure RecordWav(filename$,ms)
buffer$=Space(128) : DeleteFile_(filename$)
mciSendString_("open new type waveaudio alias capture",buffer$,128,0)
mciSendString_("set capture samplesperbuffer 8000 bytesperbuffer 8000",0,0,0)
mciSendString_("record capture",buffer$,128,0)
Sleep_(ms) ; Wait for specified capture time to end.
mciSendString_("save capture "+filename$,buffer$,128,0)
EndProcedure
;
MessageRequester("Info","Click OK to capture audio to c:\test.wav for 2 secs",0)
RecordWav("c:\test.wav",2000)
MessageRequester("Info","Done!",0)
Posted: Thu Jun 12, 2003 8:18 pm
by Denis
Thanks a lot PB,
i will translate this code in french and sent it on french forum.
Denis

LOUDER!!!
Posted: Sat Jun 14, 2003 4:54 pm
by starax
I record sounds from Mike by beating the crap out of him while holding my microphone just above his head. But be careful not to get blood in your mic as this tends to dampen the sound quality considerably.
I don't see how this has anything to do with Purebasic, try S&M next door.
Posted: Fri Aug 06, 2004 12:52 pm
by newbie
in this code :
Code: Select all
Procedure RecordWav(filename$,ms)
buffer$=Space(128) : DeleteFile_(filename$)
mciSendString_("open new type waveaudio alias capture",buffer$,128,0)
mciSendString_("set capture samplesperbuffer 8000 bytesperbuffer 8000",0,0,0)
mciSendString_("record capture",buffer$,128,0)
Sleep_(ms) ; Wait for specified capture time to end.
mciSendString_("save capture "+filename$,buffer$,128,0)
EndProcedure
;
MessageRequester("Info","Click OK to capture audio to c:\test.wav for 2 secs",0)
RecordWav("c:\test.wav",2000)
MessageRequester("Info","Done!",0)
is it possible ti send the captured sound over a network to make a basic VoIP software ?
In this case should I send the "buffer$" parameter ?
How at the other end the buffer can be read ?
I read about a "play" command on MSDN, but I don't see how to read a variable.
Thanks in advance.
(I hope that to bump this old topic is ok, I didn't find any other talking about this subject on the forum).
Posted: Fri Aug 06, 2004 10:34 pm
by eriksradio
Don't forget to close when finished or there may be a big memory leak.
Each individual may be closed selectively.
mciSendString_("close capture", 0, 0, 0)
mciSendString_("close all",0,0,0) does the lot.
Posted: Fri Aug 06, 2004 11:19 pm
by newbie
ok thx for the tip
Still searching how to put in a buffer the sound

(to use then in network commands)