Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multimedia

Status
Not open for further replies.

clarkm2

Programmer
Jun 12, 2003
11
0
0
US

Hi, I'm currentaly trying to figure out how to load a wave file (where I'm at now) and capture the data in the wave file into an array. Can anyone help me?
 
yea I'm doing that now.

simple WAV's have a header up to about 2C then one or two bytes for 8/16 and double again for stereo right up to the end of file which defined by the the bytes 4-7 (=long)
my type definition is

Type PARA
wavRIFF As String ' this says RIFF
waveend1 As Long ' this is about 7 short of the end.
wavWAVE As String ' this says WAV
wavfmt As String ' this says fmt
wavdunno As Long
byte21 As Byte
byte22 As Byte
wavchan As Byte ' number of channels
byte24 As Byte
wavfsamp As Long ' sampling frquency
wavfsamp2 As Long
wavchxbytes As Byte
byte34 As Byte
wavbyte As Byte ' number of bytes in samples
byte36 As Byte
wavfdata As String 'data
wavend2 As Long 'length of data
End Type

Sub getheader()
Dim header As PARA

Open #18 blah blah
get #18,1,header
legnth of file is header.waveend1

now you have all the numbers you need. But if it is acompressed WAV I shudder to think.


8 bits samples are biased by +128 and I used arrays type Byte to get a block of them.

16 bits I used tyep Integer and the get statement needed a location one more than I thought.

eg
Dim array(0 to 127)
get #18,44+1,array

stereo and multidimensional arrays I left alone as I was in a hurry.
 
make that last one Dim array(0 to 127) as Integer
 
ok this is cool but, where do I stick it? I want to be able to load a wav file and then dump it into an array. After that if you can help, change the formating into binary to send out of the serial port. Thanks for any input!
 
I have seen threads on accessing the serial port recently. It has been a long time since I accessed serial port (in my QB2.5 days) but it would possibly be in the Open statement where you would have to specify a channel but I am not knowledgable on this.
the

"Get #18, array

puts 128 samples into your array & each sample can be accessed with array(n)
(or array(n) & array(n+1) for stereo).


Correction

wavRIFF*4 As String ' this says RIFF
wavWAVE*4 As String ' this says WAV
wavfmt*4 As String ' this says fmt
wavfdata*4 As String 'data

The strings are always 4 bytes as far as I can see and have to be fixed length or the variables get confused.
 
I still don't understand how to load a chosen wave file? The wave files will be a low quality (8KHz, 8bit, 1 channel) which is meant to transfer voice. I got most of the serial port code finished but I have to read all the information off a wave file, transfer it and read it again.
Any ideas?
 
Just had a few more goes at loading WAV - it works fine but outputting the same variable Type creates problems. I modified the type style to be
array as byte*4
instead of a string variables. That weay you can write out to the file and not cause problems with the string stop code.

what you have to do is
Dim array(0 to 255) as byte,outarr(0 to 255) as integer, _
heada as PARA, n as long, m as integer
' see type def with last corretion

Open "Wave.WAV" for binary access read as #1 len=1
get #1,heada
for n= &H2C to waveend1 step 256
get,n,array
for m=0 to 255
outarr(m)=Cint(array(m))-128
next ' m
' your wotsit here for 256 bytes per loop
if EOF(1) then n = 257
next ' n

I am not at my machine but I reckon that is close, provided you declare the PARA type with Byte*4 correction (again check the help/example files) - you have a max for arrays of 65K (I think) so you have to handle it in chunks - which could be as small as 1 byte if you don't want arrays.

Best of luck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top