Beispiel #1
0
        private void MixTwoSamples()
        {
            while (writer == null && RecordedAudioWriter == null)
            {
            }

            Thread.Sleep(1000);

            MicFileReader     = new AudioFileReader(saveDirectory.SelectedPath + "\\" + micRecordFIleName);
            SpeakerFileReader = new AudioFileReader(saveDirectory.SelectedPath + "\\" + playBackRecordFileName);

            WaveMixerStream32 mixer = new WaveMixerStream32();

            mixer.AddInputStream(MicFileReader);
            mixer.AddInputStream(SpeakerFileReader);

            WaveFileWriter.CreateWaveFile(saveDirectory.SelectedPath + "\\" + "result.wav", mixer);

            MicFileReader.Close();
            MicFileReader.Dispose();
            MicFileReader = null;

            SpeakerFileReader.Close();
            SpeakerFileReader.Dispose();
            SpeakerFileReader = null;
        }
Beispiel #2
0
        private byte[] RealMix(ReceivedRtp item1, ReceivedRtp item2)
        {
            if (item1 == null || item2 == null)
            {
                return(null);
            }

            if (item1.size == 0 || item2.size == 0)
            {
                return(null);
            }

            byte[] wavSrc1 = new byte[item1.size - headersize];
            byte[] wavSrc2 = new byte[item2.size - headersize];

            Array.Copy(item1.buff, headersize, wavSrc1, 0, (item1.size - headersize));
            Array.Copy(item2.buff, headersize, wavSrc2, 0, (item2.size - headersize));

            WaveMixerStream32 mixer = new WaveMixerStream32();
            // mixer.AutoStop = true;
            MemoryStream               memstrem         = new MemoryStream(wavSrc1);
            RawSourceWaveStream        rawsrcstream     = new RawSourceWaveStream(memstrem, this.codec);
            WaveFormatConversionStream conversionstream = new WaveFormatConversionStream(pcmFormat16, rawsrcstream);
            WaveChannel32              channelstream    = new WaveChannel32(conversionstream);

            mixer.AddInputStream(channelstream);

            memstrem         = new MemoryStream(wavSrc2);
            rawsrcstream     = new RawSourceWaveStream(memstrem, this.codec);
            conversionstream = new WaveFormatConversionStream(pcmFormat16, rawsrcstream);
            channelstream    = new WaveChannel32(conversionstream);
            mixer.AddInputStream(channelstream);
            mixer.Position = 0;

            Wave32To16Stream to16 = new Wave32To16Stream(mixer);
            var convStm           = new WaveFormatConversionStream(pcmFormat8, to16);

            byte[] mixedbytes = new byte[(int)convStm.Length];
            int    chk        = convStm.Read(mixedbytes, 0, (int)convStm.Length);

            //Buffer.BlockCopy(tobyte, 0, writingBuffer, 0, tobyte.Length);

            memstrem.Close();
            rawsrcstream.Close();
            conversionstream.Close();
            channelstream.Close();

            convStm.Close(); convStm.Dispose(); convStm = null;
            to16.Close(); to16.Dispose(); to16          = null;
            mixer.Close(); mixer.Dispose(); mixer       = null;

            return(mixedbytes);
        }
Beispiel #3
0
        //Jam.NET.Properties.Settings.Default.TrackPath
        public NAudioJcfPlayer(JcfMedia media, IWavePlayer waveOut, string tracksPath, byte[] stick)
        {
            _media    = media;
            _waveOut  = waveOut;
            _mixer    = new WaveMixerStream32();
            _channels = new Dictionary <TrackInfo, WaveChannel32>(media.InstrumentTracks.Count + 1 + 1);

            var songPath = Path.Combine(tracksPath, $"{media.Song.Sku}.jcf");

            foreach (var track in media.InstrumentTracks)
            {
                var stream = File.OpenRead(Path.Combine(songPath, $"{track.Identifier.ToString().ToUpper()}_jcfx"));
                _channels[track] = new WaveChannel32(new ImaWaveStream(stream));
            }

            var backingStream = File.OpenRead(Path.Combine(songPath, $"{media.BackingTrack.Identifier.ToString().ToUpper()}_jcfx"));

            _channels[media.BackingTrack] = new WaveChannel32(new ImaWaveStream(backingStream));
            _channels[media.ClickTrack]   = new WaveChannel32(new ClickTrackStream(media.Beats, stick));

            foreach (var channel in _channels.Values)
            {
                _mixer.AddInputStream(channel);
                channel.Volume = 1.00f;//TODO: bind?
            }

            _waveOut.PlaybackStopped += (sender, args) => { Position = TimeSpan.Zero; };
            //_waveOut.DesiredLatency = 60;//TODO: Why?
            //_waveOut.NumberOfBuffers = 2;
            _waveOut.Init(_mixer);
        }
        /// <summary>
        /// Creates a song player for the given song using the NAudio backend.
        /// </summary>
        /// <param name="s">ISong to play.</param>
        internal JammitNAudioSongPlayer(ISong s)
        {
            _waveOut   = new WaveOutEvent();
            _mixer     = new WaveMixerStream32();
            _channels  = new List <WaveChannel32>();
            _chanNames = new List <string>();

            foreach (var t in s.Tracks)
            {
                if (t.ClassName == "JMFileTrack")
                {
                    var stream = s.GetSeekableContentStream($"{t.Id}_jcfx");
                    _channels.Add(new WaveChannel32(new ImaWaveStream(stream)));
                    _chanNames.Add(t.Title);
                }
                else if (t.ClassName == "JMClickTrack")
                {
                    _channels.Add(new WaveChannel32(new ClickTrackStream(s.Beats)));
                    _chanNames.Add(t.Title);
                }
            }

            foreach (var d in _channels)
            {
                _mixer.AddInputStream(d);
                d.Volume = 0.75f;
            }
            _waveOut.PlaybackStopped += (sender, args) => { Position = TimeSpan.Zero; };
            _waveOut.DesiredLatency   = 60;
            _waveOut.NumberOfBuffers  = 2;
            _waveOut.Init(_mixer);
        }
Beispiel #5
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);
        }
Beispiel #6
0
        public NAudioJcfPlayer(JcfMedia media)
        {
            _media    = media;
            _waveOut  = new WaveOutEvent();
            _mixer    = new WaveMixerStream32();
            _channels = new Dictionary <TrackInfo, WaveChannel32>(media.InstrumentTracks.Count + 1 + 1);

            var songPath = Path.Combine(Jam.NET.Properties.Settings.Default.TrackPath, $"{media.Song.Id}.jcf");

            foreach (var track in media.InstrumentTracks)
            {
                var stream = File.OpenRead(Path.Combine(songPath, $"{track.Identifier}_jcfx"));
                _channels[track] = new WaveChannel32(new ImaWaveStream(stream));
            }

            var backingStream = File.OpenRead(Path.Combine(Jam.NET.Properties.Settings.Default.TrackPath, $"{media.Song.Id}.jcf"));

            _channels[media.BackingTrack] = new WaveChannel32(new ImaWaveStream(backingStream));

            _channels[media.ClickTrack] = new WaveChannel32(new ClickTrackStream(media.Beats));

            foreach (var channel in _channels.Values)
            {
                _mixer.AddInputStream(channel);
                channel.Volume = 0.75f;//TODO: bind?
            }

            _waveOut.PlaybackStopped += (sender, args) => { Position = TimeSpan.Zero; };
            _waveOut.DesiredLatency   = 60;//TODO: Why?
            _waveOut.NumberOfBuffers  = 2;
            _waveOut.Init(_mixer);
        }
 private void SetButtonInfo(Button button, MixdownInfo info)
 {
     if (button.Tag != null)
     {
         ClearFile(button);
     }
     button.Tag = info;
     SetButtonAppearance(button);
     mixer.AddInputStream(info.Stream);
     SetLengthLabel();
 }
Beispiel #8
0
 public void Init(string path)
 {
     sinfo  = new StreamInfo(path);
     _mixer = new WaveMixerStream32();
     _mixer.AddInputStream(sinfo.Stream);
     _wavePlayer = new WaveOut();
     _wavePlayer.Init(_mixer);
     _mixer.AutoStop = false;
     _skipSeconds    = 3;
     Status          = PlaybackStatus.Stopped;
 }
Beispiel #9
0
        public WaveStream GetMetronome(int tempo, int bars, Stream bufferStream)
        {
            Mp3FileReader stick  = new Mp3FileReader(@"sounds\stick.mp3");
            Mp3FileReader stick2 = new Mp3FileReader(@"sounds\stick.mp3");

            //Wave
            WaveStream stickWave  = WaveFormatConversionStream.CreatePcmStream(stick);
            WaveStream stick2Wave = WaveFormatConversionStream.CreatePcmStream(stick2);

            var stick32 = new WaveChannel32(stickWave);

            stick32.PadWithZeroes = false;
            stick32.Volume        = 1.0f;

            double seconds = 60f / tempo;

            var stickOff = new WaveOffsetStream(stick2Wave, TimeSpan.FromSeconds(seconds), TimeSpan.Zero,
                                                stick2Wave.TotalTime);
            var stickOff32 = new WaveChannel32(stickOff);

            stickOff32.PadWithZeroes = false;
            stickOff32.Volume        = 1.0f;

            // Add to the mixer.
            var mixer = new WaveMixerStream32();

            mixer.AutoStop = true;
            mixer.AddInputStream(stick32);
            mixer.AddInputStream(stickOff32);

            var outputWav = new Wave32To16Stream(mixer);

            using (MemoryStream mem = new MemoryStream())
            {
                WaveStream trimmed = TrimWaveStream(outputWav, TimeSpan.Zero,
                                                    outputWav.TotalTime.Subtract(TimeSpan.FromSeconds(seconds * 2)), mem);

                var looped = LoopStream(trimmed, bars * 2, bufferStream);
                return(looped);
            }
        }
Beispiel #10
0
        public static WaveStream Mix(this WaveStream stream, WaveStream stream2)
        {
            var mixer = new WaveMixerStream32();

            mixer.AutoStop = true;

            var chann1 = new WaveChannel32(stream);

            chann1.PadWithZeroes = false;
            chann1.Volume        = 1.0f;

            var chann2 = new WaveChannel32(stream2);

            chann2.PadWithZeroes = false;
            chann2.Volume        = 1.0f;

            mixer.AddInputStream(chann1);
            mixer.AddInputStream(chann2);

            return(mixer);
        }
Beispiel #11
0
        private void addMixerStream(WaveMixerStream32 mixer, string fileName)
        {
            // create a wave stream and a channel object
            var reader  = new WaveFileReader(fileName);
            var channel = new WaveChannel32(reader)
            {
                //Set the volume
                Volume = 1.0f
            };

            mixer.AddInputStream(channel);
        }
Beispiel #12
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));
        }
Beispiel #13
0
        public WaveMixerStream32 Combine()
        {
            WaveMixerStream32 wavMix = new WaveMixerStream32();

            wavMix.AutoStop = true;

            foreach (WaveFileReader reader in toMix)
            {
                WaveChannel32 wc3 = new WaveChannel32(reader);
                wavMix.AddInputStream(wc3);
            }

            wavMix.Position = 0;
            return(wavMix);
        }
    public static void MixWavFiles(string[] inputFiles, string outFileName)
    {
        int count = inputFiles.GetLength(0);
        WaveMixerStream32 mixer = new WaveMixerStream32();

        WaveFileReader[] reader       = new WaveFileReader[count];
        WaveChannel32[]  channelSteam = new WaveChannel32[count];
        mixer.AutoStop = true;

        for (int i = 0; i < count; i++)
        {
            reader[i]       = new WaveFileReader(inputFiles[i]);
            channelSteam[i] = new WaveChannel32(reader[i]);
            mixer.AddInputStream(channelSteam[i]);
        }
        mixer.Position = 0;
        WaveFileWriter.CreateWaveFile(outFileName, mixer);
    }
        private static void EnsureLength(Pattern pattern, int msPerBeat, WaveMixerStream32 finalMixer, StreamTracker streamTracker)
        {
            int avgBytesPerMs = finalMixer.WaveFormat.AverageBytesPerSecond / 1000;
            int beatArrayLen  = avgBytesPerMs * msPerBeat;
            var silence       = new byte[beatArrayLen];
            var mem           = new IgnoreDisposeStream(new MemoryStream());

            streamTracker.AddStream(mem);

            using (var writer = new WaveFileWriter(mem, finalMixer.WaveFormat))
            {
                for (int i = 0; i < pattern.NumberOfBeats; ++i)
                {
                    writer.Write(silence, 0, silence.Length);
                    writer.Flush();
                }
            }

            mem.Position = 0;

            var rdr = new WaveFileReader(mem);

            finalMixer.AddInputStream(rdr);
        }
Beispiel #16
0
 public static string Converter(string inPath)
 {
     using (WaveFileReader mpbacground = new WaveFileReader(inPath))
     {
         using (WaveStream background = WaveFormatConversionStream.CreatePcmStream(mpbacground))
         {
             using (var mixer = new WaveMixerStream32())
             {
                 mixer.AutoStop = true;
                 var messageOffset = background.TotalTime;
                 var background32  = new WaveChannel32(background);
                 background32.PadWithZeroes = false;
                 mixer.AddInputStream(background32);
                 using (var wave32 = new Wave32To16Stream(mixer))
                 {
                     var mp3Stream = ConvertWavToMp3(wave32);
                     inPath = inPath.Split('.')[0] + ".mp3";
                     File.WriteAllBytes(inPath, mp3Stream.ToArray());
                 }
             }
         }
     }
     return(inPath);
 }
Beispiel #17
0
        private void ProcessMixing2(RcvData data, int dataSize)
        {
            string processingFn = string.Format("d:\\{0}_{1}_{2}.wav", data.seqnum, data.extension, data.peernumber);

            List <RecInfos> ls0 = lExtension0.FindAll(
                delegate(RecInfos list)
            {
                return(list.rcvData.Equals(data) && list.isExtension == 0);
            });

            List <RecInfos> ls1 = lExtension1.FindAll(
                delegate(RecInfos list)
            {
                return(list.rcvData.Equals(data) && list.isExtension == 1);
            });

            IsExtensionComparer isExtensionCompare = new IsExtensionComparer();

            ls0.Sort(isExtensionCompare);
            ls1.Sort(isExtensionCompare);

            int count  = 0;
            int count0 = ls0.Count();
            int count1 = ls1.Count();

            if (count0 - count1 < 0)
            {
                count = count0;
            }
            else
            {
                count = count1;
            }

            byte[] buffWriting = new byte[320 * count];

            for (int i = 0; i < count; i++)
            {
                if (ls0[i].seq == ls1[i].seq)
                {
                    // 믹싱
                    // 코덱 종류에 따라서 바이트 길이는 달라질 수 있다. 실제로 만들 때 경우의 수 확인하고 만들어야 한다.
                    byte[] wavSrc0 = new byte[160];
                    byte[] wavSrc1 = new byte[160];

                    Array.Copy(ls0[i].voice, 12, wavSrc0, 0, wavSrc0.Length);
                    Array.Copy(ls1[i].voice, 12, wavSrc1, 0, wavSrc1.Length);

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

                    WaveChannel32 channelStm = null;

                    MemoryStream               memStm        = null;
                    BufferedStream             bufStm        = null;
                    RawSourceWaveStream        rawSrcStm     = null;
                    WaveFormatConversionStream conversionStm = null;

                    for (int j = 0; j < 2; j++)
                    {
                        if (j == 0)
                        {
                            memStm = new MemoryStream(wavSrc0);
                        }
                        else
                        {
                            memStm = new MemoryStream(wavSrc1);
                        }

                        bufStm        = new BufferedStream(memStm);
                        rawSrcStm     = new RawSourceWaveStream(bufStm, mulawFormat);
                        conversionStm = new WaveFormatConversionStream(pcmFormat, rawSrcStm);

                        channelStm = new WaveChannel32(conversionStm);
                        mixer.AddInputStream(channelStm);
                    }
                    mixer.Position = 0;

                    Wave32To16Stream to16 = new Wave32To16Stream(mixer);
                    var    convStm        = new WaveFormatConversionStream(pcmFormat, to16);
                    byte[] tobyte         = new byte[(int)convStm.Length];
                    int    chk            = convStm.Read(tobyte, 0, (int)convStm.Length);
                    Buffer.BlockCopy(tobyte, 0, buffWriting, i * tobyte.Length, tobyte.Length);

                    conversionStm.Close();
                    rawSrcStm.Close();
                    bufStm.Close();
                    memStm.Close();

                    convStm.Close();
                    to16.Close();
                    channelStm.Close();
                    mixer.Close();

                    // 삭제
                    lExtension0.Remove(ls0[i]);
                    lExtension1.Remove(ls1[i]);
                }
                else if (ls0[i].seq - ls1[i].seq < 0)
                {
                    // ls0 만 믹싱
                    // ls0 원본에 byte[] 붙임 > 원본 byte[]를 wavesream 으로 변환 > wave 파일로 저장

                    // 믹싱
                    // 코덱 종류에 따라서 바이트 길이는 달라질 수 있다. 실제로 만들 때 경우의 수 확인하고 만들어야 한다.
                    byte[] wavSrc0 = new byte[160];
                    byte[] wavSrc1 = new byte[160];

                    Array.Copy(ls0[i].voice, 12, wavSrc0, 0, wavSrc0.Length);
                    Array.Copy(ls1[i].voice, 12, wavSrc1, 0, wavSrc1.Length);

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

                    WaveChannel32 channelStm = null;

                    MemoryStream               memStm        = null;
                    BufferedStream             bufStm        = null;
                    RawSourceWaveStream        rawSrcStm     = null;
                    WaveFormatConversionStream conversionStm = null;

                    for (int j = 0; j < 2; j++)
                    {
                        if (j == 0)
                        {
                            memStm = new MemoryStream(wavSrc0);
                        }
                        else
                        {
                            memStm = new MemoryStream(wavSrc1);
                        }

                        bufStm        = new BufferedStream(memStm);
                        rawSrcStm     = new RawSourceWaveStream(bufStm, mulawFormat);
                        conversionStm = new WaveFormatConversionStream(pcmFormat, rawSrcStm);

                        channelStm = new WaveChannel32(conversionStm);
                        mixer.AddInputStream(channelStm);
                    }
                    mixer.Position = 0;

                    Wave32To16Stream to16 = new Wave32To16Stream(mixer);
                    var    convStm        = new WaveFormatConversionStream(pcmFormat, to16);
                    byte[] tobyte         = new byte[(int)convStm.Length];
                    int    chk            = convStm.Read(tobyte, 0, (int)convStm.Length);
                    Buffer.BlockCopy(tobyte, 0, buffWriting, i * tobyte.Length, tobyte.Length);

                    conversionStm.Close();
                    rawSrcStm.Close();
                    bufStm.Close();
                    memStm.Close();

                    convStm.Close();
                    to16.Close();
                    channelStm.Close();
                    mixer.Close();

                    // 삭제
                    lExtension0.Remove(ls0[i]);
                    ls1.Insert(i + 1, ls1[i]);
                }
                else if (ls0[i].seq - ls1[i].seq > 0)
                {
                    // ls1 만 믹싱
                    // ls1 원본에 byte[] 붙임 > 원본 byte[]를 wavesream 으로 변환 > wave 파일로 저장

                    // 믹싱
                    // 코덱 종류에 따라서 바이트 길이는 달라질 수 있다. 실제로 만들 때 경우의 수 확인하고 만들어야 한다.
                    byte[] wavSrc0 = new byte[160];
                    byte[] wavSrc1 = new byte[160];

                    Array.Copy(ls0[i].voice, 12, wavSrc0, 0, wavSrc0.Length);
                    Array.Copy(ls1[i].voice, 12, wavSrc1, 0, wavSrc1.Length);

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

                    WaveChannel32 channelStm = null;

                    MemoryStream               memStm        = null;
                    BufferedStream             bufStm        = null;
                    RawSourceWaveStream        rawSrcStm     = null;
                    WaveFormatConversionStream conversionStm = null;

                    for (int j = 0; j < 2; j++)
                    {
                        if (j == 0)
                        {
                            memStm = new MemoryStream(wavSrc0);
                        }
                        else
                        {
                            memStm = new MemoryStream(wavSrc1);
                        }

                        bufStm        = new BufferedStream(memStm);
                        rawSrcStm     = new RawSourceWaveStream(bufStm, mulawFormat);
                        conversionStm = new WaveFormatConversionStream(pcmFormat, rawSrcStm);

                        channelStm = new WaveChannel32(conversionStm);
                        mixer.AddInputStream(channelStm);
                    }
                    mixer.Position = 0;

                    Wave32To16Stream to16 = new Wave32To16Stream(mixer);
                    var    convStm        = new WaveFormatConversionStream(pcmFormat, to16);
                    byte[] tobyte         = new byte[(int)convStm.Length];
                    int    chk            = convStm.Read(tobyte, 0, (int)convStm.Length);
                    Buffer.BlockCopy(tobyte, 0, buffWriting, i * tobyte.Length, tobyte.Length);

                    conversionStm.Close();
                    rawSrcStm.Close();
                    bufStm.Close();
                    memStm.Close();

                    convStm.Close();
                    to16.Close();
                    channelStm.Close();
                    mixer.Close();

                    // 삭제
                    lExtension1.Remove(ls1[i]);
                    ls0.Insert(i + 1, ls0[i]);
                }
            }

            // 10개의 버프를 바이트로 만들어 WaveFileWrite
            WaveFileWriting(buffWriting, processingFn);
        }
Beispiel #18
0
    public bool Merge(string nompartie)
    {
        if (nompartie != "")
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(Application.persistentDataPath + "/sauv.xml");
            XmlElement root = doc.DocumentElement;
            if (root.HasChildNodes)
            {
                XmlNodeList ToutesLesParties = root.ChildNodes;
                int         NombreParties    = ToutesLesParties.Count;
                for (int i = 0; i < NombreParties; i++)
                {
                    XmlElement Partie = ToutesLesParties[i] as XmlElement;
                    String     nom    = Partie.GetAttribute("name");
                    if (nom == nompartie)
                    {
                        WaveFileReader[] batterie;
                        WaveFileReader[] synthe;
                        WaveFileReader[] melodie;
                        WaveFileReader[] guitare;
                        WaveFileReader[] basse;
                        WaveFileReader[] piano;

                        WaveChannel32[] batterieStream;
                        WaveChannel32[] syntheStream;
                        WaveChannel32[] melodieStream;
                        WaveChannel32[] guitareStream;
                        WaveChannel32[] basseStream;
                        WaveChannel32[] pianoStream;

                        WaveOffsetStream[] batterieDecalage;
                        WaveOffsetStream[] syntheDecalage;
                        WaveOffsetStream[] melodieDecalage;
                        WaveOffsetStream[] guitareDecalage;
                        WaveOffsetStream[] basseDecalage;
                        WaveOffsetStream[] pianoDecalage;

                        int decalage = 0;

                        if (Partie.HasChildNodes)
                        {
                            var mixer = new WaveMixerStream32();
                            mixer.AutoStop = true;
                            XmlNodeList ToutesLesSequences = Partie.ChildNodes;
                            int         NombreSequences    = ToutesLesSequences.Count;

                            batterie = new WaveFileReader[NombreSequences];
                            synthe   = new WaveFileReader[NombreSequences];
                            melodie  = new WaveFileReader[NombreSequences];
                            guitare  = new WaveFileReader[NombreSequences];
                            basse    = new WaveFileReader[NombreSequences];
                            piano    = new WaveFileReader[NombreSequences];

                            piano[0]    = null;
                            batterie[0] = null;
                            synthe[0]   = null;
                            melodie[0]  = null;
                            guitare[0]  = null;
                            basse[0]    = null;

                            batterieDecalage = new WaveOffsetStream[NombreSequences];
                            syntheDecalage   = new WaveOffsetStream[NombreSequences];
                            melodieDecalage  = new WaveOffsetStream[NombreSequences];
                            guitareDecalage  = new WaveOffsetStream[NombreSequences];
                            basseDecalage    = new WaveOffsetStream[NombreSequences];
                            pianoDecalage    = new WaveOffsetStream[NombreSequences];

                            batterieStream = new WaveChannel32[NombreSequences];
                            syntheStream   = new WaveChannel32[NombreSequences];
                            melodieStream  = new WaveChannel32[NombreSequences];
                            guitareStream  = new WaveChannel32[NombreSequences];
                            basseStream    = new WaveChannel32[NombreSequences];
                            pianoStream    = new WaveChannel32[NombreSequences];

                            string[] batterieSrc = new string[NombreSequences];
                            string[] syntheSrc   = new string[NombreSequences];
                            string[] melodieSrc  = new string[NombreSequences];
                            string[] guitareSrc  = new string[NombreSequences];
                            string[] basseSrc    = new string[NombreSequences];
                            string[] pianoSrc    = new string[NombreSequences];

                            for (int k = 0; k < NombreSequences; k++)
                            {
                                batterieSrc[k] = "";
                                syntheSrc[k]   = "";
                                melodieSrc[k]  = "";
                                guitareSrc[k]  = "";
                                basseSrc[k]    = "";
                                pianoSrc[k]    = "";
                            }

                            for (int j = 0; j < NombreSequences; j++)
                            {
                                XmlElement Sequence = ToutesLesSequences[j] as XmlElement;
                                decalage = j * 8;
                                XmlElement Instru = Sequence.FirstChild as XmlElement;
                                string     type   = Instru.GetAttribute("type");
                                string     src    = Instru.GetAttribute("src");
                                switch (type)
                                {
                                case "piano":
                                    if (src != "")
                                    {
                                        piano[j] = new WaveFileReader(Application.dataPath + "/Resources/" + src);
                                    }
                                    pianoSrc[j] = src;
                                    if (j > 0)
                                    {
                                        if (batterieSrc[j - 1] != "")
                                        {
                                            batterie[j]    = new WaveFileReader(Application.dataPath + "/Resources/" + batterieSrc[j - 1]);
                                            batterieSrc[j] = batterieSrc[j - 1];
                                        }
                                        if (syntheSrc[j - 1] != "")
                                        {
                                            synthe[j]    = new WaveFileReader(Application.dataPath + "/Resources/" + syntheSrc[j - 1]);
                                            syntheSrc[j] = syntheSrc[j - 1];
                                        }
                                        if (guitareSrc[j - 1] != "")
                                        {
                                            guitare[j]    = new WaveFileReader(Application.dataPath + "/Resources/" + guitareSrc[j - 1]);
                                            guitareSrc[j] = guitareSrc[j - 1];
                                        }
                                        if (basseSrc[j - 1] != "")
                                        {
                                            basse[j]    = new WaveFileReader(Application.dataPath + "/Resources/" + basseSrc[j - 1]);
                                            basseSrc[j] = basseSrc[j - 1];
                                        }
                                        if (melodieSrc[j - 1] != "")
                                        {
                                            melodie[j]    = new WaveFileReader(Application.dataPath + "/Resources/" + melodieSrc[j - 1]);
                                            melodieSrc[j] = melodieSrc[j - 1];
                                        }
                                    }
                                    break;

                                case "basse":
                                    if (src != "")
                                    {
                                        basse[j] = new WaveFileReader(Application.dataPath + "/Resources/" + src);
                                    }
                                    basseSrc[j] = src;
                                    if (j > 0)
                                    {
                                        if (batterieSrc[j - 1] != "")
                                        {
                                            batterie[j]    = new WaveFileReader(Application.dataPath + "/Resources/" + batterieSrc[j - 1]);
                                            batterieSrc[j] = batterieSrc[j - 1];
                                        }
                                        if (syntheSrc[j - 1] != "")
                                        {
                                            synthe[j]    = new WaveFileReader(Application.dataPath + "/Resources/" + syntheSrc[j - 1]);
                                            syntheSrc[j] = syntheSrc[j - 1];
                                        }
                                        if (guitareSrc[j - 1] != "")
                                        {
                                            guitare[j]    = new WaveFileReader(Application.dataPath + "/Resources/" + guitareSrc[j - 1]);
                                            guitareSrc[j] = guitareSrc[j - 1];
                                        }
                                        if (melodieSrc[j - 1] != "")
                                        {
                                            melodie[j]    = new WaveFileReader(Application.dataPath + "/Resources/" + melodieSrc[j - 1]);
                                            melodieSrc[j] = melodieSrc[j - 1];
                                        }
                                        if (pianoSrc[j - 1] != "")
                                        {
                                            piano[j]    = new WaveFileReader(Application.dataPath + "/Resources/" + pianoSrc[j - 1]);
                                            pianoSrc[j] = pianoSrc[j - 1];
                                        }
                                    }
                                    break;

                                case "guitare":
                                    if (src != "")
                                    {
                                        guitare[j] = new WaveFileReader(Application.dataPath + "/Resources/" + src);
                                    }
                                    guitareSrc[j] = src;
                                    if (j > 0)
                                    {
                                        if (batterieSrc[j - 1] != "")
                                        {
                                            batterie[j]    = new WaveFileReader(Application.dataPath + "/Resources/" + batterieSrc[j - 1]);
                                            batterieSrc[j] = batterieSrc[j - 1];
                                        }
                                        if (syntheSrc[j - 1] != "")
                                        {
                                            synthe[j]    = new WaveFileReader(Application.dataPath + "/Resources/" + syntheSrc[j - 1]);
                                            syntheSrc[j] = syntheSrc[j - 1];
                                        }
                                        if (basseSrc[j - 1] != "")
                                        {
                                            basse[j]    = new WaveFileReader(Application.dataPath + "/Resources/" + basseSrc[j - 1]);
                                            basseSrc[j] = basseSrc[j - 1];
                                        }
                                        if (melodieSrc[j - 1] != "")
                                        {
                                            melodie[j]    = new WaveFileReader(Application.dataPath + "/Resources/" + melodieSrc[j - 1]);
                                            melodieSrc[j] = melodieSrc[j - 1];
                                        }
                                        if (pianoSrc[j - 1] != "")
                                        {
                                            piano[j]    = new WaveFileReader(Application.dataPath + "/Resources/" + pianoSrc[j - 1]);
                                            pianoSrc[j] = pianoSrc[j - 1];
                                        }
                                    }
                                    break;

                                case "drum1":
                                    if (src != "")
                                    {
                                        batterie[j] = new WaveFileReader(Application.dataPath + "/Resources/" + src);
                                    }
                                    batterieSrc[j] = src;
                                    if (j > 0)
                                    {
                                        if (syntheSrc[j - 1] != "")
                                        {
                                            synthe[j]    = new WaveFileReader(Application.dataPath + "/Resources/" + syntheSrc[j - 1]);
                                            syntheSrc[j] = syntheSrc[j - 1];
                                        }
                                        if (guitareSrc[j - 1] != "")
                                        {
                                            guitare[j]    = new WaveFileReader(Application.dataPath + "/Resources/" + guitareSrc[j - 1]);
                                            guitareSrc[j] = guitareSrc[j - 1];
                                        }
                                        if (basseSrc[j - 1] != "")
                                        {
                                            basse[j]    = new WaveFileReader(Application.dataPath + "/Resources/" + basseSrc[j - 1]);
                                            basseSrc[j] = basseSrc[j - 1];
                                        }
                                        if (melodieSrc[j - 1] != "")
                                        {
                                            melodie[j]    = new WaveFileReader(Application.dataPath + "/Resources/" + melodieSrc[j - 1]);
                                            melodieSrc[j] = melodieSrc[j - 1];
                                        }
                                        if (pianoSrc[j - 1] != "")
                                        {
                                            piano[j]    = new WaveFileReader(Application.dataPath + "/Resources/" + pianoSrc[j - 1]);
                                            pianoSrc[j] = pianoSrc[j - 1];
                                        }
                                    }
                                    break;

                                case "synthe":
                                    if (src != "")
                                    {
                                        synthe[j] = new WaveFileReader(Application.dataPath + "/Resources/" + src);
                                    }
                                    syntheSrc[j] = src;
                                    if (j > 0)
                                    {
                                        if (batterieSrc[j - 1] != "")
                                        {
                                            batterie[j]    = new WaveFileReader(Application.dataPath + "/Resources/" + batterieSrc[j - 1]);
                                            batterieSrc[j] = batterieSrc[j - 1];
                                        }
                                        if (guitareSrc[j - 1] != "")
                                        {
                                            guitare[j]    = new WaveFileReader(Application.dataPath + "/Resources/" + guitareSrc[j - 1]);
                                            guitareSrc[j] = guitareSrc[j - 1];
                                        }
                                        if (basseSrc[j - 1] != "")
                                        {
                                            basse[j]    = new WaveFileReader(Application.dataPath + "/Resources/" + basseSrc[j - 1]);
                                            basseSrc[j] = basseSrc[j - 1];
                                        }
                                        if (melodieSrc[j - 1] != "")
                                        {
                                            melodie[j]    = new WaveFileReader(Application.dataPath + "/Resources/" + melodieSrc[j - 1]);
                                            melodieSrc[j] = melodieSrc[j - 1];
                                        }
                                        if (pianoSrc[j - 1] != "")
                                        {
                                            piano[j]    = new WaveFileReader(Application.dataPath + "/Resources/" + pianoSrc[j - 1]);
                                            pianoSrc[j] = pianoSrc[j - 1];
                                        }
                                    }
                                    break;

                                case "melodie":
                                    if (src != "")
                                    {
                                        melodie[j] = new WaveFileReader(Application.dataPath + "/Resources/" + src);
                                    }
                                    melodieSrc[j] = src;
                                    if (j > 0)
                                    {
                                        if (batterieSrc[j - 1] != "")
                                        {
                                            batterie[j]    = new WaveFileReader(Application.dataPath + "/Resources/" + batterieSrc[j - 1]);
                                            batterieSrc[j] = batterieSrc[j - 1];
                                        }
                                        if (syntheSrc[j - 1] != "")
                                        {
                                            synthe[j]    = new WaveFileReader(Application.dataPath + "/Resources/" + syntheSrc[j - 1]);
                                            syntheSrc[j] = syntheSrc[j - 1];
                                        }
                                        if (guitareSrc[j - 1] != "")
                                        {
                                            guitare[j]    = new WaveFileReader(Application.dataPath + "/Resources/" + guitareSrc[j - 1]);
                                            guitareSrc[j] = guitareSrc[j - 1];
                                        }
                                        if (basseSrc[j - 1] != "")
                                        {
                                            basse[j]    = new WaveFileReader(Application.dataPath + "/Resources/" + basseSrc[j - 1]);
                                            basseSrc[j] = basseSrc[j - 1];
                                        }
                                        if (pianoSrc[j - 1] != "")
                                        {
                                            piano[j]    = new WaveFileReader(Application.dataPath + "/Resources/" + pianoSrc[j - 1]);
                                            pianoSrc[j] = pianoSrc[j - 1];
                                        }
                                    }
                                    break;

                                case "none":
                                    if (j > 0)
                                    {
                                        if (batterieSrc[j - 1] != "")
                                        {
                                            batterie[j]    = new WaveFileReader(Application.dataPath + "/Resources/" + batterieSrc[j - 1]);
                                            batterieSrc[j] = batterieSrc[j - 1];
                                        }
                                        if (melodieSrc[j - 1] != "")
                                        {
                                            melodie[j]    = new WaveFileReader(Application.dataPath + "/Resources/" + melodieSrc[j - 1]);
                                            melodieSrc[j] = melodieSrc[j - 1];
                                        }
                                        if (syntheSrc[j - 1] != "")
                                        {
                                            synthe[j]    = new WaveFileReader(Application.dataPath + "/Resources/" + syntheSrc[j - 1]);
                                            syntheSrc[j] = syntheSrc[j - 1];
                                        }
                                        if (guitareSrc[j - 1] != "")
                                        {
                                            guitare[j]    = new WaveFileReader(Application.dataPath + "/Resources/" + guitareSrc[j - 1]);
                                            guitareSrc[j] = guitareSrc[j - 1];
                                        }
                                        if (basseSrc[j - 1] != "")
                                        {
                                            basse[j]    = new WaveFileReader(Application.dataPath + "/Resources/" + basseSrc[j - 1]);
                                            basseSrc[j] = basseSrc[j - 1];
                                        }
                                        if (pianoSrc[j - 1] != "")
                                        {
                                            piano[j]    = new WaveFileReader(Application.dataPath + "/Resources/" + pianoSrc[j - 1]);
                                            pianoSrc[j] = pianoSrc[j - 1];
                                        }
                                    }
                                    break;
                                }
                                if (piano[j] != null)
                                {
                                    pianoDecalage[j]             = new WaveOffsetStream(piano[j], TimeSpan.FromSeconds(decalage), TimeSpan.Zero, TimeSpan.FromSeconds(8));
                                    pianoStream[j]               = new WaveChannel32(pianoDecalage[j]);
                                    pianoStream[j].PadWithZeroes = false;
                                    mixer.AddInputStream(pianoStream[j]);
                                }
                                if (basse[j] != null)
                                {
                                    basseDecalage[j]             = new WaveOffsetStream(basse[j], TimeSpan.FromSeconds(decalage), TimeSpan.Zero, TimeSpan.FromSeconds(8));
                                    basseStream[j]               = new WaveChannel32(basseDecalage[j]);
                                    basseStream[j].PadWithZeroes = false;
                                    mixer.AddInputStream(basseStream[j]);
                                }
                                if (guitare[j] != null)
                                {
                                    guitareDecalage[j]             = new WaveOffsetStream(guitare[j], TimeSpan.FromSeconds(decalage), TimeSpan.Zero, TimeSpan.FromSeconds(8));
                                    guitareStream[j]               = new WaveChannel32(guitareDecalage[j]);
                                    guitareStream[j].PadWithZeroes = false;
                                    mixer.AddInputStream(guitareStream[j]);
                                }
                                if (batterie[j] != null)
                                {
                                    batterieDecalage[j]             = new WaveOffsetStream(batterie[j], TimeSpan.FromSeconds(decalage), TimeSpan.Zero, TimeSpan.FromSeconds(8));
                                    batterieStream[j]               = new WaveChannel32(batterieDecalage[j]);
                                    batterieStream[j].PadWithZeroes = false;
                                    mixer.AddInputStream(batterieStream[j]);
                                }
                                if (melodie[j] != null)
                                {
                                    melodieDecalage[j]             = new WaveOffsetStream(melodie[j], TimeSpan.FromSeconds(decalage), TimeSpan.Zero, TimeSpan.FromSeconds(8));
                                    melodieStream[j]               = new WaveChannel32(melodieDecalage[j]);
                                    melodieStream[j].PadWithZeroes = false;
                                    mixer.AddInputStream(melodieStream[j]);
                                }
                                if (synthe[j] != null)
                                {
                                    syntheDecalage[j]             = new WaveOffsetStream(synthe[j], TimeSpan.FromSeconds(decalage), TimeSpan.Zero, TimeSpan.FromSeconds(8));
                                    syntheStream[j]               = new WaveChannel32(syntheDecalage[j]);
                                    syntheStream[j].PadWithZeroes = false;
                                    mixer.AddInputStream(syntheStream[j]);
                                }
                            }
                            var    wave32    = new Wave32To16Stream(mixer);
                            string nomSecure = nompartie;
                            foreach (char c in System.IO.Path.GetInvalidFileNameChars())
                            {
                                nomSecure = nompartie.Replace(c, '_');
                            }
                            WaveFileWriter.CreateWaveFile(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop) + "/" + nomSecure + ".wav", wave32);
                            GameObject.Find("haut").GetComponent <Text>().text = "Le fichier " + nomSecure + ".wav";
                            return(true);
                        }
                    }
                }
            }
        }
        return(false);
    }
Beispiel #19
0
        public void Play(string soundName)
        {
            try
            {
                if (aguante >= 30)
                {
                    return;
                }

                //aguante++;
                //if (output[direccion[soundName]].PlaybackState == PlaybackState.Playing)
                // {
                if (soundName.EndsWith(".wav") == true)
                {
                    //playWithMedia(soundName);
                    //return;
                }
                ISound sfx = controlador.Play2D(soundName);
                sfx.Dispose();

                return;


                WaveStream        auxoxo = CreateInputStreamReturnable(soundName);
                WaveMixerStream32 extrr  = new WaveMixerStream32();
                extrr.AutoStop = true;
                extrr.AddInputStream(auxoxo);

                auxoxo.Position = 0;


                DirectSoundOut auxili = new DirectSoundOut();


                diccionarioLoco.Add(auxili, auxoxo);
                diccionarioReLocoMixer.Add(auxili, extrr);

                auxili.PlaybackStopped += new EventHandler(auxili_PlaybackStopped);


                auxili.Init(extrr);
                auxili.Play();


                /*auxili.Dispose();
                 *  auxili.Stop();
                 *
                 *
                 *  //error("dentro del if");
                 *
                 * //}
                 * else
                 * {
                 *  mainStreams[direccion[soundName]].Position = 0;
                 *  mixeador[direccion[soundName]].AddInputStream(mainStreams[direccion[soundName]]);
                 *
                 *  output[direccion[soundName]].Init(mixeador[direccion[soundName]]);
                 *
                 *  output[direccion[soundName]].Play();
                 *
                 *
                 *  output[direccion[soundName]].Init(mainStreams[direccion[soundName]]);
                 *  output[direccion[soundName]].Play();
                 *
                 *  output[direccion[soundName]].Dispose();
                 *
                 *
                 *  error("no estoy en el if ");
                 *
                 * }
                 *
                 * output[direccion[soundName]].PlaybackStopped += new EventHandler(MainPlayer_PlaybackStopped);
                 *
                 */
            }
            catch (Exception e)
            {
                if (error != null)
                {
                    error(e.Message + " error en play " + direccion[soundName]);
                }
            }
        }
Beispiel #20
0
        private void ProcessMixingFinal(RcvData data, int dataSize)
        {
            string processingFn = string.Format("e:\\{0}_{1}_{2}.wav", data.seqnum, data.extension, data.peernumber);

            List <RecInfos> ls0 = lExtension0.FindAll(
                delegate(RecInfos list)
            {
                return(list.rcvData.Equals(data) && list.isExtension == 0);
            });

            List <RecInfos> ls1 = lExtension1.FindAll(
                delegate(RecInfos list)
            {
                return(list.rcvData.Equals(data) && list.isExtension == 1);
            });

            IsExtensionComparer isExtensionCompare = new IsExtensionComparer();

            ls0.Sort(isExtensionCompare);
            ls1.Sort(isExtensionCompare);

            int count  = 0;
            int count0 = ls0.Count();
            int count1 = ls1.Count();

            if (count0 - count1 < 0)
            {
                count = count0;
            }
            else
            {
                count = count1;
            }

            for (int i = 0; i < count; i++)
            {
                if (ls0[i].seq == ls1[i].seq)
                {
                    // 믹싱

                    byte[] wavSrc0 = new byte[160];
                    byte[] wavSrc1 = new byte[160];

                    Array.Copy(ls0[i].voice, 12, wavSrc0, 0, wavSrc0.Length);
                    Array.Copy(ls1[i].voice, 12, wavSrc1, 0, wavSrc1.Length);

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

                    WaveChannel32 channelStm = null;

                    for (int j = 0; j < 2; j++)
                    {
                        MemoryStream               memStm        = null;
                        BufferedStream             bufStm        = null;
                        RawSourceWaveStream        rawSrcStm     = null;
                        WaveFormatConversionStream conversionStm = null;

                        if (j == 0)
                        {
                            memStm = new MemoryStream(wavSrc0);
                        }
                        else
                        {
                            memStm = new MemoryStream(wavSrc1);
                        }

                        bufStm        = new BufferedStream(memStm);
                        rawSrcStm     = new RawSourceWaveStream(bufStm, mulawFormat);
                        conversionStm = new WaveFormatConversionStream(pcmFormat, rawSrcStm);

                        channelStm = new WaveChannel32(conversionStm);
                        mixer.AddInputStream(channelStm);
                    }
                    mixer.Position = 0;

                    if (File.Exists(processingFn))
                    {
                        var    wavefilestream = new WaveFileReader(processingFn);
                        byte[] wavefilebyte   = new byte[(int)wavefilestream.Length];
                        int    chk0           = wavefilestream.Read(wavefilebyte, 0, wavefilebyte.Length);

                        Wave32To16Stream to16 = new Wave32To16Stream(mixer);
                        var    conversionStm  = new WaveFormatConversionStream(pcmFormat, to16);
                        byte[] tobyte         = new byte[(int)conversionStm.Length];
                        int    chk1           = conversionStm.Read(tobyte, 0, (int)conversionStm.Length);

                        byte[] desByte = new byte[wavefilebyte.Length + tobyte.Length];

                        conversionStm.Close();
                        wavefilestream.Close();

                        Buffer.BlockCopy(wavefilebyte, 0, desByte, 0, wavefilebyte.Length);
                        Buffer.BlockCopy(tobyte, 0, desByte, wavefilebyte.Length, tobyte.Length);

                        using (MemoryStream memStm = new MemoryStream(desByte))
                            using (BufferedStream buffStm = new BufferedStream(memStm))
                                using (RawSourceWaveStream rawSrcStm = new RawSourceWaveStream(buffStm, pcmFormat))
                                {
                                    WaveFileWriter.CreateWaveFile(processingFn, rawSrcStm);
                                }
                    }
                    else
                    {
                        var mixedStm = new Wave32To16Stream(mixer);
                        var convStm  = new WaveFormatConversionStream(pcmFormat, mixedStm);
                        WaveFileWriter.CreateWaveFile(processingFn, convStm);
                        convStm.Close();
                        mixedStm.Close();
                    }

                    mixer.Close();

                    // 삭제
                    lExtension0.Remove(ls0[i]);
                    lExtension1.Remove(ls1[i]);
                }
                else if (ls0[i].seq - ls1[i].seq < 0)
                {
                    // ls0 만 믹싱
                    // ls0 원본에 byte[] 붙임 > 원본 byte[]를 wavesream 으로 변환 > wave 파일로 저장

                    if (File.Exists(processingFn))
                    {
                        //wavefilestream = new WaveFileReader(processingFn);
                    }
                    else
                    {
                    }

                    // 삭제
                    lExtension0.Remove(ls0[i]);
                    ls1.Insert(i + 1, ls1[i]);
                }
                else if (ls0[i].seq - ls1[i].seq > 0)
                {
                    // ls1 만 믹싱
                    // ls1 원본에 byte[] 붙임 > 원본 byte[]를 wavesream 으로 변환 > wave 파일로 저장

                    if (File.Exists(processingFn))
                    {
                        //wavefilestream = new WaveFileReader(processingFn);
                    }
                    else
                    {
                    }

                    // 삭제
                    lExtension1.Remove(ls1[i]);
                    ls0.Insert(i + 1, ls0[i]);
                }
            }
        }
Beispiel #21
0
        /// <summary>
        /// Creates a mashup of two or more mp3 files by using naudio
        /// </summary>
        /// <param name="files">Name of files as an string array</param>
        /// These files should be existing in a temporay folder
        /// <returns>The path of mashed up mp3 file</returns>
        public static string CreateMashup(int projectId, string mp3Folder, string[] files)
        {
            // because there is no mash up with less than 2 files
            if (files.Count() < 2)
            {
                throw new Exception("Not enough files selected!");
            }

            try
            {
                // Create a mixer object
                // This will be used for merging files together
                var mixer = new WaveMixerStream32
                {
                    AutoStop = true
                };

                // Set the path to store the mashed up output file
                var outputFile = Path.Combine(mp3Folder, $"{projectId}.mp3");

                foreach (var file in files)
                {
                    // for each file -
                    // check if it exists in the temp folder
                    var filePath = Path.Combine(file);
                    if (File.Exists(filePath))
                    {
                        // create mp3 reader object
                        var reader = new Mp3FileReader(filePath);

                        // create a wave stream and a channel object
                        var waveStream = WaveFormatConversionStream.CreatePcmStream(reader);
                        var channel    = new WaveChannel32(waveStream)
                        {
                            //Set the volume
                            Volume = 0.5f
                        };

                        // add channel as an input stream to the mixer
                        mixer.AddInputStream(channel);
                    }
                }

                CheckAddBinPath();

                // convert wave stream from mixer to mp3
                var wave32    = new Wave32To16Stream(mixer);
                var mp3Writer = new LameMP3FileWriter(outputFile, wave32.WaveFormat, 128);
                wave32.CopyTo(mp3Writer);

                // close all streams
                wave32.Close();
                mp3Writer.Close();

                // return the mashed up file path
                return(outputFile);
            }
            catch (Exception)
            {
                // TODO: handle exception
                throw;
            }
        }
Beispiel #22
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));
        }
Beispiel #23
0
 public MockSongPlayer(ISong s)
 {
     _mixer = new WaveMixerStream32();
     _mixer.AddInputStream(new WaveChannel32(new ClickTrackStream(s.Beats)));
 }
Beispiel #24
0
 public MockSongPlayer(ISong s)
 {
     _mixer = new WaveMixerStream32();
     _mixer.AddInputStream(new WaveChannel32(new Jammit.Audio.ClickTrackStream(s.Beats, Properties.Resources.stick)));
 }
        private static void AddInstrumentStreamsToMixer(Pattern pattern, int bpm, WaveMixerStream32 finalMixer, StreamTracker streamTracker)
        {
            double minutesPerBeat = 1d / (double)bpm;
            int    msPerBeat      = (int)(minutesPerBeat * 60d * 1000d);

            foreach (var instrument in pattern.Instruments)
            {
                var audio = GetIeeeFloatWaveBytes(instrument, out int audioLen, out WaveFormat format);

                int avgBytesPerMs = format.AverageBytesPerSecond / 1000;
                int beatArrayLen  = avgBytesPerMs * msPerBeat;

                var instrumentMixer = new WaveMixerStream32();
                streamTracker.AddStream(instrumentMixer);

                int i = 0;

                var silence = new byte[beatArrayLen];

                foreach (var beat in instrument.Beats)
                {
                    if (beat.IsEnabled)
                    {
                        var mem = new IgnoreDisposeStream(new MemoryStream());
                        streamTracker.AddStream(mem);

                        using (var writer = new WaveFileWriter(mem, format))
                        {
                            // for each beat of the instrument after the first, pad the stream with silence before the beat position, eg:
                            // beat
                            // silence | beat
                            // silence | silence | beat
                            // etc., then mix all the streams together
                            for (int j = 0; j < i; ++j)
                            {
                                writer.Write(silence, 0, silence.Length);
                            }

                            writer.Write(audio, 0, audioLen);
                            writer.Flush();
                        }

                        mem.Position = 0;

                        instrumentMixer.AddInputStream(new WaveFileReader(mem));
                    }

                    ++i;
                }

                var instrumentStream = new IgnoreDisposeStream(new MemoryStream());
                streamTracker.AddStream(instrumentStream);

                WaveFileWriter.WriteWavFileToStream(instrumentStream, instrumentMixer);

                instrumentStream.Position = 0;

                var instrumentReader = new WaveFileReader(instrumentStream);

                finalMixer.AddInputStream(instrumentReader);
            }

            EnsureLength(pattern, msPerBeat, finalMixer, streamTracker);
        }