Author Topic: Do not play through Bass_Asio. What's my mistake?  (Read 280 times)

Vitaliy

  • Posts: 20
Hello. Help me please in Lazarus.
Asio devices initialized. But do not play. The frequency switched to 48k and stop. Directx devices play normally. What's my mistake?
Code: [Select]
stream:= Bass_streamCreateFile(false, Pchar(UTF8ToUTF16(Listbox2.Items.Strings[item])), 0, 0, BASS_UNICODE);

BASS_ChannelGetInfo(stream,info);
CDbl:= info.freq;
BASS_ChannelGetData(stream, bufdata, BASS_DATA_AVAILABLE);
ASIOPROC(FALSE,0,bufdata,BASS_DATA_AVAILABLE,PInteger(stream));
BASS_ASIO_ChannelEnable(false, 0, MyAsioProc, PInteger(stream));
BASS_ASIO_ChannelJoin(FALSE, 1, 0);
BASS_ASIO_ChannelSetFormat (False, 0, BASS_ASIO_FORMAT_FLOAT);
       
        BASS_ASIO_ChannelSetRate(FALSE, 0, CDbl);
       
        BASS_ASIO_SetRate(CDbl);
BASS_ASIO_Start(0,0);         
And AsioProc  ???
Code: [Select]
function ASIOPROC(input:BOOL; channel:DWORD; buffer:Pointer; length:DWORD; user:Pointer): DWORD; stdcall;
var
c: Dword;
Begin
 c:=BASS_ChannelGetData(stream, bufdata, BASS_DATA_AVAILABLE);
 ASIOPROC:=c;
end;         

Test

  • Guest
Re: Do not play through Bass_Asio. What's my mistake?
« Reply #1 on: 21 Dec '17 - 12:17 »
Maybe like this will work?

Quote
function ASIOPROC(input:BOOL; channel:DWORD; buffer:Pointer; length:DWORD; user:Pointer): DWORD; stdcall;
var
c: Dword;
Begin
result :=BASS_ChannelGetData(stream, bufdata, length);
end;     


Vitaliy

  • Posts: 20
Re: Do not play through Bass_Asio. What's my mistake?
« Reply #2 on: 21 Dec '17 - 21:47 »
Maybe like this will work?

Quote
function ASIOPROC(input:BOOL; channel:DWORD; buffer:Pointer; length:DWORD; user:Pointer): DWORD; stdcall;
var
c: Dword;
Begin
result :=BASS_ChannelGetData(stream, bufdata, length);
end;     



Thank you for answer. Tried it, but does not play, the frequency on the DAC switches correctly, but does not play.

Vitaliy

  • Posts: 20
Re: Do not play through Bass_Asio. What's my mistake?
« Reply #3 on: 21 Dec '17 - 22:52 »
Code: [Select]
var
MyAsioProc: asioproc;
Right?

Vitaliy

  • Posts: 20
Re: Do not play through Bass_Asio. What's my mistake?
« Reply #4 on: 21 Dec '17 - 23:35 »
corrected:
Code: [Select]
private
    { private declarations }
   ...
  function ASIOProc(input:bool;channel:DWORD;buffer:Pointer;length:DWORD;user:Pointer):DWORD;
and
Code: [Select]
function TForm1.ASIOPROC(input:BOOL; channel:DWORD; buffer:Pointer; length:DWORD; user:Pointer): DWORD;
var
c: Dword;
Begin
result :=BASS_ChannelGetData(stream, buffer, length);
end;                         

Asio playback don't work...  ???

VST should be added before or after "BASS_ASIO_ChannelEnable" code?

Vitaliy

  • Posts: 20
Re: Do not play through Bass_Asio. What's my mistake?
« Reply #5 on: 22 Dec '17 - 02:59 »
Tried it.
Code: [Select]
function ASIOPROC(input:BOOL; channel:DWORD; buffer:Pointer; length:DWORD; user:Pointer): DWORD; StdCall;
var
c: Dword;
Begin
c := Bass_ChannelGetData(stream, buffer, Length);
 if (c = -1) then c := 0;
 Result := c;
end;
and
Code: [Select]
BASS_ASIO_ChannelEnable(false, 0, @AsioProc, nil);
BASS_ASIO_ChannelJoin(FALSE, 1, 0);
...
There is no result. I have no more ideas, please help.

Ian @ un4seen

  • Administrator
  • Posts: 20489
Re: Do not play through Bass_Asio. What's my mistake?
« Reply #6 on: 22 Dec '17 - 13:55 »
If you haven't already done so, check the return values from all of the BASS/BASSASIO calls, to see if any are failing. If a BASS call is failing, you can find out of why by using BASS_ErrorGetCode to get an error code and looking that up in the failed function's documentation. If a BASSASIO call fails, use BASS_ASIO_ErrorGetCode instead.

As you are setting the ASIO channel to floating-point (BASS_ASIO_FORMAT_FLOAT), you should also make the file stream floating-point by using BASS_SAMPLE_FLOAT flag in its BASS_StreamCreateFile call.

Vitaliy

  • Posts: 20
Re: Do not play through Bass_Asio. What's my mistake?
« Reply #7 on: 22 Dec '17 - 21:16 »
If you haven't already done so, check the return values from all of the BASS/BASSASIO calls, to see if any are failing. If a BASS call is failing, you can find out of why by using BASS_ErrorGetCode to get an error code and looking that up in the failed function's documentation. If a BASSASIO call fails, use BASS_ASIO_ErrorGetCode instead.

As you are setting the ASIO channel to floating-point (BASS_ASIO_FORMAT_FLOAT), you should also make the file stream floating-point by using BASS_SAMPLE_FLOAT flag in its BASS_StreamCreateFile call.

Thank you for your answer.
I tried it:
Code: [Select]
stream:= Bass_streamCreateFile(false, Pchar(UTF8ToWinCP(Listbox2.Items.Strings[item])), 0, 0, BASS_SAMPLE_FLOAT);
BASS_ChannelGetInfo(stream,info);
CDbl:= info.freq;
 BASS_ASIO_ChannelEnable(false, 0, @AsioProc, PInteger(stream));
  BASS_ASIO_ChannelJoin(FALSE, 1, 0);
        BASS_ASIO_ChannelSetFormat (False, 0, BASS_ASIO_FORMAT_FLOAT);
                BASS_ASIO_ChannelSetRate(FALSE, 0, CDbl);
                BASS_ASIO_SetRate(CDbl);

  BASS_ASIO_Start(0,0);
  ShowMessage(Inttostr(BASS_ASIO_ErrorGetCode));
and
Code: [Select]
function ASIOPROC(input:BOOL; channel:DWORD; buffer:Pointer; length:DWORD; user:Pointer): DWORD; StdCall;
var
c: Dword;
Begin
 c := Bass_ChannelGetData(stream, buffer, Length);
 if (c = -1) then c := 0;
 Result := c;
end;       


Error code is "0". The frequency on the DAC switches correctly, but does not play.  :'(

Vitaliy

  • Posts: 20
Re: Do not play through Bass_Asio. What's my mistake?
« Reply #8 on: 22 Dec '17 - 21:41 »
Code: [Select]
ShowMessage(Inttostr(BASS_ASIO_ChannelIsActive(False,0)));
shows "1" - "The channel is enabled."  :'(

Asio error code shows "0" - "BASS_OK"  :'(

Vitaliy

  • Posts: 20
Re: Do not play through Bass_Asio. What's my mistake?
« Reply #9 on: 22 Dec '17 - 21:57 »
Code: [Select]
ScrollBar1.Position:= Bass_ChannelGetPosition
can affect asio?

Chris

  • Posts: 1814
Re: Do not play through Bass_Asio. What's my mistake?
« Reply #10 on: 22 Dec '17 - 23:42 »
Hi
here is a complete working asio demo for lazarus.


Vitaliy

  • Posts: 20
Re: Do not play through Bass_Asio. What's my mistake?
« Reply #11 on: 23 Dec '17 - 08:16 »
Hi
here is a complete working asio demo for lazarus.

Hi. Thank you for your answer.
Code: [Select]
stream:= Bass_streamCreateFile(false, Pchar(UTF8ToWinCP(Listbox2.Items.Strings[item])), 0, 0, BASS_SAMPLE_FLOAT);
BASS_ChannelGetInfo(stream,info);
BASS_ASIO_ChannelEnable(false, stream, @AsioProc, nil);
BASS_ASIO_ChannelJoin(FALSE, 1, 0);
        BASS_ASIO_ChannelSetFormat (False, 0, BASS_ASIO_FORMAT_FLOAT);
               BASS_ASIO_ChannelSetRate(FALSE, 0, info.freq);
               BASS_ASIO_SetRate(info.freq);

  BASS_ASIO_Start(0,0);
  ShowMessage(Inttostr(BASS_ASIO_ErrorGetCode));
  ShowMessage(Inttostr(BASS_ASIO_ChannelIsActive(False,0)));

BASS_ASIO_ErrorGetCode - "18" - "BASS_ERROR_NOCHAN"
BASS_ASIO_ChannelIsActive - "0" - "BASS_ASIO_ACTIVE_DISABLED".

Vitaliy

  • Posts: 20
Re: Do not play through Bass_Asio. What's my mistake?
« Reply #12 on: 23 Dec '17 - 08:44 »
Hi
here is a complete working asio demo for lazarus.

Your example does not start. Form does not open. Lazarus 1.6.4 64bit.

Ian @ un4seen

  • Administrator
  • Posts: 20489
Re: Do not play through Bass_Asio. What's my mistake?
« Reply #13 on: 23 Dec '17 - 13:52 »
I tried it:
Code: [Select]
stream:= Bass_streamCreateFile(false, Pchar(UTF8ToWinCP(Listbox2.Items.Strings[item])), 0, 0, BASS_SAMPLE_FLOAT);
BASS_ChannelGetInfo(stream,info);
CDbl:= info.freq;
 BASS_ASIO_ChannelEnable(false, 0, @AsioProc, PInteger(stream));
  BASS_ASIO_ChannelJoin(FALSE, 1, 0);
        BASS_ASIO_ChannelSetFormat (False, 0, BASS_ASIO_FORMAT_FLOAT);
                BASS_ASIO_ChannelSetRate(FALSE, 0, CDbl);
                BASS_ASIO_SetRate(CDbl);

  BASS_ASIO_Start(0,0);
  ShowMessage(Inttostr(BASS_ASIO_ErrorGetCode));
and
Code: [Select]
function ASIOPROC(input:BOOL; channel:DWORD; buffer:Pointer; length:DWORD; user:Pointer): DWORD; StdCall;
var
c: Dword;
Begin
 c := Bass_ChannelGetData(stream, buffer, Length);
 if (c = -1) then c := 0;
 Result := c;
end;       


Error code is "0". The frequency on the DAC switches correctly, but does not play.  :'(

You should check the error code after each BASS or BASSASIO function call (it changes after each call). From what you describe, I suspect the BASS_StreamCreateFile call is failing.

3delite

  • Posts: 916
Re: Do not play through Bass_Asio. What's my mistake?
« Reply #14 on: 23 Dec '17 - 15:04 »
Tip: shouldn't the BASS_STREAM_DECODE flag be added for the Bass_streamCreateFile() function?

Chris

  • Posts: 1814
Re: Do not play through Bass_Asio. What's my mistake?
« Reply #15 on: 23 Dec '17 - 20:15 »
Quote
stream:= Bass_streamCreateFile(false, Pchar(UTF8ToWinCP(Listbox2.Items.Strings[item])), 0, 0, BASS_SAMPLE_FLOAT);
should be
Code: [Select]
if (Listbox2.ItemIndex >= 0)then
Bass_StreamCreateFile(false, PChar(Listbox2.Items[Listbox2.ItemIndex]), 0, 0, BASS_SAMPLE_FLOAT or BASS_STREAM_DECODE);

Take a look in the demo Source !!!

Vitaliy

  • Posts: 20
Re: Do not play through Bass_Asio. What's my mistake?
« Reply #16 on: 23 Dec '17 - 23:27 »
Quote
stream:= Bass_streamCreateFile(false, Pchar(UTF8ToWinCP(Listbox2.Items.Strings[item])), 0, 0, BASS_SAMPLE_FLOAT);
should be
Code: [Select]
if (Listbox2.ItemIndex >= 0)then
Bass_StreamCreateFile(false, PChar(Listbox2.Items[Listbox2.ItemIndex]), 0, 0, BASS_SAMPLE_FLOAT or BASS_STREAM_DECODE);

Take a look in the demo Source !!!

so there is a noise and silk, music can not be heard

Vitaliy

  • Posts: 20
Re: Do not play through Bass_Asio. What's my mistake?
« Reply #17 on: 24 Dec '17 - 00:29 »
Quote
stream:= Bass_streamCreateFile(false, Pchar(UTF8ToWinCP(Listbox2.Items.Strings[item])), 0, 0, BASS_SAMPLE_FLOAT);
should be
Code: [Select]
if (Listbox2.ItemIndex >= 0)then
Bass_StreamCreateFile(false, PChar(Listbox2.Items[Listbox2.ItemIndex]), 0, 0, BASS_SAMPLE_FLOAT or BASS_STREAM_DECODE);

Take a look in the demo Source !!!



if I put two flags like this "BASS_SAMPLE_FLOAT or BASS_STREAM_DECODE" in Bass_StreamCreateFile when the init DirectX device, then program do not playback the file from the playlist.
« Last Edit: 24 Dec '17 - 00:40 by Vitaliy »

Vitaliy

  • Posts: 20
Re: Do not play through Bass_Asio. What's my mistake?
« Reply #18 on: 24 Dec '17 - 01:47 »
wrote a simple program and in it Asio earned. Now I will think about how to adapt the working code to my old program.
Thanks to everyone!  :)

Vitaliy

  • Posts: 20
Re: Do not play through Bass_Asio. What's my mistake?
« Reply #19 on: 24 Dec '17 - 01:53 »
Oh my God...
When the Asio track ends, then noise starts again, until I apply Bass_asio_Stop.

Vitaliy

  • Posts: 20
Re: Do not play through Bass_Asio. What's my mistake?
« Reply #20 on: 24 Dec '17 - 06:21 »
What is this noise with grinding in the Asio channel, when the track ends, between the tracks this noise appears for half a second. Noise is generated when the channel is not loaded.
How to remove this noise from the channel? It is impossible to use the program with it, since it is loud and arises suddenly and loudly.

3delite

  • Posts: 916
Re: Do not play through Bass_Asio. What's my mistake?
« Reply #21 on: 24 Dec '17 - 14:12 »
The noise might be because the 'buffer' is not filled by BASS_ChannelGetData() because the stream ended, so it contains random data. Try for example to fill the 'buffer' manually with 0s if the call returns an error.

Something like:

Code: [Select]
function ASIOPROC(input:BOOL; channel:DWORD; buffer:Pointer; length:DWORD; user:Pointer): DWORD; StdCall;
var
    c: Dword;
Begin
    c := Bass_ChannelGetData(stream, buffer, Length);
    if c = DW_ERROR then begin
        ZeroMemory(buffer, length);
        c := length;
    end;
    Result := c;
end;   

But not sure about this, the docs say if 0 is returned from the function then the output will be paused.

Chris

  • Posts: 1814
Re: Do not play through Bass_Asio. What's my mistake?
« Reply #22 on: 24 Dec '17 - 14:18 »
@Vitaliy what is if you play the same song in my Demo?
And which Soundcard and which Asio Driver?

Vitaliy

  • Posts: 20
Re: Do not play through Bass_Asio. What's my mistake?
« Reply #23 on: 24 Dec '17 - 22:48 »
@Vitaliy what is if you play the same song in my Demo?
And which Soundcard and which Asio Driver?

Your demo did not start, as I already wrote above.

Vitaliy

  • Posts: 20
Re: Do not play through Bass_Asio. What's my mistake?
« Reply #24 on: 24 Dec '17 - 22:53 »
Problem solved.
it was noisy:
Code: [Select]
c := Bass_ChannelGetData(stream, buffer, length);
  if (c = -1) then c := 0;
  Result := c;
the noise has disappeared:
Code: [Select]
c := Bass_ChannelGetData(stream, buffer, length);
  if (c = DW_ERROR) then c := 0;
  Result := c;


Thanks again to everyone for your help!