In this lesson we take a look inside thing that were handled by alut previously.
As always we use the files from lesson 1 as a starting point. To the form you need to add a combobox and a button. The combobox will be used to display sound devices detected by openal. The button will be used to set the sound device selected from the combobox.
For the dectection of sound devices we will need the ALC_ENUMERATION_EXT extension. This will work as follows:
defaultDevice := '';
deviceList := '';
if alcIsExtensionPresent(nil,'ALC_ENUMERATION_EXT') = TRUE then
defaultDevice := alcGetString(nil, ALC_DEFAULT_DEVICE_SPECIFIER);
deviceList := alcGetString(nil, ALC_DEVICE_SPECIFIER);
Next we need to parse the list of sound devices:
//make devices tstringlist
for loop:=0 to 12 do
if length(DeviceList)<=0 then break; //exit loop if no more devices are found
Now it is easy to fill the combobox:
//fill the combobox
After the user made an selection from the combobox we need to set that sound device or the default sound device.
//Open (selected) device
if SelectDevice.itemindex = 0 then
Device := alcOpenDevice(nil) // this is supposed to select the "preferred device"
Device := alcOpenDevice(pchar(SelectDevice.Items[SelectDevice.itemindex])); //use the chosen one
Context := alcCreateContext(Device,nil);
//Set active context
//Clear Error Code
Now you can setup buffer, sources, listeners as you are used to do. In the example a buffer is filled with a not proper looped sinewave to let you hear the differences between your sound devices.
When closing the form (application) we need to clean up after ourselves (there is no more alutexit to use anymore):
//Get active context
//Get device for active context