Ejemplo n.º 1
0
        public PianoSynth()
        {
            mixer = new WaveMixerStream32();
            mixer.AutoStop = false;

            int i = 0;
            foreach (var note in noteFiles)
            {
                reader[i] = new WaveFileReader(note);

                offsetStream[i] = new WaveOffsetStream(reader[i]);
                channelSteam[i] = new WaveChannel32(offsetStream[i]);
                channelSteam[i].Position = channelSteam[i].Length;
                mixer.AddInputStream(channelSteam[i]);

                i++;
            }

            if (waveOutDevice == null)
            {
                waveOutDevice = new WaveOut {DeviceNumber = 0};
                waveOutDevice.Init(mixer);
                waveOutDevice.Volume = 0;
                waveOutDevice.Play();
                waveOutDevice.Volume = 100;
            }
        }
Ejemplo n.º 2
0
        public TestMix()
        {
            //WaveStream str1 = new Mp3FileReader("C:\\Users\\mtemkine\\Desktop\\snd\\guitar1.mp3");
            //WaveStream str2 = new Mp3FileReader("C:\\Users\\mtemkine\\Desktop\\snd\\molecules.mp3");
            //WaveMixerStream32 mix = new WaveMixerStream32(new [] {str1, str2}, false);

            var background = new Mp3FileReader("C:\\Users\\mtemkine\\Desktop\\snd\\ferriss.mp3");
            var message = new Mp3FileReader("C:\\Users\\mtemkine\\Desktop\\snd\\guitar1.mp3");

            var mixer = new WaveMixerStream32();
            mixer.AutoStop = true;

            var messageOffset = background.TotalTime;
            var messageOffsetted = new WaveOffsetStream(message, TimeSpan.FromSeconds(1.5), TimeSpan.Zero, message.TotalTime.Subtract(TimeSpan.FromSeconds(1)));

            var background32 = new WaveChannel32(background);
            background32.PadWithZeroes = false;
            background32.Volume = 0.9f;

            var message32 = new WaveChannel32(messageOffsetted);
            message32.PadWithZeroes = false;
            message32.Volume = 0.7f;

            var s1 = new RawSourceWaveStream(background32, new WaveFormat(8000, 16, 1));
            var s2 = new RawSourceWaveStream(message32, new WaveFormat(8000, 16, 1));
            WaveFormat targetFormat = WaveFormat.CreateIeeeFloatWaveFormat(128, 2);
            var ss1 = new WaveFormatConversionStream(targetFormat, background32);
            //var c = new WaveFormatConversionStream(WaveFormat.CreateALawFormat(8000, 1), background32);
            //var stream_background32 = new WaveFormatConversionStream(new WaveFormat(256, 32, 2), background32);
            //var stream_message32 = new WaveFormatConversionStream(new WaveFormat(256, 32, 2), message32);
            mixer.AddInputStream(s1);
            mixer.AddInputStream(s2);

            WaveFileWriter.CreateWaveFile("mycomposed.wav", new Wave32To16Stream(mixer));
        }
Ejemplo n.º 3
0
 public MixDiffStream(string fileName)
 {
     WaveFileReader reader = new WaveFileReader(fileName);
     offsetStream = new WaveOffsetStream(reader);
     channelSteam = new WaveChannel32(offsetStream);
     muted = false;
     volume = 1.0f;
 }
Ejemplo n.º 4
0
 public Key(string name, string sampleFile)
 {
     this.notePitch = name;
         WaveFileReader reader = new WaveFileReader(sampleFile);
         offsetStream = new WaveOffsetStream(reader);
         channelStream = new WaveChannel32(offsetStream);
         channelStream.Position = channelStream.Length;
 }
Ejemplo n.º 5
0
        private static void AddIntroOutro(string SermonFileName = "",
            string IntroFileName = "",
            string OutroFileName = "",
            double StartSermonTime = 0,
            double StartOutroTime = 0,
            string ResultingFile = "")
        {
            if (String.IsNullOrWhiteSpace(SermonFileName)) throw new ArgumentException("SermonFileName must reference a valid file.");

            if (String.IsNullOrWhiteSpace(IntroFileName)) throw new ArgumentException("IntroFileName must reference a valid file.");

            if (String.IsNullOrWhiteSpace(OutroFileName)) throw new ArgumentException("OutroFileName must reference a valid file.");

            if (String.IsNullOrWhiteSpace(ResultingFile)) ResultingFile = Settings.Default.IntroOutroDirectory;

            WaveFileReader intro = new WaveFileReader(IntroFileName);
            WaveFileReader outro = new WaveFileReader(OutroFileName);
            WaveFileReader audio = new WaveFileReader(SermonFileName);

            WaveMixerStream32 mixer = new WaveMixerStream32();
            //mixer.AutoStop;

            WaveOffsetStream audioOffsetted = new WaveOffsetStream(
                audio,
                TimeSpan.FromSeconds(StartSermonTime), //N seconds after start of intro.
                TimeSpan.Zero,
                audio.TotalTime);

            TimeSpan outroOffset = TimeSpan.FromSeconds(StartSermonTime) + audio.TotalTime - TimeSpan.FromSeconds(StartOutroTime);

            WaveOffsetStream outroOffsetted = new WaveOffsetStream(
               outro,
               outroOffset,
               TimeSpan.Zero,
               outro.TotalTime);

            WaveChannel32 intro32 = new WaveChannel32(intro);
            intro32.PadWithZeroes = false;
            mixer.AddInputStream(intro32);

            WaveChannel32 outro32 = new WaveChannel32(outroOffsetted);
            outro32.PadWithZeroes = false;
            mixer.AddInputStream(outro32);

            WaveChannel32 audio32 = new WaveChannel32(audioOffsetted);
            audio32.PadWithZeroes = false;
            mixer.AddInputStream(audio32);

            FileInfo file = new FileInfo(SermonFileName);
            if (!Directory.Exists(ResultingFile)) Directory.CreateDirectory(ResultingFile);

            string FileOut = String.Format(@"{0}\{1}", ResultingFile, file.Name);

            WaveFileWriter.CreateWaveFile(FileOut, new Wave32To16Stream(mixer));
        }
        private void showWaveSound()
        {
            waveViewer.WaveStream = new NAudio.Wave.WaveFileReader(pathFile);

            if (playStream != null)
            {
                playStream.Dispose();
                playStream = null;
            }

            playStream = new WaveOffsetStream(new NAudio.Wave.WaveFileReader(pathFile));
            waveViewer.FitToScreen();
        }
 private void StoreWave(string path, NAudio.Wave.WaveOffsetStream stream)
 {
     using (WaveFileWriter writer = new WaveFileWriter(path, stream.WaveFormat)) {
         byte[] buffer = new byte[stream.Length];
         while (stream.Position < stream.Length)
         {
             int bytesRead = stream.Read(buffer, 0, buffer.Length);
             if (bytesRead == 0)
             {
                 break;
             }
             writer.WriteData(buffer, 0, bytesRead);
             writer.Flush();
         }
     }
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Creates a wave stream from a selected file
        /// </summary>
        /// <param name="fileName">The file path to the audio file (.mp3 or .wav)</param>
        /// <param name="volume">The default desired volume</param>
        /// <param name="addToBuffer">Determines if the audio file is added to the buffer</param>
        /// <returns></returns>
    public static WaveChannel32 CreateInputStream(string fileName, float volume, bool addToBuffer)
    {
        WaveStream stream;
        WaveOffsetStream offset;
        WaveChannel32 channel;

        if (fileName.ToLower().EndsWith(".wav"))
        {
            stream = new WaveFileReader(fileName);
        }
        else if (fileName.ToLower().EndsWith(".mp3"))
        {
            stream = new Mp3FileReader(fileName);
        }
        else
        {
            Console.WriteLine("Audio format not supported");
            return null;
        }

        stream = new WaveFormatConversionStream(new WaveFormat(44100, 1), stream);
        offset = new WaveOffsetStream(stream);
        channel = new WaveChannel32(offset);
        channel.Volume = volume;

        if(addToBuffer)
            mixer.AddInputStream(channel);

        return channel;
    }