Author Topic: BASS_Mixer_ChannelGetLevelEx not working with MIDI real-time split stream  (Read 93 times)

e6211e

  • Posts: 2
I want to create MIDI mixer software that has many MIDI and bus channel and each channel can send sound to FX mixer.

It working, bus have some problems with BASS_Mixer_ChannelGetLevelEx.
I use another software for play and send MIDI event to my program with loopMIDI, bus when my program have no MIDI event coming about 1 minutes (my program will no sound). After that, i can't get Level by BASS_Mixer_ChannelGetLevelEx anymore.

So.... how can i fix this problems.
Sorry for the poor english.
Thank.

Here, my example code.
Code: [Select]
BASS_Init(-1, 44100, 0, NULL, NULL);

BASS_SetConfig(BASS_CONFIG_BUFFER, 100);
BASS_SetConfig(BASS_CONFIG_UPDATEPERIOD, 20);
BASS_SetConfig(BASS_CONFIG_CURVE_VOL, TRUE);
BASS_SetConfig(BASS_CONFIG_MIDI_VOICES, 128);
BASS_SetConfig(BASS_CONFIG_MIDI_COMPACT, TRUE);


// Create main mixer
DWORD mainMixer = BASS_Mixer_StreamCreate(44100, 2, BASS_SAMPLE_FLOAT);
BASS_ChannelPlay(mainMixer, TRUE);

// Create FX mixer
DWORD fx1Mixer    = BASS_Mixer_StreamCreate(44100, 2, BASS_SAMPLE_FLOAT|BASS_STREAM_DECODE);
// apply any FX
HFX fx = BASS_ChannelSetFX(fx1Mixer, BASS_FX_DX8_REVERB, 1);
......

// Add FX mixer to main mixer
BASS_Mixer_StreamAddChannel(mainMixer, fx1Mixer, 0);
.
.

// Create bus mixer and splitter
DWORD busMixer         = BASS_Mixer_StreamCreate(44100, 2, BASS_SAMPLE_FLOAT|BASS_STREAM_DECODE);
DWORD busSplitter      = BASS_Split_StreamCreate(busMixer, BASS_STREAM_DECODE, NULL);
DWORD busFx1Splitter = BASS_Split_StreamCreate(busMixer, BASS_STREAM_DECODE|BASS_SPLIT_SLAVE, NULL);

// Add bus to main mixer
BASS_Mixer_StreamAddChannel(mainMixer, busSplitter, BASS_MIXER_BUFFER);

// Add bus fx to FX Mixer
BASS_Mixer_StreamAddChannel(fx1Mixer, busFx1Splitter, 0);
.
.

// Create MIDI and splitter
DWORD midi                 = BASS_MIDI_StreamCreate(16, BASS_SAMPLE_FLOAT|BASS_STREAM_DECODE|BASS_MIDI_SINCINTER, 44100);
DWORD midiSplitter      = BASS_Split_StreamCreate(midi, BASS_STREAM_DECODE, NULL);
DWORD midiFx1Splitter = BASS_Split_StreamCreate(midi, BASS_STREAM_DECODE|BASS_SPLIT_SLAVE, NULL);

// Add midi to bus
BASS_Mixer_StreamAddChannel(busMixer, midiSplitter, BASS_MIXER_BUFFER);

// Add midi fx splitter to FX Mixer
BASS_Mixer_StreamAddChannel(fx1Mixer, midiFx1Splitter, 0);

// Set soundfont and any
..........
.
.

// Receive midi event from midi input and sent to midi stream
void CALLBACK MidiInProc(DWORD device, double time, const BYTE *buffer, DWORD length, void *user) {
    BASS_MIDI_EVENT event;
    if (BASS_MIDI_ConvertEvents(buffer, length, &event, 1, 0) != -1) {
        BASS_MIDI_StreamEvent(midi, event.chan, event.event, event.param);
    }
}

.
.

// Timer for get level and display vu 40 ms
void onTimerTimeout() {
    float levels[2];
    BASS_Mixer_ChannelGetLevelEx(midiSplitter, levels, 0.04f, BASS_LEVEL_STEREO);
    uiVu.peakLevel(levels[0], levels[1]);
}

Ian @ un4seen

  • Administrator
  • Posts: 21986
It looks like you are using local variables for the BASS handles in that code, which means they will not accessible in callback functions (eg. onTimerTimeout). Is that the actual code that you are using or have you just modified it to show the variable types?

Is the BASS_Mixer_ChannelGetLevelEx call failing (return false) or just giving 0 levels? If it is failing, please use BASS_ErrorGetCode to check the error code. Also check the MIDI stream's BASS_ATTRIB_MIDI_VOICES attribute value when the problem happens to confirm if the MIDI stream is playing anything:

Code: [Select]
float voices;
BASS_ChannelGetAttribute(midi, BASS_ATTRIB_MIDI_VOICES, &voices);

By the way, you could tweak the MidiInProc function slighty like this:

Code: [Select]
void CALLBACK MidiInProc(DWORD device, double time, const BYTE *buffer, DWORD length, void *user) {
BASS_MIDI_StreamEvents(midi, BASS_MIDI_EVENTS_RAW, buffer, length);
}