Author Topic: Play channel/stream to a output device and also add it to a mixer to encode  (Read 66 times)

mkllc

  • Posts: 32
Hi I have a small toy program that records from two input devices: one loopback and one microphone (BASS_RecordStart). Mixed together using a mixer (BASS_Mixer_StreamCreate with no flags, BASS_Mixer_StreamAddChannel with BASS_MIXER_CHAN_LIMIT | BASS_MIXER_CHAN_BUFFER on one and BASS_MIXER_CHAN_BUFFER on the second) to a single stream and then encoded it to ogg using a BASS_Encode_OGG_Start. The mixer is muted to avoid delay/echo problems when capturing from microphone/"what is heard" recording.

Now I want to add the functionality to play a existing file using BASS_StreamCreateFile with BASS_STREAM_AUTOFREE flag (and then use ChannelPlay, ChannelPause, ChannelStop, SetPosition, GetPosition... everything to get info/control the playing). At this point any problem as I can hear the output of the player stream on the output device and if I had the loopback as a record device it gets the sound without any problem. But I want a different approach: hear the music like now but plug the channel on the mixer to record it at the same time. I tried to simple do BASS_Mixer_StreamAddChannel but I got a BASS_ERROR_DECODE I tried to put a splitter and plug the output of the splitter to the mixer but without luck. Can this be done?

I don't want to create the stream as a DECODING as I will loss all playing control ability (as it relies on internal get_data). There is any solution to play a output to device stream/channel to a mixer to mix and then record it? (without unmuting the mixer to avoid problems with other channels of course)

Thanks!

Ian @ un4seen

  • Administrator
  • Posts: 23404
Now I want to add the functionality to play a existing file using BASS_StreamCreateFile with BASS_STREAM_AUTOFREE flag (and then use ChannelPlay, ChannelPause, ChannelStop, SetPosition, GetPosition... everything to get info/control the playing). At this point any problem as I can hear the output of the player stream on the output device and if I had the loopback as a record device it gets the sound without any problem. But I want a different approach: hear the music like now but plug the channel on the mixer to record it at the same time. I tried to simple do BASS_Mixer_StreamAddChannel but I got a BASS_ERROR_DECODE I tried to put a splitter and plug the output of the splitter to the mixer but without luck. Can this be done?

It sounds like you could use splitters for that. Note you would need 2 splitters: one for playback and one for mixing, ie. you can't play the original stream directly. You would use the BASS_STREAM_DECODE flag on the original stream and also on the splitter feeding the mixer, but not on the splitter than your want to play. Something like this:

Code: [Select]
source = BASS_StreamCreateFile(false, filename, 0, 0, BASS_STREAM_DECODE); // create decoder
mixsplit = BASS_Split_StreamCreate(source, BASS_STREAM_DECODE, NULL); // create splitter for mixing
playsplit = BASS_Split_StreamCreate(source, 0, NULL); // create splitter for playback
BASS_Mixer_StreamAddChannel(mixer, mixsplit, 0); // add to mixer
BASS_ChannelPlay(playsplit, 0); // start playing

mkllc

  • Posts: 32
Did some tests and seems works as expected except with the set position, pause, stop, volume on playsplit will not affect the one that its being recorded in the mixer, so maybe I have to repeat the commands on both channels (playsplit and mixsplit) to get in sync events during playing hearing and in the recording. I don't know if there is a way to do both dependent, but I think not.

Ian @ un4seen

  • Administrator
  • Posts: 23404
Yes, those things will be a bit trickier when using splitters. When seeking in the playback splitter, you can use BASS_Split_StreamReset on the mixer splitter to make it jump to the new position too (skip any old data in the splitter buffer). For pausing/stopping the mixer splitter, you can set the BASS_MIXER_CHAN_PAUSE flag via BASS_Mixer_ChannelFlags (and unset it to resume). For volume changes, you will need to make the BASS_ChannelSetAttribute calls on both splitters.