CSPspEmu.Hle.Modules.libatrac3plus.sceAtrac3plus.Atrac.Decode C# (CSharp) Method

Decode() public method

public Decode ( StereoShortSoundSample SamplesOut ) : int
SamplesOut CSPspEmu.Core.Audio.StereoShortSoundSample
return int
            public int Decode(StereoShortSoundSample* SamplesOut)
            {
                if (SamplesOut == null) return 0;

                //Console.Error.WriteLine("Decode");
                try
                {
                    //int Channels = 2;

                    //ToReadSamples /= 2;

                    var BlockSize = this.Format.BlockSize;
                    //this.Data
                    int channels;
                    short[] buf;

                    int rc;

                    if (BlockSize <= 0)
                    {
                        Console.WriteLine("BlockSize <= 0");
                        return -1;
                    }

                    if (this.DataStream.Available() < BlockSize)
                    {
                        Console.WriteLine("EndOfData {0} < {1} : {2}, {3}", this.DataStream.Available(), BlockSize, DecodingOffset, EndSample);
                        return 0;
                    }

                    var Data = new byte[BlockSize];
                    this.DataStream.Read(Data, 0, Data.Length);

                    fixed (byte* DataPtr = Data)
                    {
                        if ((rc = this.MaiAT3PlusFrameDecoder.decodeFrame(DataPtr, BlockSize, out channels, out buf)) != 0)
                        {
                            Console.WriteLine("MaiAT3PlusFrameDecoder.decodeFrame: {0}", rc);
                            return 0;
                        }

                        int DecodedSamples = this.MaximumSamples;
                        int DecodedSamplesChannels = DecodedSamples * channels;
                        _DecodingOffset += DecodedSamples;

                        fixed (short* buf_ptr = buf)
                        {
                            for (int n = 0; n < DecodedSamplesChannels; n += channels)
                            {
                                SamplesOut->Left = buf_ptr[n + 0];
                                SamplesOut->Right = buf_ptr[n + 1];
                                SamplesOut++;
                            }
                        }

                        return DecodedSamples;
                    }
                }
                catch
                {
                    Console.Error.WriteLine("Error Atrac3.Decode");
                    return 0;
                }
            }