<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.6000.16481" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY style="MARGIN: 4px 4px 1px; FONT: 10pt Tahoma" bgColor=#ffffff>
<DIV>I thought I should be getting 20 words because in the windows app the command line repeats "nbBytes = 20" through the entire decode phase.&nbsp; I wonder how the frames got misaligned...right now I get 10 words of data followed by 10 words of 0's which I look at through a memory window in code composer.&nbsp;now I am pretty sure there is a terminator word that gets in there so that would make 11 words being used.&nbsp; what part of the encoding phase sets the size of the encoded data and how do I change that to 20 instead of 10?&nbsp; </DIV>
<DIV>&nbsp;</DIV>
<DIV>well the project doesn't have a "main loop" per-say...it uses the DSP BIOS that comes with code composer which manages all the main looping parts... I'm running off a HW&nbsp;timer interrupt that is set for 8KHz and is constantly taking sound in from the Mic. and outputting to the speaker.&nbsp; when I push a button and tell it to start collecting data from the Mic. and put it into a 160 word buffer, when the buffer is full I trigger a SW interrupt and switch to another buffer (ping-pong), the software interrupt used to do G729A but I have it doing speex instead.&nbsp; speex encodes from that full buffer and places it into the recording buffer.&nbsp; when the recording buffer is full it stops recording and when I hit another button the HW interrupt is told to start outputting to the speaker,&nbsp;when decoding is needed I set a SW interrupt again and data is taken from the recording buffer, decoded and placed in a playing buffer. when the playing buffer is half way through I decide to decode the next chunk to another buffer (ping-pong) and it does that until I run out of data to decode.&nbsp;&nbsp; our ADCs and DACs are 16 bit, so I don't think I need to worry about bytes vs words in the output</DIV>
<DIV>&nbsp;</DIV>
<DIV>I don't know if you care about any of that but maybe it'll help.&nbsp; it's not exactly an idle loop but it's close enough so that it should be able to work the same right?&nbsp; the only deviation I do from the testenc is I don't use the callbacks, set the complexity, or disable VBR&nbsp;and I have my own bit buffer so I don't rewind or reset the bits.</DIV>
<DIV>&nbsp;</DIV>
<DIV>-Mike</DIV>
<DIV><BR>&gt;&gt;&gt; "Jim Crichton" &lt;jim.crichton@comcast.net&gt; 07/24/07 3:19 PM &gt;&gt;&gt;<BR></DIV>
<DIV style="FONT: 10pt Tahoma; COLOR: #000000">
<DIV><FONT face=Arial>Mike,</FONT></DIV>
<DIV><FONT face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial>Generally "Invalid mode encounterd" == "frames are misaligned"</FONT></DIV>
<DIV><FONT face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial>You should be getting 20 bytes from the encoder each time, and passing 20 bytes to the decoder each time.&nbsp; Is it correct that you have modeled your&nbsp; main loop after testenc-TI-c5x.c?</FONT></DIV>
<DIV><FONT face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial>If you look at encoded silence with a binary editor, you should be able to see the 20-byte repetition pattern.&nbsp; You can also use the sample simulator build, if you can capture your encoder output to a file.&nbsp; There is a&nbsp;DECODE_ONLY switch in that build, that lets you run just that portion.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial>- Jim</FONT>&nbsp;</DIV>
<BLOCKQUOTE dir=ltr style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B> <A title=Michael.Jacobson@ultratec.com href="mailto:Michael.Jacobson@ultratec.com">Michael Jacobson</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=jim.crichton@comcast.net href="mailto:jim.crichton@comcast.net">Jim Crichton</A> ; <A title=speex-dev@xiph.org href="mailto:speex-dev@xiph.org">speex-dev@xiph.org</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Tuesday, July 24, 2007 3:48 PM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> Re: [Speex-dev] Shoehorning speex is confusing a newbie</DIV>
<DIV><BR></DIV>
<DIV>Jean-Marc was correct in that the 16bit value was the culprit for my encoding woes.&nbsp; after I changed that to a 32 bit value I believe it encodes correctly, but I really don't have much of any way to know this absolutely.&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>I am using the 1.2beta2.&nbsp; I would use the enctest program, I have looked it over and based a lot of what I am doing on that code but the project I am developing this on is a little too integrated to be able to start from scratch so I believe I'm going to have to find a way to get it to work in this-here-dohickey.</DIV>
<DIV>&nbsp;</DIV>
<DIV>Jim thank you for the files I'm sure they will come in handy.&nbsp; I have currently hacked out enough of the project that is not required for this proof-of-concept test so that everything seems to fit properly at the moment and I am able to encode over a second and a half of audio to test.&nbsp; I will be looking over the code shortly to see what I can use.</DIV>
<DIV>&nbsp;</DIV>
<DIV>but I'm still having problems.</DIV>
<DIV>&nbsp;</DIV>
<DIV>I decided to run my test now that encode "works" and I get a hopeful result: something I encoded and then decoded came back and I could hear it and I could understand it! unfortunately the quality is so poor it sounds like a cylon, and I know speex is much better than this because I have a windows version that works and the quality is quite high (by quality I mean how it sounds, both systems are using a quality of 4 with 8KHz and 8kbs voice).&nbsp; I think I've narrowed down where the problem is coming from but I have no idea why it is happening.</DIV>
<DIV>&nbsp;</DIV>
<DIV>my problem is that when I go to decode my data the decoder doesn't do anything a lot of the time&nbsp;because it goes here:</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (speex_bits_remaining(bits)&lt;5)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return -1;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; wideband = speex_bits_unpack_unsigned(bits, 1);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (wideband) /* Skip wideband block (for compatibility) */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //int submode;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int advance;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; advance = /*submode =*/ speex_bits_unpack_unsigned(bits, SB_SUBMODE_BITS);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; speex_mode_query(&amp;speex_wb_mode, SPEEX_SUBMODE_BITS_PER_FRAME, &amp;advance);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (advance &lt; 0)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; speex_notify("Invalid mode encountered. The stream is corrupted.");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return -2; //&lt;----------------------*this is where I drop out*<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } </DIV>
<DIV>and drops out with a return of -2 because advance &lt; 0 because wideband = 1.&nbsp; I don't know why it does this. I am guessing that it thinks it's in wideband mode but then isn't encoded for wideband so it drops out with an error because it isn't encoded in the way it thinks it should be.&nbsp;&nbsp; but if the encode didn't work why would it work some of the time and not all of&nbsp;the time?&nbsp; I've also noticed that the encoder will always encode the 160 words into 11 words even though I allocated 21 words for each frame.&nbsp;The guy who did the windows app said that the encoding portion uses a dynamic number of&nbsp;bytes so I don't know if he is wrong or if my encoder isn't doing what it should.&nbsp;&nbsp;if you have any spare time to reply I would really appreciate it.</DIV>
<DIV>&nbsp;</DIV>
<DIV>-Mike<BR><BR>&gt;&gt;&gt; "Jim Crichton" &lt;jim.crichton@comcast.net&gt; 07/24/07 1:33 PM &gt;&gt;&gt;<BR></DIV>
<DIV style="FONT: 10pt Tahoma; COLOR: #000000">
<DIV><FONT face=Arial>Mike,</FONT></DIV>
<DIV><FONT face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial>I did this a year ago on C55 (svn build 11463), and have attached my patches to nb_celp.c, modes.c, and the project file, to remove all modes but 8kbps.&nbsp; I have also attached a debug version of stack_alloc.h, which tracks the maximum depth of the scratch stack, so that you can tweak the sizes in config.h.&nbsp; You just have to declare the variable and add this init before the call to speex_encoder_init, and go back and look at the variable after you run some data through.</FONT></DIV>
<DIV><FONT face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial>#ifdef STACKDBG<BR>&nbsp;&nbsp;&nbsp; spxGlobalScratchFree = spxGlobalScratchPtr;<BR>#endif<BR></FONT></DIV>
<DIV><FONT face=Arial>If you think that the C5416 build is broken, then (as Jean-Marc said) tell us what version you are using.&nbsp; There is a C54x project in the speex source tree that runs directly in the Code Composer simulator.&nbsp; If that fails in the latest code, let me know and I will work on tracking it down.&nbsp; As Jean-Marc indicated, this build does break from time to time because of 16/32-bit conversion problems.&nbsp; I have also had problems with 16/32 bit mismatch in function parameters leading to really bizarre behavior.</FONT></DIV>
<DIV><FONT face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial>You should be able to use the simulator build as a reference to isolate problems between your encoder and decoder (as long as your audio samples are small, the simulator is pretty slow for C54).</FONT></DIV>
<DIV><FONT face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial>Good luck.</FONT></DIV>
<DIV><FONT face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial>- Jim</DIV></FONT>
<DIV><FONT face=Arial></FONT>&nbsp;</DIV>
<DIV>----- Original Message ----- </DIV>
<BLOCKQUOTE style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B> <A title=Michael.Jacobson@ultratec.com href="mailto:Michael.Jacobson@ultratec.com">Michael Jacobson</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=speex-dev@xiph.org href="mailto:speex-dev@xiph.org">speex-dev@xiph.org</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Monday, July 23, 2007 12:54 PM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> [Speex-dev] Shoehorning speex is confusing a newbie</DIV>
<DIV><BR></DIV>
<DIV>This is going to take some explaining and I apologize in advance if any of this is found in the manual or sample code but I couldn't find it.&nbsp; I just graduated last may and this is my first experience with vocoders and dissecting a professional's code.</DIV>
<DIV>&nbsp;</DIV>
<DIV>I work for a company that is currently using a G729A vocoder from a 3rd party software company and is looking into speex so they no longer have to pay royalties.&nbsp; The product we are trying to force speex into is based on&nbsp;a TI C5416 DSP that did narrowband 8-bit, 8kbs.&nbsp; The product was fairly full as it is so some modifications had to be made in order to fit speex into the project just to allow it to link.&nbsp; The modifications are based off assumptions that I made when looking over the code so I may have been absolutely wrong.</DIV>
<DIV>&nbsp;</DIV>
<DIV>The main assumption was about the exc tables.&nbsp; In looking through modes.c it appeared that only one table was required for 8kbs so I commented out the portions of the code that referenced the other tables and modified "static const SpeexNBMode nb_mode" structure so that the pointers to the other structures that referenced the tables were NULL.&nbsp; We did not have enough data memory to store all the tables.&nbsp; I thought this would work with my initialization but when I stepped through the code in nb_celp for encode it would put it in mode 6 (instead of mode 3), which I believe is 18.2kbs (table 8.2). My set up code is:</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; st = speex_encoder_init(&amp;speex_nb_mode);<BR>&nbsp;&nbsp;speex_bits_set_bit_buffer(&amp;bits, &amp;G729_tx, COMPRESS_LENGTH);</DIV>
<DIV>&nbsp;&nbsp;tmp=TESTENC_QUALITY;&nbsp; //=4<BR>&nbsp;&nbsp;speex_encoder_ctl(st, SPEEX_SET_QUALITY, &amp;tmp);<BR>&nbsp;&nbsp;speex_encode_int(st, (spx_int16_t *)samples_in, &amp;bits);</DIV>
<DIV>&nbsp;</DIV>
<DIV>which I thought would put it in 8kbs narrowband.&nbsp; I tried to use SPEEX_SET_MODE in there too but it just got overwritten by the set mode in the encode function.&nbsp; So I thought I'd try to force it into mode 3 and see what happens, and I got A result, but when I try to decode it my decode stage gets stuck in an infinite loop:</DIV>
<DIV>&nbsp;</DIV>
<DIV>while (st-&gt;voc_offset&lt;st-&gt;subframeSize)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (st-&gt;voc_offset&gt;=0)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exc[st-&gt;voc_offset]=sqrt(1.0*ol_pitch);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; st-&gt;voc_offset+=ol_pitch;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</DIV>
<DIV>&nbsp;</DIV>
<DIV>because both voc_offset and ol_pitch is = 0 because this code is never entered:</DIV>
<DIV>&nbsp;</DIV>
<DIV>if (SUBMODE(lbr_pitch)!=-1)<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ol_pitch = st-&gt;min_pitch+speex_bits_unpack_unsigned(bits, 7);<BR>&nbsp;&nbsp; } </DIV>
<DIV>&nbsp;</DIV>
<DIV>This is how I set up the decoder:</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; dec = speex_decoder_init(&amp;speex_nb_mode);<BR>&nbsp;&nbsp;&nbsp;speex_bits_set_bit_buffer(&amp;bits, &amp;Speex_enc_buffer[0 +&nbsp;COMPRESS_LENGTH*Speex_player_frame], COMPRESS_LENGTH);<BR>&nbsp;&nbsp;&nbsp;tmp=0;<BR>&nbsp;&nbsp;&nbsp;speex_decoder_ctl(dec, SPEEX_SET_ENH, &amp;tmp);</DIV>
<DIV>&nbsp;&nbsp;&nbsp;speex_decode_int(dec, &amp;bits, (spx_int16_t *)samples_out);&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>There are some things I am sure will be asked.&nbsp; Yes I set flags for the TI_54X part, disable wideband, manual allocation,&nbsp;and fixed point in a config file and defined the #define value needed to include that config file.&nbsp; I do have a heap for the setup of the state structure for encode and decode and yes I made sure it was big enough to allocate enough to both.&nbsp; Yes I destroy the structures after I am done en/decoding them.&nbsp; If there is anything you need to help you help me then I am defiantly willing to share.&nbsp; I am thoroughly confused and could use some help.</DIV>
<DIV>&nbsp;</DIV>
<DIV>Thanks.</DIV>
<DIV>&nbsp;</DIV>
<DIV>-Mike Jacobson</DIV>
<DIV><A href="mailto:michael.jacobson@ultratec.com">michael.jacobson@ultratec.com</A></DIV>
<P>
<HR>

<P></P>_______________________________________________<BR>Speex-dev mailing list<BR>Speex-dev@xiph.org<BR>http://lists.xiph.org/mailman/listinfo/speex-dev<BR></BLOCKQUOTE></DIV></BLOCKQUOTE></DIV></BODY></HTML>