|
Hi,
HOw can i insert a image to toolstrip using c#....through property i can do....i need to do through code.
Thanks.
krishna
|
|
|
|
|
toolStripButton2.Image = new Bitmap(fileName);
Or you can embed an image in your assembly and load it using the Manifest resource stream
toolStripButton2.Image = new Bitmap(GetType().Assembly.GetManifestResourceStream("assembly.name.image.name");
|
|
|
|
|
Hi,
Can you send an example code for the same....
Thanks
krishna
|
|
|
|
|
Dear Friends,
We have to get information of gsm connection level in c# (or vb) in windows mobile device
Is there anyway ?
Thanks in advance
|
|
|
|
|
I'm trying to produce a constant sound in a WAVE file.
Using this function (byte)(256 * Math.Sin(frequency * i)); it works and the WAV file correctly created, but it sounds like very bad quality. I tested it against the Beep function and the pitch seems the same.
If I remove the frequency variable from the function, the "quality" of the WAV is far better.
Did I do something wrong or is there a way to clean up the 'noise'?
(to create the file I used a pretty straightforward open source library that I found, which generally creates a header and a byte array and writes that to file)
thanks.
(I'm probably overlooking something very simple )
V.
|
|
|
|
|
I guess the cast to byte makes a problem - isn't 8bit mono sound written as unsigned bytes? Try 16bit sound, that's (signed) Int16.
|
|
|
|
|
It's all 16 bit sound, all info past as int . Why do you think it's 8 bit? I at least defined it as stereo, 16 bit, 44100KHz sample rate.
I tried to inverse the frequency (1/freq) which seems to clean up the noise, yet it remains dirty. (other frequency tests show that I at least have to inverse the freq, else the pitch is not the same at all)
thanks for the idea.
V.
|
|
|
|
|
V. wrote: Why do you think it's 8 bit?
Well the byte cast in your OP was a clue:
(byte)(256 * Math.Sin(frequency * i));
That may be your problem - if it is byte data you are handing to a function expecting 16 bit then it could go all odd...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
MMM, I don't think so, the entire thing is written to file as a byte array (logical, it's a binary file , but only when all else is set.
Here's the code:
public void PlayNoteWav(string note, int position)
{
Dictionary<int, double> played_note = guitar_strings[note];
if (position >= 0)
{
double frequency = played_note[position];
CreateWaveFile(frequency, duration);
}
else
{
System.Threading.Thread.Sleep(duration);
}
}
public void CreateWaveFile(double frequency, int duration)
{
bool whiteNoise = false;
Random rand = new Random();
file = new WaveFile(2, 16, 44100);
int samples = 44100;
byte[] data = new byte[file.NumChannels * (file.BitsPerSample / 8) * samples];
if (whiteNoise)
{
for (int i = 0; i < data.Length; i++)
{
data[i] = (byte)rand.Next(256);
}
}
else
{
for (int i = 0; i < data.Length; i++)
{
data[i] = (byte)(256 * Math.Sin(1/frequency * i));
}
}
file.SetData(data, samples);
file.WriteFile(@"C:\Test.wav");
}
Generally in the background it will hold all the information before writing to file.
Doesn't this statement:
byte[] data = new byte[file.NumChannels * (file.BitsPerSample / 8) * samples];<br /> take in account 16 bit sound (if bitspersample is set to 16) ?
In any case I'll have a go with setting to 8 bits mono, just for testing.
thanks.
V.
|
|
|
|
|
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
|
|
|
|