[asterisk-dev] [help] Asterisk App dev buffer problem

Eric Locey e.locey at hotmail.com
Thu Apr 1 12:12:38 CDT 2010


I'm not sure if this is the right 'forum' for this, but it seems to be the best I can find. If theres a better place or an example or a google term I should have tried, feel free to tell me to stuff it and 'go X'. Just want a point in the right direction. App development seems a dark corner in terms of available info :)
 
What I'm trying to to: use soxlib to pull audio from a file and play it on a channel, allowing on the fly conversion.
Limitations of what I have right now: I'm aware it will only work with single channel audio, and only with the right sample rate etc etc. Just proof of concept at this point. I also am aware it uses several bad coding practices, goal right now is functional :)
 
Whats it do: pulls samples at 160 samples per frame, puts them on the channel, after 25 frames (25*160*2(bytes) = 8000, buffer size?) asterisk segfaults. It seems to be putting the frames in to fast. I hear like the first second of audio right before this happens.
 
The sox stuff actually seems to work perfectly based on the fact what I hear does sound like my audio file.
Only posted the relevent section the app itself does work, I had a version I did that preconveted using sox, but its that delay to do that I'm trying to get rid of.
 
while (((res = ast_waitfor(chan, -1)) > -1) && (f = ast_read(chan))) {  
     blocks++;
     ast_verbose(VERBOSE_PREFIX_3 "Start: %i\n",blocks);     
    if (f->frametype != AST_FRAME_VOICE || f->subclass != AST_FORMAT_SLINEAR) 
     continue;
     ast_verbose(VERBOSE_PREFIX_3 "frame is mine:\n");     
     size_t i;     
   block_size = f->samples;
   f->delivery.tv_sec = 0;
   f->delivery.tv_usec = 0;
   if(option_verbose > 2) 
    ast_verbose(VERBOSE_PREFIX_3 "Playback block size: %i\n",block_size);     
    
   if(sox_read(in, buf, block_size) != block_size) {
    // EOF, I think
    if(option_verbose > 2)
     ast_verbose(VERBOSE_PREFIX_3 "Playback hit EOF: %i\n",blocks);
    break;
   }
   short *sdata;
   sdata = (short*)f->data;
   i = f->samples;
   while(i--) {
    SOX_SAMPLE_LOCALS;
    *sdata++ = SOX_SAMPLE_TO_SIGNED_16BIT(buf[i],in->clips);      
   }
   ast_write(chan, f);
   ast_frfree(f);   
  }     

I also had a version where I tried making my own frames, with similar effects.
  for (i = 0; i < block_size; ++i) {
        SOX_SAMPLE_LOCALS;
       //double sample = SOX_SAMPLE_TO_FLOAT_64BIT(buf[i],);
      short newsample = SOX_SAMPLE_TO_SIGNED_16BIT(buf[i],in->clips); 
       newbuff[i] = newsample;
       
      }
      */
      // build our own frame?
     /*
      fr = malloc(sizeof(struct ast_frame));
       fr->frametype = AST_FRAME_VOICE;
    fr->subclass = AST_FORMAT_SLINEAR;
    fr->samples = block_size;
    fr->data = &newbuff;
    fr->datalen = sizeof(newbuff); 
    ast_write(chan,fr);
    */
    
   // blocks++;  
    //ast_frfree(fr);
  // }
 
Please let me know if theres somewhere I should I look method I could try, where I should go from here :)
I'm not worried about multichannel/changing sample rate, I've got all the resources I need to figure that out, once I can get the playback working in asterisk without the segfaults. 		 	   		  
_________________________________________________________________
Live connected with Messenger on your phone
http://go.microsoft.com/?linkid=9712958
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digium.com/pipermail/asterisk-dev/attachments/20100401/1cfecd8c/attachment.htm 


More information about the asterisk-dev mailing list