0
0

Hi!

I’m using Delphi 7, and I’m trying to play a song from memory. I have my song in a table of array.. like this:

CONST table : array[0..10977] of byte = (
$63, $72, $61, $63, $6B, $74, $75, $6E, $65, $30, $31, $00, $00, $00, $00, $00……………

How can I play this way? I’ve already read the loadfrommemory example in C but no success with a table of array :(

I’m using this code to play, but a error is happening:

[code:m7pbxjjh]
result := FMOD_System_Create(system);
ErrCheck(result);

result := FMOD_System_GetVersion(system, version);
ErrCheck(result);

if (version < FMOD_VERSION) then begin
showmessage(Format(’Error! You are using an old version of FMOD %.8x. This program requires %.8x’, [version, FMOD_VERSION]));
end;

result := FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, nil);
ERRCHECK(result);

// This is the point ..
result := FMOD_System_CreateSound(system, addr(table), FMOD_OPENMEMORY, nil, sound1);
ErrCheck(result);

result := FMOD_Sound_SetMode(sound1, FMOD_LOOP_OFF);
ErrCheck(result);

result := FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound1, False, channel);
ErrCheck(result);
[/code:m7pbxjjh]

Thanks in advance

  • You must to post comments
0
0

Hello,

Here’s my Delphi 7 port of the loadfrommemory example.

I haven’t done any FmodEx work since build 40416, but it still seems to work.

HTH

Send me a PM if you need more assistance as I’m not looking here much.

Kim

[code:fev9zqyt]
{===============================================================================================
Load from memory example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2005.

This example is simply a variant of the play sound example, but it loads the data into memory
then uses the ‘load from memory’ feature of System::createSound.
===============================================================================================}
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, FmodEx, FmodExErrors, FModExTypes, ComCtrls, StrUtils;
//Please note – this uses my unofficial FmodEx version of the Fmod Delphi libs, either use mine or use the original downloads, the originals might not work however.

type
TForm1 = class(TForm)
btnMonoHardware: TButton;
btnMonoSoftware: TButton;
brnStereoHardware: TButton;
Timer1: TTimer;
btnExit: TButton;
Label1: TLabel;
StatusBar: TStatusBar;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure btnExitClick(Sender: TObject);
procedure btnMonoHardwareClick(Sender: TObject);
procedure btnMonoSoftwareClick(Sender: TObject);
procedure brnStereoHardwareClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
system: FMOD_SYSTEM;
sound1, sound2, sound3: FMOD_SOUND;
channel: FMOD_CHANNEL = nil;
result: FMOD_RESULT;
version: cardinal;

implementation

{$R *.dfm}

procedure ErrCheck(result: FMOD_RESULT);
begin
if (result <> FMOD_OK) then begin
showmessage(’FMOD error! ‘ + FMOD_ErrorString(result));
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
exinfo: PFMOD_CREATESOUNDEXINFO;
memstream: TMemoryStream;
begin

result := FMOD_System_Create(system);
ErrCheck(result);

result := FMOD_System_GetVersion(system, version);
ErrCheck(result);

if (version < FMOD_VERSION) then begin
showmessage(Format(’Error! You are using an old version of FMOD %.8x. This program requires %.8x’, [version, FMOD_VERSION]));
end;

result := FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, nil);
ERRCHECK(result);

memstream := TMemoryStream.Create;
memstream.LoadFromFile(’..\..\examples\media\drumloop.wav’);
new(exinfo);
FillChar(exinfo^, sizeof(FMOD_CREATESOUNDEXINFO), 0);
Exinfo.cbsize := sizeof(FMOD_CREATESOUNDEXINFO);
Exinfo.length := memstream.Size;
result := FMOD_System_CreateSound(system, PChar(memstream.memory), FMOD_HARDWARE or FMOD_OPENMEMORY, exinfo, sound1);
ERRCHECK(result);
Dispose(exinfo);
result := FMOD_Sound_SetMode(sound1, FMOD_LOOP_OFF);
ERRCHECK(result);
memstream.Free; // don’t need the original memory any more. Note! If loading as a stream, the memory must stay active so do not free it!

memstream := TMemoryStream.Create;
memstream.LoadFromFile(’..\..\examples\media\jaguar.wav’);
new(exinfo);
FillChar(exinfo^, sizeof(FMOD_CREATESOUNDEXINFO), 0);
Exinfo.cbsize := sizeof(FMOD_CREATESOUNDEXINFO);
Exinfo.length := memstream.Size;
result := FMOD_System_CreateSound(system, PChar(memstream.memory), FMOD_HARDWARE or FMOD_OPENMEMORY, exinfo, sound2);
ERRCHECK(result);
Dispose(exinfo);
result := FMOD_Sound_SetMode(sound1, FMOD_LOOP_OFF);
ERRCHECK(result);
memstream.Free; // don’t need the original memory any more. Note! If loading as a stream, the memory must stay active so do not free it!

memstream := TMemoryStream.Create;
memstream.LoadFromFile(’..\..\examples\media\swish.wav’);
new(exinfo);
FillChar(exinfo^, sizeof(FMOD_CREATESOUNDEXINFO), 0);
Exinfo.cbsize := sizeof(FMOD_CREATESOUNDEXINFO);
Exinfo.length := memstream.Size;
result := FMOD_System_CreateSound(system, PChar(memstream.memory), FMOD_HARDWARE or FMOD_OPENMEMORY, exinfo, sound3);
ERRCHECK(result);
Dispose(exinfo);
result := FMOD_Sound_SetMode(sound1, FMOD_LOOP_OFF);
ERRCHECK(result);
memstream.Free; // don’t need the original memory any more. Note! If loading as a stream, the memory must stay active so do not free it!

end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
ms, lenms: cardinal;
channelsplaying: integer;
currentsound: FMOD_SOUND;
playing, paused: boolean;
begin
if channel <> nil then begin
result := FMOD_Channel_IsPlaying(channel, playing);
if (result <> FMOD_OK) and (result <> FMOD_ERR_INVALID_HANDLE) and (result <> FMOD_ERR_CHANNEL_STOLEN) then ERRCHECK(result);

result := FMOD_Channel_GetPaused(channel, paused);
if (result &lt;&gt; FMOD_OK) and (result &lt;&gt; FMOD_ERR_INVALID_HANDLE) and (result &lt;&gt; FMOD_ERR_CHANNEL_STOLEN) then ERRCHECK(result);

result := FMOD_Channel_GetPosition(channel, ms, FMOD_TIMEUNIT_MS);
if ((result &lt;&gt; FMOD_OK) and (result &lt;&gt; FMOD_ERR_INVALID_HANDLE) and (result &lt;&gt; FMOD_ERR_CHANNEL_STOLEN)) then ERRCHECK(result);

result := FMOD_Channel_GetCurrentSound(channel, currentsound);
if currentsound &lt;&gt; nil then result := FMOD_Sound_GetLength(currentsound, lenms, FMOD_TIMEUNIT_MS);
if (result &lt;&gt; FMOD_OK) and (result &lt;&gt; FMOD_ERR_INVALID_HANDLE) and (result &lt;&gt; FMOD_ERR_CHANNEL_STOLEN) then ERRCHECK(result);

end;

result := FMOD_System_GetChannelsPlaying(system, channelsplaying);
ERRCHECK(result);

StatusBar.SimpleText := ‘Time: ‘ + InttoStr(ms) + ‘mS of ‘ + InttoStr(lenms)
+ IfThen(paused, ‘mS Paused’, IfThen(playing, ‘mS Playing’, ‘mS Stopped’)) + ‘: Channels Playing: ‘ + inttoStr(channelsplaying);

if system <> nil then begin
result := FMOD_System_Update(system);
ERRCHECK(result);
end;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if sound1 <> nil then begin
result := FMOD_Sound_Release(sound1);
ErrCheck(result);
end;
if system <> nil then begin
result := FMOD_System_Close(system);
ErrCheck(result);
result := FMOD_System_Release(system);
ErrCheck(result);
end;
end;

procedure TForm1.btnExitClick(Sender: TObject);
begin
application.Terminate;
end;

procedure TForm1.btnMonoHardwareClick(Sender: TObject);
begin
result := FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound1, False, channel);
ErrCheck(result);
end;

procedure TForm1.btnMonoSoftwareClick(Sender: TObject);
begin
result := FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound2, False, channel);
ErrCheck(result);
end;

procedure TForm1.brnStereoHardwareClick(Sender: TObject);
begin
result := FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound3, false, channel);
ERRCHECK(result);
end;

end.
[/code:fev9zqyt]

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.