Exemple #1
0
		static void mixaudio( object unused, short[] stream, uint len )
		{
			SoundData Snd, OldSound;
			uint PlayLen, i, Buffer_Len, Buffer_RemainLen;

			uint PlayPos;
			uint nSounds;

			Buffer_Len = len;

			for( i = 0; i < Buffer_Len; i++ )
				SoundBuffer[i] = 0;
			nSounds = 0;

			Snd = PlayingSoundList;
			while( Snd != null )
			{
				if( Snd.UseIntCompute )
				{
					Buffer_RemainLen = Buffer_Len;

					while( Buffer_RemainLen != 0 )
					{
						PlayLen = ( Snd.RLen > Buffer_RemainLen ) ? Buffer_RemainLen : Snd.RLen;
						if( PlayLen == 0 )
						{

							if( Snd.Repeat )
							{
								Snd.Pos = Snd.RepeatPos;
								Snd.RLen = Snd.Len - Snd.RepeatPos;
							}
							else
							{
								if( Snd.FlagOnEnd != null ) Snd.FlagOnEnd();
								Snd.DeletePending = true;
								break;
							}
						}
						else
						{
							for( i = 0; i < PlayLen / 2; i++ ) SoundBuffer[i] += Snd.Data[i+Snd.Pos];
							Buffer_RemainLen -= PlayLen;
							Snd.RLen -= PlayLen;
							Snd.Pos += PlayLen;
						}
					}
					//SDL_MixAudio(stream, Snd.Data + Snd.Pos, PlayLen, SDL_MIX_MAXVOLUME);
					//for (i=0;i<PlayLen-2;i+=2) {((UShort *)stream)[i]=0x0;((UShort *)stream)[i+1]=0x8000;}
				}
				else
				{
					double Coef, Temp;
					uint BufferPos;
					uint MaxOffset;
					Buffer_RemainLen = Buffer_Len >> 1;
					BufferPos = 0;
					MaxOffset = ( Snd.Len >> 1 ) - 1;

					double S1, S2, Ir;
					uint Offset;



					while( Buffer_RemainLen > 0 && ( !Snd.DeletePending ) )
					{
						Coef = Snd.DPos - ( Temp = Math.Floor( Snd.DPos ) );
						Offset = (uint)Temp;
						if( Offset < MaxOffset )
						{
							S1 = Snd.Data[Offset];
							S2 = Snd.Data[Offset + 1];
							Ir = S1 * ( 1.0 - Coef ) + ( S2 * Coef );
							SoundBuffer[BufferPos++] += (uint)Ir;
							Buffer_RemainLen--;
							Snd.DPos += Snd.FrequencyVar;
						}
						else
						{
							if( Snd.Repeat )
							{
								Snd.DPos = Snd.DRepeatPos;
							}
							else
							{
								if( Snd.FlagOnEnd != null ) Snd.FlagOnEnd();// = true;
								Snd.DeletePending = true;
								break;
							}
						}
					}
				}

#if false
				OldSound = Snd;
				Snd = Snd.NextSound;

				// If sound must be deleted

				if( OldSound.DeletePending )
				{
					if( OldSound.PrevSound == null ) PlayingSoundList = OldSound.NextSound;
					else OldSound.PrevSound.NextSound = OldSound.NextSound;
					if( OldSound.NextSound != null ) OldSound.NextSound.PrevSound = OldSound.PrevSound;
					OldSound.NextSound = null;
					OldSound.PrevSound = null;
					delete OldSound;
				}
#endif

				nSounds++;
			}

			// if (nSounds) for (i=0;i<Buffer_Len/2;i++) ((Short *)stream) [i] = (Short)(SoundBuffer[i]/nSounds );
			if( nSounds != 0 ) for( i = 0; i < Buffer_Len / 2; i++ ) ( stream )[i] = (short)( SoundBuffer[i] );
			//else
				//memset( stream, 0, len );

		}
Exemple #2
0
		void Stop_PlaySound( SoundData SoundHandle )
		{
		}
Exemple #3
0
		void ModifyFrequency( SoundData SoundHandle, double NewFrequency )
		{
		}
Exemple #4
0
		bool IsPlayed( SoundData SoundHandle )
		{
			return true;
		}
Exemple #5
0
		public Sound()
		{
			int i;
			SampleCount = 0;
			SoundActivated = false; PlayingSoundList = null;
			for( i = 0; i < ZSOUND_MAX_SOUNDFILES; i++ ) { SoundBank[i].Used = false;
				SoundBank[i].SoundData = null;
				SoundBank[i].SoundLen = 0; }

		}
Exemple #6
0
		SoundData FindSound( SoundData SoundHandle )
		{
			SoundData Snd;
			Snd = PlayingSoundList;
			while( Snd != null )
			{
				if( Snd == SoundHandle )
				{
					return ( Snd );
				}

				Snd = Snd.NextSound;
			}

			return ( null );
		}
Exemple #7
0
        /// <summary>
        /// Reads and decodes the sound stream.
        /// </summary>
        /// <returns>An OpenTK.Audio.SoundData object that contains the decoded buffer.</returns>
        public override SoundData ReadToEnd()
        {
            try
            {
                //read the buffer into a byte array, even if the format is 16 bit
                //decoded_data = new byte[data_chunk_size];

                decoded_data = new SoundData(new SoundFormat(channels, bits_per_sample, sample_rate),
                                                             reader.ReadBytes((int)reader.BaseStream.Length));

                //Debug.WriteLine("decoded!");

                //return new SoundData(decoded_data, new SoundFormat(channels, bits_per_sample, sample_rate));
                return decoded_data;
            }
            catch (AudioReaderException)
            {
                reader.Close();
                throw;
            }
        }
Exemple #8
0
        /// <summary>
        /// Reads and decodes the specified number of samples from the sound stream.
        /// </summary>
        /// <param name="samples">The number of samples to read and decode.</param>
        /// <returns>An OpenTK.Audio.SoundData object that contains the decoded buffer.</returns>
        public override SoundData ReadSamples(long samples)
        {
            if (samples > reader.BaseStream.Length - reader.BaseStream.Position)
                samples = reader.BaseStream.Length - reader.BaseStream.Position;

            //while (samples > decoded_data.Data.Length * (bits_per_sample / 8))
            //    Array.Resize<byte>(ref decoded_data.Data, decoded_data.Data.Length * 2);

            decoded_data = new SoundData(new SoundFormat(channels, bits_per_sample, sample_rate),
                                                         reader.ReadBytes((int)samples));

            return decoded_data;
        }