Author Topic: Playing a (very) short sample, first time is not audible  (Read 258 times)

jeehell

  • Posts: 3
Hello

I have a few short wave files (about 150ms) that I need to play
These shorts wav files are loaded once in the app lifetime using BASS_SampleLoad call.
I tried on two devices: MoBo built-in and the one built in the monitor I use (DELL).

On my MoBo device, all is good.

On the DELL device, the first time I play that sample, the playback is empty.
The second call it works.

Here is some Delphi code. I reproduced the effect from my main App (with code I cannot share for length reasons) into a simple app, this is the reason for the BASS_CONFIG_XX used.

BASS initialization:
Code: [Select]
procedure TForm1.InitButtonClick(Sender: TObject);
begin
  BASS_Init(3, 44100, 0, 0, nil); // -> 3 is my DELL device
  BASS_SetConfig(BASS_CONFIG_UPDATEPERIOD, 5); 
  BASS_SetConfig(BASS_CONFIG_CURVE_VOL, 0); 
  BASS_SetConfig(BASS_CONFIG_NORAMP, 1);          //I tried to remove RAMP altogether, but with or without this line, I get the exact same results
  BASS_SetConfig(BASS_CONFIG_DEV_NONSTOP, 1); //this line commented out can give a different outcome see below
end;

sound loading/playing (I put it in a simple...button):
Code: [Select]

var
  shortSample: HSAMPLE = 0; //global var holding the sample handle

procedure TForm1.PlayButtonClick(Sender: TObject);
var
  f: pchar;
  chan: HCHANNEL;
  sync: cardinal;
begin
  if shortSample = 0 then
  begin
    f := PChar(ExtractFilePath(Application.ExeName) + 'ShortSound.wav');
    shortSample:= BASS_SampleLoad(false, f, 0, 0, 5, 0 {$IFDEF UNICODE} or BASS_UNICODE {$ENDIF});
  end;


  chan:= BASS_sampleGetChannel(shortSample, BASS_SAMCHAN_STREAM or BASS_STREAM_AUTOFREE);
 
  BASS_ChannelSetAttribute(chan, BASS_ATTRIB_PAN, 0);
  BASS_ChannelSetAttribute(chan, BASS_ATTRIB_VOL, 1);
  BASS_ChannelSetPosition(chan, 0, BASS_POS_RESET);

  BASS_ChannelPlay(chan, true);

Interestingly, if I remove the BASS_CONFIG_DEV_NONSTOP = 1 option, then the issue reoccurs if I play the sound let's say 3 seconds later. Sometimes, the sound is barely audible like in the middle of a fade in/out process. If I then play the sample repeatedly (or within a second) then the sample sounds normally (I cannot tell if it is actually slightly ramped or not, but it sounds nominal).
BASS_CONFIG_NORAMP = 1 gave me the same results on each device (all good on MoBo, bad on DELL...)

Do you believe it is a faulty driver here? or is there something I can work on? I could play the sound once before the app needs to run, though on "good" devices it will actually sound, and I have no way to tell before hand if a device will work correctly or not...

Thanks a lot
Jean Luc

Ian @ un4seen

  • Administrator
  • Posts: 26157
That sounds like the Dell device is going to sleep when inactive and there's a delay in it waking when activity resumes, resulting in it skipping some data. Enabling the BASS_CONFIG_DEV_NONSTOP option will keep the device active, but it won't wake an already inactive device. So you should enable it before the BASS_Init call, or call BASS_Start afterwards.

jeehell

  • Posts: 3
Thanks for the info Ian.
I could verify your thoughts with the BASS_IsStarted call and indeed it returns 2 indicating the device is inactive.
I tried to call BASS_Start afterwards as you suggested to no avail though.
Playing a blank sound triggered it and coupled with BASS_CONFIG_DEV_NONSTOP option that kept the device alive and first playback of my sound was perfect.
This is not optimal, though it is acceptable, and I guess BASS can not do much more here...
Thanks for your time, I really appreciate it.

Ian @ un4seen

  • Administrator
  • Posts: 26157
I tried to call BASS_Start afterwards as you suggested to no avail though.

Ah yes, I forgot that BASS_Start won't start an inactive output (when BASS_IsStarted = 2). You would need to also call BASS_Stop/Pause first then, for BASS_Start to have effect.

Playing a blank sound triggered it and coupled with BASS_CONFIG_DEV_NONSTOP option that kept the device alive and first playback of my sound was perfect.

It shouldn't be necessary to play a blank sound to wake the device if you enable BASS_CONFIG_DEV_NONSTOP before (instead of after) calling BASS_Init. Did you find that it was?

David_AVD

  • Posts: 85
Is there any potential downsides to using BASS_CONFIG_DEV_NONSTOP ?

jeehell

  • Posts: 3
It shouldn't be necessary to play a blank sound to wake the device if you enable BASS_CONFIG_DEV_NONSTOP before (instead of after) calling BASS_Init. Did you find that it was?
oh I misread your message it seems. I just tried, and enabling BASS_CONFIG_DEV_NONSTOP before calling BASS_Init did the trick, this is perfect!!
thank you so much for the support!

Ian @ un4seen

  • Administrator
  • Posts: 26157
Is there any potential downsides to using BASS_CONFIG_DEV_NONSTOP ?

It'll perhaps use a bit more power, as the device is kept active when nothing is playing. But you could use BASS_Stop/Pause when you know nothing will be playing for a while.