<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
--></style>
</head>
<body class='hmmessage'>
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 :)<BR> <BR>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.<BR>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 :)<BR> <BR>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.<BR> <BR>The sox stuff actually seems to work perfectly based on the fact what I hear does sound like my audio file.<BR>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.<BR> <BR>while (((res = ast_waitfor(chan, -1)) > -1) && (f = ast_read(chan))) { <BR> blocks++;<BR> ast_verbose(VERBOSE_PREFIX_3 "Start: %i\n",blocks); <BR> if (f->frametype != AST_FRAME_VOICE || f->subclass != AST_FORMAT_SLINEAR) <BR> continue;<BR> ast_verbose(VERBOSE_PREFIX_3 "frame is mine:\n"); <BR> size_t i; <BR> block_size = f->samples;<BR> f->delivery.tv_sec = 0;<BR> f->delivery.tv_usec = 0;<BR> if(option_verbose > 2) <BR> ast_verbose(VERBOSE_PREFIX_3 "Playback block size: %i\n",block_size); <BR> <BR> if(sox_read(in, buf, block_size) != block_size) {<BR> // EOF, I think<BR> if(option_verbose > 2)<BR> ast_verbose(VERBOSE_PREFIX_3 "Playback hit EOF: %i\n",blocks);<BR> break;<BR> }<BR> short *sdata;<BR> sdata = (short*)f->data;<BR> i = f->samples;<BR> while(i--) {<BR> SOX_SAMPLE_LOCALS;<BR> *sdata++ = SOX_SAMPLE_TO_SIGNED_16BIT(buf[i],in->clips); <BR> }<BR> ast_write(chan, f);<BR> ast_frfree(f); <BR> } <BR><BR>I also had a version where I tried making my own frames, with similar effects.<BR> for (i = 0; i < block_size; ++i) {<BR> SOX_SAMPLE_LOCALS;<BR> //double sample = SOX_SAMPLE_TO_FLOAT_64BIT(buf[i],);<BR> short newsample = SOX_SAMPLE_TO_SIGNED_16BIT(buf[i],in->clips); <BR> newbuff[i] = newsample;<BR> <BR> }<BR> */<BR> // build our own frame?<BR> /*<BR> fr = malloc(sizeof(struct ast_frame));<BR> fr->frametype = AST_FRAME_VOICE;<BR> fr->subclass = AST_FORMAT_SLINEAR;<BR> fr->samples = block_size;<BR> fr->data = &newbuff;<BR> fr->datalen = sizeof(newbuff); <BR> ast_write(chan,fr);<BR> */<BR> <BR> // blocks++; <BR> //ast_frfree(fr);<BR> // }<BR> <BR>Please let me know if theres somewhere I should I look method I could try, where I should go from here :)<BR>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.                                            <br /><hr />Take your contacts everywhere. <a href='http://go.microsoft.com/?linkid=9712958' target='_new'>Try Messenger for mobile</a></body>
</html>