Author Topic: SetDevice error  (Read 453 times)

Couin

  • Posts: 111
SetDevice error
« on: 8 Jun '24 - 17:38 »
Hi,

I want to init 2 devices at their freq so here is the code I put (for the first device of 2):
   
Code: [Select]
    Dim devinfo As BASS_INFO
   
    dev = 1
    Call BASS_SetDevice(dev)
    Call BASS_GetInfo(devinfo)
    Call BASS_Init(dev, devinfo.freq, 0, 0, 0)

In the IDE, I get no init during the some first launches of the day (but the day before, it was ok), after some launches, it's OK.

In compiled EXE, it's never ok.

I get error 23 for BASS_SetDevice and 8 for BASS_GetInfo calls.

Is there something I do wrong ?  I don't find   :-[

Thanks : ;D

Chris

  • Posts: 2208
Re: SetDevice error
« Reply #1 on: 8 Jun '24 - 22:15 »
1:) The sample format specified in the freq and flags parameters has no effect on the output on  Windows Vista and above - the device's native sample format is automatically used.
2: The Direction is wrong.

Call BASS_Init(1, 44100, 0, 0, 0);
Call BASS_Init(2, 44100, 0, 0, 0);

The functions that use the device selection (Bass_SetDevice) are the following: BASS_Free, BASS_GetInfo, BASS_Start, BASS_Stop, BASS_Pause, BASS_SetVolume, BASS_GetVolume, BASS_Set3DFactors, BASS_Get3DFactors, BASS_Set3DPosition, BASS_Get3DPosition. It also determines which device is used by a new sample/stream/music: BASS_MusicLoad, BASS_SampleLoad, BASS_StreamCreateFile, etc.




Couin

  • Posts: 111
Re: SetDevice error
« Reply #2 on: 9 Jun '24 - 03:16 »
Hi Chris,

Thanks for answer, I will change and put back like it was before (so with 44100).

What do you mean by "direction" ?


Edit:
I was forgetting to set the hwd (the BSS_Init calls are in a module), but it does not resolve the problem :(
In IDE:
Code: [Select]
    Call BASS_Init(1, 44100, 0, frmMain.hWnd, 0) 'First device
    MsgBox BASS_ErrorGetCode()
gives me "14"

Code: [Select]
    Call BASS_Init(0, 44100, 0, frmMain.hWnd, 0) 'Second device (set to 0 for test)
    MsgBox BASS_ErrorGetCode()
gives me "0"

The app gives me sound OK.

But when I run EXE, I get 0 and 0 and I get no playback, this makes me crazy  :o
« Last Edit: 9 Jun '24 - 03:53 by Couin »

Chris

  • Posts: 2208
Re: SetDevice error
« Reply #3 on: 9 Jun '24 - 10:24 »
Hi
  0 = no sound, 1 = first real output device

so it should be
Call BASS_Init(1, 44100, 0, frmMain.hWnd, 0) 'First device
Call BASS_Init(2, 44100, 0, frmMain.hWnd, 0) 'Second device
I would recommend to place the Init Stuff inside OnFormCreate or OnFormLoad
and
Bass_Free inside OnFormDestroy

ErrorCode 14 will  mean already initialized (BASS_ERROR_ALREADY)

The Bass_SetDevice functions that use the device selection are the following: BASS_Free, BASS_GetInfo, BASS_Start, BASS_Stop, BASS_Pause, BASS_SetVolume, BASS_GetVolume, BASS_Set3DFactors, BASS_Get3DFactors, BASS_Set3DPosition, BASS_Get3DPosition. It also determines which device is used by a new sample/stream/music: BASS_MusicLoad, BASS_SampleLoad, BASS_StreamCreateFile, etc.

Couin

  • Posts: 111
Re: SetDevice error
« Reply #4 on: 10 Jun '24 - 13:07 »
Hi Chris :)

Thanks !

Yes, 0 is "no sound" but it's in the case of the user won't have a second soundcard (and/or won't have needing of a second output).

I have to init devices after form load because I read a settings file to init the good devices.

I rewrote some code, tested with putting it in form load and unload, I get result OK. I moved codes in the module, it's OK too.

For testings, I read Bass_Init and BASS_ErrorGetCode and in IDE, I get 1 for Bass_Init and 0 for ErrorCode (so should be ok), but in EXE, I get 1 and 5 (Handle Error), even if I get sound normally.

I think it's not important to read error code on successfully Init, but I ask myself, why 0 in IDE and 5 in EXE, and also , which could be the Handle in Bass Init ?




Chris

  • Posts: 2208
Re: SetDevice error
« Reply #5 on: 10 Jun '24 - 14:41 »
Where do you have place the Bass.dll?
 in your /bin Directory ?

Error 5 will mean BASS_ERROR_HANDLE ,
so looks like a stream was not created btw the Result of creating a Stream was 0;

By the Way if you Bass_init (0,......) (No Sound) then the File can`t be playable.

Couin

  • Posts: 111
Re: SetDevice error
« Reply #6 on: 10 Jun '24 - 15:49 »
bass.dll is in the app directory.

The error 5 is not on streamcreate or play, but well after Bass_init (it should be 0 like in the IDE, as well as bass_init return success).

I have this with any device, but I can play files without problem.


jpf

  • Posts: 196
Re: SetDevice error
« Reply #7 on: 10 Jun '24 - 17:11 »
Those weird things happened to me too and I never found explanation why in some of the cases. I just had to restart the project from zero, copying the code into new modules created in the new project. I mean if I just imported the existing modules into a blank project the problem would still be there. Digging deep into the *.frm and .vbp files by openening them in notepad I couldn't find any difference with those newly created. So this is still a mystery to me.

I other cases I found that the order of execution was different in the exe from that in the Ide. My wild guess is this could happen because the vb runtime is mostly thread safe (whithin the restrictions of the appartment model) while the Ide serializes everything. I even doubt that the debugger uses the same routines that the runtime does for all of the operators / functions. Then there can be optimizations done by the exe compiler that mess things up.

If you wonder how I debugged the order of execution of the exe:
1) Never let the dlls be loaded automatically when a function in them is called. Instead load them explicitelly using the LoadLibrary api. This way you'll know exactly what copy of them are you injecting into your exe and when.
2) Don't make the main form the execution start point of your app. Instead  use Sub Main and load the main form from there. This way you can catch events happening before the form is displayed (a lot happens).
3) Add lots of Print# instructions writing to a text file through your code, each one stating exactly where in your code they are placed and the value of all of the relevant variables in that point. This way even if the app crashes you'll be able to trace the execution progress in the text file. You may well find that the events don't happen in the exact same order as in the Ide. Timer events are the most messing, but also are all the user input controls including menus, input boxes, msg boxes, lists, etc..

Could you build a barebones project to show the same behavior you're experiencing with the whole app? That would be a lot easier to trace / debug.

Ian @ un4seen

  • Administrator
  • Posts: 25866
Re: SetDevice error
« Reply #8 on: 10 Jun '24 - 17:56 »
I seem to recall that the VB6 IDE keeps BASS.DLL loaded between runs? So if you didn't call BASS_Free on the last run then BASS will already be initialized on the next run. You could try adding BASS_Free call(s) at the start of your app to get around that.

Running the compiled EXE of your app should give more reliable results.

Couin

  • Posts: 111
Re: SetDevice error
« Reply #9 on: 11 Jun '24 - 13:38 »
Hi friends,

Thanks for answers  :)

You will laugh ! Without changing code, I had tested this night on a virtual machine with XP, I had well "0" as error code (so good) in IDE like with EXE. This morning, I re-tested on usual machine (Win10), I get also "0" in EXE. No more Handle error on Bass Init.

I BASS_FRee each deice before closing app.

This will be also a mystery for me too  ;D