Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Herfried K. Wagner - HELP!

178 views
Skip to first unread message

jer

unread,
Dec 19, 2006, 3:53:50 PM12/19/06
to
I've noticed you've helped a lot of people that were trying to do sound
recording through VB.net. I'm searched all over the internet, and I'm
still having problems write sound to a wav file.

My code originate from a VB 6 application, and I'm trying to use vb
2005. I was having a lot of issues until I saw your post that cleaned
up a lot of the structures and DLL calls in this:

http://groups.google.com/group/microsoft.public.dotnet.languages.vb/browse_thread/thread/d3ab8ddcc2778c6d/e289cb58cd5469a4?lnk=st&q=MMResult+vb&rnum=8&hl=en#e289cb58cd5469a4

... So my quesiton... Do you have a similar post or sample application
for vb2005 that will write a wave file from the sound card?


Thank you very much,

Jerry

Herfried K. Wagner [MVP]

unread,
Dec 19, 2006, 4:20:47 PM12/19/06
to
"jer" <geral...@gmail.com> schrieb:

> I've noticed you've helped a lot of people that were trying to do sound
> recording through VB.net. I'm searched all over the internet, and I'm
> still having problems write sound to a wav file.

Please do not address posts to a specific person here. Each thread/question
can/should by answered by all readers.

> ... So my quesiton... Do you have a similar post or sample application
> for vb2005 that will write a wave file from the sound card?

That's not that complicated using good old MCI:

\\\
Private Declare Auto Function mciSendString Lib "winmm.dll" ( _
ByVal lpszCommand As String, _
ByVal lpszReturnString As String, _
ByVal cchReturn As Int32, _
ByVal hwndCallback As IntPtr _
) As MCIERROR

Public Enum MCIERROR
MCIERR_BASE = 256

MCIERR_INVALID_DEVICE_ID = MCIERR_BASE + 1
MCIERR_UNRECOGNIZED_KEYWORD = MCIERR_BASE + 3
MCIERR_UNRECOGNIZED_COMMAND = MCIERR_BASE + 5
MCIERR_HARDWARE = MCIERR_BASE + 6
MCIERR_INVALID_DEVICE_NAME = MCIERR_BASE + 7
MCIERR_OUT_OF_MEMORY = MCIERR_BASE + 8
MCIERR_DEVICE_OPEN = MCIERR_BASE + 9
MCIERR_CANNOT_LOAD_DRIVER = MCIERR_BASE + 10
MCIERR_MISSING_COMMAND_STRING = MCIERR_BASE + 11
MCIERR_PARAM_OVERFLOW = MCIERR_BASE + 12
MCIERR_MISSING_STRING_ARGUMENT = MCIERR_BASE + 13
MCIERR_BAD_INTEGER = MCIERR_BASE + 14
MCIERR_PARSER_INTERNAL = MCIERR_BASE + 15
MCIERR_DRIVER_INTERNAL = MCIERR_BASE + 16
MCIERR_MISSING_PARAMETER = MCIERR_BASE + 17
MCIERR_UNSUPPORTED_FUNCTION = MCIERR_BASE + 18
MCIERR_FILE_NOT_FOUND = MCIERR_BASE + 19
MCIERR_DEVICE_NOT_READY = MCIERR_BASE + 20
MCIERR_INTERNAL = MCIERR_BASE + 21
MCIERR_DRIVER = MCIERR_BASE + 22
MCIERR_CANNOT_USE_ALL = MCIERR_BASE + 23
MCIERR_MULTIPLE = MCIERR_BASE + 24
MCIERR_EXTENSION_NOT_FOUND = MCIERR_BASE + 25
MCIERR_OUTOFRANGE = MCIERR_BASE + 26
MCIERR_FLAGS_NOT_COMPATIBLE = MCIERR_BASE + 28
MCIERR_FILE_NOT_SAVED = MCIERR_BASE + 30
MCIERR_DEVICE_TYPE_REQUIRED = MCIERR_BASE + 31
MCIERR_DEVICE_LOCKED = MCIERR_BASE + 32
MCIERR_DUPLICATE_ALIAS = MCIERR_BASE + 33
MCIERR_BAD_CONSTANT = MCIERR_BASE + 34
MCIERR_MUST_USE_SHAREABLE = MCIERR_BASE + 35
MCIERR_MISSING_DEVICE_NAME = MCIERR_BASE + 36
MCIERR_BAD_TIME_FORMAT = MCIERR_BASE + 37
MCIERR_NO_CLOSING_QUOTE = MCIERR_BASE + 38
MCIERR_DUPLICATE_FLAGS = MCIERR_BASE + 39
MCIERR_INVALID_FILE = MCIERR_BASE + 40
MCIERR_NULL_PARAMETER_BLOCK = MCIERR_BASE + 41
MCIERR_UNNAMED_RESOURCE = MCIERR_BASE + 42
MCIERR_NEW_REQUIRES_ALIAS = MCIERR_BASE + 43
MCIERR_NOTIFY_ON_AUTO_OPEN = MCIERR_BASE + 44
MCIERR_NO_ELEMENT_ALLOWED = MCIERR_BASE + 45
MCIERR_NONAPPLICABLE_FUNCTION = MCIERR_BASE + 46
MCIERR_ILLEGAL_FOR_AUTO_OPEN = MCIERR_BASE + 47
MCIERR_FILENAME_REQUIRED = MCIERR_BASE + 48
MCIERR_EXTRA_CHARACTERS = MCIERR_BASE + 49
MCIERR_DEVICE_NOT_INSTALLED = MCIERR_BASE + 50
MCIERR_GET_CD = MCIERR_BASE + 51
MCIERR_SET_CD = MCIERR_BASE + 52
MCIERR_SET_DRIVE = MCIERR_BASE + 53
MCIERR_DEVICE_LENGTH = MCIERR_BASE + 54
MCIERR_DEVICE_ORD_LENGTH = MCIERR_BASE + 55
MCIERR_NO_INTEGER = MCIERR_BASE + 56

MCIERR_WAVE_OUTPUTSINUSE = MCIERR_BASE + 64
MCIERR_WAVE_SETOUTPUTINUSE = MCIERR_BASE + 65
MCIERR_WAVE_INPUTSINUSE = MCIERR_BASE + 66
MCIERR_WAVE_SETINPUTINUSE = MCIERR_BASE + 67
MCIERR_WAVE_OUTPUTUNSPECIFIED = MCIERR_BASE + 68
MCIERR_WAVE_INPUTUNSPECIFIED = MCIERR_BASE + 69
MCIERR_WAVE_OUTPUTSUNSUITABLE = MCIERR_BASE + 70
MCIERR_WAVE_SETOUTPUTUNSUITABLE = MCIERR_BASE + 71
MCIERR_WAVE_INPUTSUNSUITABLE = MCIERR_BASE + 72
MCIERR_WAVE_SETINPUTUNSUITABLE = MCIERR_BASE + 73

MCIERR_SEQ_DIV_INCOMPATIBLE = MCIERR_BASE + 80
MCIERR_SEQ_PORT_INUSE = MCIERR_BASE + 81
MCIERR_SEQ_PORT_NONEXISTENT = MCIERR_BASE + 82
MCIERR_SEQ_PORT_MAPNODEVICE = MCIERR_BASE + 83
MCIERR_SEQ_PORT_MISCERROR = MCIERR_BASE + 84
MCIERR_SEQ_TIMER = MCIERR_BASE + 85
MCIERR_SEQ_PORTUNSPECIFIED = MCIERR_BASE + 86
MCIERR_SEQ_NOMIDIPRESENT = MCIERR_BASE + 87

MCIERR_NO_WINDOW = MCIERR_BASE + 90
MCIERR_CREATEWINDOW = MCIERR_BASE + 91
MCIERR_FILE_READ = MCIERR_BASE + 92
MCIERR_FILE_WRITE = MCIERR_BASE + 93

MCIERR_NO_IDENTITY = MCIERR_BASE + 94

' all custom device driver errors must be >= than this value
MCIERR_CUSTOM_DRIVER_BASE = MCIERR_BASE + 256
End Enum

Private Function mciSimpleSendString(ByVal Command As String) As MCIERROR
Return mciSendString(Command, Nothing, 0, IntPtr.Zero)
End Function

Private Sub StartRecording()
mciSimpleSendString("close all")
mciSimpleSendString("open new type waveaudio alias capture")

' Set capturing options here.
'mciSimpleSendString("set capture bitspersample 16")
'mciSimpleSendString("set capture samplespersec 44100")
'mciSimpleSendString("set capture channels 2")
mciSimpleSendString("record capture")
End Sub

Private Sub StopRecording()
mciSimpleSendString("save capture C:\sample.wav")
mciSimpleSendString("close capture")
End Sub
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

jer

unread,
Dec 19, 2006, 4:54:14 PM12/19/06
to
My apologies... I'll remove your name from the subject.
So, you suggest the MCI recording instead of using waveopen/in?

Maybe if I explain what I'm doing, you might have a better suggestion
for me.

Where I work, I can't get a good signal for a sports station I like to
listing on the radio. So, I tought of an application that I could
write in VB.Net that would record from a radio plugged into my PC at
home (server), and record 30 minute chunks. This app would then
convert the wav to an MP3 and list it on my web server. I could
navigate to my web server (if I wanted to), and click to have it
emailed to my google account for downloading to my work PC.

The radio station does not offer streaming audio yet, so I can't listen
over the radio. Also, with my new MP3 player, I'd have enough storage
to sync it every night, and listen to the AM sports station the next
day.

So, that's my idea of the project. I will try using the code you've
supplied first. Do you foresee any issues with the large data size of
the recording? Would you still recommend this method, or maybe use
DirectX?

Thank you very much, and I greatly appreciate your input.

Jerry

Herfried K. Wagner [MVP]

unread,
Dec 19, 2006, 5:38:51 PM12/19/06
to
"jer" <geral...@gmail.com> schrieb:

> So, you suggest the MCI recording instead of using waveopen/in?

As often, there are many different ways to archive a certain thing.

> Where I work, I can't get a good signal for a sports station I like to
> listing on the radio. So, I tought of an application that I could
> write in VB.Net that would record from a radio plugged into my PC at
> home (server), and record 30 minute chunks. This app would then
> convert the wav to an MP3 and list it on my web server. I could
> navigate to my web server (if I wanted to), and click to have it
> emailed to my google account for downloading to my work PC.
>
> The radio station does not offer streaming audio yet, so I can't listen
> over the radio. Also, with my new MP3 player, I'd have enough storage
> to sync it every night, and listen to the AM sports station the next
> day.
>
> So, that's my idea of the project. I will try using the code you've
> supplied first. Do you foresee any issues with the large data size of
> the recording?

I haven't tested it but setting up such a test should be pretty easy. I
assume the recorded data is buffered somewhere.

> Would you still recommend this method, or maybe use
> DirectX?

DirectX would work too, but I assume the posted solution is easier to
implement (I already posted a basic working sample).

Cor Ligthert [MVP]

unread,
Dec 20, 2006, 12:04:11 AM12/20/06
to
Jer,

I am impressed by the answer from Herfried, I never get such nice samples
from him.

However in the SDK from DirectX are(were) in my idea samples that handles
what you want.

The pittfall is that the DirectX people are not able to write VB.Net
(probably to difficult for them) so the samples are only in C#.

Cor


"jer" <geral...@gmail.com> schreef in bericht
news:1166565254....@i12g2000cwa.googlegroups.com...

jer

unread,
Dec 20, 2006, 8:39:10 AM12/20/06
to
Cor,

I think that was my initial shortcoming. I have an app that does a
similar thing in vb6, and I wanted to upgrade it to VB2005 because I
really liked the 'run an application in a task tray' tools with vb
2005.

I've found the difference in structure declarations, api calls, and
parameter passing to be the root of my issues. As stated prior, I
found a post of a different way to declare the functions allowed me to
just list the devices on the machine, so I figured that it had to be my
issue of not being able to record.

So, in short, converting from one language, or version to another, got
me in this mess. heh... But, maybe this would be a great app to get my
feet wet with C#.

I'll let you know how it goes... Maybe even post the app, since I had
such a problem finding the info myself.

Jerry

Dennis

unread,
Dec 20, 2006, 7:54:00 PM12/20/06
to
Thanks for excellent Example. Where did you find the command string
components, i.e., a tutorial or documentation on command strings. I am
trying to convert MP3 files into wav files but have hit brick walls unless I
learn C.
--
Dennis in Houston


"Herfried K. Wagner [MVP]" wrote:

Herfried K. Wagner [MVP]

unread,
Dec 21, 2006, 7:28:32 AM12/21/06
to
"Dennis" <Den...@discussions.microsoft.com> schrieb:

> Where did you find the command string components, i.e.,
> a tutorial or documentation on command strings. I am
> trying to convert MP3 files into wav files but have hit brick
> walls unless I learn C.

Windows Multimedia -- Multimedia Command Strings
<URL:http://msdn.microsoft.com/library/en-us/multimed/htm/_win32_multimedia_command_strings.asp>

Dennis

unread,
Dec 21, 2006, 10:09:00 PM12/21/06
to
Thanks for site.
--
Dennis in Houston


"Herfried K. Wagner [MVP]" wrote:

0 new messages