Author Topic: Understand Bass_ChannelGetData  (Read 191 times)

muntablues

  • Posts: 198
Understand Bass_ChannelGetData
« on: 26 Mar '18 - 08:45 »
Hi there

I am trying to implement the beat detection and waveform rendering to a C# project and after some time, I got it working to get the same values as the demo project does.

My problem at the moment is, that i sometimes get OutOfMemoryException if I load a song. This is caused because I create a byte buffer for the whole song. So I've tried to read only small chunks of a song and use this chunks to do the calculation. Now I dont understand the result of ChannelGetData.

If I use eg. BASS_ChannelGetData(chan, buffer, 1024) and compare the buffer with fullBuffer from BASS_ChannelGetData(chan, fullBuffer, songLength) it is not the same? What am I missing here, to get the same results if I read only small chunks.

Here is the code what is done in the orig. project and I would like to replace this to avoid the out of memory exception!

Code: [Select]
var length=BASS_ChannelGetLength(chan,BASS_POS_BYTE);
int* leftData;
leftData=new int[Length];

check=BASS_ChannelGetData(chan, leftData, Length);

Regards MB

Ian @ un4seen

  • Administrator
  • Posts: 20719
Re: Understand Bass_ChannelGetData
« Reply #1 on: 26 Mar '18 - 17:02 »
Are you calling BASS_ChannelSetPosition between the BASS_ChannelGetData calls? If so, depending on the file format and flags used (eg. MP3 without BASS_STREAM_PRESCAN flag), that can result in different data than decoding straight through. Otherwise, you should get the same data whether you decode the file in a single or multiple BASS_ChannelGetData calls.

Note your code above is allocating 4x as much memory as needed. You should use a "char" array rather than an "int" array to avoid that.

Code: [Select]
char* leftData = new char[Length];

muntablues

  • Posts: 198
Re: Understand Bass_ChannelGetData
« Reply #2 on: 27 Mar '18 - 07:05 »
No I just call ChannelGetData until i reach the end and I create the stream with PRESCAN flag.

I will try to create a little test project where I can compare the different data arrays, will come back with the results!

Thanks so far!
MB