Example #1
0
        public HardwareDeviceImpl(IHardwareDeviceDriver deviceDriver, uint channelCount, uint sampleRate, float volume)
        {
            _session          = deviceDriver.OpenDeviceSession(IHardwareDeviceDriver.Direction.Output, null, SampleFormat.PcmInt16, sampleRate, channelCount, volume);
            _channelCount     = channelCount;
            _sampleRate       = sampleRate;
            _currentBufferTag = 0;

            _buffer = new byte[Constants.TargetSampleCount * channelCount * sizeof(ushort)];

            _session.Start();
        }
Example #2
0
        /// <summary>
        /// Open a new <see cref="AudioOutputSystem"/>.
        /// </summary>
        /// <param name="outputDeviceName">The output device name selected by the <see cref="AudioOutputSystem"/></param>
        /// <param name="outputConfiguration">The output audio configuration selected by the <see cref="AudioOutputSystem"/></param>
        /// <param name="obj">The new <see cref="AudioOutputSystem"/></param>
        /// <param name="memoryManager">The memory manager that will be used for all guest memory operations</param>
        /// <param name="inputDeviceName">The input device name wanted by the user</param>
        /// <param name="sampleFormat">The sample format to use</param>
        /// <param name="parameter">The user configuration</param>
        /// <param name="appletResourceUserId">The applet resource user id of the application</param>
        /// <param name="processHandle">The process handle of the application</param>
        /// <returns>A <see cref="ResultCode"/> reporting an error or a success</returns>
        public ResultCode OpenAudioOut(out string outputDeviceName,
                                       out AudioOutputConfiguration outputConfiguration,
                                       out AudioOutputSystem obj,
                                       IVirtualMemoryManager memoryManager,
                                       string inputDeviceName,
                                       SampleFormat sampleFormat,
                                       ref AudioInputConfiguration parameter,
                                       ulong appletResourceUserId,
                                       uint processHandle,
                                       float volume)
        {
            int sessionId = AcquireSessionId();

            _sessionsBufferEvents[sessionId].Clear();

            IHardwareDeviceSession deviceSession = _deviceDriver.OpenDeviceSession(IHardwareDeviceDriver.Direction.Output, memoryManager, sampleFormat, parameter.SampleRate, parameter.ChannelCount, volume);

            AudioOutputSystem audioOut = new AudioOutputSystem(this, _lock, deviceSession, _sessionsBufferEvents[sessionId]);

            ResultCode result = audioOut.Initialize(inputDeviceName, sampleFormat, ref parameter, sessionId);

            if (result == ResultCode.Success)
            {
                outputDeviceName    = audioOut.DeviceName;
                outputConfiguration = new AudioOutputConfiguration
                {
                    ChannelCount  = audioOut.ChannelCount,
                    SampleFormat  = audioOut.SampleFormat,
                    SampleRate    = audioOut.SampleRate,
                    AudioOutState = audioOut.GetState(),
                };

                obj = audioOut;

                Register(audioOut);
            }
            else
            {
                ReleaseSessionId(sessionId);

                obj = null;
                outputDeviceName    = null;
                outputConfiguration = default;
            }

            return(result);
        }