Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Recording in VB

Posted on 1998-11-17
8
Medium Priority
?
195 Views
Last Modified: 2010-05-03
Please guide me to record a wave file using the low-level (not MCI) Win32 API calls. I plan to use it to produce an oscilloscope
0
Comment
Question by:simchiang
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 

Author Comment

by:simchiang
ID: 1445200
Adjusted points to 150
0
 
LVL 2

Expert Comment

by:trillo
ID: 1445201
I'm currently developing an app that records sound using the low level Waveaudio functions, and it's not very easy....hmmm.... actually I'm using VC++. The problem is that a lot of those functions recieve adresses as parameters. Another problem is that you have to send empty buffers to the soundcard to fill them in with wave data. Thereafter you must analize those buffers, and for this purpose I'm using pointers..... I know a lot of VB but I don't know if it woul be easy (or even possible) to translate the code form C++ to VB. (because as you know, you don't have pointers in VB, and you can't handle adresses as easily)

Anyway, I can help you with some VC++ code (if you know C++ you can translate it) or otherwise I can try to tell you how would you do it in VB.
Please place a comment here telling me what you think, and how could I help you..

trillo
0
 

Author Comment

by:simchiang
ID: 1445202
trillo
I'm hopeless in C++ or even VC++. Please help in what ever way. I need to know the steps to set up the wave headers and start recording into buffers. I know how to play a wave file using low-level API though.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 2

Expert Comment

by:trillo
ID: 1445203
I'll be soon back with an answer... be a little bit patient please!

Trillo
0
 
LVL 2

Accepted Solution

by:
trillo earned 600 total points
ID: 1445204

>>I know how to play a wave file using low-level API though.
In this case, I will asume that you know how to declare the databuffers, if not, tell me. (I've not tried in VB but I supose you must use an array of bytes)

Note on my answer: The API declarations and structures I place here were token form the VB 4.0 API text wiewer, and they'll differ a little bit form my C++ program because I'm using VC++ 5.0 and it has some new API's and structures.

1.-First of all you have to declare a wave format structure

Type WAVEFORMAT
    wFormatTag As Integer     '  format type
    nChannels As Integer      '  number of channels (i.e. mono, stereo, etc.)
    nSamplesPerSec As Long    '  sample rate
    nAvgBytesPerSec As Long   '  for buffer estimation
    nBlockAlign As Integer    '  block size of data
End Type

VERSION NOTE: I used another structure: WAVEFORMATEX (I didn't find the declaration in VB 4.0). In the followint lines, I'll asume that you have the API text viewer so I won't place the function and structure declarations explicitly.

2.-Next, you have to call the "waveInOpen" function with the WAVE_FORMAT_QUERY flag (last param), to ensure the soundcard supports the format. The return value must be different to the MMSYSERR_NOERROR constant. (The Wavein device won't be opened yet)

3.-Next, you have to call the "waveInOpen" function again but this time without the WAVE_FORMAT_QUERY flag, and you must pass the WAVEFORMAT structure, now, the device will be opend for recording.

4.-Next, you have to declare some (2 or 3 or more maybe) WAVEHDR structures to specify the amount of data that can be filled in each buffer.
Type WAVEHDR
    lpData As Long                 '  pointer to locked data buffer
    dwBufferLength As Long         '  length of data buffer
    dwBytesRecorded As Long        '  used for input only
    dwUser As Long                 '  for client's use
    dwFlags As Long                '  assorted flags (see defines)
    dwLoops As Long                '  loop control counter
    wavehdr_tag As Long            '  reserved for driver
    reserved As Long               '  reserved for driver
End Type

For example:

Dim wh as WAVEHDR
wh.lpData:  adress of array of bytes
wh.dwBufferLength: size of the array
wh.dwFlags = 0
wh.dwLoops = 0
(The other members can be ignored)

5.-Next, you have to use the "waveInPrepareHeader" and "waveInAddBuffer" functions for each WAVEHDR declared, to prepare and send the buffers to be filled to the soundcard.

6.-The final step: call the "wveInStart" function to start recording, passing the handle to the wave device obtained with the waveInOpen function in step 3.

-----------------------
I don't know how did you manage to play sound using low-level API, because windows notifies your App when a buffer is filled, and as far as I know, you can't recieve notification messages in VB (version 4.0 at least)..., but you have to use the same methodology.
You can test the dwFlags member form a WAVEHDR against the WHDR_DONE constant to know if a buffer is full or not, when it's full you must do what is explained in step 7.
-----------------------
7.-when windows notifies you, that a buffer has been filled you can read the buffer's data to do anithing what you want to it, then, you must use the "waveInUnprepareHeader" to clean the buffer, and then you must use "waveInPrepareHeader" and "waveInAddBuffer" again for your buffer to be filled.

Note: for example: if you declare 3 WAVEHDR structures, you must prepare and send them. When buffer#1 is filled, you can read it's data while the soundcard fills buffer#2, this gives you the time to read, unprepare, prepare and send the buffer#1 again. When the soundcard finished with buffer#2, you do the same while it's filling the buffer #3, etc...etc.

Trillo
0
 

Author Comment

by:simchiang
ID: 1445205
Shall wait for you. You may also email me at simchiang@ieee.org
Thanks.
0
 
LVL 2

Expert Comment

by:trillo
ID: 1445206
>> Shall wait for you.
Did you see the proposed answer?
0
 

Author Comment

by:simchiang
ID: 1445207

You're right there's no WAVEFORMATEX even in VB6.

Please tell me more about:
a) declaring the databuffers and use them.
b) what are the parameters that I have to fill in in waveInOpen
   and with what.
c) how to use waveInAddBuffer - never used it before.
d) I don't know if in VB6, it can receive Windows notification.
   But please elaborate further on how to test the dwFlags as
   you mentioned.

Could you email me so that we get to correspond faster in the future? I think I'll need to ask you more questions as I continue with the oscilloscope program.

Sim Chiang

0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question