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

  • SEARCH
  • Home
  • 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 6080931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:07:04+00:00 2026-05-23T11:07:04+00:00

I need help getting started with libsndfile. I have four .wav files (all the

  • 0

I need help getting started with libsndfile.

I have four .wav files (all the same sample rate).

I want to join the first two together,then the next two together,

Then mix the resulting 2 .wav files into one.

  • 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-05-23T11:07:05+00:00Added an answer on May 23, 2026 at 11:07 am

    For mixing two wav files.

    #include <cstdio>
    #include <sndfile.h>
    #include <windows.h>
    #include <cstdlib>
    #include <cmath>
    
    #define BUFFER_LEN 1024
    #define MAX_CHANNELS 6
    
    static void data_processing (double *data, int count, int channels) ;
    
    int main (void) {
    
      static double data [BUFFER_LEN] ;
      static double data2 [BUFFER_LEN] ;
      static double outdata [BUFFER_LEN] ;
    
      SNDFILE *infile, *outfile, *infile2 ;
      SF_INFO sfinfo ;
      int readcount ;
      SF_INFO sfinfo2 ;
      int readcount2 ;
    
      const char *infilename = "inputOne.wav" ;
      const char *infilename2 = "inputTwo.wav" ;
      const char *outfilename = "output.wav" ;
    
      if (! (infile = sf_open (infilename, SFM_READ, &sfinfo))) {
        /* Open failed so print an error message. */
        printf ("Not able to open input file %s.\n", infilename) ;
    
        /* Print the error message from libsndfile. */
        puts (sf_strerror (NULL)) ;
        return 1 ;
      } ;
    
      if (sfinfo.channels > MAX_CHANNELS) {
        printf ("Not able to process more than %d channels\n", MAX_CHANNELS) ;
        return 1 ;
      } ;
    
      if (! (infile2 = sf_open (infilename2, SFM_READ, &sfinfo2))) {
        /* Open failed so print an error message. */
        printf ("Not able to open input file %s.\n", infilename2) ;
    
        /* Print the error message from libsndfile. */
        puts (sf_strerror (NULL)) ;
        return 1 ;
      } ;
    
      if (sfinfo2.channels > MAX_CHANNELS) {
        printf ("Not able to process more than %d channels\n", MAX_CHANNELS) ;
        return 1 ;
      } ;
    
      /* Open the output file. */
      if (! (outfile = sf_open (outfilename, SFM_WRITE, &sfinfo))) {
        printf ("Not able to open output file %s.\n", outfilename) ;
        puts (sf_strerror (NULL)) ;
        return 1 ;
      } ;
    
      while ((readcount = sf_read_double (infile, data, BUFFER_LEN)) &&
             (readcount2 = sf_read_double (infile2, data2, BUFFER_LEN))) { 
        data_processing (data, readcount, sfinfo.channels) ;
    data_processing(data2, readcount2, sfinfo2.channels) ;
    
        for(int i=0; i < 1024;++i) {
      outdata[i] = (data[i] + data2[i]) -(data[i])*(data2[i])/65535;
        }
    
        sf_write_double (outfile, outdata , readcount) ;
      } ;
    
      /* Close input and output files. */
      sf_close (infile) ;
      sf_close (infile2) ;
      sf_close (outfile) ;
      system("PAUSE");
      return 0 ;
    } /* main */
    
    static void data_processing(double *data, int count, int channels) { 
      double channel_gain [MAX_CHANNELS] = { 0.5, 0.8, 0.1, 0.4, 0.4, 0.9 } ;
      int k, chan ;
    
      for (chan = 0 ; chan < channels ; chan ++)
        for (k = chan ; k < count ; k+= channels)
          data [k] *= channel_gain [chan] ;
    
      return ;
    } /* data_processing */
    

    This is how i am mixing two simple wav files which are 16 bit signals.

    First of all audio mixing is not easy as one might think. There might be many ambiguities after joining two signals. In my case it is working just fine as much as i need it, but if you need exact results you might need to google more for exact superimposing signals over each other.

    For joining two wav files you can just read your first wav file copy the data in the result wav file and finally append the data of the second wav file to the result wav file.

    This link might also be useful for you
    http://www.vttoth.com/digimix.htm

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

Sidebar

Related Questions

I need help getting git extensions to run with msysgit. I have had bad
I need major help getting started! I managed to create a new project, and
I am just getting started with Code Contracts, and need a little help in
Hi I need some help on getting started with creating my first algorithm; I
Hi I have been playing around with MDX and need some very high-level getting-started
I'm just getting started with android development and I need help with background images.
I'm just getting started with ASM (NASM), and need some help with the following
I'm still pretty new to perl and regex and need some help getting started.
I need some help in getting started with jQuery and autocompleting a username for
I need help getting my head around the difference between my current OOP notion

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.