Ejemplo n.º 1
0
        public void MixAudio(Dictionary <String, int[]> songsXtimes)
        {
            lastFile = targetFile += "_" + DateTime.Now.ToString();
            toMix    = new List <WaveFileReader>();
            WaveMixerStream32 combined = null;

            foreach (String s in songsXtimes.Keys)
            {
                PrepareClip(s, songsXtimes[s]);
                //chop it up and add it to toMix
            }
            combined = Combine();


            Wave32To16Stream wavmixer = new Wave32To16Stream(combined);

            WaveFileWriter.CreateWaveFile(targetFile, wavmixer);
            wavmixer.Dispose();
            combined.Dispose();

            /*
             * byte[] b = new byte[combined.Length];
             * int len = (int)combined.Length;
             * combined.Read(b,0,len);
             * combined.Close();
             * WaveFileWriter wv = new WaveFileWriter(targetFile, combined.WaveFormat);
             * wv.Write(b, 0, (int)combined.Length);
             * */
            return;
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
 public void Dispose()
 {
     try
     {
         _wavePlayer.Dispose();
         _mixer.Dispose();
         _wavePlayer = null;
         _mixer      = null;
     }
     catch (Exception e)
     {
         Handle(e);
     }
 }
Ejemplo n.º 4
0
 private void MixDiffForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (playbackStatus != PlaybackStatus.Stopped)
     {
         Stop();
     }
     if (wavePlayer != null)
     {
         wavePlayer.Dispose();
         wavePlayer = null;
     }
     if (mixer != null)
     {
         mixer.Dispose();
         mixer = null;
     }
 }
Ejemplo n.º 5
0
        private static void mainOutput_PlaybackStopped(object sender, EventArgs e)
        {
            try
            {
                mainOutput.Stop();

                mainOutput.Dispose();
                mixerin.Dispose();
                mixerin.Close();
                mainOutput = null;
                mixerin    = null;


                Thread.Sleep(400);

                onLoop();
            }
            catch (Exception erri)
            {
                onError(erri.Message);
            }
        }