Exemplo n.º 1
0
        private Sound LoadSoundDirect([NotNull] string fileName, [NotNull] byte[] data, [NotNull] WaveFormat format, bool cloneData, bool manageResult)
        {
            var buffer = new AudioBuffer(_context);

            buffer.BufferData(data, format.SampleRate);

            var source = new AudioSource(_context);

            source.Bind(buffer);

            var sound = new Sound(source, buffer, format);

            if (manageResult)
            {
                if (cloneData)
                {
                    sound.Data = (byte[])data.Clone();
                }
                else
                {
                    sound.Data = data;
                }

                _loadedSounds.Add((fileName, sound));
            }

            return(sound);
        }
Exemplo n.º 2
0
        public static bool SNDDMA_Init()
        {
            if (snd_inited)
            {
                return(true);
            }
            if (sndbits == null)
            {
                sndbits     = Cvar.Get("sndbits", "16", CVAR_ARCHIVE);
                sndspeed    = Cvar.Get("sndspeed", "0", CVAR_ARCHIVE);
                sndchannels = Cvar.Get("sndchannels", "1", CVAR_ARCHIVE);
            }

            audioEngine = AudioEngine.CreateOpenAL();
            audioBuffer = audioEngine.CreateBuffer();
            audioSource = audioEngine.CreateSource();

            format = new AudioFormat();
            format.BitsPerSample = 16;
            format.Channels      = 2;
            format.SampleRate    = 22050;

            audioBuffer.BufferData(dma.buffer, format);
            audioSource.QueueBuffer(audioBuffer);

            dma.buffer           = new byte[65536];
            dma.channels         = format.Channels;
            dma.samplebits       = format.BitsPerSample;
            dma.samples          = dma.buffer.Length / format.BytesPerSample;
            dma.speed            = (int)format.SampleRate;
            dma.submission_chunk = 1;

            thread = new SoundThread(dma.buffer, audioEngine);
            thread.Start();
            snd_inited = true;
            return(true);
        }