Author Topic: Mixer situation  (Read 715 times)

Ed1966

  • Posts: 82
Mixer situation
« on: 9 May '18 - 10:11 »
Hi there,

Translate default Stream to DECODED and MIXER for every player.
Later I want to put them all together to a MasterMixer. Possible? And no Play in child MIXERS?
Is there a audible sound if I do?

SYNC problem with use of 'BASS_Mixer_ChannelGetData'
I Called: SENDMESSAGE and system dropped down when calling 'BASS_Mixer_ChannelGetData' when fading.
No problem before mixer.
Now I use POSTMESSAGE and it works :) But why?

Thank you.

Ian @ un4seen

  • Administrator
  • Posts: 20909
Re: Mixer situation
« Reply #1 on: 9 May '18 - 13:50 »
Translate default Stream to DECODED and MIXER for every player.
Later I want to put them all together to a MasterMixer. Possible? And no Play in child MIXERS?
Is there a audible sound if I do?

Yes, you can plug a mixer into another mixer.

SYNC problem with use of 'BASS_Mixer_ChannelGetData'
I Called: SENDMESSAGE and system dropped down when calling 'BASS_Mixer_ChannelGetData' when fading.
No problem before mixer.
Now I use POSTMESSAGE and it works :) But why?

SendMessage waits for the message to be handled before returning, while PostMessage does not wait. I'm guessing you had a deadlock in the SendMessage case, ie. it was waiting for another thread (probably the main thread) to handle the message and that other thread was waiting for the SendMessage call's thread. You should avoid waiting for other threads in a "mixtime" SYNCPROC callback (or STREAMPROC/DSPPROC).

Ed1966

  • Posts: 82
Re: Mixer situation
« Reply #2 on: 15 May '18 - 13:32 »
Thanks so far...
I must do a complete rewrite to DECODED and MIXER situation.
Can I use BASS_SPEAKER_REAR and other SPEAKER flags, like this:

Code: [Select]
FMixerLeft := BASS_Mixer_StreamCreate(AFreq, AChans, BASS_UNICODE);
FStream := BASS_StreamCreateFile(False, PChar(AMusicFile), 0, 0, BASS_STREAM_DECODE or BASS_UNICODE or BASS_SPEAKER_REAR);
Result := BASS_Mixer_StreamAddChannel(FMixerLeft, FStream, BASS_MIXER_BUFFER or BASS_MIXER_NORAMPIN or BASS_MIXER_PAUSE);

This FMixerLeft and other FMixerRight wil be pluged into a master Mixer at later time.
(I don't loose de SPEAKER flag?)

Regards,
Eduard.

Ian @ un4seen

  • Administrator
  • Posts: 20909
Re: Mixer situation
« Reply #3 on: 15 May '18 - 14:13 »
When playing through a mixer, you would move the BASS_SPEAKER flags from the BASS_StreamCreateFile call to the BASS_Mixer_StreamAddChannel call:

Code: [Select]
FMixerLeft := BASS_Mixer_StreamCreate(AFreq, AChans, 0);
FStream := BASS_StreamCreateFile(False, PChar(AMusicFile), 0, 0, BASS_STREAM_DECODE or BASS_UNICODE);
Result := BASS_Mixer_StreamAddChannel(FMixerLeft, FStream, BASS_MIXER_BUFFER or BASS_MIXER_NORAMPIN or BASS_MIXER_PAUSE or BASS_SPEAKER_REAR);

Ed1966

  • Posts: 82
Re: Mixer situation
« Reply #4 on: 15 May '18 - 16:15 »
 :D Thank you Ian.

Ed1966

  • Posts: 82
Re: Mixer situation
« Reply #5 on: 18 May '18 - 09:06 »
I want to add 'BASS_FX_TempoCreate' for stream:

Code: [Select]
function TBassMixerAudio18.LoadAudio(AMusicFile: string; AVolume: FLOAT; ASpeakerFlag: DWORD): Boolean;
var
  Flags: DWORD;
begin
  FPlayingTime := 0.0;
  FEndPoint := 0.0;
  FTotalBytes := 0;
  FStartPoint := 0.0;
  FInputFile := AMusicFile;
  FVolume := AVolume;
  BASS_StreamFree(FStream);
  SetChannelMode(BASS_ACTIVE_STOPPED);
  FStream := BASS_StreamCreateFile(False, PChar(AMusicFile), 0, 0, BASS_STREAM_DECODE or BASS_UNICODE);
  Result := (FStream <> 0) and (BASS_ErrorGetCode = 0);
  if (Result) then
  begin
    { Ready }
    FTotalBytes := BASS_ChannelGetLength(FStream, BASS_POS_BYTE);
    FPlayingTime := BASS_ChannelBytes2Seconds(FStream, FTotalBytes);
    FEndPoint := FPlayingTime;
    BASS_ChannelSetAttribute(FStream, BASS_ATTRIB_VOL, AVolume);
    BASS_ChannelSetPosition(FStream, 0, BASS_POS_BYTE);
    { Creates a resampling stream }
    FStream := BASS_FX_TempoCreate(FStream, BASS_STREAM_DECODE);
    Result := (FStream <> 0) and (BASS_ErrorGetCode = 0);
    if (Result) then
    begin
      { Setup Mixer }
      BASS_Mixer_ChannelRemove(FStream);
      { Speaker Flags must be here and not at StreamCreate }
      Flags := BASS_MIXER_BUFFER or BASS_MIXER_NORAMPIN or BASS_MIXER_PAUSE or ASpeakerFlag;
      Result := BASS_Mixer_StreamAddChannel(FMixer, FStream, Flags);
      if (Result) then ;
    end;
  end;
  ErrorCode := BASS_ErrorGetCode;
end;

And before shutdown:

Code: [Select]
  BASS_PluginFree(0);
  UnLoad_BASSDLL;
  Unload_BASSFXDLL;
  Unload_WASAPIDLL;
  Unload_BASSENCDLL;
  Unload_BASSMIXDLL;

But now I get:
---------------------------
Debugger Exception Notification
---------------------------
Project FinalPlayer.exe raised exception class $C0000005 with message 'access violation at 0x628fdeab: read of address 0x1000f04c'.
---------------------------

Is there something wrong with position:
FStream := BASS_FX_TempoCreate(FStream, BASS_STREAM_DECODE);
If I remove everything is fine.

By start program:
Code: [Select]
   if (FileExists(AddBS(LibraryFolderPath) + 'Win32\bass_fx.dll')) then begin
      Load_BASSFXDLL(AddBS(LibraryFolderPath) + 'Win32\bass_fx.dll');
   end else begin
      MessageDlg('library\Win32\bass_fx.dll not found; Incorrect file/path', mtError, [mbOK, mbCancel], 0);
      Exit;
   end;

   { Check the correct BASS_FX was loaded }
   BASS_FX_VERSION := BASS_FX_GetVersion();
   BASS_FX_VERSION_TEXT := GetBassVersionInfo(BASS_FX_VERSION);
   if (HiWord(BASS_FX_VERSION) <> BASSVERSION) then begin
     MessageDlg('An incorrect version of BASS_FX.DLL was loaded (2.4 is required)', mtError, [mbOK, mbCancel], 0);
     Exit;
   end;


Regards,
Eduard.
« Last Edit: 18 May '18 - 09:14 by Ed1966 »

Chris

  • Posts: 1847
Re: Mixer situation
« Reply #6 on: 18 May '18 - 09:18 »
Hi
$C0000005 will mean in Delphi Invalide Handle.
By the way

Quote
BASS_PluginFree(0);
  UnLoad_BASSDLL;
  Unload_BASSFXDLL;
  Unload_WASAPIDLL;
  Unload_BASSENCDLL;
  Unload_BASSMIXDLL;

should be

Code: [Select]
BASS_PluginFree(0);
  Unload_BASSFXDLL;
  Unload_WASAPIDLL;
  Unload_BASSENCDLL;
  Unload_BASSMIXDLL;
  UnLoad_BASSDLL;

Unload Bass as last not as first

Ed1966

  • Posts: 82
Re: Mixer situation
« Reply #7 on: 18 May '18 - 12:08 »
Changed, but problem the same as before?

Chris

  • Posts: 1847
Re: Mixer situation
« Reply #8 on: 18 May '18 - 16:46 »
does the Exception occurs if you close your application?
or does it come during a call ?
normally you can see it inside the debugger from where the crash comes.

Ian @ un4seen

  • Administrator
  • Posts: 20909
Re: Mixer situation
« Reply #9 on: 18 May '18 - 17:36 »
Yes, try running the code under the debugger and check the callstack when the crash happens. If that doesn't show what call the crash happened in then try placing a breakpoint on the BASS_FX_TempoCreate call and then step over that call to confirm whether the crash is happening in it.

Ed1966

  • Posts: 82
Re: Mixer situation
« Reply #10 on: 20 May '18 - 06:34 »
Solved. I forgot to FREE the Mixer and Stream when shutdown project.
BASS_StreamFree(FStream) and FMixer := BASS_Mixer_StreamCreate(AFreq, AChans, BASS_UNICODE or BASS_STREAM_AUTOFREE);
It went well for a while but apparently due to more code the error became visible.

Regards,
Eduard.

Ian @ un4seen

  • Administrator
  • Posts: 20909
Re: Mixer situation
« Reply #11 on: 21 May '18 - 17:19 »
Oh yes, you shouldn't unload BASS while there are still streams existing, or indeed while a device is still initialized. Make sure you call BASS_Free, eg. just before the BASS_PluginFree call. BASS_Free will also free the streams (on the freed device), so you don't really need to call BASS_StreamFree too then.

Ed1966

  • Posts: 82
Re: Mixer situation
« Reply #12 on: 21 May '18 - 19:31 »
I am very happy everything is now working. I only have one question about:

Code: [Select]
BASS_ChannelSetAttribute(FStream, BASS_ATTRIB_TEMPO, AValue);
If I put value of -65 or +65 for testing the sound is disturbing. Crackling.
The only valid value is about maximum -24 and +24.
Is this okay or am I wrong?

If I take a look at example:

Code: [Select]
float tempo = (goalBPM / bpmValue - 1.0f) * 100.0f;
BASS_ChannelSetAttribute(chan, BASS_ATTRIB_TEMPO, tempo);


I use Delphi and if I use for testing:

(150 / 99) * 100 (I get as result 151)
Is that not too much and must this multiply by 100% (result is then 1.51)

Hopefully clear what I mean.
Regards,
Eduard.

 

Chris

  • Posts: 1847
Re: Mixer situation
« Reply #13 on: 22 May '18 - 14:02 »
The Tempo Value is Percent.....
so example +24 is then 124% to the original Value
-24 is then 76% to the Original Value.
If you want to making from Frank Sinatra -> Micky Mouse then Pitching is a Better Alternative.

Ian @ un4seen

  • Administrator
  • Posts: 20909
Re: Mixer situation
« Reply #14 on: 22 May '18 - 14:06 »
If I take a look at example:

Code: [Select]
float tempo = (goalBPM / bpmValue - 1.0f) * 100.0f;
BASS_ChannelSetAttribute(chan, BASS_ATTRIB_TEMPO, tempo);


I use Delphi and if I use for testing:

(150 / 99) * 100 (I get as result 151)
Is that not too much and must this multiply by 100% (result is then 1.51)

You need to subtract 1 before multiplying, or 100 after multiplying, so the result there would be 51.

Regarding the valid BASS_ATTRIB_TEMPO range, that is -95 to 5000, but I think the result is quite likely to sound worse as you move further away from 0 (the default).

Ed1966

  • Posts: 82
Re: Mixer situation
« Reply #15 on: 22 May '18 - 17:35 »
Thank you now it's clear.  :) :D

Ed1966

  • Posts: 82
Re: Mixer situation
« Reply #16 on: 25 May '18 - 10:06 »
Is there a differents between the new BASS en the older. Now I must FreeStream for microphone also.
Solvable I think but I was thinking why.

And is there a topic for vinyl scratch that is working so I can do some testing?

Ian @ un4seen

  • Administrator
  • Posts: 20909
Re: Mixer situation
« Reply #17 on: 25 May '18 - 17:23 »
There have been some posts about implementing vinyl scratch effects over the years. Here are a couple that include code:

   www.un4seen.com/forum/?topic=9754
   www.un4seen.com/forum/?topic=10910.msg96190#msg96190

Ed1966

  • Posts: 82
Re: Mixer situation
« Reply #18 on: 25 May '18 - 17:37 »
Thank you. But not the differents for Stream free?

Ian @ un4seen

  • Administrator
  • Posts: 20909
Re: Mixer situation
« Reply #19 on: 25 May '18 - 17:58 »
I wasn't entirely sure what you meant there. Please post before and after code snippets to show what you've had to change.

Ed1966

  • Posts: 82
Re: Mixer situation
« Reply #20 on: 28 May '18 - 12:36 »
I had make little mistake and solved it with:

Code: [Select]
BASS_StreamFree(LineMonitorInputStream);
BASS_StreamFree(MicrophoneInputStream);

One other question about VST.

I get a valid Handle but how to show screen? (Delphi user)

Code: [Select]
VSTEffect := AddBS(VSTPluginFolderPath) + 'Scratch it.dll';
if fileExists(VSTEffect) then begin
    DSPHandle := BASS_VST_ChannelSetDSP(MasterMixer18.GetStream, PChar(VSTEffect), BASS_UNICODE, 0);
    DisplayError('BASS_VST_ChannelSetDSP', BASS_ErrorGetCode);
end;

Maybe some startpointer for me. I cannot find sample?

Regards,
Eduard.

Chris

  • Posts: 1847
Re: Mixer situation
« Reply #21 on: 28 May '18 - 15:00 »
Hi,
Code: [Select]
var
 Finfo: BASS_VST_INFO;
VSTEffect := AddBS(VSTPluginFolderPath) + 'Scratch it.dll';
if fileExists(VSTEffect) then
    DSPHandle := BASS_VST_ChannelSetDSP(MasterMixer18.GetStream, PChar(VSTEffect), BASS_UNICODE, 0);
  if DSPHandle = 0 then // Error
    DisplayError('BASS_VST_ChannelSetDSP', BASS_ErrorGetCode);
// Show the Editor remember you will need a TPanel or a window Based Control (TForm,TPanel,or a TPaintBox) which have a own handle for showing the Editor
  BASS_VST_GetInfo(FInfo,DSPHandle);// we need this to catch the size of the editor
  Panel2.Height:= FInfo.EditorHeight;
  Panel2.Width:= FInfo.EditorWidth;
 if not  BASS_VST_EmbedEditor(DSPHandle,Panel2.handle) then// In this example we will showing the VST Editor in Panel2
   DisplayError('Error, cant Display The VST Editor inside Panel2', BASS_ErrorGetCode);
« Last Edit: 28 May '18 - 15:11 by Chris »

Ed1966

  • Posts: 82
Re: Mixer situation
« Reply #22 on: 28 May '18 - 16:40 »
Thank you.  :D

There is only one problem with GetInfo.
(I use Dynamic_BassVST)

Code: [Select]
var
   FInfo: BASS_VST_INFO;

BASS_VST_GetInfo(DSPHandle, @FInfo);// we need this to catch the size of the editor
Form.Height:= FInfo.EditorHeight;
Form.Width:= FInfo.EditorWidth;

I only get garbage info. All random values. Is this GetMem issue?

Here my little test source:

Code: [Select]
procedure TfrmMixerSetup.Button1Click(Sender: TObject);
var
  Form: TForm;
  VSTEffect: string;
  DSPHandle: HSTREAM;
  FInfo: BASS_VST_INFO;

  procedure DisplayError(AStr: string; ErrCode: Integer); overload;
  begin
    if ErrCode > 46 then ErrCode := 10;
    AStr := AStr + #32 + GetBASSErrorCode(ErrCode) + ' (Error code: ' + IntToStr(ErrCode) + ')';
    ShowMessage(AStr);
  end;

begin
  VSTEffect := AddBS(VSTPluginFolderPath) + 'Scratch it.dll';
  // VSTEffect := AddBS(VSTPluginFolderPath) + 'DD Equaliser.dll'; { Same problem GetInfo }
  if fileExists(VSTEffect) then begin
    DSPHandle := BASS_VST_ChannelSetDSP(MasterMixer18.GetStream, PChar(VSTEffect), BASS_UNICODE, 0);
    if DSPHandle = 0 then // Error
      DisplayError('BASS_VST_ChannelSetDSP', BASS_ErrorGetCode);
    Form := TForm.Create(Self);
    // Show the Editor remember you will need a TPanel or a window Based Control
    // (TForm,TPanel,or a TPaintBox) which have a own handle for showing the Editor

    BASS_VST_GetInfo(DSPHandle, @FInfo);// we need this to catch the size of the editor
    Form.Height:= FInfo.EditorHeight;
    Form.Width:= FInfo.EditorWidth;

    if not BASS_VST_EmbedEditor(DSPHandle,Form.handle) then // In this example we will showing the VST Editor in Panel2
      DisplayError('Error, cant Display The VST Editor inside Form', BASS_ErrorGetCode);
    Form.Show;
  end;
end;

« Last Edit: 28 May '18 - 18:01 by Ed1966 »

Chris

  • Posts: 1847
Re: Mixer situation
« Reply #23 on: 28 May '18 - 21:33 »
Here is a little working modified demo  incl bass ->bass_fx -> mixer->BassVST .

Ed1966

  • Posts: 82
Re: Mixer situation
« Reply #24 on: 29 May '18 - 01:32 »
Thanks for demo but there is no differents with my source.

When evaluate 'FInfo' I get these results:



This is not correct. I use XE8.

Now I see problem, it's in 'Dynamic_BassVST:BASS_VST_INFO
Char must be AnsiChar.


Code: [Select]
EffectName : array [0..79] of AnsiChar;    // the effect name
ProductName : array [0..79] of AnsiChar;   // the product name, may be empty
VendorName: array [0..79] of AnsiChar;     // the vendor name, may be empty

Maybe 'BASS_VST_PARAM_INFO' needs AnsiChar to?

Regards,
Eduard.