Exemple #1
0
        public MemoryStream GetMemoryStreamFromNewMessage(EASMessage message, bool ebsTone,
                                                          bool nwsTone, byte[] announcementStream)
        {
            WaveFormat waveFormat = new WaveFormat(44100, 16, 2);

            return(GetMemoryStreamFromNewMessage(message, ebsTone, nwsTone, announcementStream, waveFormat));
        }
Exemple #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (player != null)
            {
                player.Stop();
                return;
            }

            if (!ValidateInput())
            {
                return;
            }

            _start    = dateStart.Value.ToUniversalTime();
            _senderId = txtSender.Text;
            _length   = ZeroPad(comboLengthHour.Text, 2) + ZeroPad(comboLengthMinutes.Text, 2);

            var newMessage = new EASMessage(_selectedOriginator.Id, _selectedAlertCode.Id,
                                            Regions, _length, _start, _senderId);


            var messageStream = EASEncoder.EASEncoder.GetMemoryStreamFromNewMessage(newMessage, chkEbsTones.Checked,
                                                                                    chkNwsTone.Checked, formatAnnouncement(txtAnnouncement.Text));

            btnGeneratePlay.Text = "Stop Playing";
            WaveStream mainOutputStream = new RawSourceWaveStream(messageStream, new WaveFormat());
            var        volumeStream     = new WaveChannel32(mainOutputStream);

            volumeStream.PadWithZeroes = false;

            player = new WaveOutEvent();
            player.PlaybackStopped += (o, args) =>
            {
                player.Dispose();
                player = null;
                btnGeneratePlay.Text = "Generate && Play";
            };

            player.Init(volumeStream);

            player.Play();
        }
Exemple #3
0
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            if (!ValidateInput())
            {
                return;
            }
            _start    = dateStart.Value.ToUniversalTime();
            _senderId = txtSender.Text;
            _length   = ZeroPad(comboLengthHour.Text, 2) + ZeroPad(comboLengthMinutes.Text, 2);

            var newMessage = new EASMessage(_selectedOriginator.Id, _selectedAlertCode.Id,
                                            Regions, _length, _start, _senderId);

            if (String.IsNullOrEmpty(txtOutputFile.Text))
            {
                MessageBox.Show("You must enter a valid output file name for the EAS audio message.", "Unable to create EAS Message", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            EASEncoder.EASEncoder.CreateNewMessage(newMessage, chkEbsTones.Checked, chkNwsTone.Checked,
                                                   formatAnnouncement(txtAnnouncement.Text));
        }
Exemple #4
0
        public static void CreateNewMessage(EASMessage message, bool ebsTone = true, bool nwsTone = false,
                                            string announcement = "", string filename             = "")
        {
            //headerByteCache = new Dictionary<decimal, List<int>>();
            _useEbsTone   = ebsTone;
            _useNwsTone   = nwsTone;
            _announcement = announcement;

            _headerSamples = new int[0];
            var byteArray = Encoding.Default.GetBytes(message.ToSameHeaderString());
            var volume    = 5000;

            var          byteSpec = new List <SameWavBit>();
            byte         thisByte;
            SAMEAudioBit thisBit;

            for (var i = 0; i < byteArray.Length; i++)
            {
                thisByte = byteArray[i];

                for (var e = 0; e < 8; e++)
                {
                    thisBit = ((thisByte & (short)Math.Pow(2, e)) != 0 ? Mark : Space);
                    byteSpec.Add(new SameWavBit(thisBit.frequency, thisBit.length, volume));
                }
            }

            foreach (var currentSpec in byteSpec)
            {
                int[] returnedBytes = RenderTone(currentSpec);
                int[] c             = new int[_headerSamples.Length + returnedBytes.Length];
                Array.Copy(_headerSamples, 0, c, 0, _headerSamples.Length);
                Array.Copy(returnedBytes, 0, c, _headerSamples.Length, returnedBytes.Length);

                _headerSamples = c;
            }

            _eomSamples = new int[0];
            byteArray   = Encoding.Default.GetBytes(message.ToSameEndOfMessageString());
            volume      = 5000;

            byteSpec = new List <SameWavBit>();

            foreach (var t in byteArray)
            {
                thisByte = t;

                for (var e = 0; e < 8; e++)
                {
                    thisBit = ((thisByte & (short)Math.Pow(2, e)) != 0 ? Mark : Space);
                    byteSpec.Add(new SameWavBit(thisBit.frequency, thisBit.length, volume));
                }
            }

            foreach (var currentSpec in byteSpec)
            {
                int[] returnedBytes = RenderTone(currentSpec);
                int[] c             = new int[_eomSamples.Length + returnedBytes.Length];
                Array.Copy(_eomSamples, 0, c, 0, _eomSamples.Length);
                Array.Copy(returnedBytes, 0, c, _eomSamples.Length, returnedBytes.Length);
                _eomSamples = c;
            }

            //1 second silence
            _silenceSamples = new List <int>();
            while (_silenceSamples.Count < 176400)
            {
                _silenceSamples.Add(0);
            }

            _ebsTonesStream = GenerateEbsTones();
            _ebsToneSamples = _ebsTonesStream.Length;

            _nwsTonesStream = GenerateNwsTones();
            _nwstoneSamples = _nwsTonesStream.Length;

            _totalSamples = (TotalHeaderSamples * 3) + (totalSilenceSamples * 7) + (TotalEomSamples * 3) + (_ebsToneSamples * 8) +
                            (_nwstoneSamples * 8);

            _announcementStream =
                GenerateVoiceAnnouncement(announcement);
            _announcementSamples = _announcementStream.Length;

            GenerateWavFile(filename);
            GenerateMp3File(filename);
        }
Exemple #5
0
 public MemoryStream GetMemoryStreamFromNewMessage(EASMessage message, bool ebsTone = true,
                                                   bool nwsTone = false, string announcement = "")
 {
     _announcement = announcement;
     return(GetMemoryStreamFromNewMessage(message, ebsTone, nwsTone, GenerateVoiceAnnouncement(announcement)));
 }
Exemple #6
0
        public MemoryStream GetMemoryStreamFromNewMessage(EASMessage message, bool ebsTone,
                                                          bool nwsTone, byte[] announcementStream, bool eom)

        {
            _useEbsTone = ebsTone;
            _useNwsTone = nwsTone;
            _useEOM     = eom;

            _headerSamples = new int[0];
            var byteArray = Encoding.Default.GetBytes(message.ToSameHeaderString());
            var volume    = 5000;

            var          byteSpec = new List <SameWavBit>();
            byte         thisByte;
            SAMEAudioBit thisBit;

            //TODO: Extremely slow - fix!
            foreach (var t in byteArray)
            {
                thisByte = t;

                for (var e = 0; e < 8; e++)
                {
                    thisBit = ((thisByte & (short)Math.Pow(2, e)) != 0 ? Mark : Space);
                    byteSpec.Add(new SameWavBit(thisBit.frequency, thisBit.length, (int)(volume * thisBit.level)));
                }
            }

            foreach (var currentSpec in byteSpec)
            {
                int[] returnedBytes = RenderTone(currentSpec);
                int[] c             = new int[_headerSamples.Length + returnedBytes.Length];
                Array.Copy(_headerSamples, 0, c, 0, _headerSamples.Length);
                Array.Copy(returnedBytes, 0, c, _headerSamples.Length, returnedBytes.Length);

                _headerSamples = c;
            }

            _eomSamples = new int[0];
            if (_useEOM)
            {
                byteArray = Encoding.Default.GetBytes(message.ToSameEndOfMessageString());
                volume    = 5000;

                byteSpec = new List <SameWavBit>();

                foreach (var t in byteArray)
                {
                    thisByte = t;

                    for (var e = 0; e < 8; e++)
                    {
                        thisBit = ((thisByte & (short)Math.Pow(2, e)) != 0 ? Mark : Space);
                        byteSpec.Add(new SameWavBit(thisBit.frequency, thisBit.length, (int)(volume * thisBit.level)));
                    }
                }

                foreach (var currentSpec in byteSpec)
                {
                    int[] returnedBytes = RenderTone(currentSpec);
                    int[] c             = new int[_eomSamples.Length + returnedBytes.Length];
                    Array.Copy(_eomSamples, 0, c, 0, _eomSamples.Length);
                    Array.Copy(returnedBytes, 0, c, _eomSamples.Length, returnedBytes.Length);
                    _eomSamples = c;
                }
            }


            //1 second silence
            _silenceSamples = new List <int>();
            while (_silenceSamples.Count < totalSilenceSamples)
            {
                _silenceSamples.Add(0);
            }

            _ebsTonesStream = GenerateEbsTones();
            _ebsToneSamples = _ebsTonesStream.Length;

            _nwsTonesStream = GenerateNwsTones();
            _nwstoneSamples = _nwsTonesStream.Length;

            _totalSamples = (TotalHeaderSamples * 3) + (totalSilenceSamples * 7) + (TotalEomSamples * 3) + (_ebsToneSamples * 8) +
                            (_nwstoneSamples * 8);

            _announcementStream =
                announcementStream;
            _announcementSamples = _announcementStream.Length;

            return(GenerateMemoryStream());
        }
Exemple #7
0
 public MemoryStream GetMemoryStreamFromNewMessage(EASMessage message, bool ebsTone,
                                                   bool nwsTone, byte[] announcementStream, WaveFormat waveFormat)
 {
     return(GetMemoryStreamFromNewMessage(message, ebsTone, nwsTone, announcementStream, true));
 }
Exemple #8
0
            public EASMessage message()
            {
                EASMessage newmessage = new EASMessage(originator, eventCode, Regions, length, DateTime.UtcNow, senderId);

                return(newmessage);
            }