# running code on a better computer online

This topic is 1777 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have this code I created that will take a long time to finish, around 100 hours in my computer

do you know any place on the internet that will run the code on a much better computer and then send me the output by email

the code is small, it reads a .wav file of 40 MBytes and the output is the .wav file modified but with the same size

the code uses one thread too

In C++ code

Edited by lomateron

##### Share on other sites
I have a really fast computer! Send me the code, the wav file, and \$1,250 USD, and I will have it done by the next day.
(Partially serious.)

What sort of processing are you doing on the audio?

(40MB wav @ 44100 samples/s stereo ~ 7 minutes 33 seconds) Edited by fastcall22

##### Share on other sites

Seriously post us your code so maybe we can optimize it by some order of magnitude faster. Most of the time, when something take that long for such a small data set, your algorithm is wrong and could be optimized better.

I had this routine in my 3d model exporter that calculated vertex normals and it took O(n2) time to finish, that mean, if i had 10000 vertices to process, i would have to do

10000 x 10000 = 1,000,000,000 iteration, wich would take like 5 mins sometime for big models, much less for small mesh but still. Then i optimized it with only 1 loop instead of 2 using a clever trick i though of, and then bam, the algo run in a fraction of a second no matter the mesh size, ie: O(n).

Im not saying that you can achieve exactly that same ammout of speed up as in my example but it's possible you are doing something wrong without knowing it.

Edited by Vortez

##### Share on other sites

My pc is too slow, it's an old laptop

I want someone to run it on their powerfull CPU

I really want to know how the new .wav file will sound so here is the code:

* it only works with .wav....16bit....stereo......44100

* put your .wav file in the folder where the project is and name it "a.wav"

* its around O((n^2-n)/2) ......n=number of sampes in one channel

* because of this I recommend using from Coldplay "A hopeful transmission.wav", it's 33 seconds

or a minimun of a 10 second complex repetitive music

* the code maybe has bugs(I found one when reading a very old .wav file music)

To know how much is left to finish:

the code will output at the start 2 lines the first line is a number X

the second line is:  0,X ....sometimes (X=X-1)

the third will be : 1,X

the fourth: 2,X

the fifth: 3,X

and so on until it reaches: X,X

#include <stdio.h>
#include <fstream>
#include <iostream>

int main ()
{
FILE* fp = fopen("a.wav","rb");
FILE* FW = fopen("sound.wav","wb");
short* dutu;

if (fp==NULL)
{
return 0;
}

char id[5];
unsigned long size;
short format_tag, channels, block_align, bits_per_sample;
unsigned long format_length, sample_rate, avg_bytes_sec, data_size;

fwrite(id, sizeof(char), 4, FW);
id[4] = '\0';

if (!strcmp(id, "RIFF"))
{
fwrite(&size, sizeof(unsigned long), 1, FW);
fwrite(id, sizeof(char), 4, FW);
id[4] = '\0';

if (!strcmp(id,"WAVE"))
{

fwrite(id, sizeof(char), 4, FW);
fwrite(&format_length, sizeof(unsigned long),1,FW);
fwrite(&format_tag, sizeof(short), 1, FW);
fwrite(&channels, sizeof(short),1,FW);
fwrite(&sample_rate, sizeof(unsigned long), 1, FW);
fwrite(&avg_bytes_sec, sizeof(unsigned long), 1, FW);
fwrite(&block_align, sizeof(short), 1, FW);
fwrite(&bits_per_sample, sizeof(short), 1, FW);

fwrite(id, sizeof(char), 4, FW);
fwrite(&data_size, sizeof(unsigned long), 1, FW);

dutu=new short[data_size];
data_size=data_size/sizeof(short);
}
}
fclose(fp);
unsigned __int32 lo=data_size/2;
fwrite(dutu, sizeof(short), lo, FW);

unsigned short* res=new unsigned short[65536];

unsigned short mani=0,valu;
bool conti=true;
unsigned short mxs;int mxv;short chui;
unsigned __int32 lo2,lom;

lo=data_size/2;
bool* boli=new bool[lo];

lom=(lo/2)+unsigned __int32(lo & 1);
lo/=2;
std::cout << lo;

unsigned __int32 cin;
for(unsigned __int32 can=0;can<lo;can++)
{
lo2=lom+can;
std::cout << "\n" << can << "," << lo2 << "\n";
for(unsigned __int32 cen=1;cen<lo2;cen++)
{
//std::cout << cen << ",";

cin=cen;
for(unsigned __int32 con=lo2-cin;con!=4294967295;con--)
{
boli[con]=dutu[(con+cen)*2]==dutu[con*2];
}

for(cin=cen;cin<lo2;cin++)
{
conti=true;mani=0;
for(unsigned __int32 con=lo2-cin;con!=4294967295 && conti;con--)
{
//guu=dutu[(con+cen)*2]==dutu[con*2];
if(con==lo2-cin)
{
conti=boli[con];
valu=dutu[con*2]+32768;
}
else if(boli[con])
{
conti=dutu[(con+cin+cen)*2]==dutu[con*2];
mani+=conti;
}
}
res[valu]+=conti*mani;
}
}

mxs=0;mxv=0;
for(unsigned __int32 cen=0;cen<65536;cen++)
{
if(res[cen]>mxs)
{
mxs=res[cen];
mxv=int(cen);
}
}
mxv-=32768;
chui=mxv;
dutu[(lo2+1)*2]=chui;

fwrite(&chui, sizeof(short), 1, FW);chui=0;
fwrite(&chui, sizeof(short), 1, FW);

memset(res, 0, 2*65536);
}
fclose(FW);

delete[] dutu;
return 0;
}

Edited by lomateron

##### Share on other sites

Fill your buffer in memory and then fwrite it outside the loop... that may help.

##### Share on other sites

Fill your buffer in memory and then fwrite it outside the loop... that may help.

what buffer? the buffer called "dutu"? isn't it in RAM memory?

Edited by lomateron

##### Share on other sites

Well you keep writing out 2 bytes at a time. Allocate all the memory you need, fill it, then write it to disk in one go.

##### Share on other sites

Well i tried and compiled your code, and tested it a bit, but i don't get what it's doing in the loops. Also, i tried with a 2 second sample and it takes forever to do 1 iteration so im not gonna wait a day for this. Seriously, what does that code do? It has like 3 nested loop in it, and that's not good at all for perfs.

The code is not so bad overall but could be improved a lot, you're not initializing your variables and char arrays, and a lot of code is just plain repetition (the header read/write part). And without comments, i can't figure out what you're trying to do at all.

I dont think the disk I/O is the bottleneck, like, at all at this point.

Edited by Vortez

##### Share on other sites
That's a whole lot of looping going on.

I only have time to glance over it, but what I'm seeing scares me. Do you have a link to the algorithm you are trying to implement?

Not sure about if your formulas are correct or what they are supposed to do, but some of that work seems nasty. For a 40MB data file, the loop filling up boli[] is going to process something like 20 million bytes each time through the loop, and you're doing the loop 20 million times. Computing your res values also looks highly suspicious, if I'm reading that correctly you are going to accumulate a value many million times into a 16-bit value, which is going to just result in garbage as it overflows many hundred thousand times. Also it seems possible valu could be uninitialized when it hits res[valu], which would be very bad. Hopefully I'm just tired and misreading all that.

It would be nice to compare the implementation against the actual desired math formulas for whatever you are trying to build, since I'm concerned the code may not be doing what you think it does.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 9
• 15
• 14
• 46
• ### Forum Statistics

• Total Topics
634062
• Total Posts
3015303
×