2008-01-19 15:26:16 +00:00
|
|
|
|
#region --- License ---
|
|
|
|
|
/* Copyright (c) 2006-2008 the OpenTK team
|
|
|
|
|
* See license.txt for licensing details
|
|
|
|
|
*/
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
using System;
|
2008-01-11 20:17:01 +00:00
|
|
|
|
|
|
|
|
|
using OpenTK.OpenAL;
|
2008-01-17 14:07:32 +00:00
|
|
|
|
using OpenTK.OpenAL.Enums;
|
|
|
|
|
using OpenTK.Audio;
|
2008-01-11 20:17:01 +00:00
|
|
|
|
|
|
|
|
|
using AlContext = System.IntPtr;
|
|
|
|
|
using AlDevice = System.IntPtr;
|
2008-01-18 15:10:25 +00:00
|
|
|
|
using System.Diagnostics;
|
2008-01-11 20:17:01 +00:00
|
|
|
|
|
2008-01-17 14:07:32 +00:00
|
|
|
|
namespace Examples
|
2008-01-11 20:17:01 +00:00
|
|
|
|
{
|
2008-01-18 14:00:28 +00:00
|
|
|
|
[Example("AudioContext Test", ExampleCategory.Test)]
|
2008-01-11 20:17:01 +00:00
|
|
|
|
class TestApp
|
|
|
|
|
{
|
2008-01-18 15:10:25 +00:00
|
|
|
|
public static void PrintOpenALErrors( IntPtr device )
|
2008-01-11 20:17:01 +00:00
|
|
|
|
{
|
2008-01-18 15:10:25 +00:00
|
|
|
|
ALError AlErr = AL.GetError();
|
|
|
|
|
// AudioContext should throw on errors, so no need to test them manually.
|
|
|
|
|
//AlcError AlcErr = Alc.GetError(device);
|
|
|
|
|
AlutError AlutErr = Alut.GetError();
|
|
|
|
|
Console.WriteLine("Al: " + AlErr + " Alut: " + Alut.GetErrorString(AlutErr));
|
2008-01-11 20:17:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-01-17 14:07:32 +00:00
|
|
|
|
public static void Main()
|
2008-01-11 20:17:01 +00:00
|
|
|
|
{
|
2008-01-17 14:07:32 +00:00
|
|
|
|
AlcUnitTestFunc();
|
2008-01-11 20:17:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void AlcUnitTestFunc()
|
|
|
|
|
{
|
2008-01-18 14:13:04 +00:00
|
|
|
|
AudioContext context = new AudioContext();
|
|
|
|
|
|
2008-01-18 15:10:25 +00:00
|
|
|
|
Trace.WriteLine("Testing AudioContext functions.");
|
|
|
|
|
Trace.Indent();
|
|
|
|
|
|
|
|
|
|
Trace.WriteLine("Suspend()...");
|
|
|
|
|
context.Suspend();
|
|
|
|
|
Trace.Assert(!context.IsProcessing);
|
|
|
|
|
|
|
|
|
|
Trace.WriteLine("Process()...");
|
|
|
|
|
context.Process();
|
|
|
|
|
Trace.Assert(context.IsProcessing);
|
|
|
|
|
|
|
|
|
|
Trace.WriteLine("MakeCurrent()...");
|
|
|
|
|
context.MakeCurrent();
|
|
|
|
|
Trace.Assert(context.IsCurrent);
|
|
|
|
|
|
|
|
|
|
Trace.WriteLine("IsCurrent = false...");
|
|
|
|
|
context.IsCurrent = false;
|
|
|
|
|
Trace.Assert(!context.IsCurrent);
|
|
|
|
|
|
2008-01-19 15:26:16 +00:00
|
|
|
|
Trace.WriteLine("IsCurrent = true...");
|
|
|
|
|
context.IsCurrent = true;
|
2008-01-20 22:12:04 +00:00
|
|
|
|
Trace.Assert(context.IsCurrent);
|
2008-01-19 15:26:16 +00:00
|
|
|
|
|
|
|
|
|
Trace.WriteLine("AudioContext.CurrentContext...");
|
|
|
|
|
Trace.Assert(AudioContext.CurrentContext == context);
|
|
|
|
|
|
|
|
|
|
#region Get Attribs
|
|
|
|
|
|
|
|
|
|
int AttribCount;
|
|
|
|
|
Alc.GetInteger(context.Device, AlcGetInteger.AttributesSize, sizeof(int), out AttribCount);
|
|
|
|
|
Console.WriteLine("AttributeSize: " + AttribCount);
|
|
|
|
|
|
|
|
|
|
if (AttribCount > 0)
|
|
|
|
|
{
|
|
|
|
|
int[] Attribs = new int[AttribCount];
|
|
|
|
|
Alc.GetInteger(context.Device, AlcGetInteger.AllAttributes, AttribCount, out Attribs[0]);
|
|
|
|
|
for (int i = 0; i < Attribs.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
Console.Write(Attribs[i]);
|
|
|
|
|
Console.Write(" ");
|
|
|
|
|
}
|
|
|
|
|
Console.WriteLine();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion Get Attribs
|
|
|
|
|
|
2008-01-18 15:10:25 +00:00
|
|
|
|
#if false
|
2008-01-11 20:17:01 +00:00
|
|
|
|
AlDevice MyDevice;
|
|
|
|
|
AlContext MyContext;
|
|
|
|
|
|
|
|
|
|
// Initialize Open AL
|
|
|
|
|
MyDevice = Alc.OpenDevice( null );// open default device
|
|
|
|
|
if ( MyDevice != Al.Null )
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine( "Device allocation succeeded." );
|
|
|
|
|
MyContext = Alc.CreateContext( MyDevice, Al.Null ); // create context
|
|
|
|
|
if ( MyContext != Al.Null )
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine( "Context allocation succeeded." );
|
|
|
|
|
GetOpenALErrors( MyDevice );
|
|
|
|
|
|
|
|
|
|
Alc.SuspendContext( MyContext ); // disable context
|
|
|
|
|
Alc.ProcessContext( MyContext ); // enable context. The default state of a context created by alcCreateContext is that it is processing.
|
|
|
|
|
Al.Bool result = Alc.MakeContextCurrent( MyContext ); // set active context
|
|
|
|
|
Console.WriteLine( "MakeContextCurrent succeeded? " + result );
|
|
|
|
|
GetOpenALErrors( MyDevice );
|
|
|
|
|
|
|
|
|
|
Console.WriteLine( "Default: " + Alc.GetString( MyDevice, Enums.AlcGetString.DefaultDeviceSpecifier ) );
|
|
|
|
|
Console.WriteLine( "Device: " + Alc.GetString( MyDevice, Enums.AlcGetString.DeviceSpecifier ) );
|
|
|
|
|
Console.WriteLine( "Extensions: " + Alc.GetString( MyDevice, Enums.AlcGetString.Extensions ) );
|
|
|
|
|
GetOpenALErrors( MyDevice );
|
|
|
|
|
|
|
|
|
|
#region Get Attribs
|
|
|
|
|
int AttribCount;
|
|
|
|
|
Alc.GetInteger( MyDevice, Enums.AlcGetInteger.AttributesSize, sizeof( int ), out AttribCount );
|
|
|
|
|
Console.WriteLine( "AttributeSize: " + AttribCount );
|
|
|
|
|
|
|
|
|
|
if ( AttribCount > 0 )
|
|
|
|
|
{
|
|
|
|
|
int[] Attribs = new int[AttribCount];
|
|
|
|
|
Alc.GetInteger( MyDevice, Enums.AlcGetInteger.AttributesSize, AttribCount, out Attribs[0] );
|
|
|
|
|
for ( int i = 0; i < Attribs.Length; i++ )
|
|
|
|
|
Console.Write( ", " + Attribs[i] );
|
|
|
|
|
Console.WriteLine( );
|
|
|
|
|
}
|
|
|
|
|
#endregion Get Attribs
|
|
|
|
|
GetOpenALErrors( MyDevice );
|
|
|
|
|
|
|
|
|
|
AlDevice currdev = Alc.GetContextsDevice( MyContext );
|
|
|
|
|
AlContext currcon = Alc.GetCurrentContext( );
|
|
|
|
|
|
|
|
|
|
if ( MyDevice == currdev )
|
|
|
|
|
Console.WriteLine( "Devices match." );
|
|
|
|
|
else
|
|
|
|
|
Console.WriteLine( "Error: Devices do not match." );
|
|
|
|
|
|
|
|
|
|
if ( MyContext == currcon )
|
|
|
|
|
Console.WriteLine( "Context match." );
|
|
|
|
|
else
|
|
|
|
|
Console.WriteLine( "Error: Contexts do not match." );
|
|
|
|
|
|
|
|
|
|
// exit
|
|
|
|
|
Alc.MakeContextCurrent( Al.Null ); // results in no context being current
|
|
|
|
|
Alc.DestroyContext( MyContext );
|
|
|
|
|
result = Alc.CloseDevice( MyDevice );
|
|
|
|
|
Console.WriteLine( "Result: " + result );
|
|
|
|
|
Console.ReadLine( );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine( "Context creation failed." );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine( "Failed to find suitable Device." );
|
|
|
|
|
}
|
2008-01-18 15:10:25 +00:00
|
|
|
|
#endif
|
2008-01-11 20:17:01 +00:00
|
|
|
|
/*
|
|
|
|
|
include <stdlib.h>
|
|
|
|
|
include <AL/alut.h>
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
main (int argc, char **argv)
|
|
|
|
|
{
|
|
|
|
|
ALuint helloBuffer, helloSource;
|
|
|
|
|
alutInit (&argc, argv);
|
2008-01-18 14:00:28 +00:00
|
|
|
|
helloBuffer = alutCreateBufferHelloWorld (); alGenSources (1, &helloSource);
|
2008-01-11 20:17:01 +00:00
|
|
|
|
alSourcei (helloSource, AL_Buffer, helloBuffer);
|
|
|
|
|
alSourcePlay (helloSource);
|
|
|
|
|
alutSleep (1);
|
|
|
|
|
alutExit ();
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
* Processing Loop Example:
|
|
|
|
|
// PlaceCamera - places OpenGL camera & updates OpenAL listener data
|
|
|
|
|
void AVEnvironment::PlaceCamera()
|
|
|
|
|
{
|
|
|
|
|
// update OpenGL camera position
|
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
|
glLoadIdentity();
|
|
|
|
|
glFrustum(-0.1333, 0.1333, -0.1, 0.1, 0.2, 50.0);
|
|
|
|
|
gluLookAt(listenerPos[0], listenerPos[1], listenerPos[2],
|
|
|
|
|
(listenerPos[0] + sin(listenerAngle)), listenerPos[1],
|
|
|
|
|
(listenerPos[2] - cos(listenerAngle)),
|
|
|
|
|
0.0, 1.0, 0.0);
|
|
|
|
|
// update OpenAL
|
|
|
|
|
// place listener at camera
|
|
|
|
|
alListener3f(AL_POSITION, listenerPos[0], listenerPos[1], listenerPos[2]);
|
|
|
|
|
float directionvect[6];
|
|
|
|
|
directionvect[0] = (float) sin(listenerAngle);
|
|
|
|
|
directionvect[1] = 0;
|
|
|
|
|
directionvect[2] = (float) cos(listenerAngle);
|
|
|
|
|
directionvect[3] = 0;
|
|
|
|
|
directionvect[4] = 1;
|
|
|
|
|
directionvect[5] = 0;
|
|
|
|
|
alListenerfv(AL_ORIENTATION, directionvect);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|