Ejemplo n.º 1
0
        /// <summary>Returns a byte array containing 16-bit signed samples for the specified speaker sound.</summary>
        /// <param name="speakerSound">The speaker sound.</param>
        /// <param name="soundsPointer">The speaker sounds pointer.</param>
        /// <param name="sampleFrequency">The sample frequency in Hz.</param>
        /// <param name="amplitude">The peak amplitude (0 to 1).</param>
        /// <returns>A byte array.</returns>
        public static byte[] GetSpeakerSamplesS16(spksndtype speakerSound, memptr soundsPointer, double sampleFrequency, double amplitude)
        {
            soundsPointer.Offset(speakerSound.start);

            PCSpeaker pcSpeaker = new PCSpeaker(sampleFrequency, amplitude);

            // as: Added checks to catch problems with SOUNDS.HOV files (Demon Hunter v1.1):
            // Also, the maximum sample time has been limited to 10s
            // and: sound generation stops if the end of the soundsPointer buffer is reached

            double time = 1.0 / spksndtype.Frequency(0x2147);
            ushort timerValue = soundsPointer.GetUInt16(0);
            double maxTime = 10.0;
            while(timerValue != spksndtype.SpeakerData_EndSound)
            {
                pcSpeaker.SetTimer((ushort) timerValue);
                pcSpeaker.WriteSamples(time);

                soundsPointer.Offset(2);

                if(soundsPointer.BaseIndex + 1 >= soundsPointer.Buffer.Length)
                    break;

                timerValue = soundsPointer.GetUInt16(0);

                if(pcSpeaker.ElapsedTime > maxTime)
                    break;
            }

            return pcSpeaker.ToArray();
        }
Ejemplo n.º 2
0
        /// <summary>Returns a byte array containing samples (Mono 16-bit Signed) for the intro sound.</summary>
        /// <param name="sampleFrequency">The sample frequency in Hz.</param>
        /// <param name="amplitude">The peak amplitude (0 to 1).</param>
        /// <returns>A byte array.</returns>
        public static byte[] CreateIntroSoundSamplesS16(double sampleFrequency, double amplitude)
        {
            PCSpeaker pcSpeaker = new PCSpeaker(sampleFrequency, amplitude);

            // from HOVMAIN.C:Intro
            float NUMFRAMES = 300.0f;
            float MAXANGLE = (3.141592657f * 0.6f);
            short f = 1;
            do
            {
                float step = f / NUMFRAMES;
                float angle = MAXANGLE * step;
                float sn = (float) Math.Sin(angle);
                int frequency = (int) (sn * 1500);

                pcSpeaker.SetFrequency(frequency);
                pcSpeaker.WriteSamples(1.0 / 140.0);

                f++;
            } while(f <= NUMFRAMES);

            return pcSpeaker.ToArray();
        }