Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

separate audio stream per midi channel #101

Open
kmatze opened this issue Jan 9, 2025 · 2 comments
Open

separate audio stream per midi channel #101

kmatze opened this issue Jan 9, 2025 · 2 comments

Comments

@kmatze
Copy link

kmatze commented Jan 9, 2025

Hi,

i use your formidable tsf.h without tml.h.

with

        tsf_channel_note_on(g_TinySoundFont, chn, bData1, 1.0 / 127 * bData2);
	tsf_channel_note_off(g_TinySoundFont, chn, bData1);

i play midi note (on/off)
and with

        int SampleCount = (size / (2 * sizeof(short))); 					//2 output channels
	tsf_render_short(g_TinySoundFont, (short*)stream, SampleCount, 0);

i get the actual audio stream for the whole tsf backend.

Is it possible to get an separate audio stream for a (midi) channel? So I can use my own audio effects per MIDI channel and then mix them finally.

thx - kmatze

@WindowsNT
Copy link

WindowsNT commented Jan 10, 2025

I'm doing it in my code to support effects per channel.

   tsf* f  = ...;
   struct tsf_voice* v = f->voices, * vEnd = v + f->voiceNum;
		for (; v != vEnd; v++)
		{
			if (v->playingPreset != -1)
			{
				TSF_MEMSET(buffer2, 0, sizeof(float) * SamplesMix);
				tsf_voice_render(f, v, buffer2, samples);

```               ....

@kmatze
Copy link
Author

kmatze commented Jan 10, 2025

Thx, that`s a good entry, but i get only crazy noise.

So far I had used the following code:

		SFGetSample(sndSF2, waveBufLen);	                                                 // get synth data streams ...	
		tal_effect(sndSF2,   waveBufLen, sfxSF2);                                                 // ... process them with effects
		tal_mixer(soundbuf[i], snd1, sndSF2, snd3, waveBufLen);               	// ... an mixing together
void SFGetSample1(void *stream, long size) {
	int SampleCount = (size / (2 * sizeof(short))); 					//2 output channels
	tsf_render_short(g_TinySoundFont, (short*)stream, SampleCount, 0);
}

i change it to:

void SFGetSample(void *stream, long size) {
	int SampleCount 		= (size / (2 * sizeof(short))); 	//2 output channels
	struct tsf_voice *v    	= g_TinySoundFont->voices;
	struct tsf_voice *vEnd 	= v + g_TinySoundFont->voiceNum;
	for (; v != vEnd; v++) {
		if (v->playingPreset != -1) {
			TSF_MEMSET(stream, 0, sizeof(float)* SampleCount);
			tsf_voice_render(g_TinySoundFont, v, stream, SampleCount);
		}
	}
}

and get crazy noise

i don`t understand the logic of voice and channels, is it the same? Can you explain it please and the use of effect support.

thank you very much - greetings - kmatze

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants