Author Topic: Changing loop status after loading sample and hrtf  (Read 299 times)

Rastislav Kiss

  • Posts: 7
Hello all,
I am new on this forum and also new in using of the Bass library. I selected it for my c++ projects, main reason was that Fmod and Openal were not compilable with g++ on my Windows machine, second reason is that I like Bass solution, its way used for sound managing.
I have already built few projects and now working on wrapper to make work with many sounds easier, hovever I found one problem. I created class named sound with two variables (HSAMPLE and HCHANNEL) and three methods (load, play, play_wait). My image is that programmer simply one time calls load function which loads wanted sound to the memory and play function when playing is needed. This structure was also in my previously used language, also fmod was constructed by this way and few other libraries, so I thought it will be the same here. Hovever I can not reach it, library don't want to accept my call of SampleSetInfo with change about looped playing (I read in manual that it is normal, I don't understand why), only that I can do is set it in load method, hovever that is inefficient for my purpose, many sounds are loaded on program start when I as programmer don't know if playing in loop will be necessary or not, also both can be applyed and in that case sound must to be loaded more times than needed. Is it there some way to set looping while or before playing? I know that few loads are not too hard, hovever it require minimally change of my wrapper, especially part with automatic sounds managing system.

And my second question is about 3D audio in Bass, I plan to use also this feature. Is there a way to implement hrtf technology in it? In games that I am working on accurate 3D audio is important, so I appreciate as high quality as possible. Of course it is not condition, I never worked with hrtf and things was okay, I asking only for interest.

Thank you in advance for answers, I hope I will get some more practice with this library in future.
Greetings

Rastislav

Ian @ un4seen

  • Administrator
  • Posts: 20336
Re: Changing loop status after loading sample and hrtf
« Reply #1 on: 8 Mar '17 - 17:36 »
I have already built few projects and now working on wrapper to make work with many sounds easier, hovever I found one problem. I created class named sound with two variables (HSAMPLE and HCHANNEL) and three methods (load, play, play_wait). My image is that programmer simply one time calls load function which loads wanted sound to the memory and play function when playing is needed. This structure was also in my previously used language, also fmod was constructed by this way and few other libraries, so I thought it will be the same here. Hovever I can not reach it, library don't want to accept my call of SampleSetInfo with change about looped playing (I read in manual that it is normal, I don't understand why), only that I can do is set it in load method, hovever that is inefficient for my purpose, many sounds are loaded on program start when I as programmer don't know if playing in loop will be necessary or not, also both can be applyed and in that case sound must to be loaded more times than needed. Is it there some way to set looping while or before playing? I know that few loads are not too hard, hovever it require minimally change of my wrapper, especially part with automatic sounds managing system.

It should be possible to set/unset the BASS_SAMPLE_LOOP flag via BASS_SampleSetInfo. Perhaps you used a HCHANNEL handle in the call? BASS_SampleSetInfo can only be used with HSAMPLE handles (it sets the sample's defaults). You can use BASS_ChannelFlags instead to set/unset the BASS_SAMPLE_LOOP flag on existing HCHANNEL handles.

And my second question is about 3D audio in Bass, I plan to use also this feature. Is there a way to implement hrtf technology in it? In games that I am working on accurate 3D audio is important, so I appreciate as high quality as possible. Of course it is not condition, I never worked with hrtf and things was okay, I asking only for interest.

Unfortunately, HRTF isn't currently supported (it used to be supported via DirectSound3D before it was disabled in Vista). I wouldn't rule out it being supported in future, but there are no immediate plans for it.

Rastislav Kiss

  • Posts: 7
Re: Changing loop status after loading sample and hrtf
« Reply #2 on: 13 Mar '17 - 21:38 »
Hello Ian,
for first thanks for your reply. Because things are little bit unclear for me now, I will quote a Bass 2.4 documentation:

"The length, origres and chans members of the BASS_SAMPLE structure cannot be modified; any changes are ignored. The BASS_SAMPLE_8BITS, BASS_SAMPLE_MONO, BASS_SAMPLE_3D, BASS_SAMPLE_MUTEMAX, BASS_SAMPLE_SOFTWARE and BASS_SAMPLE_VAM flags also cannot be changed."

This is from section Sample at BASS_SampleSetInfo, I understand from it that loop can not be set while sample is loaded. It surprised me, so I made a test, something like:

BASS_SampleGetInfo(sample, &info);
info.flags=BASS_SAMPLE_LOOP;
BASS_SampleSetInfo(sample, &info);
BASS_ChannelPlay(channel);

Sorry for possible mistakes in small and capital letters, I have not concrete code while writing this, hovever I know it was correct for compiler. Anyway sample did not loop.
Now I see also one possible attribute to set in channel attributes, I guess that will make loop all sounds under modified channel when playing simultaneously, that may or may not be problem, I don't know right now, I must to make few tests if channel loop status can be changed after loading.

Thanks again for your help.

Greetings

Rastislav

Ian @ un4seen

  • Administrator
  • Posts: 20336
Re: Changing loop status after loading sample and hrtf
« Reply #3 on: 14 Mar '17 - 14:41 »
"The length, origres and chans members of the BASS_SAMPLE structure cannot be modified; any changes are ignored. The BASS_SAMPLE_8BITS, BASS_SAMPLE_MONO, BASS_SAMPLE_3D, BASS_SAMPLE_MUTEMAX, BASS_SAMPLE_SOFTWARE and BASS_SAMPLE_VAM flags also cannot be changed."

This is from section Sample at BASS_SampleSetInfo, I understand from it that loop can not be set while sample is loaded.

But BASS_SAMPLE_LOOP isn't included in that list of flags :)

BASS_SampleGetInfo(sample, &info);
info.flags=BASS_SAMPLE_LOOP;
BASS_SampleSetInfo(sample, &info);
BASS_ChannelPlay(channel);

Changes to the sample's defaults (via BASS_SampleSetInfo) will only affect sample channels that are subsequently created via BASS_SampleGetChannel. Existing sample channels will be unaffected. To change an existing sample channel's looping setting, you can use BASS_ChannelFlags:

Code: [Select]
BASS_ChannelFlags(channel, BASS_SAMPLE_LOOP, BASS_SAMPLE_LOOP); // set the LOOP flag

Rastislav Kiss

  • Posts: 7
Re: Changing loop status after loading sample and hrtf
« Reply #4 on: 25 Mar '17 - 16:44 »
Good afternoon,
Hmmm, it looks like I am dreaming or what, you are right, BASS_SAMPLE_LOOP is not included, I don't know why I thought that it is, sorry for it. Anyway your code helped, thank you too much, I think it will be good if fact that BASS_SamplesetInfo do not affect samples in already existing channels is reminded in description of this function, but that is only designal thing.

Yeah and when this topic is already opened, I would like to ask also how to set orientation of player in function BASS_Set3DPosition()? I see that it is one of its parameters, but type is BASS_3D_Vector, I have no idea how to represent degree from 0 to 359 in that. Only with setting direction where player will get after moving into that direction, hovever I doubt that it is right, there are useless calculations with possible unaccurate result. So how should I represent it?
Thanks for your help.
Greetings

Rastislav

Ian @ un4seen

  • Administrator
  • Posts: 20336
Re: Changing loop status after loading sample and hrtf
« Reply #5 on: 27 Mar '17 - 16:07 »
I would like to ask also how to set orientation of player in function BASS_Set3DPosition()? I see that it is one of its parameters, but type is BASS_3D_Vector, I have no idea how to represent degree from 0 to 359 in that. Only with setting direction where player will get after moving into that direction, hovever I doubt that it is right, there are useless calculations with possible unaccurate result. So how should I represent it?

Something like this should do it:

Code: [Select]
BASS_3DVECTOR front, top;
front.x = sin(angle * 2 * M_PI / 360);
front.y = 0;
front.z = cos(angle * 2 * M_PI / 360);
top.x = 0;
top.y = 1;
top.z = 0;
BASS_Set3DPosition(NULL, NULL, front, top);