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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:19:49+00:00 2026-05-18T08:19:49+00:00

My question is a little tricky, and I’m not exactly experienced (I might get

  • 0

My question is a little tricky, and I’m not exactly experienced (I might get some terms wrong), so here goes.
I’m declaring an instance of an object called “Singer”. The instance is called “singer1”. “singer1” produces an audio signal. Now, the following is the code where the specifics of the audio signal are determined:

OSStatus playbackCallback(void *inRefCon,
                      AudioUnitRenderActionFlags *ioActionFlags,
                      const AudioTimeStamp *inTimeStamp,
                      UInt32 inBusNumber, 
                      UInt32 inNumberFrames,
                      AudioBufferList *ioData) {    

//Singer *me = (Singer *)inRefCon;

static int phase = 0;

for(UInt32 i = 0; i < ioData->mNumberBuffers; i++) {

    int samples = ioData->mBuffers[i].mDataByteSize / sizeof(SInt16);

    SInt16 values[samples];

    float waves;
    float volume=.5;

    for(int j = 0; j < samples; j++) {


        waves = 0;


        waves += sin(kWaveform * 600 * phase)*volume;
        waves += sin(kWaveform * 400 * phase)*volume;
        waves += sin(kWaveform * 200 * phase)*volume;
        waves += sin(kWaveform * 100 * phase)*volume;            

        waves *= 32500 / 4; // <--------- make sure to divide by how many waves you're stacking

        values[j] = (SInt16)waves;
        values[j] += values[j]<<16;

        phase++;

    }

    memcpy(ioData->mBuffers[i].mData, values, samples * sizeof(SInt16));

}

return noErr;

}

99% of this is borrowed code, so I only have a basic understanding of how it works (I don’t know about the OSStatus class or method or whatever this is. However, you see those 4 lines with 600, 400, 200 and 100 in them? Those determine the frequency. Now, what I want to do (for now) is insert my own variable in there in place of a constant, which I can change on a whim. This variable is called “fr1”. “fr1” is declared in the header file, but if I try to compile I get an error about “fr1” being undeclared. Currently, my technique to fix this is the following: right beneath where I #import stuff, I add the line

fr1=0.0;//any number will work properly

This sort of works, as the code will compile and singer1.fr1 will actually change values if I tell it to. The problems are now this:A)even though this compiles and the tone specified will play (0.0 is no tone), I get the warnings “Data definition has no type or storage class” and “Type defaults to ‘int’ in declaration of ‘fr1′”. I bet this is because for some reason it’s not seeing my previous declaration in the header file (as a float). However, again, if I leave this line out the code won’t compile because “fr1 is undeclared”. B)Just because I change the value of fr1 doesn’t mean that singer1 will update the value stored inside the “playbackcallback” variable or whatever is in charge of updating the output buffers. Perhaps this can be fixed by coding differently? C)even if this did work, there is still a noticeable “gap” when pausing/playing the audio, which I need to eliminate. This might mean a complete overhaul of the code so that I can “dynamically” insert new values without disrupting anything. However, the reason I’m going through all this effort to post is because this method does exactly what I want (I can compute a value mathematically and it goes straight to the DAC, which means I can use it in the future to make triangle, square, etc waves easily). I have uploaded Singer.h and .m to pastebin for your veiwing pleasure, perhaps they will help. Sorry, I can’t post 2 HTML tags so here are the full links.
(http://pastebin.com/ewhKW2Tk)
(http://pastebin.com/CNAT4gFv)

So, TL;DR, all I really want to do is be able to define the current equation/value of the 4 waves and re-define them very often without a gap in the sound.
Thanks. (And sorry if the post was confusing or got off track, which I’m pretty sure it did.)

  • 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-18T08:19:50+00:00Added an answer on May 18, 2026 at 8:19 am

    My understanding is that your callback function is called every time the buffer needs to be re-filled. So changing fr1..fr4 will alter the waveform, but only when the buffer updates. You shouldn’t need to stop and re-start the sound to get a change, but you will notice an abrupt shift in the timbre if you change your fr values. In order to get a smooth transition in timbre, you’d have to implement something that smoothly changes the fr values over time. Tweaking the buffer size will give you some control over how responsive the sound is to your changing fr values.

    Your issue with fr being undefined is due to your callback being a straight c function. Your fr variables are declared as objective-c instance variables as part of your Singer object. They are not accessible by default.

    take a look at this project, and see how he implements access to his instance variables from within his callback. Basically he passes a reference to his instance to the callback function, and then accesses instance variables through that.

    https://github.com/youpy/dowoscillator

    notice:

    Sinewave *sineObject = inRefCon;
    float freq = sineObject.frequency * 2 * M_PI / samplingRate;
    

    and:

    AURenderCallbackStruct input;
    input.inputProc = RenderCallback;
    input.inputProcRefCon = self;
    

    Also, you’ll want to move your callback function outside of your @implementation block, because it’s not actually part of your Singer object.

    You can see this all in action here: https://github.com/coryalder/SineWaver

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

Sidebar

Related Questions

I have a little tricky question. I have a Telerik Grid with some ClientSide
My question is a little bit tricky. at least I think. Maybe not, anyway.
I find this question a little tricky. Maybe someone knows an approach to answer
Question might be tricky (because of its nature or my way of describing it),
I just want some tricks for increase ASP.Net application. This question is a little
Hey guys, this question might be a little weird worded but I was looking
alredy a question out about this. but here comes another question little diffrent, and
Question - A Little Elephant from the Zoo of Lviv likes lucky numbers very
Just a little question for you... I'm currently trying to implement a role structure
A small - little question. I have seen many application having buttons like following.

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.