Welcome to %s forums

BrainModular Users Forum

Login Register

audio ramp generator

Create your own modules in C++
Post Reply
User avatar
oli_lab
Member
Posts: 1261
Location: Brittany, France
Contact:

Unread post by oli_lab » 30 Dec 2015, 14:06

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
http://oli-lab.org

Win11 Ryzen9/32GB RAM - RME MADIFACE - SSL alpha link 4-16 - OSC capable interfaces

follow OLI_LAB adventures on Mastodon
@olivar_premier@mastodon.social

User avatar
oli_lab
Member
Posts: 1261
Location: Brittany, France
Contact:

Unread post by oli_lab » 06 Jan 2016, 12:19

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);
}
}
http://oli-lab.org

Win11 Ryzen9/32GB RAM - RME MADIFACE - SSL alpha link 4-16 - OSC capable interfaces

follow OLI_LAB adventures on Mastodon
@olivar_premier@mastodon.social

User avatar
oli_lab
Member
Posts: 1261
Location: Brittany, France
Contact:

Unread post by oli_lab » 06 Jan 2016, 13:41

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...
http://oli-lab.org

Win11 Ryzen9/32GB RAM - RME MADIFACE - SSL alpha link 4-16 - OSC capable interfaces

follow OLI_LAB adventures on Mastodon
@olivar_premier@mastodon.social

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 06 Jan 2016, 15:47

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);

User avatar
oli_lab
Member
Posts: 1261
Location: Brittany, France
Contact:

Unread post by oli_lab » 07 Jan 2016, 10:26

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
http://oli-lab.org

Win11 Ryzen9/32GB RAM - RME MADIFACE - SSL alpha link 4-16 - OSC capable interfaces

follow OLI_LAB adventures on Mastodon
@olivar_premier@mastodon.social

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 07 Jan 2016, 14:32

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 .

User avatar
oli_lab
Member
Posts: 1261
Location: Brittany, France
Contact:

Unread post by oli_lab » 07 Jan 2016, 18:48

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....
http://oli-lab.org

Win11 Ryzen9/32GB RAM - RME MADIFACE - SSL alpha link 4-16 - OSC capable interfaces

follow OLI_LAB adventures on Mastodon
@olivar_premier@mastodon.social

martignasse
Site Admin
Posts: 611
Location: Lyon, FRANCE
Contact:

Unread post by martignasse » 15 Jan 2016, 19:25

hey oli,

maybe i can help with this, but i need to see your source code for that ;)
Martin FLEURENT - Usine Developer - SDK maintainer

User avatar
oli_lab
Member
Posts: 1261
Location: Brittany, France
Contact:

Unread post by oli_lab » 15 Jan 2016, 20:05

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...
http://oli-lab.org

Win11 Ryzen9/32GB RAM - RME MADIFACE - SSL alpha link 4-16 - OSC capable interfaces

follow OLI_LAB adventures on Mastodon
@olivar_premier@mastodon.social

User avatar
oli_lab
Member
Posts: 1261
Location: Brittany, France
Contact:

Unread post by oli_lab » 27 Jan 2016, 20:05

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
http://oli-lab.org

Win11 Ryzen9/32GB RAM - RME MADIFACE - SSL alpha link 4-16 - OSC capable interfaces

follow OLI_LAB adventures on Mastodon
@olivar_premier@mastodon.social

User avatar
oli_lab
Member
Posts: 1261
Location: Brittany, France
Contact:

Unread post by oli_lab » 28 Jan 2016, 12:03

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;
}
}
}
http://oli-lab.org

Win11 Ryzen9/32GB RAM - RME MADIFACE - SSL alpha link 4-16 - OSC capable interfaces

follow OLI_LAB adventures on Mastodon
@olivar_premier@mastodon.social

User avatar
oli_lab
Member
Posts: 1261
Location: Brittany, France
Contact:

Unread post by oli_lab » 29 Feb 2016, 21:33

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)
http://oli-lab.org

Win11 Ryzen9/32GB RAM - RME MADIFACE - SSL alpha link 4-16 - OSC capable interfaces

follow OLI_LAB adventures on Mastodon
@olivar_premier@mastodon.social

Post Reply

Who is online

Users browsing this forum: No registered users and 42 guests