We help IT Professionals succeed at work.

Write my own function to read WAV files

stephany080397
on
Medium Priority
608 Views
Last Modified: 2012-05-04
In an WAV file containing a word, I need to erase the silence that appears before the word is pronunced and at the end of the file, due to the reaction time of the man who speaks to start to speak and to stop his record.
I hope I am clear enougth!!!
I do not want to do this by displaying the file, I want something automatic without intervention of the user.
I have thougth of writing my own function to read a WAV file instead of using the commands that VB provides. This can allows me to detect the level of the sound and remove all the sounds below a predefined value.
I got some functions doing this but they are written with Visual C++, they are called MMIO. I would like to know if I can find the same functions written with Visual Basic 4, and most important, Where??.
Thanks.
stephanie.
Comment
Watch Question

Commented:
Steph:

WAV files have a very simple format.  If you look at them with a hex viewer (Such as the hex mode in Verne Buerg's DOS List Program), you can see the repeating patterns in the file.  Basically, they have a fixed header, and then individual bytes for relative amplitude off the origin.  It's hard to explain this without a graph, but here goes:

Consider a simple sine wave on a cartesian coordinate system.  Let's start at y=0.  Your y measures are your amplitude, and your x measures are your samples.  So, reading from left to right, as the x value increases, depending on your phase, y first increases, reaches peak amplitude, then decreases, then crosses the x axis at 0, continues to decrease, reaches minimum amplitude at -peak amplitude, then climbs back to 0, then repeats.

Well, in a wave file, each byte following the header is an ascii value that represents an amplitude.  Since the maximum ascii value you can achieve is 255, the middle of this range is 127 (hex 7F).  SOo.. in a wave file your origin value is 127, and your max amplitude is 0, and your minimum amplitude is 255.  

This is experimental knowledge that comes from study and experimentation of wav file formats, in order to generate my own wavs, and in wondering how I could apply an algorithm that make's Bill Clinton sound like Donald Duck (or whatever).

Anyway, to acheive what you want to do, you can use a preprogram to process your wav files before you send them to your player.  Just copy the file, opening and writing in binary mode.  Always copy the header (You can determine it's length by examining multiple wav files on your system, and comparing the beginning parts of each to find the initial pattern that's the same in all your wav files. I forget what the actual length is, but that's the way we figured it out).  Then, don't copy through those bytes that are real close to 127 in absolute value.  Then copy everything else through, until you get into extremely low amplitudes again. No noise should be ascii 127 (hex FF).

You don't need libraries to do this, you can do it yourself.

Author

Commented:
Thanks a lot for your answer, you understood exactly what I want to do, but i'm under pressure of time, and cannot waste time examining the format of a wav file. What I want to find are the functions already writtten to read wav file, so I just have to add a little piece of code, or even better functions that do what I want: remove the silence at the beginning and the end of my wav file written with VB4, but maybe I'm dreaming.
Stephanie
ESI

Commented:
Hi Steph,
U wrote VB provides functions to read WAV files ? Wich ones ?
I figure out u use the LoadResData(x,10) function as your waves are encapsulated into a .RES file ?
btw, I have basic modules performing some low-pass filter, echo, reverberate, aso.. functions so all the bloody things are done and u can easily modify it to fit your needs.

Author

Commented:
Sorry for the confusion, I wanted to say that I used the basic VB commands to "play" WAV files.
Maybe some of yours modules could help me, but how can I get them?
stephanie.
CERTIFIED EXPERT

Commented:
If you have functions to do this in Visual C/C++ you can make those a DLL and simply call them from VB...

Author

Commented:
Sorry again, I do not want to seem difficult, but I am asked to make the software with Visual Basic 4 only. I am quite sure that if these functions have been written with VC++, they must exist with VB4. Somewhere...
Stephanie.

CERTIFIED EXPERT

Commented:
All I was saying if you have the stuff in VC++ just simply make it a DLL and then you can call the functions from within VB.  I've made several DLLs here that I call from VB, it is just like making an API call...
ESI

Commented:
Steph
Email at this address : eessii@mailexcite.com and I'll reply & attach the zip'd VB4 modules.
Btw, tward is right, if u already have the source u need...
CU

Commented:
Just use Sound Recorder and delete the silence then save your .wav file. Then use VB to play it as is

Author

Commented:
I do not want to have to display the sounds to do it, I want something done automatically, without intervention of the user. Any way, ESI has answered my question by sending me some modules, I just do not know how to give him his points. So the question is closed.
Thanks everybody.
Stephanie.
Commented:
Hi Steph,
Thanks for your reply, and I'm glad to see the modules I sent you helped !!
My pleasure !
Bye

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.