#[repr(C)]pub struct playdate_sound_synth {Show 30 fields
pub newSynth: Option<unsafe extern "C" fn() -> *mut PDSynth>,
pub freeSynth: Option<unsafe extern "C" fn(synth: *mut PDSynth)>,
pub setWaveform: Option<unsafe extern "C" fn(synth: *mut PDSynth, wave: SoundWaveform)>,
pub setGenerator_deprecated: Option<unsafe extern "C" fn(synth: *mut PDSynth, stereo: c_int, render: synthRenderFunc, noteOn: synthNoteOnFunc, release: synthReleaseFunc, setparam: synthSetParameterFunc, dealloc: synthDeallocFunc, userdata: *mut c_void)>,
pub setSample: Option<unsafe extern "C" fn(synth: *mut PDSynth, sample: *mut AudioSample, sustainStart: u32, sustainEnd: u32)>,
pub setAttackTime: Option<unsafe extern "C" fn(synth: *mut PDSynth, attack: c_float)>,
pub setDecayTime: Option<unsafe extern "C" fn(synth: *mut PDSynth, decay: c_float)>,
pub setSustainLevel: Option<unsafe extern "C" fn(synth: *mut PDSynth, sustain: c_float)>,
pub setReleaseTime: Option<unsafe extern "C" fn(synth: *mut PDSynth, release: c_float)>,
pub setTranspose: Option<unsafe extern "C" fn(synth: *mut PDSynth, halfSteps: c_float)>,
pub setFrequencyModulator: Option<unsafe extern "C" fn(synth: *mut PDSynth, mod_: *mut PDSynthSignalValue)>,
pub getFrequencyModulator: Option<unsafe extern "C" fn(synth: *mut PDSynth) -> *mut PDSynthSignalValue>,
pub setAmplitudeModulator: Option<unsafe extern "C" fn(synth: *mut PDSynth, mod_: *mut PDSynthSignalValue)>,
pub getAmplitudeModulator: Option<unsafe extern "C" fn(synth: *mut PDSynth) -> *mut PDSynthSignalValue>,
pub getParameterCount: Option<unsafe extern "C" fn(synth: *mut PDSynth) -> c_int>,
pub setParameter: Option<unsafe extern "C" fn(synth: *mut PDSynth, parameter: c_int, value: c_float) -> c_int>,
pub setParameterModulator: Option<unsafe extern "C" fn(synth: *mut PDSynth, parameter: c_int, mod_: *mut PDSynthSignalValue)>,
pub getParameterModulator: Option<unsafe extern "C" fn(synth: *mut PDSynth, parameter: c_int) -> *mut PDSynthSignalValue>,
pub playNote: Option<unsafe extern "C" fn(synth: *mut PDSynth, freq: c_float, vel: c_float, len: c_float, when: u32)>,
pub playMIDINote: Option<unsafe extern "C" fn(synth: *mut PDSynth, note: MIDINote, vel: c_float, len: c_float, when: u32)>,
pub noteOff: Option<unsafe extern "C" fn(synth: *mut PDSynth, when: u32)>,
pub stop: Option<unsafe extern "C" fn(synth: *mut PDSynth)>,
pub setVolume: Option<unsafe extern "C" fn(synth: *mut PDSynth, left: c_float, right: c_float)>,
pub getVolume: Option<unsafe extern "C" fn(synth: *mut PDSynth, left: *mut c_float, right: *mut c_float)>,
pub isPlaying: Option<unsafe extern "C" fn(synth: *mut PDSynth) -> c_int>,
pub getEnvelope: Option<unsafe extern "C" fn(synth: *mut PDSynth) -> *mut PDSynthEnvelope>,
pub setWavetable: Option<unsafe extern "C" fn(synth: *mut PDSynth, sample: *mut AudioSample, log2size: c_int, columns: c_int, rows: c_int) -> c_int>,
pub setGenerator: Option<unsafe extern "C" fn(synth: *mut PDSynth, stereo: c_int, render: synthRenderFunc, noteOn: synthNoteOnFunc, release: synthReleaseFunc, setparam: synthSetParameterFunc, dealloc: synthDeallocFunc, copyUserdata: synthCopyUserdata, userdata: *mut c_void)>,
pub copy: Option<unsafe extern "C" fn(synth: *mut PDSynth) -> *mut PDSynth>,
pub clearEnvelope: Option<unsafe extern "C" fn(synth: *mut PDSynth)>,
}Fields§
§newSynth: Option<unsafe extern "C" fn() -> *mut PDSynth>PDSynth* playdate->sound->synth->newSynth(void)
Creates a new synth object.
freeSynth: Option<unsafe extern "C" fn(synth: *mut PDSynth)>void playdate->sound->synth->freeSynth(PDSynth* synth)
Frees a synth object, first removing it from the sound engine if needed.
setWaveform: Option<unsafe extern "C" fn(synth: *mut PDSynth, wave: SoundWaveform)>void playdate->sound->synth->setWaveform(PDSynth* synth, SoundWaveform wave)
Sets the waveform of the synth. The SoundWaveform enum contains the following values:
SoundWaveform
typedef enum
{
kWaveformSquare,
kWaveformTriangle,
kWaveformSine,
kWaveformNoise,
kWaveformSawtooth,
kWaveformPOPhase,
kWaveformPODigital,
kWaveformPOVosim
} SoundWaveform;setGenerator_deprecated: Option<unsafe extern "C" fn(synth: *mut PDSynth, stereo: c_int, render: synthRenderFunc, noteOn: synthNoteOnFunc, release: synthReleaseFunc, setparam: synthSetParameterFunc, dealloc: synthDeallocFunc, userdata: *mut c_void)>§setSample: Option<unsafe extern "C" fn(synth: *mut PDSynth, sample: *mut AudioSample, sustainStart: u32, sustainEnd: u32)>void playdate->sound->synth->setSample(PDSynth* synth, AudioSample* sample, uint32_t sustainStart, uint32_t sustainEnd)
Provides a sample for the synth to play. Sample data must be uncompressed PCM, not ADPCM. If a sustain range is set, it is looped while the synth is playing a note. When the note ends, if an envelope has been set on the synth and the sustain range goes to the end of the sample (i.e. there’s no release section of the sample after the sustain range) then the sustain section continues looping during the envelope release; otherwise it plays through the end of the sample and stops. As a convenience, if sustainEnd is zero and sustainStart is greater than zero, sustainEnd will be set to the length of the sample.
setAttackTime: Option<unsafe extern "C" fn(synth: *mut PDSynth, attack: c_float)>void playdate->sound->synth->setAttackTime(PDSynth* synth, float attack)
setDecayTime: Option<unsafe extern "C" fn(synth: *mut PDSynth, decay: c_float)>void playdate->sound->synth->setDecayTime(PDSynth* synth, float decay)
setSustainLevel: Option<unsafe extern "C" fn(synth: *mut PDSynth, sustain: c_float)>void playdate->sound->synth->setSustainLevel(PDSynth* synth, float sustain)
setReleaseTime: Option<unsafe extern "C" fn(synth: *mut PDSynth, release: c_float)>void playdate->sound->synth->setReleaseTime(PDSynth* synth, float release)
Sets the parameters of the synth’s ADSR envelope.
setTranspose: Option<unsafe extern "C" fn(synth: *mut PDSynth, halfSteps: c_float)>void playdate->sound->synth->setTranspose(PDSynth* synth, float halfSteps)
Transposes the synth’s output by the given number of half steps. For example, if the transpose is set to 2 and a C note is played, the synth will output a D instead.
setFrequencyModulator: Option<unsafe extern "C" fn(synth: *mut PDSynth, mod_: *mut PDSynthSignalValue)>void playdate->sound->synth->setFrequencyModulator(PDSynth* synth, PDSynthSignalValue* mod)
Sets a signal to modulate the synth’s frequency. The signal is scaled so that a value of 1 doubles the synth pitch (i.e. an octave up) and -1 halves it (an octave down). Set to NULL to clear the modulator.
getFrequencyModulator: Option<unsafe extern "C" fn(synth: *mut PDSynth) -> *mut PDSynthSignalValue>PDSynthSignalValue* playdate->sound->synth->getFrequencyModulator(PDSynth* synth)
Returns the currently set frequency modulator.
setAmplitudeModulator: Option<unsafe extern "C" fn(synth: *mut PDSynth, mod_: *mut PDSynthSignalValue)>void playdate->sound->synth->setAmplitudeModulator(PDSynth* synth, PDSynthSignalValue* mod)
Sets a signal to modulate the synth’s output amplitude. Set to NULL to clear the modulator.
getAmplitudeModulator: Option<unsafe extern "C" fn(synth: *mut PDSynth) -> *mut PDSynthSignalValue>PDSynthSignalValue* playdate->sound->synth->getAmplitudeModulator(PDSynth* synth)
Returns the currently set amplitude modulator.
getParameterCount: Option<unsafe extern "C" fn(synth: *mut PDSynth) -> c_int>int playdate->sound->synth->getParameterCount(PDSynth* synth)
Returns the number of parameters advertised by the synth.
setParameter: Option<unsafe extern "C" fn(synth: *mut PDSynth, parameter: c_int, value: c_float) -> c_int>int playdate->sound->synth->setParameter(PDSynth* synth, int num, float value)
Sets the (1-based) parameter at position num to the given value. Returns 0 if num is not a valid parameter index.
setParameterModulator: Option<unsafe extern "C" fn(synth: *mut PDSynth, parameter: c_int, mod_: *mut PDSynthSignalValue)>void playdate->sound->synth->setParameterModulator(PDSynth* synth, int num, PDSynthSignalValue* mod)
Sets a signal to modulate the parameter at index num. Set to NULL to clear the modulator.
getParameterModulator: Option<unsafe extern "C" fn(synth: *mut PDSynth, parameter: c_int) -> *mut PDSynthSignalValue>PDSynthSignalValue* playdate->sound->synth->getParameterModulator(PDSynth* synth, int num)
Returns the currently set parameter modulator for the given index.
playNote: Option<unsafe extern "C" fn(synth: *mut PDSynth, freq: c_float, vel: c_float, len: c_float, when: u32)>void playdate->sound->synth->playNote(PDSynth* synth, float freq, float vel, float len, uint32_t when)
Plays a note on the synth, at the given frequency. Specify len = -1 to leave the note playing until a subsequent noteOff() call. If when is 0, the note is played immediately, otherwise the note is scheduled for the given time. Use playdate→sound→getCurrentTime() to get the current time.
playMIDINote: Option<unsafe extern "C" fn(synth: *mut PDSynth, note: MIDINote, vel: c_float, len: c_float, when: u32)>void playdate->sound->synth->playMIDINote(PDSynth* synth, MIDINote note, float vel, float len, uint32_t when)
The same as playNote but uses MIDI note (where 60 = C4) instead of frequency. Note that MIDINote is a typedef for `float’, meaning fractional values are allowed (for all you microtuning enthusiasts).
noteOff: Option<unsafe extern "C" fn(synth: *mut PDSynth, when: u32)>void playdate->sound->synth->noteOff(PDSynth* synth, uint32_t when)
Sends a note off event to the synth, either immediately (when = 0) or at the scheduled time.
stop: Option<unsafe extern "C" fn(synth: *mut PDSynth)>§setVolume: Option<unsafe extern "C" fn(synth: *mut PDSynth, left: c_float, right: c_float)>void playdate->sound->synth->setVolume(PDSynth* synth, float lvol, float rvol)
Sets the playback volume (0.0 - 1.0) for the left and, if the synth is stereo, right channels of the synth. This is equivalent to
playdate->sound->source->setVolume((SoundSource*)synth, lvol, rvol);getVolume: Option<unsafe extern "C" fn(synth: *mut PDSynth, left: *mut c_float, right: *mut c_float)>float playdate->sound->synth->getVolume(PDSynth* synth, float* outlvol, float* outrvol)
Gets the playback volume for the left and right (if stereo) channels of the synth. This is equivalent to
playdate->sound->source->getVolume((SoundSource*)synth, outlvol, outrvol);isPlaying: Option<unsafe extern "C" fn(synth: *mut PDSynth) -> c_int>int playdate->sound->synth->isPlaying(PDSynth* synth)
Returns 1 if the synth is currently playing.
getEnvelope: Option<unsafe extern "C" fn(synth: *mut PDSynth) -> *mut PDSynthEnvelope>PDSynthEnvelope* playdate->sound->synth->getEnvelope(PDSynth* synth)
Returns the synth’s envelope. The PDSynth object owns this envelope, so it must not be freed.
setWavetable: Option<unsafe extern "C" fn(synth: *mut PDSynth, sample: *mut AudioSample, log2size: c_int, columns: c_int, rows: c_int) -> c_int>int playdate->sound->synth->setWavetable(PDSynth* synth, AudioSample* sample, int log2size, int columns, rows)
Sets a wavetable for the synth to play. Sample data must be 16-bit mono uncompressed. log2size is the base 2 logarithm of the number of samples in each waveform “cell” in the table, and columns and rows gives the number of cells in each direction; for example, if the wavetable is arranged in an 8x8 grid, columns and rows are both 8 and log2size is 6, since 2^6 = 8x8.
The function returns 1 on success. If it fails, use playdate→sound→getError() to get a human-readable error message.
The synth’s “position” in the wavetable is set manually with setParameter() or automated with setParameterModulator(). In some cases it’s easier to use a parameter that matches the waveform position in the table, in others (notably when using envelopes and lfos) it’s more convenient to use a 0-1 scale, so there’s some redundancy here. Parameters are
-
1: x position, values are from 0 to the table width
-
2: x position, values are from 0 to 1, parameter is scaled up to table width
For 2-D tables (height > 1):
-
3: y position, values are from 0 to the table height
-
4: y position, values are from 0 to 1, parameter is scaled up to table height
setGenerator: Option<unsafe extern "C" fn(synth: *mut PDSynth, stereo: c_int, render: synthRenderFunc, noteOn: synthNoteOnFunc, release: synthReleaseFunc, setparam: synthSetParameterFunc, dealloc: synthDeallocFunc, copyUserdata: synthCopyUserdata, userdata: *mut c_void)>void playdate->sound->synth->setGenerator(PDSynth* synth, int stereo, synthRenderFunc* render, synthNoteOnFunc* noteOn, synthReleaseFunc* release, synthSetParameterFunc* setparam, synthDeallocFunc* dealloc, synthCopyUserdataFunc copyUserdata, void* userdata)
GeneratorCallbacks
typedef int (*synthRenderFunc)(void* userdata, int32_t* left, int32_t* right, int nsamples, uint32_t rate, int32_t drate);
typedef void (*synthNoteOnFunc)(void* userdata, MIDINote note, float velocity, float len); // len == -1 if indefinite
typedef void (*synthReleaseFunc)(void* userdata, int endoffset);
typedef int (*synthSetParameterFunc)(void* userdata, int parameter, float value);
typedef void (*synthDeallocFunc)(void* userdata);
typedef void* (*synthCopyUserdata)(void* userdata);Provides custom waveform generator functions for the synth. These functions are called on the audio render thread, so they should return as quickly as possible. synthRenderFunc, the data provider callback, is the only required function.
synthRenderFunc: called every audio cycle to get the samples for playback. left (and right if setGenerator() was called with the stereo flag set) are sample buffers in Q8.24 format. rate is the amount to change a (Q32) phase accumulator each sample, and drate is the amount to change rate each sample. Custom synths can ignore this and use the note paramter in the noteOn function to handle pitch, but synth→setFrequencyModulator() won’t work as expected.
synthNoteOnFunc: called when the synth receives a note on event. len is the length of the note in seconds, or -1 if it’s not known yet when the note will end.
synthReleaseFunc: called when the synth receives a note off event. endoffset is how many samples into the current render cycle the note ends, allowing for sample-accurate timing.
synthSetParameterFunc: called when a parameter change is received from synth→setParameter() or a modulator.
synthDeallocFunc: called when the synth is being dealloced. This function should free anything that was allocated for the synth and also free the userdata itself.
synthCopyUserdata: called when synth→copy() needs a unique copy of the synth’s userdata. External objects should be retained or copied so that the object isn’t freed while the synth is still using it.
copy: Option<unsafe extern "C" fn(synth: *mut PDSynth) -> *mut PDSynth>PDSynth* playdate->sound->synth->copy(PDSynth* synth)
Returns a copy of the given synth. Caller assumes ownership of the returned object and should free it when it is no longer in use.
clearEnvelope: Option<unsafe extern "C" fn(synth: *mut PDSynth)>void playdate->sound->synth->clearEnvelope(PDSynth* synth)
Clears the synth’s envelope settings.
Trait Implementations§
Source§impl Clone for playdate_sound_synth
impl Clone for playdate_sound_synth
Source§fn clone(&self) -> playdate_sound_synth
fn clone(&self) -> playdate_sound_synth
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for playdate_sound_synth
impl Debug for playdate_sound_synth
Source§impl Default for playdate_sound_synth
impl Default for playdate_sound_synth
Source§fn default() -> playdate_sound_synth
fn default() -> playdate_sound_synth
Source§impl Hash for playdate_sound_synth
impl Hash for playdate_sound_synth
Source§impl Ord for playdate_sound_synth
impl Ord for playdate_sound_synth
Source§impl PartialEq for playdate_sound_synth
impl PartialEq for playdate_sound_synth
Source§impl PartialOrd for playdate_sound_synth
impl PartialOrd for playdate_sound_synth
Source§fn partial_cmp(&self, other: &playdate_sound_synth) -> Option<Ordering>
fn partial_cmp(&self, other: &playdate_sound_synth) -> Option<Ordering>
impl Copy for playdate_sound_synth
impl Eq for playdate_sound_synth
impl StructuralPartialEq for playdate_sound_synth
Auto Trait Implementations§
impl Freeze for playdate_sound_synth
impl RefUnwindSafe for playdate_sound_synth
impl Send for playdate_sound_synth
impl Sync for playdate_sound_synth
impl Unpin for playdate_sound_synth
impl UnwindSafe for playdate_sound_synth
Blanket Implementations§
§impl<T> Any for Twhere
T: 'static + ?Sized,
impl<T> Any for Twhere
T: 'static + ?Sized,
§impl<T> Borrow<T> for Twhere
T: ?Sized,
impl<T> Borrow<T> for Twhere
T: ?Sized,
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)§impl<T, U> Into<U> for Twhere
U: From<T>,
impl<T, U> Into<U> for Twhere
U: From<T>,
§impl<T> ToOwned for Twhere
T: Clone,
impl<T> ToOwned for Twhere
T: Clone,
§impl<T, U> TryFrom<U> for Twhere
U: Into<T>,
impl<T, U> TryFrom<U> for Twhere
U: Into<T>,
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 120 bytes