Пример #1
0
        private async void encode(object sender, RoutedEventArgs e)
        {
            // player.Stop();
            LameWrapper lame = new LameWrapper();

            lame.InitialLame(44100, 44100, 2, 5);
            IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();

            using (IsolatedStorageFileStream WorkStream = isf.CreateFile("encoded_mp3.mp3"))
            {
                using (PCMStream = isf.OpenFile("/decoded_pcm.pcm", FileMode.Open))
                {
                    int totalread = 0;
                    while (PCMStream.Position < PCMStream.Length)
                    {
                        byte[] rawbytes = new byte[65536];

                        int actualcount = PCMStream.Read(rawbytes, 0, 65536);
                        //  MessageBox.Show("read:" + actualcount);
                        totalread         += actualcount;
                        PCMStream.Position = totalread;
                        IBuffer PCMSampleBuffer = WindowsRuntimeBufferExtensions.AsBuffer(rawbytes, 0, rawbytes.Length);

                        CompressedMp3Content citem = await lame.EncodePcm2Mp3(PCMSampleBuffer);

                        //  MessageBox.Show(citem.Mp3Data.Length+"");
                        WorkStream.Write(citem.Mp3Data, 0, citem.Mp3Data.Length);
                        WorkStream.Flush();
                        statustb.Text = "position: " + PCMStream.Position + " total: " + PCMStream.Length;
                    }
                }
            }

            isf.Dispose();
            lame.CloseLame();
        }
Пример #2
0
        private async void encode(object sender, RoutedEventArgs e)
        {
           // player.Stop();
            LameWrapper lame = new LameWrapper();
            lame.InitialLame(44100, 44100, 2, 5);
            IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
            using (IsolatedStorageFileStream WorkStream = isf.CreateFile("encoded_mp3.mp3"))
            {
                using (PCMStream = isf.OpenFile("/decoded_pcm.pcm", FileMode.Open))
                {
                    int totalread=0;
                    while (PCMStream.Position<PCMStream.Length)
                    {
                        byte[] rawbytes=new byte[65536];

                        int actualcount=PCMStream.Read(rawbytes, 0, 65536);
                      //  MessageBox.Show("read:" + actualcount);
                        totalread += actualcount;
                        PCMStream.Position = totalread;
                        IBuffer PCMSampleBuffer = WindowsRuntimeBufferExtensions.AsBuffer(rawbytes, 0, rawbytes.Length);
                     
                        CompressedMp3Content citem = await lame.EncodePcm2Mp3(PCMSampleBuffer);
                      //  MessageBox.Show(citem.Mp3Data.Length+"");
                        WorkStream.Write(citem.Mp3Data, 0, citem.Mp3Data.Length);
                        WorkStream.Flush();
                        statustb.Text = "position: " + PCMStream.Position + " total: " + PCMStream.Length ;
                    }
                }
            }

            isf.Dispose();
            lame.CloseLame();
        }