Note that there are some explanatory texts on larger screens.

plurals
  1. POC/C++ - Understanding Audio interpolation code
    primarykey
    data
    text
    <p>The code below is intended to implement two strategies to interpolate across missing packets - the two strategies are 1) fill the gap with silence, or 2) repeat the previous packet and if longer than one packet fill the rest with silence. The code has broad comments but I can't seem to get my head around what the different variables are supposed to mean. Would someone mind giving me a helping hand understanding this code? Appreciate any guidance!</p> <pre><code>#include "interpolate.h" #include "assert.h" /* write a packet's worth of silence */ void write_silence(FILE *ofile, int num_samples) { short missing_pkt[num_samples]; int i; for (i=0; i &lt; num_samples; i++) { missing_pkt[i]=0; } fwrite(missing_pkt, 1, num_samples*2, ofile); } /* simulate the reception of a packet, and apply a loss repair strategy */ void recv_packet(int seqno, int len, char *data, FILE *ofile, int strategy) { static int prev_seqno = -1; static short* prev_samples = 0; /* interpret the data as signed 16 bit integers */ short *samples = (short*)data; int num_samples = len/2; printf("recv_packet: seqno=%d\n", seqno); if (prev_seqno != -1 &amp;&amp; (prev_seqno+1 != seqno)) { int i, missing_seqno; /* there was missing data */ printf("s=%d\n", strategy); switch(strategy) { case SILENCE: { /* create a packet containing silence */ missing_seqno = prev_seqno + 1; while (missing_seqno &lt; seqno) { write_silence(ofile, num_samples); missing_seqno++; } break; } case REPEAT_PREV: { /* repeat the previous packet */ fwrite(prev_samples, 2, num_samples, ofile); missing_seqno = prev_seqno + 2; while (missing_seqno &lt; seqno) { /* repeating the same packet more than once sounds bad */ write_silence(ofile, num_samples); missing_seqno++; } break; } default: abort(); } } fwrite(samples, 1, num_samples*2, ofile); /* hold onto the last received packet - we may need it */ if (prev_samples != 0) free(prev_samples); prev_samples = samples; prev_seqno = seqno; }; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload