Sound Class Reference
Sound output control class, based on a PwmOut. More...
#include <SoundSPI.h>
Data Structures | |
struct | sound_t |
tone data struct More... | |
Public Member Functions | |
Sound (PinName pwm, PinName kijun) | |
Create a sound object connected to the specified PwmOut pin & DigitalOut pin. | |
bool | sound_sound (void) |
Check tone. | |
void | sound_sound (sound_t data) |
output tone | |
bool | sound_enso (char *path) |
merody data set (file data) | |
void | sound_enso (Sound::sound_t *onpudata) |
merody data set (data table) | |
bool | sound_enso (void) |
check merody | |
void | sound_enso (bool siji) |
request merody start or stop |
Detailed Description
Sound output control class, based on a PwmOut.
Example:
// Output tone and merody #include "mbed.h" #include "Sound.h" // sound library header Sound sound(p21, p10); // 1tu me no sound syuturyoku (pwmOut = p21, digitalOut = p10) <scematic> -------- _/ mbed(p21) -----|R:200ohm|----| | speaker pwmOut -------- | | | | mbed(p10) -------------------|_| digitalOut \ //-------------------------------- // "westminster chime" merody data //-------------------------------- const Sound::sound_t WESTMINSTER[] = { // hanon siji 0:b(flat) 1:tujo 2:#(sharp) // | C1 - B9 kan deno onkai(Gx ha 9x ni okikae te siji) 0xFF=end data // | | time (1/1[ms]/count) // | | | envelope(yoin) (1/1 [ms]/count) // | | | | {1,0xA4,1200,1000}, {1,0xF4,1200,1000}, {1,0x94,1200,1000}, {1,0xC4,2400,1000}, {1,0xC4,1200,1000}, {1,0x94,1200,1000}, {1,0xA4,1200,1000}, {1,0xF4,2400,1000}, {1,0xFF,1000,0}, // end }; /-------------------------------------- * main /--------------------------------------- int main() { //--------------------- // enso data no settei //--------------------- // sound.sound_enso("/local/enso.txt"); // mbed local file data "enso.txt" load (sita ni data no rei wo oite oku) sound.sound_enso((Sound::sound_t*)WESTMINSTER); //--------------------------------------------------- // output tone //--------------------------------------------------- // tone1 Sound::sound_t oto = {1,0x95,200,100}; sound.sound_sound(oto); while(sound.sound_sound() == true){} // tone2 oto.hanon = 1; oto.onkai = 0xA5; oto.time = 2000; oto.envelope = 1000; sound.sound_sound(oto); while(sound.sound_sound() == true){} //--------------- // output merody //-------------- sound.sound_enso(true); while(1) { } *}
Definition at line 128 of file SoundSPI.h.
Constructor & Destructor Documentation
Sound | ( | PinName | pwm, |
PinName | kijun | ||
) |
Create a sound object connected to the specified PwmOut pin & DigitalOut pin.
- Parameters:
-
pin PwmOut pin to connect to pin DigitalOut pin to connect to
Definition at line 19 of file SoundSPI.cpp.
Member Function Documentation
bool sound_enso | ( | char * | path ) |
merody data set (file data)
- Parameters:
-
merody data file path and name (example : "/local/merodyFileName.txt")
Definition at line 249 of file SoundSPI.cpp.
void sound_enso | ( | Sound::sound_t * | onpudata ) |
merody data set (data table)
- Parameters:
-
merody data table name (example : "(Sound::sound_t*)WESTMINSTER")
Definition at line 277 of file SoundSPI.cpp.
bool sound_enso | ( | void | ) |
check merody
- Parameters:
-
raturn ture:merody output //false:merody stop
Definition at line 287 of file SoundSPI.cpp.
void sound_enso | ( | bool | siji ) |
request merody start or stop
- Parameters:
-
ture:start merody //false:stop merody
Definition at line 304 of file SoundSPI.cpp.
void sound_sound | ( | sound_t | data ) |
bool sound_sound | ( | void | ) |
Check tone.
- Parameters:
-
return A bool ture : output \false: none
Definition at line 151 of file SoundSPI.cpp.
Generated on Wed Jul 13 2022 08:40:22 by 1.7.2