> for(i=0, i < BUFFRAMES; i++;) Hi Pablo,
I don't have time to look at the whole thing at the moment. I know that you're a beginner, but the FIRST thing you need to do is carefully "proof read" each line of code and ask yourself if it's right. For instance, look at your FOR loop. above. It should look like this: for (initial_condition; test_condition; each_time) Your "initial_condition": i=0, i < BUFFRAMES; Your "test_condition": i++; Your "each_time": <nothing at all> So, your test condition is true for a LONG LONG TIME (until the integer rolls back to zero). SECOND, you need to learn how to use your debugger and check that things are doing what you think they are doing. There are websites that are better suited to beginner questions than this mailing list, where you'll have a lot of people eager to look at your code and give much quicker turn around. Good luck. On Jan 24, 2014, at 8:49 AM, Pablo Frank <[email protected]> wrote: > After initializing psf_out2, initializing psfinfo_out to zero, and correcting > the if, as displayed below at (1), the code displayed below in (2) still > generates an empty stereo file. The correction of the code will be greatly > thanked, pointing errors will probably continue to cause misunderstandings > (i'm a beginner, sorry). > > > (1) > You never open psf_out2 si writing to it will be a disaster. > Also it is safer to initialise psfinfo_out to zero > > psfinfo_out= (SF_INFO *) calloc(1,sizeof(SF_INFO)); > > ///////////// > >> // check if file is mono or stereo >> if (!(psfinfo_out->channels = 2)) >> >> /* allocate buffer memory */ >> buffer = (float *) malloc(sizeof(float)*BUFFRAMES); >> out = (float *) malloc(sizeof(float)*BUFFRAMES*2); > > I think you mean > > if (psfinfo_out->channels != 2) { > … > } > > Note missing brackets, plus the logical comparison versus your assignment > ("=2") > > The missing brackets will make it work like this: > > if (…) > buffer = … > > out = ... > > So, the buffer won't be allocated, since the "if" always evaluated to false… > > /////////////////////////////////////////////////////////////////////// > > (2) > #include <stdio.h> > #include <stdlib.h> > #include <sndfile.h> > > #define BUFFRAMES 512 > > void usage(); > > int main(int argc, char** argv) { > > SNDFILE *psf_in, *psf_out,*psf_out2; > SF_INFO *psfinfo_in, *psfinfo_out; > float *buffer, *out; > sf_count_t count; > int chans; > > if(argc < 3) { > usage(); > exit(-1); > } > > /* memory for SF_INFO structures */ > psfinfo_in = (SF_INFO *) calloc(1,sizeof(SF_INFO)); > psfinfo_out = (SF_INFO *) calloc(1,sizeof(SF_INFO)); > > /* open input */ > if(!(psf_in = sf_open(argv[1],SFM_READ,psfinfo_in))){ > printf("error opening input file\n"); > exit(-1); > } > > // check if file is mono or stereo > if (psfinfo_out->channels != 2){ > > > /* allocate buffer memory */ > buffer = (float *) malloc(sizeof(float)*BUFFRAMES); > out = (float *) malloc(sizeof(float)*BUFFRAMES*2); > > /* Now we initialise the SF_INFO structure > > with the same sampling rate... */ > psfinfo_out->samplerate = psfinfo_in->samplerate; > /* ... same number of channels... */ > psfinfo_out->channels = 2; > //<-------------------------------------Stereo FILE > chans = psfinfo_in->channels; > > /* and WAV format with the same precision */ > psfinfo_out->format = SF_FORMAT_WAV | (psfinfo_in->format & > SF_FORMAT_SUBMASK); > } > > > /* now we open the file */ > if(!(psf_out = sf_open(argv[2], SFM_WRITE,psfinfo_out)) || !(psf_out2 = > sf_open(argv[2], SFM_WRITE,psfinfo_out))) { > printf("error opening output file\n"); > exit(-1); > } > > /* and we copy the data, frame by frame */ > do { > int i; > count = sf_readf_float(psf_in, buffer, BUFFRAMES); > > for(i=0, i < BUFFRAMES; i++;) > out[i] = buffer[i]; > > sf_writef_float(psf_out, out, count); > sf_writef_float(psf_out2, out, count); > } > while(count); > > > > > sf_close(psf_in); > sf_close(psf_out); > sf_close(psf_out2); > free(psfinfo_in); > free(psfinfo_out); > free(buffer); > return 0; > } > > > > void usage(){ > printf("\nusage: aiff2wave input.aif output.wav\n"); > } > > > > > > -- > dupswapdrop -- the music-dsp mailing list and website: > subscription info, FAQ, source code archive, list archive, book reviews, dsp > links > http://music.columbia.edu/cmc/music-dsp > http://music.columbia.edu/mailman/listinfo/music-dsp -- dupswapdrop -- the music-dsp mailing list and website: subscription info, FAQ, source code archive, list archive, book reviews, dsp links http://music.columbia.edu/cmc/music-dsp http://music.columbia.edu/mailman/listinfo/music-dsp
