c# - Mix two or more mp3 files into one, keeping high performance -


i have problem mixing 2 mp3 files one. actually, i've found test code using naudio library, slow me. new "audio programming" need help, advice how make algorithm solving problem faster code below.

the code mixes 2 files 1 in 8+seconds much slow. actually, checked , convertwavtomp3() lasts 8 seconds. files 1.mp3 , 2.mp3 3+ minutes long.

    static void main(string[] args)     {         var watch = stopwatch.startnew();         watch.start();         var path = @"c:\users\gutek\desktop\";         // read mp3 files disk         mp3filereader mpbacground = new mp3filereader(path + "1.mp3");         mp3filereader mpmessage = new mp3filereader(path + "2.mp3");          //convert them wave stream or decode mp3 file         wavestream background = waveformatconversionstream.createpcmstream(mpbacground);         wavestream message = waveformatconversionstream.createpcmstream(mpmessage);          var mixer = new wavemixerstream32();         mixer.autostop = true;          var messageoffset = background.totaltime;         var messageoffsetted = new waveoffsetstream(         message, timespan.fromseconds(10), timespan.zero, message.totaltime.subtract(timespan.fromseconds(30)));          var background32 = new wavechannel32(background);         background32.padwithzeroes = false;         // set volume of background file         background32.volume = 0.4f;         //add stream mixer         mixer.addinputstream(background32);          var message32 = new wavechannel32(messageoffsetted);         message32.padwithzeroes = false;         // set volume of 2nd mp3 song         message32.volume = 0.6f;         mixer.addinputstream(message32);         var wave32 = new wave32to16stream(mixer);         //encode wave stream mp3         var mp3stream = convertwavtomp3(wave32);         // write mp3 on disk         file.writeallbytes(path + "output.mp3", mp3stream.toarray());         watch.stop();         console.writeline(watch.elapsedmilliseconds);         console.readkey();     }      public static memorystream convertwavtomp3(wave32to16stream wavfile)     {         using (var retms = new memorystream())         using (var wtr = new lamemp3filewriter(retms, wavfile.waveformat, 128))         {             wavfile.copyto(wtr);             return retms;         }     } 


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -