public void Initialize(Stream stream, AudioInfo audioInfo, MetadataDictionary metadata, SettingsDictionary settings) { Contract.Ensures(_stream != null); Contract.Ensures(_stream == stream); Contract.Ensures(_metadata != null); Contract.Ensures(_metadata == metadata); Contract.Ensures(_settings != null); Contract.Ensures(_settings == settings); Contract.Ensures(_audioFile != null); _stream = stream; _multiplier = (float)Math.Pow(2, audioInfo.BitsPerSample - 1); _metadata = metadata; _settings = settings; AudioStreamBasicDescription inputDescription = GetInputDescription(audioInfo); AudioStreamBasicDescription outputDescription = GetOutputDescription(inputDescription); try { _audioFile = new NativeExtendedAudioFile(outputDescription, AudioFileType.M4A, stream); ExtendedAudioFileStatus status = _audioFile.SetProperty(ExtendedAudioFilePropertyId.ClientDataFormat, inputDescription); if (status != ExtendedAudioFileStatus.Ok) { throw new IOException(string.Format(CultureInfo.CurrentCulture, Resources.SampleEncoderInitializationError, status)); } } catch (TypeInitializationException e) { if (e.InnerException != null && e.InnerException.GetType() == typeof(ExtensionInitializationException)) { throw e.InnerException; } throw; } }
public void Initialize(Stream stream, AudioInfo audioInfo, MetadataDictionary metadata, SettingsDictionary settings) { Contract.Ensures(_stream != null); Contract.Ensures(_stream == stream); Contract.Ensures(_metadata != null); Contract.Ensures(_metadata == metadata); Contract.Ensures(_settings != null); Contract.Ensures(_settings == settings); Contract.Ensures(_audioFile != null); _stream = stream; _metadata = metadata; _settings = settings; // Load the external gain filter: ExportFactory <ISampleFilter> sampleFilterFactory = ExtensionProvider.GetFactories <ISampleFilter>("Name", "ReplayGain").SingleOrDefault(); if (sampleFilterFactory == null) { throw new ExtensionInitializationException(Resources.AacSampleEncoderReplayGainFilterError); } _replayGainFilterLifetime = sampleFilterFactory.CreateExport(); _replayGainFilterLifetime.Value.Initialize(metadata, settings); AudioStreamBasicDescription inputDescription = GetInputDescription(audioInfo); AudioStreamBasicDescription outputDescription = GetOutputDescription(inputDescription); try { _audioFile = new NativeExtendedAudioFile(outputDescription, AudioFileType.M4A, stream); ExtendedAudioFileStatus status = _audioFile.SetProperty(ExtendedAudioFilePropertyId.ClientDataFormat, inputDescription); if (status != ExtendedAudioFileStatus.Ok) { throw new IOException(string.Format(CultureInfo.CurrentCulture, Resources.SampleEncoderInitializationError, status)); } // Configure the audio converter: ConfigureConverter(settings, audioInfo.Channels, _audioFile.GetProperty <IntPtr>(ExtendedAudioFilePropertyId.AudioConverter)); // Setting the ConverterConfig property to null resynchronizes the converter settings: ExtendedAudioFileStatus fileStatus = _audioFile.SetProperty( ExtendedAudioFilePropertyId.ConverterConfig, IntPtr.Zero); if (fileStatus != ExtendedAudioFileStatus.Ok) { throw new IOException(string.Format(CultureInfo.CurrentCulture, Resources.SampleEncoderConverterError, status)); } } catch (TypeInitializationException e) { if (e.InnerException != null && e.InnerException.GetType() == typeof(ExtensionInitializationException)) { throw e.InnerException; } throw; } }