473,782 Members | 2,454 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why do these two methods produce diffrent output

Public mLength As Integer
Public mChannels As Short
Public mSampleRate As Integer
Public mDataLength As Integer
Public mBitsPerSample As Short

Public Sub CreateWaveHeade r(ByRef sPath As String)
Dim fileNumber As Integer

Try
fileNumber = FreeFile()

FileOpen(fileNu mber, sPath, OpenMode.Binary , OpenAccess.Writ e)

'Write the RIFF bit of the header first.
FilePut(fileNum ber, "RIFF", 1)
FilePut(fileNum ber, mLength, 5)

'Then do the wave header.
FilePut(fileNum ber, "WAVEfmt ", 9)
FilePut(fileNum ber, CInt(16), 17)
FilePut(fileNum ber, CShort(1), 21)
FilePut(fileNum ber, mChannels, 23)
FilePut(fileNum ber, mSampleRate, 25)
FilePut(fileNum ber, CInt(mSampleRat e * ((mBitsPerSampl e *
mChannels) / 8)), 29)
FilePut(fileNum ber, CShort((mBitsPe rSample * mChannels) / 8),
33)
FilePut(fileNum ber, mBitsPerSample, 35)
FilePut(fileNum ber, "data", 37)
FilePut(fileNum ber, mDataLength, 41)
Catch ex As Exception
Throw ex
Finally
FileClose(fileN umber)
End Try
End Sub

Public Sub CreateWaveHeade rEx(ByRef sPath As String)
Try
Using bw As New BinaryWriter(Fi le.Open(sPath,
FileMode.OpenOr Create, FileAccess.Writ e))
'Write the RIFF bit of the header first.
bw.Write("RIFF" )
bw.Write(mLengt h)

'Then the wave header.
bw.Write("WAVEf mt ")
bw.Write(CInt(1 6))
bw.Write(CShort (1))
bw.Write(mChann els)
bw.Write(mSampl eRate)
bw.Write(CInt(m SampleRate * ((mBitsPerSampl e * mChannels) /
8)))
bw.Write(CShort ((mBitsPerSampl e * mChannels) / 8))
bw.Write(mBitsP erSample)
bw.Write("data" )
bw.Write(mDataL ength)
bw.Flush()
End Using
Catch ex As Exception
Throw ex
End Try
End Sub
Mar 30 '07 #1
5 1551
Chad,

In my idea is your sample to long for a newsgroup, can you bring it back to
the essentials?

Cor

"Chad Miller" <ch***@predicti veconcepts.coms chreef in bericht
news:46******** *************** @roadrunner.com ...
Public mLength As Integer
Public mChannels As Short
Public mSampleRate As Integer
Public mDataLength As Integer
Public mBitsPerSample As Short

Public Sub CreateWaveHeade r(ByRef sPath As String)
Dim fileNumber As Integer

Try
fileNumber = FreeFile()

FileOpen(fileNu mber, sPath, OpenMode.Binary , OpenAccess.Writ e)

'Write the RIFF bit of the header first.
FilePut(fileNum ber, "RIFF", 1)
FilePut(fileNum ber, mLength, 5)

'Then do the wave header.
FilePut(fileNum ber, "WAVEfmt ", 9)
FilePut(fileNum ber, CInt(16), 17)
FilePut(fileNum ber, CShort(1), 21)
FilePut(fileNum ber, mChannels, 23)
FilePut(fileNum ber, mSampleRate, 25)
FilePut(fileNum ber, CInt(mSampleRat e * ((mBitsPerSampl e *
mChannels) / 8)), 29)
FilePut(fileNum ber, CShort((mBitsPe rSample * mChannels) / 8),
33)
FilePut(fileNum ber, mBitsPerSample, 35)
FilePut(fileNum ber, "data", 37)
FilePut(fileNum ber, mDataLength, 41)
Catch ex As Exception
Throw ex
Finally
FileClose(fileN umber)
End Try
End Sub

Public Sub CreateWaveHeade rEx(ByRef sPath As String)
Try
Using bw As New BinaryWriter(Fi le.Open(sPath,
FileMode.OpenOr Create, FileAccess.Writ e))
'Write the RIFF bit of the header first.
bw.Write("RIFF" )
bw.Write(mLengt h)

'Then the wave header.
bw.Write("WAVEf mt ")
bw.Write(CInt(1 6))
bw.Write(CShort (1))
bw.Write(mChann els)
bw.Write(mSampl eRate)
bw.Write(CInt(m SampleRate * ((mBitsPerSampl e * mChannels) /
8)))
bw.Write(CShort ((mBitsPerSampl e * mChannels) / 8))
bw.Write(mBitsP erSample)
bw.Write("data" )
bw.Write(mDataL ength)
bw.Flush()
End Using
Catch ex As Exception
Throw ex
End Try
End Sub

Mar 31 '07 #2
Thanks Cor,

I need to leave the two methods in my post. I am writting a wav header out
to a file. They should both create the same result. The only diffrence is
that one uses a binary writer and the other uses the older FilePut method.

- Chad
"Cor Ligthert [MVP]" <no************ @planet.nlwrote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
Chad,

In my idea is your sample to long for a newsgroup, can you bring it back
to the essentials?

Cor

"Chad Miller" <ch***@predicti veconcepts.coms chreef in bericht
news:46******** *************** @roadrunner.com ...
>Public mLength As Integer
Public mChannels As Short
Public mSampleRate As Integer
Public mDataLength As Integer
Public mBitsPerSample As Short

Public Sub CreateWaveHeade r(ByRef sPath As String)
Dim fileNumber As Integer

Try
fileNumber = FreeFile()

FileOpen(fileNu mber, sPath, OpenMode.Binary , OpenAccess.Writ e)

'Write the RIFF bit of the header first.
FilePut(fileNum ber, "RIFF", 1)
FilePut(fileNum ber, mLength, 5)

'Then do the wave header.
FilePut(fileNum ber, "WAVEfmt ", 9)
FilePut(fileNum ber, CInt(16), 17)
FilePut(fileNum ber, CShort(1), 21)
FilePut(fileNum ber, mChannels, 23)
FilePut(fileNum ber, mSampleRate, 25)
FilePut(fileNum ber, CInt(mSampleRat e * ((mBitsPerSampl e *
mChannels) / 8)), 29)
FilePut(fileNum ber, CShort((mBitsPe rSample * mChannels) / 8),
33)
FilePut(fileNum ber, mBitsPerSample, 35)
FilePut(fileNum ber, "data", 37)
FilePut(fileNum ber, mDataLength, 41)
Catch ex As Exception
Throw ex
Finally
FileClose(fileN umber)
End Try
End Sub

Public Sub CreateWaveHeade rEx(ByRef sPath As String)
Try
Using bw As New BinaryWriter(Fi le.Open(sPath,
FileMode.OpenO rCreate, FileAccess.Writ e))
'Write the RIFF bit of the header first.
bw.Write("RIFF" )
bw.Write(mLengt h)

'Then the wave header.
bw.Write("WAVEf mt ")
bw.Write(CInt(1 6))
bw.Write(CShort (1))
bw.Write(mChann els)
bw.Write(mSampl eRate)
bw.Write(CInt(m SampleRate * ((mBitsPerSampl e * mChannels)
/ 8)))
bw.Write(CShort ((mBitsPerSampl e * mChannels) / 8))
bw.Write(mBitsP erSample)
bw.Write("data" )
bw.Write(mDataL ength)
bw.Flush()
End Using
Catch ex As Exception
Throw ex
End Try
End Sub


Mar 31 '07 #3
So what's different about the output?

Robin S.
--------------------
"Chad Miller" <ch***@predicti veconcepts.comw rote in message
news:46******** *************** @roadrunner.com ...
Thanks Cor,

I need to leave the two methods in my post. I am writting a wav header
out to a file. They should both create the same result. The only
diffrence is that one uses a binary writer and the other uses the older
FilePut method.

- Chad
"Cor Ligthert [MVP]" <no************ @planet.nlwrote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
>Chad,

In my idea is your sample to long for a newsgroup, can you bring it back
to the essentials?

Cor

"Chad Miller" <ch***@predicti veconcepts.coms chreef in bericht
news:46******* *************** *@roadrunner.co m...
>>Public mLength As Integer
Public mChannels As Short
Public mSampleRate As Integer
Public mDataLength As Integer
Public mBitsPerSample As Short

Public Sub CreateWaveHeade r(ByRef sPath As String)
Dim fileNumber As Integer

Try
fileNumber = FreeFile()

FileOpen(fileNu mber, sPath, OpenMode.Binary ,
OpenAccess.Wr ite)

'Write the RIFF bit of the header first.
FilePut(fileNum ber, "RIFF", 1)
FilePut(fileNum ber, mLength, 5)

'Then do the wave header.
FilePut(fileNum ber, "WAVEfmt ", 9)
FilePut(fileNum ber, CInt(16), 17)
FilePut(fileNum ber, CShort(1), 21)
FilePut(fileNum ber, mChannels, 23)
FilePut(fileNum ber, mSampleRate, 25)
FilePut(fileNum ber, CInt(mSampleRat e * ((mBitsPerSampl e *
mChannels) / 8)), 29)
FilePut(fileNum ber, CShort((mBitsPe rSample * mChannels) /
8), 33)
FilePut(fileNum ber, mBitsPerSample, 35)
FilePut(fileNum ber, "data", 37)
FilePut(fileNum ber, mDataLength, 41)
Catch ex As Exception
Throw ex
Finally
FileClose(fileN umber)
End Try
End Sub

Public Sub CreateWaveHeade rEx(ByRef sPath As String)
Try
Using bw As New BinaryWriter(Fi le.Open(sPath,
FileMode.Open OrCreate, FileAccess.Writ e))
'Write the RIFF bit of the header first.
bw.Write("RIFF" )
bw.Write(mLengt h)

'Then the wave header.
bw.Write("WAVEf mt ")
bw.Write(CInt(1 6))
bw.Write(CShort (1))
bw.Write(mChann els)
bw.Write(mSampl eRate)
bw.Write(CInt(m SampleRate * ((mBitsPerSampl e *
mChannels) / 8)))
bw.Write(CShort ((mBitsPerSampl e * mChannels) / 8))
bw.Write(mBitsP erSample)
bw.Write("data" )
bw.Write(mDataL ength)
bw.Flush()
End Using
Catch ex As Exception
Throw ex
End Try
End Sub



Apr 1 '07 #4
Chad Miller wrote:
FilePut(fileNum ber, "RIFF", 1)
bw.Write("RIFF" )
I suspect you might need the StringIsFixedLe ngth parameter for the first one
of those lines to produce the same output as the second.

Andrew
Apr 2 '07 #5
Chad Miller wrote:
<snip>
>Public Sub CreateWaveHeade r(ByRef sPath As String)
<snip'n'edit>
FileOpen(fileNu mber, sPath, OpenMode.Binary , OpenAccess.Writ e)

'Write the RIFF bit of the header first.
FilePut(fileNum ber, "RIFF", 1)
<snip>
>End Sub
>Public Sub CreateWaveHeade rEx(ByRef sPath As String)
<snip'm'edit>
Using bw As New BinaryWriter(Fi le.Open(sPath, _
FileMode.OpenOr Create, FileAccess.Writ e))
'Write the RIFF bit of the header first.
bw.Write("RIFF" )
<snip>
>End Sub
Because BinaryWriter.Wr ite(String) puts a length prefix before the
actual chars. You need to get the chars from the string and write
*them*.

<aircode>
'Force Ansi encoding (chars are 1 byte,
'non-ascii chars are valid
Dim Ansi As System.Text.Enc oding = _
System.Text.Enc oding.GetEncodi ng(1252)

Try
Using bw As New BinaryWriter( _
File.Open(sPath , FileMode.OpenOr Create, FileAccess.Writ e), _
Ansi)
'Write the RIFF bit of the header first.
bw.Write("RIFF" .ToCharArray)

'I guess you can takje from here...
</aircode>

HTH.

Regards,

Branco.

Apr 3 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
2187
by: Steven Bethard | last post by:
Jack Diederich wrote: > > itertools to iter transition, huh? I slipped that one in, I mentioned > it to Raymond at PyCon and he didn't flinch. It would be nice not to > have to sprinkle 'import itertools as it' in code. iter could also > become a type wrapper instead of a function, so an iter instance could > be a wrapper that figures out whether to call .next or __getitem__ > depending on it's argument. > for item in...
0
3046
by: Morten Gulbrandsen | last post by:
mysql> USE company; Database changed mysql> mysql> DROP TABLE IF EXISTS EMPLOYEE; -------------- DROP TABLE IF EXISTS EMPLOYEE -------------- Query OK, 0 rows affected (0.00 sec)
1
1988
by: Eliza Zadura | last post by:
My scenario is: I need to produce documentation from an application that stores data in XML and a RDBMS. The desired output format is mainly to be used for print. The goal would be to be able to provide alternatives like HTML output and PDF output. The "dream" is to be able to provide editable output in a format that can handle both text, links and images. The images are .svg and there is an export function available (Ilog Jview). ...
2
17417
by: Matt | last post by:
I want to generate text output from XML using XSLT. The question is how to produce a newline? When I produce HTML as output, I have no problems. But when I attempt to produce text, all data is append together. please help. thanks!!
2
1314
by: Brian Henry | last post by:
Hi everyone, What I am doing in my application is I have a base app, then a bunch of plug-in dll files. Well this gets confuseing to diferentiate between the real plug-ins and the actual link libraries that are not to be used as plugins (in reality they are both DLL files) is there anyway I could make VS.NET compile my VB.NET DLL plug-in projects into a diffrent extension but still be DLL files? (i dont feel like changeing tens of...
60
3203
by: Eric | last post by:
I thought it might be fun to run a simple vote to discover the most preferred spacing style for a simple if statement with a single, simple boolean test. By my count, there are 32 possible variations for this case. Here is a complete list. AA: if ( a > b ) AB: if ( a > b) AC: if ( a >b ) AD: if ( a >b) AE: if ( a> b )
0
2374
by: bcobra | last post by:
What am I doing wrong? the code: age Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %> <%@ Register TagPrefix="MM" Namespace="DreamweaverCtrls" Assembly="DreamweaverCtrls,version=1.0.0.0,publicKeyToken=836f606ede05d46a,culture=neutral" %> <MM:DataSet id="SSF2Pinky"
0
2144
by: Metalzed | last post by:
Hi I have a little problem If I use the this C# code DateTime.Now.ToString() output = 2006-11-03 06:15:17 But if i use this code in MSSQL (CONVERT(VARCHAR(35), { fn NOW() })) output= Nov 3 2006 6:15AM
318
11135
by: King Raz | last post by:
The shootout site has benchmarks comparing different languages. It includes C# Mono vs Java but not C# .NET vs Java. So I went through all the benchmark on the site ... http://kingrazi.blogspot.com/2008/05/shootout-c-net-vs-java-benchmarks.html Just to keep the post on topic for my friends at comp.lang.c++, how do I play default windows sounds with C++?
0
9479
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10311
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9942
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7492
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6733
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5378
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5509
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4043
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2874
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.