Illegal param error on BASS_SampleLoad in ver 1.8

Started by Dasmius,

Dasmius

I havn't updated my BASS sound library since BASS 0.9, and I have code that used to work in the old version that doesn't work in 1.8.

Basically I am getting in 1625 bytes of compressed WAV data (GSM 6.1 8khz) from my TCP/IP control, which contains no wave header, just the raw compressed wave data. I have a buffer in memory with a pre-made wave header filled in with the codec definition to tell BASS it's GSM, the size, etc.

It plays perfectly fine in BASS 0.9. But if I try it in BASS 1.6 or 1.8, in the code below when I call BASS_SampleLoad, I get an error code 20 (BASS_ERROR_ILLPARAM - an illegal parameter was specified).

What am I passing in wrong, that would have worked in 0.9 but not in the newer versions of BASS?

The code looks like this:

var
      Buffer: array[0..2000] of char;


procedure TForm1.CreateWaveHeader;
var
      s: array[0..7] of char;
begin
      s := 'RIFF'; move(s, Buffer[0], 4);
      Buffer[4] := #68; Buffer[5] := #9;      // 44 09
      Buffer[6] := #0; Buffer[7] := #0;      // 00 00
      s := 'WAVEfmt '; move(s, Buffer[8], 8);
      Buffer[16] := #20; Buffer[17] := #0;      // 14 00
      Buffer[18] := #0; Buffer[19] := #0;      // 00 00
      Buffer[20] := #49; Buffer[21] := #0;      // 31 00
      Buffer[22] := #1; Buffer[23] := #0;      // 01 00
      Buffer[24] := #64; Buffer[25] := #31;      // 40 1F
      Buffer[26] := #0; Buffer[27] := #0;      // 00 00
      Buffer[28] := #89; Buffer[29] := #6;      // 59 06
      Buffer[30] := #0; Buffer[31] := #0;      // 00 00
      Buffer[32] := #65; Buffer[33] := #0;      // 41 00
      Buffer[34] := #0; Buffer[35] := #0;      // 00 00
      Buffer[36] := #2; Buffer[37] := #0;      // 02 00
      Buffer[38] := #64; Buffer[39] := #1;      // 40 01
      s := 'data'; move(s, Buffer[40], 4);
end;

procedure TForm1.PlayVoiceData(data: pointer; size: integer);
var
      mysamp: HSAMPLE;
begin
      if size <= 0 then exit;

      move(data^, Buffer[48], size);
      move(size, Buffer[44], 4);
      size := size + 40;
      move(size, Buffer[4], 4);

      mysamp := BASS_SampleLoad(TRUE, @Buffer, 0, 0, 1, BASS_SAMPLE_OVER_POS);

      if mysamp = 0 then showmessage('can''t load sample' + #13#10 + '(error code: ' + IntToStr(BASS_ErrorGetCode) + ')');

      BASS_SamplePlayEx(mysamp, 0, -1, 100, 0, FALSE);
end;

Ian @ un4seen

You need to specify the length of the data in memory, in the "length" parameter. This wasn't necessary in 0.9 because only WAV files were supported as samples. But now, with support for MPEG/OGG (which don't tell the file size in the header) samples, it is necessary.

Dasmius

Thanks Ian! Much appreciated ...

Should I be passing in the exact length of only the data portion of the wave (1625 bytes), or should I pass in the total length of the entire wave data in memory including the wave header (i.e. 1665 bytes) as the length parameter?

Ian @ un4seen

"length" is the total length of the block of memory you want to load from, including any header.