0
0

Hi,
I’ve done a program in Delphi and have a problem closing and reinit FMOD. That’s the FMOD-involved events:

1) Init FMOD with global settings (OK)
2) Play songs in a “preview box” with global settings (OK)
3) Select a song from another box (OK)
4) Import cd tracks

Note that I close and reinit FMOD for every item of the list, because I may change the global audio settings.

Now the problem: when I’ve to rip a cd track I init FMOD as shown in the cddarip example, FMOD rips the track correctly, I call FSOUND_Close, reinit with global settings and… BOOM. :(
I tracked the code, all streams are closed correctly, DSP callback is unactive.
Any suggestions?

Tnx in advance.

  • You must to post comments
0
0

Hm, my VB6 player supports runtime changing of sound device without any problems (tested with fmod 3.6x / 3.7x).
Anywhy, you should not reinit fmod in not required. Stop playback and change device if required, or set an boolean variable whether a reinit is required after current track

  • You must to post comments
0
0

Try the Delphi FMOD testbed and change the config. That does a FSOUND_Close/FSOUND_Init cycle.

  • You must to post comments
0
0

Eheh, I know that’s a problem related to my code and not to FMOD, that’s why I’m here!
When I use FMOD to play or mix tracks I have no crashes. Pls look at this code:

[code:3brjqoae]

(FSOUND_Close here)

var RipStream : TFileStream;
WavRec : WAVRecord; // header from Audio Tools Library
stream_ended: Boolean = False;
byteswritten: integer = 0;

function EndCallback(Stream: PFSoundStream; Buff: Pointer; Len, Param: Integer): ByteBool; stdcall;
begin
stream_ended:= TRUE;
Result:= TRUE;
end;

function DSP_RawWriteCallback(originalbuffer, newbuffer: Pointer; Len, Param: Integer): Pointer; stdcall;
begin
If Assigned(RipStream) and not stream_ended
then begin
RipStream.Write(NewBuffer^, len shl 2);
Inc(byteswritten, len shl 2);
end;
Result:= newbuffer;
end;

procedure RipTrack(Drive: string; Track: integer; FName: string);
var
stream, rawwrite_dsp: Pointer;

begin
try
If not FSOUND_SetOutput(FSOUND_OUTPUT_NOSOUND_NONREALTIME) then Abort;
If FSOUND_Init(44100, 1000, 0) then // it might be closed before
begin
RipStream:= TFileStream.Create(FName, fmCreate);
try
RipStream.Seek(0, soFromBeginning);
RipStream.Write(WavRec, sizeof(WavRec));
rawwrite_dsp:= FSOUND_DSP_Create(DSP_RawWriteCallback, FSOUND_DSP_DEFAULTPRIORITY_USER, 0);
If rawwrite_dsp = nil then Abort;
FSOUND_DSP_SetActive(rawwrite_dsp, TRUE);
Stream:= FSOUND_Stream_Open(PChar(Drive), FSOUND_NORMAL, 0, 0);
If Stream = nil then Abort;
If not FSOUND_Stream_SetEndCallback(stream, endcallback, 0) then Abort;
If not FSOUND_Stream_SetSubStream(stream, track – 1) then Abort;
FSOUND_Stream_Play(FSOUND_FREE, stream);
While not stream_ended
do begin
FSOUND_Update;
Application.ProcessMessages;
end;
If not FSOUND_Stream_Close(stream) then Abort;
FSOUND_DSP_SetActive(rawwrite_dsp, FALSE);
FSOUND_DSP_Free(rawwrite_dsp);
WavRec.FileSize:= sizeOf(WavRec) + byteswritten – 8;
WavRec.DataSize:= byteswritten;
RipStream.Seek(0, soFromBeginning);
RipStream.Write(WavRec, sizeof(WavRec));
finally
RipStream.Free;
end;
end else Abort;
except
raise Exception.Create(FMOD_ErrorString(FSOUND_GetError));
end;
end;

(FSOUND_Close and FSOUND_Init with global settings here)

[/code:3brjqoae]

The result is that the engine is closed, the track is ripped and saved and a crash happen with FSOUND_Close.
I’m wrong with callbacks?

  • You must to post comments
0
0

Okay, I discovered that init crash happens in debug time: when the prog runs outside the IDE its’ok, when in debugging the execution stops and Delphi CPU window shows a failure in the StopSound@4 call.

๐Ÿ˜ณ

  • You must to post comments
0
0

I removed completely the crash in the IDE setting the mixer (normally set in autodetect mode) to treat 16bit data

[code:1r6u3vrp]
FSOUND_SetMixer(FSOUND_MIXER_QUALITY_MMXP5)
[/code:1r6u3vrp]

๐Ÿ˜‰ Hope it may be useful.

  • You must to post comments
0
0

I’m mostly using fmod with my player in VB6 ide, and it works fine… just avoid simply stopping the problem crashes of course, because vb6 doesn’t know fmod.dll has to be closed. You can however break and change your program and continue without problems (as long as no restart/program stop is required), or even call the unload function in the immidiate window and then stop your program without a crash

  • You must to post comments
0
0

I don’t know why the cddarip example doesn’t need to specify an MMX mixer but, that is, it works.
I found this trick after testing ALL possible combinations of mixer/output/device/buffers etc.; I also noticed that with FPU mixer and “normal” output and device (i.e. my soundcard) my procedure works (obviously ripping at 1x, while playing), even if this is an unwanted case.

Howewer, I’m happy man now ๐Ÿ˜›

  • You must to post comments
Showing 7 results
Your Answer

Please first to submit.