music.set_sample_rate¶
- music.set_sample_rate(rate)[source]¶
Set the sample rate routines use when they are not given one.
Every routine that takes a
sample_ratedefaults it to None, which means this rate. Called on its own line, the setting lasts for the rest of the thread or asyncio task; as the subject of awithstatement, it lasts for the block, and the rate before it comes back when the block ends, however it ends. Either way it applies immediately, so there is no form of the call that sets nothing.A
sample_rategiven to a routine always wins over this one, and an object that renders later – aSequencer, aStimulationSession, an oscillator – keeps the rate that was in effect when it was made.- Parameters:
- rate
int Samples per second, a positive whole number.
- rate
- Returns:
contextmanagerThe setting, which a
withstatement undoes on exit;asbinds the rate. Use it in onewithstatement at most.
- Raises:
ValueErrorIf
rateis not a positive whole number. A fractional rate, or a boolean, is refused rather than truncated: nothing that writes a file could keep it.
- Parameters:
rate (int)
- Return type:
_RateSetting
See also
get_sample_ratethe rate in effect.
Examples
>>> with set_sample_rate(48000): ... len(note(duration=1)) 48000 >>> len(note(duration=1)) 44100