|
Yes, but if as your code indicates, it is 16 bits per sample, why are you generating 8 bit samples and loading them into successive bytes?
It means you file ends up with 16 bit samples made of two 8 bit bytes with the same frequency value. Should you not be using short or ushort values instead?
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
I'm pretty sure there are several errors here.
1.
if your samples are 16-bit you should use 16-bit quantities everywhere; so either work with a short array, or convert the intended short values to their upper and lower byte values; what you have basically is 8-bit samples.
2.
if your sound is to be stereophonic, you should generate two signals (e.g. two distinct sine waves) and alternate their samples; what you have is a single sine wave where consecutive samples are sent to the left and right channel, that isn't real stereo at all, there is just a small phase shift between left and right.
3.
if frequency is intended to indicate the tone pitch in Hertz, you need a conversion factor, probably 2*Math.Pi to make that happen. A sine wave goes one full cycle when its argument is increased by that amount, not by 1.
|
|
|
|
|
mmm, had to think about it a bit, but (i think) it starts to make sense .
1. OK, so 2 bytes for each value.
2. makes sense
3. I think it should be 1/frequency, 2*PI gave bad results, but maybe that was for another reason .
If I find the solution I'll let you know.
many thanks.
V.
|
|
|
|
|
Obviously for higher frequencies, the phase step has to be larger, not smaller, so F is in the numerator.
If you want N sine samples at frequency F spanning a period of 1 second, the phase step should be:
double deltaPhase=2*Math.Pi*F/N;
for(int i=0; i<N; i++) {
double phase=i*deltaPhase;
}
which means after N steps, your phase has increased by 2*Math.Pi*F, i.e. by F full circles.
|
|
|
|
|
Hi Luc,
I really need to learn this stuff for my ongoing multimedia stuff (yeah, still tweaking and improving it when time allows, the article will follow one day). I understand it all from a musicians perspective but from a coding perspective I've yet to experiment with audio but it's high on my to do list! Thanks for this little insight as it will save me some time
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Hi Dave,
if you need the basics, Wikipedia[^] is quite OK. You'll notice they use ω (omega, the angular frequency), which equals 2*pi*f.
|
|
|
|
|
Thanks, I appreciate the help.
I do understand the theory, but I think I jumped in a little too quickly.
much obliged.
V.
|
|
|
|
|
Hi All,
i am trying to create a socket connection to a server and send it a XML string and receive the results.
For some reason it does not work, here is my code:
XML String: <?xml version="1.0" encoding="UTF-8" standalone="yes"? <MemberLookupRequest><Code>XXX</Code><idNumber>XXXXXXXXXXXXX</idNumber></MemberLookupRequest>
and my socket connection code:
try
{
TcpClient socketForServer;
socketForServer = new TcpClient(xxx.xxx.xxx.xxx, 6000);
socketForServer.SendTimeout = 300000;
socketForServer.ReceiveTimeout = 300000;
NetworkStream networkStream = socketForServer.GetStream();
System.IO.StreamReader streamReader =
new System.IO.StreamReader(networkStream);
System.IO.StreamWriter streamWriter =
new System.IO.StreamWriter(networkStream);
string outputString;
// read the data from the host and display it
streamWriter.WriteLine(XML String goes here);
streamWriter.Flush();
outputString = streamReader.ReadToEnd();
networkStream.Close();
return outputString;
}
catch (Exception ex)
{
return ex.Message.ToString();
}
it shows that i am connected to the server but i don't get any results back.
can anyone please help me with this?
thanks in advance!
living life on the flip side
|
|
|
|
|
may be the server will not send data back to the client?!? this piece of code is not very helpfull for a good answer.
first your XML you want to send is corrupt! take a look at the xml-declaration >.
sencond one is that you will read data from the stream without knowing whether data is available or not ^^
use the search function to take a look at articles that work as server/client app..
|
|
|
|
|
You are asking for results immediately but results would not be available immediately. You need a read loop to get the number of bytes back you expect from the server.
|
|
|
|
|
You need to block with
networkStream.Read()
Otherwise the connection closes before you have the oportunity to read data.
See ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/fxref_system/html/b46663bf-ae16-3bd8-73c3-2d057d0868e3.htm
|
|
|
|
|
Hi All,
Thanks for the answers, will take them into account and will post my results.
living life on the flip side
|
|
|
|
|
Good Day All
i have a Function e.g
public String Getdata(String mystr)
{
}
and i want to call this function and pass data in Javascript like this
function KeyPress() {
var TExtbox1 = document.getElementById('Text1');
if (TExtbox1.value.length == 2) {
return false;
}
}
Thanks
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
|
Thanks , Now i have this
On the Server side
[WebMethod, System.Web.Script.Services.ScriptMethod]
public static string Getadata(String Data)
{
String Scriptt = "<script>alert('" + Data + "');</script>";
return Scriptt;
}
function KeyPress() {
var TExtbox1 = document.getElementById('Text1');
var Results;
if (TExtbox1.value.length == 2)
{
Results = Getadata(TExtbox1.value);
alert(Results);
}
return false;
}
and my ScriptManager
<asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server">
</asp:ScriptManager>
but when i run it nothing happens
Thanks
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
You call Getadata in your javascript. You should call PageMethods.Getadata instead.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Thanks , sorry i missed that, now i have a small problem with my javascript
<br />
function KeyPress() {<br />
<br />
<br />
var TExtbox1 = document.getElementById('Text1');<br />
var Results;<br />
if (TExtbox1.value.length == 2) {<br />
<br />
Results = PageMethods.Getadata(TExtbox1.value);<br />
alert(Results);<br />
} <br />
return false;<br />
}<br />
the alert shows me "undefined"
is there anything wrong there ?
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
That's because a script method doesn't return like this. What you need to do is supply a callback function which your javascript executes. Here's a sample page:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<script>
function keyPress()
{
var tb = document.getElementById('Text1');
if (tb.value.length == 2)
PageMethods.Getadata(tb.value, myFunction);
return false;
}
function myFunction(msg)
{
alert(msg);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True" />
<div>
<input type="text" id="Text1" onkeypress="keyPress()" />
</div>
</form>
</body>
</html>
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Good Morning Pete
Thank you for your kind reples. its working like wonders. I have one last question. as you have seen i have been using a html textbox not an asp.net textbox. i see the asp text does not have the Keypress event , Is there a way that i can modify this working code to work with asp.net textbox defined like this
<asp:TextBox ID="Text2" runat="server"></asp:TextBox>
Thanks
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
Thanks for your help , i found the solution to my last request.
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
Hi,
I need to insert a logo image in banner bitmap property while creating a setup. But from the property i couldn't find the bannerbitmap property. Can you pls help me.....
Thanks.
krishna
|
|
|
|
|
win form setup creation???? you meen wix setup or you are writing your own ?!?!? there are definalty missing information. in wix you can set the banner image using the old one by just renaming the file
|
|
|
|
|
Do you mean in a Setup project in Visual Studio?
If so, right-click the Project and select View | User Interface (or us the menu View |Editor | User Interface)
In the properties of Install | Start | Welcome, "Banner Bitmap" is at the top. Just browse for what you want to use.
|
|
|
|
|
Hi,
This is most likely a basic problem but I can't get my head around it!
I am trying to construct a parameterized sql query that takes information entered from a textbox (the search box of the query) and adds it to the query before it executes.
What I would like to do is have the user search the 'CODE' column by entering something like:
= "CO" or "SO"
and have that added to my sql query after WHERE CODE
Any help greatly appreciated!
Joe
|
|
|
|
|
Erm. AFAIK the whole point of a parameterized query was to stop this kind of design so that's not going to work.
You'd have to go back to the old skool method of generating the entire SQL statement and firing it back to your DB. I'd check if you really need to as this is horrendously insecure. Can you just not create a search stored proc and pass in a search term on that?
|
|
|
|