My code saves algorithm data slowly!


#1

Hi,

I’ve written a plug-in which incorporates a simple echo-canceller (written to disclose the impuls response and the transfer function of some device connected to the sound-card - or simply to see the impulse reponse of the sound-card itself).

I’ve have made a button which when pressed should store the coefficients of the adaptive filter - this works but it takes approx. 30 seconds for the 512 coefficients to be stored in the file which corresponds to 18kb of data. The code used to store the data follows:

[code] if(button==saveButtonSoundCard)
{
currentFileSoundCard = T(“C:\AdapCoefsSoundCard.txt”);

	if(currentFileSoundCard.existsAsFile())
		currentFileSoundCard.deleteFile ();
	else {
		double* pointerCoefs = gl->canvas->pAdapCoefs;
		for(int i=0; i<(gl->canvas->adapOrder) ; i++)
			currentFileSoundCard.appendText(String(*pointerCoefs++) + T(" \n"),false);
	}
} 
if(button==saveButtonTelephone)
{
	currentFileTelephone = T("C:\\AdapCoefsTelephone.txt");

	if(currentFileTelephone.existsAsFile())
		currentFileTelephone.deleteFile ();
	else {
		double* pointerCoefs = gl->canvas->pAdapCoefs;
		for(int i=0; i<(gl->canvas->adapOrder) ; i++)
			currentFileTelephone.appendText(String(*pointerCoefs++) + T(" \n"),false);
	}
} [/code]

Can someone please tell me how the data can be stored faster?

Cheers


#2

Aagh! Not surprising! Every time you call appendText, it has to open the file, create a stream, write the data, flush and close the file!

Use File::createOutputStream() instead!


#3

[quote=“jules”]Aagh! Not surprising! Every time you call appendText, it has to open the file, create a stream, write the data, flush and close the file!

Use File::createOutputStream() instead![/quote]

Hi,

Sorry but I need some babysitting here!

I can’t seem to setup the outputStream correctly - I’m still a newbie!

The class in which the writting of the coefficients take place I inheret the OutputStream as such:

class DemoEditorComponent : public AudioFilterEditor, public ChangeListener, public SliderListener, public ComboBoxListener, [b]public FileOutputStream [/b]

These added code lines gives me the following errors:

[code][i] ..\..\src\DemoEditorComponent.cpp(47) : error C2512: 'juce::FileOutputStream' : no appropriate default constructor available ..\..\src\DemoEditorComponent.cpp(47) : error C2512: 'juce::FileOutputStream' : no appropriate default constructor available[/i][/code]

Can you please explain what I’m doing wrong here?

Thanks[/b]


#4

you’re getting very tangled up there… Just create an output stream with File::createOutputStream, and write to it, then delete it. You don’t need to inherit from it.


#5

Hi again,

Ok, if I can’t use .appendText or .appendData how can I then write my data using OutputStream - I can’t seem to find others methods that can do writting?

Is the structure below correct (except for the pseudo-code line)?

if(button==saveButtonSoundCard) { currentFileSoundCard.createOutputStream(2048); if(currentFileSoundCard.existsAsFile()) currentFileSoundCard.deleteFile (); else { double* pointerCoefs = gl->canvas->pAdapCoefs; for(int i=0; i<(gl->canvas->adapOrder) ; i++) WRITE DATA TO FILE } }


#6

no, you use the stream object to do the writing… Do a search through the juce codebase for some of the places where I use createOutputStream, and see if you can get any tips from that!


#7

Solved…

Thanks for the guidelines!

[code]File AdapCoefsSoundCard(T(“C:\AdapCoefsSoundCard.txt”));
pFileSoundcard =new FileOutputStream(AdapCoefsSoundCard);

double* pointerCoefs = gl->canvas->pAdapCoefs;
for(int i=0; i<(gl->canvas->adapOrder) ; i++)
pFileSoundcard->writeText(String(*pointerCoefs++) + T(" \n"),false,false);
delete pFileSoundcard;[/code]


#8