Esempio n. 1
0
        private void ButtonActivateDevice_Click(object sender, RoutedEventArgs e)
        {
            int hr     = 0;
            int devIdx = mListBoxPlaybackDevices.SelectedIndex;

            Properties.Settings.Default.LastUsedDevice = mPlayer.SpatialAudio.DevicePropertyList[
                mListBoxPlaybackDevices.SelectedIndex].devIdStr;


            {
                int maxDynObjCount = 0;
                int staticObjMask  = WWSpatialAudioUser.DwChannelMaskToAudioObjectTypeMask(mPlayer.DwChannelMask);

                hr = mPlayer.SpatialAudio.ChooseDevice(devIdx, maxDynObjCount, staticObjMask);
            }
            if (0 <= hr)
            {
                // Activate成功。
                AddLog(string.Format("SpatialAudio.ChooseDevice({0}) success.\n", devIdx));

                // 無音送出開始。
                mPlayer.SpatialAudio.SetCurrentPcm(
                    WWSpatialAudioUser.TrackTypeEnum.None,
                    WWSpatialAudioUser.ChangeTrackMethod.Immediately);
                hr = mPlayer.Start();
                if (hr < 0)
                {
                    var s = string.Format("SpatialAudio.Start({0}) failed with error {1:X8}.\n", devIdx, hr);
                    AddLog(s);
                    MessageBox.Show(s);
                    hr = mPlayer.SpatialAudio.ChooseDevice(-1, 0, 0);
                    AddLog(string.Format("SpatialAudio.ChooseDevice(-1)\n"));
                    return;
                }

                // 全て成功。
                UpdateUIState(State.Activated);
            }
            else
            {
                // 失敗。
                if (E_UNSUPPORTED_TYPE == (uint)hr)
                {
                    var s = string.Format("Error: Spatial Audio of the specified device is not enabled! Please enable Spatial Audio of the device.\n", devIdx);
                    AddLog(s);
                    MessageBox.Show(s);
                }
                else
                {
                    var s = string.Format("SpatialAudio.ChooseDevice({0}) failed with error {1:X8}.\n", devIdx, hr);
                    AddLog(s);
                    MessageBox.Show(s);
                }
                UpdateUIState(State.Deactivated);
            }
        }
Esempio n. 2
0
        private string DwChannelMaskToStr(int dwChannelMask)
        {
            var sb = new StringBuilder();

            foreach (var item in WWSpatialAudioUser.DwChannelMaskToList(dwChannelMask))
            {
                sb.AppendFormat("{0} ", WWSpatialAudioUser.DwChannelMaskShortStr(item));
            }

            return(sb.ToString().TrimEnd(new char[] { ' ' }));
        }
        private WWSpatialAudioUser.AudioObjectType DwChannelMaskChannelGetAudioObjectTypeof(int ch)
        {
            // DwChannelMaskからAudioObjectTypeのリストを作成。
            int aoMask = AudioObjectTypeMask;
            var aoList = WWSpatialAudioUser.AudioObjectTypeMaskToList(aoMask);

            if (ch < 0 || aoList.Count <= ch)
            {
                // Dynamicにしても良い?
                return(WWSpatialAudioUser.AudioObjectType.None);
            }

            return(aoList[ch]);
        }
        public virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    mSAudio.Dispose();
                    mSAudio = null;
                }

                // free unmanaged resources here.

                disposedValue = true;
            }
        }
        /// <summary>
        /// mResampledPcmByChannelのPCMデータをNativeバッファーに入れる。
        /// </summary>
        public int StoreSamplesToNativeBuffer()
        {
            if (mResampledPcmByChannel.Count == 0)
            {
                Console.WriteLine("Error: WWSpatialAudioPlayer::StoreSamplesToNativeBuffer() PCM sample not found\n");
                return(-1);
            }

            int hr = 0;

            mSAudio.ClearAllPcm();
            for (int ch = 0; ch < mResampledPcmByChannel.Count; ++ch)
            {
                var from = mResampledPcmByChannel[ch];

                mSAudio.SetPcmBegin(ch, from.LongLength);

                int COPY_COUNT = 16 * 1024 * 1024;
                var buf        = new float[COPY_COUNT];

                for (long pos = 0; pos < from.LongLength; pos += COPY_COUNT)
                {
                    int copyCount = COPY_COUNT;
                    if (from.LongLength < pos + COPY_COUNT)
                    {
                        copyCount = (int)(from.LongLength - pos);
                        buf       = new float[copyCount];
                    }

                    from.CopyTo(pos, ref buf, 0, copyCount);
                    mSAudio.SetPcmFragment(ch, pos, buf);
                }

                // チャンネル番号ch のDwChannekMaskType
                var cmt = WWSpatialAudioUser.DwChannelMaskToList(DwChannelMask)[ch];
                var aot = WWSpatialAudioUser.DwChannelMaskTypeToAudioObjectType(cmt);
                if (aot == WWSpatialAudioUser.AudioObjectType.None)
                {
                    Console.WriteLine("D: channel {0} {1} does not map to audio object...", ch, cmt);
                }
                else
                {
                    mSAudio.SetPcmEnd(ch, aot);
                }
            }

            return(hr);
        }