How to record sounds from a mike ?

Everything else that doesn't fall into one of the other PB categories.
Denis
Enthusiast
Enthusiast
Posts: 778
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

How to record sounds from a mike ?

Post 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
A+
Denis
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

a mic :)

I answer in french : Je ne sais pas :D/I don't know
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

But I would love to know, I'm interested in that !
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Post 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
El_Choni
ppjm99
User
User
Posts: 23
Joined: Mon Jun 02, 2003 7:39 pm
Location: Canada

Record Sound?

Post 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.
ppjm99
User
User
Posts: 23
Joined: Mon Jun 02, 2003 7:39 pm
Location: Canada

Record Sound

Post by ppjm99 »

I think el choni's approach is definitely easier
Denis
Enthusiast
Enthusiast
Posts: 778
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Post 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. :wink:

@ppjm99
Thanks too, may be this code will help some of us.


@Polo
Are you French-speaking ?



Denis
A+
Denis
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Post 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 :D)
El_Choni
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

Denis => Comment tu as deviné ?
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: How to record sounds from a mike ?

Post 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)
Denis
Enthusiast
Enthusiast
Posts: 778
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Post by Denis »

Thanks a lot PB,

i will translate this code in french and sent it on french forum.


Denis :wink:
A+
Denis
starax
User
User
Posts: 26
Joined: Sun Jun 01, 2003 7:28 pm

LOUDER!!!

Post 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.
newbie
Enthusiast
Enthusiast
Posts: 296
Joined: Tue Jul 29, 2003 5:47 pm
Location: FRANCE
Contact:

Post 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).
- Registered PB user -

Using PB 4.00
eriksradio
User
User
Posts: 30
Joined: Tue Sep 09, 2003 11:44 pm
Location: Queensland, Australia

Post 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.
newbie
Enthusiast
Enthusiast
Posts: 296
Joined: Tue Jul 29, 2003 5:47 pm
Location: FRANCE
Contact:

Post by newbie »

ok thx for the tip ;)

Still searching how to put in a buffer the sound :?
(to use then in network commands)
- Registered PB user -

Using PB 4.00
Post Reply