Author Topic: BASS_StreamCreateFile offset and length as times?  (Read 149 times)

SoundMike

  • Posts: 351
My users often set specific start and end times for playback of audio files. I can't easily use the offset and length parameters in BASS_StreamCreateFile because these parameters are byte positions, and I can't convert seconds to bytes until after I've created the stream. After creating the stream, I can use BASS_ChannelSecondsToBytes and then use BASS_ChannelSetPosition to set the start position, and BASS_ChannelSetSync with BASS_SYNC_POS to issue a callback at the end position. It would be useful to have an alternative form of BASS_StreamCreateFile that supports times (double) for the offset and length parameters.

00AVD

  • Posts: 19
Re: BASS_StreamCreateFile offset and length as times?
« Reply #1 on: 3 Dec '19 - 10:00 »
How about creating a temporary stream to get the byte based parameters before you create the real playback stream?

Ian @ un4seen

  • Administrator
  • Posts: 22253
Re: BASS_StreamCreateFile offset and length as times?
« Reply #2 on: 3 Dec '19 - 16:38 »
My users often set specific start and end times for playback of audio files. I can't easily use the offset and length parameters in BASS_StreamCreateFile because these parameters are byte positions, and I can't convert seconds to bytes until after I've created the stream. After creating the stream, I can use BASS_ChannelSecondsToBytes and then use BASS_ChannelSetPosition to set the start position, and BASS_ChannelSetSync with BASS_SYNC_POS to issue a callback at the end position. It would be useful to have an alternative form of BASS_StreamCreateFile that supports times (double) for the offset and length parameters.

Perhaps you could just write a wrapper function for BASS_StreamCreateFile that calls BASS_ChannelSetPosition and BASS_ChannelSetSync too? Something like this:

Code: [Select]
HSTREAM BASS_StreamCreateFileTimes(char *filename, DWORD flags, double start, double end)
{
HSTREAM stream = BASS_StreamCreateFile(false, filename, 0, 0, flags); // create stream
if (stream) {
BASS_ChannelSetPosition(stream, BASS_ChannelSeconds2Bytes(stream, start), BASS_POS_BYTE); // seek to start position
BASS_ChannelSetSync(stream, BASS_SYNC_POS | BASS_SYNC_MIXTIME, BASS_ChannelSeconds2Bytes(stream, end), StopSyncProc, NULL); // set sync at end position
}
return stream;
}

void CALLBACK StopSyncProc(HSYNC handle, DWORD channel, DWORD data, void *user)
{
BASS_ChannelStop(channel); // stop the stream
}

SoundMike

  • Posts: 351
Re: BASS_StreamCreateFile offset and length as times?
« Reply #3 on: 4 Dec '19 - 04:27 »
Thanks for the suggestions. I'll review my code.