PDA

View Full Version : Ubuntu & FPC = Confused



code_glitch
25-10-2010, 04:32 PM
Yes its true, my setup crashed. And now I'm on Ubuntu. Its great, until I tried fpc. Woops.

I've tried everything on the first 3 pages of google for about 20 term and no luck, no matter what I try I get the following compiler output:



fpc -MDelphi -Tlinux "PWars.pas" (in directory: /media/ELEMENTS/M777/WIN7 DISK/Users/Ben/Desktop/Probewars/V1.3)
Free Pascal Compiler version 2.4.0-2 [2010/03/06] for x86_64
Copyright (c) 1993-2009 by Florian Klaempfl
Target OS: Linux for x86-64
Compiling PWars.pas
Linking PWars
/usr/bin/ld: warning: link.res contains output sections; did you forget -T?
/usr/bin/ld: cannot find -lSDL
/usr/bin/ld: cannot find -lSDL_image
/usr/bin/ld: cannot find -lSDL_gfx
/usr/bin/ld: cannot find -lSDL_ttf
Compilation failed.
Error: Error while linking
Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
Error: /usr/bin/ppcx64 returned an error exitcode (normal if you did not specify a source file to be compiled)


I'm using Geany but fp and other editors produce the same thing.

Any help would be of great help, thanks.
cheers,
code_glitch.

PS: Does anyone know how to get Programmers Notepad (current stable version) working on WINE?

Stoney
25-10-2010, 05:17 PM
You need the installing the development packages of SDL through your package manager:

libsdl-dev
libsdl_image-dev
libsdl_ttf-dev
libsdl_gfx-dev

After you installed them, it should compile without any problems.

code_glitch
25-10-2010, 05:35 PM
I managed to get libsdl-dev installed. It auto-fixed it to libsdl1.2-dev or something, but I havemt had any luck with any of the others. But it did clear up one of the errors. Is there a repository I need to include?

Cheers,
code_glitch

finally geting used to this... sort of.

Update: I did get two others working:
image by using sudo apt-get install libsdl-image1.2-dev
gfx by using sudo apt-get install libsdl-gfx1.2-dev

which leaves sdl_ttf to which I have absolutely no clue...

for which you have to use sudo apt-get install libsdl-ttf2.0-dev
don't know why but its solved now. Thanks for pointing me in the right direction there stoney.

code_glitch
25-10-2010, 08:12 PM
K, dont know if anyone will read this but how to you get your hands on a copy of the elusive matroska.ppu file?? Or at least how do you get the OpenAl demo from fpc to compile??

cheers to any responses.

Andru
25-10-2010, 09:57 PM
Or at least how do you get the OpenAl demo from fpc to compile?
I have just tried it and... ooops, it's broken now O_o I remember that it worked fine in FPC 2.2.4, but now... So, I fixed it for you :) I removed matroska, mad and dts units, also I replaced alBufferWriteData_LOKI by alBufferData. Here the new madopenal.pas:


program test;

{$mode objfpc}

uses
classes, sysutils, ctypes, openal, ogg, vorbis, a52, modplug;

var
source : TStream;
codec : Integer;
codec_bs : Longword;
codec_read : function(const Buffer: Pointer; const Count: Longword): Longword = nil;
codec_rate : Longword;
codec_chan : Longword;

function source_read_func(datasource: pointer; ptr: pointer; size: cuint): cuint; cdecl;
begin
Result := TStream(datasource).Read(ptr^, size);
end;

function source_read_func_ogg(ptr: pointer; size, nmemb: csize_t; datasource: pointer): csize_t; cdecl;
begin
Result := TStream(datasource).Read(ptr^, size*nmemb);
end;

function source_seek_func(datasource: pointer; offset: clong; whence: cint): clong; cdecl;
begin
case whence of
{SEEK_SET} 0: Result := TStream(datasource).Seek(offset, soFromBeginning);
{SEEK_CUR} 1: Result := TStream(datasource).Seek(offset, soFromCurrent);
{SEEK_END} 2: Result := TStream(datasource).Seek(offset, soFromEnd);
else Result := 0;
end;
end;

function source_seek_func_ogg(datasource: pointer; offset: ogg_int64_t; whence: cint): cint; cdecl;
begin
case whence of
{SEEK_SET} 0: TStream(datasource).Seek(offset, soFromBeginning);
{SEEK_CUR} 1: TStream(datasource).Seek(offset, soFromCurrent);
{SEEK_END} 2: TStream(datasource).Seek(offset, soFromEnd);
end;
Result := 0;
end;

function source_close_func(datasource: pointer): cint; cdecl;
begin
TStream(datasource).Position := 0;
Result := 0;
end;

function source_tell_func(datasource: pointer): clong; cdecl;
begin
Result := TStream(datasource).Position;
end;


// oggvorbis
var
ogg_file : OggVorbis_File;
ogg_callbacks : ov_callbacks;

{procedure ogg_reset;
begin
ov_pcm_seek(ogg_file, 0);
end;}

function ogg_read(const Buffer: Pointer; const Count: Longword): Longword;
var
Res: clong;
begin
Res := ov_read_ext(ogg_file, Buffer, Count, false, 2, true);
if Res < 0 then
Result := 0 else
Result := Res;
end;


// a52
var
a52_decoder : pa52_decoder;

function a52_read(const Buffer: Pointer; const Count: Longword): Longword;
var
Res: cint;
begin
Res := a52_decoder_read(a52_decoder, Buffer, Count);
if Res < 0 then
Result := 0 else
Result := Res;
end;

// modplug
var
mod_file: PModPlugFile;

function mod_read(const Buffer: Pointer; const Count: Longword): Longword;
var
Res: cint;
begin
Res := ModPlug_Read(mod_file, Buffer, Count);
if Res < 0 then
Result := 0 else
Result := Res;
end;


// openal
const
al_format : array[1..2] of ALenum = (AL_FORMAT_MONO16, AL_FORMAT_STEREO16);

// Note: if you lower the al_bufcount, then you have to modify the al_polltime also!
al_bufcount = 4;
al_polltime = 100;

var
al_device : PALCdevice;
al_context : PALCcontext;
al_source : ALuint;
al_buffers : array[0..al_bufcount-1] of ALuint;
al_bufsize : Longword;
al_readbuf : Pointer;

procedure alPlay;
var
i: Integer;
begin
alSourceStop(al_source);
alSourceRewind(al_source);
alSourcei(al_source, AL_BUFFER, 0);

for i := 0 to al_bufcount - 1 do
begin
if codec_read(al_readbuf, al_bufsize) = 0 then
Break;

alBufferData(al_buffers[i], al_format[codec_chan], al_readbuf, al_bufsize, codec_rate);
alSourceQueueBuffers(al_source, 1, @al_buffers[i]);
end;

// Under windows, AL_LOOPING = AL_TRUE breaks queueing, no idea why
alSourcei(al_source, AL_LOOPING, AL_FALSE);
alSourcePlay(al_source);
end;

procedure alStop;
begin
alSourceStop(al_source);
alSourceRewind(al_source);
alSourcei(al_source, AL_BUFFER, 0);
end;

function alProcess: Boolean;
var
processed : ALint;
buffer : ALuint;
begin
alGetSourcei(al_source, AL_BUFFERS_PROCESSED, processed);
while (processed > 0) and (processed <= al_bufcount) do
begin
Write('.');

alSourceUnqueueBuffers(al_source, 1, @buffer);

if codec_read(al_readbuf, al_bufsize) = 0 then
begin
alStop;
Exit(False);
end;

alBufferData(buffer, al_format[codec_chan], al_readbuf, al_bufsize, codec_rate);
alSourceQueueBuffers(al_source, 1, @buffer);

Dec(processed);
end;

Result := True;
end;

var
Filename: String;
ov: pvorbis_info;
tmp: pointer;
begin
// define codec
WriteLn('Define codec');
Writeln(' (1) mp3');
Writeln(' (2) ogg');
Writeln(' (3) ac3');
Writeln(' (4) dts');
Writeln(' (5) xm,mod,it,s3m');
Writeln(' (6) mka');
Write('Enter: '); ReadLn(codec);
Write('File: '); ReadLn(Filename);

{codec := 4;
Filename := 'test.dts';}


// load file
source := TFileStream.Create(Filename, fmOpenRead);


// inittialize codec
case codec of
2: // oggvorbis
begin
ogg_callbacks.read := @source_read_func_ogg;
ogg_callbacks.seek := @source_seek_func_ogg;
ogg_callbacks.close := @source_close_func;
ogg_callbacks.tell := @source_tell_func;

if ov_open_callbacks(source, ogg_file, nil, 0, ogg_callbacks) >= 0 then
begin
ov := ov_info(ogg_file, -1);
codec_read := @ogg_read;
codec_rate := ov^.rate;
codec_chan := ov^.channels;
codec_bs := 2*codec_chan;
end;
end;

3: // a52
begin
a52_decoder := a52_decoder_init(0, source, @source_read_func, @source_seek_func, @source_close_func, @source_tell_func);
codec_read := @a52_read;
codec_rate := 44100;//48000;
codec_chan := 2;
codec_bs := 2*codec_chan;
end;

5: // modplug
begin
GetMem(tmp, source.Size);
source.Read(tmp^, source.Size);
mod_file := ModPlug_Load(tmp, source.Size);
FreeMem(tmp);

codec_read := @mod_read;
codec_rate := 44100;//48000;
codec_chan := 2;
codec_bs := 2*codec_chan;
end;
end;

if not Assigned(codec_read) then
Exit;

//al_bufsize := 20000 - (20000 mod codec_bs);
al_bufsize := 20000 - (20000 mod codec_bs);
WriteLn('Codec Blocksize : ', codec_bs);
WriteLn('Codec Rate : ', codec_rate);
WriteLn('Codec Channels : ', codec_chan);
WriteLn('OpenAL Buffers : ', al_bufcount);
WriteLn('OpenAL Buffer Size : ', al_bufsize);


// init openal
al_device := alcOpenDevice(nil);
al_context := alcCreateContext(al_device, nil);
alcMakeContextCurrent(al_context);

alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED);
alGenSources(1, @al_source);
alGenBuffers(al_bufcount, @al_buffers);

GetMem(al_readbuf, al_bufsize);


// play
alPlay;
while alProcess do
Sleep(al_polltime);

// finalize openal
alDeleteSources(1, @al_source);
alDeleteBuffers(al_bufcount, @al_buffers);
alcDestroyContext(al_context);
alcCloseDevice(al_device);
FreeMem(al_readbuf);


// finalize codec
case codec of
2: // oggvorbis
begin
ov_clear(ogg_file);
end;

3: // a52
begin
a52_decoder_free(a52_decoder);
end;

5: // modplug
begin
ModPlug_Unload(mod_file);
end;
end;


// close file
source.Free;
end.

code_glitch
25-10-2010, 10:09 PM
oh my thankyou thankyou thankyou so much. To be honest, this was the source of all my earlier posts on OpenAl since I'd never used it I had no idea how to fix it... With this, I can finally implement audio properly. Again, thank you so much.

chronozphere
26-10-2010, 06:45 AM
Hi Andru,

that piece of code looks really interesting. Do you know where I can get all the used units?
It would be great if someone could make a nice audio tutorial out of this. :)

Thanks!

code_glitch
26-10-2010, 07:23 AM
What OS are you targeting it at? They should alerady be in your default fpc install. For linux though, you have to go through the above faff and I've no idea about mac.

Andru
26-10-2010, 07:28 AM
that piece of code looks really interesting. Do you know where I can get all the used units?
All those units are part of FreePascal :) And that example also a part of FreePascal.


It would be great if someone could make a nice audio tutorial out of this.
If I would have good English skills... although I hate to write articles in any language, because it's boring :) And there are many articles and discussions about OpenAL and ogg playing(and it not so critical if they are for C++).

User137
27-10-2010, 01:10 PM
So the thing was that fpc 2.2.x has different .res encoding than 2.4.x? I've encountered that a couple times. If working with linux and windows same time better to keep the both using latest compiler. For Windows Lazarus this means latest daily snapshot or SVN. Linux packethandlers should automatically update to latest i guess.

code_glitch
27-10-2010, 02:10 PM
Adding to what User137 said, I can definitely say there is a massive difference to fpc on win32, win64 and linux. Don't know about mac, but if the code for fpc on each of these platforms is the same, then I would definitely rate linux as the better platform in terms of performance and stability but not necessarily ease of use (cryptic error messages sometimes). In terms of performance though, I get an extra 10-25 frames/sec on demo programs than I used to on NT systems, and a lot let crashes; which are a lot easier to solve since it isn't Runtime error 9000 at $123321...

Shame Programmer's Notepad refuse to play nice with wine.