Author Topic: Several questions  (Read 167 times)

questions

  • Posts: 2
Several questions
« on: 28 Jan '18 - 10:52 »
Hello, thanks for awesome library, i have a few questions.
Question 1
Should i use BASS_FX_FREESOURCE if i creating stream like this ?
Code: [Select]
stream = BASS_FX_TempoCreate(
BASS_StreamCreateFile(FALSE,path,0,0,BASS_STREAM_DECODE|BASS_STREAM_PRESCAN|BASS_SAMPLE_FLOAT)
,BASS_FX_FREESOURCE);
Question 2
Is there any difference between BASS_ChannelStop and BASS_ChannelPause when using on stream that was created with construction above ? I tried to pause and play, and to stop and play, and can't see any difference.
Question 3
Should i free the stream if i want to load another file into it ? Or can i just stop/pause stream then load different file and call BASS_ChannelPlay(stream,TRUE) ?
Question 4
Why is it possible to load 2 files into one stream and play them out of sync and even with different tempo ?
Code: [Select]
stream = BASS_FX_TempoCreate(
BASS_StreamCreateFile(FALSE,path,0,0,BASS_STREAM_DECODE|BASS_STREAM_PRESCAN|BASS_SAMPLE_FLOAT)
,BASS_FX_FREESOURCE);

BASS_ChannelSetAttribute(stream, BASS_ATTRIB_TEMPO, 50.0f);
BASS_ChannelPlay(stream,TRUE);

sleep(5);

stream = BASS_FX_TempoCreate(
BASS_StreamCreateFile(FALSE,path,0,0,BASS_STREAM_DECODE|BASS_STREAM_PRESCAN|BASS_SAMPLE_FLOAT)
,BASS_FX_FREESOURCE);

BASS_ChannelPlay(stream,TRUE);
Now there is 2 different audio playing at different positions and different tempo.
Question 5
And lastly what the hell stream variable contains ? It always equals something like 2147483650, except for the time i tested with loading file into stream starting playback, then loading another one and starting playback. At that moment it was 2147483652
Code: [Select]
void set_tempo(HSTREAM stream){
reset(stream);
BASS_ChannelSetAttribute(stream, BASS_ATTRIB_TEMPO, 50.0f);
}

void set_hz(HSTREAM stream){
reset(stream);
BASS_ChannelSetAttribute(stream, BASS_ATTRIB_TEMPO_FREQ, 60000);
}

void reset(HSTREAM stream){
BASS_ChannelSetAttribute(stream, BASS_ATTRIB_TEMPO, 1);
BASS_ChannelSetAttribute(stream, BASS_ATTRIB_TEMPO_FREQ, 44100);
}

set_tempo(stream);
sleep(5);
set_hz(stream);
The code above works despite i passed stream variable by value to my function and then called BASS' function on that value, tempo was reset before setting frequency. I'm confused, is this some kind of descriptor ?

Ian @ un4seen

  • Administrator
  • Posts: 20612
Re: Several questions
« Reply #1 on: 29 Jan '18 - 15:01 »
Question 1
Should i use BASS_FX_FREESOURCE if i creating stream like this ?
Code: [Select]
stream = BASS_FX_TempoCreate(
BASS_StreamCreateFile(FALSE,path,0,0,BASS_STREAM_DECODE|BASS_STREAM_PRESCAN|BASS_SAMPLE_FLOAT)
,BASS_FX_FREESOURCE);

You can do that, but I would recommend calling BASS_StreamCreateFile first separately so that you can check the return value and possible error code (with BASS_ErrorGetCode) in case of failure. You can still use BASS_FX_FREESOURCE in the subsequent BASS_FX_TempoCreate call then.

Question 2
Is there any difference between BASS_ChannelStop and BASS_ChannelPause when using on stream that was created with construction above ? I tried to pause and play, and to stop and play, and can't see any difference.

There is effectively no difference in this case. There would be a difference if you used the BASS_STREAM_AUTOFREE flag to the BASS_FX_TempoCreate call.

Question 3
Should i free the stream if i want to load another file into it ? Or can i just stop/pause stream then load different file and call BASS_ChannelPlay(stream,TRUE) ?
Question 4
Why is it possible to load 2 files into one stream and play them out of sync and even with different tempo ?
Code: [Select]
stream = BASS_FX_TempoCreate(
BASS_StreamCreateFile(FALSE,path,0,0,BASS_STREAM_DECODE|BASS_STREAM_PRESCAN|BASS_SAMPLE_FLOAT)
,BASS_FX_FREESOURCE);

BASS_ChannelSetAttribute(stream, BASS_ATTRIB_TEMPO, 50.0f);
BASS_ChannelPlay(stream,TRUE);

sleep(5);

stream = BASS_FX_TempoCreate(
BASS_StreamCreateFile(FALSE,path,0,0,BASS_STREAM_DECODE|BASS_STREAM_PRESCAN|BASS_SAMPLE_FLOAT)
,BASS_FX_FREESOURCE);

BASS_ChannelPlay(stream,TRUE);
Now there is 2 different audio playing at different positions and different tempo.

You are replacing the "stream" variable with a new stream handle here, but you have not freed the old stream, so it will still exist and continue playing. If you want the new stream to replace the old one, you should free the old one first by calling BASS_StreamFree:

Code: [Select]
...
sleep(5);

BASS_StreamFree(stream);

stream = BASS_FX_TempoCreate(
BASS_StreamCreateFile(FALSE,path,0,0,BASS_STREAM_DECODE|BASS_STREAM_PRESCAN|BASS_SAMPLE_FLOAT)
,BASS_FX_FREESOURCE);
...

Question 5
And lastly what the hell stream variable contains ? It always equals something like 2147483650, except for the time i tested with loading file into stream starting playback, then loading another one and starting playback. At that moment it was 2147483652

It is just a handle used by BASS. Each stream you create will have a different one.

questions

  • Posts: 2
Re: Several questions
« Reply #2 on: 31 Jan '18 - 13:04 »
« Last Edit: 31 Jan '18 - 13:10 by questions »