Parcourir la source

Update WM8731 example

dds
PaulStoffregen il y a 10 ans
Parent
révision
4346fff2fa
4 fichiers modifiés avec 54 ajouts et 62 suppressions
  1. +3
    -0
      control_wm8731.cpp
  2. +1
    -1
      control_wm8731.h
  3. +0
    -61
      examples/HardwareTesting/PlaySineMikroe/PlaySineMikroe.ino
  4. +50
    -0
      examples/HardwareTesting/WM8731MikroSine/WM8731MikroSine.ino

+ 3
- 0
control_wm8731.cpp Voir le fichier

@@ -85,6 +85,9 @@ bool AudioControlWM8731::write(unsigned int reg, unsigned int val)

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;
//Serial.print("volumeInteger, n = ");
//Serial.println(n);

+ 1
- 1
control_wm8731.h Voir le fichier

@@ -34,7 +34,7 @@ class AudioControlWM8731 : public AudioControl
public:
bool enable(void);
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 inputSelect(int n) { return false; }
protected:

+ 0
- 61
examples/HardwareTesting/PlaySineMikroe/PlaySineMikroe.ino Voir le fichier

@@ -1,61 +0,0 @@
#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);
}

+ 50
- 0
examples/HardwareTesting/WM8731MikroSine/WM8731MikroSine.ino Voir le fichier

@@ -0,0 +1,50 @@
// 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() {
}

Chargement…
Annuler
Enregistrer