示例#1
0
        public void CanRepositionToNonBlockAlignedPositions()
        {
            BlockAlignedWaveStream    inputStream = new BlockAlignedWaveStream(726, 80000);
            BlockAlignReductionStream blockStream = new BlockAlignReductionStream(inputStream);


            byte[] inputBuffer = new byte[1024];
            int    read        = blockStream.Read(inputBuffer, 0, 1024);

            Assert.AreEqual(1024, read, "bytes read 1");
            Assert.AreEqual(blockStream.Position, 1024);
            CheckReadBuffer(inputBuffer, 1024, 0);

            read = blockStream.Read(inputBuffer, 0, 1024);
            Assert.AreEqual(1024, read, "bytes read 2");
            Assert.AreEqual(2048, blockStream.Position, "position 2");
            CheckReadBuffer(inputBuffer, 1024, 1024);


            // can reposition correctly
            blockStream.Position = 1000;
            read = blockStream.Read(inputBuffer, 0, 1024);
            Assert.AreEqual(1024, read, "bytes read 3");
            Assert.AreEqual(2024, blockStream.Position, "position 3");
            CheckReadBuffer(inputBuffer, 1024, 1000);
        }
示例#2
0
        public static Song LoadMP3(string path)
        {
            Song song = new Song();

            int readLength = 100000;

            using (Mp3FileReader reader = new Mp3FileReader(path)) {
                byte[] buffer = new byte[0];

                using (WaveStream pcm = WaveFormatConversionStream.CreatePcmStream(reader)) {
                    using (WaveStream aligned = new BlockAlignReductionStream(pcm)) {
                        buffer = new byte[aligned.Length];
                        for (int i = 0; i < aligned.Length; i += readLength)
                        {
                            aligned.Read(buffer, i, readLength);
                        }
                        song.sampleRate = aligned.WaveFormat.SampleRate;
                        song.channels   = aligned.WaveFormat.Channels;
                    }
                }

                song.samples = new double[buffer.Length / 2];
                for (int i = 0; i < song.samples.Length; i++)
                {
                    song.samples[i] = BitConverter.ToInt16(buffer, i * 2) / 32768.0f;
                }
            }

            return(song);
        }
示例#3
0
        private void PlayNotificationSound()
        {
            if (DateTime.UtcNow >= nextAudioAlertPlay)
            {
                DisableAudioAlertForDuration();
                try
                {
                    System.Windows.Resources.StreamResourceInfo sri = Application.GetResourceStream(new Uri("WPFApp/Resources/audio/FeenPhoneDJAlert.wav", UriKind.Relative));

                    using (WaveStream ws =
                               new BlockAlignReductionStream(
                                   WaveFormatConversionStream.CreatePcmStream(
                                       new WaveFileReader(sri.Stream))))
                    {
                        var length = ws.Length;
                        if (length < int.MaxValue)
                        {
                            byte[] data   = new byte[length];
                            var    format = ws.WaveFormat;
                            int    read   = ws.Read(data, 0, (int)length);
                            EventSource.InvokePlaySoundEffect(this, format, data);
                        }
                    }
                }
                catch { }
            }
        }
示例#4
0
        public void CanReadNonBlockAlignedLengths()
        {
            BlockAlignedWaveStream    inputStream = new BlockAlignedWaveStream(726, 80000);
            BlockAlignReductionStream blockStream = new BlockAlignReductionStream(inputStream);


            byte[] inputBuffer = new byte[1024];
            int    read        = blockStream.Read(inputBuffer, 0, 1024);

            Assert.AreEqual(1024, read, "bytes read 1");
            Assert.AreEqual(blockStream.Position, 1024);
            CheckReadBuffer(inputBuffer, 1024, 0);

            read = blockStream.Read(inputBuffer, 0, 1024);
            Assert.AreEqual(1024, read, "bytes read 2");
            Assert.AreEqual(2048, blockStream.Position, "position 2");
            CheckReadBuffer(inputBuffer, 1024, 1024);
        }