0
0

Is it possible to detect whether a cd that has been opened and playing as a stream has just been ejected?

I would use FSOUND_IsPlaying and tell if the channel has anything playing on it, but it might just be that it is between tracks or has gotten to the end of the cd.

The reason I ask is that I need to detect if a cd has been inserted so it can re-read the toc.

  • You must to post comments
0
0

Thank you for reply. :)
I never use FSOUND_Update in my app. I should ? ๐Ÿ˜ณ
Yes i think it’s the latest fmod.dll because for each run it create automatically the fmodcdda report file.
What I do :
I create a loop I call every 500ms.
The first time the loop is called I open the CD like that :
CdStream = API(“fmod”, “_FSOUND_Stream_Open@16”, “g:”, FSOUND_NONBLOCKING, 0, 0)
It return a logical number : 32730216.
My function fSoundStreamGetOpenState is written like that : API(“fmod”, “_FSOUND_Stream_GetOpenState@4”, StreamToTest)
And I test fSoundStreamGetOpenState(CdStream) every 500ms (loop period).
First test : I run my app whitout CD into the drive, the results are : -2 0 0 0 0 ….
2nd test : I introduce a CD into the drive, I wait 1 second and I run my app. The results are : -2 -2 0 0 0 0 ….
If I open the CD with “g” I obtain the -3, but the results are -2 -3 -3 -3 … in the 2 cases of test.
I don’t understand where I’m wrong, it’s look like so simple ! ๐Ÿ˜•

  • You must to post comments
0
0

The error is FMOD_ERR_INVALID_PARAM. Are you sure the stream handle you pass in is valid? What about the C examples – does the C cdda example work for you?

  • You must to post comments
0
0

Call FSOUND_Update in your main loop.

  • You must to post comments
0
0

The solution, I thought, was to try and re-read the toc, and if it failed, it meant the cd was no longer in the drive…

However, using: FSOUND_Stream_FindTagField( stream, 0, “CD_TOC” ….

the stream has a value, and the above function still populates my structure for me, even though I don’t think it should…. or should it?

  • You must to post comments
0
0

Yes, cdda works fine – I haven’t changed it to pickup your return value of -3, but when I eject the cd it just permanently pauses the cdda. Should it quit out or tell me there is no cd in the drive?

Anyway, I have fixed it by another way:

    public int CDInTray()
    {
        int retVal = 0;

        SelectQuery query = new SelectQuery("select volumename, volumeserialnumber from win32_logicaldisk where drivetype=5");
        ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
        foreach (ManagementObject mo in searcher.Get()) 
        {
            // If both properties are null I suppose there's no CD
            if((mo["volumename"] != null) || (mo["volumeserialnumber"] != null))
                retVal = 1;

            //  Console.WriteLine("{0} - {1} ",mo["volumename"],mo["volumeserialnumber"]);
        }

        return retVal;
    }

The above function queries the cd drive at the os level to see if there is anything in it.

Thanks for trying anyway.

  • You must to post comments
0
0

Hi Andrew,
I’m back
Nothing to do, it do not work !

Here my code example :
API(“fmod”, “_FSOUND_SetBufferSize@4”, 200)
API(“fmod”, “_FSOUND_Stream_SetBufferSize@4”, 2000)
API(“fmod”, “_FSOUND_SetOutput@4”, FSOUND_OUTPUT_DSOUND)
API(“fmod”, “_FSOUND_SetDriver@4”, 1)
API(“fmod”, “_FSOUND_Init@12”, 44100, 20, FSOUND_INIT_ENABLESYSTEMCHANNELFX)

API(“fmod”, “_FSOUND_CD_OpenTray@8”, 103, 1) // (103 = the G drive)

LOOP (called every 1 second)

if StreamGetOpenStateResult <> -2 then StreamPtrCD = API(“fmod”, “_FSOUND_Stream_Open@16”, CD_DRIVE, FSOUND_NONBLOCKING, 0, 0)

StreamGetOpenStateResult = API(“fmod”, “_FSOUND_Stream_GetOpenState@4”, StreamPtrCD)

API(“fmod”, “_FSOUND_Update@0”)

if StreamGetOpenStateResult <> -2 then
API(“fmod”, “_FSOUND_Stream_Close@4”, StreamPtrCD)
Print(StreamGetOpenStateResult )
end if

END of LOOP

Test 1 :
I begin the test without CD into the drive
CD_DRIVE = “g:”
Result : 0
I introduce a CD : result : 0
I eject the CD with API(“fmod”, “_FSOUND_CD_OpenTray@8”, 103, 1) : result : 0
I introduce a CD : result : 0
I eject the CD : result : -3
I introduce a CD : result : 0
I eject the CD : result : -3
I introduce a CD : result : 0
I eject the CD : result : 0
I introduce a CD : result : 0
I eject the CD : result : 0
Test ended

Test 2 :
I introduce a CD into the drive before to begin the test
CD_DRIVE = “g:”
Approximatively same results than test 1

Test 3 :
Test 1 without FSOUND_CD_OpenTray before LOOP
Approximatively same results

Test 4 :
Test 2 without FSOUND_CD_OpenTray before LOOP
It seems be good, it is good a lot of time, and …… not ! After that approximatively same results

Tests 1, 2, 3 and 4 realised with CD_DRIVE = “g:\” , results : always -3

Could you help me …
Thanks

  • You must to post comments
0
0

I would be inclined to try using the that method but with the analog CD functions.

if(FSOUND_CD_GetVolume(0)==-1)
//there is no CD

  • You must to post comments
0
0

[quote:8xx6u2bc]Yes, cdda works fine – I haven’t changed it to pickup your return value of -3, but when I eject the cd it just permanently pauses the cdda. Should it quit out or tell me there is no cd in the drive?
[/quote:8xx6u2bc]

No, it sounds like it’s working fine. Does it still respond when you hit ESC to exit the program?

[quote:8xx6u2bc]Anyway, I have fixed it by another way:
<snip>
[/quote:8xx6u2bc]

That’s cool but we can’t use that method internally in FMOD because it depends on the .NET framework. Can you do me a quick favour and download the latest cddatest program here :

[url:8xx6u2bc]http://www.fmod.org/files/cddatest.zip[/url:8xx6u2bc]

…run it with an audio CD in the specified drive and then eject the CD while the test is running? i.e. any time when it says “Working…”. Does it say “CD EJECTED” and then exit the program?

Thanks for your help PHB.

Cheers,

  • You must to post comments
0
0

i don’t think that will work because i think that fmod uses the standard Windows Mixer volumes for analog cd playback. Correct me if i’m wrong ๐Ÿ˜‰ Maybe you find something on google or http://msdn.microsoft.com/library.

  • You must to post comments
0
0

Hi Andrew,

Yep, that worked exactly as you suggested. Perhaps you could let me have a look at the code of cddatest to see what I am doing wrong in my logic???

Thanks!

  • You must to post comments
0
0

Or maybe the Fmod crew have an answer?

  • You must to post comments
0
0

Add these lines to the cdda example just before the call to FSOUND_Update :

[code:31mwgdax] if (FSOUND_Stream_GetOpenState(stream) == -3)
{
printf("\nCD EJECTED\n");
FSOUND_Stream_Close(stream);
FSOUND_Close();
return 0;
}
[/code:31mwgdax]

Cheers,

  • You must to post comments
0
0

Trouble with setsubstream is that it will reset the track being played if the cd is currently playing.

I can’t really see why FSOUND_Stream_FindTagField( stream, 0, “CD_TOC”

returns me a table of contents in the toc structure if the cd has been ejected. Surely it should return me nothing?

  • You must to post comments
0
0

OK, you mention a call to FSOUND_Update() which I am most defianately not calling. I have taken a look at the help notes on it, and am not much the wiser.

Should I just put it into my thread loop so it gets repeatedly called?

  • You must to post comments
0
0

There’s an updated fmod.dll available at :

[url:2ba467ej]http://www.fmod.org/files/fmod.dll[/url:2ba467ej]

In this version, FSOUND_GetOpenState() will return -3 if the cd is ejected. Let me know if you have any problems with it.

Cheers,

  • You must to post comments
0
0

Yes.

  • You must to post comments
0
0

Will do. Thanks for taking a look at it for me.

  • You must to post comments
0
0

Right… that sorted it.

Thanks very much for your patience Andrew ๐Ÿ˜‰ ๐Ÿ˜€

  • You must to post comments
0
0

If I do the following:

this_openstate = FSOUND_Stream_GetOpenState( stream );
if( this_openstate == -3)
{
our cd has been ejected
}

within a thread that sleeps for 100 ms I find that the above function crashes. Do I assume that it would have to be preceeded by a SetSubStream call? – coz if so, then it won’t work because that would force the track to keep restarting?

  • You must to post comments
0
0

hello
i’m very interested about the new response -3 when there is no CD in the drive.
I have tested cddatest and it work as you said in my PIONEER DVD-ROM DVD-120S.
In my own soft (and with this new dll of course) it doesn’t work.
I have opened the CD in nonblocking method.
It return -2 one time (the first time, immediately after Stream_Open)
After I test FSOUND_Stream_GetOpenState every 500ms and it return allways 0 !
I have tested with all parameters *?!ja (one or more) and without any.
I successfull solve many problem myself in the past, but here …
Could you help me to look for my error ?
Denis from Paris

  • You must to post comments
Showing 1 - 20 of 23 results
Your Answer

Please first to submit.