Author Topic: how to add bass.net to blazor web app  (Read 352 times)

hungnt

  • Posts: 11
how to add bass.net to blazor web app
« on: 25 Jan '21 - 15:38 »
hi,

Is it possible to add bass.net to blazor web app? if it is capable to do that, which version of bass.net for blazor client app and for blazor server app

Thanks,

hungnt

  • Posts: 11
Re: how to add bass.net to blazor web app
« Reply #1 on: 4 Feb '21 - 14:31 »
Does anyone  know this ??

Please support me this case.

Ian @ un4seen

  • Administrator
  • Posts: 23640
Re: how to add bass.net to blazor web app
« Reply #2 on: 4 Feb '21 - 16:12 »
I'm unfamiliar with Blazor. Does it allow you to use native libraries, like BASS.DLL? That would be the main requirement to make using BASS possible. Note BASS.Net is a wrapper for the native BASS libraries, so they are also needed.

radio42

  • Posts: 4717
Re: how to add bass.net to blazor web app
« Reply #3 on: 4 Feb '21 - 21:26 »
Honestly, I also haven't used Blazor so far.

RiokiGun

  • Posts: 1
Re: how to add bass.net to blazor web app
« Reply #4 on: 5 Feb '21 - 13:05 »
No matter how much I look for an answer to your question, I can't find anything and I am reduced to the opinion that it is impossible.

hungnt

  • Posts: 11
Re: how to add bass.net to blazor web app
« Reply #5 on: 6 Feb '21 - 14:51 »
hi all,

Thanks for your replies.

Yes, I know bass.net is wrapper of the native bass.dll. I also tested with winform app, it works very well.

Can you please take a look at blazor definition then check its compatibility of bass.net? I am very beginner on web app, so this time it is not easy for me to find out why


hungnt

  • Posts: 11
Re: how to add bass.net to blazor web app
« Reply #6 on: 26 Feb '21 - 15:41 »
Hi,

After having some of suggestion in blazor forum, I have re-created web project with TargetFramework .netcore 3.0 ( I selected it because your bass.net now is for .netcore 2.1 ( or higher  ). Then I got error as the attachment.

Can you please take a look, then explain what is error come there?

I am sorry if I bother you guys too much.

Thanks

serkanp

  • Posts: 95
Re: how to add bass.net to blazor web app
« Reply #7 on: 23 Apr '21 - 13:59 »
Hi,

After having some of suggestion in blazor forum, I have re-created web project with TargetFramework .netcore 3.0 ( I selected it because your bass.net now is for .netcore 2.1 ( or higher  ). Then I got error as the attachment.

Can you please take a look, then explain what is error come there?

I am sorry if I bother you guys too much.

Thanks

hi,
what you get as error is bass.net tries to find bass.dll and can't find it..

let me explain why:
actually blazor can run only dotnet standart or dotnet core dll's..
why? because blazor is a platform, that you can run your existing dotnet standartor dotnet core apps (not dotnet framework 4.xx, some parts are platform depended) on browser. with blazor, you can run your .net framework standart/core based apps on browser.
microsoft ported .net framework to browser scripting code (it is someting like javascript for you, but actually it is a webassembly port of native code). blazor based dotnet apps, uses non platform depended code. so on any browser, teorically, it can work..

bass.net is a "wrapper" of c++ native bass.dll (.dll on windows,.so on linux, other types on different platforms. so on each platform ,bass have different compiled versions, means each one is platform depended like linux, android, macos, windows).
this means, when your dotnet code sends a command to bass.dll, bass.net "wrapper" takes your command and sends it to bass.dll.. so when you are on windows, browser must access bass.dll, on linux bass.so, on android/ios/macos etc..  to different "platform depended" native code.

on browser, you may use bass.net wrapper,yes it is compatible with dotnet standart/core, but it can not use bass.dll .
first problem is platform dependency, second, browser restricts to access such kind of native libraries due to security restrictions. (bass.dll is innocent, because it only uses audio features, but think any other native code formats computer or do dangerous operations on your pc. there were some very interesting viruses that uses webassembly.. one of them creates a new code on browser, compiles it on browser, creates private certificate and gets remote public certificate, then communicates with its server.. gets encrypted virus from remote computer, decodes it , so antivirus programs cannot detect malicious code while downloading and runs it on your browser. this means it runs that virus on your pc. that new virus, mines crypto coins on your hardware, and installs itself as windows service, so it runs on every reboot of your computer :)) very clever.. )

so, how to use bass.dll with blazor? :)
@ian must write a webassembly version/port of bass.dll and then, you may use it on browser. but there might be some restrictions on accessing hardware with webassembly.. ian must check them.. but it is not that easy..

so what is webassembly? a native code that can run on browser. there are some standarts how to port your existing native code to webassembly..

there are different webassembly ported native c++ apps. like "ffmpeg" and "lame" encoder. you can use lame as javascript or webassembly.
also check unity games.. when you develop a unity based game, you can export to any platform (mac, windows, android, ios etc), and unity can export your game as webassembly..

maybe, ian might consider porting his great library for webassembly..
when it becomes a webassembly library, you may use it with blazor or javascript.. no matter which one you are using..
then we can develop great audio apps with bass on browser..

you may check https://markheath.net/post/porting-interop-and-webassembly  , it will give you idea on blazor and webassembly and porting existing c++ codes to webassembly(wasm)
« Last Edit: 23 Apr '21 - 14:27 by serkanp »

hungnt

  • Posts: 11
Re: how to add bass.net to blazor web app
« Reply #8 on: 10 May '21 - 15:53 »
Hi serkanp,

Now I have a chance to return to this thread.
I really appreciate it after I finished reading your post. You offer more than that I expected, although to fully understand I need to learn more.

Coming back to my problem, I understand that I don't have the skills to do porting like that. That's why I decided to find another solution:

In the Angular based frontend app, We use the WebRTC library to record audio from the mic, this data is as base64 string blob which is then transmitted to the program on the server via signalr hub. At this program, I use the bass.net library to play back the recorded sound, but it was not successful, the sound emitted a nonsense sound. Below is the code that I write on the server :

1. The code that initialized stream handle
 _recHandle = Bass.BASS_StreamCreatePush(44100, 1, BASSFlag.BASS_SAMPLE_8BITS, IntPtr.Zero);

 EncoderLAME _lame   = new EncoderLAME(_recHandle);           
            _lame.InputFile     = null;
            _lame.OutputFile    = null;
            _lame.LAME_Bitrate  = (int)this._Kbps;
            _lame.LAME_Mode     = EncoderLAME.LAMEMode.Default;
            _lame.LAME_TargetSampleRate = (int)EncoderLAME.SAMPLERATE.Hz_44100;
            _lame.LAME_Quality          = EncoderLAME.LAMEQuality.Quality;
            if (!_lame.EncoderExists) { return -2; }
            encoder = _lame;[/left]
  // now create the ICEcast instance using LAME
            _icecast = new ICEcast(_lame);
            _icecast.ServerAddress = this._server_ip;
            _icecast.ServerPort = this._server_port;
            _icecast.Username = "hungnt";
            _icecast.Password = "mk123456";
            _icecast.MountPoint = "/recording";
            _icecast.StreamName = "StreamName";
            _icecast.StreamGenre = "Test mic";
            _icecast.PublicFlag = true;
            _icecast.SongTitle = "Test mic";

2. the below to decode base64 string audio blob that we received via signalr hub into byte array
byte[] bytes = Convert.FromBase64String(livemodel.AudioBlob);
3. Pass above byte array to stream
Un4seen.Bass.Bass.BASS_StreamPutData(_recHandle,
                                                    arrayByte,
                                                    arrayByte.Length);

Un4seen.Bass.Bass.BASS_ChannelPlay(_recHandle, false);

=> result: the sounds is very noised.

Can you give me some suggestions on this

Best regards,
Hung