Page 1 of 1

Posted: 30 Dec 2015, 14:06
by oli_lab
Hi,
I'd like to experiment with strange sound generators...
is anyone has an easy way to build a basic audio sawtooth in the sdk ?

this sawtooth will give me the frequency and phase and I'll manage to do all the funny sound generation from it by passing it throught cos(x) and all...

thanks

Olivar

Posted: 06 Jan 2016, 12:19
by oli_lab
I started this project but I have a problem here :
I have nothing on the audioOutput, because bufferSize = 0...
do I have to set the blockSize ? or else ? how ?

thanx

Olivar

void AudioGen1::onProcess ()
{
int bufferSize = sdkGetEvtSize(audioOutput);
sdkTraceInt(bufferSize);
double phaseIncrementInsideBuffer = phaseIncrement / bufferSize;
for (int j = 0; j < bufferSize; j++)
{
phase = phase + phaseIncrementInsideBuffer;
if (phase >= 2) {
phase = 0;
}
sdkSetEvtArrayData(audioOutput, j, phase);
}
}

Posted: 06 Jan 2016, 13:41
by oli_lab
ok...
I'm going somewhere :

I did this :

// initialisation
void AudioGen1::onInitModule (MasterInfo* pMasterInfo, ModuleInfo* pModuleInfo)
{
o_frameRate = sdkGetSampleRate();
o_blockSize = sdkGetBlocSize();
phase = 0;
}

[...]

but still, the output signal is not consistent...

Posted: 06 Jan 2016, 15:47
by 23fx23
if it's an audio out better use ptaudio i think, set its size of bloc size, then bestway i feel is to fill an internal buffer of -1..1 floats as you wish (of bloc size) then copy it to the pt audio dest on process, something like:

//on init
BLOC_SIZE = sdkGetBlocSize(); //int
SMP_RATE = sdkGetSampleRate(); // long
BLOC_BYTES_SIZE = BLOC_SIZE * sizeof(float); //int
sdkSetEvtSize(pAudioOut, BLOC_SIZE); // ptaudio
PTR_AUDIO_OUT = sdkGetEvtDataAddr(pAudioOut); //TPrecision pointer

//manip code fuction fill the buffer
void my_function()
{
for (int i=0; i++; i<BLOC_SIZE)
{BLOC_SMP_BUFFER = wanted_sample_value;}
}


//process
my_fuction();
memcpy((void*)PTR_AUDIO_OUT, (void*)(BLOC_SMP_BUFFER), BLOC_BYTES_SIZE);

Posted: 07 Jan 2016, 10:26
by oli_lab
thank you.

>> internal buffer of -1..1 floats as you wish (of bloc size)
for some reason, I have to make one of fixed sized (ie 512 or 256) doing Tpecision BLOC_SMP_BUFFER[BLOC_SIZE] is not working

the stuff inside the "my_fonction" is not reconized, even though all the variables are declared in the .h file (it is reckonnized if the content of my_fonction is placed directly inside "on_process"...

for the rest no sound is going to the output apart of a high pitch glitch...

I keep investigate.

cheers

Posted: 07 Jan 2016, 14:32
by 23fx23
mm ok for the size its normal, standard 'arrays' don't accept dynamic size in cpp sadly . vector do but imply including vector class and sometimes it's not worthy i find. in such cases i either make a larger array fixed size on init but use only bloc size length or a possible thing is make like:
//on. h
float* my_buffer = new[max_possible_size].

//on init when you get blocsize
my_buffer = new float*[bloc_size];

this will make my_buffer of bloc size. but it should idealy be done only once as it increase memory, each time a 'new' object is made it should be destroyed somewhere when/if not used anymore. for exemple if in a fuction a new bloc_size was incoming would use delete[]my_buffer; my_buffer = nullptr; before creating a new one.

strange you can't access the function/var out of process mmmm have to find about this cause creating variables in process is much more cpu consuming than if one was only set in .h.
no idea why it wouldn't work sorry .

Posted: 07 Jan 2016, 18:48
by oli_lab
thanx, I keep investigating, as I know that as soon as I'll get a viable backbone, I'll be able to build quite a few new bli and glitches generators....

Posted: 15 Jan 2016, 19:25
by martignasse
hey oli,

maybe i can help with this, but i need to see your source code for that ;)

Posted: 15 Jan 2016, 20:05
by oli_lab
What I did is put an audio input so my module use an external sawtooth oscillator.
So the buffer is therefore sized by the incoming audio.
So my module is an fx module now...
Will publish soon...

Posted: 27 Jan 2016, 20:05
by oli_lab
I think I managed the buffer allright, but on a different project.

it is a butterworth filter.

trouble is, it does not working like a filter, more like a reverb !

I attached the code if someone can have a fresh look on it.

thanks

http://www.sensomusic.com/forums/upload ... 0rance.zip

Posted: 28 Jan 2016, 12:03
by oli_lab
eureka !

I made 2 dimensionnal buffers instead of simple array, that was the mistake !

Now it sounds like there will be a new creative filter in the Usine wardrobe !

have to do some work on the resonance...

//The filter algo:
//out(n) = a1 * in + a2 * in(n - 1) + a3 * in(n - 2) - b1*out(n - 1) - b2*out(n - 2)
{
sdkSmoothPrecision(cutoff, m_cutoff, 0.1f);
computeCoeff();
for (int i = 0; i < numOfAudiotInsOuts; i++)
{
sdkCopyEvt(audioInputs, audioOutputs);
//filter
for (int j = 0; j < sdkGetEvtSize(audioOutputs); j++)
{
signal = a1 * sdkGetEvtArrayData(audioInputs, j);
signal += a2 * audioBufferN1;
signal += a3 * audioBufferN2;
signal -= b1 * audioBufferN1;
signal -= b2 * audioBufferN2;
//output
sdkSetEvtArrayData(audioOutputs, j, signal);
audioBufferN2 = audioBufferN1[i];
audioBufferN1[i] = signal;
}
}
}

Posted: 29 Feb 2016, 21:33
by oli_lab
At last, I managed to have a working audio ramp !

void packetsSynth::onProcess ()
{
sdkSetEvtSize(audioOutputs, sdkGetBlocSize());
//sawtooth generator
for (int j = 0; j < sdkGetBlocSize(); j++)
{
saw += m_frequency * invSamplerate * 2.0f;
if (saw >= 1.0f) {
saw = -1.0f;
}
sdkSetEvtArrayData(audioOutputs, j, saw);
}
}

that is the begining of a new era (at least for me)