/// <summary>
        ///     Creates a new <see cref="GXPEngine.Sound" />.
        ///     This class represents a sound file.
        ///     Sound files are loaded into memory unless you set them to 'streamed'.
        ///     An optional parameter allows you to create a looping sound.
        /// </summary>
        /// <param name='filename'>
        ///     Filename, should include path and extension.
        /// </param>
        /// <param name='looping'>
        ///     If set to <c>true</c> the sound file repeats itself. (It loops)
        /// </param>
        /// <param name='streaming'>
        ///     If set to <c>true</c>, the file will be streamed rather than loaded into memory.
        /// </param>
        /// <param name='cached'>
        ///     If set to <c>true</c>, the sound will be stored in cache, preserving memory when creating the same sound multiple
        ///     times.
        /// </param>
        public Sound(string filename, bool looping = false, bool streaming = false)
        {
            if (_system == 0)
            {
                // if fmod not initialized, create system and init default
                FMOD.System_Create(out _system);
                FMOD.System_Init(_system, 32, 0, 0);
            }

            uint loop = FMOD.FMOD_LOOP_OFF; // no loop

            if (looping)
            {
                loop = FMOD.FMOD_LOOP_NORMAL;
            }
            if (streaming)
            {
                FMOD.System_CreateStream(_system, filename, loop, 0, out _id);
                if (_id == 0)
                {
                    throw new Exception("Sound file not found: " + filename);
                }
            }
            else
            {
                if (_soundCache.ContainsKey(filename))
                {
                    _id = _soundCache[filename];
                }
                else
                {
                    FMOD.System_CreateSound(_system, filename, loop, 0, out _id);
                    if (_id == 0)
                    {
                        throw new Exception("Sound file not found: " + filename);
                    }
                    _soundCache[filename] = _id;
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a new <see cref="GXPEngine.Sound"/>.
        /// This class represents a sound file.
        /// Sound files are loaded into memory unless you set them to 'streamed'.
        /// An optional parameter allows you to create a looping sound.
        /// </summary>
        /// <param name='filename'>
        /// Filename, should include path and extension.
        /// </param>
        /// <param name='looping'>
        /// If set to <c>true</c> the sound file repeats itself. (It loops)
        /// </param>
        /// <param name='streaming'>
        /// If set to <c>true</c>, the file will be streamed rather than loaded into memory.
        /// </param>
        public Sound(String filename, bool looping = false, bool streaming = false)
        {
            if (_system == 0)                 // if fmod not initialized, create system and init default
            {
                FMOD.System_Create(out _system);
                FMOD.System_Init(_system, 32, 0, 0);
            }
            uint loop = FMOD.FMOD_LOOP_OFF;             // no loop

            if (looping)
            {
                loop = FMOD.FMOD_LOOP_NORMAL;
            }
            if (streaming)
            {
                FMOD.System_CreateStream(_system, filename, loop, 0, out _id);
            }
            else
            {
                FMOD.System_CreateSound(_system, filename, loop, 0, out _id);
            }
        }