No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mixer.rs 1.7KB

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