|
I need to develop a program that plays the signals which are arrived from an external device as follow. My problem is that there are artifacts in the onset and offset of each stream (sound.Play(data)).
what's the solution?
using System;
using System.Windows.Forms;
using Microsoft.DirectX.DirectSound;
using System.IO;
namespace TestSound
{
class CSound : Form
{
const int HEADER_SIZE = 44;
const bool FLAG_STEREO = true;
const short BITS_PER_SAMPLE = 16;
const int SAMPLE_RATE = 44100;
int numberOfSamples;
MemoryStream stream;
BinaryWriter writer;
Device ApplicationDevice = null;
SecondaryBuffer buffer = null;
BufferDescription description;
public CSound()
{
try
{
ApplicationDevice = new Device();
}
catch
{
MessageBox.Show("Unable to create sound device.");
ApplicationDevice = null;
return;
}
ApplicationDevice.SetCooperativeLevel(this, CooperativeLevel.Priority);
description = new BufferDescription();
description.ControlEffects = false;
stream = new MemoryStream();
writer = new BinaryWriter(stream);
}
private void AddHeader()
{
stream.Position = 0;
writer.Write(0x46464952);
writer.Write((int)(HEADER_SIZE + (numberOfSamples * BITS_PER_SAMPLE * (FLAG_STEREO ? 2 : 1) / 8)) - 8);
writer.Write(0x45564157);
writer.Write(0x20746d66);
writer.Write(16);
writer.Write((short)1);
writer.Write((short)(FLAG_STEREO ? 2 : 1));
writer.Write(SAMPLE_RATE);
writer.Write(SAMPLE_RATE * (FLAG_STEREO ? 2 : 1) * BITS_PER_SAMPLE / 8);
writer.Write((short)((FLAG_STEREO ? 2 : 1) * BITS_PER_SAMPLE / 8));
writer.Write(BITS_PER_SAMPLE);
writer.Write(0x61746164);
writer.Write((int)(numberOfSamples * BITS_PER_SAMPLE * (FLAG_STEREO ? 2 : 1) / 8));
}
public void Play(short[] samples)
{
if (ApplicationDevice == null)
return;
stream.Position = HEADER_SIZE;
numberOfSamples = samples.Length;
for (int i = 0; i < numberOfSamples; i++)
{
writer.Write(samples[i]);
if (FLAG_STEREO)
writer.Write(samples[i]);
}
AddHeader();
stream.Position = 0;
try
{
if (buffer != null)
{
buffer.Dispose();
buffer = null;
}
buffer = new SecondaryBuffer(stream, description, ApplicationDevice);
buffer.Play(0, BufferPlayFlags.Default);
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
}
public class Test
{
CSound sound = new CSound();
void Run()
{
short[] data;
port.Read(data);
sound.Play(data);
}
}
}
I think I should find a way to add new stream to current stream instead of destroying the current stream and creating new one(buffer.Dispose(); buffer = null; buffer = new...)
what's your suggestions?
|
|
|
|
|
Hi all,
I try to making a user control that show data from dataset, how I do for pass the dataset to any property and in other property display automaticaly all the fields of this dataset ??
Thanks in advance.
|
|
|
|
|
By implementing a DataSource propery and a DataMember property
Something like this:
private object dataSource = null;
private string dataMember = string.Empty;
[
Category("Data"),
Editor("SystemWindows.Forms.Design.DataMemberListEditor, System.Design", typeof(UITypeEditor))
]
public string DataMember
{
get
{
return this.dataMember;
}
set
{
this.dataMember = value;
}
}
[
Category("Data"),
AttributeProvider(typeof(IListSource)),
TypeConverter("System.Windows.Forms.Design.DataSourceConverter, System.Design")
]
public object DataSource
{
get
{
return this.dataSource;
}
set
{
this.dataSource = value;
}
}
It may be more complicated than this, but these are the basics. Look up any of the terms on MSDN for more detail.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I want to use taglib# in my serial id3 tagger (c) project, but I can't find out how to use/assign the taglib-libraries[^].
So where do I copy which files of the libraries and how do I assign them to my project? (as in: do I put using <k:\d\dev\taglib\taglib.h> ; in the header?)
|
|
|
|
|
pietlut wrote: So where do I copy which files of the libraries
If you want to add project to solution copy files to solution folder, or yust copy dll to your project
pietlut wrote: how do I assign them to my project? (as in: do I put using <k:\d\dev\taglib\taglib.h>; in the header?)
Absolutly not that whay. This is not C++. Yust add to solution as exsisting project, then under main projet add reference to another project. Or you can yust copy dll files to your project, add reference to it and when you will run, those dll will be automatcly copied to same folder as exe file
And then you can use: using NameOfNameSpace;
|
|
|
|
|
|
this is a little bit tricky. write a wrapper for the function, what you want to use, using C++ .NET. Create that wrapper as a .NET DLL. Then add reference from C#. But it is not so easy, it is not for beginner.
|
|
|
|
|
pietlut wrote: I assign them to my project
You would add a reference to the taglib-sharp.dll to your project.
pietlut wrote: in the header
If you are using a header file, you are asking in wrong forum.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
Help humanity, join the CodeProject grid computing team here
|
|
|
|
|
I am having a problem setting the x & y axis fontsize in MSChart. I have played with the settings through the properties window, but when I run it, nothing changes.
I can find out what the size currently is by typing:
float size = Chart1.ChartAreas["ChartArea1"].AxisX.TitleFont.SizeInPoints;
and that will bring up a size of 8. I do not know how to then set the size to something I want.
I've tried:
Chart1.ChartAreas["ChartArea1"].AxisX.TitleFont.Size.Equals(50);
which does nothing, and I've also tried
Chart1.ChartAreas["ChartArea1"].AxisX.TitleFont.SizeInPoints = 10;
which gives me an error of "Property or indexer 'System.Drawing.Font.SizeInPoints' cannot be assigned to -- it is read only"
So does anyone know what I can type to set the axis? Thanks for your help!
John Michael
|
|
|
|
|
Hi,
in .NET some properties are read-only, i.e. you can get them but not set them.
Most often then there also is a "bigger" property that can be set.
Example: Form.Width is not settable, Form.Size is settable.
In your particular case you have to set a new TitleFont.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
That makes sense, but I'm not sure how to do that b/c TitleFont is not a type. Could you give me an example?
|
|
|
|
|
Sorry no, I never used MSChart. Anyway, isn't TitleFont holding a Font instance?
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Its got a FontFamily, but once again, its a get property, does not have any set properties. I'll see if I can tinker with it some more and figure it out. Thank for your help!
JM
|
|
|
|
|
Hi,
I need to know when SetForegroundWindow return false because i try to set a form to the front using this code :
form.TopMost = true;
form.BringToFront();
bool focused = SetForegroundWindow(form.Handle);
if (!focused)
SwitchToThisWindow(form.Handle, true);
form.TopMost = false;
the form is showen but without having the focus.
best regards.
Keep it simple, stupid!
|
|
|
|
|
IIRC, SetForegroundWindow returns false if the window is not brought to the foreground. In your case, perhaps it's because your form is already at the foreground.
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
If only there would be some official documentation that holds such trivial information.
Googling for it would have taken half the keystrokes and less than 1 minute.
We prefer to help with real questions around here.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
You can also prevent other applications from stealing the focus, using TweakUI
<rant>
It's bloody annoying; you're typing merrily away, and suddenly start hearing the bleeping-sound of the computer-speaker because some programmer assumed that his application is important enough to disturb me during my work.
"Updates are available? Do you want to install/download them now?" If you must steal focus, then steal the entire screen and blink it red. It's either really important, or you behave and don't bug me at all.
</rant>
I are Troll
|
|
|
|
|
Some automation jobs may require SetForegroundWindow in order to use keyboard/mouse actions on another app. Of course this would require:
1. A user requesting it
2. A warning window telling the user he shouldn't touch anything until told otherwise.
3. The automation stuff
4. A notification to the user all is over.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Hello All,
I have created a new appdomain . Now i want to load assembly in this newly created appdomain .
I tried to do using appdomain.load().. But i got error.
can u please suggest me some code to implement the same.
Regards,
Phani
|
|
|
|
|
Hi,
what kind of error did you get? Could you post the error message and the code?
Regards
Sebastian
|
|
|
|
|
Hey Sorry ,
I got the path wrong and now fixed it out . but i have some requirement hope you can help it out.
I have dll which has 2 classes One is Employee class and other is Controller class. this class has has table which will add employee object to the hastable.
Now i have created another application , where i am going to use this DLL and i have to do this in new Appdomain .
So i want to load that dll in newly appdomain and want to creat on e mployee object and add that to list .
Can u help me out in this . I am at learning statge
|
|
|
|
|
I'm (re-) using a snippet from PIEBALDConsult, works like a charm;
name = System.IO.Path.GetFileNameWithoutExtension ( Filename ) ;
assm = System.AppDomain.CreateDomain ( name ).
Load ( System.IO.File.ReadAllBytes ( Filename ) ) ;
I are Troll
|
|
|
|
|
file namse should include path too ???
|
|
|
|
|
I triend with complete path but it is saying couldn not find the file
|
|
|
|
|
How does "Filename" look just before executing the ReadAllBytes when you put a watch on it?
BTW, this isn't a "beginners" topic, but rather somewhat "advanced"
I are Troll
|
|
|
|