|
DOUGT - Sound Working But...
--------------------------------------------------------------------------------
I needed to be able to create wave sound files with VB 4.0. I received some code that would allow this to be done, but it only
worked for VB 6.0. With some helpful insight from DougT I was able to get it to work in VB 4.0. Am including this code below.
Dougs' "theory" turned out to be right on the nose.
I took his suggestions and made the changes and 'voila' out came a baked tone cake! Got a wave file that sounded just fine. File size about 87 kb.
So it looks like this will work just fine as he said right from the beginning.
It looks like there is still a hitch though. While the sound quality and ability to adjust it is indeed there, I'm still left needing to produce a series of these tones in one wave file. It won't actually work for me unless I can do this, I'll just end up with a whole bunch of really small wave files of one tone each, if you get my drift...
So the scenario is still, I have a simple text file that contains a variable number of hertz frequencies as numeric decimals, i.e.
234.7856 Hertz
432.56
256.01
542.1711
329.8888
etc.....
In some text files there may be only a dozen notes, but in some text files there could be hundreds.
What I intend to do is feed the text file of notes into the routine provided and use the routine to output to a wave file. So I can figure out how to set up my loops (I'm pretty sure), but the 'chunking' stuff is way over my head. Sounds stupid, but its simply the truth. I can grasp what the more complex parts of the code is doing concept wise, but it makes my head swim a little bit. I tried to figure out how to loop this on my own, thought I could loop the generate function, but it blew the stack. Also I could not join the buffs together to make a sequence of tones before writing them all to file.
So I'm stuck, ironically, with the solution in sight. I can see that the basic premise is sound, but I do not understand how to make it produce a wave file consisting of a series of tones from the input text file. I don't need to be spoon fed, but I also don't grok how to make a series of tones in the wave file..... Am I making sense?
==========
create wav file
Originally Posted by DougT
Both model statemets are perfectly OK in VB6 so I would guess that VB4 does not support Optional arguments. You can test the theory by making a few simple changes. (To make it work in VB 4.0)
Model statements:
Private Sub GenerateTone(ByVal Frequency As Single, _
IntBuff() As Integer, _
Amplitude As Single, _
SamplesPerSec As Long , _
Startpos As Long , Length As Long)
Private Sub SaveWaveFile(ByVal WaveFileName As String, _
ByRef Buffer() As Integer, _
SamplesPerSec As Long )
and change the calling statements to include all the arguments. eg
Code:
GenerateTone 261.62, Buff, 1, 44100&, 0&, -1&
SaveWaveFile "C:\test_Wave.wav", Buff, 44100&
(The '&' after some of the values is to force them to be of type Long)
--------------------------------------------------------------------------------
The following is the code for VB 6.0
The following code lets me specify exact frequencies
This generates a wave file (no clicks or ticks... just clear sound )
(It makes a 1 second tone of 440 Hz)
VB Code
Option Explicit
Private Type tWAVEFORMATEX
wFormatTag As Integer
nChannels As Integer
nSamplesPerSec As Long
nAvgBytesPerSec As Long
nBlockAlign As Integer
wBitsPerSample As Integer
cbSize As Integer
ExtraData(1 To 32) As Byte ' makes the structure 50 bytes long
End Type
Private Type FileHeader
lRiff As Long
lFileSize As Long
lWave As Long
lFormat As Long
lFormatLength As Long
End Type
Private Type WaveFormat
wFormatTag As Integer
nChannels As Integer
nSamplesPerSec As Long
nAvgBytesPerSec As Long
nBlockAlign As Integer
wBitsPerSample As Integer
End Type
Private Type ChunkHeader
lType As Long
lLen As Long
End Type
Private Sub Form_Load()
Dim Buff(0 To 44100) As Integer
GenerateTone 440, Buff, 1
SaveWaveFile "C\test_Wave.wav", Buff
End Sub
Private Sub GenerateTone(ByVal Frequency As Single, IntBuff() As Integer, Optional Amplitude As Single = 1, Optional SamplesPerSec As Long = 44100, Optional Startpos As Long = 0, Optional Length As Long = -1)
Dim K As Long, V1 As Double
Const PI As Double = 3.14159265358979
V1 = SamplesPerSec / (PI * 2 * Frequency)
If Length = -1 Then Length = UBound(IntBuff) - Startpos
For K = Startpos To Startpos + Length
IntBuff(K) = CInt(Fix(Sin(K / V1) * (32766.5 * Amplitude)))
Next K
End Sub
Private Sub SaveWaveFile(ByVal WaveFileName As String, ByRef Buffer() As Integer, Optional SamplesPerSec As Long = 44100)
Dim WF As tWAVEFORMATEX
WF.wFormatTag = 1 'WAVE_FORMAT_PCM
WF.nChannels = 1
WF.wBitsPerSample = 16
WF.nSamplesPerSec = SamplesPerSec
WF.nBlockAlign = (WF.wBitsPerSample * WF.nChannels) \ 8
WF.nAvgBytesPerSec = WF.nSamplesPerSec * WF.nBlockAlign
Open WaveFileName For Binary Access Write Lock Write As #1
WaveWriteHeader 1, WF
Put #1, , Buffer
WaveWriteHeaderEnd 1
Close #1
End Sub
Private Sub WaveWriteHeader(ByVal OutFileNum As Integer, WaveFmt As tWAVEFORMATEX)
Dim header As FileHeader
Dim HdrFormat As WaveFormat
Dim chunk As ChunkHeader
With header
.lRiff = &H46464952 ' "RIFF"
.lFileSize = 0
.lWave = &H45564157 ' "WAVE"
.lFormat = &H20746D66 ' "fmt "
.lFormatLength = Len(HdrFormat)
End With
With HdrFormat
.wFormatTag = WaveFmt.wFormatTag
.nChannels = WaveFmt.nChannels
.nSamplesPerSec = WaveFmt.nSamplesPerSec
.nAvgBytesPerSec = WaveFmt.nAvgBytesPerSec
.nBlockAlign = WaveFmt.nBlockAlign
.wBitsPerSample = WaveFmt.wBitsPerSample
End With
chunk.lType = &H61746164 ' "data"
chunk.lLen = 0
Put #OutFileNum, 1, header
Put #OutFileNum, , HdrFormat
Put #OutFileNum, , chunk
End Sub
Private Sub WaveWriteHeaderEnd(ByVal OutFileNum As Integer)
Dim header As FileHeader
Dim HdrFormat As WaveFormat
Dim chunk As ChunkHeader
Dim Lng As Long
Lng = LOF(OutFileNum)
Put #OutFileNum, 5, Lng
Lng = LOF(OutFileNum) - (Len(header) + Len(HdrFormat) + Len(chunk))
Put #OutFileNum, Len(header) + Len(HdrFormat) + 5, Lng
End Sub
|
|
|
|
|
Hi,
I need to print Receipt(Bill) in VB.Net application. I created that Receipt using crystal report wizard and I put report name as myBill.rpt. My application has "Print" button. I need to print that receipt directly after clicking that "Print" button without using Crystal Report Viewer tool.
Is it possible? What are the coding I'll add to that "Print" button. Any one can help me, pls send me some sample code ?
Regards
Kusal
|
|
|
|
|
Kusal wrote: Is it possible? What are the coding I'll add to that "Print" button. Any one can help me, pls send me some sample code ?
Off course ,possible..
try this code in Print button's Click event
Dim myRpt as myBill<br />
myRpt .Refresh()<br />
myRpt .PrintOptions.PrinterName = "Path of the printer"<br />
myRpt .PrintOptions.PaperSource = "Printer tray"<br />
myRpt .PrintToPrinter(1, False, 1, 1)
hope it will work
Tirtha
Miles to go before I sleep
|
|
|
|
|
Dear Tirtha
Many Thanks
Regards
Kusal
|
|
|
|
|
can some one help me with a problem Im having with generating soudn frequencies?
|
|
|
|
|
Do you want to describe the problem or should we just guess?
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
I use vb.net to create project new website and it run completely in my client browser but when I move that project to my server and run in intranet the error is "Unrecognized configuration section 'connectionStrings'" in web.config (Version Information: Microsoft .NET Framework Version:1.1.4322.2300; ASP.NET Version:1.1.4322.2300 ) I don't know how to correct it. May I must install the other version of .NET Framework or not?
Thank you for your suggestion.
Kitty
|
|
|
|
|
If your website is in .net 2.0 you need to have the 2.0 .net framework loaded and you need to set the properties of the site to be the .net 2.0 framework. Right click the web site select properties then go to the asp.net tab and make sure the 2.0 framework is selected.
Hope that helps.
Ben
|
|
|
|
|
No.You must create your ConnectionString on the server
|
|
|
|
|
I've tried to create website on server,but it still error. Yesterday I installed dot net framework version 2 on my server and restart the server but I observe that in the footnote of the error page it still show "Version Information: Microsoft .NET Framework Version:1.1.4322.2300; ASP.NET Version:1.1.4322.2300 " not show version 2 (version 2 is already show in admin page in control panel) Is it the cause of this errors?
Kitty
|
|
|
|
|
Now. I can manage my old trouble, the error of connecttionstring is passed and the footer show ->--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42 .....ready but the next problem is <authentication mode="Windows"> I don,t know how to correct it.
Kitty
|
|
|
|
|
Heya, looking for some help with a tic tac toe program.
easy stuff for someone that knows how to program.
If u beeleive u can help me, reply and i will add you to my msn for details thanks.
|
|
|
|
|
I recommend doing your own homework. It tends to make it easier for you to do future homework, if you've built the foundation that your teacher intended.
If you do need to ask for homework help, try to make if of the sort where you ask a specific question and post code, not of the sort where you describe your homework broadly and show no sign of having given it any thought yourself.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
|
i m using multiple group boxes n multiple check boxes within them..
i hav made columns in data grid acc. to the name of group boxes,
can anybody please tell me how can i show the text that i checked in the group box in the data grid with comma's b\w them
please help
|
|
|
|
|
When I open the web page "http://finance.yahoo.com/q/os?s=qqqq&m=2007-04" and view the source in
Internet Explorer with Notepad, the text I am looking for looks like
class="yfnc_h" align="right"><b><span id="yfs_l10_qavdf.x">11.67<
but when I use
RichTextBox1.Text = Inet1.OpenURL("http://finance.yahoo.com/q/os?s=qqqq&m=2007-04")
it looks like
class="yfnc_h" align="right"><b>11.67<
in the RichTextBox.
What happened to the
<span id="yfs_l10_qavdf.x"
Thanks in advance
HHP
|
|
|
|
|
consider there r two group boxes n five check boxes within them.
how to do coding for it???
n also keep in mind that i hav to display the result in data grid
|
|
|
|
|
abbss.gaurav wrote: consider there r two group boxes n five check boxes within them.
how to do coding for it???
Coding for what? You haven't metioned what you want this code to do.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Hello,
VS 2005
Strange problem with my visual studio.
I have typed datasets in the designer. I have table adapters that i have dragged from the server explorer. I have used these for the last couple of month. I have added queries, stored procedures, added and deleted fields in the table adapters.
Now, I added an extra column to one of my tables in sql server 2005. I right clicked the relevant table adapter and clicked configure, and included the extra column.
I build the program, but the changes to the table adapter does not reflect in the code. When I do the following: tableAdapter.insert() the extra column has not been included.
I tried this with another table adapter in the dataset designer by adding a new field. The same problem.
I used rebuild, i have deleted the table adapter and added a new one. I have restarted VS, and also restarted the computer. I have also opened the project on another machine. I have deleted the table adapter from the form designer and added a new one from the components tab. And still the same problem.
When I preview the data, the extra column is there. But not when I use it in code.
Can anyone please tell if they know about this problem and is there a way to solve it.
Many thanks if you can.
|
|
|
|
|
Hi Steve,
I have experienced a somewhat similar problem with datasets in VS 2003. Although I am still not sure how or why it happened, I managed to solve the problem by creating a new dataset with a another name and changing all references to the old dataset to the new one. So in your case for example you could delete the existing tableAdapter or keep it (same difference), and create a new one with the name tableAdapter1. Then just roam through your code and add a 1 where necessary.
Hope it helps,
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
I've been trying to get an application that can compile code at runtime, then save it as a .exe file.
So basically what I did was go on MSDN, 'steal' some code (yeah, I know I shouldn't...) that compiled VB and try to change it so it could also save it.
Public Class Form1<br />
<br />
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
CodeEmitter.RunCode("Microsoft.VisualBasic.MsgBox(" & """" & "Hello World" & """" & ")")<br />
<br />
End Sub<br />
End Class<br />
Class CodeEmitter<br />
<br />
Shared Sub RunCode(ByVal code As String)<br />
<br />
Dim cmplrParms As New CodeDom.Compiler.CompilerParameters<br />
<br />
cmplrParms.GenerateExecutable = True<br />
<br />
cmplrParms.OutputAssembly = "C:/VBCompile.exe"<br />
<br />
cmplrParms.TreatWarningsAsErrors = False<br />
<br />
cmplrParms.WarningLevel = 4<br />
<br />
cmplrParms.ReferencedAssemblies.AddRange(New String() {"System.dll", "Microsoft.VisualBasic.dll"})<br />
<br />
code = String.Format("Public NotInheritable Class EmittedClass{0}Public Shared Sub DoWork{0}{1}{0}End Sub{0}End Class", Environment.NewLine, code)<br />
Dim pvdr As New VBCodeProvider<br />
<br />
Dim rslts As CodeDom.Compiler.CompilerResults = pvdr.CompileAssemblyFromSource(cmplrParms, code)<br />
<br />
MsgBox("Path: " & rslts.PathToAssembly)<br />
<br />
Dim assmbly As Reflection.Assembly = rslts.CompiledAssembly<br />
<br />
Dim t As Type = assmbly.GetType("EmittedClass")<br />
<br />
t.InvokeMember("DoWork", Reflection.BindingFlags.InvokeMethod Or Reflection.BindingFlags.Public Or Reflection.BindingFlags.Static, _<br />
Nothing, Nothing, Nothing)<br />
<br />
End Sub<br />
<br />
End Class
The original code worked until I changed
cmplrParms.GenerateInMemory = True
to
cmplrParms.GenerateExecutable = True<br />
<br />
cmplrParms.OutputAssembly = "C:/VBCompile.exe"
Now I get an error FileNotFoundException at
Dim assmbly As Reflection.Assembly = rslts.CompiledAssembly because it turns out that nothing was ever compiled to C:\ in the first place!
Thanks in advance for any help!
|
|
|
|
|
I thought Windows used baclward slashes to separate directories.
ROFLOLMFAO
|
|
|
|
|
Tried that
Doesn't work
EDIT: I found a fix for it. Thanks for trying to help!
-- modified at 7:19 Monday 2nd April, 2007
|
|
|
|
|
Sir/madam.
I am facing a problem i button text.
The problem is i am passing a button control as an argument
like following is my form
i have a function there and in the function signatures i am passing a button control as a argument.
The problem is i am not getting the text of the button in the myclass class.
the object b shows t.text is blank("")
class form1
private sub fun()
dim obj as new myclass
obj.funct(Button1)
'Button1 is name of the button in the form.
end sub
end class
class myclass
public sub funct(byval b as button)
messagebox.show(b.text)
end sub
end class
Please help.
I am using vb.net 2003 Window Application.
Thanks and regards
Pankaj
|
|
|
|
|
Myclass is a reserved word.
Private Sub fun()
Dim obj As New class1
obj.funct(Button1)
'Button1 is name of the button in the form.
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
fun()
End Sub
End Class
Class class1
Public Sub funct(ByVal b As Button)
MessageBox.Show(b.Text)
End Sub
End Class
|
|
|
|
|