Struct spectrusty::peripherals::bus::ay::Ay3_891xAudio
source · pub struct Ay3_891xAudio { /* private fields */ }
Expand description
Implements AY-3-8910/8912/8913 programmable sound generator.
For the implementation of I/O ports see crate::ay.
Implementations§
source§impl Ay3_891xAudio
impl Ay3_891xAudio
Use the Default trait to create instances of this struct.
sourcepub fn freq_to_tone_period(clock_hz: f32, hz: f32) -> Option<NonZeroU16>
pub fn freq_to_tone_period(clock_hz: f32, hz: f32) -> Option<NonZeroU16>
Converts a tone frequency given in Hz to a closest 16-bit tone period register value.
clock_hz
AY-3-891x clock frequency in Hz. In ZX Spectrum it equals to CPU_HZ / 2.
Amstrad CPC has PSG clocked at 1 MHz. Atari ST at 2 MHz.
Returns None
if the result can’t be properly represented by 16-bit unsigned integer or if
the result is 0
.
sourcepub fn tone_period_to_freq(clock_hz: f32, tp: u16) -> f32
pub fn tone_period_to_freq(clock_hz: f32, tp: u16) -> f32
Converts a 16-bit tone period register value to a tone frequency in Hz.
clock_hz
AY-3-891x clock frequency in Hz. In ZX Spectrum it equals to CPU_HZ / 2.
Amstrad CPC has PSG clocked at 1 MHz. Atari ST at 2 MHz.
sourcepub fn tone_periods<I>(
clock_hz: f32,
min_octave: i32,
max_octave: i32,
note_freqs: I
) -> impl IntoIterator<Item = u16>where
I: Clone + IntoIterator<Item = f32>,
pub fn tone_periods<I>(
clock_hz: f32,
min_octave: i32,
max_octave: i32,
note_freqs: I
) -> impl IntoIterator<Item = u16>where
I: Clone + IntoIterator<Item = f32>,
Creates an iterator of tone periods for the AY-3-891x chip.
min_octave
A minimal octave number, 0-based (0 is the minimum).
max_octave
A maximal octave number, 0-based (7 is the maximum).
note_freqs
An array of tone frequencies (in Hz) in the 5th octave (0-based: 4).
To generate frequencies you may want to use audio::music::equal_tempered_scale_note_freqs.
clock_hz
The AY-3-891x clock frequency in Hz. Usually, it’s CPU_HZ / 2.
Panics
Panics if any period can’t be expressed by 16-bit unsigned integer.
sourcepub fn render_audio<V, I, A>(
&mut self,
changes: I,
blep: &mut A,
end_ts: i32,
frame_tstates: i32,
chans: [usize; 3]
)where
V: AmpLevels<<A as Blep>::SampleDelta>,
I: IntoIterator<Item = AyRegChange>,
A: Blep,
pub fn render_audio<V, I, A>(
&mut self,
changes: I,
blep: &mut A,
end_ts: i32,
frame_tstates: i32,
chans: [usize; 3]
)where
V: AmpLevels<<A as Blep>::SampleDelta>,
I: IntoIterator<Item = AyRegChange>,
A: Blep,
Renders square-wave audio pulses via the Blep interface while mutating the internal state.
The internal state is being altered every INTERNAL_CLOCK_DIVISOR * HOST_CLOCK_RATIO Cpu
clock cycles until end_ts
is reached. The internal cycle counter is then decremented by the
value of frame_tstates
before returning from this method.
Provide AmpLevels that can handle level
values from 0 to 15 (4-bits).
changes
should be ordered bytime
and recorded only withtime
<end_ts
otherwise, some register changes may be lost - the iterator will be drained anyway.end_ts
should be a value of an end of frame T-state counter value.frame_tstates
should be a duration of a single frame in T-states.channels
- indicate Blep audio channels for[A, B, C]
AY channels.
sourcepub fn update_register(&mut self, reg: AyRegister, val: u8)
pub fn update_register(&mut self, reg: AyRegister, val: u8)
Updates the value of one of the sound generator registers for the indicated reg
register,
with the value given in val
.
This method can be used to instantly set the state of the sound generator without the need to generate audio pulses.
sourcepub fn get_tone_periods(&self) -> [u16; 3]
pub fn get_tone_periods(&self) -> [u16; 3]
Returns the current tone periods of each channel.
The period is in the range: [1, 4095].
sourcepub fn get_amp_levels(&self) -> [u8; 3]
pub fn get_amp_levels(&self) -> [u8; 3]
Returns the current amplitude level of each channel.
If the channel volume register’s envelope bit is set, it returns the current envelope level for that channel.
The levels are in the range: [0, 15].
sourcepub fn get_noise_pitch(&self) -> u8
pub fn get_noise_pitch(&self) -> u8
Returns the current noise pitch.
The pitch is in the range: [0, 31].
sourcepub fn get_mixer(&self) -> u8
pub fn get_mixer(&self) -> u8
Returns the current value of the mixer register.
t - tone bit: 0 tone enabled, 1 disabled
n - noise bit: 0 noise enabled, 1 disabled
b7 b6 b5 b4 b3 b2 b1 b0 bit
- - n n n t t t value
- - C B A C B A channel
sourcepub fn get_envelope_level(&self) -> u8
pub fn get_envelope_level(&self) -> u8
Returns the current level of the envelope generator.
sourcepub fn get_envelope_shape(&self) -> u8
pub fn get_envelope_shape(&self) -> u8
Returns the envelope shape.
sourcepub fn get_envelope_period(&self) -> u16
pub fn get_envelope_period(&self) -> u16
Returns the envelope period.
The period is in the range: [1, 65535].
Trait Implementations§
source§impl Clone for Ay3_891xAudio
impl Clone for Ay3_891xAudio
source§fn clone(&self) -> Ay3_891xAudio
fn clone(&self) -> Ay3_891xAudio
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for Ay3_891xAudio
impl Debug for Ay3_891xAudio
source§impl Default for Ay3_891xAudio
impl Default for Ay3_891xAudio
source§fn default() -> Ay3_891xAudio
fn default() -> Ay3_891xAudio
source§impl<'de> Deserialize<'de> for Ay3_891xAudio
impl<'de> Deserialize<'de> for Ay3_891xAudio
source§fn deserialize<__D>(
__deserializer: __D
) -> Result<Ay3_891xAudio, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D
) -> Result<Ay3_891xAudio, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
source§impl Serialize for Ay3_891xAudio
impl Serialize for Ay3_891xAudio
source§fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl RefUnwindSafe for Ay3_891xAudio
impl Send for Ay3_891xAudio
impl Sync for Ay3_891xAudio
impl Unpin for Ay3_891xAudio
impl UnwindSafe for Ay3_891xAudio
Blanket Implementations§
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
source§impl<S, T> IntoSample<S> for Twhere
S: FromSample<T>,
impl<S, T> IntoSample<S> for Twhere
S: FromSample<T>,
source§fn into_sample(self) -> S
fn into_sample(self) -> S
S
a sample type from self
.§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> Rwhere
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> Rwhere
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
self
, then passes self.as_ref()
into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
Borrow<B>
of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
BorrowMut<B>
of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
AsRef<R>
view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
AsMut<R>
view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere
Self: Deref<Target = T>,
T: ?Sized,
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere
Self: Deref<Target = T>,
T: ?Sized,
Deref::Target
of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
Deref::Target
of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds. Read more§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
.tap_borrow()
only in debug builds, and is erased in release
builds. Read more§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
.tap_borrow_mut()
only in debug builds, and is erased in release
builds. Read more§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
.tap_ref()
only in debug builds, and is erased in release
builds. Read more§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
.tap_ref_mut()
only in debug builds, and is erased in release
builds. Read more