[LAD] using libsndfile to write signed short

Joël Krähemann weedlight at gmail.com
Sat Sep 27 05:11:37 UTC 2014


On Fri, 2014-09-26 at 13:40 +0200, Joël Krähemann wrote:
> On Fri, 2014-09-26 at 12:15 +0200, Joël Krähemann wrote:
> > On Fri, 2014-09-26 at 10:20 +0200, Cedric Roux wrote:
> > > On 09/25/2014 11:50 PM, Joël Krähemann wrote:
> > > > void
> > > > ags_sndfile_write(AgsPlayable *playable, signed short *buffer, guint
> > > > buffer_length)
> > > > {
> > > >    AgsSndfile *sndfile;
> > > >    sf_count_t multi_frames, retval;
> > > >
> > > >    sndfile = AGS_SNDFILE(playable);
> > > >
> > > >    multi_frames = buffer_length;
> > > >    retval = sf_write_short(sndfile->file, buffer, multi_frames);
> > > 
> > > If buffer_length gives the number of bytes of the buffer,
> > > you may be in trouble here. For sf_write_short, /usr/include/sndfile.h
> > > says:
> > > ** All of these read/write function return number of items read/written.
> > > See also the libsndfile FAQ:
> > > http://www.mega-nerd.com/libsndfile/FAQ.html#Q012
> > > 
> > > HTH
> > > 
> > > >
> > > >    if(retval > multi_frames){
> > > >      //    sf_seek(sndfile->file, (multi_frames - retval),
> > > > SEEK_CUR);
> > > >    }
> > > > }
> > 
> > This is how the buffer is allocated. Strange to me is
> > 
> > multi_frames = buffer_length;
> > 
> > or
> > 
> > multi_frames = sndfile->file->info->channels * buffer_length;
> > 
> > gives about the same size of file.
> > 
> > 
> > 
> >   /* buffer */
> >   devout->buffer = (signed short **) malloc(4 * sizeof(signed short*));
> >   devout->buffer[0] = (signed short *) malloc(devout->dsp_channels *
> > devout->buffer_size * sizeof(signed short));
> >   devout->buffer[1] = (signed short *) malloc(devout->dsp_channels *
> > devout->buffer_size * sizeof(signed short));
> >   devout->buffer[2] = (signed short *) malloc(devout->dsp_channels *
> > devout->buffer_size * sizeof(signed short));
> >   devout->buffer[3] = (signed short *) malloc(devout->dsp_channels *
> > devout->buffer_size * sizeof(signed short));
> > 
> > 
> > 
> 
> The code should be correct rather a problem with the thread tree, once
> more.
> 
> 
> 
> 

Am I correct assuming 1 sample of stereo frames will be written 44100
times by a rate of 44100 Hz audio sampled data?
Whereby one sample contains 2 frames. For one second, this would be a
sized array of:
CHANNELS = 2
buffer_size_per_second = CHANNELS * 44100 * sizeof(signed short);





More information about the Linux-audio-dev mailing list