Assigning values to buffers


I am developing my first synthesiser using juce.
I have run into a problem involving Buffers.
I declare a buffer of size = vector size.

When running the built application
it crashes after one run. The output sound file is created. Then
the application crashes.

[code]buffer = new float[def_vsize];

buffer = car.Proc(amp[j],freq[j]);…car.proc = class

However if i skip the buffer line and run sound out as below, the built.exe
runs all the time.

Is there a special way of dealing with these sort of buffers in Juce.
I have a version using buffers of the synthesiser without juce, no user interface,
which works fine.

Thanks in advance


buffer = car.Proc(…) means that you reaffect the pointer to whatever pointed by car.Proc(…)

You should memcpy the buffer DATA instead (memcpy(buffer, car.Proc(…), size)).

Also, make sure you are deleting the buffer just after the call (I don’t know if soundout copies the buffer (in that case, your buffer is useless), or not).

Thank you for the reply, I just need to ask one more question about, where to but the delete memory function. I have attached a shortened version of the code to show where i have it currently.

[code]modsig = new float[def_vsize];

wave = sinus_table();

// open sound file error message if fails

if(!(psf = soundout_open(“output.wav”))){
printf(“error opening output file\n”);

Osc mod(wave); //oscillation generater class

for(int i=0; i < dur_smps[j]; i++){

memcpy(modsig, mod.Proc(.1f, 400.f), def_vsize);
soundout(psf,modsig);//libsound soundout function


// close file & free memory
delete[] modsig;

return 0;

} [/code]