PWM drives the speaker.

Revision:
3:37a886d77bae
Parent:
0:aba6e62b51a7
--- a/PwmOutSpeaker.h	Fri Mar 24 06:55:24 2017 +0000
+++ b/PwmOutSpeaker.h	Tue Jul 24 08:31:11 2018 +0000
@@ -18,12 +18,12 @@
 #define PWMOUT_SPEAKER_H
 
 #include "mbed.h"
-#include "rtos.h"
+#include "AUDIO_RBSP.h"
 
 /** PwmOutSpeaker class
 *
 */
-class PwmOutSpeaker {
+class PwmOutSpeaker : public AUDIO_RBSP {
 public:
     /** Create a PwmOutSpeaker
      * 
@@ -32,12 +32,16 @@
      */
     PwmOutSpeaker(PinName pwm_l, PinName pwm_r);
 
+    virtual void power(bool type = true) {
+        return;
+    }
+
     /** Set I2S interface bit length and mode
      *
      * @param length Set bit length to 8 or 16 bits
      * @return true = success, false = failure
      */
-    bool format(char length, char ch = 2);
+    virtual bool format(char length);
 
     /** Set sample frequency
      *
@@ -47,7 +51,7 @@
      * Supports the following frequencies: 8kHz, 8.021kHz, 32kHz, 44.1kHz, 48kHz
      * Default is 44.1kHz
      */
-    bool frequency(int hz);
+    virtual bool frequency(int hz);
 
     /** Enqueue asynchronous write request
      *
@@ -55,7 +59,11 @@
      * @param data_size Number of bytes to write
      * @return Number of bytes written on success. negative number on error.
      */
-    int write(uint8_t * const p_data, uint32_t data_size);
+    virtual int write(void * const p_data, uint32_t data_size, const rbsp_data_conf_t * const p_data_conf = NULL);
+
+    virtual int read(void * const p_data, uint32_t data_size, const rbsp_data_conf_t * const p_data_conf = NULL) {
+        return -1;
+    }
 
     /** Volume control
      *
@@ -63,7 +71,11 @@
      * @return Returns "true" for success, "false" if parameters are out of range
      * Parameters accept a value, where 0.0 <= parameter <= 1.0 (1.0 = default)
      */
-    bool outputVolume(float volume);
+    virtual bool outputVolume(float leftVolumeOut, float rightVolumeOut);
+
+    virtual bool micVolume(float VolumeIn) {
+        return false;
+    }
 
 private:
     #define WRITE_BUFF_SIZE    (1024 * 4)
@@ -72,14 +84,14 @@
     PwmOut   _speaker_l;
     PwmOut   _speaker_r;
     Ticker   _timer;
-    int      _channel;
     int      _length;
     int      _hz_multi;
     int      _data_cnt;
     bool     _playing;
     volatile uint32_t _bottom;
     volatile uint32_t _top;
-    float    _speaker_vol;
+    float    _speaker_vol_l;
+    float    _speaker_vol_r;
     float    _pwm_duty_buf[WRITE_BUFF_SIZE];
 
     void sound_out(void);