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

speed21

  • Posts: 3
Re: BASS.NET API 2.4.10.3
« Reply #1225 on: 20 Nov '13 - 14:29 »
Hello evereyone

I have a problem with the bass.net on my internet stream releated program.

I start the playback in a new thread everthing works fine except when i quickly click on play twice it loads two same streams and when i click stop i stops just the first, have no idea how to fix this i tried everthing

This is the code where i start the thread it is on the play button

Code: [Select]
countThread = New Threading.Thread(New Threading.ThreadStart(AddressOf irp_play))
        countThread.IsBackground = True
        countThread.Start()

and in the irp_play sub is the bass.dll code for loading and playing the stream

Note: It happens only when i fast click twice the play button

radio42

  • Posts: 4576
Re: BASS.NET API 2.4.10.3
« Reply #1226 on: 21 Nov '13 - 12:38 »
That doesn't sound like a Bass.Net issue, but more like a general coding issue.

To overcome your issue, you need to prevent starting a 2nd thread in parallel while the first one is already starting/running.
So a simple synchronization pattern might help.
Here is some help:
http://msdn.microsoft.com/en-us/library/ms173179(v=vs.110).aspx

Code: [Select]
private volatile bool _executing;

private void DoWork()
{
    if (_executing)
        return;

    _executing = true;

    // start you thread here
    ....
}

private void ThreadRunFunc()
{
    try
    {
        // do your work here
        ....
    }
    finally
    {
        _executing = false;
    }
}

ken

  • Posts: 739
Re: BASS.NET API 2.4.10.3
« Reply #1227 on: 25 Dec '13 - 11:09 »
Hi Bernd,

I'm trying to push data over TCP, with "BASS_ChannelGetData", and "BASS_StreamPutData" and it works kind of... But I want an Encoder on the recording side, but I can't get it working. Am I doing right here?

This example records and plays on the same application, just sending byte Array from "Recoder" to "Player", it works (with studdering sound) when using the "RecordingHandler" but not via "EncodingWriter"

Code: [Select]

 private RECORDPROC _recProc;
 private ENCODEPROC _myEndoderProc;
 private byte[] _encbuffer = new byte[1048510]; // 1MB buffer
 int _recHandle = 0;
 int _playHandle = 0;

private void InitBass()
        {
            Bass.BASS_Free();
            Bass.BASS_RecordFree();

            //Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_REC_BUFFER, 5000);
            //Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_BUFFER, 5000);


            Bass.BASS_Init(cmbAudioDevicesOut.SelectedIndex - 1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);


            Console.Write("** Bass_Init OK! " + Bass.BASSVERSION);

            bool _recOK = Bass.BASS_RecordInit(cmbAudioDevicesIn.SelectedIndex - 1);

            if (_recOK)
            {
                _recProc = new RECORDPROC(RecordingHandler);
                _recHandle = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_RECORD_PAUSE, _recProc, IntPtr.Zero);

                Console.WriteLine("_recHandle: " + _recHandle);

                _myEndoderProc = new ENCODEPROC(EncodingWriter);

                EncoderLAME _EncoderLAME = new EncoderLAME(_recHandle);
                _EncoderLAME.LAME_Bitrate = 320;
                _EncoderLAME.InputFile = null;
                _EncoderLAME.OutputFile = null;
                _EncoderLAME.LAME_UseVBR = false;
                _EncoderLAME.LAME_TargetSampleRate = 44100;
                _EncoderLAME.LAME_Mode = EncoderLAME.LAMEMode.Default;
                _EncoderLAME.Start(_myEndoderProc, IntPtr.Zero, false);


                Bass.BASS_ChannelPlay(_recHandle, false);


            }

            //Playback the data array
            Bass.BASS_StreamFree(_playHandle);

            _playHandle = Bass.BASS_StreamCreatePush(44100, 2, BASSFlag.BASS_DEFAULT, IntPtr.Zero);

            Bass.BASS_ChannelPlay(_playHandle, false);

            Console.WriteLine("_playHandle: " + _playHandle);

           
        }

private bool RecordingHandler(int handle, IntPtr buffer, int length, IntPtr user)
{
            Byte[] _data = new Byte[length];
            Bass.BASS_ChannelGetData(_recHandle, _data, _data.Length);

            SendData(_data);  //This works (with some stuttering in the sound)

            return true;
}


private void EncodingWriter(int handle, int channel, IntPtr buffer, int length, IntPtr user)
{
           
           Marshal.Copy(buffer, _encbuffer, 0, length);
   
         // SendData(_encbuffer);  //This I'm not sure...

}

private void SendData(byte[] data)
{
   Bass.BASS_StreamPutData(_playHandle, data, data.Length);
}



/Ken

radio42

  • Posts: 4576
Re: BASS.NET API 2.4.10.3
« Reply #1228 on: 26 Dec '13 - 18:54 »
When method are you using on the 'receiving' side?
Note, that you should use BASS_StreamCreateFileUser when using an encoder but BASS_StreamCreate when using raw PCM sample data.

ken

  • Posts: 739
Re: BASS.NET API 2.4.10.3
« Reply #1229 on: 26 Dec '13 - 20:09 »
When method are you using on the 'receiving' side?
Note, that you should use BASS_StreamCreateFileUser when using an encoder but BASS_StreamCreate when using raw PCM sample data.

The code is just for testing the concept, I'm shuffling data internal in one app.

Yes I figured that BASS_StreamPutData only handle PCM and not my encoded data array.  Is there a "Decoder" I can use, or is there another why to play a MP3 encoded data array, maybe some simple C# to get me started...?

/Ken

ken

  • Posts: 739
Re: BASS.NET API 2.4.10.3
« Reply #1230 on: 8 Jan '14 - 09:05 »
Hi,

I have problem converting some audio from iTunes (m4a). I can play the audio, the encoder return true and shows progress (a bit faster than normal), but I get no output file. I tested convert to OGG, MP3, OPUS and WMA. For some reson convert to WMA always work even when the others fail.



Here is how I convert:

Code: [Select]

//OGG
EncoderOGG _ogg = new EncoderOGG(0);
_ogg.OGG_Bitrate = bitRate;
_ogg.OGG_UseQualityMode = false;

 _ret = BaseEncoder.EncodeFile(inpFile, outputFile, _ogg, new BaseEncoder.ENCODEFILEPROC(FileEncodingNotification), true, false, true);


//OPUS
EncoderOPUS _opus = new EncoderOPUS(0);
_opus.OPUS_Bitrate = bitRate;
_opus.OPUS_Mode = EncoderOPUS.OPUSMode.CBR;

_ret = BaseEncoder.EncodeFile(inpFile, outputFile, _opus, new BaseEncoder.ENCODEFILEPROC(FileEncodingNotification), true, false, true);


//WMA
EncoderWMA _wma = new EncoderWMA(0);
_wma.WMA_Bitrate = bitRate;

_ret = BaseEncoder.EncodeFile(inpFile, outputFile, _wma, new BaseEncoder.ENCODEFILEPROC(FileEncodingNotification), true, false, true);


public void FileEncodingNotification(long bytesTotal, long bytesDone)
{

     double _prog = Math.Round((double)bytesDone / (double)bytesTotal, 2);

      Console.WriteLine(_prog  + "%");
 }



I have the lastest version of all Bass. Have also tested using with our without BASS_PluginLoad("bass_aac.dll")  after BASS_Init

/Ken

 

radio42

  • Posts: 4576
Re: BASS.NET API 2.4.10.3
« Reply #1231 on: 8 Jan '14 - 14:15 »
I would have no idea what might be causing this...

ken

  • Posts: 739
Re: BASS.NET API 2.4.10.3
« Reply #1232 on: 8 Jan '14 - 20:39 »
I would have no idea what might be causing this...

Ok... Can I send the audiofiles to Ian? I need this working.

/Ken

Simulator

  • Posts: 32
Re: BASS.NET API 2.4.10.3
« Reply #1233 on: 9 Jan '14 - 06:47 »
Hello guys,

I'm using the latest BASS.NET API 2.4.10.3 (or even tried the pre BASS.NET API 2.4.10.4 version) with the latest bass.dll and wasapi dll. I can still confirm the issue with the BASS_RecordGetInput. I tried it on several computers, but it always returns null. Here is my simple code snippet:

Code: [Select]
   
           Bass.BASS_RecordInit(-1)
            Dim n As Integer = 0
            Dim name As String = ""

            While Not (name Is Nothing)
                name = Bass.BASS_RecordGetInputName(n)
                n += 1

                If Not (name Is Nothing) Then
                    MessageBox.Show(name)
                    Dim vol As Single = 0.0F
                    Dim setting As Integer = Bass.BASS_RecordGetInput(n, vol)
                    Debug.Print("{0} [{1} : {2}] - {3}",
                                      name,
                                      CType(CInt(BASSInputType.BASS_INPUT_TYPE_MASK) And setting, BASSInputType),
                                      vol,
                                      CStr(IIf(CInt(BASSInput.BASS_INPUT_OFF) And setting <> 0, "Off", "On")))
                End If
            End While

Will there be any solution for this?

radio42

  • Posts: 4576
Re: BASS.NET API 2.4.10.3
« Reply #1234 on: 9 Jan '14 - 08:42 »
You code isn't using any WASAPI stuff...can you explain what you are trying to achieve?
Have you tried using "BASS_RecordGetInputNames()"?

Simulator

  • Posts: 32
Re: BASS.NET API 2.4.10.3
« Reply #1235 on: 9 Jan '14 - 09:38 »
First I listed all the input devices:

Code: [Select]
Dim wasapiDevices As BASS_WASAPI_DEVICEINFO() = BassWasapi.BASS_WASAPI_GetDeviceInfos()

                For i As Integer = 0 To wasapiDevices.Length - 1
                    Try
                        If Not wasapiDevices(i).IsEnabled Then
                            wasapiDevices(i).name = "ERROR N/A: " + wasapiDevices(i).name
                        Else

                            If wasapiDevices(i).IsInput = True And wasapiDevices(i).IsLoopback = False Then
                                Accounts.Add(New AccountNameKeyPair(wasapiDevices(i).name, i))

                            End If
                        End If


                    Catch ex As Exception
                        Debug.Print("Hiba: " & ex.ToString)
                    End Try
                Next

Then I put it into a combobox, then select one and I want to start record on it. I read that I should select the endpoint of it, that's why I wanted to list it. Am I correct?

radio42

  • Posts: 4576
Re: BASS.NET API 2.4.10.3
« Reply #1236 on: 9 Jan '14 - 10:47 »
I guess you are mixing two different driver models: WDM/DirectSound and WASAPI.
Recording from WASAPI doesn't have anything to do with the "Bass.BASS_Recordxxx" functions.
The "Bass.BASS_Recordxxx" functions are only used when using WDM/DirectSound!

Simulator

  • Posts: 32
Re: BASS.NET API 2.4.10.3
« Reply #1237 on: 9 Jan '14 - 12:35 »
Okey, my mistake, sorry. Is there any example for this code, how to record anything to a wav file?

Code: [Select]
Dim wasapiDevices As BASS_WASAPI_DEVICEINFO() = BassWasapi.BASS_WASAPI_GetDeviceInfos()

                For i As Integer = 0 To wasapiDevices.Length - 1
                    Try
                        If Not wasapiDevices(i).IsEnabled Then
                            wasapiDevices(i).name = "ERROR N/A: " + wasapiDevices(i).name
                        Else

                            If wasapiDevices(i).IsInput = True And wasapiDevices(i).IsLoopback = False Then
                                Accounts.Add(New AccountNameKeyPair(wasapiDevices(i).name, i))

                            End If
                        End If


                    Catch ex As Exception
                        Debug.Print("Hiba: " & ex.ToString)
                    End Try
                Next

Ian @ un4seen

  • Administrator
  • Posts: 20436
Re: BASS.NET API 2.4.10.3
« Reply #1238 on: 9 Jan '14 - 16:19 »
Ok... Can I send the audiofiles to Ian? I need this working.

Is the problem affecting both the BASS_AAC and Media Foundation decoders? If so, please see if you can reproduce it with BASSenc's pre-compiled CONTEST.EXE example (in C\BIN folder). If it does happen with that too, then please upload an example troublesome file to have a look at here...

   ftp.un4seen.com/incoming/

Also confirm what Windows version you're using, in case it's version-specific.

Simulator

  • Posts: 32
Re: BASS.NET API 2.4.10.3
« Reply #1239 on: 10 Jan '14 - 08:19 »
Sorry Ian, can you help with some sample. And I have an another problem. If I list the endpoints with my code, if there is some UTF8 chars in it (like ő,ű,,,), then it will be displayed as ?.

Is there any way to fix it?

Okey, my mistake, sorry. Is there any example for this code, how to record anything to a wav file?

Code: [Select]
Dim wasapiDevices As BASS_WASAPI_DEVICEINFO() = BassWasapi.BASS_WASAPI_GetDeviceInfos()

                For i As Integer = 0 To wasapiDevices.Length - 1
                    Try
                        If Not wasapiDevices(i).IsEnabled Then
                            wasapiDevices(i).name = "ERROR N/A: " + wasapiDevices(i).name
                        Else

                            If wasapiDevices(i).IsInput = True And wasapiDevices(i).IsLoopback = False Then
                                Accounts.Add(New AccountNameKeyPair(wasapiDevices(i).name, i))

                            End If
                        End If


                    Catch ex As Exception
                        Debug.Print("Hiba: " & ex.ToString)
                    End Try
                Next

Simulator

  • Posts: 32
Re: BASS.NET API 2.4.10.3
« Reply #1240 on: 10 Jan '14 - 09:40 »
Okey, I figered it out.

Code: [Select]
   Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UNICODE, True)

My only question is now, how to record anything with wasapi from an input device :)

ken

  • Posts: 739
Re: BASS.NET API 2.4.10.3
« Reply #1241 on: 10 Jan '14 - 21:37 »
Ok... Can I send the audiofiles to Ian? I need this working.

Is the problem affecting both the BASS_AAC and Media Foundation decoders? If so, please see if you can reproduce it with BASSenc's pre-compiled CONTEST.EXE example (in C\BIN folder). If it does happen with that too, then please upload an example troublesome file to have a look at here...

   ftp.un4seen.com/incoming/

Also confirm what Windows version you're using, in case it's version-specific.

Hi,

CONTEST.EXE plays the file and that I can do without problem in my program too. The problem is that I can not convert the file to OGG (WMA works). Windows 7 64bit, but the code is compiled for 32bit.

/Ken

rv

  • Posts: 192
Re: BASS.NET API 2.4.10.3
« Reply #1242 on: 12 Jan '14 - 09:51 »
Hello,

Where did you find this feature ?

http://www.bass.radio42.com/help/html/9d82cc1a-9ac0-3ff6-a599-9dd1dc898938.htm

I don't see it in Bass_VST.dll

radio42

  • Posts: 4576
Re: BASS.NET API 2.4.10.3
« Reply #1243 on: 20 Jan '14 - 20:40 »
That is/was an additional feature which I discussed and implemented with the previous VST developer.
It adds a plugin state save/restore feature for plugins which use the binary chuck mode to save and restore their state.
I am currently in contact with BassHead to add that to his latest version as well.
So far these function can not be used, but they will be added soon to BASS_VST...so pls stand-by...

rv

  • Posts: 192
Re: BASS.NET API 2.4.10.3
« Reply #1244 on: 21 Jan '14 - 08:36 »
You are right, we need this feature for a SAVE/RESTORE of VST plugin state.

a2ngsa

  • Posts: 26
Re: BASS.NET API 2.4.10.3
« Reply #1245 on: 30 Jan '14 - 05:59 »
Hello,
i'm new in c#, still testing on BASS.Net, now i create class "BassPlayer" :
- i use public event base on public delegate to set event for "status" (play,stop,pause...) and play "progress" to any form using += (on any form those event will apply to form controls)

- on BassPlayer class, i use BASSTimer, and the problem is how i call  "progress" event in BASSTimer eventhandler. so far still got "cross thread operation not valid...." error ?

- and also on Sync proc for END_SYNC, i use delegate to call "status" event like this :
Code: [Select]

BassSyncDelegate endSyc = new BassSyncDelegate(internalOnEndSync);
IAsyncResult result = endSync.BeginInvoke(user.ToInt32(), null, null);

it works, but is this right way to do. ?

Thanks,

radio42

  • Posts: 4576
Re: BASS.NET API 2.4.10.3
« Reply #1246 on: 30 Jan '14 - 08:17 »
When you get a "cross thread operation" exception, see here for details: http://www.bass.radio42.com/help/html/9b9af3f1-f0dd-42e8-898a-ed607b9d0f60.htm#xThreadCom

Yes, a SYNCPROC can be perfectly used to get notified about when the track has been come to an end.

a2ngsa

  • Posts: 26
Re: BASS.NET API 2.4.10.3
« Reply #1247 on: 30 Jan '14 - 11:00 »
thanks for your info, but :

1. what i mean is if Bass start from a simple Class (on examples is always start form class who has "this.invoke:), so i use delegate, here's part of the code :

Code: [Select]

private delegate void BassSyncDelegate(int index);

...

syncProc = new SYNCPROC(InternalOnSync);
syncEndHandle = Bass.BASS_ChannelSetSync(channel.handle, BASSSync.BASS_SYNC_END, 0, syncProc new IntPtr(0));

....

private void InternalOnSync(int handle, int channel, int data, IntPtr user)
{
     BassSyncDelegate endSync = new BassSyncDelegate(InternalOnEndSync);
     endSync.BeginInvoke(user.ToInt32(), null, null);
....

}

private void InternalOnEndSync(int index)
{
    ....
    this.onStateChanged(this, index, BassState.BASS_END); // ... assigned form event, who will updates UI
}


this code works fine, but i need to confirm since i was working on Delphi.


2. As i use "BassPlayer" as simple class, it contains your Bass.BASSTimer, and the problem comes on :

Code: [Select]

private void timerUpdate_Tick(object sender, System.EventArgs e)
{

   ...... How ? to call event delegate, to update UI

}


on examples was very clear since all place on form class ?

Thanks again for your answers,

radio42

  • Posts: 4576
Re: BASS.NET API 2.4.10.3
« Reply #1248 on: 30 Jan '14 - 11:46 »
I guess you are mixing things here:
The "delegate.BeginInvoke" just calls things asynchronious in its own worker thread.
But this has nothing to do with the exception you got, which was a "cross thread operation" exception.
You only get this exception, if you update a UI element from another thread  (other than the one it was created on) - meaning not the UI thread.
See here http://msdn.microsoft.com/en-us/library/ms171728.aspx on how to make thread-safe calls to windows forms controls.

a2ngsa

  • Posts: 26
Re: BASS.NET API 2.4.10.3
« Reply #1249 on: 1 Feb '14 - 01:57 »
seems i have to learn more about c# threading, one last question if i create play progress event who trigger on BASSTimer like this :

Code: [Select]

...
        private void onPlayerProgressChanged(object sender, int index)
        {

            if (this.trackBarControl1.InvokeRequired)
            {
                SetPlayerProgressCallback progress = new SetPlayerProgressCallback(internalSetPlayerProgress);
                this.Invoke(progress, new object[] { index, Player.channelPositionInt(0) });
            }
            else
            {
                trackBarControl1.Value = Player.channelPositionInt(0);
            }
             
        }

is this right way to create delegate every time playback position change (also for performance), or just create "setPlayerProgressCallback progress" as global private variable ?

thanks Radio42,