Welcome to %s forums

BrainModular Users Forum

Login Register

ptAudio Manipulation

Create your own modules in C++
Post Reply
23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 15 Apr 2015, 17:22

So sorry for onc emore quest (ive warned :p)

I got a float buffer array ranging -1 .. 1 contening wav sample info let's say of 1 second lenght 44100.

for now ive created an "AudioOut" ptArray output of blocsize, . and i srub my big buffer array on process procedure.
that works if i connect ausio outs to the array i do hear the escpected audio. but feel it would be more clean, i would get more function if i used a ptAudio instead.

Howerver im currently stuck, don't really understand how to work with.

im tring to precompute/fill a BLOC_SMP_BUFFER of bloc size, then 'apply it to Audioout but that doesn't seem to work that way.

Code: Select all

	if (PLAY)
	{
	BLOC_SMP_BUFFER = new float[BlocSize];

	sdkSetEvtSize(Audio_Out, BlocSize);    //set size temporary here for debug, will be in callback
	sdkSetEvtSize(AudioOut, BlocSize);     // Audio_Out is a ptArray, AudioOut ptAudiio

	CurrentBloc = CurrentBloc + 1;

		if (CurrentBloc > floor(( SMP_DURATION / BlocSize )))      // loops if reaching end of buffer
		{
			CurrentBloc = 0;
		}


		for &#40;int i = 0; i < BlocSize; i++&#41;
		&#123;
			BLOC_SMP_BUFFER&#91;i&#93; = SMP_BUFFER&#91;i + &#40;CurrentBloc * BlocSize&#41;&#93;;            //preparing a blocsize filled buffer

			//sdkSetEvtArrayData&#40;Audio_Out, i, SMP_BUFFER&#91;i + &#40;CurrentBloc * BlocSize&#41;&#93;&#41;;         // old code that was working if ptArrayOut
			//sdkSetEvtPointer&#40;AudioOut, BLOC_SMP_BUFFER&#41;;
		&#125;

		sdkSetEvtPointer&#40;AudioOut, BLOC_SMP_BUFFER&#41;;                  // trying to set the ptaudio out,   doesn't seem to work, what's the correct way of doing?


	&#125;
any enlightments?

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

Unread post by martignasse » 15 Apr 2015, 21:19

mmmm, lots of confusions here

i'll try to clarify

first of all, if you do this code in the onProcess, you are massively leaking memory because of this

Code: Select all

BLOC_SMP_BUFFER = new float&#91;BlocSize&#93;;
it mean you allocate a new array every audio tick ! !
plus the fact that you should avoid completly allocating memory in the onProcess callback

but it's not the cause of your problem, you misunderstood the meaning of sdkSetEvtPointer()
it give you the pointer to the event itself, not a pointer to the data of the event.
you should use sdkGetEvtDataAddr() instead.

what you want to achieve can be made more simply, assuming SMP_BUFFER is your 1 second audio buffer array

Code: Select all

	// declare a TPrecision* ptrBufferBloc member in the include file
	if &#40;PLAY&#41;
	&#123;
		// should be in onBlockSizeChanged callback
		sdkSetEvtSize&#40;Audio_Out, BlocSize&#41;;
		sdkSetEvtSize&#40;AudioOut, BlocSize&#41;;
		
		CurrentBloc = CurrentBloc + 1;
		
		// floor&#40;&#40; SMP_DURATION / BlocSize &#41;&#41; can be preconputed outside of onProcess
		// in onBlockSizeChanged callback precisely 
		// but should also take care of when SMP_DURATION change
		if &#40;CurrentBloc > floor&#40;&#40; SMP_DURATION / BlocSize &#41;&#41;&#41;
		&#123;
			CurrentBloc = 0;
		&#125;
		
		ptrBufferBloc = sdkGetEvtDataAddr &#40;AudioOut&#41;;
		memcpy &#40;&#40;void*&#41;ptrBufferBloc, &#40;void*&#41;&#40;SMP_BUFFER + &#40;CurrentBloc * BlocSize&#41;&#41;;
    &#125;&#125;
doc to memcpy here

the code isn't test but should put you on the right track

also note that you loose the end of your SMP_BUFFER in case it's not multiple of BlockSize
Martin FLEURENT - Usine Developer - SDK maintainer

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 15 Apr 2015, 22:03

thanks for response Martin!! yeah i still makes lots of cufussions relating pointers and stuff ^^

for the size yup was not very clear in my comments but every thing occurs in call back onec and only normally.
I try to be carefull to exlude everything that can be out of process thanks for the reminder.

Cool, can't wait to test that :) ! thx a lot! will theck that memcopy thing i missed!

yeay did it quicly for tetst, i have to figure for the non complete buffer stuff.

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 16 Apr 2015, 19:51

Hey martin, ive tweaked a bit and i start to get some results.

however i noticed the audioout was heavy distorded compared to standard array out, ive plugged an array display or set to check and it seems mecopy only copy the first 32 values of my 128 blocsize array, while i specified 128, and audioOut size was set to 128, as the tempbuffer i filled and feed for the bloc copy.

float4bytes, 4x 32 = 128 , might it be related maybe mmm? i keep on investigate

any ideas?

edit : yesss if i multy blocsizeby4 for meme copy that seems to work . ok start to undersatnd :)

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

Unread post by martignasse » 17 Apr 2015, 01:44

yep, mistake from my part, memcpy last parameter is the size in byte, and you are copying some float, so...
Martin FLEURENT - Usine Developer - SDK maintainer

Post Reply

Who is online

Users browsing this forum: No registered users and 112 guests