22 May '13 - 01:23 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Reply  |  Print  
Author Topic: .net wrapper  (Read 843 times)
BulleTTime
Posts: 28


« on: 21 Feb '12 - 19:10 »
Reply with quoteQuote

I would like to create a basic little .net wrapper to easily stream internet radio's. It needs to be .Net 2.0.The initalize works, However when i start BASS_ChannelPlay i basicly hear some sound, but VERY jerky and crackling. What goes wrong?

My code:



using UnityEngine;
using System.Collections;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime;
using System.Runtime.InteropServices;
public class bass : MonoBehaviour {

public enum flags {
BASS_DEFAULT
}

public enum configs {
BASS_CONFIG_NET_PLAYLIST
}
[DllImport("bass.dll")]
public static extern bool BASS_Init(int device, int freq, int flag,IntPtr hwnd, IntPtr clsid);

[DllImport("bass.dll")]

public static extern bool BASS_SetConfig(configs config,int valuer);

[DllImport("bass.dll")]

public static extern Int32 BASS_StreamCreateURL(string url,int offset,flags flag);

[DllImport("bass.dll")]
public static extern bool BASS_ChannelPlay(int steam,bool restart);

[DllImport("bass.dll")]
public static extern bool BASS_StreamFree(int stream);

[DllImport("bass.dll")]
public static extern bool BASS_Free();

private int stream;


void Start () {


if ( BASS_Init(-1, 44100,0,IntPtr.Zero, IntPtr.Zero) ) {  //works

BASS_SetConfig(configs.BASS_CONFIG_NET_PLAYLIST,2);

stream = BASS_StreamCreateURL("http://91.121.149.200:8100/",0,flags.BASS_DEFAULT);


if (stream != 0) { //works
BASS_ChannelPlay(stream, false);
}
}

}

void OnApplicationQuit() {

BASS_StreamFree(stream);
BASS_Free();

}


« Last Edit: 21 Feb '12 - 19:16 by BulleTTime » Logged
Ionut Cristea
Posts: 1374


« Reply #1 on: 21 Feb '12 - 20:35 »
Reply with quoteQuote

  I believe in .NET you should use unicode strings so BASS_UNICODE flag should be added at stream creation?
Logged
BulleTTime
Posts: 28


« Reply #2 on: 22 Feb '12 - 12:30 »
Reply with quoteQuote

i tried that, but still i hear a faltering sound. What else might be wrong Huh
Logged
radio42
Posts: 4012


« Reply #3 on: 22 Feb '12 - 14:04 »
Reply with quoteQuote

Sounds like it wouldn't have anything to do with your .Net wrapper, but might be any other general issue, e.g. with your network connection, buffer settings etc.?!
Logged
Ian @ un4seen
Administrator
Posts: 15259


« Reply #4 on: 22 Feb '12 - 15:41 »
Reply with quoteQuote

Yep. The URL (http://91.121.149.200:8100/) is a high bitrate stream (320kbit/s), and perhaps it's too high for the connection speed? Are you able to play the stream without problem in other software? When you say it's "jerky and crackling", do you mean playback keeps stopping and starting, or do you actually hear crackling noises? If the latter, do you hear the same when playing local files, eg. with the pre-compiled examples in the C\BIN directory?
Logged
BulleTTime
Posts: 28


« Reply #5 on: 22 Feb '12 - 16:24 »
Reply with quoteQuote

Yes, the url works fine with the .Net wrapper from http://bass.radio42.com/. Also it works fine within any browser.
So It might be that one of these settings for BASS_Init or BASS_StreamCreateURL are wrong?

When i try to stream a single mp3 file, i hear the same kind of sound.

Also yes, it seems that the playback keeps stopping and starting, realy faltering.

Any idea?
« Last Edit: 22 Feb '12 - 16:33 by BulleTTime » Logged
Ian @ un4seen
Administrator
Posts: 15259


« Reply #6 on: 22 Feb '12 - 16:41 »
Reply with quoteQuote

Looking again, I think the problem is the value of BASS_CONFIG_NET_PLAYLIST. That should be 21, but it looks like it would be 0 in the code above, in which case the BASS_SetConfig call is actually setting the BASS_CONFIG_BUFFER option to 2 instead, which would explain the problem you describe.
Logged
BulleTTime
Posts: 28


« Reply #7 on: 22 Feb '12 - 20:17 »
Reply with quoteQuote

Nope its not the config. I tried to set it to 21 and also removed it. Still i hear the same kind of sound, also with a single streamed mp3.

Actually the buffer length is set to 101, i guess default.

So but, is it good to leave parameters away or do i need to set all parameters of the BASS_StreamCreateURL and BASS_Init functions?
Logged
Ian @ un4seen
Administrator
Posts: 15259


« Reply #8 on: 23 Feb '12 - 15:19 »
Reply with quoteQuote

Are you sure you have defined BASS_CONFIG_NET_PLAYLIST as 21? If so, are you using any other config options too? The default BASS_CONFIG_BUFFER setting is 500ms, so if you're seeing it as 101ms, then that means it has been changed in a BASS_SetConfig call. Note it has a minimum of BASS_CONFIG_UPDATEPEROID+1 and BASS_CONFIG_UPDATEPEROID defaults to 100ms, hence you end up with 101ms when trying to set anything lower (like 2 in the code above).
Logged
BulleTTime
Posts: 28


« Reply #9 on: 23 Feb '12 - 16:23 »
Reply with quoteQuote

Yes, with further inspection i noticed that the BASS_SetConfig is indeed changing the the Buffer Length.

When i remove the following code, streaming works. Note that i dont use any other config settings.


BASS_SetConfig(configs.BASS_CONFIG_NET_PLAYLIST,21);


Why would it change the buffer length instead of the CONFIG_NET_PLAYLIST? Perhaps the enum issnt right? When i set the Buffer to 500 it still got set to 101..
« Last Edit: 23 Feb '12 - 16:26 by BulleTTime » Logged
Ian @ un4seen
Administrator
Posts: 15259


« Reply #10 on: 23 Feb '12 - 17:51 »
Reply with quoteQuote

The problem is the BASS_CONFIG_NET_PLAYLIST definition, here:

public enum configs {
BASS_CONFIG_NET_PLAYLIST
}

That needs to be changed to this...

public enum configs {
BASS_CONFIG_NET_PLAYLIST=21
}

I would suggest using BASS.Net instead of trying to create your own .Net wrapper. It'll save you a lot of time and effort Smiley
Logged
BulleTTime
Posts: 28


« Reply #11 on: 24 Feb '12 - 19:45 »
Reply with quoteQuote

Thanks.

I cant use the .net wrapper because it uses parts of code some parts are ambiguous with Unity System.Core. Because of this i cant use BassNet to register it.

I'll try the config stuff, see what happens ill let u know.
actaly, how would i able to change the value if its defined. I cant change the setting at runtime. Any idea? is a enum the right thing to use?
Logged
BulleTTime
Posts: 28


« Reply #12 on: 24 Feb '12 - 20:34 »
Reply with quoteQuote

Alright , it seems to work all. Thanks Smiley
Logged
crawler
Posts: 1


« Reply #13 on: 28 Jan '13 - 15:33 »
Reply with quoteQuote

Hello! I'm using BulleTTime's code to stream internet radio's. In the Unity Editor it works fine. Thanks very much.
But when I run windows standalone exe it crashes.

Could anyone help me please?



Output log:
Quote
========== OUTPUTING STACK TRACE ==================

 (0x0018F3BC) ((module-name not available)): (filename not available): (function-name not available)

 ========== END OF STACKTRACE ===========

 **** Crash! **
Logged
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.18 | SMF © 2013, Simple Machines