Author Topic: BASS.NET API 2.4.12.7  (Read 783438 times)

toob

  • Posts: 133
Re: BASS.NET API 2.4.6.6
« Reply #800 on: 20 Aug '10 - 14:28 »
HELP, Does anyone have an idea what's wrong with this? (bass.net, bass_fx) VB

This is what I want to happen.

1. Play an mp3 (streamFX)
2. Copy 2 seconds of streamFX into copiedclip
3. Pause streamFX
4. Play copiedclip

But I do not hear anything when copiedclip is played.
Any ideas?


---------------------------------------------------------------------
'play sub

Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero)
stream1 = Bass.BASS_StreamCreateFile("groove.mp3", 0, 0, BASSFlag.BASS_STREAM_DECODE)
streamFX = BassFx.BASS_FX_TempoCreate(stream1, BASSFlag.BASS_FX_FREESOURCE)
Bass.BASS_ChannelPlay(streamFX, True)

Music plays fine
While music is playing I run the copy sub below
---------------------------------------------------------------------

'Copy sub

copiedclip = CInt(Bass.BASS_ChannelSeconds2Bytes(streamFX, 2.01))
Dim data(copiedclip / 4 - 1) As Single
copiedclip = Bass.BASS_ChannelGetData(streamFX, data, copiedclip)

copiedclip has data
I then pause the original music, sub below
---------------------------------------------------------------------

'pause streamFX sub

Bass.BASS_ChannelPause(streamFX)

original music paused ok
I then run the play copiedclip sub below
---------------------------------------------------------------------

'play copiedclip

Bass.BASS_ChannelPlay(copiedclip, True)

No sound but copiedclip has data
---------------------------------------------------------------------

stream1, streamFX, copiedclip are all public as Integers

radio42

  • Posts: 4576
Re: BASS.NET API 2.4.6.6
« Reply #801 on: 20 Aug '10 - 16:15 »
'copiedclip' is not a BASS stream handle - so how do you expect to use that with BASS_ChannelPlay!?

You might use "BASS_SampleCreate" or "BASS_StreamCreate" to create a playable stream based on your copied data.

fstarred

  • Posts: 104
Re: BASS.NET API 2.4.6.6
« Reply #802 on: 29 Aug '10 - 02:19 »
Hi all, my purposes to use bass.net is just for

- get wav info (freq, bits and real length) from a byte[] data (because I've already open the file before)
- get the data only, without the header, ever under the byte[] form.
- converto the freq , render to mono and get the byte[] data modified

I don't need to use any callback or play functions.

Before starting (I already tried to be honest but I'm a little stuck  ;D) is bass the right library to do the above things?

Thanks a lot (any help could be really appreciated in case )
« Last Edit: 29 Aug '10 - 02:24 by zenon »

radio42

  • Posts: 4576
Re: BASS.NET API 2.4.6.6
« Reply #803 on: 29 Aug '10 - 08:59 »
Yes, you can do all this with Bass/Bass.Net:

a) get wav info (freq, bits and real length):
See the BASS_ChannelGetInfo method (BASS_CHANNELINFO) to get the 'freq' and 'origres'
See the BASS_ChannelGetLength method to get the 'length'

b) get the data only:
When creating a decoding stream (see BASS_StreamCreateFile using the BASS_STREAM_DECODE flag) you can call BASS_ChannelGetData to get the PCM sample data as a byte[].

c) converto the freq , render to mono:
You can use the BASSmix add-on and create a mono mixer channel with any target freq using BASS_Mixer_StreamCreate.
You can then add the source as created in b) to that mixer via BASS_Mixer_StreamAddChannel and then call BASS_ChannelGetData on that mixer channel to get the converted sample data.

fstarred

  • Posts: 104
Re: BASS.NET API 2.4.6.6
« Reply #804 on: 30 Aug '10 - 00:25 »
radio42 thanks a lot for the quick answer as well as the useful infos!

Maybe I'm close, but things going bad using WaveWriter:

Here's the code, can you tell me please what I'm doing in a odd way?



static void Main(string[] args)
        {
            BASSError bassError;
            GCHandle _hGCFile;

            bool isBassLibLoad = Bass.LoadMe("lib");
            bool isBassMixLibLoad = BassMix.LoadMe("lib");

            // open a file, is stereo 44100Hz
            FileStream fs = File.OpenRead("d:\\melody_space1.wav");
            // get the legth of the file
            long length = fs.Length;
            // create the buffer which will keep the file in memory
            byte[] buffer = new byte[length];
            // read the file into the buffer
            fs.Read(buffer, 0, (int)length);
            // buffer is filled, file can be closed
            fs.Close();

            bool isBassInit = Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);

            // now create a pinned handle, so that the Garbage Collector will not move this object
            _hGCFile = GCHandle.Alloc(buffer, GCHandleType.Pinned);

            // create the stream (AddrOfPinnedObject delivers the necessary IntPtr)
            int handle = Bass.BASS_StreamCreateFile(_hGCFile.AddrOfPinnedObject(), 0L, length, BASSFlag.BASS_STREAM_DECODE);

            bassError = Bass.BASS_ErrorGetCode();

            // get channel info
            BASS_CHANNELINFO bassChannelInfo = Bass.BASS_ChannelGetInfo(handle);

            bassError = Bass.BASS_ErrorGetCode();

            // get raw data
            bool isGetData = Bass.BASS_SampleGetData(handle, buffer);

            // get source sample length
            long sampleLength = Bass.BASS_ChannelGetLength(handle);

            // byte[] of source raw data
            byte[] rawDataBuffer = new byte[sampleLength];

            // retrieve raw data of the source on byte[]
            int channelTotalData = Bass.BASS_ChannelGetData(handle, rawDataBuffer, (int)sampleLength);

            // reset the stream position to 0
            bool isPosGood = Bass.BASS_ChannelSetPosition(handle, 0, BASSMode.BASS_POS_BYTES);

            // this will be the final mixer output stream being played
            int mixer = BassMix.BASS_Mixer_StreamCreate(22100, 1, BASSFlag.BASS_STREAM_DECODE);

//till here everything seems going in the right way

            // add channel to mixer
            bool isMixerGood = BassMix.BASS_Mixer_StreamAddChannel(mixer, handle, BASSFlag.BASS_STREAM_DECODE);

            byte[] convertedBuffer = new byte[sampleLength];

            // total data written to the new byte[] buffer
            int totalDataWritten = Bass.BASS_ChannelGetData(mixer, convertedBuffer, (int)sampleLength);

            WaveWriter waveWriter = new WaveWriter("d:\\test.wav", mixer, true);

            waveWriter.Write(convertedBuffer, totalDataWritten);

            bassError = Bass.BASS_ErrorGetCode();

            bool isBassLibFree = Bass.FreeMe();
            bool isBassMixLibFree = BassMix.FreeMe();

        }



Unfortunately test.wav sounds totally noises.
Nonetheless, seems is double length while playing...

What I'm doing wrong ?  ???

Thankss!!!  :D
I've noticed this works:

WaveWriter waveWriter = new WaveWriter("d:\\test.wav", mixer, true);
            
            short[] data = new short[32768];
            while (Bass.BASS_ChannelIsActive(handle) == BASSActive.BASS_ACTIVE_PLAYING)
            {
                int length = Bass.BASS_ChannelGetData(mixer, data, 32768);
                if (length > 0)
                    waveWriter.Write(data, length);
            }

//this doesn't work but I don't know why :P
            //waveWriter.Write(convertedBuffer, totalDataWritten);

            waveWriter.Close()



Also I've noticed row

while (Bass.BASS_ChannelIsActive(handle) == BASSActive.BASS_ACTIVE_PLAYING)

I must put the original stream handle instead of mixer, because this last one loop infinitely.. why?

Finally, is there another way to get the real sample length for >8bit and stereo?

because everytime I have to check these properties and the divide by 2 or 4
(it's not a so much critical situation I know :P)

Thanks !!!
« Last Edit: 30 Aug '10 - 00:51 by zenon »

radio42

  • Posts: 4576
Re: BASS.NET API 2.4.6.6
« Reply #805 on: 30 Aug '10 - 11:28 »
Quote
while (Bass.BASS_ChannelIsActive(handle) == BASSActive.BASS_ACTIVE_PLAYING)
A mixer channel has no real end as it is kind of continous.
But BASS_ChannelGetData on a mixer channel would return 0 (or -1 in case of an error) - which can be used to end the while loop.
Somwthing like:
Code: [Select]
while (true)
{
    int length = Bass.BASS_ChannelGetData(mixer, data, 32768);
    if (length > 0)
        waveWriter.Write(data, length);
    else
        break;
}

vasaka

  • Posts: 5
Re: BASS.NET API 2.4.6.6
« Reply #806 on: 3 Sep '10 - 23:16 »
Hi, I'm having a problem with opening WMA stream.

Code: [Select]
        static void Main(string[] args)
        {
            Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
            var plg = Bass.BASS_PluginLoad("basswma.dll");
            var radioChannel = Bass.BASS_StreamCreateURL("http://78.46.54.158:1146", 0,
                               BASSFlag.BASS_DEFAULT, null, IntPtr.Zero);
            Bass.BASS_ChannelPlay(radioChannel, false);
            Console.ReadKey();
        }
It doesn't work. However, netradio from basswm24 plays it well, although it writes HTTP/1.0 400 BAD REQUEST.

ken

  • Posts: 739
Re: BASS.NET API 2.4.6.6
« Reply #807 on: 5 Sep '10 - 18:48 »
Hi Bernd!

I have some issues with WaveForm and WASAPI, the position of "playline" is not in sync as when using BASS only

I init Wasapi like this:
Code: [Select]
Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 0);
Bass.BASS_Init(-1, _MixFreq, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
_mixer = BassMix.BASS_Mixer_StreamCreate(_MixFreq, 2, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_MIXER_NONSTOP | BASSFlag.BASS_MIXER_POSEX);
_BassWasapiHandlerOut = new BassWasapiHandler(_DeviceID, false, _MixFreq, 2, 0.2F, 0);

bool _retInit = _BassWasapiHandlerOut.Init();
Bass.BASS_PluginLoad("basswma.dll");
Bass.BASS_PluginLoad("bass_aac.dll");

Start play like this:
Code: [Select]
_stream = Bass.BASS_StreamCreateFile(_Filename, 0, 0, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE);
BassMix.BASS_Mixer_StreamAddChannel(_mixer, _stream, BASSFlag.BASS_STREAM_AUTOFREE);

WF.SyncPlayback(_stream);
Bass.BASS_ChannelSetPosition(_stream, StartCue.TotalSeconds);



Waveform is drawn like your "Simple" example. For regular BASS I use _deviceLatencyBytes=0. For WASAPI I tested with:

Code: [Select]
_deviceLatencyBytes = (int)Bass.BASS_ChannelSeconds2Bytes(_stream, 0.2F);

Any suggestion on how to do it correct, code?

/Ken

radio42

  • Posts: 4576
Re: BASS.NET API 2.4.6.6
« Reply #808 on: 6 Sep '10 - 12:56 »
Are you using BASS_ChannelGetPosition or BASS_Mixer_ChannelGetPosition to draw the position line?

ken

  • Posts: 739
Re: BASS.NET API 2.4.6.6
« Reply #809 on: 6 Sep '10 - 17:02 »
Are you using BASS_ChannelGetPosition or BASS_Mixer_ChannelGetPosition to draw the position line?

Ahh, thats right. I tried some and this looks like it works, is it correct to use?
Code: [Select]
long pos = BassMix.BASS_Mixer_ChannelGetPositionEx(_stream, BASSMode.BASS_POS_BYTES, (int)Bass.BASS_ChannelSeconds2Bytes(_stream, 0.2F));

radio42

  • Posts: 4576
Re: BASS.NET API 2.4.6.6
« Reply #810 on: 6 Sep '10 - 17:39 »
yep

ken

  • Posts: 739
Re: BASS.NET API 2.4.6.6
« Reply #811 on: 7 Sep '10 - 10:50 »
Bernd,

I play some channels added to a mixer. (Wasapi)

Shall I use Bass.BASS_ChannelSetSync or BassMix.BASS_Mixer_ChannelSetSync ? 

Now I use BASS_ChannelSetSync, it works but sometimes this sync don't execute (end of file):
Code: [Select]
Bass.BASS_ChannelSetSync(_channel1, BASSSync.BASS_SYNC_END, 0, _Sync, new IntPtr(1)); //End of File


/Ken

ken

  • Posts: 739
Re: BASS.NET API 2.4.6.6
« Reply #812 on: 8 Sep '10 - 10:36 »
Bernd,

More problems, this time with WaveForm and recording.  I "record" from a WASAPI channel. In short just add an encoder and start/stop that. That works fine, but when I add WF I get problems. WF is rendering as it should, but when I stop it hangs.

First this is how I init WASAPI
Code: [Select]

Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 0);
Bass.BASS_Init(-1, audioDevOut.MixFreq, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);

_mixer = BassMix.BASS_Mixer_StreamCreate(_MixFreq, 2, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_MIXER_NONSTOP | BASSFlag.BASS_MIXER_POSEX);

_BassWasapiHandlerOut = new BassWasapiHandler(_DeviceID, false, _MixFreq, 2, 0.2F, 0);

_BassWasapiHandlerOut.Init();

_BassWasapiHandlerOut.AddOutputSource(_mixer, BASSFlag.BASS_DEFAULT);

_BassWasapiHandlerOut.Start();



if (_BassWasapiHandlerIn != null)
   _BassWasapiHandlerIn.Stop();

   _BassWasapiHandlerIn = new BassWasapiHandler(_DeviceID, false, _MixFreq, 2, 0f, 0f);
   if (_BassWasapiHandlerIn.Init())
   {
      _recordStream = _BassWasapiHandlerIn.InputChannel;
_BassWasapiHandlerIn.Start();
   }




Start "recording" encoding to file.
Code: [Select]

private WaveForm _waveForm = null;
private BaseEncoder _BaseEncoder;
private DSPPROC _recDSP;

private StartRec()
{
EncoderTooLAME _tooLame = new EncoderTooLAME(_recordStream);
_tooLame.InputFile = null;
_tooLame.OutputFile = _FileName;
_tooLame.TOO_Bitrate = BitRate;
_tooLame.Start(null, IntPtr.Zero, false);

_BaseEncoder = _tooLame;

_waveForm = new WaveForm();
_waveForm.FrameResolution = 0.002f;
_waveForm.CallbackFrequency = 0;

_recDSP = new DSPPROC(recDSPCallback);
_recDSP = Bass.BASS_ChannelSetDSP(_recordStream, _recDSP, IntPtr.Zero, 0);

_waveForm.RenderStartRecording(_recordStream, 5f, 5f);

}



Callback
Code: [Select]

private void vtrecDSPCallback(int handle, int channel, IntPtr buffer, int length, IntPtr user)
{
           
     if (length > 0 && buffer != IntPtr.Zero)
     {
        _waveForm.RenderRecording(buffer, length);
        DrawWaveRec();
     }
}

DrawWaveRec()
{
    image = _waveForm.CreateBitmap(500, 75, -1, -1, false);
}




Stop Recording
Code: [Select]

_BaseEncoderMixer.Stop();  // hangs here, but only if I use WaveForm!!
_BaseEncoderMixer.Dispose();
_BaseEncoderMixer = null;


_waveForm.RenderStopRecording();
DrawWaveRec();



Any ideas?

/Ken

radio42

  • Posts: 4576
Re: BASS.NET API 2.4.6.7
« Reply #813 on: 10 Sep '10 - 13:15 »
10.09.2010: Version 2.4.6.7 is out!

Support for all latest BASS versions added
General:
  - WaveForm: gradient drawing bug-fic
  - WaveForm: DrawCenterLine property added

Full Install:
  www.un4seen.com/filez/4/Bass24.Net.zip

Lib only:
  www.un4seen.com/filez/4/Bass24.Net_update.zip


mario222

  • Posts: 46
Re: BASS.NET API 2.4.6.5
« Reply #814 on: 12 Sep '10 - 09:05 »
Here is a little helper class you might use to determine where/what you have 'clicked' with your mouse[...]

Hi Bernd. Can you please provide a vb.net version of the class? I'm stuck at this line:
Code: [Select]
public WaveFormObjectType HitObjectType = WaveFormObjectType.LowerHalf;In vb.net this should be:
Code: [Select]
Public HitObjectType As WaveFormObjectType = WaveFormObjectType.LowerHalfBut i get a "WaveFormObjectType is not defined" error

Thank you very much,
Marius.

radio42

  • Posts: 4576
Re: BASS.NET API 2.4.6.7
« Reply #815 on: 12 Sep '10 - 19:37 »
I am actually no VB.Net gus - so maybe someoneelse can jump in.

Dermot

  • Posts: 12
Re: BASS.NET API 2.4.6.7
« Reply #816 on: 13 Sep '10 - 01:09 »
Using Bass.net.dll/Bass.dll (both latest of post) to stream, having a issue with app crashing after char count goes over 64 in taginfo

C# vs 2010 windows 7 professional 64 bit

Cause..

Code: [Select]
private void MetaSync(int handle, int channel, int data, IntPtr user)
        {
            // BASS_SYNC_META is triggered on meta changes of SHOUTcast streams
            if (_tagInfo.UpdateFromMETA(Bass.BASS_ChannelGetTags(channel, BASSTag.BASS_TAG_META), false, true))
            {
                this.Invoke(new UpdateTagDelegate(UpdateTagDisplay));
            }
        }

Error is..

Code: [Select]
System.ArgumentOutOfRangeException was unhandled
  Message=Text length must be less than 64 characters long.
Parameter name: Text
Actual value was Brought to you by Santrex.net - Far Away Feat Tiff Lacey (Adam Nickey Mix).
  Source=System.Windows.Forms
  ParamName=Text
  StackTrace:
       at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
       at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
       at System.Windows.Forms.Control.Invoke(Delegate method)
       at Tunes.Form1.MetaSync(Int32 handle, Int32 channel, Int32 data, IntPtr user) in C:\Users\New User\documents\visual studio 2010\Projects\Tunes\Tunes\Form1.cs:line 175

This causes app to hang and crash.

line 175 is this.Invoke(new UpdateTagDelegate(UpdateTagDisplay));

Any way to either stop the 64 char limit or work around it.
 

radio42

  • Posts: 4576
Re: BASS.NET API 2.4.6.7
« Reply #817 on: 13 Sep '10 - 10:32 »
Could it be, that it is not Bass.Net but your code which causes the exception?!
E.g. a textboc, label etc. has the text ,imit property set to 64 - as Bass.Net doesn't have any 64 char limit.

As you said, the exception is thrown at line 175, which is:
Code: [Select]
    this.Invoke(new UpdateTagDelegate(UpdateTagDisplay));And this means the previous lines already succeeded without any exception ;-)

Dermot

  • Posts: 12
Re: BASS.NET API 2.4.6.7
« Reply #818 on: 14 Sep '10 - 18:21 »

the textbox max char limit is set to 150

So i'm not sure where it is getting this limit from, could it be bass.dll?

maybe ian might have an idea why it's springing this exception, kinda stumped me at present.

Markus

  • Guest
ALSA lib pcm_dmix.c:1008:(snd_pcm_dmix_open) unable to open
« Reply #819 on: 14 Sep '10 - 19:02 »
Hello,

I have following problem:

I have to sound cards (onBoard + Delta LT 1010).
In my application, I will init the devices on start-up:

Code: [Select]
Bass.BASS_Init(device1, frequency, BASSInit.BASS_DEVICE_LATENCY, handle) // Delta
Bass.BASS_Init(device2, frequency, BASSInit.BASS_DEVICE_LATENCY, handle) // onBoard

When I exit the app, I will free the devices:

Code: [Select]
Bass.BASS_SetDevice(device1); // Delta
Bass.BASS_Free();

Bass.BASS_SetDevice(device2); // onBoard
Bass.BASS_Free();

That works fine for the first start. When I will start the app again, i get following error:
(it's always the onBoard device)

Code: [Select]
ALSA lib pcm_dmix.c:1008:(snd_pcm_dmix_open) unable to open
Bass.BASS_ErrorGetCode() returns BASS_ERROR_NOTAVAIL


When I logout an re-login, then it works. But only once.
I'm using Mono 2.4. on Ubuntu 9.10

Thx
Markus

Dermot

  • Posts: 12
Re: BASS.NET API 2.4.6.7
« Reply #820 on: 14 Sep '10 - 19:56 »

Seems to be similar to this old bug in the framework that went unanswered

http://social.msdn.microsoft.com/forums/en-US/netfxcompact/thread/0cb91458-23b7-480c-8d0b-cdc24a824d20


radio42

  • Posts: 4576
Re: BASS.NET API 2.4.6.7
« Reply #821 on: 14 Sep '10 - 23:39 »
@Markus
take a look to the end of the Linux thread guess someone had the same problem

Markus

  • Guest
Re: BASS.NET API 2.4.6.7
« Reply #822 on: 15 Sep '10 - 08:41 »
@Ian: Now it looks good.

I removed the pulseaudio package:

Code: [Select]
sudo apt-get remove pulseaudio
.. and now it's working :-)

vasaka

  • Posts: 5
Re: BASS.NET API 2.4.6.6
« Reply #823 on: 15 Sep '10 - 20:36 »
Hi, I'm having a problem with opening WMA stream.

Code: [Select]
        static void Main(string[] args)
        {
            Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
            var plg = Bass.BASS_PluginLoad("basswma.dll");
            var radioChannel = Bass.BASS_StreamCreateURL("http://78.46.54.158:1146", 0,
                               BASSFlag.BASS_DEFAULT, null, IntPtr.Zero);
            Bass.BASS_ChannelPlay(radioChannel, false);
            Console.ReadKey();
        }
It doesn't work. However, netradio from basswm24 plays it well, although it writes HTTP/1.0 400 BAD REQUEST.
Problem still doesn't solved. Can someone help me, please?
BASS_ErrorGetCode() returns BASS_ERROR_HANDLE.

Dermot

  • Posts: 12
Re: BASS.NET API 2.4.6.7
« Reply #824 on: 16 Sep '10 - 00:43 »

Just a follow up, i fixed the issue after i found it was the notify icon text field (tooltip) is limited to 64 characters in C#

I had the song name and artist showing on it, and thus was springing the exception.

So just changed it to a optional balloon and all working now, thanks.