Пример #1
0
 public SoundManager()
 {
     Alut.alutInit();
     DiscoverSoundChannels();
 }
Пример #2
0
        private static void Keyboard(byte key, int x, int y)
        {
            switch (key)
            {
            case (byte)'1':
                Al.alSourcePlay(source[0]);
                break;

            case (byte)'2':
                Al.alSourcePlay(source[1]);
                break;

            case (byte)'3':
                Al.alSourcePlay(source[2]);
                break;

            case (byte)'4':
                Al.alSourceStop(source[0]);
                break;

            case (byte)'5':
                Al.alSourceStop(source[1]);
                break;

            case (byte)'6':
                Al.alSourceStop(source[2]);
                break;

            case (byte)'w':
            case (byte)'W':
                listenerPosition[2] -= 0.1f;
                Al.alListenerfv(Al.AL_POSITION, listenerPosition);
                break;

            case (byte)'a':
            case (byte)'A':
                listenerPosition[0] -= 0.1f;
                Al.alListenerfv(Al.AL_POSITION, listenerPosition);
                break;

            case (byte)'s':
            case (byte)'S':
                listenerPosition[2] += 0.1f;
                Al.alListenerfv(Al.AL_POSITION, listenerPosition);
                break;

            case (byte)'d':
            case (byte)'D':
                listenerPosition[0] += 0.1f;
                Al.alListenerfv(Al.AL_POSITION, listenerPosition);
                break;

            case 27:
                Al.alSourceStop(source[2]);
                Al.alSourceStop(source[1]);
                Al.alSourceStop(source[0]);
                Alut.alutExit();
                Glut.glutDestroyWindow(window);
                Environment.Exit(0);
                break;

            default:
                break;
            }
            Glut.glutPostRedisplay();
        }
Пример #3
0
        private string fileName;                        //The file to play

        //Initialise the player
        public WavPlayer(string fileName)
        {
            this.fileName = fileName;
            Alut.alutInit();
            LoadALData();
        }
Пример #4
0
        private static void Init()
        {
            Gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

            Al.alListenerfv(Al.AL_POSITION, listenerPosition);
            Al.alListenerfv(Al.AL_VELOCITY, listenerVelocity);
            Al.alListenerfv(Al.AL_ORIENTATION, listenerOrientation);

            Al.alGetError();
            Al.alGenBuffers(NUM_BUFFERS, buffer);
            if (Al.alGetError() != Al.AL_NO_ERROR)
            {
                Console.WriteLine("Error creating buffers.");
                Environment.Exit(-1);
            }

            string fileName = "";

            fileName = FindFile("OpenAlExamples.Boxes.C.wav");
            if (fileName == null)
            {
                Environment.Exit(-1);
            }
            data = Alut.alutLoadMemoryFromFile(fileName, out format, out size, out frequency);
            Al.alBufferData(buffer[0], format, data, size, (int)frequency);
            //Alut.alutUnloadWAV(format, out data, size, frequency);

            fileName = FindFile("OpenAlExamples.Boxes.B.wav");
            if (fileName == null)
            {
                Environment.Exit(-1);
            }
            data = Alut.alutLoadMemoryFromFile(fileName, out format, out size, out frequency);
            Al.alBufferData(buffer[1], format, data, size, (int)frequency);
            //Alut.alutUnloadWAV(format, out data, size, frequency);

            fileName = FindFile("OpenAlExamples.Boxes.A.wav");
            if (fileName == null)
            {
                Environment.Exit(-1);
            }
            data = Alut.alutLoadMemoryFromFile(fileName, out format, out size, out frequency);
            Al.alBufferData(buffer[2], format, data, size, (int)frequency);
            //Alut.alutUnloadWAV(format, out data, size, frequency);

            Al.alGetError();
            Al.alGenSources(NUM_SOURCES, source);
            if (Al.alGetError() != Al.AL_NO_ERROR)
            {
                Console.WriteLine("Error creating sources.");
                Environment.Exit(-1);
            }

            Al.alSourcef(source[0], Al.AL_PITCH, 1.0f);
            Al.alSourcef(source[0], Al.AL_GAIN, 1.0f);
            Al.alSourcefv(source[0], Al.AL_POSITION, redPosition);
            Al.alSourcefv(source[0], Al.AL_VELOCITY, redVelocity);
            Al.alSourcei(source[0], Al.AL_BUFFER, buffer[0]);
            Al.alSourcei(source[0], Al.AL_LOOPING, Al.AL_TRUE);

            Al.alSourcef(source[1], Al.AL_PITCH, 1.0f);
            Al.alSourcef(source[1], Al.AL_GAIN, 1.0f);
            Al.alSourcefv(source[1], Al.AL_POSITION, greenPosition);
            Al.alSourcefv(source[1], Al.AL_VELOCITY, greenVelocity);
            Al.alSourcei(source[1], Al.AL_BUFFER, buffer[1]);
            Al.alSourcei(source[1], Al.AL_LOOPING, Al.AL_TRUE);

            Al.alSourcef(source[2], Al.AL_PITCH, 1.0f);
            Al.alSourcef(source[2], Al.AL_GAIN, 1.0f);
            Al.alSourcefv(source[2], Al.AL_POSITION, bluePosition);
            Al.alSourcefv(source[2], Al.AL_VELOCITY, blueVelocity);
            Al.alSourcei(source[2], Al.AL_BUFFER, buffer[2]);
            Al.alSourcei(source[2], Al.AL_LOOPING, Al.AL_TRUE);
        }