View Full Version : Free Pascal Non-OOP sound

06-05-2007, 08:40 PM
Well, I've been trying BASS, and FMOD, but I couldn't make either work (due to my lack of knowledge). Is there a sound system designed SPECIFICALLY for FPC or atleast non-OOP pascal? FMOD would probably work; but the problem lies that the help file shows how to initialize and use only for C/C++ (AFAIK).

So, is there a sound system for FPC thats non-oop? I need to do one thing:
Play .mp3 files from a specific directory, no matter the length/size.

I really don't need much more functionality than that.

06-05-2007, 09:18 PM
openal is not oop, look in my sig - a wrapper for openal which still stays non-oop.

08-05-2007, 12:14 AM
Is there help files available anywhere? If not, I need either an alternative or else instructions on how to use it.

08-05-2007, 03:44 AM
You can try Noeska's OpenAL site. He has his own set of headers, but he also has a bunch of Tutorials as well.


08-05-2007, 11:38 PM
Well, on an inspection of OpenAL, it is either oop, or delphi. Either way, I don't understand it. My program doesn't have graphics to have a 'form' or 'button', which the OpenAL tutorials have in them. I can compile fine, but the program does not run. (I simply put it in a new procedure and changed the .wav file.) When called, it just simply doesn't do anything. I had a repeat-until going, so it should of worked, or at the minimum play the sound atleast once. But it didn't... So... I'm confused.

Edit: 2D sound works too... All I'm using it for (for now) is playing sounds.

Edit: Or maybe I need to learn classes?

09-05-2007, 04:14 AM
my little openal wrapper is pretty easy to figure out, it's pretty trivial - you load wav files with it and playback them as sources. it comes with an example too.

09-05-2007, 10:47 AM
I can't compile it though... I'm not using Lazarus or Delphi.. Just plain old FPC. And FPC doesn't have the units for forms, dialogs, buttons, etc...

Plus I have no clue what implementation is, so that doesn't help. None of the example is commented, either. Maybe if you could comment it for me?

09-05-2007, 11:18 AM

The main thing is only in AL_Lib.pas and VirtualOpenAL.pas, and those VCL units used are easily replaced by whatever you use in FPC.

09-05-2007, 06:04 PM
Just curious.

What is your os.

Do you have the openal runtime installed.

Are you using fpc or delphi.

The examples on my site are for delphi, but should also work with fpc. Just leave out the forms stuff.

E.g. i have had an working example with fpc under linux and openal.

Take a look at: http://www.noeska.com/doal/lesson13.aspx this has an fpc example project. It should provide info on your soundcard.

program fpcopenaldemo;

//compile with fpc -Sd fpcopenaldemo.pas

uses openal;

buffer : TALuint;
source : TALuint;
sourcepos: array [0..2] of TALfloat= ( 0.0, 0.0, 0.0 );
sourcevel: array [0..2] of TALfloat= ( 0.0, 0.0, 0.0 );
listenerpos: array [0..2] of TALfloat= ( 0.0, 0.0, 0.0);
listenervel: array [0..2] of TALfloat= ( 0.0, 0.0, 0.0);
listenerori: array [0..5] of TALfloat= ( 0.0, 0.0, -1.0, 0.0, 1.0, 0.0);
Context: PALCcontext;
Device: PALCdevice;

data : Array[0..1000] OF Byte;
loop : Integer;

writeln('hello world!');

//init openal library under windows you should use InitOpenAL()
if InitOpenAL('libopenal.so') then
writeln('OpenAl lib found')
writeln('Oops OpenAL not found')

//Open (selected) device
Device := alcOpenDevice(nil); // this is supposed to select the "preferred device"

writeln('Open Device');

//Create context(s)
Context := alcCreateContext(Device,nil);

//Set active context

//Clear Error Code

writeln('init done');

//Create Buffers
AlGenBuffers(1, @buffer);
For Loop:=0 to 1000 do
data[loop] := Round(50*sin(loop*(5*pi)/50.0)+128);
alBufferData(buffer, AL_FORMAT_MONO8, @data, 1001, 11024);

//Create Sources
AlGenSources(1, @source);
AlSourcei ( source, AL_BUFFER, buffer);
AlSourcef ( source, AL_PITCH, 1.0 );
AlSourcef ( source, AL_GAIN, 1.0 );
AlSourcefv ( source, AL_POSITION, @sourcepos);
AlSourcefv ( source, AL_VELOCITY, @sourcevel);
AlSourcei ( source, AL_LOOPING, AL_TRUE);

//Create Listener
AlListenerfv ( AL_POSITION, @listenerpos);
AlListenerfv ( AL_VELOCITY, @listenervel);
AlListenerfv ( AL_ORIENTATION, @listenerori);

//start playing sound

Writeln('Press [ENTER] to stop playing sound');

//stop playing sound

AlDeleteBuffers(1, @buffer);
AlDeleteSources(1, @source);

//Free Context and Device

//Get active context
//Get device for active context
//Release context(s)
//Close device


09-05-2007, 06:59 PM
No openal runtime (didn't realize I needed it).

I will take a look at your example, thanks.
I'm new to any type of audio/graphical programming... so thats why I'm so stuck. I'm a noob :( Must fix that :)

10-05-2007, 11:41 PM
Well, with some messing around, and having found a file on this site for FPCBass, I have gotten Bass working. It's playing my sounds, and thats all I need :) Thanks for all the help, guys.