|
Hi,
This is going to be a bih question but please if you can help me in any way.
I am building a application that is creating wav files. I have managed to create a wav file but I need to insert a pause in the WAV - a straight line, no sound. but still part of the wav. The code is following:
Dim i As Long
Dim lngLimit As Double
Dim lngDataL, lngDataR As Double
Dim dblDataPt As Double
Dim blnPositive As Boolean
Dim intCycleCount As Integer
Dim lngFileSize As Double
Dim lngSamples As Double
Dim lngDataSize As Double
Dim dblDataSlice As Double
Dim dblWaveTime As Double
Dim dblTotalTime As Double
Dim dblSampleTime As Double
dblFrequency = Frequency
'If dblFrequency > 1000 Then
' intCycles = 100
'Else
' intCycles = 10
'End If
intCycles = CInt(trajanje)
dblWaveTime = 1 / dblFrequency
dblTotalTime = dblWaveTime * intCycles
dblSampleTime = 1 / CDbl(lngSampleRate)
dblDataSlice = (2 * PI) / (dblWaveTime / dblSampleTime)
lngSamples = 0
intCycleCount = 0
blnPositive = True
Do
dblDataPt = System.Math.Sin(lngSamples * dblDataSlice)
If lngSamples > 0 Then
If dblDataPt < 0 Then
blnPositive = False
Else
' Detect Zero Crossing
If Not blnPositive Then
intCycleCount = intCycleCount + 1
If intCycleCount >= intCycles Then Exit Do
blnPositive = True
End If
End If
End If
lngSamples = lngSamples + 1
Loop
'-------------------------------------------------------------------------------
' Bytes 40 - 43 Length of Data Samples * Channels * Bits per Sample / 8
'-------------------------------------------------------------------------------
lngDataSize = lngSamples * intAudioWidth * (intBits / 8)
ReDim Preserve WavArray(0 To 43 + lngDataSize)
WavArray(40) = ExtractByte(lngDataSize, 0)
WavArray(41) = ExtractByte(lngDataSize, 1)
WavArray(42) = ExtractByte(lngDataSize, 2)
WavArray(43) = ExtractByte(lngDataSize, 3)
'-------------------------------------------------------------------------------
' Bytes 04 - 07 Total Length to Follow (Length of File - 8)
'-------------------------------------------------------------------------------
lngFileSize = lngDataSize + 36
WavArray(4) = ExtractByte(lngFileSize, 0)
WavArray(5) = ExtractByte(lngFileSize, 1)
WavArray(6) = ExtractByte(lngFileSize, 2)
WavArray(7) = ExtractByte(lngFileSize, 3)
'-------------------------------------------------------------------------------
' Bytes 44 - End Data Samples
'-------------------------------------------------------------------------------
If intBits = 8 Then
lngLimit = 127
Else
lngLimit = 32767
End If
For i = 0 To lngSamples - 1
If intBits = 8 Then
'-----------------------------------------------------------------------
' 8 Bit Data
'-----------------------------------------------------------------------
' Calculate data point.
dblDataPt = System.Math.Sin(i * dblDataSlice) * lngLimit
lngDataL = Int(dblDataPt * dblVolumeL) + lngLimit
lngDataR = Int(dblDataPt * dblVolumeR) + lngLimit
' Place data point in wave tile.
If intAudioMode = MODE_MONO Then WavArray(i + 44) = ExtractByte(lngDataL, 0)
If intAudioMode = MODE_LR Then 'L+R stereo
WavArray((2 * i) + 44) = ExtractByte(lngDataL, 0)
WavArray((2 * i) + 45) = ExtractByte(lngDataR, 0)
End If
If intAudioMode = MODE_L Then ' L only stereo
WavArray((2 * i) + 44) = ExtractByte(lngDataL, 0)
WavArray((2 * i) + 45) = 0
End If
If intAudioMode = MODE_R Then ' R only stereo
WavArray((2 * i) + 44) = 0
WavArray((2 * i) + 45) = ExtractByte(lngDataR, 0)
End If
Else
'-----------------------------------------------------------------------
' 16 Bit Data
'-----------------------------------------------------------------------
' Calculate data point.
dblDataPt = System.Math.Sin(i * dblDataSlice) * lngLimit
lngDataL = Int(dblDataPt * dblVolumeL)
lngDataR = Int(dblDataPt * dblVolumeR)
' Place data point in wave tile.
If intAudioMode = MODE_MONO Then
WavArray((2 * i) + 44) = ExtractByte(lngDataL, 0)
WavArray((2 * i) + 45) = ExtractByte(lngDataL, 1)
End If
If intAudioMode = MODE_LR Then
WavArray((4 * i) + 44) = ExtractByte(lngDataL, 0)
WavArray((4 * i) + 45) = ExtractByte(lngDataL, 1)
WavArray((4 * i) + 46) = ExtractByte(lngDataR, 0)
WavArray((4 * i) + 47) = ExtractByte(lngDataR, 1)
End If
If intAudioMode = MODE_L Then
WavArray((4 * i) + 44) = ExtractByte(lngDataL, 0)
WavArray((4 * i) + 45) = ExtractByte(lngDataL, 1)
WavArray((4 * i) + 46) = 0
WavArray((4 * i) + 47) = 0
End If
If intAudioMode = MODE_R Then
WavArray((4 * i) + 44) = 0
WavArray((4 * i) + 45) = 0
WavArray((4 * i) + 46) = ExtractByte(lngDataR, 0)
WavArray((4 * i) + 47) = ExtractByte(lngDataR, 1)
End If
End If
Next
this is the function that creates the array. another function just writes the wav as binary writer, and all is good. I get a perfect result; a perfect sine wave. But i need to insert some pauses -SILENCE that is in the WAV.
This is a great challenge for me, maybe it will be for you too.
Please help.
Thank you.
|
|
|
|
|
I'm pretty sure that if you just write a stream of zeros in a 16 bit file or a stream of 127s or 128s in an 8 bit file then you should get no sound. Actually any number as long as it stays the same and doesn't vary should produce no sound.
Basically the loudness of a noise is just the difference between its highest air pressure and its lowest air pressure. When the numbers in a wave file go to the speaker it causes it to push something back and forth depending on what the number is and this vibration creates the noise. And all a microphone does is record air pressure at a given moment in time.
|
|
|
|
|
i have been looking for a way to find the number of files in a folder and if there is more the n
number of files in that folder delete the oldest ones. i have fount a way to count the number of
files in the folder, but i am not having any look in finding something to help me in deleting the
oldest files. any guidance would be helpful.
I'm using Vb.net 2.0.
|
|
|
|
|
Above your code write Imports System.IO . Then check out the possibilities of File (File.Exists, File.GetCreationTime, etc)
Good luck,
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
this line gets the count System.IO.Directory.GetFiles("c:\").Length
|
|
|
|
|
i had already fount a way to do this but this is alot simpler. So thanks
|
|
|
|
|
You can have a function which will find the oldest file in a given directory and then you may delete it.
Call this function in a loop while System.IO.Directory.GetFiles("Path").Length>n.
Following is such a small function which finds the oldest file at the given path and removes it –
-------------------Start Code--------------
Private Sub RemoveOldFiles()
Dim str() As String
str = System.IO.Directory.GetFiles("Path")
Dim d As Date
Dim oldfile As String
d = Now()
For Each fl As String In System.IO.Directory.GetFiles("Path")
If d > System.IO.File.GetCreationTime(fl) Then
oldfile = fl
d = System.IO.File.GetCreationTime(fl)
End If
Next
System.IO.File.Delete(oldfile)
End Sub
--------------End Sub-------------------
I hope this helps .
-Dave.
Dave Traister,
ComponentOne LLC.
www.componentone.com
|
|
|
|
|
Thanks
this is just what i needed. it works perfectly for what i need
|
|
|
|
|
Hi I have a column that should only allow the user to enter in integer values in the range 0-100. Only integers. How do I do this and where would I need to put the code.
Mr oizo
|
|
|
|
|
<edititemtemplate>
<asp:label id="retailCBEditLbl" text="<%# Convert.ToDouble(DataBinder.Eval(Container.DataItem, "AmexRetailCB")).ToString("C")%>" runat="server">
<asp:textbox id="retailCBEditTxt" runat="server" width="50" text="<%# Convert.ToDouble(DataBinder.Eval(Container.DataItem, "AmexRetailCB")).ToString%>" maxlength="11">
<asp:requiredfieldvalidator id="Req1" runat="server" controltovalidate="retailCBEditTxt" errormessage="You must enter Retail CB amount." display="None">
<asp:regularexpressionvalidator enabled="true" id="RegEx1" runat="server" display="None" controltovalidate="retailCBEditTxt" errormessage="Please enter only numbers in currency format for Retail CB amount." validationexpression="^(-)?\d+(\.\d\d)?$">
Replace the resular expression to an expression that only accepts numeric (^([0-9]*|\d*\d{1}?\d*)$)
To allow only 0-100 use a custome validator just like regex and validate in code behind.
Hope this helps
|
|
|
|
|
<EditItemTemplate>
<asp:Label ID="retailCBEditLbl" Text='<%# Convert.ToDouble(DataBinder.Eval(Container.DataItem, "AmexRetailCB")).ToString("C")%>' Runat="server" /><br />
<asp:textbox id ="retailCBEditTxt" runat="server" width="50" Text='<%# Convert.ToDouble(DataBinder.Eval(Container.DataItem, "AmexRetailCB")).ToString%>' maxlength="11" ></asp:textbox>
<asp:requiredfieldvalidator id="Req1" runat="server" controltovalidate="retailCBEditTxt" errormessage="You must enter Retail CB amount." display="None"></asp:requiredfieldvalidator>
<asp:regularexpressionvalidator enabled="true" id="RegEx1" runat="server" display="None" controltovalidate="retailCBEditTxt" errormessage="Please enter only numbers in currency format for Retail CB amount." validationexpression="^(-)?\d+(\.\d\d)?$" ></asp:regularexpressionvalidator>
</EditItemTemplate>
Sorry about the earlier message, here you go
|
|
|
|
|
Hi,
we use a ListView control in order to show thumbnails. After we add some thumbnails, we need to know which thumbnail(ListViewItem is selected or clicked/selected with the mouse) and for this we use ListView1_SelectedIndexChanged event. To know that, we want to know the slected index of the ListView so we use the .SelectedIndices(0) method, but it gets an exception error as shown below.
Private Sub ListView1_SelectedIndexChanged(ByVal .....)
Dim index as Integer
index = ListView1.SelectedIndices(0)
End Sub
- ex {"InvalidArgument=Value of '0' is not valid for 'index'.
Parameter name: index"} System.Exception
Any idea how to retrieve the index of the selected ListViewItem?
|
|
|
|
|
You first have to check if SelectedIndices contains anything at all. The SelectedIndexChanged event is also triggered when the previously selected item is unselected, and then no item is selected and the collection is empty.
---
single minded; short sighted; long gone;
|
|
|
|
|
I am having a page1,page2,page3 in a form .in that i am having a controls . I want to save it into .xml file and i want to retrieve the same order of the form and their properties .IS it possible or not through dataset and has to store in .xml file ??
|
|
|
|
|
It's possible to use a DataSet, but you have to populate the DataSet, or any other container, yourself. The ControlsCollection class is not seriablize, not are the controls it contains.
Your code has to examine each control and pick out the properties you want, then save that information in the DataSet or other container.
You might want to check out this blog post[^] for an example of Dynamic Control Creation from an XML file. It does NOT show you how to serialize the controls to make the file though.
Combine what you see in that post with Reflection and XML documents and you should be able to put together a solution. BTW, a DataSet will not help you much.
|
|
|
|
|
Can we get the properties of form Consider controls in xml format for example like this of form controls for multiple pages . or custom properties into xml file using datasets .
<Pages xmlns=""><br />
- <Page PageNo="1"><br />
<PageName>Page1</PageName> <br />
<PageSize>3</PageSize> <br />
<PageOrientation>0</PageOrientation> <br />
<PagePicture /> <br />
<PageNoPicture>false</PageNoPicture> <br />
<PageAllPages>false</PageAllPages> <br />
<PageDesignOnly>false</PageDesignOnly> <br />
- <PageBorder><br />
<BorderLeft>0.75</BorderLeft> <br />
<BorderTop>0.75</BorderTop> <br />
<BorderHeight>0.75</BorderHeight> <br />
<BorderWidth>0.75</BorderWidth> <br />
<BorderPattern>1</BorderPattern> <br />
</PageBorder><br />
- <txt:TextBox TextIndex="1"><br />
<txt:TextName>Text1</txt:TextName> <br />
<txt:TextAlign>0</txt:TextAlign> <br />
<txt:Appearance>1</txt:Appearance> <br />
<txt:TextBackColor>-2147483643</txt:TextBackColor> <br />
<txt:TextForeColor>-2147483640</txt:TextForeColor> <br />
<txt:TextBorderStyle>1</txt:TextBorderStyle> <br />
<txt:TextText>Text1</txt:TextText> <br />
- <fn:Font><br />
<fn:FontName>MS Sans Serif</fn:FontName> <br />
- <fn:FontStyle><br />
<fn:Bold>false</fn:Bold> <br />
<fn:Italic>false</fn:Italic> <br />
</fn:FontStyle><br />
<fn:FontSize>8</fn:FontSize> <br />
<fn:FontUnderline>false</fn:FontUnderline> <br />
<fn:FontStrikeout>false</fn:FontStrikeout> <br />
</fn:Font><br />
<txt:TextToolTip /> <br />
- <pos:Position><br />
<pos:Left>1935</pos:Left> <br />
<pos:Top>1560</pos:Top> <br />
<pos:Height>315</pos:Height> <br />
<pos:Width>1605</pos:Width> <br />
</pos:Position><br />
<txt:TextLocked>false</txt:TextLocked> <br />
<txt:TextMaxLen>255</txt:TextMaxLen> <br />
<txt:TextMinLen>0</txt:TextMinLen> <br />
<txt:TextMultiline>false</txt:TextMultiline> <br />
<txt:TextDataType>0</txt:TextDataType> <br />
<txt:TextFormat /> <br />
<txt:IsIndexField>True</txt:IsIndexField> <br />
</txt:TextBox><br />
- <txt:TextBox TextIndex="2"><br />
<txt:TextName>Text2</txt:TextName> <br />
<txt:TextAlign>0</txt:TextAlign> <br />
<txt:Appearance>1</txt:Appearance> <br />
<txt:TextBackColor>-2147483643</txt:TextBackColor> <br />
<txt:TextForeColor>-2147483640</txt:TextForeColor> <br />
<txt:TextBorderStyle>1</txt:TextBorderStyle> <br />
<txt:TextText>Text2</txt:TextText> <br />
- <fn:Font><br />
<fn:FontName>MS Sans Serif</fn:FontName> <br />
- <fn:FontStyle><br />
<fn:Bold>false</fn:Bold> <br />
<fn:Italic>false</fn:Italic> <br />
</fn:FontStyle><br />
<fn:FontSize>8</fn:FontSize> <br />
<fn:FontUnderline>false</fn:FontUnderline> <br />
<fn:FontStrikeout>false</fn:FontStrikeout> <br />
</fn:Font><br />
<txt:TextToolTip /> <br />
- <pos:Position><br />
<pos:Left>1965</pos:Left> <br />
<pos:Top>2085</pos:Top> <br />
<pos:Height>315</pos:Height> <br />
<pos:Width>1605</pos:Width> <br />
</pos:Position><br />
<txt:TextLocked>false</txt:TextLocked> <br />
<txt:TextMaxLen>255</txt:TextMaxLen> <br />
<txt:TextMinLen>0</txt:TextMinLen> <br />
<br />
<txt:TextFormat /> <br />
<txt:IsIndexField>False</txt:IsIndexField> <br />
</txt:TextBox><br />
- <txt:TextBox TextIndex="3"><br />
<txt:TextName>Text3</txt:TextName> <br />
<txt:TextAlign>0</txt:TextAlign> <br />
<txt:Appearance>1</txt:Appearance> <br />
<txt:TextBackColor>-2147483643</txt:TextBackColor> <br />
<br />
<txt:TextBorderStyle>1</txt:TextBorderStyle> <br />
<txt:TextText>Text3</txt:TextText> <br />
- <fn:Font><br />
<fn:FontName>MS Sans Serif</fn:FontName> <br />
- <fn:FontStyle><br />
<fn:Bold>false</fn:Bold> <br />
<fn:Italic>false</fn:Italic> <br />
<br />
- <pos:Position><br />
<pos:Left>2925</pos:Left> <br />
<pos:Top>4935</pos:Top> <br />
<pos:Height>315</pos:Height> <br />
<pos:Width>1605</pos:Width> <br />
</pos:Position><br />
<txt:TextLocked>false</txt:TextLocked> <br />
<txt:TextMaxLen>255</txt:TextMaxLen> <br />
<txt:TextMinLen>0</txt:TextMinLen> <br />
<txt:TextMultiline>false</txt:TextMultiline> <br />
<txt:TextDataType>0</txt:TextDataType> <br />
<txt:TextFormat /> <br />
<txt:IsIndexField>True</txt:IsIndexField> <br />
</txt:TextBox><br />
- <chk:CheckBox ChkBoxIndex="1"><br />
<chk:ChkBoxName>Checkbox1</chk:ChkBoxName> <br />
<chk:ChkBoxAlign>0</chk:ChkBoxAlign> <br />
<chk:ChkBoxAppearance>1</chk:ChkBoxAppearance> <br />
<chk:ChkBoxBackColor>16777215</chk:ChkBoxBackColor> <br />
<chk:ChkBoxCaption>Checkbox1</chk:ChkBoxCaption> <br />
- <fn:Font><br />
<fn:FontName>MS Sans Serif</fn:FontName> <br />
- <fn:FontStyle><br />
<fn:Bold>false</fn:Bold> <br />
<fn:Italic>false</fn:Italic> <br />
</fn:FontStyle><br />
<fn:FontSize>8</fn:FontSize> <br />
<fn:FontUnderline>false</fn:FontUnderline> <br />
<fn:FontStrikeout>false</fn:FontStrikeout> <br />
</fn:Font><br />
<chk:ChkBoxForeColor>-2147483630</chk:ChkBoxForeColor> <br />
- <pos:Position><br />
<pos:Left>2280</pos:Left> <br />
<pos:Top>3180</pos:Top> <br />
<pos:Height>285</pos:Height> <br />
<pos:Width>1395</pos:Width> <br />
</pos:Position><br />
<chk:ChkBoxToolTip /> <br />
<chk:ChkBoxDefaultValue>false</chk:ChkBoxDefaultValue> <br />
</chk:CheckBox><br />
</Page><br />
</Pages><br />
</Name>
|
|
|
|
|
You might want to check the little box that says "Ignore HTML tags in this message" before you hit post. Your post is completely unreadable.
But, I think you're question is "Can we get a form to render controls automatically from an XML file??" No. You have to write the code to parse the XML file and create the controls and set the properties one at a time.
|
|
|
|
|
hi
combo box in vb.net 2005 is very confusing
-When i click on combo box i cant click anywhere else in form
- some time it show display member some time value member
-it never work in grid
Plz help me
faisal iqbal ch
|
|
|
|
|
Without seeing the code that setup the ComboBox, it's pretty difficult to tell you what's wrong.
|
|
|
|
|
Hi all,
i am having trouble with the line of code below, both my table and record are variables which is fine, but the problem is that sometimes the VARAddRecord string contains an apostrophe and it causes an error - Syntax error (missing operator) in query expression
VARStr = "INSERT INTO [" & VARaddTable & "] ([Episode]) VALUES ('" & VARaddRecord & "')"
im sure it is simple but im fairly new to vb .net so im unsure on how to get around this
can anyone help please?
thanks
|
|
|
|
|
This is the problem with using string concantenation to build SQL queries. You open yourself up to SQL Injection attacks and you have to write a bunch of extra code to handle all the things a user can do to screw up your query.
Read this article[^] by Colin Angus Mackey and you'll understand why what you're doing is a bad idea.
Convert this to a parameterized query and you'll solve your immediate problem, without writing a ton of code to handle character escapes.
|
|
|
|
|
thank you, i will read through that article
i am not using this anywhere that it would be vulnerable to such an attack though as im only creating this program as a hobby, my main job is networking.
but thank you.
P.S if it is not being used for a business do u think there would be much point in me going to the trouble of securing it again injection attacks?
|
|
|
|
|
There's nothing like learning the correct way to do something, even if you don't think you'll need it.
|
|
|
|
|
eyeball_2003 wrote: f it is not being used for a business do u think there would be much point in me going to the trouble of securing it again injection attacks?
Yes.
1. The problem that you have is so closely linked to sql injections that it's hard to solve it without learning anything about sql injections.
2. Bad code has a tendency to spread. Even if it's not used in a business system now, some part of it might be in the future. "Hmm... Didn't I write some code for that before, that I can just copy and paste into this new system...?"
---
single minded; short sighted; long gone;
|
|
|
|
|
number 2 is a valid point, thank you.
and its always in my best interest to learn the correct way
thanks guys
|
|
|
|