Recent

Author Topic: Special characters BASS_StreamCreateFile  (Read 1040 times)

pcurtis

  • Full Member
  • ***
  • Posts: 118
Special characters BASS_StreamCreateFile
« on: June 28, 2020, 06:42:40 pm »
I'm still playing with BASS and have one final last problem.

If the filename contains special characters (ěščř ...) then BASS_StreamCreateFile fails with error 2.

I came across this problem before and fixed it with :


{$mode Delphi}

BASS_StreamCreateFile(False, pwidechar(aFile), 0, 0, BASS_UNICODE);

I have just created a class (see attachment - you will need bass.dll and bass_fx.dll) and it doesn't work. The code works fine on normal file names.

Any suggestions?
« Last Edit: June 28, 2020, 08:16:38 pm by pcurtis »
Windows 10 / Linux Mint 20
Laz 2.0.8
FPC 3.0.4

winni

  • Hero Member
  • *****
  • Posts: 1605
Re: Special characters BASS_StreamCreateFile
« Reply #1 on: June 28, 2020, 07:37:36 pm »
Again


BASS_StreamCreateFile(False, pchar(aFile), 0, 0, BASS_UNICODE);

Winni

pcurtis

  • Full Member
  • ***
  • Posts: 118
Re: Special characters BASS_StreamCreateFile
« Reply #2 on: June 28, 2020, 08:05:29 pm »
No, it still doesn't work  :(
Windows 10 / Linux Mint 20
Laz 2.0.8
FPC 3.0.4

winni

  • Hero Member
  • *****
  • Posts: 1605
Re: Special characters BASS_StreamCreateFile
« Reply #3 on: June 28, 2020, 08:59:40 pm »
RTFM:

BASS_Unicode   file is in UTF -16 form. Otherwise it is ANSI or Windows or Windows CE, and UTF8 on other platforms.

From: BASS.chm

Winni





pcurtis

  • Full Member
  • ***
  • Posts: 118
Re: Special characters BASS_StreamCreateFile
« Reply #4 on: June 28, 2020, 09:21:32 pm »
OK, but how do I fix it?
Windows 10 / Linux Mint 20
Laz 2.0.8
FPC 3.0.4

winni

  • Hero Member
  • *****
  • Posts: 1605
Re: Special characters BASS_StreamCreateFile
« Reply #5 on: June 28, 2020, 09:35:39 pm »
Hi!

Replace the flag BASS_UNICODE with a zero!!!

Winni

pcurtis

  • Full Member
  • ***
  • Posts: 118
Re: Special characters BASS_StreamCreateFile
« Reply #6 on: June 28, 2020, 09:56:15 pm »
It still doesn't work :(
Windows 10 / Linux Mint 20
Laz 2.0.8
FPC 3.0.4

winni

  • Hero Member
  • *****
  • Posts: 1605
Re: Special characters BASS_StreamCreateFile
« Reply #7 on: June 28, 2020, 10:24:54 pm »
What Bass version?

What OS ?

What fpc version?

What Lazarus version?

What country?

What codepage for the filenames?

Which crystall ball shall I use?

Winni

pcurtis

  • Full Member
  • ***
  • Posts: 118
Re: Special characters BASS_StreamCreateFile
« Reply #8 on: June 28, 2020, 10:53:53 pm »
What Bass version? bass 2.4.15.0 bass_fx 2.4.12.1

What OS ? Win 10

What fpc version? 3.0.4

What Lazarus version? 2.0.8

What country? Czech Republic - but US OS

What codepage for the filenames? How do I find this info? chcp gives 437

Which crystall ball shall I use?

Maybe I didn't make it clear in the opening post. I had already solved this problem once, but it returned after I made a class. See attachment in opening post, and I can't figure out why.
« Last Edit: June 28, 2020, 11:16:33 pm by pcurtis »
Windows 10 / Linux Mint 20
Laz 2.0.8
FPC 3.0.4

winni

  • Hero Member
  • *****
  • Posts: 1605
Re: Special characters BASS_StreamCreateFile
« Reply #9 on: June 28, 2020, 11:53:20 pm »
Hi!

Tested your code with adaption to Linux - wont run.

You are trying everything at the same time.

Step 1: Dont mix up the creation, the initialization and the loading of a file.
Do it step by step.
Sep 2: Try to avoid recursive uses. Not a big trick.
Step 3: Just try to play a song.  Then Try to load a filename with special chars.
Step 4. If everything runs then try to implement the equalizer.

I am unable to read that Spagethi code.

And for that simple issues you don't need a class.

Winni




pcurtis

  • Full Member
  • ***
  • Posts: 118
Re: Special characters BASS_StreamCreateFile
« Reply #10 on: June 29, 2020, 04:55:51 am »
Found the way with help on the un4seen forum :

Code: Pascal  [Select][+][-]
  1. constructor TMyBASS.Create(aHandle : THandle; aFile: string; aVol : Double; aPreset : integer);
  2. var
  3.   myfx : dword;
  4.   eqCount : integer;
  5.   p : BASS_BFX_PEAKEQ;
  6.   UniString : UnicodeString;
  7. begin
  8.   Equalizer_Centers := TCenters.Create(80, 170, 310, 600, 1000, 3000, 7000, 12000, 14000, 16000);
  9.   Custom_Bands := TCustomBands.Create(0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  10.   BASS_Init(-1, 44100, aHandle, 0, nil);
  11.   myfx := BASS_FX_GetVersion;
  12.   BASS_SetVolume(aVol);
  13.  
  14.   UniString := aFile;
  15.  
  16.   aStream := BASS_StreamCreateFile(False, PWideChar(UniString), 0, 0, BASS_UNICODE);
  17.  
  18.   eqfx := BASS_ChannelSetFX(aStream, BASS_FX_BFX_PEAKEQ, 0);
  19.   BASS_ChannelPlay(aStream, False);
  20. end;
  21.  
« Last Edit: June 29, 2020, 04:58:03 am by pcurtis »
Windows 10 / Linux Mint 20
Laz 2.0.8
FPC 3.0.4

morknot

  • New Member
  • *
  • Posts: 31
  • still learning
Re: Special characters BASS_StreamCreateFile
« Reply #11 on: June 29, 2020, 11:53:20 am »
I had the same problem but solved it slightly differently:

Code: Pascal  [Select][+][-]
  1. function TplayerF.loadtrack(musicfile:string):DWORD;
  2. var
  3.   s:widestring;
  4. begin
  5. s:=widestring(musicfile);
  6. Result:= BASS_StreamCreateFile(false, Pchar(s), 0, 0,  BASS_UNICODE);
  7. end;

Doing it your way you are likely to get a debugger warning of:

Warning: Implicit string type conversion from "AnsiString" to "UnicodeString".

I have no idea whether this is crucial or not as your code still works.




 

wp

  • Hero Member
  • *****
  • Posts: 7362
Re: Special characters BASS_StreamCreateFile
« Reply #12 on: June 29, 2020, 12:22:17 pm »
I had the same problem but solved it slightly differently:

Code: Pascal  [Select][+][-]
  1. function TplayerF.loadtrack(musicfile:string):DWORD;
  2. var
  3.   s:widestring;
  4. begin
  5. s:=widestring(musicfile);
  6. Result:= BASS_StreamCreateFile(false, Pchar(s), 0, 0,  BASS_UNICODE);
  7. end;

This code looks very strange, and normally it should not work: when you cast the string "musicfile" to widestring s why can you use a "PChar(s)" as the 2nd parameter of BASS_StreamCreateFile (instead of "PWideChar(s)")? Looking at the signature of BASS_StreamCreateFile I see that it requests only an untyped pointer here, and this is why your code is working:

Code: Pascal  [Select][+][-]
  1. function BASS_StreamCreateFile(mem: BOOL; f: Pointer; offset, length: QWORD; flags: DWORD): HSTREAM; {$IFDEF MSWINDOWS}stdcall{$ELSE}cdecl{$ENDIF}; external bassdll;
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

winni

  • Hero Member
  • *****
  • Posts: 1605
Re: Special characters BASS_StreamCreateFile
« Reply #13 on: June 29, 2020, 12:23:11 pm »
Hi!

Don't  hack here and there on your code.

Make a simple redesign and then enhance it.

I just put the main steps together for you:

Code: Pascal  [Select][+][-]
  1. var B_Stream: DWord;
  2.     err: Integer;
  3.     B_Volume,B_Pan : single;
  4. begin
  5.  
  6. BASS_Init(-1, 44100, 0, Handle, nil);
  7. ......
  8. if NOT BASS_ACTIVE_STOPPED then
  9. begin
  10. BASS_ChannelStop(B_Stream);
  11. BASS_StreamFree(B_Stream);
  12. end
  13.  
  14. B_Stream := BASS_StreamCreateFile(False, PChar(Filename), 0, 0, BASS_STREAM_PRESCAN OR BASS_SAMPLE_FLOAT );
  15. // OR:
  16. // B_Stream := BASS_StreamCreateURL(Pchar(URL),0,BASS_Sample_Float,NIL,Nil);
  17.  
  18. err := BASS_ErrorGetCode;
  19. if err <>  0 then begin showMessage ('ERROR '+IntToStr(err)); exit; end;
  20. .....
  21. B_Volume := 0.5;
  22. B_Pan := 0;
  23. BASS_ChannelSetAttribute(B_Stream, BASS_ATTRIB_VOL, B_Volume);
  24. BASS_ChannelSetAttribute(B_Stream, BASS_ATTRIB_PAN, B_PAN);
  25. BASS_ChannelPlay(B_Stream , false);
  26. end;
  27.  
  28.  

And when you got it working you can enlarge your code.

Winni


PS.: And forget about BASS_UNICODE. This is wrong!
« Last Edit: June 29, 2020, 12:30:13 pm by winni »

morknot

  • New Member
  • *
  • Posts: 31
  • still learning
Re: Special characters BASS_StreamCreateFile
« Reply #14 on: June 29, 2020, 01:19:07 pm »
I can't explain why my code works, it just does. I am a very amateur coder.

If your "filename" is a standard string then for me, BASS_StreamCreateFile fails.

Also if I omit BASS_UNICODE then BASS_StreamCreateFile also fails whether it's a widestring
or standard string.

 

TinyPortal © 2005-2018