Example #1
0
        /// <summary>
        /// Преобразует поток с wav файлом в mp3
        /// </summary>
        /// <param name="wavFile"></param>
        public static void WavToMP3(string wavPath, string Mp3path)
        {
            using (Stream source = new FileStream(wavPath, FileMode.Open))
                using (Stream Mp3file = new FileStream(Mp3path, FileMode.Create))
                    using (NAudio.Wave.WaveFileReader rdr = new NAudio.Wave.WaveFileReader(source))
                    {
                        WaveLib.WaveFormat fmt = new WaveLib.WaveFormat(rdr.WaveFormat.SampleRate, rdr.WaveFormat.BitsPerSample, rdr.WaveFormat.Channels);

                        // convert to MP3 at 96kbit/sec...
                        Yeti.Lame.BE_CONFIG conf = new Yeti.Lame.BE_CONFIG(fmt, 96);

                        // Allocate a 1-second buffer
                        int    blen   = rdr.WaveFormat.AverageBytesPerSecond;
                        byte[] buffer = new byte[blen];

                        Yeti.MMedia.Mp3.Mp3Writer mp3 = new Yeti.MMedia.Mp3.Mp3Writer(Mp3file, fmt, conf);

                        int readCount;
                        while ((readCount = rdr.Read(buffer, 0, blen)) > 0)
                        {
                            mp3.Write(buffer, 0, readCount);
                        }

                        Mp3file.Flush();
                        mp3.Close();
                    }
        }
Example #2
0
        public static byte[] WavToMP3(byte[] wavFile)
        {
            using (MemoryStream source = new MemoryStream(wavFile))
                using (WaveFileReader rdr = new WaveFileReader(source))
                {
                    WaveLib.WaveFormat fmt = new WaveLib.WaveFormat(rdr.WaveFormat.SampleRate, rdr.WaveFormat.BitsPerSample, rdr.WaveFormat.Channels);

                    // convert to MP3 at 96kbit/sec...
                    Yeti.Lame.BE_CONFIG conf = new Yeti.Lame.BE_CONFIG(fmt, 96);

                    // Allocate a 1-second buffer
                    int    blen   = rdr.WaveFormat.AverageBytesPerSecond;
                    byte[] buffer = new byte[blen];

                    // Do conversion
                    using (MemoryStream output = new MemoryStream())
                    {
                        Yeti.MMedia.Mp3.Mp3Writer mp3 = new Yeti.MMedia.Mp3.Mp3Writer(output, fmt, conf);

                        int readCount;
                        while ((readCount = rdr.Read(buffer, 0, blen)) > 0)
                        {
                            mp3.Write(buffer, 0, readCount);
                        }

                        mp3.Close();
                        return(output.ToArray());
                    }
                }
        }
Example #3
0
        public void Start()
        {
            Stop();
            try
            {
                // Start Connection to Airport Express
                at        = new RAOPClient(ip);
                at.Volume = Volume;

                try
                {
                    at.Connect();
                }
                catch (Exception ex)
                {
                    at = null;

                    ErrorEventArgs e = new ErrorEventArgs();
                    e.Error     = ErrorEventArgs.ERRORNUMBER.ERRORCONNECTING;
                    e.Exception = ex;
                    ErrorEvent(e);

                    //Console.WriteLine("Connect failed: {0}", e.Message);
                    return;
                }


                string s = String.Format("JackStatus: {0}{1}JackType: {2}{3}",
                                         at.JackStatus == RAOPClient.JACK_STATUS_CONNECTED ?
                                         "connected" : "disconnected", Environment.NewLine,
                                         at.JackType == RAOPClient.JACK_TYPE_DIGITAL ?
                                         "digital" : "analog", Environment.NewLine);
                Console.WriteLine(s);


                // Start recorder

                //Get device here!!!
                WaveLib.WaveFormat fmt = new WaveLib.WaveFormat(44100, 16, 2);
                m_Recorder = new WaveLib.WaveInRecorder(deviceid, fmt, BufferSize, 16, new WaveLib.BufferDoneEventHandler(DataArrived));

                ConnectedEvent(EventArgs.Empty);
            }
            catch (Exception ex)
            {
                ErrorEventArgs e = new ErrorEventArgs();
                e.Error     = ErrorEventArgs.ERRORNUMBER.ERRORRECORDING;
                e.Exception = ex;
                ErrorEvent(e);

                at = null;
                Stop();
                //throw;
            }
        }
Example #4
0
        protected override void OnStreamingStartedResumed()
        {
            base.OnStreamingStartedResumed();

            WaveLib.WaveFormat waveFormat   = YetiWaveFormat;
            Mp3SoundFormat     outputFormat = (Mp3SoundFormat)OutputFormat;

            mp3Writer = new Yeti.MMedia.Mp3.Mp3Writer(Output,
                                                      waveFormat, new Yeti.Lame.BE_CONFIG(waveFormat, outputFormat.BitRate,
                                                                                          Yeti.Lame.LAME_QUALITY_PRESET.LQP_NORMAL_QUALITY), false);
        }
Example #5
0
 private void Start()
 {
     Stop();
     try
     {
         WaveLib.WaveFormat fmt = new WaveLib.WaveFormat(44100, 16, 2);
         m_Player   = new WaveLib.WaveOutPlayer(-1, fmt, 16384, 3, new WaveLib.BufferFillEventHandler(Filler));
         m_Recorder = new WaveLib.WaveInRecorder(-1, fmt, 16384, 3, new WaveLib.BufferDoneEventHandler(DataArrived));
     }
     catch
     {
         Stop();
         throw;
     }
 }
Example #6
0
 /// <summary>
 /// Начало записи/воспроизведения звука
 /// </summary>
 public void Start()
 {
     Stop();
     ThreadListen.Resume();
     try
     {
         WaveLib.WaveFormat fmt = new WaveLib.WaveFormat(22050, 16, 2);
         m_Player   = new WaveLib.WaveOutPlayer(-1, fmt, 32000, 5, new WaveLib.BufferFillEventHandler(Filler));
         m_Recorder = new WaveLib.WaveInRecorder(-1, fmt, 32000, 5, new WaveLib.BufferDoneEventHandler(DataSend));
     }
     catch
     {
         Stop();
         throw;
     }
 }
Example #7
0
 private void StartAudio()
 {
     StopAudio();
     try
     {
         // Rates: 44100, 22050, 88200
         // Valore buono: 44100, 16, 1 / Buffer 8192, 2
         //WaveLib.WaveFormat fmt = new WaveLib.WaveFormat(44100, 16, 2);
         //m_Player = new WaveLib.WaveOutPlayer(-1, fmt, 8192, 3, new WaveLib.BufferFillEventHandler(Filler));
         //m_Recorder = new WaveLib.WaveInRecorder(-1, fmt, 8192, 3, new WaveLib.BufferDoneEventHandler(SendAudioFrame));
         WaveLib.WaveFormat fmt = new WaveLib.WaveFormat(22050, 16, 1);
         m_Player   = new WaveLib.WaveOutPlayer(-1, fmt, 8192, 2, new WaveLib.BufferFillEventHandler(Filler));
         m_Recorder = new WaveLib.WaveInRecorder(-1, fmt, 8192, 2, new WaveLib.BufferDoneEventHandler(SendAudioFrame));
     }
     catch
     {
         StopAudio();
         throw;
     }
 }
Example #8
0
        public unsafe Recorder(string tempfilepath)
        {
            cb = new VorbisEnc.CircleBuffer();
            //ve = new VorbisEnc.VorbisEnc();
            ve = new VorbisEnc.FlacEncoder();
            //byte[] data = Encoding.GetBytes(tempfilepath);
            //filepath = System.Runtime.InteropServices.Marshal.AllocHGlobal(data.Length + 1);

            //System.Runtime.InteropServices.Marshal.Copy(data, 0, filepath, data.Length);
            //ve.Initialise((sbyte*)filepath.ToPointer());
            ve.Initialise((sbyte*)System.Runtime.InteropServices.Marshal.StringToHGlobalUni(tempfilepath).ToPointer());
            //System.Runtime.InteropServices.Marshal.FreeHGlobal(filepath);//need anymore?

            System.Threading.Thread th = new System.Threading.Thread(EncodeData);

            WaveLib.WaveFormat fmt = new WaveLib.WaveFormat(16000, 16, 1);
            m_Recorder = new WaveLib.WaveInRecorder(-1, fmt, 4096, 4, new WaveLib.BufferDoneEventHandler(DataArrived));

            th.Start();
        }
Example #9
0
        public unsafe Recorder(string tempfilepath)
        {
            cb = new VorbisEnc.CircleBuffer();
            //ve = new VorbisEnc.VorbisEnc();
            ve = new VorbisEnc.FlacEncoder();
            //byte[] data = Encoding.GetBytes(tempfilepath);
            //filepath = System.Runtime.InteropServices.Marshal.AllocHGlobal(data.Length + 1);

            //System.Runtime.InteropServices.Marshal.Copy(data, 0, filepath, data.Length);
            //ve.Initialise((sbyte*)filepath.ToPointer());
            ve.Initialise((sbyte *)System.Runtime.InteropServices.Marshal.StringToHGlobalUni(tempfilepath).ToPointer());
            //System.Runtime.InteropServices.Marshal.FreeHGlobal(filepath);//need anymore?

            System.Threading.Thread th = new System.Threading.Thread(EncodeData);

            WaveLib.WaveFormat fmt = new WaveLib.WaveFormat(16000, 16, 1);
            m_Recorder = new WaveLib.WaveInRecorder(-1, fmt, 4096, 4, new WaveLib.BufferDoneEventHandler(DataArrived));

            th.Start();
        }
Example #10
0
        public bool ConvertToWAV(string inPath, string outPath, uint sampleRate, uint sampleSize, uint channels)
        {
            WaveLib.WaveFormat fmt = new WaveLib.WaveFormat((int)sampleRate, (int)sampleSize, (int)channels);
            using (WmaStream str = new WmaStream(inPath, fmt)) {
                byte[] buffer = new byte[str.SampleSize * 2];

                AudioWriter writer = new WaveWriter(new FileStream(outPath, FileMode.Create), str.Format);
                try {
                    int read;
                    while ((read = str.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        writer.Write(buffer, 0, read);
                    }
                }
                finally {
                    writer.Close();
                }
            } //str.Close() is automatically called by Dispose.

            return(true);
        }
Example #11
0
        public void Start()
        {
            Stop();
            try
            {
                // Start Connection to Airport Express
                at = new RAOPClient(ip);
                at.Volume = Volume;

                try
                {
                    at.Connect();
                }
                catch (Exception ex)
                {
                    at = null;

                    ErrorEventArgs e = new ErrorEventArgs();
                    e.Error = ErrorEventArgs.ERRORNUMBER.ERRORCONNECTING;
                    e.Exception = ex;
                    ErrorEvent(e);

                    //Console.WriteLine("Connect failed: {0}", e.Message);
                    return;
                }

                string s = String.Format("JackStatus: {0}{1}JackType: {2}{3}",
                    at.JackStatus == RAOPClient.JACK_STATUS_CONNECTED ?
                    "connected" : "disconnected", Environment.NewLine,
                    at.JackType == RAOPClient.JACK_TYPE_DIGITAL ?
                    "digital" : "analog", Environment.NewLine);
                Console.WriteLine(s);

                // Start recorder

                //Get device here!!!
                WaveLib.WaveFormat fmt = new WaveLib.WaveFormat(44100, 16, 2);
                m_Recorder = new WaveLib.WaveInRecorder(deviceid, fmt, BufferSize, 16, new WaveLib.BufferDoneEventHandler(DataArrived));

                ConnectedEvent(EventArgs.Empty);
            }
            catch (Exception ex)
            {
                ErrorEventArgs e = new ErrorEventArgs();
                e.Error = ErrorEventArgs.ERRORNUMBER.ERRORRECORDING;
                e.Exception = ex;
                ErrorEvent(e);

                at = null;
                Stop();
                //throw;
            }
        }
Example #12
0
 public void Start()
 {
     Stop();
     refreshSettings();
     try	{
         WaveLib.WaveFormat fmt = new WaveLib.WaveFormat(
             Properties.Settings.Default.samplingRate,
             Properties.Settings.Default.samplingFormat,
             1);
         int device = PClapper.Properties.Settings.Default.inputDevice;
         recorder = new WaveLib.WaveInRecorder(
             device, fmt,
             Properties.Settings.Default.bufferLength,
             Properties.Settings.Default.numBuffers,
             new WaveLib.BufferDoneEventHandler(DataArrived)
             );
     }
     catch(Exception e) {
         Stop();
         MessageBox.Show(e.Message);
     }
 }
Example #13
0
 /// <summary>
 /// Начало записи/воспроизведения звука
 /// </summary>
 public void Start()
 {
     Stop();
     ThreadListen.Resume();
     try
     {
         WaveLib.WaveFormat fmt = new WaveLib.WaveFormat(22050, 16, 2);
         m_Player = new WaveLib.WaveOutPlayer(-1, fmt, 32000, 5, new WaveLib.BufferFillEventHandler(Filler));
         m_Recorder = new WaveLib.WaveInRecorder(-1, fmt, 32000, 5, new WaveLib.BufferDoneEventHandler(DataSend));
     }
     catch
     {
         Stop();
         throw;
     }
 }
Example #14
0
 private void Start()
 {
     Stop();
     try
     {
         WaveLib.WaveFormat fmt = new WaveLib.WaveFormat(44100, 16, 2);
         m_Player = new WaveLib.WaveOutPlayer(-1, fmt, 16384, 3, new WaveLib.BufferFillEventHandler(Filler));
         m_Recorder = new WaveLib.WaveInRecorder(-1, fmt, 16384, 3, new WaveLib.BufferDoneEventHandler(DataArrived));
     }
     catch
     {
         Stop();
         throw;
     }
 }