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

dj28

  • Posts: 63
Re: BASS.NET API 2.4.17.2
« Reply #1600 on: 16 Feb '23 - 16:47 »
Hi, I wanted to say good job...
But I have one big issue which drives me crazy.

Decode channel and using BASS_ChannelGetData();
I use VS2019 and Win10.
EDIT: Now I have also tried with VS2022 and with Core. Same thing. Both using x86 and X64. Tried a dllimport of BASS_ChannelGetData and also the same thing. I don't understand.

Im trying both vb.net and C#.
The codes are exactly the same (converted though for C#) but it only works for vb.net and not C#.
In vb.net the buffer fills with data as it should but with C# it fills the buffer with only 0. The bytes read is the same for both and no errors.

I'm trying to open a mp3-file and read the data, filling it into a buffer, with a decoding channel. This is the code:

Code: [Select]
if (!Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero))
            {
                MessageBox.Show("Couldn't init Bass" + Bass.BASS_ErrorGetCode());
                return;
}

OpenFileDialog fdialog = new OpenFileDialog();
fdialog.Filter = "Music files (*.mp3, *.wav, *.flac)|*.mp3|*.wav|*.flac";
if (fdialog.ShowDialog() != DialogResult.OK) return;

string file = fdialog.FileName;

int stream = Bass.BASS_StreamCreateFile(file, 0, 0, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_STREAM_PRESCAN);
if (stream == 0)
                MessageBox.Show("Couldn't create stream: " + Bass.BASS_ErrorGetCode());
                Bass.BASS_Free();
                return;
}

long length = Bass.BASS_ChannelGetLength(stream, BASSMode.BASS_POS_BYTE);
if (length == -1)
                MessageBox.Show("Couldn't get length: " + Bass.BASS_ErrorGetCode());
                Bass.BASS_Free();
                return;
}

short[] buffer = new short[length];
int readbytes = Bass.BASS_ChannelGetData(stream, buffer, (int)length);
« Last Edit: 17 Feb '23 - 10:08 by dj28 »

radio42

  • Posts: 4840
Re: BASS.NET API 2.4.17.2
« Reply #1601 on: 17 Feb '23 - 12:03 »
'length' is in byte...but you create a buffer of 'short' values.
Code: [Select]
long length = Bass.BASS_ChannelGetLength(stream, BASSMode.BASS_POS_BYTE);
short[] buffer = new short[length/2];
int readbytes = Bass.BASS_ChannelGetData(stream, buffer, (int)length);

dj28

  • Posts: 63
Re: BASS.NET API 2.4.17.2
« Reply #1602 on: 17 Feb '23 - 12:30 »
It shouldn't make any difference since it works in vb.net.
As long as the buffer is in correct size regarding the length. 16bits (short) is the same size as 2 bytes, hence divided by two.
And tried it now just in case. All 0's.

Ian @ un4seen

  • Administrator
  • Posts: 26172
Re: BASS.NET API 2.4.17.2
« Reply #1603 on: 17 Feb '23 - 13:02 »
It shouldn't make any difference since it works in vb.net.

Are the "length" and "readbytes" values the same in both cases?

dj28

  • Posts: 63
Re: BASS.NET API 2.4.17.2
« Reply #1604 on: 17 Feb '23 - 13:03 »
Yes they are.

Ian @ un4seen

  • Administrator
  • Posts: 26172
Re: BASS.NET API 2.4.17.2
« Reply #1605 on: 17 Feb '23 - 13:09 »
And what values are they?

Are you having the problem with a particular file (or file format) and not others? If so, please also try converting the same file to WAV with the pre-compiled WRITEWAV.EXE example included in the BASS package (C\BIN folder) and see if the output BASS.WAV file contains all 0s too.

dj28

  • Posts: 63
Re: BASS.NET API 2.4.17.2
« Reply #1606 on: 17 Feb '23 - 13:12 »
42 691 004 bytes for one particular mp3 track.
I've tested a lot of mp3 files, wav files and flac files. It doesn't matter. They all give 0's except when it's in vb.net which works just fine.

dj28

  • Posts: 63
Re: BASS.NET API 2.4.17.2
« Reply #1607 on: 17 Feb '23 - 13:18 »
I tried to start writewave.exe but it says "The application was unable to start correctly (0xc000007b).".
I think I have trolls in my computer...

dj28

  • Posts: 63
Re: BASS.NET API 2.4.17.2
« Reply #1608 on: 17 Feb '23 - 13:32 »
I used writewav.exe with a mp3file and it did work. Must be something with my c# environment. I don't get it...

radio42

  • Posts: 4840
Re: BASS.NET API 2.4.17.2
« Reply #1609 on: 17 Feb '23 - 15:00 »
Have you debugged your application? where exactly is it failing resp. returning 0?
And are you sure you don't mix a 64-bit app with the native 32-bit BASS dlls?
I.e. make sure to use the correct native libs...

Ian @ un4seen

  • Administrator
  • Posts: 26172
Re: BASS.NET API 2.4.17.2
« Reply #1610 on: 17 Feb '23 - 15:38 »
I used writewav.exe with a mp3file and it did work. Must be something with my c# environment. I don't get it...

Please try calling BASS_ChannelGetLevelEx (BASS_ChannelGetLevels in BASS.Net) instead of BASS_ChannelGetData and see if it returns 0. BASS_ChannelGetLevelEx uses BASS_ChannelGetData internally, so if it sees non-0 data then so should your BASS_ChannelGetData call. Call it something like this:

Code: [Select]
float[] levels = BASS.BASS_ChannelGetLevels(stream, 10000, BASSLevel.BASS_LEVEL_MONO);

dj28

  • Posts: 63
Re: BASS.NET API 2.4.17.2
« Reply #1611 on: 18 Feb '23 - 04:37 »
This got a weird outcome.
First I tried core version once and it worked. The first time. Not after that. I couldn't recreate the situation though. Trolls.

Then I tried your suggestion:

levels.length was only 1.
And levels[0] was also 1.

I also tried with 100 000 instead of 10 000 as lenght but same result.
« Last Edit: 18 Feb '23 - 04:44 by dj28 »

dj28

  • Posts: 63
Re: BASS.NET API 2.4.17.2
« Reply #1612 on: 18 Feb '23 - 04:43 »
Radio42: Im running it in debug mode and also tried the compiled exe file. Same thing.
I also tried both x86 and x64 version of bass.dll. Same thing. I've done everything I could came up with. At least as of now.

The code runs without any errors. Works fine except for the 0 buffer. I made a halt in the code right efter BASS_ChannelGetData to look at the buffer. 0's.

I even compiled your version showing the waveform and it worked. Don't know if you're using BASS_ChannelGetData for that one though but I suspect you do.

To me, it seems like my C# ide is weird and I "forgot" some setting for this to work. I just don't know and my hair just turned grey :P
« Last Edit: 18 Feb '23 - 04:54 by dj28 »

dj28

  • Posts: 63
Re: BASS.NET API 2.4.17.2
« Reply #1613 on: 18 Feb '23 - 17:46 »
Hi,

It's working now...I reinstalled Visual Studio 2022.
I must have trolls in my computer  ???

Thanks for all your help and now I feel stupid for occupying your time  :P

Ian @ un4seen

  • Administrator
  • Posts: 26172
Re: BASS.NET API 2.4.17.2
« Reply #1614 on: 20 Feb '23 - 11:35 »
Good to hear that you've got it working now, even if it is a bit of a mystery! Just to confirm, your BASS_ChannelGetLevels result was fine (BASS_LEVEL_MONO means a single value will be returned, and the 1 value means it peaked at 0db), so the data seems to have been fine but you just couldn't see it in your array for some reason - perhaps it was a debugger issue?

dj28

  • Posts: 63
Re: BASS.NET API 2.4.17.2
« Reply #1615 on: 20 Feb '23 - 11:48 »
I honestly don't have a clue. But I have noticed my VS2022 has been acting strange a couple of days. Errors when trying to get my form in design mode, simple combined calculations being wrong etc. It's very weird. It wouldn't surprised me if the computers RAM memory is faulty or some sectors of the hard drive but then I would have got me some blue screens, which I haven't...yet :P

And I do have antivirus program and no viruses but after this I got very skeptical and suspect everything, even a couple of small gremlins in my computer :P

And again, thx for the help! Both you and radio42.

poqut

  • Posts: 20
Re: BASS.NET API 2.4.17.2
« Reply #1616 on: 12 Mar '23 - 23:25 »
Hey,

I'm having the same issue as dj28.

My files are 44100 16 FLAC.

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

radio42

  • Posts: 4840
Re: BASS.NET API 2.4.17.2
« Reply #1617 on: 13 Mar '23 - 07:51 »
Did you tried the same solution as DJ28?

poqut

  • Posts: 20
Re: BASS.NET API 2.4.17.2
« Reply #1618 on: 13 Mar '23 - 09:38 »
Did you tried the same solution as DJ28?

Yes, reinstalled VS2022 but it didn't work for me.

I'm using Bass.Net core version with .net 7.

I will try to make a simple test project with Bass.Net full & .net framework 4.8 to make sure it's not .net related issue.

poqut

  • Posts: 20
Re: BASS.NET API 2.4.17.2
« Reply #1619 on: 13 Mar '23 - 11:21 »
I've tried both core and full as 32 and 64bit separately, I even tried with ManagedBass, the result is same for those small amount of files, like 6 in about 1000 files.

dj28

  • Posts: 63
Re: BASS.NET API 2.4.17.2
« Reply #1620 on: 13 Mar '23 - 11:47 »
How did you check all the zeros? Which tool did you use and how much of the buffer did you check?

poqut

  • Posts: 20
Re: BASS.NET API 2.4.17.2
« Reply #1621 on: 13 Mar '23 - 12:00 »
How did you check all the zeros? Which tool did you use and how much of the buffer did you check?

I'm reading the whole file as I shared above and I used the simple code below to make sure it's all zeros.

Code: [Select]
float total = 0;
foreach (var value in data) {
total += value;
}

dj28

  • Posts: 63
Re: BASS.NET API 2.4.17.2
« Reply #1622 on: 13 Mar '23 - 12:22 »
Just to be sure cause I got weird values when I not did specify that it was float and I don't know if var really translates to float. So to be on the safe side change var to float and check again. I don't use var so I have no experience of it.

I haven't downloaded the file and checked it yet though. And try add BASS_STREAM_PRESCAN when you create the stream. As I understand it's only effective on variable bitstream mp3's but I use it anyway :P

You can also set a breakpoint on the row after channelgetdata, run the application and when it stops at your breakpoint, put your mouse over "data", then choose View - IEnumerable Visualizer to check the whole buffer.

dj28

  • Posts: 63
Re: BASS.NET API 2.4.17.2
« Reply #1623 on: 13 Mar '23 - 12:30 »
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.

dj28

  • Posts: 63
Re: BASS.NET API 2.4.17.2
« Reply #1624 on: 13 Mar '23 - 12:37 »
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.