Author Topic: BASS.NET API 2.4.17.5  (Read 1134299 times)

poqut

  • Posts: 20
Re: BASS.NET API 2.4.17.2
« Reply #1625 on: 13 Mar '23 - 12:42 »
I downloaded the track and tested. I get the same thing, all zeros. Must be something with the track. Gonna check and see if I can find something not ordinary.

Thank you for your effort =)

I've tried some flags and config values already as you said, it's still same.

Now I replaced vars too, still same.

poqut

  • Posts: 20
Re: BASS.NET API 2.4.17.2
« Reply #1626 on: 13 Mar '23 - 12:46 »
Ok. It seems like the file is to long? I shorted the track to 12 minutes and then it worked. Before that I converted to WAV, same thing. Then I converted to mp3, same thing and now I shorted the track to 12 minutes and saved to wav, it worked.

Nice catch, thank you =) I don't know how but I'll try to read in batches somehow.

radio42

  • Posts: 4840
Re: BASS.NET API 2.4.17.2
« Reply #1627 on: 13 Mar '23 - 13:09 »
Sounds like Ian might want to take a look at that file, as it seems to be unrealated to .Net!

poqut

  • Posts: 20
Re: BASS.NET API 2.4.17.2
« Reply #1628 on: 13 Mar '23 - 13:55 »
Sounds like Ian might want to take a look at that file, as it seems to be unrealated to .Net!

I've just checked the files and all the failed ones has length bigger than 00:12:30 as dj28 found out.

Ian @ un4seen

  • Administrator
  • Posts: 26177
Re: BASS.NET API 2.4.17.2
« Reply #1629 on: 13 Mar '23 - 14:39 »
Code works fine for most of them. But I get full of zeros as data array with some of them and BASS_ErrorGetCode returns BASS_ERROR_ILLPARAM. Converting them to WAV gives the same result too.

You can download one of them from https://we.tl/t-pE3j5jvZ1s to see if you can reproduce.

Code: [Select]
var handle = Bass.BASS_StreamCreateFile(filename, 0, 0, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT);

if (handle != 0) {
var length = Bass.BASS_ChannelGetLength(handle, BASSMode.BASS_POS_BYTE);
    var data = new float[length / 4];
    var read = Bass.BASS_ChannelGetData(handle, data, (int)length);

Bass.BASS_StreamFree(handle);

return data;
}

What is the value of the "length" variable? I suspect the issue is that it's too high for a single BASS_ChannelGetData call. Please note that the PCM data amount is limited to 28 bits (ie. 0xFFFFFFF or 268435455), with the high 4 bits being used for flags. When larger amounts are needed, you can break them down to multiple BASS_ChannelGetData calls. For example, like this:

Code: [Select]
int read = 0;
while (read < length) {
int got = BASS_ChannelGetData(handle, (BYTE*)data + read, min(length - read, 0xfffffff));
if (got <= 0) break;
read += got;
}

poqut

  • Posts: 20
Re: BASS.NET API 2.4.17.2
« Reply #1630 on: 13 Mar '23 - 15:20 »
What is the value of the "length" variable? I suspect the issue is that it's too high for a single BASS_ChannelGetData call. Please note that the PCM data amount is limited to 28 bits (ie. 0xFFFFFFF or 268435455), with the high 4 bits being used for flags. When larger amounts are needed, you can break them down to multiple BASS_ChannelGetData calls. For example, like this:

Code: [Select]
int read = 0;
while (read < length) {
int got = BASS_ChannelGetData(handle, (BYTE*)data + read, min(length - read, 0xfffffff));
if (got <= 0) break;
read += got;
}

It is 333819360, as you said it's bigger than that limit. I was already trying to do multiple reads in c# but couldn't make it yet =)

Do you know how can I convert "(BYTE*)data + read" part to c# via Bass.Net?

Ian @ un4seen

  • Administrator
  • Posts: 26177
Re: BASS.NET API 2.4.17.2
« Reply #1631 on: 13 Mar '23 - 16:14 »
I'm not a C# user myself, but perhaps "data + read / 4" or "&data[read / 4]" will work?

poqut

  • Posts: 20
Re: BASS.NET API 2.4.17.2
« Reply #1632 on: 13 Mar '23 - 16:49 »
I'm not a C# user myself, but perhaps "data + read / 4" or "&data[read / 4]" will work?

Thank you, I will figure it out later, I'm done for today.

And thank you everyone for your support on this issue =)

dj28

  • Posts: 63
Re: BASS.NET API 2.4.17.2
« Reply #1633 on: 13 Mar '23 - 16:53 »
I havent tested this suggestion but similar earlier and it worked (I was using DLLIMPORT for BASS_ChannelGetData but I think it should work), try:

Code: [Select]
int read = 0;
while (read < length) {
int got = BASS_ChannelGetData(handle, (IntPtr)data[read], Math.Min(length - read, 0xfffffff));
if (got <= 0) break;
read += got;
}
« Last Edit: 13 Mar '23 - 17:10 by dj28 »

radio42

  • Posts: 4840
Re: BASS.NET API 2.4.17.2
« Reply #1634 on: 13 Mar '23 - 20:38 »
In Bass.Net there are several overloads for BASS_ChannelGetData. When you read float values just devise (as Ian suggested) the size by 4. As the length is in byte and a float uses 4-bytes.
That simple.
So you can process all files even in much smaller chucks… to save memory…

poqut

  • Posts: 20
Re: BASS.NET API 2.4.17.2
« Reply #1635 on: 14 Mar '23 - 10:04 »
I kept getting AccessViolationException with IntPtr, also I'm not familiar with pointers and unsafe stuff in c#, so I don't know how performant or if it's proper way to do it but here is the final code that gives the array I need.

Thanks all of you again for all the information and support =)

Code: [Select]
var handle = Bass.BASS_StreamCreateFile(filename, 0, 0, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT);

if (handle != 0) {
    var length = (int)Bass.BASS_ChannelGetLength(handle, BASSMode.BASS_POS_BYTE);

    var data = new List<float>();

    int read = 0;

    while (read < length) {
        var bytesLeft = Math.Min(length - read, 134217728);

        var buffer = new float[bytesLeft / 4];

        var got = Bass.BASS_ChannelGetData(handle, buffer, bytesLeft);

        data.AddRange(buffer);

        if (got <= 0)
            break;

        read += got;
    }


    Bass.BASS_StreamFree(handle);

    return data.ToArray();
}

muntablues

  • Posts: 202
Re: BASS.NET API 2.4.17.5
« Reply #1636 on: 17 Apr '24 - 16:29 »
Hi Bernd

Is there somewhere a Link to a older version (2.4.14.1) of BASS.NET? If I update to latest library I need to update to .NET 4.8 but some of my users are still using older OS and so it would be great to use .NET 4.

Thanks and regards!


radio42

  • Posts: 4840
Re: BASS.NET API 2.4.17.5
« Reply #1637 on: 18 Apr '24 - 20:09 »
I am sorry, but I don't maintain the old versions.

carolino

  • Posts: 2
Re: BASS.NET API 2.4.17.5
« Reply #1638 on: 15 Aug '24 - 13:36 »
Hi, are there any plans to include BASSLoud? I'm interested in using it, but from what I've seen in the documentation it's not supported by BASS.NET.

radio42

  • Posts: 4840
Re: BASS.NET API 2.4.17.5
« Reply #1639 on: 1 Sep '24 - 10:21 »
I'll take a look to add it to the next version.