Ejemplo n.º 1
0
        public IAudioRenderer(
            Horizon system,
            MemoryManager memory,
            IAalOutput audioOut,
            AudioRendererParameter rendererParams)
        {
            _updateEvent = new KEvent(system.KernelContext);

            _memory   = memory;
            _audioOut = audioOut;
            _params   = rendererParams;

            _track = audioOut.OpenTrack(
                AudioRendererConsts.HostSampleRate,
                AudioRendererConsts.HostChannelsCount,
                AudioCallback);

            _memoryPools = CreateArray <MemoryPoolContext>(rendererParams.EffectCount + rendererParams.VoiceCount * 4);

            _voices = CreateArray <VoiceContext>(rendererParams.VoiceCount);

            _effects = CreateArray <EffectContext>(rendererParams.EffectCount);

            _elapsedFrameCount = 0;

            InitializeAudioOut();

            _playState = PlayState.Stopped;
        }
Ejemplo n.º 2
0
        public IAudioRenderer(AMemory Memory, IAalOutput AudioOut, AudioRendererParameter Params)
        {
            m_Commands = new Dictionary <int, ServiceProcessRequest>()
            {
                { 4, RequestUpdateAudioRenderer },
                { 5, StartAudioRenderer },
                { 6, StopAudioRenderer },
                { 7, QuerySystemEvent }
            };

            UpdateEvent = new KEvent();

            this.Memory   = Memory;
            this.AudioOut = AudioOut;
            this.Params   = Params;

            Track = AudioOut.OpenTrack(
                AudioConsts.HostSampleRate,
                AudioConsts.HostChannelsCount,
                AudioCallback);

            MemoryPools = CreateArray <MemoryPoolContext>(Params.EffectCount + Params.VoiceCount * 4);

            Voices = CreateArray <VoiceContext>(Params.VoiceCount);

            InitializeAudioOut();
        }
Ejemplo n.º 3
0
        public long OpenAudioOut(ServiceCtx Context)
        {
            IAalOutput AudioOut = Context.Ns.AudioOut;

            string DeviceName = AMemoryHelper.ReadAsciiString(
                Context.Memory,
                Context.Request.SendBuff[0].Position,
                Context.Request.SendBuff[0].Size);

            if (DeviceName == string.Empty)
            {
                DeviceName = "FIXME";
            }

            long DeviceNamePosition = Context.Request.ReceiveBuff[0].Position;
            long DeviceNameSize     = Context.Request.ReceiveBuff[0].Size;

            byte[] DeviceNameBuffer = Encoding.ASCII.GetBytes(DeviceName);

            if (DeviceName.Length <= DeviceNameSize)
            {
                AMemoryHelper.WriteBytes(Context.Memory, DeviceNamePosition, DeviceNameBuffer);
            }

            int SampleRate = Context.RequestData.ReadInt32();
            int Channels   = Context.RequestData.ReadInt32();

            Channels = (ushort)(Channels >> 16);

            if (SampleRate == 0)
            {
                SampleRate = 48000;
            }

            if (Channels < 1 || Channels > 2)
            {
                Channels = 2;
            }

            KEvent ReleaseEvent = new KEvent();

            ReleaseCallback Callback = () =>
            {
                ReleaseEvent.WaitEvent.Set();
            };

            int Track = AudioOut.OpenTrack(SampleRate, Channels, Callback, out AudioFormat Format);

            MakeObject(Context, new IAudioOut(AudioOut, ReleaseEvent, Track));

            Context.ResponseData.Write(SampleRate);
            Context.ResponseData.Write(Channels);
            Context.ResponseData.Write((int)Format);
            Context.ResponseData.Write((int)PlaybackState.Stopped);

            return(0);
        }
Ejemplo n.º 4
0
        public void OpenAudioOutMethod(ServiceCtx Context, long SendPosition, long SendSize, long ReceivePosition, long ReceiveSize)
        {
            IAalOutput AudioOut = Context.Ns.AudioOut;

            string DeviceName = AMemoryHelper.ReadAsciiString(
                Context.Memory,
                SendPosition,
                SendSize
                );

            if (DeviceName == string.Empty)
            {
                DeviceName = DefaultAudioOutput;
            }

            byte[] DeviceNameBuffer = Encoding.ASCII.GetBytes(DeviceName + "\0");

            if ((ulong)DeviceNameBuffer.Length <= (ulong)ReceiveSize)
            {
                Context.Memory.WriteBytes(ReceivePosition, DeviceNameBuffer);
            }
            else
            {
                Context.Ns.Log.PrintError(LogClass.ServiceAudio, $"Output buffer size {ReceiveSize} too small!");
            }

            int SampleRate = Context.RequestData.ReadInt32();
            int Channels   = Context.RequestData.ReadInt32();

            Channels = (ushort)(Channels >> 16);

            if (SampleRate == 0)
            {
                SampleRate = 48000;
            }

            if (Channels < 1 || Channels > 2)
            {
                Channels = 2;
            }

            KEvent ReleaseEvent = new KEvent();

            ReleaseCallback Callback = () =>
            {
                ReleaseEvent.WaitEvent.Set();
            };

            int Track = AudioOut.OpenTrack(SampleRate, Channels, Callback, out AudioFormat Format);

            MakeObject(Context, new IAudioOut(AudioOut, ReleaseEvent, Track));

            Context.ResponseData.Write(SampleRate);
            Context.ResponseData.Write(Channels);
            Context.ResponseData.Write((int)Format);
            Context.ResponseData.Write((int)PlaybackState.Stopped);
        }
Ejemplo n.º 5
0
        public AalHardwareDevice(int bufferTag, IAalOutput output, uint channelCount, uint sampleRate)
        {
            _bufferTag    = bufferTag;
            _channelCount = channelCount;
            _sampleRate   = sampleRate;
            _output       = output;
            _releaseEvent = new AutoResetEvent(true);
            _trackId      = _output.OpenTrack((int)sampleRate, (int)channelCount, AudioCallback);
            _releasedTags = new Queue <long>();

            _buffer = new short[RendererConstants.TargetSampleCount * channelCount];

            _output.Start(_trackId);
        }
Ejemplo n.º 6
0
        public IAudioRenderer(
            Horizon system,
            MemoryManager memory,
            IAalOutput audioOut,
            AudioRendererParameter Params)
        {
            _commands = new Dictionary <int, ServiceProcessRequest>
            {
                { 0, GetSampleRate },
                { 1, GetSampleCount },
                { 2, GetMixBufferCount },
                { 3, GetState },
                { 4, RequestUpdateAudioRenderer },
                { 5, StartAudioRenderer },
                { 6, StopAudioRenderer },
                { 7, QuerySystemEvent }
            };

            _updateEvent = new KEvent(system);

            _memory   = memory;
            _audioOut = audioOut;
            _params   = Params;

            _track = audioOut.OpenTrack(
                AudioConsts.HostSampleRate,
                AudioConsts.HostChannelsCount,
                AudioCallback);

            _memoryPools = CreateArray <MemoryPoolContext>(Params.EffectCount + Params.VoiceCount * 4);

            _voices = CreateArray <VoiceContext>(Params.VoiceCount);

            InitializeAudioOut();

            _playState = PlayState.Stopped;
        }
Ejemplo n.º 7
0
        private long OpenAudioOutImpl(ServiceCtx Context, long SendPosition, long SendSize, long ReceivePosition, long ReceiveSize)
        {
            string DeviceName = AMemoryHelper.ReadAsciiString(
                Context.Memory,
                SendPosition,
                SendSize);

            if (DeviceName == string.Empty)
            {
                DeviceName = DefaultAudioOutput;
            }

            if (DeviceName != DefaultAudioOutput)
            {
                Logger.PrintWarning(LogClass.Audio, "Invalid device name!");

                return(MakeError(ErrorModule.Audio, AudErr.DeviceNotFound));
            }

            byte[] DeviceNameBuffer = Encoding.ASCII.GetBytes(DeviceName + "\0");

            if ((ulong)DeviceNameBuffer.Length <= (ulong)ReceiveSize)
            {
                Context.Memory.WriteBytes(ReceivePosition, DeviceNameBuffer);
            }
            else
            {
                Logger.PrintError(LogClass.ServiceAudio, $"Output buffer size {ReceiveSize} too small!");
            }

            int SampleRate = Context.RequestData.ReadInt32();
            int Channels   = Context.RequestData.ReadInt32();

            if (SampleRate == 0)
            {
                SampleRate = DefaultSampleRate;
            }

            if (SampleRate != DefaultSampleRate)
            {
                Logger.PrintWarning(LogClass.Audio, "Invalid sample rate!");

                return(MakeError(ErrorModule.Audio, AudErr.UnsupportedSampleRate));
            }

            Channels = (ushort)Channels;

            if (Channels == 0)
            {
                Channels = DefaultChannelsCount;
            }

            KEvent ReleaseEvent = new KEvent(Context.Device.System);

            ReleaseCallback Callback = () =>
            {
                ReleaseEvent.ReadableEvent.Signal();
            };

            IAalOutput AudioOut = Context.Device.AudioOut;

            int Track = AudioOut.OpenTrack(SampleRate, Channels, Callback);

            MakeObject(Context, new IAudioOut(AudioOut, ReleaseEvent, Track));

            Context.ResponseData.Write(SampleRate);
            Context.ResponseData.Write(Channels);
            Context.ResponseData.Write((int)SampleFormat.PcmInt16);
            Context.ResponseData.Write((int)PlaybackState.Stopped);

            return(0);
        }
Ejemplo n.º 8
0
        private ResultCode OpenAudioOutImpl(ServiceCtx context, long sendPosition, long sendSize, long receivePosition, long receiveSize)
        {
            string deviceName = MemoryHelper.ReadAsciiString(
                context.Memory,
                sendPosition,
                sendSize);

            if (deviceName == string.Empty)
            {
                deviceName = DefaultAudioOutput;
            }

            if (deviceName != DefaultAudioOutput)
            {
                Logger.PrintWarning(LogClass.Audio, "Invalid device name!");

                return(ResultCode.DeviceNotFound);
            }

            byte[] deviceNameBuffer = Encoding.ASCII.GetBytes(deviceName + "\0");

            if ((ulong)deviceNameBuffer.Length <= (ulong)receiveSize)
            {
                context.Memory.Write((ulong)receivePosition, deviceNameBuffer);
            }
            else
            {
                Logger.PrintError(LogClass.ServiceAudio, $"Output buffer size {receiveSize} too small!");
            }

            int sampleRate = context.RequestData.ReadInt32();
            int channels   = context.RequestData.ReadInt32();

            if (sampleRate == 0)
            {
                sampleRate = DefaultSampleRate;
            }

            if (sampleRate != DefaultSampleRate)
            {
                Logger.PrintWarning(LogClass.Audio, "Invalid sample rate!");

                return(ResultCode.UnsupportedSampleRate);
            }

            channels = (ushort)channels;

            if (channels == 0)
            {
                channels = DefaultChannelsCount;
            }

            KEvent releaseEvent = new KEvent(context.Device.System.KernelContext);

            ReleaseCallback callback = () =>
            {
                releaseEvent.ReadableEvent.Signal();
            };

            IAalOutput audioOut = context.Device.AudioOut;

            int track = audioOut.OpenTrack(sampleRate, channels, callback);

            MakeObject(context, new IAudioOut(audioOut, releaseEvent, track));

            context.ResponseData.Write(sampleRate);
            context.ResponseData.Write(channels);
            context.ResponseData.Write((int)SampleFormat.PcmInt16);
            context.ResponseData.Write((int)PlaybackState.Stopped);

            return(ResultCode.Success);
        }