Click here to Skip to main content
15,919,245 members
Home / Discussions / C#
   

C#

 
GeneralRe: Sending a connection to another computer in a PEER TO PEER network Pin
CoderForEver21-Aug-09 6:21
CoderForEver21-Aug-09 6:21 
GeneralRe: Sending a connection to another computer in a PEER TO PEER network Pin
Richard MacCutchan25-Aug-09 10:34
mveRichard MacCutchan25-Aug-09 10:34 
GeneralRe: Sending a connection to another computer in a PEER TO PEER network Pin
CoderForEver26-Aug-09 1:56
CoderForEver26-Aug-09 1:56 
GeneralRe: Sending a connection to another computer in a PEER TO PEER network Pin
Richard MacCutchan26-Aug-09 3:12
mveRichard MacCutchan26-Aug-09 3:12 
GeneralRe: Sending a connection to another computer in a PEER TO PEER network Pin
CoderForEver26-Aug-09 3:40
CoderForEver26-Aug-09 3:40 
GeneralRe: Sending a connection to another computer in a PEER TO PEER network Pin
Richard MacCutchan26-Aug-09 6:21
mveRichard MacCutchan26-Aug-09 6:21 
GeneralRe: Sending a connection to another computer in a PEER TO PEER network Pin
CoderForEver26-Aug-09 10:35
CoderForEver26-Aug-09 10:35 
GeneralRe: Sending a connection to another computer in a PEER TO PEER network Pin
Richard MacCutchan26-Aug-09 21:23
mveRichard MacCutchan26-Aug-09 21:23 
QuestionHow do you compile code from notepad? Pin
Nathan Revka20-Aug-09 9:27
Nathan Revka20-Aug-09 9:27 
AnswerRe: How do you compile code from notepad? Pin
Pete O'Hanlon20-Aug-09 9:34
mvePete O'Hanlon20-Aug-09 9:34 
AnswerRe: How do you compile code from notepad? Pin
Christian Graus20-Aug-09 11:44
protectorChristian Graus20-Aug-09 11:44 
GeneralRe: How do you compile code from notepad? Pin
PIEBALDconsult20-Aug-09 12:55
mvePIEBALDconsult20-Aug-09 12:55 
AnswerRe: How do you compile code from notepad? Pin
PIEBALDconsult20-Aug-09 12:54
mvePIEBALDconsult20-Aug-09 12:54 
AnswerRe: How do you compile code from notepad? Pin
Natural_Demon20-Aug-09 14:14
Natural_Demon20-Aug-09 14:14 
AnswerRe: How do you compile code from notepad? Pin
darkelv20-Aug-09 15:38
darkelv20-Aug-09 15:38 
GeneralRe: How do you compile code from notepad? Pin
dan!sh 20-Aug-09 18:49
professional dan!sh 20-Aug-09 18:49 
AnswerRe: How do you compile code from notepad? Pin
Richard MacCutchan25-Aug-09 10:38
mveRichard MacCutchan25-Aug-09 10:38 
QuestionProblem with play real-time audio signals Pin
hossein khatoonabadi20-Aug-09 9:25
hossein khatoonabadi20-Aug-09 9:25 
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); // "RIFF" in ASCII
            writer.Write((int)(HEADER_SIZE + (numberOfSamples * BITS_PER_SAMPLE * (FLAG_STEREO ? 2 : 1) / 8)) - 8);
            writer.Write(0x45564157); // "WAVE" in ASCII
            writer.Write(0x20746d66); // "fmt " in ASCII
            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); // "data" in ASCII
            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?
QuestionUser Control: Property use Pin
favianq20-Aug-09 9:22
favianq20-Aug-09 9:22 
AnswerRe: User Control: Property use Pin
Henry Minute20-Aug-09 11:48
Henry Minute20-Aug-09 11:48 
QuestionHow do I use external libraries in my project? (using <taglib>)</taglib> Pin
pietlut20-Aug-09 6:35
pietlut20-Aug-09 6:35 
AnswerRe: How do I use external libraries in my project? (using ) Pin
Saksida Bojan20-Aug-09 7:26
Saksida Bojan20-Aug-09 7:26 
AnswerRe: How do I use external libraries in my project? (using ) Pin
PIEBALDconsult20-Aug-09 7:57
mvePIEBALDconsult20-Aug-09 7:57 
AnswerRe: How do I use external libraries in my project? (using ) Pin
stancrm20-Aug-09 8:10
stancrm20-Aug-09 8:10 
AnswerRe: How do I use external libraries in my project? (using ) Pin
Wes Aday20-Aug-09 9:24
professionalWes Aday20-Aug-09 9:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.