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 653769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:25:10+00:00 2026-05-13T22:25:10+00:00

First time poster here. A quick question about setting up a loop here. I

  • 0

First time poster here.

A quick question about setting up a loop here. I want to set up a for loop for the first 1/3 of the main loop that will increase a value from .00001 or similar to 1. So I can use it to multiply a sample variable so as to create a fade-in in this simple audio file playback routine.

So far it’s turning out to be a bit of a head scratcher, any help greatfully recieved.

for(i=0; i < end && !feof(fpin); i+=blockframes) 
{ 
    samples = fread(audioblock, sizeof(short), blocksamples, fpin); 
    frames = samples; 
    for(j=0; j < frames; j++)
    {   
        for (f = 0; f< frames/3 ;f++)
        {
            fade = fade--;
        } 
    output[j] = audioblock[j]/fade;
    }

    fwrite(output,sizeof(short), frames, fpoutput); 
} 

Apologies,
So far I’ve read and re-write the file successfully. My problem is I’m trying to figure out a way to loop the variable ‘fade’ so it either increases or decreases to 1, so as I can modify the output variable.

I wanted to do this in say 3 stages:
1. From 0 to frames/3 to increace a multiplication factor from .0001 to 1
2. from frames 1/3 to frames 2/3 to do nothing (multiply by 1) and
3. For the factor to decrease again below 1 so as for the output variable to decrease back to the original point.

How can I create a loop that will increase and decrease these values over the outside loop?

  • 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-13T22:25:10+00:00Added an answer on May 13, 2026 at 10:25 pm

    I think you thought yourself into a corner, to say so. There’s no need to create a nested loop to modify the fade gain, you can simply keep track of it through the loop and adapt it if necessary. Also, your variable naming of frames/samples seems a bit muddy to me, I hope I got that one right.

    float fadeTime = 0.5f;
    float outputGain = 0.0f;
    float gainProgressionPerSample = 1.0f/(fadeTime*SAMPLERATE);
    float fadeInStop = fadeTime*SAMPLERATE;
    float fadeOutBegin;
    
    for(i=0; i < end && !feof(fpin); i+=blockframes) 
    { 
        samples = fread(audioblock, sizeof(short), blocksamples, fpin); 
        fadeOutBegin = samples - fadeTime*SAMPLERATE;
        for(j=0; j < samples; j++)
        {
           if (j < fadeInStop)   
           {
             outputGain += gainProgressionPerSample;
           }
           // else is not used intentionally to allow fade in/out blending for short tracks
           if (j > fadeOutBegin)
           {
             outputGain -= gainProgressionPerSample;
           }
           output[j] = audioblock[j]*outputGain;
        }
    
        fwrite(output,sizeof(short), samples, fpoutput); 
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Long time reader/ first time poster here, with a question I suspect will be
First time poster here but definitely not a first time reader. My question is
first time poster - semi-newb to Rails. Here is my question. Suppose you have
Long time lurker, first time poster here. My question is: Using C# 2.0, is
I know that this is not the first time a question about this issue
long time reader/first time poster here. So I've got a checkbox array that posted
This is a pretty simple question; first time poster and long time looker. Here
First time poster here. I've assembled a scrolling website that also has a sliding
Long time reader, first time poster here. I'm creating a test app that creates
First time Stack Overflow poster. Please bear with me! :) I have a set

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.