Author Topic: FX on asio input + channel mixing  (Read 477 times)

johnvantelli

  • Posts: 64
FX on asio input + channel mixing
« on: 3 Mar '18 - 10:08 »
My target is to use one or two input channel (line and mic) to play guitar or sing while a mp3 is playing.
For now I'm using a decoded channel (fSong) attached to a bassMix (fMixer).

For best performance I'm using ASIO and my asio callback proc is (copied from forum):

Code: [Select]
function AsioProc(input: BOOL; channel: dword; buffer: Pointer; length: dword;
user: Pointer): dword; stdcall;
Var
  c: dword;
begin
   c := Bass_ChannelGetData(fMixer, buffer, length);
   if (c = DW_ERROR) then  c := 0;
   Result := c;
end;

Mic and guitar input channels will be processed by FX or DSP and I need advice on how to make this.

- should I create a dummy input channel connected to my mixer? If yes, how to get it from asio input?
- do I have to modify my asio callback proc? If yes how? (I've no idea)
- after that will I be able to check the input level?

Thanks for support

johnvantelli

  • Posts: 64
Re: FX on asio input + channel mixing
« Reply #1 on: 4 Mar '18 - 21:32 »
I'm doing some tests after reading documentation.
this is my asio proc...

Code: [Select]
function MyAsioProc(input: BOOL; channel: dword; buffer: Pointer; length: dword; user: Pointer): dword; stdcall;
Var c: dword;
begin

  if (input) then
     c := BASS_StreamPutData(fMicStream, buffer, length)
  else
     c := BASS_ChannelGetData(fMixer, buffer, length)
  end;

  if (c = DW_ERROR) then  c := 0;
  Result := c;
end;


and this is my bass init code:

Code: [Select]
  BASS_SetConfig(BASS_CONFIG_UPDATEPERIOD, 0);
  BASS_Init(0, 44100, 0, 0, nil);

 // ################
 // the mixer
 // ################

  fMixer := BASS_Mixer_StreamCreate(44100, 2, 0
    or BASS_MIXER_BUFFER or BASS_MIXER_NORAMPIN
    or BASS_MIXER_NONSTOP or BASS_SAMPLE_FLOAT
    or BASS_STREAM_DECODE or BASS_UNICODE );

 // ################
 // the mic stream
 // ################

 fMicStream := BASS_StreamCreate(44100, 1, BASS_STREAM_DECODE or BASS_SAMPLE_FLOAT, STREAMPROC_PUSH, nil);

 BASS_Mixer_StreamAddChannel(fMixer, fMicStream, BASS_MIXER_DOWNMIX or BASS_MIXER_NORAMPIN);
 
 
  // #####################################
  // Asio Init an setup
  // #####################################

  BASS_ASIO_Init(0, 0 or BASS_ASIO_THREAD);
 
  BASS_ASIO_SetRate(44100);

  BASS_ASIO_ChannelJoin(false, 1, 0);

  BASS_ASIO_ChannelSetRate(false, 0, 44100); 
  BASS_ASIO_ChannelSetRate(true, 0, 44100);

  BASS_ASIO_ChannelEnable(false, 0, @MyAsioProc, self);
  BASS_ASIO_ChannelEnable(true, 0, @MyAsioProc, self);

  BASS_ASIO_ChannelSetFormat(false, 0, BASS_ASIO_FORMAT_FLOAT);
  BASS_ASIO_ChannelSetFormat(true, 0, BASS_ASIO_FORMAT_FLOAT);
 
  BASS_ASIO_Start(0, 1);


in the mixer I insert also an MP3 stream and when I play that stream it returns in a loop...
I think the problem is in the asio callback but I'm not sure.



Ian @ un4seen

  • Administrator
  • Posts: 21133
Re: FX on asio input + channel mixing
« Reply #2 on: 5 Mar '18 - 16:49 »
That looks like you have the right idea, eg. using a "push" stream to feed the ASIO input channel's data into the mixer. A couple of little things... BASS_MIXER_BUFFER/BASS_MIXER_NORAMPIN/BASS_UNICODE are not valid flags for BASS_Mixer_StreamCreate, so you should remove them from your call (using invalid flags can activate unintended options). I would recommend using BASS_ASIO_GetRate after the BASS_ASIO_SetRate call and use the result in the BASS_Mixer_StreamCreate and BASS_StreamCreate calls for best performance/quality (avoid unnecessary resampling), just in case the BASS_ASIO_SetRate call fails.

If you still have a problem, please describe it a bit more. I'm not entirely sure what you mean by "it returns in a loop". Perhaps you mean you're getting feedback, ie. the mic is picking up the output? If so, using headphones to listen to the output will prevent that.

johnvantelli

  • Posts: 64
Re: FX on asio input + channel mixing
« Reply #3 on: 5 Mar '18 - 19:58 »
Thanks Ian,
I've removed wrong flags from mixer.
As you rightly said what I hear is a feedback and I can hear it also using headphones.
I attach a wave registration of it.

Asio Panel shows me a lot of devices (perhaps virtual) that I have to turn on or off to switch between speaker and headphones.
After switch from one to another I have to restart my application and I can hear sound.
Is there a way to switch them using bass library?

Sorry for my poor english :-)


 

Ian @ un4seen

  • Administrator
  • Posts: 21133
Re: FX on asio input + channel mixing
« Reply #4 on: 6 Mar '18 - 14:56 »
You can call BASS_ASIO_ControlPanel to open that control panel, but I don't think it's possible to programmatically change the settings in it, unless ASIO4ALL has its own API. Does changing the settings in there prevent the feedback problem happening? It seems strange that you would still get the feedback when using headphones.

johnvantelli

  • Posts: 64
Re: FX on asio input + channel mixing
« Reply #5 on: 6 Mar '18 - 15:09 »
No, it doesn't prevent the feedback... I can hear it with headphones too.
It seems that the output buffer returns into input and I have a doubt about my asio callback proc...

Do you confirm me that is right as I wrote above?

In other threads I found asio proc with copymemory and BASS_StreamPutData...
what is the difference? Wich one is better?


Code: [Select]
    CopyMemory(@buf, buffer, length);

and

Code: [Select]
    BASS_StreamPutData(TfrmMain(user).fMicStream, buffer, length);

Ian @ un4seen

  • Administrator
  • Posts: 21133
Re: FX on asio input + channel mixing
« Reply #6 on: 6 Mar '18 - 16:37 »
BASS_StreamPutData is correct for the ASIO input channel's ASIOPROC; it is feeding the input's data to a push stream, which is plugged into the mixer.

Are you getting the feedback on all sound in the room, or only the MP3 file that's playing through the mixer? Does it happen even if the mic isn't in the mixer?

johnvantelli

  • Posts: 64
Re: FX on asio input + channel mixing
« Reply #7 on: 6 Mar '18 - 19:09 »
only while playing.
If I start my app without playing any audio file, I can set the mic level to max with this code without any feedback :

Code: [Select]
BASS_ChannelSlideAttribute(fMicStream, BASS_ATTRIB_VOL, Value,
      MASTER_VOLUME_SLICE_TIME);

but if I play an MP3 file feedback starts until I set the mic level to 0.


Ian @ un4seen

  • Administrator
  • Posts: 21133
Re: FX on asio input + channel mixing
« Reply #8 on: 7 Mar '18 - 17:28 »
That's strange. Is the "mic" input actually a microphone, eg. can you speak into it and capture the sound? From what you've said (headphones not helping), it sounds like it may be capturing the device's output mix instead.

johnvantelli

  • Posts: 64
Re: FX on asio input + channel mixing
« Reply #9 on: 7 Mar '18 - 18:42 »
In other application I can hear the mic, but in my app not.
I think I did a bit 'of confusion with the init sequence...

Code: [Select]
if (HIWORD(BASS_GetVersion) <> BASSVERSION) then
    log.Error('InitSoundSystem: - Audio library wrong version', APP_NAME);

  BASS_Free;
 
  BASS_ASIO_Free;

  BASS_Init(0, 44100, 0, 0, nil);
 
  BASS_SetConfig(BASS_CONFIG_UPDATEPERIOD, 0);
 
  fMixer := BASS_Mixer_StreamCreate(44100, 2, 0 or BASS_MIXER_NONSTOP or BASS_SAMPLE_FLOAT or BASS_STREAM_DECODE);
 
  BASS_ASIO_GetDeviceInfo(0, anAsioDeviceInfo);
 
  BASS_ASIO_Init(0, 0 or BASS_ASIO_THREAD);

  BASS_ASIO_SetDevice(0);

  BASS_ASIO_SetRate(44100);

  BASS_ASIO_ChannelSetRate(false, 0, 44100);

  BASS_ASIO_ChannelJoin(false, 1, 0;

  BASS_ASIO_ChannelEnable(false, 0, @AsioProc, self);

  BASS_ASIO_ChannelSetFormat(false, 0, BASS_ASIO_FORMAT_FLOAT);

  BASS_ASIO_ChannelEnable(true, 0, @AsioProc, self);

  BASS_ASIO_ChannelSetFormat(true, 0, BASS_ASIO_FORMAT_FLOAT);

  fMicStream := BASS_StreamCreate(44100, 1, BASS_STREAM_DECODE or BASS_SAMPLE_FLOAT, STREAMPROC_PUSH, nil);

  BASS_Mixer_StreamAddChannel(fMixer, fMicStream, BASS_MIXER_DOWNMIX or BASS_MIXER_NORAMPIN);

  BASS_ASIO_Start(0, 1);

Ian @ un4seen

  • Administrator
  • Posts: 21133
Re: FX on asio input + channel mixing
« Reply #10 on: 8 Mar '18 - 16:07 »
If you run the pre-compiled LIST.EXE example that's included in the BASSASIO package (C\BIN folder), what do you see?

johnvantelli

  • Posts: 64
Re: FX on asio input + channel mixing
« Reply #11 on: 8 Mar '18 - 17:43 »
Quote
dev 0: ASIO4ALL v2
driver: C:\Program Files (x86)\ASIO4ALL v2\asio4all.dll
        in 0: HD Audio output with SST 1 (group 0, format 18)
        in 1: HD Audio output with SST 2 (group 0, format 18)
        in 2: Audio 2nd output with SST 1 (group 0, format 18)
        in 3: Audio 2nd output with SST 2 (group 0, format 18)
        out 0: Audio output with SST 1 (group 0, format 18)
        out 1: Audio output with SST 2 (group 0, format 18)
        out 2: 2nd output with SST 1 (group 0, format 18)
        out 3: 2nd output with SST 2 (group 0, format 18)

Ian @ un4seen

  • Administrator
  • Posts: 21133
Re: FX on asio input + channel mixing
« Reply #12 on: 9 Mar '18 - 14:41 »
From the channel names, it looks like the input channels are capturing the data sent to the output channels? Perhaps it is not possible to capture from the mic via ASIO, ie. it has no ASIO drivers? Have you tried using the normal BASS recording functions instead, ie. BASS_RecordInit/Start? You can run the pre-compiled DEVLIST.EXE example from the BASS package (C\BIN folder) to quickly see what recording inputs are available that way.

johnvantelli

  • Posts: 64
Re: FX on asio input + channel mixing
« Reply #13 on: 10 Mar '18 - 09:03 »
ok, I'll try that way...

this is DEVLIST.exe output

Quote
Output Devices
1: Altoparlanti (Realtek High Definition Audio(SST))
        driver: {0.0.0.00000000}.{12e96828-a276-473b-9b43-de0b30cd33c9}
        type: Speakers
        flags: enabled default (2000003)

Input Devices
0: Gruppo microfoni (Realtek High Definition Audio(SST))
        driver: {0.0.1.00000000}.{3e5f6c41-829c-4c38-b6c7-9beac6254ed3}
        type: Microphone
        flags: enabled default (5000003)