2016-05-04 3 views
1

Ici, j'ai utilisé le code ci-dessous pour convertir un fichier audio au format wav pour supprimer le bruit indésirable et une meilleure qualité.Ce code fonctionne très bien dans l'hôte local .. mais tandis que le code s'exécute une erreur comme:'' Impossible de charger la DLL 'mfplat.dll': Le module spécifié est introuvable. (Exception de HRESULT: 0x8007007E) "

Impossible de charger 'mfplat.dll' DLL. Le module spécifié n'a pas pu être trouvé (Exception de HRESULT: 0x8007007E)

et je suis en utilisant le codec audio pour NAudio n'importe qui trouver une solution pour cela, plz m'aider à le trier ..

static void ConversionTest(string _outfilename, string _infilename) 
    { 
     try 
     { 
      using(var reader = new MediaFoundationReader(_infilename)) 
      { 
       // Create a wave format for 16-bit pcm at 8000 samples per second. 
       int channels = reader.WaveFormat.Channels; 
       int rate = 8000; 
       int rawsize = 2; 
       int blockalign = rawsize * channels; // this is the size of one sample. 
       int bytespersecond = rate * blockalign; 
       var midformat = 
        WaveFormat.CreateCustomFormat(WaveFormatEncoding.Pcm, 
                rate, 
                channels, 
                bytespersecond, 
                blockalign, 
                rawsize * 8); 

       // And a conversion stream to turn input into 16-bit PCM. 
       var midstream = new MediaFoundationResampler(reader, midformat); 
       //var midstream = new WaveFormatConversionStream(midformat, reader); 

       // The output stream is our custom stream. 
       var outstream = new PcmToALawConversionStream(midstream); 


       WaveFileWriter.CreateWaveFile(_outfilename, outstream); 
      } 
     } 
     catch(Exception _ex) 
     { 
     } 
    } 

    } 

Et voici la classe qui convertit PCM 16 bits en A-Law ou en U-Law. A la fin des spécialisations pour A-Law ou U-LAW:

/// <summary> 
    /// Encodes 16-bit PCM input into A- or u-Law, presenting the output 
    /// as an IWaveProvider. 
    /// </summary> 
    public class PcmToG711ConversionStream : IWaveProvider 
    { 
     /// <summary>Gets the local a-law or u-law format.</summary> 
     public WaveFormat WaveFormat { get { return waveFormat; } } 

     /// <summary>Returns <paramref name="count"/> encoded bytes.</summary> 
     /// <remarks> 
     /// Note that <paramref name="count"/> is raw bytes. It doesn't consider 
     /// channel counts, etc. 
     /// </remarks> 
     /// <param name="buffer">The output buffer.</param> 
     /// <param name="offset">The starting position in the output buffer.</param> 
     /// <param name="count">The number of bytes to read.</param> 
     /// <returns>The total number of bytes encoded into <paramref name="buffer"/>.</returns> 
     public int Read(byte[] buffer, int offset, int count) 
     { 
      // We'll need a source buffer, twice the size of 'count'. 
      int shortcount = count*2; 
      byte [] rawsource = new byte [shortcount]; 
      int sourcecount = Provider.Read(rawsource, 0, shortcount); 
      int bytecount = sourcecount/2; 
      for(int index = 0; index < bytecount; ++index) 
      { 
       short source = BitConverter.ToInt16(rawsource, index*2); 
       buffer[offset+index] = Encode(source); 
      } 
      return bytecount; 
     } 


     /// <summary> 
     /// Initializes and A-Law or u-Law "WaveStream". The source stream 
     /// must be 16-bit PCM! 
     /// </summary> 
     /// <param name="_encoding">ALaw or MuLaw only.</param> 
     /// <param name="_sourcestream">The input PCM stream.</param> 
     public PcmToG711ConversionStream(WaveFormatEncoding _encoding, 
              IWaveProvider _provider) 
     { 
      Provider = _provider; 
      WaveFormat sourceformat = Provider.WaveFormat; 
      if((sourceformat.Encoding != WaveFormatEncoding.Pcm) && 
       (sourceformat.BitsPerSample != 16)) 
      { 
       throw new NotSupportedException("Input must be 16-bit PCM. Try using a conversion stream."); 
      } 

      if(_encoding == WaveFormatEncoding.ALaw) 
      { 
       Encode = this.EncodeALaw; 
       waveFormat = WaveFormat.CreateALawFormat(_provider.WaveFormat.SampleRate, 
                  _provider.WaveFormat.Channels) ; 

      } 
      else if(_encoding == WaveFormatEncoding.MuLaw) 
      { 
       Encode = this.EncodeMuLaw; 
       waveFormat = WaveFormat.CreateMuLawFormat(_provider.WaveFormat.SampleRate, 
                  _provider.WaveFormat.Channels) ; 
      } 
      else 
      { 
       throw new NotSupportedException("Encoding must be A-Law or u-Law"); 
      } 
     } 


     /// <summary>The a-law or u-law encoder delegate.</summary> 
     EncodeHandler Encode; 
     /// <summary>a-law or u-law wave format.</summary> 
     WaveFormat waveFormat; 
     /// <summary>The input stream.</summary> 
     IWaveProvider Provider; 

     /// <summary>A-Law or u-Law encoder delegate.</summary> 
     /// <param name="_sample">The 16-bit PCM sample to encode.</param> 
     /// <returns>The encoded value.</returns> 
     delegate byte EncodeHandler(short _sample); 

     byte EncodeALaw(short _sample) 
     { 
      return ALawEncoder.LinearToALawSample(_sample); 
     } 
     byte EncodeMuLaw(short _sample) 
     { 
      return MuLawEncoder.LinearToMuLawSample(_sample); 
     } 
    } 


    public class PcmToALawConversionStream : PcmToG711ConversionStream 
    { 
     public PcmToALawConversionStream(IWaveProvider _provider) 
      : base(WaveFormatEncoding.ALaw, _provider) 
     { 
     } 
    } 

    public class PcmToMuLawConversionStream : PcmToG711ConversionStream 
    { 
     public PcmToMuLawConversionStream(IWaveProvider _provider) 
      : base(WaveFormatEncoding.MuLaw, _provider) 
     { 
     } 
    } 
} 

Répondre

3

Media Foundation est une option sur les éditions Windows Server, vous devez l'installer. Quelques instructions here

+0

health J'ai installé Media Foundation sur Windows Server mais la même erreur s'affiche. – user4340020

+0

essayez également d'installer "Expérience de bureau" –

+0

Maintenant, il fonctionne bien ... Merci @ Santé Santé. – user4340020