コード例 #1
0
ファイル: DirectSound.cs プロジェクト: Nezz/SharpDX
 /// <summary>
 /// Retrieves the speaker configuration of the device.
 /// </summary>
 /// <param name="speakerSet" />
 /// <param name="geometry" />
 public void GetSpeakerConfiguration(out SpeakerConfiguration speakerSet, out SpeakerGeometry geometry)
 {
     int speakerConfig;
     GetSpeakerConfiguration(out speakerConfig);
     speakerSet = (SpeakerConfiguration)(speakerConfig & 0xFFFF);
     geometry = (SpeakerGeometry)(speakerConfig >> 16);
 }
コード例 #2
0
        /// <summary>
        /// Retrieves the speaker configuration of the device.
        /// </summary>
        /// <param name="speakerSet" />
        /// <param name="geometry" />
        public void GetSpeakerConfiguration(out SpeakerConfiguration speakerSet, out SpeakerGeometry geometry)
        {
            int speakerConfig;

            GetSpeakerConfiguration(out speakerConfig);
            speakerSet = (SpeakerConfiguration)(speakerConfig & 0xFFFF);
            geometry   = (SpeakerGeometry)(speakerConfig >> 16);
        }
コード例 #3
0
        public WaveFormatExtensible(SampleRate rate, BitDepth bits, SpeakerConfiguration channelMask, Guid subFormat)
            : base(rate, bits, channelMask, WaveFormatEncoding.Extensible, Marshal.SizeOf(typeof(WaveFormatExtensible)))
        {
            wValidBitsPerSample = (short)bits;
            dwChannelMask       = (int)channelMask;

            this.subFormat = subFormat;
        }
コード例 #4
0
ファイル: DSound.cs プロジェクト: yplassiard/Three-D-Velocity
        /// <summary>
        /// Pans a sound.
        /// This method was written using the guide at https://docs.microsoft.com/en-us/windows/win32/xaudio2/how-to--pan-a-sound
        /// </summary>
        /// <param name="sound">The sound to pan.</param>
        /// <param name="pan">The value by which to pan the sound. -1.0f is completely left, and 1.0f is completely right. 0.0f is center.</param>
        public static void setPan(ExtendedAudioBuffer sound, float pan)
        {
            SpeakerConfiguration mask = (SpeakerConfiguration)mainMasteringVoice.ChannelMask;

            float[] outputMatrix = new float[8];
            float   left         = 0.5f - pan / 2;
            float   right        = 0.5f + pan / 2;

            switch (mask)
            {
            case SpeakerConfiguration.mono:
                outputMatrix[0] = 1.0f;
                break;

            case SpeakerConfiguration.stereo:
            case SpeakerConfiguration.twoPointOne:
            case SpeakerConfiguration.surround:
                outputMatrix[0] = left;
                outputMatrix[1] = right;
                break;

            case SpeakerConfiguration.quad:
                outputMatrix[0] = outputMatrix[2] = left;
                outputMatrix[1] = outputMatrix[3] = right;
                break;

            case SpeakerConfiguration.fourPointOne:
                outputMatrix[0] = outputMatrix[3] = left;
                outputMatrix[1] = outputMatrix[4] = right;
                break;

            case SpeakerConfiguration.fivePointOne:
            case SpeakerConfiguration.sevenPointOne:
            case SpeakerConfiguration.fivePointOneSurround:
                outputMatrix[0] = outputMatrix[4] = left;
                outputMatrix[1] = outputMatrix[5] = right;
                break;

            case SpeakerConfiguration.sevenPointOneSurround:
                outputMatrix[0] = outputMatrix[4] = outputMatrix[6] = left;
                outputMatrix[1] = outputMatrix[5] = outputMatrix[7] = right;
                break;
            }
            VoiceDetails soundDetails     = sound.getVoiceDetails();
            VoiceDetails masteringDetails = mainMasteringVoice.VoiceDetails;

            sound.setOutputMatrix(soundDetails.InputChannelCount, masteringDetails.InputChannelCount, outputMatrix);
        }
コード例 #5
0
ファイル: WaveFormat.cs プロジェクト: C0smin/AudioSwitcher
        protected WaveFormat(SampleRate rate, BitDepth bits, SpeakerConfiguration channelMask, WaveFormatEncoding formatTag, int totalSize)
        {
            channels = ChannelsFromMask((int)channelMask);

            if (channels < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(channelMask), "Channels must be 1 or greater");
            }

            sampleRate    = (int)rate;
            bitsPerSample = (short)bits;
            extraSize     = 0;

            blockAlign            = (short)(channels * (bitsPerSample / 8));
            averageBytesPerSecond = sampleRate * blockAlign;

            waveFormatTag = formatTag;
            extraSize     = (short)(totalSize - Marshal.SizeOf(typeof(WaveFormat)));
        }
コード例 #6
0
        public void EnableSpeaker(SpeakerConfiguration config)
        {
            //using (AsyncReadState state = BeginAsyncRead()) {
            //byte[] buff = CreateReport(OutputReport.SpeakerEnable);
            SetSpeakerEnabled(true);
            SetSpeakerMuted(true);
            WriteByte(Registers.Speaker1, 0x01);
            //WriteByte(Registers.SpeakerConfig, 0x80);
            WriteByte(Registers.SpeakerConfig, 0x08);
            WriteData(Registers.SpeakerConfig, 7, config.ToBytes());

            /*WriteByte(Registers.Speaker1, 0x55);
             * WriteByte(Registers.SpeakerConfig, 0x08);
             * WriteData(Registers.SpeakerConfig, 7, config.ToBytes());
             * WriteByte(Registers.Speaker2, 0x01);
             * SetSpeakerMuted(false);*/
            WriteByte(Registers.Speaker2, 0x01);
            SetSpeakerMuted(false);
            speakerConfig = config;
            wiimoteState.Status.Speaker = true;
            //}
        }
コード例 #7
0
        private void OnPlayWiimote(object sender, RoutedEventArgs e)
        {
            player.Stop();
            SpeakerConfiguration config = new SpeakerConfiguration {
                Volume = volume,
                //Unknown2 = 0x0c,
                //Unknown3 = 0x0e,
                SampleRate = sampleRate,
                Format     = speakerFormat,
            };

            Wiimote?.DisableSpeaker();
            Wiimote?.EnableSpeaker(config);
            Thread.Sleep(100);
            Wiimote?.DisableSpeaker();
            Wiimote?.EnableSpeaker(config);
            //byte[] configData = Wiimote.ReadData(0x04a20001, 7);
            //if (soundObj is PrebufferedSound prebuffered)
            //	Wiimote?.PlaySound(prebuffered);
            //else
            Wiimote?.PlaySound((byte[])soundObj);
            waveform.Play();
        }
コード例 #8
0
        public void Open(string scriptPath)
        {
            lock (locker)
            {
                try
                {
                    script = scriptPath;
                    LoadAviSynth();

                    if (IsError || IsAborted)
                    {
                        return;
                    }

                    if (HasVideo)
                    {
                        try
                        {
                            //Framework 3.0 с SP1+
                            CreateInteropBitmap();
                        }
                        catch (TypeLoadException)
                        {
                            //Framework 3.0 без SP1
                            CreateWriteableBitmap();
                        }
                    }

                    if (HasAudio)
                    {
                        SetUpAudioDevice();
                    }

                    #region ShowPictureViewInfo
                    if (HasVideo && reader.GetVarBoolean("ShowPictureViewInfo", false))
                    {
                        SpeakerConfiguration conf = 0; SpeakerGeometry geom = 0;
                        if (HasAudio)
                        {
                            AudioDevice.GetSpeakerConfiguration(out conf, out geom);
                        }

                        Stopwatch sw = Stopwatch.StartNew();
                        for (int i = 0; i < 100; i++)
                        {
                            Thread.Sleep(1);
                        }
                        sw.Stop();

                        Message mes = new Message(Owner);
                        mes.ShowMessage("Video\r\n  Resolution: " + reader.Width + "x" + reader.Height + ", FrameRate: " + reader.Framerate + ", Format: " +
                                        reader.Clip.OriginalColorspace + ((reader.Clip.OriginalColorspace != AviSynthColorspace.RGB32) ? "->RGB32" : "") + " \r\n  Output: " +
                                        ((IsInterop) ? "InteropBitmap" : "WriteableBitmap (Install SP1 for .NET Framework 3.0!)") + "\r\n\r\nAudio\r\n" +
                                        ((HasAudio) ? "  Bits: " + BufferDesc.Format.BitsPerSample + ((reader.Clip.SampleType == AudioSampleType.FLOAT) ? " FLOAT" : "") +
                                         ", SampleRate: " + BufferDesc.Format.SampleRate + ", Channels: " + BufferDesc.Format.Channels + ((BufferDesc.Format.Encoding == WaveFormatEncoding.Extensible) ?
                                                                                                                                          ", Mask: " + ((WaveFormatExtensible)BufferDesc.Format).ChannelMask + " (" + (int)((WaveFormatExtensible)BufferDesc.Format).ChannelMask + ")" : "") +
                                         "\r\n  PrimaryBuffers: " + AudioDevice.Capabilities.PrimaryBuffers + ", MixingBuffers: " + AudioDevice.Capabilities.MaxHardwareMixingAllBuffers +
                                         " (" + AudioDevice.Capabilities.FreeHardwareMixingAllBuffers + "), 3DBuffers: " + AudioDevice.Capabilities.MaxHardware3DAllBuffers + " (" +
                                         AudioDevice.Capabilities.FreeHardware3DAllBuffers + "), MemBytes: " + AudioDevice.Capabilities.TotalHardwareMemBytes + " (" +
                                         AudioDevice.Capabilities.FreeHardwareMemBytes + "), SampleRate: " + AudioDevice.Capabilities.MinSecondarySampleRate + " - " +
                                         AudioDevice.Capabilities.MaxSecondarySampleRate + (((AudioDevice.Capabilities.Flags & CapabilitiesFlags.ContinousRate) > 0) ? " (continuous)" : "") +
                                         "\r\n  SpeakerConfiguration: " + conf + ", SpeakerGeometry: " + geom + "\r\n" : "  None" + ((!EnableAudio) ? " (disabled)" : "") + "\r\n") +
                                        "\r\nTimers\r\n  Sleep(100): " + sw.ElapsedMilliseconds + ", HighResolutionStopwatch: " + Stopwatch.IsHighResolution, Languages.Translate("Info"));
                    }
                    #endregion
                }
                catch (Exception ex)
                {
                    SetError(ex);
                }
            }
        }
コード例 #9
0
 /// <summary>
 /// Sets the speaker configuration of the device.
 /// </summary>
 /// <param name="speakerSet" />
 /// <param name="geometry" />
 public void SetSpeakerConfiguration(SpeakerConfiguration speakerSet, SpeakerGeometry geometry)
 {
     SetSpeakerConfiguration(((int)speakerSet) | (((int)geometry) << 16));
 }
コード例 #10
0
ファイル: DirectSound.cs プロジェクト: Nezz/SharpDX
 /// <summary>
 /// Sets the speaker configuration of the device.
 /// </summary>
 /// <param name="speakerSet" />
 /// <param name="geometry" />
 public void SetSpeakerConfiguration(SpeakerConfiguration speakerSet, SpeakerGeometry geometry)
 {
     SetSpeakerConfiguration(((int)speakerSet) | (((int)geometry) << 16));
 }
コード例 #11
0
 /// <summary>
 /// Creates a new WaveFormatExtensible for PCM
 /// KSDATAFORMAT_SUBTYPE_PCM
 /// </summary>
 public WaveFormatExtensible(SampleRate rate, BitDepth bits, SpeakerConfiguration channelMask)
     : this(rate, bits, channelMask, new Guid("00000001-0000-0010-8000-00AA00389B71"))
 {
     wValidBitsPerSample = (short)bits;
     dwChannelMask       = (int)channelMask;
 }
コード例 #12
0
ファイル: WaveFormat.cs プロジェクト: C0smin/AudioSwitcher
 public WaveFormat(SampleRate rate, BitDepth bits, SpeakerConfiguration channelMask)
     : this(rate, bits, channelMask, WaveFormatEncoding.Pcm, Marshal.SizeOf(typeof(WaveFormat)))
 {
 }
コード例 #13
0
 /// <summary>Converts a <see cref="SpeakerConfiguration"/> to an <see cref="AudioChannels"/> value.</summary>
 /// <param name="speakerConfiguration">A speaker configuration.</param>
 /// <returns>Returns an <see cref="AudioChannels"/> value representing the specified <paramref name="speakerConfiguration"/>.</returns>
 public static AudioChannels ToAudioChannels(this SpeakerConfiguration speakerConfiguration)
 {
     return((AudioChannels)speakerConfiguration);
 }
コード例 #14
0
 /// <summary>Returns the index of an audio channel in a speaker configuration, or -1.</summary>
 /// <param name="speakerConfiguration">A speaker configuration.</param>
 /// <param name="channel">An audio channel.</param>
 /// <returns>Returns the index of the specified <paramref name="channel"/> in the <paramref name="speakerConfiguration"/>, or -1.</returns>
 public static int GetChannelIndex(this SpeakerConfiguration speakerConfiguration, AudioChannels channel)
 {
     return(GetChannelIndex((AudioChannels)speakerConfiguration, channel));
 }
コード例 #15
0
 /// <summary>Returns the number of channels corresponding to a <see cref="SpeakerConfiguration"/>.</summary>
 /// <param name="speakerConfiguration">A <see cref="SpeakerConfiguration"/> value.</param>
 /// <returns>Returns the number of channels set.</returns>
 public static int GetChannelCount(this SpeakerConfiguration speakerConfiguration)
 {
     return(GetChannelCount((AudioChannels)speakerConfiguration));
 }