Skip to content

Commit

Permalink
Don't hardcode timepos sample rate to 44100 in AU
Browse files Browse the repository at this point in the history
AU had a hard coded 44100. Rather than use that, cache the last sample
rate we saw when reset and use it to advance timepos in the sample block.
Related to surge-synthesizer#662.
  • Loading branch information
baconpaul committed Feb 25, 2019
1 parent b46339e commit 30145c6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/au/aulayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ ComponentResult aulayer::Initialize()
plugin_instance->setSamplerate(samplerate);
plugin_instance->audio_processing_active = true;
plugin_instance->allNotesOff();
sampleRateCache = samplerate;

blockpos = 0;
events_this_block = 0;
Expand Down Expand Up @@ -180,7 +181,8 @@ ComponentResult aulayer::ChangeStreamFormat(
ComponentResult result = AUBase::ChangeStreamFormat(inScope,inElement,inPrevFormat,inNewFormat);

if(plugin_instance) plugin_instance->setSamplerate(samplerate);

sampleRateCache = samplerate;

return result;
}

Expand All @@ -193,6 +195,7 @@ ComponentResult aulayer::Reset(AudioUnitScope inScope, AudioUnitElement inElemen
double samplerate = GetOutput(0)->GetStreamFormat().mSampleRate;
plugin_instance->setSamplerate(samplerate);
plugin_instance->allNotesOff();
sampleRateCache == samplerate;
}
return noErr;
}
Expand Down Expand Up @@ -309,7 +312,7 @@ ComponentResult aulayer::Render( AudioUnitRenderActionFlags & ioActionFlags, con
SurgeSynthesizer *s = (SurgeSynthesizer*) plugin_instance;
s->process_input = 0;

float sampleRate = 44100.f;
float sampleRate = sampleRateCache;
float* outputs[N_OUTPUTS];
float* inputs[N_INPUTS];

Expand Down
1 change: 1 addition & 0 deletions src/au/aulayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class aulayer : public AUInstrumentBase
AUChannelInfo cinfo[2]; // stored output configs
AudioUnitParameterID parameterIDlist[n_total_params];
CFStringRef parameterIDlist_CFString[n_total_params];
float sampleRateCache;
};

struct CFAUPreset
Expand Down

0 comments on commit 30145c6

Please sign in to comment.