bool AudioControlWM8731::volumeInteger(unsigned int n) | bool AudioControlWM8731::volumeInteger(unsigned int n) | ||||
{ | { | ||||
// n = 127 for max volume (+6 dB) | |||||
// n = 48 for min volume (-73 dB) | |||||
// n = 0 to 47 for mute | |||||
if (n > 127) n = 127; | if (n > 127) n = 127; | ||||
//Serial.print("volumeInteger, n = "); | //Serial.print("volumeInteger, n = "); | ||||
//Serial.println(n); | //Serial.println(n); |
public: | public: | ||||
bool enable(void); | bool enable(void); | ||||
bool disable(void) { return false; } | bool disable(void) { return false; } | ||||
bool volume(float n) { return volumeInteger(n * 0.8 + 47.499); } | |||||
bool volume(float n) { return volumeInteger(n * 80.0 + 47.499); } | |||||
bool inputLevel(float n) { return false; } | bool inputLevel(float n) { return false; } | ||||
bool inputSelect(int n) { return false; } | bool inputSelect(int n) { return false; } | ||||
protected: | protected: |
#include <Audio.h> | |||||
#include <Wire.h> | |||||
#include <SPI.h> | |||||
#include <SD.h> | |||||
AudioSynthWaveform mysine(AudioWaveformSine); | |||||
AudioOutputI2Sslave dac; | |||||
AudioControlWM8731master codec; | |||||
AudioConnection c1(mysine,dac); | |||||
int volume = 0; | |||||
void setup() { | |||||
codec.enable(); | |||||
delay(100); | |||||
while (!Serial) ; | |||||
Serial.println("Begin AudioTest"); | |||||
// Audio connections require memory to work. For more | |||||
// detailed information, see the MemoryAndCpuUsage example | |||||
AudioMemory(15); | |||||
mysine.frequency(440); | |||||
mysine.amplitude(0.9); | |||||
codec.volume(0.70); | |||||
Serial.println("setup done"); | |||||
} | |||||
void loop() { | |||||
/* | |||||
Serial.print("cpu: "); | |||||
Serial.print(AudioProcessorUsage()); | |||||
Serial.print(", max: "); | |||||
Serial.print(AudioProcessorUsageMax()); | |||||
Serial.print(", memory: "); | |||||
Serial.print(AudioMemoryUsage()); | |||||
Serial.print(", max: "); | |||||
Serial.print(AudioMemoryUsageMax()); | |||||
Serial.println(""); | |||||
*/ | |||||
//int n; | |||||
//n = analogRead(15); | |||||
//Serial.println(n); | |||||
//if (n != volume) { | |||||
//volume = n; | |||||
//codec.volume((float)n / 10.23); | |||||
//} | |||||
//n = analogRead(16) / 8; | |||||
//Serial.println(n); | |||||
//mysine.frequency(200 + n * 4); | |||||
//delay(5); | |||||
} |
// Simple sine wave test for WM8731 Audio Codec Board | |||||
// | |||||
// Requires the MikroElektronika Audio Codec board or similar hardware | |||||
// http://www.mikroe.com/add-on-boards/audio-voice/audio-codec-proto/ | |||||
// | |||||
// Recommended connections: | |||||
// | |||||
// Mikroe Teensy 3.1 | |||||
// ------ ---------- | |||||
// SCK 9 | |||||
// MISO 13 | |||||
// MOSI 22 | |||||
// ADCL | |||||
// DACL 23 | |||||
// SDA 18 | |||||
// SCL 19 | |||||
// 3.3V +3.3V | |||||
// GND GND | |||||
// | |||||
// This example code is in the public domain. | |||||
#include <Audio.h> | |||||
#include <Wire.h> | |||||
#include <SPI.h> | |||||
#include <SD.h> | |||||
// GUItool: begin automatically generated code | |||||
AudioSynthWaveform waveform1; //xy=110,75 | |||||
AudioOutputI2Sslave i2ss1; //xy=303,78 | |||||
AudioConnection patchCord1(waveform1, 0, i2ss1, 0); | |||||
AudioConnection patchCord2(waveform1, 0, i2ss1, 1); | |||||
AudioControlWM8731master wm8731m1; //xy=230,154 | |||||
// GUItool: end automatically generated code | |||||
void setup() { | |||||
wm8731m1.enable(); | |||||
AudioMemory(15); | |||||
waveform1.begin(WAVEFORM_SINE); | |||||
waveform1.frequency(440); | |||||
waveform1.amplitude(0.9); | |||||
wm8731m1.volume(0.50); | |||||
} | |||||
void loop() { | |||||
} |