Hi,
I am working to implement xmp module player with lazarus pascal, the first test is ok and the module aquarium.digi was played without
problems. Used sdl2 and xmplayer library to call external dll functions;
https://xmp.sourceforge.net/I will extract audio stuff from Sdl2 nothing else .
It's 2h43 late and just performed very interesting code !! stay tuned !!
Regards
Gtr
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls,libxmp,sdl2;
type
ESDL2Error = class(Exception);
Uint8 = Byte;
Uint16 = Word;
Uint32 = LongWord;
Int16 = SmallInt;
Int32 = LongInt;
AudioCallback = procedure(udata: Pointer; stream: PByte; len: Integer); cdecl;
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
MemoInfo: TMemo;
Timer1: TTimer;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
xmp_context : Pointer;
public
ctx: xmp_context;
playing: Boolean;
end;
var
Form1: TForm1;
playing: Boolean;
implementation
{$R *.lfm}
procedure FillAudio(udata: Pointer; stream: PByte; len: Integer); cdecl;
begin
if xmp_play_buffer(xmp_context(udata), stream, len, 0) < 0 then
playing := False;
end;
function SDL_InitAudio(ctx: xmp_context): Integer;
var
a : TSDL_AudioSpec;
begin
// just audio
try
if SDL_Init(SDL_INIT_AUDIO) <> 0 then
raise ESDL2Error.Create('SDL_Init failed: Flag = ' + IntToStr(SDL_INIT_AUDIO));
except
on E: ESDL2Error do
try
SDL_Quit;
except
raise;
end;
end;
SDL_Quit;
// ShowMessage('SDL_Initialized... OK !!');
a.freq := 44100;
a.format := AUDIO_S16;
a.channels := 2;
a.samples := 2048;
a.padding := 0;
a.silence := 0;
a.callback := @FillAudio;
a.userdata := ctx;
if SDL_OpenAudio(@a, nil) < 0 then
begin
ShowMessage(SDL_GetError);
Result := -1;
Exit;
end;
Result := 0;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
mi: xmp_module_info;
begin
ctx := xmp_create_context;
SDL_InitAudio(ctx);
xmp_load_module(ctx, 'worm_hole.s3m');
playing := True;
SDL_PauseAudio(0);
xmp_start_player(ctx, 44100, 0 );
end;
procedure TForm1.Button1Click(Sender: TObject); // stop module
begin
if playing=true then begin
SDL_PauseAudio(1);
xmp_end_player(ctx);
xmp_release_module(ctx);
xmp_free_context(ctx);
SDL_CloseAudio();
playing := false;
end;
end;
procedure TForm1.Button2Click(Sender: TObject); // play
begin
xmp_start_player(ctx, 44100, 0 );
end;
procedure TForm1.Button3Click(Sender: TObject); // load module
begin
ctx := xmp_create_context;
SDL_InitAudio(ctx);
xmp_load_module(ctx, 'worm_hole.s3m');
playing := True;
SDL_PauseAudio(0);
playing := true;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
SDL_PauseAudio(1);
xmp_end_player(ctx);
xmp_release_module(ctx);
xmp_free_context(ctx);
SDL_CloseAudio();
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
mi: xmp_module_info;
fi: xmp_frame_info;
moduleName: String;
begin
xmp_get_module_info(ctx, mi);
xmp_get_frame_info(ctx,fi);
moduleName := String(mi.module^.name);
memoinfo.Lines[8] := 'Title : ' + moduleName ;
// Affichage des informations du module en cours d ecoute 250 ms /
memoinfo.Lines[0] := 'bmp: ' + IntToStr(fi.bpm) ;
memoinfo.Lines[1] := 'speed: ' + IntToStr(fi.speed);
memoinfo.Lines[2] := 'position: ' + IntToStr(fi.pos);
memoinfo.Lines[3] := 'pattern: ' + IntToStr(fi.pattern);
memoinfo.Lines[4] := 'row: ' + IntToStr(fi.row);
memoinfo.Lines[5] := 'virtual Channel: ' + IntToStr(fi.virt_channels);
memoinfo.Lines[6] := 'virtual Used: ' + IntToStr(fi.virt_used);
memoinfo.Lines[7] := 'volume : ' + IntToStr(fi.volume);
end;
end.
Xmp supports many module formats and variations. A few incomplete formats such as DTT and DMF were disabled in recent releases. Currently libxmp recognizes the following formats:
Amiga tracker formats
ChipTracker: KRIS
DIGI Booster: 1.4, 1.5, 1.6, 1.7
DigiBooster Pro (DBM): DBM0
Ice Tracker: IT10
MED 1.12 (MED): MED2
MED 2.10 (MED): MED3
MED 3.00 (MED): MED4
OctaMED (MED): MMD0, MMD1, MMD2, MMD3
Oktalyzer (OKT)
Protracker 3.59
Protracker song
Quadra Composer (EMOD): 0001
Sound/Noise/Protracker standard 31-instrument (MOD): M.K., M!K!, M&K!, N.T.
SoundFX (SFX): 1.3, 2.0?
Soundtracker 15-instrument (MOD, M15)
Soundtracker 2.6 MTN format
Startrekker/Audio Sculpture (MOD, MOD.NT): FLT4/8/N, EXO4/8
Ultimate Soundtracker 15-instrument (MOD)
PC tracker formats
Composer 669/UNIS 669 (669): if, JN
Digitrakker (MDL): 0.0, 1.0, 1.1
Farandole Composer (FAR): 1.0
Fast Tracker II extended module (XM): 1.02, 1.03, 1.04, MED2XM
Fast Tracker multichannel (MOD): 6CHN, 8CHN
Funktracker (FNK): R0, R1, R2
Imago Orpheus (IMF): 1.0
Impulse Tracker (IT): 1.00, 2.00, 2.14, 2.15
Liquid Tracker (LIQ): 0.0, 1.0
Mod's Grave 8-channel M.K. (MOD, WOW)
Multitracker (MTM): 1.0
Poly Tracker (PTM): 2.03
Real Tracker (RTM): 1.00
Scream Tracker 2 (STM): !Scream!, BMOD2STM
Scream Tracker 3 (S3M): 3.00, 3.01+
TakeTracker 4-channel (MOD): TDZ4
TakeTracker/Fast Tracker II multichannel (MOD): xxCH
Ultra Tracker (ULT): V0001, V0002, V0003, V0004
X-Tracker (DMF): 7, 8
Amiga packed formats
AC1D Packer
Heatseeker: mc1.0
FC-M Packer: 1.0
Fuchs Tracker
Fuzzac Packer
Hornet Packer: HRT!
Images Music System
Kefrens Sound Machine
Module Protector
NoisePacker: 1.0, 2.0, 3.0
NoiseRunner
The Player: 4.x, 5.0a, 6.0a, 6.1a
Tracker Packer: 3
Power Music
Pha Packer
ProPacker: 2.1
Promizer: 0.1, 1.0c, 1.8a, 2.0, 4.0
ProRunner: 1.0, 2.0
SKYT Packer
StarTrekker Packer
Titanics Player
Unic Tracker: 1.0, 2.0
Wanton Packer
XANN Packer
Zen Packer
PC packed formats
Dual Module Player DSMI (AMF): 0.9, 1.0, 1.1, 1.2, 1.3, 1.4
Generic Digital Music (GDM): 1.0
ST Music Interface Kit (STX): 1.0, 1.1
Game formats
AMOS Music Bank
ASYLUM Music Format (AMF)
Digital Illusions
Game Music Creator (GMC)
Epic Megagames MASI (PSM): Epic, Sinaria
Galaxy Music System 5.0 (J2B)
Galaxy Music System 4.0
Magnetic Fields Packer
Novotrade Packer
Protracker Studio (PSM): 0.01, 1.00
Slam Tilt
Epic Games Unreal/UT (UMX): IT, S3M, MOD, XM
Atari formats
Digital Tracker (MOD): FA04, FA06, FA08
Digital Tracker (DTM): 1.9
Flextrax (FLX) [effects not supported]
Graoumf Tracker (GTK): GTK1, GTK4
Octalyser multichannel (MOD): CD61, CD81
TCB Tracker (MOD): 'AN COOL.'
Acorn formats
Archimedes Tracker: V1.0+++
Digital Symphony: 0
Desktop Tracker