All pastes #143260 Raw Edit

Untitled

public text v1 · immutable
#143260 ·published 2006-08-21 23:24 UTC
rendered paste body
 * First, I have a sound.c file, which have to care about soundfiles and isolate their frames into an array.
I have defined the Sound type as this:

typedef struct  
{
    char        *name ;
    SF_INFO     infos ;
    float       *tabframes ; /* the array contening the frames */
    double      position ;
    int         error ;
    int         filled ;
} Sound;

  In this sound.c, a soundfile is read with this function:

Sound
sound_new( const char *name, const char *filename ) 
{

    Sound           new_sound ;
    sf_count_t      lu ;
    SNDFILE         *stream ;
    

    if (filename) {
        new_sound.name = strdup(name) ;

        /* read the wav file */
        if (( stream = sf_open(filename, SFM_READ, &(new_sound.infos)) ) == NULL ) {
            new_sound.error = 1 ;
            return new_sound ;
        }

        new_sound.tabframes = calloc((new_sound.infos.frames * new_sound.infos.channels), sizeof(float)) ;
        lu  = sf_readf_float(stream, new_sound.tabframes, (int) new_sound.infos.frames) ;

        if ( lu != new_sound.infos.frames ) {
            new_sound.error = 1 ;
            return new_sound ;
        }

        new_sound.position = 0 ; /* will be used to know where to begin the read in jack process() */
        new_sound.filled = 1 ;

        sf_close(stream) ;
    }
    /* returning a void Sound if no filename is given, in order to populate the sampler*/

    return new_sound ;

}

 * And here is my process() from jack.c . The Sampler type does nothing much for now but holding Samples that are created (they are hold in a_Sampler.bank[] )

int
process(jack_nframes_t nframe, void *args)
{

    jack_default_audio_sample_t *out ;
    int                         i, j ;
    float                       frame2play ;
    Sampler                     *instant_sampler ;

    get_sampler(&instant_sampler) ; /* this function is used to get the actual sampler */
    for (i=0; i<MAXSAMPLES; i++) {
        if (instant_sampler->bank[i].filled) {

            out = (jack_default_audio_sample_t *) jack_port_get_buffer(output_port, nframe ) ;

           for (j=0; j<nframe; j++) {
                memcpy(out, (jack_default_audio_sample_t *) &instant_sampler->bank[i].tabframes[j], 1) ;
                instant_sampler->bank[i].position += 1 ;
           }
        }
    }

    return(0) ;
}

 * My problem is that the memcpy always make a segfault in the last occurence of the 'for' loop, in process() . 
Even if I put " for (j=0; j<2; j++) " instead, it segfault.
  I have looked in gdb what's going wrong, but don't find a clue. instant_sampler contains the good values, and all the occurences of the for loop run well before the last (but I don't have sound, anyway)...

  Can anyone help me?

  elmekki dot olivier @ neuf dot fr