Parcourir la source

firmware: Some stubs for the audio mixing code.

Mathias Gottschlag il y a 5 ans
Parent
révision
dde38551ef
1 fichiers modifiés avec 55 ajouts et 0 suppressions
  1. 55
    0
      hackamp/firmware/src/mixer.rs

+ 55
- 0
hackamp/firmware/src/mixer.rs Voir le fichier

@@ -1,2 +1,57 @@
1 1
 //! Functionality to mix and forward different audio streams.
2 2
 #![warn(missing_docs)]
3
+
4
+use cortex_m::interrupt;
5
+
6
+use super::audio_buffer::AudioBuffer;
7
+
8
+/// The mixer connects several upstream audio ports (i.e., USB audio device interface) to one
9
+/// downstream audio port.
10
+///
11
+/// The audio from the upstream ports is mixed and forwarded to the downstream port. The audio from
12
+/// the downstream port (i.e., microphone) is forwarded to all upstream ports.
13
+pub struct Mixer {
14
+    usb1: AudioPort,
15
+    amp: AudioPort,
16
+}
17
+
18
+impl Mixer {
19
+    /// Creates a new mixer for the specified audio ports.
20
+    pub fn new(usb1: AudioPort, amp: AudioPort) -> Mixer {
21
+        Mixer { usb1, amp }
22
+    }
23
+
24
+    /// Checks whether data can be read from the audio ports and mixes/forwards it as required.
25
+    ///
26
+    /// The function returns true if any data was sent to any audio port.
27
+    pub fn poll(&mut self) -> bool {
28
+        interrupt::free(|cs| {
29
+            if self.usb1.in_.can_read(cs) {
30
+                // TODO
31
+            }
32
+            if self.amp.in_.can_read(cs) {
33
+                // TODO
34
+            }
35
+            // TODO
36
+        });
37
+        false
38
+    }
39
+}
40
+
41
+/// The connection between an audio source/sink and the mixer.
42
+///
43
+/// The connection is made via two buffers (one for input, one for output).
44
+pub struct AudioPort {
45
+    // TODO: Fields and functions to set the volume and to mute the port.
46
+    in_: &'static AudioBuffer,
47
+    out: &'static AudioBuffer,
48
+}
49
+
50
+impl AudioPort {
51
+    /// Creates a new audio port.
52
+    ///
53
+    /// The port is initially muted and set to maximum volume.
54
+    pub fn new(in_: &'static AudioBuffer, out: &'static AudioBuffer) -> AudioPort {
55
+        AudioPort { in_, out }
56
+    }
57
+}

Loading…
Annuler
Enregistrer