BASS.NET API 2.4.17.5

Started by radio42,

poqut

Quote from: dj28I 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

Quote from: dj28Ok. 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

Sounds like Ian might want to take a look at that file, as it seems to be unrealated to .Net!

poqut

Quote from: radio42Sounds 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

Quote from: poqutCode 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.

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:

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

Quote from: Ian @ un4seenWhat 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:

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

I'm not a C# user myself, but perhaps "data + read / 4" or "&data[read / 4]" will work?

poqut

Quote from: Ian @ un4seenI'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

#1633
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:

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;
}

radio42

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

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 =)

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

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

I am sorry, but I don't maintain the old versions.

carolino

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

I'll take a look to add it to the next version.