program project1;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
Classes, SysUtils, CustApp, raylib, uos_libxmp;
type
{ TRayApplication }
TRayApplication = class(TCustomApplication)
protected
procedure DoRun; override;
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
end;
const
AppTitle = 'raylib - basic window';
SampleRate = 44100;
BufferSize = 8192 ; // buffer size=8192 is now Ok !!!
var
playing: boolean;
ctx: xmp_context;
stream: TAudioStream;
mi: xmp_module_info;
fi: xmp_frame_info;
ti : xmp_test_info;
ci : xmp_channel_info;
moduleName: string;
format : string;
procedure FillAudio(bufferData: Pointer; frames: LongWord); cdecl;
begin
if xmp_play_buffer(ctx, bufferData, frames * 4, 0) < 0 then
playing := False;
end;
constructor TRayApplication.Create(TheOwner: TComponent);
var
ordir, thelib: string;
begin
inherited Create(TheOwner);
InitWindow(800, 600, AppTitle); // for window settings, look at example - window flags
ordir := IncludeTrailingBackslash(ExtractFilePath(ParamStr(0)));
{$IFDEF windows}
thelib := 'libxmp.dll';
{$Else}
thelib := 'libxmp-64.so';
{$ENDIF}
writeln(GetApplicationDirectory + thelib);
if xmp_Load(GetApplicationDirectory + thelib) then
begin
ctx := xmp_create_context();
ordir := GetApplicationDirectory + 'oxygene_part_iv.s3m';
if xmp_load_module(ctx, PChar(ordir)) <> 0 then
begin
writeln('Load module error.');
Exit;
end;
xmp_start_player(ctx, SampleRate, 0);
playing := True;
end;
InitAudioDevice;
SetAudioStreamBufferSizeDefault(BufferSize);
stream := LoadAudioStream(SampleRate, 16, 2);
SetAudioStreamCallback(Stream,@FillAudio);
PlayAudioStream(stream); // Start processing stream buffer (no data loaded currently)
end;
procedure TRayApplication.DoRun;
begin
while (not WindowShouldClose) do // Detect window close button or ESC key
begin
// Update your variables here
if playing then
begin
xmp_get_module_info(ctx, mi);
xmp_get_frame_info(ctx,fi);
moduleName := string(mi.module^.name);
format := string(mi.module^.typ);
end else
StopAudioStream(stream);
// Draw
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText(Pchar('bmp: ' + IntToStr(fi.bpm)), 190, 200, 20, DARKGRAY);
DrawText(Pchar('speed: ' + IntToStr(fi.speed)), 190, 220, 20, DARKGRAY);
DrawText(Pchar('position: ' + IntToStr(fi.pos)), 190, 240, 20, DARKGRAY);
DrawText(Pchar('pattern: ' + IntToStr(fi.pattern)), 190, 260, 20, DARKGRAY);
DrawText(Pchar('row: ' + IntToStr(fi.row)), 190, 280, 20, DARKGRAY);
DrawText(Pchar('module channels: ' + IntToStr(mi.module^.chn)), 190, 300, 20, DARKGRAY);
DrawText(Pchar('used channels: ' + IntToStr(fi.virt_used)), 190, 320, 20, DARKGRAY);
DrawText(Pchar('Title : ' + moduleName), 190, 340, 20, DARKGRAY);
DrawText(Pchar('type : ' + format), 190, 360, 20, DARKGRAY);
EndDrawing();
end;
// Stop program loop
Terminate;
end;
destructor TRayApplication.Destroy;
begin
// De-Initialization
UnloadAudioStream(stream); // Close raw audio stream and delete buffers from RAM
CloseAudioDevice(); // Close audio device (music streaming is automatically stopped)
xmp_end_player(ctx);
xmp_release_module(ctx);
xmp_free_context(ctx);
CloseWindow(); // Close window and OpenGL context
inherited Destroy;
end;
var
Application: TRayApplication;
begin
Application:=TRayApplication.Create(nil);
Application.Title:=AppTitle;
Application.Run;
Application.Free;
end.