3 Commits

Author SHA1 Message Date
4a04e95757 readme update 2025-06-17 16:29:03 +02:00
06642bd570 beeps and clicks and more config options for colors 2025-06-17 16:19:42 +02:00
07323ec068 readme update 2025-06-17 12:20:52 +02:00
2 changed files with 139 additions and 52 deletions

View File

@ -13,9 +13,8 @@
## SD Card contents ## SD Card contents
´´´ ```
config.txt config.txt
click.wav
sound/ sound/
├─ 1.wav ├─ 1.wav
├─ 2.wav ├─ 2.wav
@ -25,8 +24,11 @@ sound/
├─ 6.wav ├─ 6.wav
├─ 7.wav ├─ 7.wav
├─ 8.wav ├─ 8.wav
ui/
├─ click.wav
├─ beep.wav
´´´ ```
### config.txt ### config.txt
@ -34,45 +36,89 @@ Json formatted config file. For now only edge led color working.
``` ```
{ {
"boxid":"",
"edge": { "edge": {
"color":{ "color":{
"idle":{
"r":50, "r":50,
"g":0, "g":0,
"b":0 "b":50
},
"active":{
"r":0,
"g":50,
"b":50
}
}
},
"ring": {
"color":{
"idle":{
"r":0,
"g":50,
"b":50
},
"active":{
"r":0,
"g":80,
"b":50
}
} }
} }
} }
``` ```
### click.wav ## Sound
Put a file called `click.wav` (not longer than a few seconds) in the root of the SD card and it will play when you press a button. ### UI
There are two UI sounds - `click.wav` and `beep.wav`.
- `click.wav` is played when a button is pressed other than the select button
- `beep.wav` is played when the rotary encoder select button is pressed
Put these files in the subfolder `ui` on the SD card.
#### Wave File Format for UI Sounds
`click.wav` needs to be **22050Hz (22kHz) 16bit Mono**
### Sounds ### Audio Out or Speakers
Put all sounds into the ´/sound´ subfolder. Name them ´1.wav, 2.wav, 3.wav...´ Put all sounds into the `/sound` subfolder. Name them `1.wav, 2.wav, 3.wav...`
## Wave File Format #### Wave File Format for Audio Out and Speakers
Export all sounds as **48000Hz (48kHz) 16bit Stereo**.
Export all sounds except ´click.wav´ as **48000Hz (48kHz) 16bit Stereo**.
### Audacity ### Audacity
You can use Audacity to export all soundfiles to WAV format. You can use Audacity to export all soundfiles to WAV format.
Download it here [Github](https://github.com/audacity/audacity/releases)
1. Load file into Audacity 1. Load file into Audacity
2. Select Track 2. Select Track
3. File -> Export Audio 3. File -> Export Audio
#### Format options in Audacity #### Format options in Audacity
**Audio Out**
- WAV(Microsoft) - WAV(Microsoft)
- Chanels: Stereo - Chanels: Stereo
- Samplerate: 48000Hz - Samplerate: 48000Hz
- Encoding: Signed 16-bit PCM - Encoding: Signed 16-bit PCM
**UI**
- WAV(Microsoft)
- Channels: Mono
- Samplerate: 22050Hz
- Encoding: Signed 16-bit PCM
---- ----

View File

@ -56,22 +56,34 @@ CRGB ui_leds[74];
CRGB edge_leds[11]; CRGB edge_leds[11];
volatile bool buttonChanged = false; volatile bool buttonChanged = false;
volatile bool click = false; volatile bool ui_click = false;
volatile bool ui_beep = false;
volatile bool amp = false; volatile bool amp = false;
int counter = 0; int counter = 0;
bool buttons[16] = {false}; bool buttons[16] = {false};
int16_t beep[UI_SAMPLERATE]; int16_t ui_click_snd[UI_SAMPLERATE];
uint16_t click_length = 0;
int16_t ui_beep_snd[UI_SAMPLERATE];
uint16_t beep_length = 0; uint16_t beep_length = 0;
bool sd_card_detected = false; bool sd_card_detected = false;
struct Color {
int r;
int g;
int b;
int r_active;
int g_active;
int b_active;
};
struct Config { struct Config {
int edge_color_r = 0; Color edge_color = {0,0,50,0,50,0};
int edge_color_g = 0; Color ring_color = {0,50,50,0,80,50};
int edge_color_b = 50;
}; };
Config config; Config config;
@ -83,9 +95,19 @@ void loadConfiguration(Config& config) {
DeserializationError error = deserializeJson(doc, file); DeserializationError error = deserializeJson(doc, file);
if(error) Serial.println(F("Failed to read file, using default configuration")); if(error) Serial.println(F("Failed to read file, using default configuration"));
config.edge_color_r = doc["edge"]["color"]["r"] | 0; config.edge_color.r = doc["edge"]["color"]["idle"]["r"] | 0;
config.edge_color_g = doc["edge"]["color"]["g"] | 0; config.edge_color.g = doc["edge"]["color"]["idle"]["g"] | 0;
config.edge_color_b = doc["edge"]["color"]["b"] | 50; config.edge_color.b = doc["edge"]["color"]["idle"]["b"] | 50;
config.edge_color.r_active = doc["edge"]["color"]["active"]["r"] | 0;
config.edge_color.g_active = doc["edge"]["color"]["active"]["g"] | 50;
config.edge_color.b_active = doc["edge"]["color"]["active"]["b"] | 0;
config.ring_color.r = doc["ring"]["color"]["idle"]["r"] | 0;
config.ring_color.g = doc["ring"]["color"]["idle"]["g"] | 50;
config.ring_color.b = doc["ring"]["color"]["idle"]["b"] | 50;
config.ring_color.r_active = doc["ring"]["color"]["active"]["r"] | 0;
config.ring_color.g_active = doc["ring"]["color"]["active"]["g"] | 80;
config.ring_color.b_active = doc["ring"]["color"]["active"]["b"] | 50;
//strlcpy(config.hostname, doc["hostname"] | "example.com", sizeof(config.hostname)); //strlcpy(config.hostname, doc["hostname"] | "example.com", sizeof(config.hostname));
@ -116,12 +138,23 @@ void codec_receive(){
void pwm_audio_callback() { void pwm_audio_callback() {
while (ui_snd.availableForWrite()) { while (ui_snd.availableForWrite()) {
if(click) { if(ui_click || ui_beep) {
ui_snd.write(beep[counter]); if(ui_beep) {
ui_snd.write(ui_beep_snd[counter]);
counter++; counter++;
if(counter == beep_length) { if(counter == beep_length) {
counter = 0; counter = 0;
click = false; ui_beep = false;
}
continue;
}
if(ui_click) {
ui_snd.write(ui_click_snd[counter]);
counter++;
if(counter == click_length) {
counter = 0;
ui_click = false;
}
} }
} else { } else {
digitalWrite(7, LOW); digitalWrite(7, LOW);
@ -131,6 +164,32 @@ void pwm_audio_callback() {
} }
} }
bool load_ui_sounds(const char* file, int16_t *buffer, uint16_t &length){
if(SD.exists(file)) {
File f_click = SD.open(file);
f_click.seek(44, SeekSet);
int click_bytes = 0;
while (f_click.available() && click_bytes < UI_SAMPLERATE) {
uint8_t samplebyte[2];
f_click.read(samplebyte, 2);
int16_t sample = (samplebyte[1] << 8) + samplebyte[0];
buffer[click_bytes] = sample;
click_bytes++;
}
f_click.close();
length = click_bytes;
return true;
} else {
for(int i = 0; i < UI_SAMPLERATE; i++){
float sine_pos = (2.0f * M_PI * 3000.0f * (float)i) / (float)UI_SAMPLERATE;
buffer[i] = (int16_t)(sin(sine_pos) * 8000.0f);
}
Serial.println("Synthesized 8kHz sine into beep array.");
length = UI_SAMPLERATE;
}
return false;
}
void tca_irq() { void tca_irq() {
buttonChanged = true; buttonChanged = true;
} }
@ -170,27 +229,9 @@ void setup() {
if(sdInitialized) loadConfiguration(config); if(sdInitialized) loadConfiguration(config);
if(sdInitialized && SD.exists("/click.wav")) { if(sdInitialized){
File click = SD.open("/click.wav"); load_ui_sounds("/ui/click.wav", ui_click_snd, click_length);
click.seek(44, SeekSet); load_ui_sounds("/ui/beep.wav", ui_beep_snd, beep_length);
int click_bytes = 0;
while (click.available() || click_bytes == UI_SAMPLERATE-1) {
uint8_t samplebyte[2];
click.read(samplebyte, 2);
int16_t sample = (samplebyte[1] << 8) + samplebyte[0];
beep[click_bytes] = sample;
click_bytes++;
}
click.close();
beep_length = click_bytes;
} else {
for(int i = 0; i < UI_SAMPLERATE; i++){
float sine_pos = (2.0f * M_PI * 8000.0f * (float)i) / (float)UI_SAMPLERATE;
beep[i] = (int16_t)(sin(sine_pos) * 8000.0f);
}
Serial.println("Synthesized 8kHz sine into beep array.");
beep_length = UI_SAMPLERATE;
} }
Serial.println("INIT WIRE"); Serial.println("INIT WIRE");
@ -220,7 +261,7 @@ void setup() {
ui_snd.onTransmit(pwm_audio_callback); ui_snd.onTransmit(pwm_audio_callback);
ui_snd.begin(UI_SAMPLERATE); ui_snd.begin(UI_SAMPLERATE);
digitalWrite(7, LOW); digitalWrite(7, LOW); // UI amp off
pinMode(19, OUTPUT); // MCLK enable pinMode(19, OUTPUT); // MCLK enable
digitalWrite(19, HIGH); // enable MCLK digitalWrite(19, HIGH); // enable MCLK
@ -294,7 +335,6 @@ void setup() {
digitalWrite(6, HIGH); digitalWrite(6, HIGH);
delay(25); delay(25);
digitalWrite(6, LOW); digitalWrite(6, LOW);
} }
bool dactest = false; bool dactest = false;
@ -308,7 +348,7 @@ void loop() {
// EDGE LEDs // EDGE LEDs
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
edge_leds[i] = CRGB(config.edge_color_r, config.edge_color_g, config.edge_color_b); edge_leds[i] = CRGB(config.edge_color.r, config.edge_color.g, config.edge_color.b);
} }
// LED Ring leeren // LED Ring leeren
@ -353,7 +393,7 @@ void loop() {
// Make beep // Make beep
if (AURAL && buttonDown) { if (AURAL && buttonDown) {
digitalWrite(7, HIGH); digitalWrite(7, HIGH);
click = true; ui_click = true;
} }
// Flash encoder leds // Flash encoder leds
@ -390,6 +430,7 @@ void loop() {
if(buttons[SELECT]){ if(buttons[SELECT]){
stream[active % NSTREAMS].toggle(); stream[active % NSTREAMS].toggle();
ui_beep = true;
} }
Serial.println(codec.getVolumeL()); Serial.println(codec.getVolumeL());
@ -418,7 +459,7 @@ void loop() {
// set active LED ring LED // set active LED ring LED
for(int i = 0; i < active_led_ring; i++){ for(int i = 0; i < active_led_ring; i++){
ui_leds[lut_ring_ccw[i]] = CRGB(50, 0, 25); ui_leds[lut_ring_ccw[i]] = CRGB(config.ring_color.r, config.ring_color.g, config.ring_color.b);
} }
FastLED.show(); FastLED.show();