Torshify.Core.Native.NativeSessionCallbacks.MusicDeliveryCallback C# (CSharp) Method

MusicDeliveryCallback() private method

private MusicDeliveryCallback ( IntPtr sessionPtr, IntPtr formatPtr, IntPtr framesPtr, int numFrames ) : int
sessionPtr System.IntPtr
formatPtr System.IntPtr
framesPtr System.IntPtr
numFrames int
return int
        private int MusicDeliveryCallback(IntPtr sessionPtr, IntPtr formatPtr, IntPtr framesPtr, int numFrames)
        {
            if (sessionPtr != _session.Handle)
            {
                return 0;
            }

            byte[] samplesBytes = new byte[0];
            Spotify.SpotifyAudioFormat format = (Spotify.SpotifyAudioFormat)Marshal.PtrToStructure(formatPtr, typeof(Spotify.SpotifyAudioFormat));

            if (numFrames > 0)
            {
                samplesBytes = new byte[numFrames * format.Channels * 2];
                Marshal.Copy(framesPtr, samplesBytes, 0, samplesBytes.Length);
            }

            var args = new MusicDeliveryEventArgs(format.Channels, format.SampleRate, samplesBytes, numFrames);
            _session.OnMusicDeliver(args);

            return args.ConsumedFrames;
        }