Author Topic: Problem with BASSWASAPI and my driver (Keppy's Driver)  (Read 318 times)

KaleidonKep99

  • Posts: 150
I added WASAPI support to my driver, called Keppy's Driver. (https://github.com/KaleidonKep99/Keppy-s-Driver)
I have this strange problem, where (I think) the buffer gets full too fast, and BASSWASAPI starts making static noises.

Here's a video of the problem: https://www.youtube.com/watch?v=nFIkpQLlBjA&feature=youtu.be

And here's the code:


BASSWASAPI Init:
Code: [Select]
...
OutputDebugString(L"Initializing the stream...");
if (BASS_Init(0, frequencyvalue, 0, NULL, NULL)) {
if (wasapimode == 0) {
if (sound_driver == NULL) {
sound_driver = create_sound_out_xaudio2();
sound_out_float = IsVistaOrNewer();
sound_driver->open(g_msgwnd->get_hwnd(), frequency + 100, 2, (IsFloatingPointEnabled() ? sound_out_float : nofloat), SPFSTD, frames);
/* Why frequency + 100? There's a bug on XAudio that cause clipping when the MIDI driver's audio frequency is the same has the sound card's max audio frequency. */
}
}
else {
BASS_WASAPI_Init(-1, 0, 2, BASS_WASAPI_SHARED, 0.01, 1, NULL, NULL);
BASS_WASAPI_Start();
}
consent = 1;
hStream[0] = BASS_MIDI_StreamCreate(tracks, BASS_STREAM_DECODE | (IgnoreSystemReset() ? BASS_MIDI_NOSYSRESET : sysresetignore) | (IsSoftwareModeEnabled() ? BASS_SAMPLE_SOFTWARE : softwaremode) | (IsFloatingPointEnabled() ? BASS_SAMPLE_FLOAT : nofloat) | (IsNoteOff1TurnedOn() ? BASS_MIDI_NOTEOFF1 : noteoff1) | (AreEffectsDisabled() ? BASS_MIDI_NOFX : nofx) | (check_sinc() ? BASS_MIDI_SINCINTER : sinc), 0);
if (!hStream[0]) {
BASS_StreamFree(hStream[0]);
hStream[0] = 0;
continue;
}
...

Buffer system:
Code: [Select]
...
while (stop_thread == 0){
if (reset_synth[0] != 0){
reset_synth[0] = 0;
load_settings();
BASS_MIDI_StreamEvent(hStream[0], 0, MIDI_EVENT_SYSTEM, MIDI_SYSTEM_DEFAULT);
BASS_MIDI_StreamLoadSamples(hStream[0]);
}
bmsyn_play_some_data();
float sound_buffer[2][SPFSTD];
decoded = BASS_ChannelGetData(hStream[0], sound_buffer[0], BASS_DATA_FLOAT + SPFSTD * sizeof(float));
if (decoded < 0) {

}
else {
for (unsigned i = 0, j = decoded / sizeof(float); i < j; i++) {
float sample = sound_buffer[0][i];
sample *= sound_out_volume_float;
sound_buffer[0][i] = sample;
}
if (wasapimode == 0) {
sound_driver->write_frame(sound_buffer[0], decoded / sizeof(float), false);
}
else {
BASS_WASAPI_PutData(sound_buffer[0], SPFSTD * sizeof(float));
}
}
realtime_load_settings();
keybindings();
debug_info();
}
...

Ian @ un4seen

  • Administrator
  • Posts: 20424
Please check the BASS_WASAPI_PutData return value to confirm how much data was actually accepted, ie. how much there was space for in the device buffer. If it is less than was provided, then you will need to call BASS_WASAPI_PutData again later with the remaining data.

If you would like to check how much space there is in the buffer, you can use BASS_WASAPI_GetData with the BASS_DATA_AVAILABLE flag, like this:

Code: [Select]
DWORD got=BASS_WASAPI_GetData(NULL, BASS_DATA_AVAILABLE); // get amount of data in buffer
DWORD space=buflen-got; // buffer space = buffer length - amount got

The buffer length is available from BASS_WASAPI_GetInfo.