Author Topic: VB; Can I concatenate samples?  (Read 653 times)

TakeV

  • Posts: 10
VB; Can I concatenate samples?
« on: 8 Jul '15 - 11:20 »
Hello.

Learning BASS for VB6 I can now to create a single samples with different parameters. I can keep them in memory and play and stop any of them.

Can I concatenate some of them in another sample?

I.e., having Smp_1, _2 ... _n presetted samples, is it possible to proceed concatenation like
Code: [Select]
Smp_1_5_9 = (Smp_1 + Smp_5 + Smp_9) and play it?

Or, another way, can I set a sequence of samples playing instead of their concatenation?
.

Ian @ un4seen

  • Administrator
  • Posts: 20401
Re: VB; Can I concatenate samples?
« Reply #1 on: 8 Jul '15 - 17:30 »
Do you want to play multiple files in sequence without any gaps? If so, you could use the BASSmix add-on to achieve that, ie. create a mixer and play the files one after another through that. I'm not a VB user myself, so I can't advise much on the specifics of that, but in C/C++ playing a sequence of files could look something like this...

Code: [Select]
for (int n=0; n<filecount; n++)
decoder[n]=BASS_StreamCreateFile(FALSE, filename[n], 0, 0, BASS_STREAM_DECODE); // create decoder for n'th file
BASS_CHANNELINFO ci;
BASS_ChannelGetInfo(decoder[0], &ci); // get sample format info from 1st file
mixer=BASS_Mixer_StreamCreate(ci.freq, ci.chans, BASS_MIXER_END); // create mixer with same format that ends with its sources
BASS_ChannelSetSync(mixer, BASS_SYNC_END|BASS_SYNC_MIXTIME, 0, MixerEndSyncProc, 0); // set a mixtime END sync on the mixer
BASS_Mixer_StreamAddChannel(mixer, decoder[currentfile=0], 0); // plug the 1st file into the mixer
BASS_ChannelPlay(mixer, 0); // start the mixer

...

void CALLBACK MixerEndSyncProc(HSYNC handle, DWORD channel, DWORD data, void *user)
{
currentfile++; // increment current file
if (currentfile<filecount) { // got another file to play
BASS_ChannelSetPosition(decoder[currentfile], 0, BASS_POS_BYTE); // rewind the file (in case it's already been played)
BASS_Mixer_StreamAddChannel(mixer, decoder[currentfile], BASS_MIXER_NORAMPIN); // add it to the mixer
BASS_ChannelSetPosition(mixer, 0, BASS_POS_BYTE); // reset the mixer to continue playing (it's ended)
}
}

If you want to play the files in a different sequence, you could introduce another array (eg. called "sequence") to define the sequence...

Code: [Select]
...
BASS_Mixer_StreamAddChannel(mixer, decoder[sequence[currentfile=0]], 0); // plug the 1st file into the mixer
...
void CALLBACK MixerEndSyncProc(HSYNC handle, DWORD channel, DWORD data, void *user)
{
currentfile++; // increment current file
if (currentfile<sequencelength) { // got another file to play
BASS_ChannelSetPosition(decoder[sequence[currentfile]], 0, BASS_POS_BYTE); // rewind the file (in case it's already been played)
BASS_Mixer_StreamAddChannel(mixer, decoder[sequence[currentfile]], BASS_MIXER_NORAMPIN); // add it to the mixer
BASS_ChannelSetPosition(mixer, 0, BASS_POS_BYTE); // reset the mixer to continue playing (it's ended)
}
}

Please see the documentation for details on the aforementioned functions.

TakeV

  • Posts: 10
Re: VB; Can I concatenate samples?
« Reply #2 on: 8 Jul '15 - 18:14 »
Do you want to play multiple files in sequence without any gaps? ...
No, no. I don't mean to play files sequence - it was discussed on your forum many times and there are a lot of info on forum and in very usefull help. Thank you.

I mean the samples (literally), that I get by BASS_SampleCreate & BASS_SampleSetData and then play by BASS_ChannelPlay (Stop, Pause).

I want to inform application's user about important events by several short beeps like BIOS POST codes or Morse codes. Having few samples with different length & tone (including the silence) I could combine them in short audio messages that are easy legible by user.
.

Ian @ un4seen

  • Administrator
  • Posts: 20401
Re: VB; Can I concatenate samples?
« Reply #3 on: 9 Jul '15 - 14:32 »
For perfectly gapless playback, you need to have a single output stream, eg. the mixer in the code above. That isn't possible with sample channels. If you have blocks of sample data in memory rather than in files, then you could replace the mixer and decoders with a single stream created with BASS_StreamCreate, and feed the data blocks to the stream's STREAMPROC callback function in the order that you want. A simpler (but perhaps less memory efficient) option is make it a "push" stream, which will avoid the need for a STREAMPROC callback function. For example, something like this:

Code: [Select]
stream=BASS_StreamCreate(freq, chans, 0, STREAMPROC_PUSH, 0); // create the push stream
for (int n=0; n<sequencelength; n++) {
BASS_StreamPutData(stream, block[sequence[n]].data, block[sequence[n]].length); // add the n'th block in the sequence to the stream
}
BASS_ChannelPlay(stream, 0); // start the stream

TakeV

  • Posts: 10
Re: VB; Can I concatenate samples?
« Reply #4 on: 9 Jul '15 - 14:55 »
Ian, thank you for the clarifications. I will try both of methods you offer.
.