Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7847807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:00:28+00:00 2026-06-02T18:00:28+00:00

The code below is intended to implement two strategies to interpolate across missing packets

  • 0

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!

#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 < 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 && (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 < 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 < 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;
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T18:00:30+00:00Added an answer on June 2, 2026 at 6:00 pm

    Variables convention :

    • seqno : sequence number
    • samples : audio data as samples
    • prev_ : previous
    • ofile : output file

    How do you know what the code is supposed to do without understanding it?
    The idea is that packets have incremental sequence numbers, from 0 to infinity. -1 is the initial state, when no packets have even been received.
    When you receive a packet and

      if (prev_seqno != -1 //it is not the first packet 
          && 
         (prev_seqno+1 != seqno) //the packet is not the one we expected  
          ){ 
       //there are (seqno - prev_seqno - 1) packet missing.
       //do something about it.
    

    when you enter this condition then you have a gap. Depending on the strategy you fill the output file ofile with silence or copy of the last samples received. In audio silence = 0.

    For example, if the last packet was 0 and you received packet 4, it means packet 1, 2 and 3 are missing. In this case depending on the strategy you will consider 1, 2, 3 as silence packets or as 0 being repeated.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The code below is intended to enable the submit button once the user clicks
The code below works as intended, but it's not quite what I need. I
In the code below, I'm catching a TimeoutException after 100 seconds as intended. At
The code below is intended to display the pages of a PDF while properly
I'm attempting to learn some Python and Tkinter. The sample code below is intended
I'm seeing some odd behavior with XML::LibXML . The code below is intended to
The code snippet below is intended to open a specific worksheet of a specific
Code below does not run correctly and throws InvalidOperationExcepiton . public void Foo() {
Code below is not working as expected to detect if it is in design
Code below is working well as long as I have class ClassSameAssembly in same

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.