Author Topic: X11 Window Handler for BASS_Init  (Read 84 times)

TOGtheMighty

  • Posts: 7
X11 Window Handler for BASS_Init
« on: 25 Jan '25 - 02:10 »
Hello,

Been using BASS in Windows for a while on personal projects and have been loving its capabilities!

Trying to port my stuff over to Linux, however, and i am not sure how to pass the X11 Window in as the fourth parameter of BASS_Init. Using SDL2 for graphics and windows handling, if anyone's familiar with that and that helps in answering my question.

Here's a snippet of my code:
Code: [Select]
SDL_SysWMinfo systemInfo;
SDL_VERSION(&systemInfo.version);
SDL_GetWindowWMInfo(gWindow, &systemInfo);

Window hwnd = systemInfo.info.x11.window;
   
BASS_Init(-1, 44100, 0, hwnd, NULL);

...and the error it returned:
main.cpp:100:33: error: invalid conversion from 'long unsigned int' to 'void*' [-fpermissive]

Have dabbled only a little with Linux before, but never with the programming side of it, so figured it was best to ask here, given my searches not resulting in anything obvious about how to deal with the long unsigned int <-> void * mismatch when it comes to X11 Window Handles. Looked briefly at xlib, but didn't see anything obvious there, and wasn't sure where to look beyond their usage of Window.

For comparison, the equivalent Windows (OS) code works:
Code: [Select]
SDL_SysWMinfo systemInfo;
SDL_VERSION(&systemInfo.version);
SDL_GetWindowWMInfo(gWindow, &systemInfo);

HWND hwnd = systemInfo.info.win.window;
   
BASS_Init(-1, 44100, 0, hwnd, NULL);

Thanks for any help anyone can provide!
TOG

mrRdo

  • Posts: 26
Re: X11 Window Handler for BASS_Init
« Reply #1 on: 26 Jan '25 - 12:31 »
The HWND is only needed for Direct Sound on Windows, so just pass NULL to this parameter.

TOGtheMighty

  • Posts: 7
Re: X11 Window Handler for BASS_Init
« Reply #2 on: 26 Jan '25 - 19:17 »
Thanks, yes. I was able to get sound with NULL being passed in. I'm realizing i didn't explain I was looking to have the ability to control volume per application, like a higher level mixer, which is maybe a little strange, but I like separating the different approaches i do for the experimental music I make. As they can crash sometimes  ;), and don't want to have it all go down at once. Nothing to do with the stability of BASS, i do kind of weird things with memory to source timing and sample choice, etc.  :P

I did figure it out by eventually seeing an example (can't track it down in my too long of internet history looking for it). If anyone else is looking to do this, you simply cast the Window as a void pointer, like so:
Code: [Select]
BASS_Init(-1, 44100, 0, (void *)hwnd, NULL);

Seems a bit odd the address in memory is given as an unsigned int, but not too used to programming in Linux yet. Tested that it worked by opening the Sound program, going under the tab Applications, and messing with volumes once I had two BASS programs running. This is in Linux Mint 22.1; not sure about the interface in other distros.