Welcome to %s forums

BrainModular Users Forum

Login Register

Wav files handles

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

Unread post by 23fx23 » 06 Apr 2015, 16:55

ima bit stucked on this one.
i could sucessfully create my first module with all i/o , start to manipulates datas ect (big up for the exemples!)

but i got a console error on that part and i fail to understand, maybe someone could help?

Basically i got an array of float id'like to fill in a wav file and then write/load/stream

Code: Select all

		AudioFilePtr kick;
		kick = sdkCreateAudioFile();
		sdkSetChannelsAudioFile(kick, 1);
		sdkSetSizeAudioFile(kick, 22050);

		float * SMP_BUFFER = new float[22050];
		for &#40;int i = 0; i < Psize; i++&#41;
		&#123;
			FX&#91;i&#93; = sdkGetEvtArrayData&#40;Mem_FX, i&#41;;
			FY&#91;i&#93; = sdkGetEvtArrayData&#40;Mem_FY, i&#41;;
			AX&#91;i&#93; = sdkGetEvtArrayData&#40;Mem_AX, i&#41;;
			AY&#91;i&#93; = sdkGetEvtArrayData&#40;Mem_AY, i&#41;;
			i++;
		&#125;
		DRAW_KICK&#40;FX, FY, AX, AY, Psize, MinF, MaxF, 22050, SMP_BUFFER&#41;;
		 int j;
		j = 0;
		while &#40;j < 22050&#41;
		&#123;
			sdkSetSampleAudioFile&#40;kick, 1, j, SMP_BUFFER&#91;j&#93;&#41;;
			j++;
		&#125;
	       sdkSaveToDiskAudioFile&#40;kick, "usinekick.wav", 1&#41;;
Ive muted all the code down to up and i got the error even with first two lines actives:

AudioFilePtr kick;
kick = sdkCreateAudioFile();

I suppose im doing wrong...still total c noob :/ ,any ideas on whats the correct the way to proceed?

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 07 Apr 2015, 13:47

by waiting i created a custom function tweaked from the web to write a wav without sdk to check the code. it seems ok and create a functionnal wav file at usine folder main path, but feel it would be better/more clean with implemented with sdk function... will test the loads function from this file, maybe will help to understand.

ceasless
Member
Posts: 330
Contact:

Unread post by ceasless » 07 Apr 2015, 18:03

Hey there,

Easier to debug if you share the error :D

But maybe this is also a case of needing to define it as a private member of the class?

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 07 Apr 2015, 21:37

hi ceasless
, yup sorry i failed to understand yet how to trace/debug efficiently , it's very fresh for me, just one week i tied C++ and sdk, im a bit lost ^^
the file compiled corectly but when i called to trig that part via a button on callback or process i i had a red 'error process' in trace without specific message.
didn't yet fully understand/check classes, thanks for input, i will investigate! :)

ceasless
Member
Posts: 330
Contact:

Unread post by ceasless » 07 Apr 2015, 23:16

Good point -- it would be nice to have clearer error messages in the trace log :(

With the member of class thing, essentially you move the declaration of the kick pointer into the class definition, which is stored in the header (.h) file. Apologies if you already know these things, just trying to be helpful.

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 08 Apr 2015, 01:27

oh don't be i got ALLLl to learn lol ^^ im taking every single advice

im really at the early stage, was starting to be ok with delphi scripting langage but getting into compiling and C++
i see it's a waaay diffrernt thing i face.. u know like dynamic array stuff/ global variables transmissions/ char stings ect.. a bit much harder^^ i slowly try to catch the concepts..hopefully my girlfriend made a tiny bit of c by the past and she tried to exlained few things like the header thing, i don't get all yet but from what i understood it's kinof 'summary' pre-proc link for easier process but it semms much more and i have to catch the classes.
will check and document on this, and will try this many thanks!

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

Unread post by martignasse » 13 Apr 2015, 10:05

ceasless wrote:Good point -- it would be nice to have clearer error messages in the trace log :(.
hehe, of course, but we are in C++ and in the process function, which is The real time function.

On the Usine side, the Process function is optimized in a way to minimize logs has printing string/char has a big cost (in a real time point of view at least)
In C++, nothing is automatic, but you can add every behavior you want, it's up to you, like use a try/catch block just for debuggging (you remove it after, for release)

@23fx23
in your case, if the code you show us is in the onProcess callback, you can begin by wipe out the creation, config and save of the audio file out of the process, in another place like the onInit callback for the creation and config, for the save, it's more tricky but doable. Do you need to save it on disk in the first place ?
Variable creation mean memory allocation and it's bad to do this in the real time thread which is where the onProcess callback is executed.

maybe you need more C/C++ understanding to deal with this kind of feature, Saving a file to disk in the onProcess callback is just not an option.

hope it help
Martin FLEURENT - Usine Developer - SDK maintainer

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 13 Apr 2015, 13:33

Hi Martin thanks for the suggz,

I first tried in callback and later in process, but you're right i should be more patient ^^hehe. Anyway I first debugged all the stuff and now nearly every thing of the old script works as module :)
the only thing remaining is the wavfile creation/reload stream. I got it working if wrinting on callback with a custom function i copied from the net, that writes the binary header then binary datas. it does work but it writes the wav at usine folder, and usine must be launched as admin, ect, so not very clean solution, but maybe i don't need to save to disk you are righr, will try to get the wav create/fill in callback with sdk functions and play/stream in process, that will be my today exercice :)

Post Reply

Who is online

Users browsing this forum: No registered users and 112 guests