Beispiel #1
0
        /// <summary>
        /// Permet de renvoyer des sons dans l'ordre d'une liste et les exclure ou non au fur et à mesure.
        /// </summary>
        /// <param name="audioClips"></param>
        /// <param name="soundMode"></param>
        /// <returns></returns>
        public static AudioClip OrderedSounds(List <AudioClip> audioClips, SoundMode soundMode = SoundMode.Normal)
        {
            if (audioClips.Count > 0)
            {
                AudioClip audio;

                switch (soundMode)
                {
                case SoundMode.Normal:
                    audio = audioClips[orderedSoundsIndex];
                    orderedSoundsIndex++;
                    if (orderedSoundsIndex > audioClips.Count)
                    {
                        orderedSoundsIndex = 0;
                    }
                    return(audio);

                case SoundMode.ExcludeAfterPlay:
                    audio = audioClips[0];
                    audioClips.Remove(audio);
                    return(audio);
                }
                return(null);
            }
            else
            {
                return(null);
            }
        }
        unsafe public override Sound SoundCreateDataBuffer(SoundMode mode, int channels,
                                                           int frequency, int bufferSize, DataReadDelegate dataReadCallback)
        {
            criticalSection.Enter();

            Sound sound;

            if ((int)(mode & SoundMode.Record) != 0)
            {
                DirectCaptureSound captureSound = new DirectCaptureSound(
                    mode, channels, frequency, bufferSize);
                if (captureSound.soundCapture == null)
                {
                    captureSound = null;
                }
                sound = captureSound;
            }
            else
            {
                sound = new DirectDataStreamSound(mode, channels, frequency,
                                                  bufferSize, dataReadCallback);
            }

            criticalSection.Leave();

            return(sound);
        }
        public override Sound SoundCreate(VirtualFileStream stream, bool closeStreamAfterReading,
                                          SoundType soundType, SoundMode mode)
        {
            criticalSection.Enter();

            DirectSound sound;
            bool        initialized;

            if ((int)(mode & SoundMode.Stream) == 0)
            {
                sound = new DirectSampleSound(stream, soundType, null, mode, out initialized);
                if (closeStreamAfterReading)
                {
                    stream.Close();
                }
            }
            else
            {
                sound = new DirectFileStreamSound(stream, closeStreamAfterReading, soundType, null,
                                                  mode, out initialized);
            }

            if (!initialized)
            {
                sound.Dispose();
                sound = null;
            }

            criticalSection.Leave();

            return(sound);
        }
Beispiel #4
0
        /// <summary>
        /// Loads a sound into memory, or opens it for streaming.
        /// </summary>
        /// <param name="name">
        /// Name of the file or URL to open. For CD playback, Windows-only, the name should be a drive letter with a colon.
        /// </param>
        /// <param name="mode">Behaviour modifier for opening the sound. See SoundMode.</param>
        /// <param name="sound">Address of a variable to receive a newly created FMOD Sound object.</param>
        /// <returns></returns>
        public Result CreateSound(string name, SoundMode mode, ref Sound sound)
        {
            var exinfo = new CreateSoundExInfo();

            exinfo.Size = Marshal.SizeOf(exinfo);
            return(CreateSound(name, mode, ref exinfo, out sound));
        }
Beispiel #5
0
        /// <summary>
        /// Play music.
        /// </summary>
        /// <param name="fileName">The file name.</param>
        /// <param name="loop">Looping flag.</param>
        public static void MusicPlay(string fileName, bool loop)
        {
            Init();

            if (musicSound != null && string.Compare(musicSound.Name, fileName, true) == 0)
            {
                return;
            }

            MusicStop();

            if (!string.IsNullOrEmpty(fileName) && VirtualFile.Exists(fileName))
            {
                SoundMode mode = SoundMode.Stream;
                if (loop)
                {
                    mode |= SoundMode.Loop;
                }

                musicSound = SoundWorld.Instance.SoundCreate(fileName, mode);

                if (musicSound != null)
                {
                    musicChannel = SoundWorld.Instance.SoundPlay(musicSound, musicChannelGroup, .5f);
                }
            }
        }
        private AudioClip getAudioClip(SoundMode mode)
        {
            int clipIndex = lastIndex;

            switch (soundMode)
            {
            case SoundMode.walking:
                while (lastIndex == clipIndex)
                {
                    clipIndex = Random.Range(0, walkSounds.Length - 1);
                }
                lastIndex = clipIndex;
                return(walkSounds[clipIndex]);

            case SoundMode.sprinting:
                while (lastIndex == clipIndex)
                {
                    clipIndex = Random.Range(0, sprintSounds.Length - 1);
                }
                lastIndex = clipIndex;
                return(sprintSounds[clipIndex]);

            case SoundMode.crawling:
                while (lastIndex == clipIndex)
                {
                    clipIndex = Random.Range(0, duckSounds.Length - 1);
                }
                lastIndex = clipIndex;
                return(duckSounds[clipIndex]);
            }

            return(null);
        }
Beispiel #7
0
        public override Sound SoundCreateDataBuffer(SoundMode mode, int channels, int frequency,
                                                    int bufferSize, DataReadDelegate dataReadCallback)
        {
            criticalSection.Enter();

            Sound sound;

            if ((mode & SoundMode.Record) != 0)
            {
                OpenALCaptureSound captureSound = new OpenALCaptureSound(
                    mode, channels, frequency, bufferSize);
                if (captureSound.alCaptureDevice == IntPtr.Zero)
                {
                    criticalSection.Leave();
                    return(null);
                }
                sound = captureSound;
            }
            else
            {
                sound = new OpenALDataStreamSound(mode, channels, frequency, bufferSize,
                                                  dataReadCallback);
            }

            criticalSection.Leave();

            return(sound);
        }
        //

        public OpenALFileStreamSound(VirtualFileStream stream, bool closeStreamAfterReading,
                                     SoundType soundType, string name, SoundMode mode, out bool initialized)
        {
            initialized = false;

            if (soundType == SoundType.Unknown)
            {
                if (name != null)
                {
                    soundType = GetSoundTypeByName(name);
                }
                else
                {
                    soundType = GetSoundTypeByStream(stream);
                }
            }

            if (soundType != SoundType.OGG)
            {
                Log.Warning(string.Format("Streaming is not supported for \"{0}\" files ({1}).",
                                          soundType, name));
                return;
            }

            vorbisFile = new VorbisFile.File();

            vorbisFileReader = new VorbisFileReader(stream, closeStreamAfterReading);

            if (!vorbisFileReader.OpenVorbisFile(vorbisFile))
            {
                vorbisFileReader.Dispose();
                Log.Warning(string.Format("Creating sound \"{0}\" failed.", name));
                return;
            }

            long numSamples = vorbisFile.pcm_total(-1);

            vorbisFile.get_info(-1, out channels, out frequency);

            //convert to mono for 3D
            if ((mode & SoundMode.Mode3D) != 0 && channels == 2)
            {
                needConvertToMono = true;
                channels          = 1;
            }

            if (!GenerateBuffers(2))
            {
                Log.Warning("OpenALSoundSystem: Creating sound failed \"{0}\".", name);
                return;
            }

            double length = (double)numSamples / (double)frequency;

            Init(name, mode, (float)length, channels, frequency);
            initialized = true;
        }
 // Start is called before the first frame update
 void Start()
 {
     rb               = GetComponentInParent <Rigidbody>();
     audioSource      = GetComponent <AudioSource>();
     currentSound     = 0;
     audioSource.clip = walkSounds[currentSound];
     soundMode        = SoundMode.walking;
     isActive         = true;
     readyTime        = Time.time + playRate[currentSound];
 }
Beispiel #10
0
        /// <summary>
        /// Loads a sound into memory, or opens it for streaming.
        /// </summary>
        /// <param name="data">A pointer to a preloaded sound.</param>
        /// <param name="mode">Behaviour modifier for opening the sound. See SoundMode.</param>
        /// <param name="exInfo">
        /// Pointer to a CreateSoundExInfo structure which lets the user provide extended information while playing the sound.
        /// </param>
        /// <param name="sound">Address of a variable to receive a newly created FMOD Sound object.</param>
        /// <returns></returns>
        public Result CreateSound(byte[] data, SoundMode mode, ref CreateSoundExInfo exInfo, ref Sound sound)
        {
            sound       = null;
            exInfo.Size = Marshal.SizeOf(exInfo);
            IntPtr soundraw;
            Result result = FMOD_System_CreateSound(rawPtr, data, mode, ref exInfo, out soundraw);

            sound = new Sound(soundraw);
            return(result);
        }
Beispiel #11
0
        public void PlaySound(Sound sound)
        {
            if (SoundMode is SoundMode.None)
            {
                return;
            }

            var path = Path.Combine("Sounds", SoundMode.ConvertToString(), $"{sound.ConvertToString()}.mp3");

            PlayFile(new Uri(path, UriKind.Relative), Volume);
        }
Beispiel #12
0
        /// <summary>
        /// Loads a sound into memory, or opens it for streaming.
        /// </summary>
        /// <param name="name">
        /// Name of the file or URL to open. For CD playback, Windows-only, the name should be a drive letter with a colon.
        /// </param>
        /// <param name="mode">Behaviour modifier for opening the sound. See SoundMode.</param>
        /// <param name="exInfo">
        /// Pointer to a CreateSoundExInfo structure which lets the user provide extended information while playing the sound.
        /// </param>
        /// <param name="sound">Address of a variable to receive a newly created FMOD Sound object.</param>
        /// <returns></returns>
        public Result CreateSound(string name, SoundMode mode, ref CreateSoundExInfo exInfo, out Sound sound)
        {
            sound = null;
            byte[] stringData;
            stringData  = Encoding.UTF8.GetBytes(name + Char.MinValue);
            exInfo.Size = Marshal.SizeOf(exInfo);
            IntPtr soundraw;
            Result result = FMOD_System_CreateSound(rawPtr, stringData, mode, ref exInfo, out soundraw);

            sound = new Sound(soundraw);
            return(result);
        }
Beispiel #13
0
    public static void SetLevel(SoundMode mode, string levelName)
    {
        if (CurrentLevel != levelName || CurrentMode != mode)
        {
            file.WriteLine("level: " + levelName);
            file.WriteLine("mode: " + mode);
            file.WriteLine();

            CurrentLevel = levelName;
            CurrentMode  = mode;
            Attempt      = 0;
        }
    }
Beispiel #14
0
    // Use this for initialization
    void Start()
    {
        bombs     = GameObject.Find("bomb pool").GetComponent <ObjectPool>();
        clouds    = GameObject.Find("cloud pool").GetComponent <ObjectPool>();
        stars     = GameObject.Find("star pool").GetComponent <ObjectPool>();
        rafts     = GameObject.Find("raft pool").GetComponent <ObjectPool>();
        water     = GameObject.Find("water").GetComponent <WaterScript>();
        music     = GameObject.Find("MusicController").GetComponent <MusicController>();
        nextTick  = Time.time + tickDuration;
        soundMode = Log.CurrentMode;
        Log.StartLevel(Time.time);

        StartCoroutine(LevelScript());
    }
Beispiel #15
0
 public SoundEffectEvent(
     SampleId soundId,
     byte volume,
     byte restartProbability,
     byte unk3,
     ushort frequencyOverride,
     SoundMode mode)
 {
     SoundId            = soundId;
     Volume             = volume;
     RestartProbability = restartProbability;
     Unk3 = unk3;
     FrequencyOverride = frequencyOverride;
     Mode = mode;
 }
Beispiel #16
0
    // Use this for initialization
    void Start()
    {
        levelToLoad = Log.CurrentLevel;
        soundMode   = Log.CurrentMode;
        if (levelToLoad == "")
        {
            return;
        }

        System.Type type = System.Type.GetType(levelToLoad);
        Log.SetLevel(soundMode, levelToLoad);
        gameObject.AddComponent(type);
        button.SetActive(false);
        background.SetActive(false);
    }
        // Update is called once per frame
        void Update()
        {
            if ((Mathf.Abs(rb.velocity.x) > xVelocityMin) || (Mathf.Abs(rb.velocity.z) > zVelocityMin))
            {
                isActive = true;
                //Debug.Log(rb.velocity.magnitude);
            }
            else
            {
                isActive = false;
                audioSource.Stop();
            }

            if (transform.gameObject.GetComponentInParent <FPSController>().isSprinting)
            {
                soundMode = SoundMode.sprinting;
            }
            else
            {
                if (transform.gameObject.GetComponentInParent <FPSController>().isDucking)
                {
                    soundMode = SoundMode.crawling;
                }
                else
                {
                    soundMode = SoundMode.walking;
                }
            }



            if (isActive && (Time.time > readyTime))
            {
                //Debug.Log("Playing audio " + sounds[currentSound]);
                audioSource.clip = getAudioClip(soundMode);
                if (!audioSource.isPlaying)
                {
                    audioSource.Play(0);
                }
                else
                {
                    Debug.Log("Warning! Audio replay rate is faster than sound clip!");
                    audioSource.Stop();
                    audioSource.Play(0);
                }
                readyTime = Time.time + playRate[(int)soundMode];
            }
        }
        //

        public OpenALDataStreamSound(SoundMode mode, int channels, int frequency, int bufferSize,
                                     SoundWorld.DataReadDelegate dataReadCallback)
        {
            this.channels         = channels;
            this.frequency        = frequency;
            this.dataReadCallback = dataReadCallback;
            this.bufferSize       = bufferSize;

            if (!GenerateBuffers(2))
            {
                Log.Warning("OpenALSoundSystem: Creating data stream sound failed.");
                return;
            }

            Init(null, mode, 100000.0f, channels, frequency);
        }
        public override Sound SoundCreate(string name, SoundMode mode)
        {
            criticalSection.Enter();

            DirectSound sound;

            sound = (DirectSound)base.SoundCreate(name, mode);
            if (sound != null)
            {
                criticalSection.Leave();
                return(sound);
            }

            VirtualFileStream stream = CreateFileStream(name);

            if (stream == null)
            {
                criticalSection.Leave();
                DirectSoundWorld.Warning(string.Format("Creating sound \"{0}\" failed.", name));
                return(null);
            }

            bool initialized;

            if ((int)(mode & SoundMode.Stream) == 0)
            {
                sound = new DirectSampleSound(stream, SoundType.Unknown, name,
                                              mode, out initialized);
                stream.Close();
            }
            else
            {
                sound = new DirectFileStreamSound(stream, true, SoundType.Unknown,
                                                  name, mode, out initialized);
            }

            if (!initialized)
            {
                sound.Dispose();
                sound = null;
            }

            criticalSection.Leave();

            return(sound);
        }
Beispiel #20
0
        unsafe public DirectDataStreamSound(SoundMode mode, int channels, int frequency, int bufferSize,
                                            SoundWorld.DataReadDelegate dataReadCallback)
        {
            this.dataReadCallback   = dataReadCallback;
            this.creationBufferSize = bufferSize;

            waveFormat = (WAVEFORMATEX *)NativeUtils.Alloc(NativeMemoryAllocationType.SoundAndVideo,
                                                           sizeof(WAVEFORMATEX));
            NativeUtils.ZeroMemory((IntPtr)waveFormat, sizeof(WAVEFORMATEX));
            waveFormat->wFormatTag      = DSound.WAVE_FORMAT_PCM;
            waveFormat->nChannels       = (ushort)channels;
            waveFormat->nSamplesPerSec  = (uint)frequency;
            waveFormat->wBitsPerSample  = 16;
            waveFormat->nBlockAlign     = (ushort)((waveFormat->nChannels * waveFormat->wBitsPerSample) / 8);
            waveFormat->nAvgBytesPerSec = waveFormat->nSamplesPerSec * waveFormat->nBlockAlign;

            Init(null, mode, 100000.0f, channels, frequency);
        }
        //

        public OpenALCaptureSound(SoundMode mode, int channels, int frequency, int bufferSize)
        {
            mode |= SoundMode.Loop | SoundMode.Software;

            int alFormat = channels == 2 ? Al.AL_FORMAT_STEREO16 : Al.AL_FORMAT_MONO16;

            alCaptureDevice = Alc.alcCaptureOpenDevice(OpenALSoundWorld.Instance.captureDeviceName,
                                                       frequency, alFormat, bufferSize);

            if (alCaptureDevice == IntPtr.Zero)
            {
                return;
            }

            this.channels  = channels;
            this.frequency = frequency;

            Init(null, mode, 100000.0f, channels, frequency);
        }
Beispiel #22
0
        public frmMain()
        {
            InitializeComponent();
            _fmod = new FmodSystem();
            _fmod.Init(32, InitFlags.SoftwareHRTF);
            _fmod.SetDspBufferSize(256, 2);

            _drums = new Dictionary <DrumType, Sound>();
            const SoundMode flags = SoundMode.NonBlocking | SoundMode.SoftwareProcessing;

            _drums[DrumType.Snare]        = _fmod.CreateSound("data/snare.wav", flags);
            _drums[DrumType.TomMid]       = _fmod.CreateSound("data/tom_mid.wav", flags);
            _drums[DrumType.TomLow]       = _fmod.CreateSound("data/tom_low.wav", flags);
            _drums[DrumType.TomFloor]     = _fmod.CreateSound("data/tom_floor.wav", flags);
            _drums[DrumType.Kick]         = _fmod.CreateSound("data/kick.wav", flags);
            _drums[DrumType.HihatOpen]    = _fmod.CreateSound("data/cym_hatopen.wav", flags);
            _drums[DrumType.HihatMid]     = _fmod.CreateSound("data/cym_hatmid.wav", flags);
            _drums[DrumType.HithatClosed] = _fmod.CreateSound("data/cym_hatclosed.wav", flags);
            _drums[DrumType.CymbalCrash]  = _fmod.CreateSound("data/cym_crash.wav", flags);
            _drums[DrumType.CymbalRide]   = _fmod.CreateSound("data/cym_ride.wav", flags);
        }
Beispiel #23
0
    public SoundInfo(SoundSCV csv)
    {
        if (Utils.IsEnumParseName(typeof(SoundMode), csv.Mode))
        {
            Mode = (SoundMode)Enum.Parse(typeof(SoundMode), csv.Mode);
        }
        else
        {
            Mode = SoundMode.None;
        }

        if (Utils.IsEnumParseName(typeof(SoundManager.SoundName), csv.Name))
        {
            Name = (SoundManager.SoundName)Enum.Parse(typeof(SoundManager.SoundName), csv.Name);
        }
        else
        {
            Name = SoundManager.SoundName.MAX;
        }

        Step = csv.Step;
    }
Beispiel #24
0
        /// <summary>
        /// Permet de renvoyer des sons aléatoires d'une liste et les exclure ou non au fur et à mesure.
        /// </summary>
        /// <param name="audioClips"></param>
        /// <param name="soundMode"></param>
        /// <returns></returns>
        public static AudioClip RandomSounds(List <AudioClip> audioClips, SoundMode soundMode = SoundMode.Normal)
        {
            if (audioClips.Count > 0)
            {
                AudioClip audio;

                switch (soundMode)
                {
                case SoundMode.Normal:
                    audio = audioClips[Random.Range(0, audioClips.Count)];
                    return(audio);

                case SoundMode.ExcludeAfterPlay:
                    audio = audioClips[Random.Range(0, audioClips.Count)];
                    audioClips.Remove(audio);
                    return(audio);
                }
                return(null);
            }
            else
            {
                return(null);
            }
        }
Beispiel #25
0
 public Sound CreateStream(string path, SoundMode mode)
 {
     IntPtr resultHandle = IntPtr.Zero;
     Errors.ThrowIfError(CreateStream(DangerousGetHandle(), path, mode, 0, ref resultHandle));
     var result = new Sound(resultHandle);
     _sounds.Add(resultHandle, result);
     return result;
 }
Beispiel #26
0
 public Sound CreateSound(UnmanagedMemoryStream data, SoundMode mode = SoundMode.Default)
 {
     var stream = new MemoryStream();
     data.CopyTo(stream);
     return CreateSound(stream.ToArray(), mode);
 }
Beispiel #27
0
        unsafe public DirectCaptureSound(SoundMode mode, int channels, int frequency, int bufferSize)
        {
            SoundMode newMode = mode | SoundMode.Loop | SoundMode.Software;

            int hr;

            if (DirectSoundWorld.Instance.recordDriverIndex == -1)
            {
                DirectSoundWorld.Warning("Recording failed. No active device.");
                return;
            }
            GUID deviceGuid = DirectSoundWorld.Instance.recordDriverGuids[
                DirectSoundWorld.Instance.recordDriverIndex];

            //soundCapture
            void */*IDirectSoundCapture8*/ tempSoundCapture;

            hr = DSound.DirectSoundCaptureCreate(&deviceGuid, out tempSoundCapture, null);
            if (Wrapper.FAILED(hr))
            {
                DirectSoundWorld.Warning("DirectSoundCaptureCreate", hr);
                return;
            }
            soundCapture = (IDirectSoundCapture8 *)tempSoundCapture;

            //waveFormat
            waveFormat = (WAVEFORMATEX *)NativeUtils.Alloc(NativeMemoryAllocationType.SoundAndVideo,
                                                           sizeof(WAVEFORMATEX));
            NativeUtils.ZeroMemory((IntPtr)waveFormat, sizeof(WAVEFORMATEX));
            waveFormat->wFormatTag      = DSound.WAVE_FORMAT_PCM;
            waveFormat->nChannels       = (ushort)channels;
            waveFormat->nSamplesPerSec  = (uint)frequency;
            waveFormat->wBitsPerSample  = 16;
            waveFormat->nBlockAlign     = (ushort)((waveFormat->nChannels * waveFormat->wBitsPerSample) / 8);
            waveFormat->nAvgBytesPerSec = waveFormat->nSamplesPerSec * waveFormat->nBlockAlign;

            //captureBuffer

            DSCBUFFERDESC bufferDesc = new DSCBUFFERDESC();

            //ZeroMemory( &bufferDesc, sizeof( DSCBUFFERDESC ) );
            bufferDesc.dwSize        = (uint)sizeof(DSCBUFFERDESC);
            bufferDesc.dwBufferBytes = (uint)bufferSize;
            bufferDesc.lpwfxFormat   = waveFormat;

            void */*IDirectSoundCaptureBuffer*/ tempCaptureBuffer;

            hr = IDirectSoundCapture8.CreateCaptureBuffer(soundCapture,
                                                          ref bufferDesc, out tempCaptureBuffer, null);
            if (Wrapper.FAILED(hr))
            {
                DirectSoundWorld.Warning("CreateCaptureBuffer", hr);
                IDirectSoundCapture8.Release(soundCapture);
                soundCapture = null;
                return;
            }
            captureBuffer = (IDirectSoundCaptureBuffer *)tempCaptureBuffer;

            //get bufferSize
            DSCBCAPS bufferCaps = new DSCBCAPS();

            //ZeroMemory( &bufferCaps, sizeof( DSCBCAPS ) );
            bufferCaps.dwSize = (uint)sizeof(DSCBCAPS);
            IDirectSoundCaptureBuffer.GetCaps(captureBuffer, ref bufferCaps);
            this.bufferSize = (int)bufferCaps.dwBufferBytes;

            Init(null, newMode, 100000.0f, channels, frequency);
        }
Beispiel #28
0
        //

        unsafe public DirectFileStreamSound(VirtualFileStream stream, bool closeStreamAfterReading,
                                            SoundType soundType, string name, SoundMode mode, out bool initialized)
        {
            initialized = false;

            if (soundType == SoundType.Unknown)
            {
                if (name != null)
                {
                    soundType = GetSoundTypeByName(name);
                }
                else
                {
                    soundType = GetSoundTypeByStream(stream);
                }
            }

            if (soundType != SoundType.OGG)
            {
                DirectSoundWorld.Warning(string.Format(
                                             "Streaming is not supported for \"{0}\" files ({1}).", soundType, name));
                return;
            }

            vorbisFile = new VorbisFile.File();

            vorbisFileReader = new VorbisFileReader(stream, closeStreamAfterReading);

            if (!vorbisFileReader.OpenVorbisFile(vorbisFile))
            {
                vorbisFileReader.Dispose();
                DirectSoundWorld.Warning(string.Format("Creating sound \"{0}\" failed.", name));
                return;
            }

            int channels;
            int frequency;

            long numSamples = vorbisFile.pcm_total(-1);

            vorbisFile.get_info(-1, out channels, out frequency);

            //convert to mono for 3D
            if ((int)(mode & SoundMode.Mode3D) != 0 && channels == 2)
            {
                needConvertToMono = true;
                channels          = 1;
            }

            waveFormat = (WAVEFORMATEX *)NativeUtils.Alloc(NativeMemoryAllocationType.SoundAndVideo,
                                                           sizeof(WAVEFORMATEX));
            NativeUtils.ZeroMemory((IntPtr)waveFormat, sizeof(WAVEFORMATEX));
            waveFormat->wFormatTag      = DSound.WAVE_FORMAT_PCM;
            waveFormat->nChannels       = (ushort)channels;
            waveFormat->nSamplesPerSec  = (uint)frequency;
            waveFormat->wBitsPerSample  = 16;
            waveFormat->nBlockAlign     = (ushort)((waveFormat->nChannels * waveFormat->wBitsPerSample) / 8);
            waveFormat->nAvgBytesPerSec = waveFormat->nSamplesPerSec * waveFormat->nBlockAlign;

            double length = (double)numSamples / (double)frequency;

            Init(name, mode, (float)length, channels, frequency);
            initialized = true;
        }
Beispiel #29
0
 private static extern Result FMOD_System_CreateStream(IntPtr system, byte[] name_or_data, SoundMode mode, int exinfo, out IntPtr sound);
Beispiel #30
0
 private static extern Result FMOD_System_CreateSound(IntPtr system, string name_or_data, SoundMode mode, int exinfo, out IntPtr sound);
Beispiel #31
0
		unsafe public DirectCaptureSound( SoundMode mode, int channels, int frequency, int bufferSize )
		{
			SoundMode newMode = mode | SoundMode.Loop | SoundMode.Software;

			int hr;

			if( DirectSoundWorld.Instance.recordDriverIndex == -1 )
			{
				DirectSoundWorld.Warning( "Recording failed. No active device." );
				return;
			}
			GUID deviceGuid = DirectSoundWorld.Instance.recordDriverGuids[
				DirectSoundWorld.Instance.recordDriverIndex ];

			//soundCapture
			void*/*IDirectSoundCapture8*/ tempSoundCapture;
			hr = DSound.DirectSoundCaptureCreate( &deviceGuid, out tempSoundCapture, null );
			if( Wrapper.FAILED( hr ) )
			{
				DirectSoundWorld.Warning( "DirectSoundCaptureCreate", hr );
				return;
			}
			soundCapture = (IDirectSoundCapture8*)tempSoundCapture;

			//waveFormat
			waveFormat = (WAVEFORMATEX*)NativeUtils.Alloc( NativeMemoryAllocationType.SoundAndVideo,
				sizeof( WAVEFORMATEX ) );
			NativeUtils.ZeroMemory( (IntPtr)waveFormat, sizeof( WAVEFORMATEX ) );
			waveFormat->wFormatTag = DSound.WAVE_FORMAT_PCM;
			waveFormat->nChannels = (ushort)channels;
			waveFormat->nSamplesPerSec = (uint)frequency;
			waveFormat->wBitsPerSample = 16;
			waveFormat->nBlockAlign = (ushort)( ( waveFormat->nChannels * waveFormat->wBitsPerSample ) / 8 );
			waveFormat->nAvgBytesPerSec = waveFormat->nSamplesPerSec * waveFormat->nBlockAlign;

			//captureBuffer

			DSCBUFFERDESC bufferDesc = new DSCBUFFERDESC();
			//ZeroMemory( &bufferDesc, sizeof( DSCBUFFERDESC ) );
			bufferDesc.dwSize = (uint)sizeof( DSCBUFFERDESC );
			bufferDesc.dwBufferBytes = (uint)bufferSize;
			bufferDesc.lpwfxFormat = waveFormat;

			void*/*IDirectSoundCaptureBuffer*/ tempCaptureBuffer;

			hr = IDirectSoundCapture8.CreateCaptureBuffer( soundCapture,
				ref bufferDesc, out tempCaptureBuffer, null );
			if( Wrapper.FAILED( hr ) )
			{
				DirectSoundWorld.Warning( "CreateCaptureBuffer", hr );
				IDirectSoundCapture8.Release( soundCapture );
				soundCapture = null;
				return;
			}
			captureBuffer = (IDirectSoundCaptureBuffer*)tempCaptureBuffer;

			//get bufferSize
			DSCBCAPS bufferCaps = new DSCBCAPS();
			//ZeroMemory( &bufferCaps, sizeof( DSCBCAPS ) );
			bufferCaps.dwSize = (uint)sizeof( DSCBCAPS );
			IDirectSoundCaptureBuffer.GetCaps( captureBuffer, ref bufferCaps );
			this.bufferSize = (int)bufferCaps.dwBufferBytes;

			Init( null, newMode, 100000.0f, channels, frequency );
		}
Beispiel #32
0
		/// <summary>
		/// Initializes a new instance of the sound sensor class.
		/// </summary>
		/// <param name="mode">Mode.</param>
		public NXTSoundSensor (SensorPort port, SoundMode  mode) :  base(port)
		{
			Mode = mode;
		}
Beispiel #33
0
 private static extern ErrorCode CreateStream(IntPtr system, string name, SoundMode mode, int exinfo, ref IntPtr sound);
Beispiel #34
0
		//

		unsafe public DirectFileStreamSound( VirtualFileStream stream, bool closeStreamAfterReading,
			SoundType soundType, string name, SoundMode mode, out bool initialized )
		{
			initialized = false;

			if( soundType == SoundType.Unknown )
			{
				if( name != null )
					soundType = GetSoundTypeByName( name );
				else
					soundType = GetSoundTypeByStream( stream );
			}

			if( soundType != SoundType.OGG )
			{
				DirectSoundWorld.Warning( string.Format(
					"Streaming is not supported for \"{0}\" files ({1}).", soundType, name ) );
				return;
			}

			vorbisFile = new VorbisFile.File();

			vorbisFileReader = new VorbisFileReader( stream, closeStreamAfterReading );

			if( !vorbisFileReader.OpenVorbisFile( vorbisFile ) )
			{
				vorbisFileReader.Dispose();
				DirectSoundWorld.Warning( string.Format( "Creating sound \"{0}\" failed.", name ) );
				return;
			}

			int channels;
			int frequency;

			long numSamples = vorbisFile.pcm_total( -1 );
			vorbisFile.get_info( -1, out channels, out frequency );

			//convert to mono for 3D
			if( (int)( mode & SoundMode.Mode3D ) != 0 && channels == 2 )
			{
				needConvertToMono = true;
				channels = 1;
			}

			waveFormat = (WAVEFORMATEX*)NativeUtils.Alloc( NativeMemoryAllocationType.SoundAndVideo,
				sizeof( WAVEFORMATEX ) );
			NativeUtils.ZeroMemory( (IntPtr)waveFormat, sizeof( WAVEFORMATEX ) );
			waveFormat->wFormatTag = DSound.WAVE_FORMAT_PCM;
			waveFormat->nChannels = (ushort)channels;
			waveFormat->nSamplesPerSec = (uint)frequency;
			waveFormat->wBitsPerSample = 16;
			waveFormat->nBlockAlign = (ushort)( ( waveFormat->nChannels * waveFormat->wBitsPerSample ) / 8 );
			waveFormat->nAvgBytesPerSec = waveFormat->nSamplesPerSec * waveFormat->nBlockAlign;

			double length = (double)numSamples / (double)frequency;

			Init( name, mode, (float)length, channels, frequency );
			initialized = true;
		}
Beispiel #35
0
 private static extern ErrorCode CreateSound(IntPtr system, string name, SoundMode mode, ref SoundInfo exinfo, ref IntPtr Sound);
Beispiel #36
0
 ///////////////////////////////////////////
 public void PreloadSound( string soundName, SoundMode mode )
 {
     if( !string.IsNullOrEmpty( soundName ) )
     {
         SoundWorld.Instance.SoundCreate(
             RelativePathUtils.ConvertToFullPath( Path.GetDirectoryName( FilePath ), soundName ), mode );
     }
 }
Beispiel #37
0
		public override Sound SoundCreate( string name, SoundMode mode )
		{
			criticalSection.Enter();

			DirectSound sound;

			sound = (DirectSound)base.SoundCreate( name, mode );
			if( sound != null )
			{
				criticalSection.Leave();
				return sound;
			}

			VirtualFileStream stream = CreateFileStream( name );
			if( stream == null )
			{
				criticalSection.Leave();
				DirectSoundWorld.Warning( string.Format( "Creating sound \"{0}\" failed.", name ) );
				return null;
			}

			bool initialized;

			if( (int)( mode & SoundMode.Stream ) == 0 )
			{
				sound = new DirectSampleSound( stream, SoundType.Unknown, name,
					mode, out initialized );
				stream.Close();
			}
			else
			{
				sound = new DirectFileStreamSound( stream, true, SoundType.Unknown,
					name, mode, out initialized );
			}

			if( !initialized )
			{
				sound.Dispose();
				sound = null;
			}

			criticalSection.Leave();

			return sound;
		}
Beispiel #38
0
		unsafe public override Sound SoundCreateDataBuffer( SoundMode mode, int channels,
			int frequency, int bufferSize, DataReadDelegate dataReadCallback )
		{
			criticalSection.Enter();

			Sound sound;

			if( (int)( mode & SoundMode.Record ) != 0 )
			{
				DirectCaptureSound captureSound = new DirectCaptureSound(
					mode, channels, frequency, bufferSize );
				if( captureSound.soundCapture == null )
					captureSound = null;
				sound = captureSound;
			}
			else
			{
				sound = new DirectDataStreamSound( mode, channels, frequency,
					bufferSize, dataReadCallback );
			}

			criticalSection.Leave();

			return sound;
		}
Beispiel #39
0
		public override void SelectPreviousMode ()
		{
			Mode = Mode.Previous();
			return;
		}
Beispiel #40
0
		public override Sound SoundCreateDataBuffer( SoundMode mode, int channels, int frequency,
			int bufferSize, DataReadDelegate dataReadCallback )
		{
			criticalSection.Enter();

			Sound sound;

			if( ( mode & SoundMode.Record ) != 0 )
			{
				OpenALCaptureSound captureSound = new OpenALCaptureSound(
					mode, channels, frequency, bufferSize );
				if( captureSound.alCaptureDevice == IntPtr.Zero )
				{
					criticalSection.Leave();
					return null;
				}
				sound = captureSound;
			}
			else
			{
				sound = new OpenALDataStreamSound( mode, channels, frequency, bufferSize,
					dataReadCallback );
			}

			criticalSection.Leave();

			return sound;
		}
Beispiel #41
0
		public override void SelectNextMode()
		{
			Mode = Mode.Next();
			return;
		}
Beispiel #42
0
		unsafe public DirectDataStreamSound( SoundMode mode, int channels, int frequency, int bufferSize,
			SoundWorld.DataReadDelegate dataReadCallback )
		{
			this.dataReadCallback = dataReadCallback;
			this.creationBufferSize = bufferSize;

			waveFormat = (WAVEFORMATEX*)NativeUtils.Alloc( NativeMemoryAllocationType.SoundAndVideo,
				sizeof( WAVEFORMATEX ) );
			NativeUtils.ZeroMemory( (IntPtr)waveFormat, sizeof( WAVEFORMATEX ) );
			waveFormat->wFormatTag = DSound.WAVE_FORMAT_PCM;
			waveFormat->nChannels = (ushort)channels;
			waveFormat->nSamplesPerSec = (uint)frequency;
			waveFormat->wBitsPerSample = 16;
			waveFormat->nBlockAlign = (ushort)( ( waveFormat->nChannels * waveFormat->wBitsPerSample ) / 8 );
			waveFormat->nAvgBytesPerSec = waveFormat->nSamplesPerSec * waveFormat->nBlockAlign;

			Init( null, mode, 100000.0f, channels, frequency );
		}
		/// <summary>
		/// Initializes a new instance of the <see cref="MonoBrick.NXT.NXTSoundSensor"/> class.
		/// </summary>
		/// <param name='soundMode'>
		/// Sound mode
		/// </param>
		public NXTSoundSensor(SoundMode soundMode) : base((SensorType)soundMode, SensorMode.Percent) { }
Beispiel #44
0
 private static extern Result FMOD_System_CreateSound(IntPtr system, byte[] name_or_data, SoundMode mode, ref CreateSoundExInfo exinfo, out IntPtr sound);
Beispiel #45
0
		//

		public OpenALFileStreamSound( VirtualFileStream stream, bool closeStreamAfterReading,
			SoundType soundType, string name, SoundMode mode, out bool initialized )
		{
			initialized = false;

			if( soundType == SoundType.Unknown )
			{
				if( name != null )
					soundType = GetSoundTypeByName( name );
				else
					soundType = GetSoundTypeByStream( stream );
			}

			if( soundType != SoundType.OGG )
			{
				Log.Warning( string.Format( "Streaming is not supported for \"{0}\" files ({1}).",
					soundType, name ) );
				return;
			}

			vorbisFile = new VorbisFile.File();

			vorbisFileReader = new VorbisFileReader( stream, closeStreamAfterReading );

			if( !vorbisFileReader.OpenVorbisFile( vorbisFile ) )
			{
				vorbisFileReader.Dispose();
				Log.Warning( string.Format( "Creating sound \"{0}\" failed.", name ) );
				return;
			}

			long numSamples = vorbisFile.pcm_total( -1 );
			vorbisFile.get_info( -1, out channels, out frequency );

			//convert to mono for 3D
			if( ( mode & SoundMode.Mode3D ) != 0 && channels == 2 )
			{
				needConvertToMono = true;
				channels = 1;
			}

			if( !GenerateBuffers( 2 ) )
			{
				Log.Warning( "OpenALSoundSystem: Creating sound failed \"{0}\".", name );
				return;
			}

			double length = (double)numSamples / (double)frequency;

			Init( name, mode, (float)length, channels, frequency );
			initialized = true;
		}
Beispiel #46
0
        unsafe public DirectSampleSound(VirtualFileStream stream,
                                        SoundType soundType, string name, SoundMode mode, out bool initialized)
        {
            initialized = false;

            int   channels;
            int   frequency;
            float timeLength;

            if (soundType == SoundType.Unknown)
            {
                if (name != null)
                {
                    soundType = GetSoundTypeByName(name);
                }
                else
                {
                    soundType = GetSoundTypeByStream(stream);
                }
            }

            string error;

            if (!LoadSamplesFromStream(stream, soundType, out channels, out frequency,
                                       out timeLength, out error))
            {
                if (name != null)
                {
                    DirectSoundWorld.Warning(string.Format("Creating sound \"{0}\" failed ({1}).",
                                                           name, error));
                }
                else
                {
                    DirectSoundWorld.Warning(string.Format("Creating sound from stream failed ({0}).",
                                                           error));
                }
                return;
            }

            //convert to mono for 3D
            if ((int)(mode & SoundMode.Mode3D) != 0 && channels == 2)
            {
                byte[] oldSamples = soundSamples;
                soundSamples = new byte[oldSamples.Length / 2];
                for (int n = 0; n < soundSamples.Length; n += 2)
                {
                    soundSamples[n + 0] = oldSamples[n * 2 + 0];
                    soundSamples[n + 1] = oldSamples[n * 2 + 1];
                }
                channels = 1;
            }

            //create buffer
            waveFormat = (WAVEFORMATEX *)NativeUtils.Alloc(NativeMemoryAllocationType.SoundAndVideo,
                                                           sizeof(WAVEFORMATEX));
            NativeUtils.ZeroMemory((IntPtr)waveFormat, sizeof(WAVEFORMATEX));
            waveFormat->wFormatTag      = DSound.WAVE_FORMAT_PCM;
            waveFormat->nChannels       = (ushort)channels;
            waveFormat->nSamplesPerSec  = (uint)frequency;
            waveFormat->wBitsPerSample  = 16;
            waveFormat->nBlockAlign     = (ushort)((waveFormat->nChannels * waveFormat->wBitsPerSample) / 8);
            waveFormat->nAvgBytesPerSec = waveFormat->nSamplesPerSec * waveFormat->nBlockAlign;

            Init(name, mode, timeLength, channels, frequency);
            initialized = true;
        }
Beispiel #47
0
		//

		public OpenALDataStreamSound( SoundMode mode, int channels, int frequency, int bufferSize,
			SoundWorld.DataReadDelegate dataReadCallback )
		{
			this.channels = channels;
			this.frequency = frequency;
			this.dataReadCallback = dataReadCallback;
			this.bufferSize = bufferSize;

			if( !GenerateBuffers( 2 ) )
			{
				Log.Warning( "OpenALSoundSystem: Creating data stream sound failed." );
				return;
			}

			Init( null, mode, 100000.0f, channels, frequency );
		}
Beispiel #48
0
 private static extern ErrorCode SetMode(IntPtr sound, SoundMode mode);
Beispiel #49
0
		//

		public OpenALCaptureSound( SoundMode mode, int channels, int frequency, int bufferSize )
		{
			mode |= SoundMode.Loop | SoundMode.Software;

			int alFormat = channels == 2 ? Al.AL_FORMAT_STEREO16 : Al.AL_FORMAT_MONO16;

			alCaptureDevice = Alc.alcCaptureOpenDevice( OpenALSoundWorld.Instance.captureDeviceName,
				frequency, alFormat, bufferSize );

			if( alCaptureDevice == IntPtr.Zero )
				return;

			this.channels = channels;
			this.frequency = frequency;

			Init( null, mode, 100000.0f, channels, frequency );
		}
		/// <summary>
		/// Initializes a new instance of the <see cref="MonoBrick.EV3.SoundSensor"/> class.
		/// </summary>
		/// <param name="mode">Mode.</param>
		public SoundSensor (SoundMode mode) :  base((SensorMode)mode)
		{
		
		}
Beispiel #51
0
		unsafe public OpenALSampleSound( VirtualFileStream stream, SoundType soundType, string name,
			SoundMode mode, out bool initialized )
		{
			initialized = false;

			byte[] samples;
			int sizeInBytes;
			float timeLength;

			if( string.Compare( Path.GetExtension( name ), ".ogg", true ) == 0 )
			{
				//ogg

				VorbisFileReader vorbisFileReader = new VorbisFileReader( stream, false );
				VorbisFile.File vorbisFile = new VorbisFile.File();

				if( !vorbisFileReader.OpenVorbisFile( vorbisFile ) )
				{
					vorbisFile.Dispose();
					vorbisFileReader.Dispose();

					Log.Warning( "OpenALSoundSystem: Creating sound failed \"{0}\" (Reading failed).",
						name );
					return;
				}

				int numSamples = (int)vorbisFile.pcm_total( -1 );

				vorbisFile.get_info( -1, out channels, out frequency );
				timeLength = (float)vorbisFile.time_total( -1 );

				sizeInBytes = numSamples * channels * 2;
				samples = new byte[ sizeInBytes ];

				fixed( byte* pSamples = samples )
				{
					int samplePos = 0;
					while( samplePos < sizeInBytes )
					{
						int readBytes = vorbisFile.read( (IntPtr)( pSamples + samplePos ),
							sizeInBytes - samplePos, 0, 2, 1, IntPtr.Zero );
						if( readBytes <= 0 )
							break;
						samplePos += readBytes;
					}
				}

				vorbisFile.Dispose();
				vorbisFileReader.Dispose();
			}
			else if( string.Compare( Path.GetExtension( name ), ".wav", true ) == 0 )
			{
				//wav

				string error;
				if( !WavLoader.Load( stream, out channels,
					out frequency, out samples, out sizeInBytes, out error ) )
				{
					Log.Warning( "OpenALSoundSystem: Creating sound failed \"{0}\" ({1}).",
						name, error );
					return;
				}

				timeLength = (float)( samples.Length / channels / 2 ) / (float)frequency;
			}
			else
			{
				Log.Warning( "OpenALSoundSystem: Creating sound failed \"{0}\" (Unknown file type).",
					name );
				return;
			}

			//create buffer

			Al.alGenBuffers( 1, out alBuffer );

			int alFormat = ( channels == 1 ) ? Al.AL_FORMAT_MONO16 : Al.AL_FORMAT_STEREO16;

			//bug fix: half volume mono 2D sounds
			//convert to stereo
			if( ( mode & SoundMode.Mode3D ) == 0 && alFormat == Al.AL_FORMAT_MONO16 )
			{
				byte[] stereoSamples = new byte[ sizeInBytes * 2 ];
				for( int n = 0; n < sizeInBytes; n += 2 )
				{
					stereoSamples[ n * 2 + 0 ] = samples[ n ];
					stereoSamples[ n * 2 + 1 ] = samples[ n + 1 ];
					stereoSamples[ n * 2 + 2 ] = samples[ n ];
					stereoSamples[ n * 2 + 3 ] = samples[ n + 1 ];
				}
				samples = stereoSamples;
				alFormat = Al.AL_FORMAT_STEREO16;
				sizeInBytes *= 2;
			}

			//convert to mono for 3D
			if( ( mode & SoundMode.Mode3D ) != 0 && channels == 2 )
			{
				byte[] oldSamples = samples;
				samples = new byte[ oldSamples.Length / 2 ];
				for( int n = 0; n < samples.Length; n += 2 )
				{
					samples[ n + 0 ] = oldSamples[ n * 2 + 0 ];
					samples[ n + 1 ] = oldSamples[ n * 2 + 1 ];
				}
				alFormat = Al.AL_FORMAT_MONO16;
				sizeInBytes /= 2;
			}

			fixed( byte* pSamples = samples )
			{
				Al.alBufferData( alBuffer, alFormat, pSamples, sizeInBytes, frequency );
			}

			if( OpenALSoundWorld.CheckError() )
			{
				Log.Warning( "OpenALSoundSystem: Creating sound failed \"{0}\".", name );
				return;
			}

			Init( name, mode, timeLength, channels, frequency );
			initialized = true;
		}
Beispiel #52
0
 public Sound CreateSound(byte[] data, SoundMode mode = SoundMode.Default)
 {
     IntPtr resultHandle = IntPtr.Zero;
     Errors.ThrowIfError(CreateSound(DangerousGetHandle(), data, mode, 0, ref resultHandle));
     var result = new Sound(resultHandle);
     _sounds.Add(resultHandle, result);
     return result;
 }
Beispiel #53
0
 private static extern ErrorCode GetMode(IntPtr sound, ref SoundMode mode);
Beispiel #54
0
 public Sound CreateStream(byte[] data, SoundMode mode, SoundInfo exinfo)
 {
     IntPtr resultHandle = IntPtr.Zero;
     Errors.ThrowIfError(CreateStream(DangerousGetHandle(), data, mode, ref exinfo, ref resultHandle));
     var result = new Sound(resultHandle);
     _sounds.Add(resultHandle, result);
     return result;
 }
Beispiel #55
0
		public override Sound SoundCreate( VirtualFileStream stream, bool closeStreamAfterReading,
			SoundType soundType, SoundMode mode )
		{
			criticalSection.Enter();

			DirectSound sound;
			bool initialized;

			if( (int)( mode & SoundMode.Stream ) == 0 )
			{
				sound = new DirectSampleSound( stream, soundType, null, mode, out initialized );
				if( closeStreamAfterReading )
					stream.Close();
			}
			else
			{
				sound = new DirectFileStreamSound( stream, closeStreamAfterReading, soundType, null,
					mode, out initialized );
			}

			if( !initialized )
			{
				sound.Dispose();
				sound = null;
			}

			criticalSection.Leave();

			return sound;
		}
Beispiel #56
0
 private static extern ErrorCode CreateSound(IntPtr system, byte[] data, SoundMode mode, ref SoundInfo exinfo, ref IntPtr sound);
Beispiel #57
0
 private static extern ErrorCode SetMode(IntPtr channel, SoundMode mode);
Beispiel #58
0
 private static extern ErrorCode CreateStream(IntPtr system, byte[] data, SoundMode mode, int exinfo, ref IntPtr sound);
Beispiel #59
0
		unsafe public DirectSampleSound( VirtualFileStream stream,
			SoundType soundType, string name, SoundMode mode, out bool initialized )
		{
			initialized = false;

			int channels;
			int frequency;
			float timeLength;

			if( soundType == SoundType.Unknown )
			{
				if( name != null )
					soundType = GetSoundTypeByName( name );
				else
					soundType = GetSoundTypeByStream( stream );
			}

			string error;
			if( !LoadSamplesFromStream( stream, soundType, out channels, out frequency,
				out timeLength, out error ) )
			{
				if( name != null )
				{
					DirectSoundWorld.Warning( string.Format( "Creating sound \"{0}\" failed ({1}).",
						name, error ) );
				}
				else
				{
					DirectSoundWorld.Warning( string.Format( "Creating sound from stream failed ({0}).",
						error ) );
				}
				return;
			}

			//convert to mono for 3D
			if( (int)( mode & SoundMode.Mode3D ) != 0 && channels == 2 )
			{
				byte[] oldSamples = soundSamples;
				soundSamples = new byte[ oldSamples.Length / 2 ];
				for( int n = 0; n < soundSamples.Length; n += 2 )
				{
					soundSamples[ n + 0 ] = oldSamples[ n * 2 + 0 ];
					soundSamples[ n + 1 ] = oldSamples[ n * 2 + 1 ];
				}
				channels = 1;
			}

			//create buffer
			waveFormat = (WAVEFORMATEX*)NativeUtils.Alloc( NativeMemoryAllocationType.SoundAndVideo,
				sizeof( WAVEFORMATEX ) );
			NativeUtils.ZeroMemory( (IntPtr)waveFormat, sizeof( WAVEFORMATEX ) );
			waveFormat->wFormatTag = DSound.WAVE_FORMAT_PCM;
			waveFormat->nChannels = (ushort)channels;
			waveFormat->nSamplesPerSec = (uint)frequency;
			waveFormat->wBitsPerSample = 16;
			waveFormat->nBlockAlign = (ushort)( ( waveFormat->nChannels * waveFormat->wBitsPerSample ) / 8 );
			waveFormat->nAvgBytesPerSec = waveFormat->nSamplesPerSec * waveFormat->nBlockAlign;

			Init( name, mode, timeLength, channels, frequency );
			initialized = true;
		}