Пример #1
0
        /// <summary>
        ///     Reconstruct a stream from WBH data.
        /// </summary>
        /// <param name="entry"></param>
        /// <param name="convertToPcm"></param>
        /// <returns></returns>
        public Memory <byte> ReconstructWave(WBHEntry entry, bool convertToPcm)
        {
            var data        = Data.Span.Slice(entry.Offset, entry.Size);
            var entryMutate = entry;

            // ReSharper disable once InvertIf
            if (convertToPcm && entry.Codec != WAVECodec.PCM && entry.Channels == 1)
            {
                data = entry.Codec switch
                {
                    WAVECodec.MSADPCM => MSADPCM.Decode(data, entryMutate.BlockAlign),
                    WAVECodec.GCADPCM when entry.Setup is short[] coefficients => GCADPCM.Decode(data, coefficients, entry.Samples),
                    _ => data
                };

                entryMutate.BlockAlign = 2;
                entryMutate.Codec      = WAVECodec.PCM;
            }

            return(PCM.ConstructWAVE((short)entryMutate.Codec, entry.Channels, entryMutate.Frequency, entryMutate.BlockAlign, entryMutate.Codec switch
            {
                WAVECodec.PCM => 16,
                WAVECodec.MSADPCM => 4,
                WAVECodec.GCADPCM => 4,
                _ => 4
            }, data));
Пример #2
0
        public async Task <IActionResult> Edit(int id, [Bind("pcmFName,pcmLName,PCMID,Specialty")] PCM pCM)
        {
            if (id != pCM.PCMID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(pCM);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PCMExists(pCM.PCMID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(pCM));
        }
Пример #3
0
 public void Game_Ready()
 {
     ui_manager.Ingame_camera();
     track_manager.TrackInit();
     PCM.Initialize();
     car_manager.CarInit();
     record_manager.Server_Time();
     record_manager.Reset_Start_Time();
     tip_manager.Random_Tip();
 }
Пример #4
0
        public async Task <IActionResult> Create([Bind("pcmFName,pcmLName,PCMID,Specialty")] PCM pCM)
        {
            if (ModelState.IsValid)
            {
                _context.Add(pCM);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(pCM));
        }
Пример #5
0
        /// <summary>
        ///     Reconstructs stream to a WAV
        /// </summary>
        /// <returns></returns>
        public List <Memory <byte> > ReconstructWave(bool convertPcm)
        {
            // TODO: BFWAV?
            if (!convertPcm)
            {
                return(ReconstructAsIndividual());
            }

            var streams = new List <Memory <byte> >();

            for (var index = 0; index < AudioBuffers.Count; index++)
            {
                var buffer = AudioBuffers[index];
                var coeffs = new Span <GCADPCMCoefficient>(new[] { Table[index].Coefficient1, Table[index].Coefficient2 });
                var data   = buffer.Span;
                data = GCADPCM.Decode(data, MemoryMarshal.Cast <GCADPCMCoefficient, short>(coeffs).ToArray(), Table[index].SampleCount);

                streams.Add(new Memory <byte>(PCM.ConstructWAVE(0x0001, 1, Header.SampleRate, 0x2, 16, data).ToArray()));
            }

            return(streams);
        }
Пример #6
0
        public void PerformTest()
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Title  = "Open Sound File";
            ofd.Filter = "ADPCM Wave File (*.wav)|*.wav";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Title  = "Save Sound File";
                sfd.Filter = "Wave File (*.wav)|*.wav";
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    Stream    input   = ofd.OpenFile();
                    XboxADPCM encoded = new XboxADPCM(input);
                    PCM       decoded = new PCM(encoded.ChannelCount, encoded.SampleRate);
                    decoded.SetRawData(encoded.GetRaw());
                    Stream output = File.OpenWrite(sfd.FileName);
                    decoded.Write(output);
                    output.Close();
                    input.Close();
                }
            }
        }
Пример #7
0
        private static byte[] DecodeSamples(byte[] binary, short encoding, WaveFormat format)
        {
            switch (encoding)
            {
            case 0: // none
                PCM pcm = new PCM(format.Channels, format.SamplesPerSecond);
                pcm.SetEncodedData(binary);
                return(pcm.GetRaw());

            case 1: // xbox adpcm
                XboxADPCM xbadpcm = new XboxADPCM(format.Channels, format.SamplesPerSecond);
                xbadpcm.SetEncodedData(binary);
                return(xbadpcm.GetRaw());

            case 2: // ima adpcm
                throw new HaloException("The sound encoding 'ima adpcm' is not yet supported.");

            case 3: // ogg vorbis
                throw new HaloException("The sound encoding 'ogg vorbis' is not yet supported.");

            default:
                throw new HaloException("The sound encoding {0} does not exist.", encoding);
            }
        }
Пример #8
0
        /// <summary>
        ///     Reconstructs stream to a WAV
        /// </summary>
        /// <returns></returns>
        public List <Memory <byte> > ReconstructWave(bool convertPcm)
        {
            var streams = new List <Memory <byte> >();

            foreach (var buffer in AudioBuffers)
            {
                var data       = buffer.Span;
                var codec      = 0x0002;
                var blockAlign = Info.FrameSize;
                if (convertPcm)
                {
                    data       = MSADPCM.Decode(data, blockAlign);
                    codec      = 0x0001;
                    blockAlign = 0x2;
                }


                streams.Add(new Memory <byte>(PCM.ConstructWAVE((short)codec, 1, Header.SampleRate, blockAlign, (WAVECodec)codec switch
                {
                    WAVECodec.PCM => 16,
                    WAVECodec.MSADPCM => 4,
                    WAVECodec.GCADPCM => 4,
                    _ => 4
                }, data).ToArray()));
Пример #9
0
        //public static List<ErrorData> ErrorList { get; } = new List<ErrorData>();

        /*
         * /// <summary>
         * /// Gets the can talon.
         * /// </summary>
         * /// <param name="id">The identifier.</param>
         * /// <returns></returns>
         * public static CanTalonData GetCanTalon(int id)
         * {
         *  CanTalonData data;
         *  bool retVal = s_canTalon.TryGetValue(id, out data);
         *  if (retVal)
         *  {
         *      //Contains key. Just return it
         *      return data;
         *  }
         *  else
         *  {
         *      //CAN Talon does not exist yet. Return null.
         *      return null;
         *  }
         * }
         *
         * /// <summary>
         * /// Initializes the can talon.
         * /// </summary>
         * /// <param name="id">The identifier.</param>
         * /// <returns></returns>
         * public static bool InitializeCanTalon(int id)
         * {
         *  CanTalonData data;
         *  bool retVal = s_canTalon.TryGetValue(id, out data);
         *  if (retVal)
         *  {
         *      //Contains key. return false saying we did not initialize a new one.
         *      return false;
         *  }
         *  else
         *  {
         *      //Create a new Can Talon data and return true.
         *      data = new CanTalonData();
         *      s_canTalon.Add(id, data);
         *      OnTalonSRXAddedOrRemoved?.Invoke(id, new TalonSRXEventArgs(true));
         *      return true;
         *  }
         * }
         *
         * /// <summary>
         * /// Removes the can talon.
         * /// </summary>
         * /// <param name="id">The identifier.</param>
         * public static void RemoveCanTalon(int id)
         * {
         *  s_canTalon.Remove(id);
         *  OnTalonSRXAddedOrRemoved?.Invoke(id, new TalonSRXEventArgs(false));
         * }
         *
         * /// <summary>
         * /// Gets the PCM.
         * /// </summary>
         * /// <param name="id">The identifier.</param>
         * /// <returns></returns>
         * public static PCMData GetPCM(int id)
         * {
         *  PCMData data;
         *  bool retVal = s_pcm.TryGetValue(id, out data);
         *  if (retVal)
         *  {
         *      //Contains key. Just return it
         *      return data;
         *  }
         *  else
         *  {
         *      data = new PCMData();
         *      s_pcm.Add(id, data);
         *      OnPCMAdded?.Invoke(data, null);
         *      return data;
         *  }
         * }
         *
         * /// <summary>
         * /// Initializes the PCM.
         * /// </summary>
         * /// <param name="id">The identifier.</param>
         * /// <returns></returns>
         * public static bool InitializePCM(int id)
         * {
         *  PCMData data;
         *  bool retVal = s_pcm.TryGetValue(id, out data);
         *  if (retVal)
         *  {
         *      //Contains key. return false saying we did not initialize a new one.
         *      return false;
         *  }
         *  else
         *  {
         *      //Create a new PCM data and return true.
         *      data = new PCMData();
         *      s_pcm.Add(id, data);
         *      OnPCMAdded?.Invoke(data, null);
         *      return true;
         *  }
         * }
         *
         * /// <summary>
         * /// Gets the PDP.
         * /// </summary>
         * /// <param name="id">The identifier.</param>
         * /// <returns></returns>
         * public static PDPData GetPDP(int id)
         * {
         *  PDPData data;
         *  bool retVal = s_pdp.TryGetValue(id, out data);
         *  if (retVal)
         *  {
         *      //Contains key. Just return it
         *      return data;
         *  }
         *  else
         *  {
         *      data = new PDPData();
         *      s_pdp.Add(id, data);
         *      OnPDPAdded?.Invoke(data, null);
         *      return data;
         *  }
         * }
         *
         * /// <summary>
         * /// Initializes a new PDP.
         * /// </summary>
         * /// <param name="id">The identifier.</param>
         * /// <returns>True if new PDP was created, otherwise false</returns>
         * public static bool InitializePDP(int id)
         * {
         *  PDPData data;
         *  bool retVal = s_pdp.TryGetValue(id, out data);
         *  if (retVal)
         *  {
         *      //Contains key. return false saying we did not initialize a new one.
         *      return false;
         *  }
         *  else
         *  {
         *      //Create a new PCM data and return true.
         *      data = new PDPData();
         *      s_pdp.Add(id, data);
         *      OnPDPAdded?.Invoke(data, null);
         *      return true;
         *  }
         * }
         *
         * /// <summary>
         * /// Occurs on talon SRX added or removed.
         * /// </summary>
         * public static event EventHandler<TalonSRXEventArgs> OnTalonSRXAddedOrRemoved;
         * /// <summary>
         * /// Occurs when a PCM is added.
         * /// </summary>
         * public static event EventHandler OnPCMAdded;
         * /// <summary>
         * /// Occurs when a PDP is added.
         * /// </summary>
         * public static event EventHandler OnPDPAdded;
         *
         */
        static SimData()
        {
            for (int i = 0; i < HAL_GetNumPCMModules(); i++)
            {
                PCM.Add(new HALSimPCMData(i));
            }

            for (int i = 0; i < HAL_GetNumPDPModules(); i++)
            {
                PDP.Add(new HALSimPDPData(i));
            }

            for (int i = 0; i < HAL_GetNumAccumulators(); i++)
            {
                AnalogGyro.Add(new HALSimAnalogGyroData(i));
            }

            for (int i = 0; i < HAL_GetNumAnalogOutputs(); i++)
            {
                AnalogOut.Add(new HALSimAnalogOutData(i));
            }

            for (int i = 0; i < HAL_GetNumAnalogInputs(); i++)
            {
                AnalogIn.Add(new HALSimAnalogInData(i));
            }

            for (int i = 0; i < HAL_GetNumAnalogTriggers(); i++)
            {
                AnalogTrigger.Add(new HALSimAnalogTriggerData(i));
            }

            for (int i = 0; i < HAL_GetNumDigitalChannels(); i++)
            {
                DIO.Add(new HALSimDIOData(i));
            }

            for (int i = 0; i < HAL_GetNumDigitalPWMOutputs(); i++)
            {
                DigitalPWM.Add(new HALSimDigitalPWMData(i));
            }

            for (int i = 0; i < 4; i++)
            {
                //DigitalGlitchFilter.Add(new DigitalGlitchFilterData());
            }

            for (int i = 0; i < HAL_GetNumPWMChannels(); i++)
            {
                PWM.Add(new HALSimPWMData(i));
            }

            for (int i = 0; i < 4; i++)
            {
                Relay.Add(new HALSimRelayData(i));
            }

            for (int i = 0; i < 8; i++)
            {
                //Counter.Add(new CounterData());
            }

            for (int i = 0; i < 8; i++)
            {
                Encoder.Add(new HALSimEncoderData(i));
            }

            for (int i = 0; i < 5; i++)
            {
                SPIAccelerometer.Add(new HALSimSPIAccelerometerData(i));
            }

            for (int i = 0; i < 5; i++)
            {
                //SPIAccumulator.Add(new SPIAccumulatorData());
            }

            //InitializePDP(0);
            //ErrorList.Clear();
        }
Пример #10
0
 public Larynx()
 {
     pcm = new PCM();
 }