libsndfile-mixing any number of soundfiles in loop

Discussion in 'C' started by lason.naitsirk, Apr 1, 2009.

Thread Status:
Not open for further replies.
  1. lason.naitsirk

    lason.naitsirk New Member

    Joined:
    Apr 1, 2009
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Hi,

    I am very new in programming (six months), so many apologies for silly questions.
    I intended to write a console prog that uses libsndfile. It is kind of synthetiser. It reads text file created by user, where on each line, the information about parametres of sound synthesis are stored (frequency, amplitude, FM, AM, Additive, envelopes, effects...). For each line there is an corresponding process loop, that counts and performs synthesis and in the end creates *.wav soundfile. So in the end of main loop there are as many soundfiles as number of lines in the text file. These sound files may differ in lenth, but not in number of channels and samplerate, there are given names by the number of line in text file, that represents their data (i.e.: 0.wav, 1.wav, 2.wav – for textfile of three lines). This works perfectly...everythink is created and closed, there are no warnings during compilation, console does not fail. – But now should come the easy stuf. I need to mix all the files into one final output file. I want to create an loop taking these temporary files and writing them into the output file in line (witing one after another to the end of output file). I have tryed to do this in several ways, but I am probably not using the sf_seek function correctly, as the files are just rewriting themself...or there is somethink bad with my way of memory managemant. Please can you support me with any idea, what I am doing wrong? Or better, write an example code how to write one *.wav file to the end of another? I am very fresh in c++.

    Thank you very much!!!

    this the relevant part of my code:

    ...closing of predecesing part of code
    |
    v

    for(int i=0; i<n; i++)
    {
    char b[10];
    itoa(i, b, 10 );
    char NAMEIN[8] = {b[0], '.', 'w', 'a', 'v'};

    psfinfoin = (SF_INFO *) malloc(sizeof(SF_INFO));
    psfinfoout = (SF_INFO *) malloc(sizeof(SF_INFO));

    if(!(psfin = soundin_open(NAMEIN, chans, sr))){ cout << "error opening output file\n" << NAMEIN << endl; exit(-1);}
    else cout << "soubor " << NAMEIN << " uspesne otevren pro cteni" << endl;

    buffer1= new float [def_len];

    if(!(psfout = soundout_open("out.wav"))){ cout << "error opening output file\n" << endl; exit(-1);}
    else cout << "soubor <out.wav> otevren pro psani" << endl;
    do {
    sf_seek(psfout, 0, SEEK_END);
    count1 = sf_readf_float(psfin, buffer1, def_len);
    sf_writef_float(psfout, buffer1, count1);
    }
    while(count1);
    soundin_close(psfin);
    soundout_close(psfout);
    free(psfinfoin);
    free(psfinfoout);
    free(buffer1);
    }

    |
    v

    than delete all temporary files...and end the code
    _________________________________________
    I know that I am mixing C with C++, but seems to me, that it is not the problem.
    Integer n in for loop is the number of files plus 1. <def_len> in the code has value of 1024.

    p.s.: sorry for my English, still learning

    Thank you,
    K.
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
Thread Status:
Not open for further replies.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice