public AudioConfigurator(
     ICurrentAudioConfiguration currentConfiguration,
     IAudioConfigurationChecker checker)
 {
     this.currentConfiguration = currentConfiguration;
     this.checker = checker;
 }
        private SoundFile Decode(Stream s)
        {
            IAudioDecoder decoder = new Mpg123();

            if (!decoder.IsAvailable)
            {
                decoder = new MP3AudioDecoder();
            }

            if (!decoder.IsAvailable)
            {
                throw new Exception("No mp3 decoder available!");
            }

            try
            {
                decoder.BeginDecode(s);
                using var data = new MemoryStream();
                var packet = decoder.Decode();
                IAudioConfiguration config = packet;
                while (packet != null)
                {
                    data.Write(packet.Data, 0, packet.Length);
                    packet = decoder.Decode();
                }
                return(new SoundFile(config, data.ToArray()));
            }
            finally
            {
                decoder.Close();
            }
        }
 /// <summary>
 /// Checks for equality with another IAudioConfiguration.
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public bool Equals(IAudioConfiguration other)
 {
     return(other == null
         ? false
         : (other.SamplingRate == SamplingRate) &&
            (other.Format == Format) &&
            (other.Channels == Channels));
 }
Example #4
0
 /// <summary>
 /// Signs that the provider has been attached to the Spectrum virtual machine
 /// </summary>
 public override void OnAttachedToVm(ISpectrumVm hostVm)
 {
     base.OnAttachedToVm(hostVm);
     _audioPars = Type == AudioProviderType.Beeper
         ? hostVm.AudioConfiguration :
                  hostVm.SoundConfiguration;
     WaveFormat = WaveFormat.CreateIeeeFloatWaveFormat(_audioPars.AudioSampleRate, 1);
     Reset();
 }
Example #5
0
        /// <summary>Obtains a new audio out stream.</summary>
        /// <param name="configuration">Audio configuration to use.</param>
        /// <returns></returns>
        /// <exception cref="ObjectDisposedException">OpenALOutputDevice.</exception>
        public AudioOut CreateAudioOut(IAudioConfiguration configuration)
        {
            if (Handle == IntPtr.Zero)
            {
                OpenHandles();
            }

            return(new OALOut(this, configuration));
        }
Example #6
0
 /// <summary>
 /// Signs that the device has been attached to the Spectrum virtual machine
 /// </summary>
 public void OnAttachedToVm(ISpectrumVm hostVm)
 {
     HostVm = hostVm;
     _audioConfiguration = hostVm.AudioConfiguration;
     _beeperProvider     = hostVm.BeeperProvider;
     _frameTacts         = hostVm.FrameTacts;
     _tactsPerSample     = _audioConfiguration.TactsPerSample;
     Reset();
 }
Example #7
0
 /// <summary>
 /// Signs that the device has been attached to the Spectrum virtual machine
 /// </summary>
 public void OnAttachedToVm(ISpectrumVm hostVm)
 {
     HostVm = hostVm;
     _soundConfiguration = hostVm.SoundConfiguration;
     _soundProvider      = hostVm.SoundProvider;
     _frameTacts         = hostVm.FrameTacts;
     _tactsPerSample     = _soundConfiguration.TactsPerSample;
     _lpf = new BandPassFilter(32, _soundConfiguration.AudioSampleRate, 150.0, 8000.0);
     Reset();
 }
Example #8
0
 public VlcAudioJob(IAudioConfiguration audioConfig, IPortAllocator allocator, IStatusParser statusParser, IVlcStatusSource statusSouce, ITimeSouce timeSouce, ILogger logger)
     : base(allocator, statusParser, statusSouce, timeSouce, logger)
 {
     if (audioConfig == null)
     {
         var argumentNullException = new ArgumentNullException("audioConfig");
         logger.Error(argumentNullException);
         throw argumentNullException;
     }
     AudioConfiguration = audioConfig;
 }
Example #9
0
 public VlcAudioJob(IAudioConfiguration audioConfig, IPortAllocator allocator, IStatusParser statusParser, IVlcStatusSource statusSouce, ITimeSouce timeSouce, ILogger logger)
     : base(allocator, statusParser, statusSouce, timeSouce, logger)
 {
     if(audioConfig == null)
     {
         var argumentNullException = new ArgumentNullException("audioConfig");
         logger.Error(argumentNullException);
         throw argumentNullException;
     }
     AudioConfiguration = audioConfig;
 }
Example #10
0
 internal OALOut(OALDevice dev, IAudioConfiguration configuration)
     : base(dev, configuration)
 {
     // m_BufferSize = configuration.BytesPerTick * Math.Max(1, configuration.SamplingRate / OAL.BuffersPerSecond);
     m_Device = dev;
     lock (OAL.SyncRoot)
     {
         OAL.SafeNativeMethods.alcMakeContextCurrent(m_Device.Context);
         OAL.SafeNativeMethods.alGenSources(1, out m_Source);
         OAL.SafeNativeMethods.alSourcei(m_Source, OAL.AL_LOOPING, OAL.AL_FALSE);
         OAL.SafeNativeMethods.CheckError();
         Position3D = Vector3.Create(0, 0, 0);
     }
 }
 public void Check(IAudioConfiguration configuration)
 {
     if (configuration == null)
     {
         throw new InvalidAudioConfigurationException(AudioConfigSetFailReason.IsNull);
     }
     if (configuration.ChannelsCount > MaxChannelsCount)
     {
         throw new InvalidAudioConfigurationException(AudioConfigSetFailReason.ChannelsCounСontradictsСonstraints);
     }
     if (configuration.IsStereo && configuration.ChannelsCount < MaxChannelsCount)
     {
         throw new InvalidAudioConfigurationException(AudioConfigSetFailReason.ChannelsCountContradictsChannelsMode);
     }
 }
        /// <summary>
        /// Creates a new <see cref="AudioDeviceCapabilities"/> object.
        /// </summary>
        /// <param name="devType">The device type.</param>
        /// <param name="outputConfigurations">The available output configurations.</param>
        /// <param name="inputConfigurations">The available input configurations.</param>
        public AudioDeviceCapabilities(AudioDeviceType devType, IAudioConfiguration[] outputConfigurations, IAudioConfiguration[] inputConfigurations)
        {
            Type = devType;
            if (outputConfigurations == null)
            {
                outputConfigurations = new IAudioConfiguration[0];
            }

            if (inputConfigurations == null)
            {
                inputConfigurations = new IAudioConfiguration[0];
            }

            m_OutputConfigurations = outputConfigurations;
            m_InputConfigurations  = inputConfigurations;
        }
        /// <summary>
        /// Creates a new <see cref="AudioDeviceCapabilities"/> object.
        /// </summary>
        /// <param name="devType"></param>
        /// <param name="configurations"></param>
        public AudioDeviceCapabilities(AudioDeviceType devType, params IAudioConfiguration[] configurations)
        {
            Type = devType;
            if (configurations == null)
            {
                configurations = new IAudioConfiguration[0];
            }

            if ((Type & AudioDeviceType.Input) != 0)
            {
                m_InputConfigurations = configurations;
            }
            if ((Type & AudioDeviceType.Output) != 0)
            {
                m_OutputConfigurations = configurations;
            }
        }
Example #14
0
 /// <summary>
 /// Resets the renderer device
 /// </summary>
 public override void Reset()
 {
     try
     {
         _waveOut?.Dispose();
     }
     catch
     {
         // --- We ignore this exception deliberately
     }
     _audioPars = Type == AudioProviderType.Beeper
         ? HostVm.AudioConfiguration :
                  HostVm.SoundConfiguration;
     WaveFormat    = WaveFormat.CreateIeeeFloatWaveFormat(_audioPars.AudioSampleRate, 1);
     _waveOut      = null;
     _bufferLength = (_audioPars.SamplesPerFrame + 1) * FRAMES_BUFFERED;
     _waveBuffer   = new float[_bufferLength];
     _frameCount   = 0;
     _writeIndex   = 0;
     _readIndex    = 0;
 }
Example #15
0
        /// <summary>Initializes a new instance of the <see cref="PAOut"/> class.</summary>
        /// <param name="dev">The device to use.</param>
        /// <param name="configuration">The configuration to use.</param>
        /// <exception cref="NotSupportedException">
        /// </exception>
        /// <exception cref="Exception"></exception>
        internal PAOut(IAudioDevice dev, IAudioConfiguration configuration)
            : base(dev, configuration)
        {
            var l_OutputParameters = new PAStreamParameters();

            switch (configuration.ChannelSetup)
            {
            case AudioChannelSetup.Mono:
            case AudioChannelSetup.Stereo:
                l_OutputParameters.ChannelCount = configuration.Channels; break;

            default: throw new NotSupportedException(string.Format("Audio channel setup {0} not supported!", configuration.ChannelSetup));
            }
            switch (configuration.Format)
            {
            case AudioSampleFormat.Float: l_OutputParameters.SampleFormat = PASampleFormat.Float32; break;

            case AudioSampleFormat.Int8: l_OutputParameters.SampleFormat = PASampleFormat.Int8; break;

            case AudioSampleFormat.Int16: l_OutputParameters.SampleFormat = PASampleFormat.Int16; break;

            case AudioSampleFormat.Int24: l_OutputParameters.SampleFormat = PASampleFormat.Int24; break;

            case AudioSampleFormat.Int32: l_OutputParameters.SampleFormat = PASampleFormat.Int32; break;

            default: throw new NotSupportedException(string.Format("Audio format {0} not supported!", configuration.Format));
            }
            l_OutputParameters.Device = ((PADevice)dev).DeviceIndex;

            SamplesPerBuffer   = Math.Max(1, configuration.SamplingRate / PA.BuffersPerSecond);
            BufferSize         = configuration.BytesPerTick * SamplesPerBuffer;
            m_CallbackDelegate = new PA.StreamCallbackDelegate(Callback);
            PAErrorCode l_ErrorCode = PA.SafeNativeMethods.Pa_OpenStream(out m_StreamHandle, IntPtr.Zero, ref l_OutputParameters, configuration.SamplingRate, (uint)SamplesPerBuffer, PAStreamFlags.ClipOff, m_CallbackDelegate, IntPtr.Zero);

            if (l_ErrorCode != PAErrorCode.NoError)
            {
                throw new Exception(PA.GetErrorText(l_ErrorCode));
            }
        }
Example #16
0
 /// <summary>
 /// Creates a new audio stream for the specified device.
 /// </summary>
 /// <param name="device">The device to use.</param>
 /// <param name="configuration">The configuration to use.</param>
 protected internal AudioOut(IAudioDevice device, IAudioConfiguration configuration)
 {
     Device        = device ?? throw new ArgumentNullException(nameof(device));
     Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
 }
Example #17
0
 public VlcVideoJob(IVideoConfiguration videoConfiguration, IAudioConfiguration audioConfiguration, IPortAllocator allocator, IStatusParser statusParser, IVlcStatusSource statusSouce, ITimeSouce timeSouce, ILogger logger)
     : base(allocator, statusParser, statusSouce, timeSouce, logger)
 {
     VideoConfiguration = videoConfiguration;
     AudioConfiguration = audioConfiguration;
 }
Example #18
0
 /// <summary>
 /// Gets a new audio queue (sound target/source).
 /// </summary>
 /// <param name="configuration">The desired AudioConfiguration.</param>
 /// <returns>Returns an IAudioQueue or IAudioQueue3D.</returns>
 public abstract AudioOut CreateAudioOut(IAudioConfiguration configuration);
Example #19
0
 void UpdateFormat()
 {
     m_CurrentConfig = M123.SafeNativeMethods.mpg123_getformat(m_DecoderHandle);
 }
Example #20
0
 /// <summary>Obtains a new audio queue (sound target/source).</summary>
 /// <param name="configuration">The desired AudioConfiguration.</param>
 /// <returns>Returns an IAudioQueue or IAudioQueue3D.</returns>
 public override AudioOut CreateAudioOut(IAudioConfiguration configuration)
 {
     return(new PAOut(this, configuration));
 }
Example #21
0
 /// <summary>Gets a new audio queue (sound target/source).</summary>
 /// <param name="configuration">The desired AudioConfiguration.</param>
 /// <returns>Returns an IAudioQueue or IAudioQueue3D.</returns>
 public override AudioOut CreateAudioOut(IAudioConfiguration configuration) => new PAOut(this, configuration);
Example #22
0
 public VlcVideoJob(IVideoConfiguration videoConfiguration, IAudioConfiguration audioConfiguration, IPortAllocator allocator, IStatusParser statusParser, IVlcStatusSource statusSouce, ITimeSouce timeSouce, ILogger logger)
     : base(allocator, statusParser, statusSouce, timeSouce, logger)
 {
     VideoConfiguration = videoConfiguration;
     AudioConfiguration = audioConfiguration;
 }
Example #23
0
 /// <summary>Initializes a new instance of the <see cref="AudioData"/> class.</summary>
 /// <param name="config">The configuration.</param>
 /// <param name="data">The data.</param>
 public AudioData(IAudioConfiguration config, byte[] data)
     : base(config.SamplingRate, config.Format, config.Channels)
 {
     this.data   = data;
     SampleCount = data.Length / BytesPerSample;
 }
Example #24
0
 public AudioWizardStepStep(IAudioConfiguration audioConfiguration, IRadioFactory radioFactory)
 {
     _audioConfiguration = audioConfiguration;
     _radioFactory = radioFactory;
 }
Example #25
0
 /// <summary>Initializes a new instance of the <see cref="SoundFile"/> class.</summary>
 /// <param name="config">The configuration.</param>
 /// <param name="data">The data.</param>
 public SoundFile(IAudioConfiguration config, byte[] data)
 {
     Config = config;
     Data   = data;
 }
 public void SetConfiguation(IAudioConfiguration configuration)
 {
     checker.Check(configuration);
     currentConfiguration = configuration;
 }