1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
    Copyright (C) 2020-2022  Rafal Michalski

    This file is part of SPECTRUSTY, a Rust library for building emulators.

    For the full copyright notice, see the lib.rs file.
*/
use core::num::NonZeroU32;
use crate::audio::*;
#[cfg(feature = "peripherals")]
use crate::peripherals::ay::audio::AyAudioFrame;
#[cfg(feature = "peripherals")]
use crate::peripherals::bus::ay::AyAudioBusDevice;
use crate::bus::BusDevice;
use crate::clock::VFrameTs;
use crate::memory::PagedMemory8k;
use crate::chip::{
    EarIn, MicOut, ReadEarMode,
    ula::Ula
};
use crate::video::VideoFrame;
use super::Scld;

#[cfg(feature = "peripherals")]
impl<A, M, B, X, V> AyAudioFrame<A> for Scld<M, B, X, V>
    where A: Blep,
          M: PagedMemory8k,
          B: AyAudioBusDevice + BusDevice,
          B::Timestamp: From<VFrameTs<V>>,
          V: VideoFrame
{
    #[inline]
    fn render_ay_audio_frame<L: AmpLevels<A::SampleDelta>>(&mut self, blep: &mut A, chans: [usize; 3]) {
        self.ula.render_ay_audio_frame::<L>(blep, chans)
    }
}

impl<A, M, B, X, V> AudioFrame<A> for Scld<M, B, X, V>
    where A: Blep,
          M: PagedMemory8k,
          Ula<M, B, X, V>: AudioFrame<A>
{
    #[inline]
    fn ensure_audio_frame_time(&self, blep: &mut A, sample_rate: u32, cpu_hz: f64) {
        self.ula.ensure_audio_frame_time(blep, sample_rate, cpu_hz)
    }

    #[inline]
    fn get_audio_frame_end_time(&self) -> FTs {
        self.ula.get_audio_frame_end_time()
    }
}

impl<A, M, B, X, F> EarMicOutAudioFrame<A> for Scld<M, B, X, F>
    where A: Blep,
          M: PagedMemory8k,
          F: VideoFrame
{
    #[inline(always)]
    fn render_earmic_out_audio_frame<V: AmpLevels<A::SampleDelta>>(&self, blep: &mut A, channel: usize) {
        self.ula.render_earmic_out_audio_frame::<V>(blep, channel)
    }
}

impl<A, M, B, X, F> EarInAudioFrame<A> for Scld<M, B, X, F>
    where A: Blep,
          M: PagedMemory8k,
          F: VideoFrame
{
    #[inline(always)]
    fn render_ear_in_audio_frame<V: AmpLevels<A::SampleDelta>>(&self, blep: &mut A, channel: usize) {
        self.ula.render_ear_in_audio_frame::<V>(blep, channel)
    }
}

impl<M, B, X, V> EarIn for Scld<M, B, X, V>
    where M: PagedMemory8k,
          V: VideoFrame
{
    fn set_ear_in(&mut self, ear_in: bool, delta_fts: u32) {
        self.ula.set_ear_in(ear_in, delta_fts)
    }

    fn feed_ear_in<I>(&mut self, fts_deltas: I, max_frames_threshold: Option<usize>)
        where I: Iterator<Item=NonZeroU32>
    {
        self.ula.feed_ear_in(fts_deltas, max_frames_threshold)
    }

    fn purge_ear_in_changes(&mut self, ear_in: bool) {
        self.ula.purge_ear_in_changes(ear_in)
    }

    fn read_ear_in_count(&self) -> u32 {
        self.ula.read_ear_in_count()
    }

    fn read_ear_mode(&self) -> ReadEarMode {
        self.ula.read_ear_mode()
    }

    fn set_read_ear_mode(&mut self, mode: ReadEarMode) {
        self.ula.set_read_ear_mode(mode)
    }
}

impl<'a, M: 'a, B: 'a, X: 'a, V: 'a> MicOut<'a> for Scld<M, B, X, V>
    where M: PagedMemory8k,
          V: VideoFrame
{
    type PulseIter = <Ula<M, B, X, V> as MicOut<'a>>::PulseIter;
    fn mic_out_pulse_iter(&'a self) -> Self::PulseIter {
        self.ula.mic_out_pulse_iter()
    }
}