Click here to Skip to main content
15,915,750 members
Home / Discussions / C#
   

C#

 
QuestionSmsSendMessage still working when mobile have no balance. Pin
Le@rner18-Aug-09 20:36
Le@rner18-Aug-09 20:36 
AnswerRe: SmsSendMessage still working when mobile have no balance. Pin
Christian Graus18-Aug-09 21:08
protectorChristian Graus18-Aug-09 21:08 
GeneralRe: SmsSendMessage still working when mobile have no balance. Pin
Le@rner18-Aug-09 21:40
Le@rner18-Aug-09 21:40 
GeneralRe: SmsSendMessage still working when mobile have no balance. Pin
Christian Graus18-Aug-09 23:23
protectorChristian Graus18-Aug-09 23:23 
GeneralRe: SmsSendMessage still working when mobile have no balance. Pin
Le@rner18-Aug-09 23:27
Le@rner18-Aug-09 23:27 
Questionconnecting to Telnet [modified] Pin
treuveni18-Aug-09 20:30
treuveni18-Aug-09 20:30 
AnswerRe: connecting to Telnet Pin
treuveni18-Aug-09 23:08
treuveni18-Aug-09 23:08 
Questiononline audio stream Pin
hossein khatoonabadi18-Aug-09 19:28
hossein khatoonabadi18-Aug-09 19:28 
Dear All,
I need to develop a program that gets signals continuously and then play them. So I play audio streams in 100ms periods. My problem is that there is an undesired sound in the onset and offset of each stream. For example I write a program which plays an audio stream with constant values as follow, but it makes a noisy sound instead of constant sound.
What's the problem? and 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);
            }
        }

        static short[] samples = new short[4410]; // 100 ms
        static CSound sound;

        static void Main()
        {
            Form form = new Form();
            form.Show();

            sound = new CSound();
            Random random = new Random();
            for (int i = 0; i < samples.Length; i++)
                samples[i] = 1000; // constant value

            while (true)
            {
                sound.Play(samples);
                System.Threading.Thread.Sleep(100); // 100 ms
            }
        }
     }
}

QuestionGraphic Problem [modified] Pin
Reza Shojaee18-Aug-09 18:54
Reza Shojaee18-Aug-09 18:54 
AnswerRe: Graphic Problem Pin
Christian Graus18-Aug-09 19:29
protectorChristian Graus18-Aug-09 19:29 
Questionprocess words in c# Pin
prasadbuddhika18-Aug-09 18:40
prasadbuddhika18-Aug-09 18:40 
AnswerRe: process words in c# Pin
Christian Graus18-Aug-09 19:29
protectorChristian Graus18-Aug-09 19:29 
GeneralRe: process words in c# Pin
prasadbuddhika18-Aug-09 20:09
prasadbuddhika18-Aug-09 20:09 
AnswerRe: process words in c# Pin
dan!sh 18-Aug-09 19:42
professional dan!sh 18-Aug-09 19:42 
GeneralRe: process words in c# Pin
prasadbuddhika18-Aug-09 19:59
prasadbuddhika18-Aug-09 19:59 
GeneralRe: process words in c# Pin
Christian Graus18-Aug-09 21:10
protectorChristian Graus18-Aug-09 21:10 
GeneralRe: process words in c# Pin
dan!sh 18-Aug-09 21:55
professional dan!sh 18-Aug-09 21:55 
QuestionToolStripControlHost full backcolor Pin
Xmen Real 18-Aug-09 18:07
professional Xmen Real 18-Aug-09 18:07 
QuestionLimit size of text file (LIFO) Pin
Maddie from Dartford18-Aug-09 16:58
Maddie from Dartford18-Aug-09 16:58 
AnswerRe: Limit size of text file (LIFO) Pin
Mycroft Holmes18-Aug-09 17:05
professionalMycroft Holmes18-Aug-09 17:05 
GeneralRe: Limit size of text file (LIFO) Pin
Maddie from Dartford18-Aug-09 17:37
Maddie from Dartford18-Aug-09 17:37 
GeneralRe: Limit size of text file (LIFO) Pin
Mycroft Holmes18-Aug-09 18:03
professionalMycroft Holmes18-Aug-09 18:03 
AnswerRe: Limit size of text file (LIFO) Pin
N a v a n e e t h18-Aug-09 18:35
N a v a n e e t h18-Aug-09 18:35 
GeneralRe: Limit size of text file (LIFO) Pin
Maddie from Dartford18-Aug-09 19:07
Maddie from Dartford18-Aug-09 19:07 
GeneralRe: Limit size of text file (LIFO) Pin
Saksida Bojan18-Aug-09 20:49
Saksida Bojan18-Aug-09 20:49 

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.