PDA

View Full Version : Free Pascal Non-OOP sound



DarknessX
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.

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

DarknessX
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.

WILL
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.

http://www.noeska.com/doal/

DarknessX
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?

JernejL
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.

DarknessX
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?

JernejL
09-05-2007, 11:18 AM
http://www.pascalgamedevelopment.com/viewtopic.php?p=33161#33161

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.

noeska
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;

var
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;

begin
writeln('hello world!');

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

//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
alcMakeContextCurrent(Context);

//Clear Error Code
//alGetError();

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
AlSourcePlay(source);

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

//stop playing sound
AlSourceStop(source);

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

//Free Context and Device

//Get active context
Context:=alcGetCurrentContext();
//Get device for active context
Device:=alcGetContextsDevice(Context);
//Release context(s)
alcDestroyContext(Context);
//Close device
alcCloseDevice(Device);

end.

DarknessX
09-05-2007, 06:59 PM
Windows,
FPC,
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 :)

DarknessX
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.