|
|
|
I've try t use HttpWebRequest and HttpWebResponse to download files,but the problem is the connection speed of the network.This is my example
Assume that i have 100 files name A1,A2,A3..A100 in the same url folder http://www.myweb.com/data/
when i try to download these file i must connect to
http://www.myweb.com/data/A1
http://www.myweb.com/data/A2
.
.
.
So it has 100 connections!!!.
It's not make sense why i have to open 100 connections to download file in the same url.
Could i make just 1 connection to http://www.myweb.com/data , start download 100 files and then quit the connection? if so,how?
Thank =)
|
|
|
|
|
I'm making a program that requires you to take the sound from a microphone, change it (all it really has to do is change the pitch a little), and play it through the speakers. So...
1. How can you get the sound data from the microphone
2. How can you change the pitch (without speeding it up)
3. How can you play this changed sound data through the speakers?
I haven't found any articles yet on CodeProject or Google. Any help here?
Hippophobia - Fear of horses. What?
|
|
|
|
|
I assume you want to use human speech, or you want arbitrary sounds?
For your second question, look at phrases like speech processg, and LPC, You need some intensive processing to extract the pich and recreate the voice signal. These methods do not work for sounds in general. I don't think you will find samples on code project, you can use. Maybe the Micrososft speech processing APIs will help. (Don't know how they are colled exactly SAPI maybe?)
Rudolf Heijink
|
|
|
|
|
Not sure what arbitrary sounds are, but... Yes, it's going to be human speech mostly, but really, just any sound... I'm taking a look at SAPI right now.
See, what I'm doing is taking the sound from the microphone, changing the pitch of the incoming sound, and then (immediately) playing the altered sound through the speakers. I was thinking I would start out by just playing the sound back normally through the speakers, without alterations, like a normal microphone hooked up to some speakers.
Then, I'm going to need to know how to change the pitch of the sound and play simultaneously with the normal voice. I know that to play two sounds at once you pretty much just average the sine wavs, but I'm not sure how you would change the pitch. I was thinking that you would just increase the frequency of the wave and then increase the repetitions (so that it wouldn't come out faster), but I'm not quite sure how to do that yet...
Also, I know how a .wav file works, so I could put the sound information into that, but I have no idea how I would play it through the speakers. Is there a way to change the position of that little thing inside the speaker (don't know what it's called, but it's the thing that moves back and forth to produce the sound) to the position that you specify?
I wish I could drive...
|
|
|
|
|
Hi.
My problem is the following. I have a class that contains a "MakeByteArray" function.
I have many objects of that class. Inside that function, I have a private variable,
that is NOT static. It seems that when I put all these objects in other objects, and
then into a list, and I iterate through every object, the PRIVATE variable that i use
in "MakeByteArray" is altered depending on what the value was in the previous object.
This makes no sense since the objects don't know about each other, and the variable is
not static.
In short, the following happnes:
Print contents of object 1; object 1 has private variable "priv_var" that is a short
and has a value of "X"; correct contents printed
Print contents of object 2; object 2 has private variable "priv_var" that is a short
and has a value of "Y"; incorrect contents printed; "Y" should have been printed, but,
"Y+X" was printed instead (note that "X" is the value of "priv_var" in object 1)
OR, if I reset priv_var to 0 at end of MakeByteArray() in object 1, then sometimes the value
(0) carries over to object 2's priv_var (when it shouldn't)
How do I know that object 2's "priv_var" got the value "Y+X" from object 1, and NOT from
somewhere else? I did tests. When object 1's value changed, so did object 2's. I tried
many different (short) values, and the results were the same. However, this doesn't
happen always. I know *when* it happens, but I don't know *why*.
I this summarizes my problem, however, if you want to see more
(very long), including code, scroll down.
Oh, forgot to mention, I am using Visual Studio 2005, Windows XP, on an intel machine.
I'd appreciate any help with this.
Thank you.
-----------------------------------------------------------------------------------------------
Before you start, I apologize in advance for the formatting (or lack of) of my code.
Now, my code. This is the code for the class whose objects are put into another object.
namespace ConsoleApplication1
{
public class MyPara : MyFormat
{
public static long totalSum = 0; // public for testing purposes
protected short rc;
public MyPara()
{
/*
various variables initialized here
*/
rc = 0;
}
/*
more constructors here; all of them do rc = 0;
multiple (irrelevant) functions here as well;
*/
public bool IncRc()
{
rc++;
}
public byte[] MakeByteArray()
{
short rc2 = rc;
totalSum = totalSum + rc2;
buffer = new byte[byteLength]; // byteLength is defined in a parent class
recordCount2 = IPAddress.HostToNetworkOrder((short)(rc << 4));
byte[] temp_ba = BitConverter.GetBytes(rc2);
if ((temp_ba[0] == 0x00) && (temp_ba[1] == 0x00)) // used to check if value of '0' is present
Console.WriteLine("bad!!!!!!!!"); // code never reaches this line
System.Buffer.BlockCopy(temp_h, 0, buffer, 0, 2);
/*
copy more stuff into buffer using System.Buffer.BlockCopy here;
when done copying, return buffer;
*/
// rc = 0; <--- when this line is included, totalSum is correct, but many objects then use this value instead of their own
return (buffer);
}
}
}
Before I go onto my next class... Why do I declare another variable (rc2) that I just give the
value of rc? It was for a test. The same thing happens if i use the variable "rc" and rc2",
the results I get are identical.
now, this following class is a class whose objects "contain" the objects of the above class
(MyPara):
namespace ConsoleApplication1
{
public class MyPage : MyPageFormat
{
protected static short page_number = 0;
private List<mypara> paras;
public MyPage()
{
/*
initializes a bunch of variables
*/
paras = new List<mypara>();
}
/*
more constructors go here; all of them do paras = new List<mypara>();
multiple (irrelevant) functions here as well
*/
public bool AddPara(MyPara mp) // returns true if paragraph was added successfully, false otherwise
{
if ((byteLength + mp.ByteLength) <= maxSize) // maxSize defined through constructor or parent class
{
paras.Add(mp);
byteLength = (short)(byteLength + mp.ByteLength); // byteLength defined in parent class
page_length = page_length + mp.ByteLength; // page_length defined in parent class
return (true);
}
else
return (false);
}
public override void WriteToStream(MemoryStream ms)
{
BinaryWriter bw = new BinaryWriter(ms);
/*
write a bunch of private variables;
ex: bw.Write(var_1); bw.Write(var_2); etc.
*/
for (short z = 0; z < paras.Count; z++)
bw.Write(paras[z].MakeByteArray());
ms.Position = 0;
}
}
}
This class basically contains objects that are of type MyPara. As you can see, we can either
write the paragraph to a byte array (using MyPara's MakeByteArray()) or we can write the
whole page to a stream (using MyPage's WriteToStream which calls each MyPara's MakeByteArray()).
Now, the class that does stuff with the above classes:
namespace ConsoleApplication1
{
public class ppTest
{
/*
constructors go here;
various other functions here as well;
*/
public void TestSchedulePP()
{
List<mypage> pages = new List<mypage>();
/*
code to 'fill' pages list goes here;
pages contain multiple 'paragraphs';
IMPORTANT: At this point, before putting paragraphs
into pages, each paragraph's private rc variable was
checked and it DID have the CORRECT value
*/
//pages are now 'filled' with 'paragraphs'
//write them to a file
ToFile<mypage>(pages);
}
public void ToFile<e>(List<e> pages) where E : MyPageFormat // MyPageFormat is parent class of MyPage listed above
{
byte[] barray;
FileStream fs = new FileStream("mypages.bin", FileMode.Append);
MemoryStream ms;
BinaryWriter bw = new BinaryWriter(sp);
for (int e = 0; e < pages.Count; e++)
{
ms = new MemoryStream();
pages[e].WriteToStream(ms);
barray = new byte[ms.Length];
ms.Read(barray, 0, barray.Length);
bw.Write(barray);
ms.Flush();
ms.Close();
barray = null;
}
bw.Close();
sp.Close();
}
}
}
The first function basically "fills" my list of pages, and then calls ToFile which prints the
contents of the list (all pages including all paragraphs).
Finally, my main program code:
ppTest pp = new ppTest();
pp.TestSchedulePP();
So, after all that, the flow looks like this:
Main program --> TestSchedulePP() in ppTest --> ToFile() in ppTest --> WriteToStream() in MyPage --> MakeByteArray() in MyPara
I have ensured that after I fill my pages, I NEVER call IncRc(). In other words, between each
WriteToStream() call (or each MakeByteArray() call), I DO NOT call IncRc at all. The last IncRc() call occurs BEFORE the pages are "filled" with paragraphs.
To reiterate my question, the problem value/variable is in MyPara. "rc" should NEVER have the value of the previous object, but sometimes, it does! I don't understand how a bunch of objects of MyPara that are in an object of MyPage can know about each other, and use each other's values.
So when I am going through the loop in MyPage (in WriteToStream()), I call each MyPara's MakeByteArray(), but why would one have the value of the previous one? For example, how can the rc var in paras[z].ToByteArray() have the same value as paras[z+1].ToByteArray() ??? I realise that if it happens that BOTH paragraphs had the same number of IncRc() calls, the rc value will be the same, but they don't. In fact, I check all the rc values (of each paragraph) before putting them in pages and they are ALL correct. So how does the rc value of object 1 get into the rc of object 2??????
Two things to add: I know "rc" is a 16-bit number and I am shifting it by 4 bits. I never increment rc past a 12-bit number (checked) so thats ok. Also, if you look at the last commented line in MakeByteArray() in MyPara, when it is uncommented the totalSum is correct, but many paragraphs have rc = 0 which should never happen. When the line is left commented, like in my example above, no paragraphs have rc = 0 (which is correct), but totalSum is wrong.
I am sorry that this was very long winded.
As I said above, I would appreciate any assistance with this problem.
Thank you.
-- modified at 12:02 Tuesday 11th September, 2007
|
|
|
|
|
I would like to know how to create a mp3 scratching program like dj's do with vinyl.
I'm using Visual C# 2005 with DirectX to write the program
I have an idea, like taking the buffer and flipping it back
and forth and changing the frequency speed according to the mouse.
Please help...
Thank You
-- modified at 18:55 Monday 10th September, 2007
|
|
|
|
|
Try look at the fmod [fmodex] library, i think it could be used in C# too.
Or use C++ to code stuff you want FMod have a lot of DSP effects aso; you can write plugins for it....
VirtualVoid.NET
|
|
|
|
|
Weird... unless I'm not understanding something about Regions.
I build an array of Region objects (constructed from GraphicsPath objects). When I access any array element (to set the Region property of a control), it works fine the first time, but if I try to access that same element a second time, it gives me an Invalid Parameter exception. It's as if the array is read-once.
I work around this by saving an array of RegionData objects, and constructing Regions on-the-fly from elements of this array. Clutzy at best.
Does anyone have any insight on what is going on? (Or what I'm doing wrong?)
Thanks!
Tom
-- modified at 17:36 Monday 10th September, 2007
|
|
|
|
|
Have you tried debugging? Perhaps you should post some code.
|
|
|
|
|
Here's a simple project with a form having one button, and a UserControl.
Initially, control looks like a blue circle (as expected).
Click the button, sets currRegionIndex to 1, and the control is a blue square (as expected).
Click the button again sets currRegionIndex back to 0, and ArgumentException ("Parameter is not valid") results. Weird, huh?
-------------------------------------
// Form1.cs
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace RegionTest
{
public partial class Form1 : Form
{
private Region[] region = new Region[2];
private int currRegionIndex = 1;
private MyControl myControl = new MyControl();
public Form1()
{
InitializeComponent();
GraphicsPath gp0 = new GraphicsPath();
gp0.AddEllipse(myControl.ClientRectangle);
region[0] = new Region(gp0);
GraphicsPath gp1 = new GraphicsPath();
gp1.AddRectangle(myControl.ClientRectangle);
region[1] = new Region(gp1);
myControl.Region = region[1];
Controls.Add(myControl);
}
private void button1_Click(object sender, EventArgs e)
{
currRegionIndex = (currRegionIndex + 1) % 2;
myControl.Region = region[currRegionIndex];
myControl.Refresh();
}
}
}
-------------------------------------
// Mycontrol.cs
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace RegionTest
{
public partial class MyControl : UserControl
{
public MyControl()
{
InitializeComponent();
BackColor = Color.Blue;
}
}
}
------------------------------------------------------
Incidentally, I'm using VS2005
Thanks for your help,
Tom
-- modified at 18:33 Monday 10th September, 2007
|
|
|
|
|
A little smart debugging and a glance in Reflector exposes the problem.
If you place a breakpoint at this line:
myControl.Region = region[currRegionIndex];
and examine the region array, each Region object has a Non-Public member called "nativeRegion". This is an IntPtr handle to a Win32 Rgn object. The first time you use the region, that IntPtr value is not zero - that is, item != IntPtr.Zero. Once you assign the region to the control, that same value becomes 0.
Looking at the code for Control.Region in Reflector exposes why:
IntPtr zero = IntPtr.Zero;
try
{
if (value != null)
{
zero = this.GetHRgn(value);
}
if (this.IsActiveX)
{
zero = this.ActiveXMergeRegion(zero);
}
if (UnsafeNativeMethods.SetWindowRgn(new HandleRef(this, this.Handle), new HandleRef(this, zero), SafeNativeMethods.IsWindowVisible(new HandleRef(this, this.Handle))) != 0)
{
zero = IntPtr.Zero;
}
}
finally
{
if (zero != IntPtr.Zero)
{
SafeNativeMethods.DeleteObject(new HandleRef(null, zero));
}
}
You see what's going on. The region is being deleted once it is used successfully.
The solution, then, is to assign a copy of each region instead, using the Region.Clone method:
<code> public Form1()
{
InitializeComponent();
GraphicsPath gp0 = new GraphicsPath();
gp0.AddEllipse(myControl.ClientRectangle);
region[0] = new Region(gp0);
GraphicsPath gp1 = new GraphicsPath();
gp1.AddRectangle(myControl.ClientRectangle);
region[1] = new Region(gp1);
myControl.Region = region[1].Clone();
Controls.Add(myControl);
}
private void button1_Click(object sender, EventArgs e)
{
currRegionIndex = (currRegionIndex + 1) % 2;
myControl.Region = region[currRegionIndex].Clone();
myControl.Refresh();
}</code>
|
|
|
|
|
Wow... thanks, Patrick.
Hmm, this is not the behaviour one would expect, but who
says life should be predictable .
My workaround was:
-----------------------------
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace RegionTest
{
public partial class Form1 : Form
{
RegionData[] regionData = new RegionData[2];
int currRegionIndex = 0;
MyControl myControl = new MyControl();
public Form1()
{
InitializeComponent();
GraphicsPath gp0 = new GraphicsPath();
gp0.AddEllipse(myControl.ClientRectangle);
regionData[0] = (new Region(gp0)).GetRegionData();
GraphicsPath gp1 = new GraphicsPath();
gp1.AddRectangle(myControl.ClientRectangle);
regionData[1] = (new Region(gp1)).GetRegionData();
myControl.Region = new Region(region[0]);
Controls.Add(myControl);
}
private void button1_Click(object sender, EventArgs e)
{
currRegionIndex = (currRegionIndex + 1) % 2;
myControl.Region = new Region(regionData[currRegionIndex]);
myControl.Refresh();
}
}
}
-----------------------------
which in the end is similar to yours in efficiency (I guess)
but yours is more elegant.
Tom
|
|
|
|
|
hi all,
am getting a stange problem. from a call back function, am calling a MODELESS dialog,(when timeout reached for my dialog), but it's creating as a modal dialog... it's not my requirement. i've develop a sample,i think, it's created on a different thread than main thread. (may be.. not sure.).... please provide any commentsa nad solution.. please...
my code:(design form not included)
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading;
namespace TimeoutWindow
{
public partial class TimeoutForm : Form
{
private System.Threading.Timer m_Timer = null;
private const int WH_KEYBOARD = 2;
private const int WH_MOUSE = 7;
private LowLevelKeyboardProc _procKey = KeyHookCallback;
private LowLevelKeyboardProc _prockMouse = MouseHookCallBack;
private static IntPtr _hookIDKey = IntPtr.Zero;
private static IntPtr _hookIDMouse = IntPtr.Zero;
private static UInt32 m_LastHitTime = 0;
private System.Threading.TimerCallback timerCallBack = null;
private AutoResetEvent autoEvent = null;
private Form2 dlg;
private delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam);
public TimeoutForm()
{
InitializeComponent();
_hookIDKey = SetWindowsHookEx(WH_KEYBOARD,_procKey,(IntPtr)0,(uint)AppDomain.GetCurrentThreadId());
_hookIDMouse = SetWindowsHookEx(WH_MOUSE,_procKey,(IntPtr)0,(uint)AppDomain.GetCurrentThreadId());
timerCallBack = new System.Threading.TimerCallback(this.CheckTimeout);
autoEvent = new AutoResetEvent(false);
m_LastHitTime = GetTickCount();
m_Timer = new System.Threading.Timer(timerCallBack, autoEvent, 20000, 20000);
}
private void OnTryLogin(object sender, EventArgs e)
{
MessageBox.Show("HI");
Form2 dlg = new Form2();
dlg.ShowDialog();
}
public void CheckTimeout(Object stateInfo)
{
autoEvent = (AutoResetEvent)stateInfo;
UInt32 curTime = GetTickCount();
if (curTime - m_LastHitTime > 2000)
{
this.m_Timer.Dispose();
try
{
this.dlg = new Form2();
if (dlg != null)
{
//problem occuring here................
this.dlg.ShowDialog(); /// creating modal dialog.
m_LastHitTime = GetTickCount();
m_Timer = new System.Threading.Timer(timerCallBack, autoEvent,2000,2000);
}
else
System.Windows.Forms.MessageBox.Show("NULL");
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
}
#region dllimport
[System.Runtime.InteropServices.DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId);
[System.Runtime.InteropServices.DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool UnhookWindowsHookEx(IntPtr hhk);
[System.Runtime.InteropServices.DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);
[System.Runtime.InteropServices.DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr GetModuleHandle(string lpModuleName);
[System.Runtime.InteropServices.DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern System.UInt32 GetTickCount();
#endregion
private static IntPtr KeyHookCallback(int nCode, IntPtr wParam, IntPtr lParam)
{
if (nCode < 0)
return CallNextHookEx(_hookIDKey, nCode, wParam, lParam);
else
{
m_LastHitTime = GetTickCount();
return CallNextHookEx(_hookIDKey, nCode, wParam, lParam);
}
}
private static IntPtr MouseHookCallBack(int nCode, IntPtr wParam, IntPtr lParam)
{
if (nCode < 0)
return CallNextHookEx(_hookIDMouse, nCode, wParam, lParam);
else
{
m_LastHitTime = GetTickCount();
return CallNextHookEx(_hookIDMouse, nCode, wParam, lParam);
}
}
private void OnCloseForm1(object sender, FormClosedEventArgs e)
{
UnhookWindowsHookEx(_hookIDKey);
UnhookWindowsHookEx(_hookIDMouse);
}
}
}
-- modified at 15:56 Monday 10th September, 2007
kamalesh
|
|
|
|
|
kamalesh82 wrote: am calling a modal dialog,(when timeout reached for my dialog), but it's creating as a modal dialog
If you don't want a modal dialog, then call Show instead of ShowDialog. Or, have I missed what the problem is ?
Christian Graus - Microsoft MVP - C++
"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 )
|
|
|
|
|
sorry for the typing mistake,... i neead modal, but it's creating modeless... .
kamalesh
|
|
|
|
|
OK, perhaps you're right, you're on another thread, and that is the problem.
Christian Graus - Microsoft MVP - C++
"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 )
|
|
|
|
|
Hi, In my game that I'm making I have a 2D Array of Picture boxes. Using a function:
<br />
<br />
image_arr[0] = Bulldozer_2._0.Properties.Resources.empty;
image_arr[1] = Bulldozer_2._0.Properties.Resources.wall;<br />
image_arr[2] = Bulldozer_2._0.Properties.Resources.target;<br />
image_arr[3] = Bulldozer_2._0.Properties.Resources.rock;<br />
image_arr[4] = Bulldozer_2._0.Properties.Resources.target_w_rock;<br />
image_arr[5] = Bulldozer_2._0.Properties.Resources.bulldozer_down;<br />
image_arr[6] = Bulldozer_2._0.Properties.Resources.bulldozer_up;<br />
image_arr[7] = Bulldozer_2._0.Properties.Resources.bulldozer_left;<br />
image_arr[8] = Bulldozer_2._0.Properties.Resources.bulldozer_right;<br />
<br />
const Byte IMAGE_WIDTH = 32;<br />
const Byte IMAGE_HEIGHT = 32;<br />
<br />
PictureBox[,] PicBoxes = new PictureBox[MAX_ROWS, MAX_COLS];<br />
<br />
private void draw_image(Byte type, int row, int col)<br />
{<br />
PicBoxes[row, col] = new PictureBox();<br />
PicBoxes[row, col].Name = "pictureBox1";<br />
PicBoxes[row, col].Size = new System.Drawing.Size(IMAGE_WIDTH, IMAGE_HEIGHT);<br />
PicBoxes[row, col].Image = image_arr[type];<br />
PicBoxes[row, col].Location = new System.Drawing.Point(col * IMAGE_WIDTH, row * IMAGE_HEIGHT);<br />
}<br />
<br />
Got any ideas why the image isn't showing up? The Images are there and in the resources folder.
|
|
|
|
|
in draw_image add it to form controls
Form.Controls.Add()
|
|
|
|
|
I typed Form but there was no "Controls" sub program.
|
|
|
|
|
Form is the name of the class. You need the name of the form itself, which you did not provide. Actually, you need to replace Form with this, as you're inside the form.
Christian Graus - Microsoft MVP - C++
"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 partly understood what you meant so I put "PicBoxes[row, col].Controls.Add();" but I don't know what to put for Parameters.
|
|
|
|
|
Controls is not a program but member collection.
As I have written before - formName.Collection.Add()
Collection is without ()
|
|
|
|
|
I'm not too familiar with object oriented programming. I'm used to C++ and PHP. I kinda figured out through trial and error but what do I put for the parameter for Add ()?
|
|
|
|
|