forked from becauseinterwebs/tktalkie-v4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tktalkieV4.ino
208 lines (188 loc) · 6.42 KB
/
tktalkieV4.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/****
* TK TALKIE by TK-81113 (Brent Williams) <becauseinterwebs@gmail.com>
* www.tktalkie.com / www.tk81113.com
*
* Version 4.4
*
* WhiteArmor.net User ID: lerxstrulz
*
* This sketch is meant to use a Teensy 3.2 with a Teensy Audio Shield and
* reads sounds from an SD card and plays them after the user stops talking
* to simulate comm noise such as clicks and static. This version adds a lot
* of new features, including the ability to be controlled via a mobile app
* and Bluetooth. This release also introduces memory optimizations and other
* improvements.
*
* You are free to use this code in your own projects, provided they are for
* personal, non-commercial use.
*
* The audio components and connections were made using the GUI tool
* available at http://www.pjrc.com/teensy/gui. If you want to modify
* the signal path, add more effects, etc., you can copy and paste the
* code marked by 'GUITool' into the online editor at the above URL.
*
* WHAT'S NEW:
*
* v4.4 (06/02/2022)
* 1. Added check for wake button in sleep check. If no wake button is programmed,
* it will not go to sleep.
* 2. Added sleep timeout reset to button press events (previously only on voice events.)
* 3. Added audio interrupt calls for file operations
*
* v4.3 (04/29/18)
* 1. Reorganized include files for easier management.
* 2. Upgraded ArduinoJson to version 6.
*
* v4.2 (12/17/18)
* 1. Added ability to play random sound on PTT button release
* (previously only random or none)
* 2. Added ability to play fixed, random or no sound when mic is
* activated in VA mode (prevously no sound played.)
* 3. Added ability to play fixed sound (previously only random or none)
* when user stops talking in VA mode.
*
* v4.1 (12/10/18)
* 1. Misc bug fixes regarding loading profiles
*
* v4.0 (12/03/17)
* 1. Added Chorus and Flange processing for the voice channel.
* 2. Added a dry (unprocessed) voice channel.
*
* V3.15 (10/20/17)
* 1. Add support for 3 sound-glove buttons.
*
* V3.14 (10/10/17)
* 1. Added AUTO SLEEP function to put the TK-Talkie to sleep to conserve
* battery if no sound is heard from the microphone for a pre-configured
* amount of time (configurable by the user.)
*
* V3.13 (10/1/17)
* 1. Add mute_effects option to stop effects from playing after talkings
*
* 2. Startup sound, if specified, will always play even if effects level is 0
*
* 3. Allowed for empty effects.dir option
*
* 4. Added App.app_ver so sketch will know what version of the APP is accessing
* it. This is for future use.
*
* V3.1 (5/30/2017)
* 1. Added new setting to the CONFIG.TXT control file to alert the
* mobile app which input/volume controls should be presented.
* Valid values are:
* MIC = Show the microphone jack controls only
* LINE = Show the line-in controls only
* BOTH = Show mic/line-in controls and input switcher
* By default this is set to BOTH for backwards compatibility. As of
* version 3.1 of the TKTalkie hardware, inputs are wired to mic only
* as it will support both wired and wireless microphones.
*
* 2. Added new settings to the CONFIG.TXT control file to alert the
* mobile app which output/volume controls should be presented.
* Valid values are:
* SPKR = Show only headphones/speaker controls
* LINE = Show only line-out controls
* BOTH = Show both
* By default this is set to BOTH for backwards compatibility
*
* 3. Add new option (all versions) to allow background loop to continue
* playing while talking (loop is paused by default)
*
* 4. Fixed bug that prevented PTT button setting up properly.
*
* V3.0 (4/10/2017)
* 1. Modified to be able to communicate via Bluetooth Low Energy (BLE)
* serial adapter with mobile app for control of settings and profile
* switching.
* 2. Began optimizations on usage of C-type strings to reduce memory usage.
* 3. Added new commands specific to BLE adapter usage.
* 4. Added new commands to manage multiple configuration profiles.
* 5. Reorganized SD card files and folders
*
* Please visit http://www.tktalkie.com/changelog for prior changes.
*/
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <Snooze.h>
#include <Bounce2.h>
#include <ArduinoJson.h>
#include "ControlButton.h"
#include "globals.h"
#include "utils.h"
#include "files.h"
#include "sounds.h"
#include "calibrate.h"
#include "settings.h"
#include "ble.h"
#include "main.h"
/***
* Initial setup...runs only once when the board is turned on.
*/
void setup()
{
// Not used yet
//analogReference(DEFAULT);
//analogReadResolution(12);
//analogReadAveraging(32);
/*
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
delay(250);
digitalWrite(LED_BUILTIN, HIGH);
*/
App.state = STATE_BOOTING;
// Serial connection for debugging
Serial.begin(57600);
delay(250);
// Always allocate memory for the audio shield!
AudioMemory(16);
// turn on audio shield
audioShield.enable();
// disable volume and outputs during setup to avoid pops
audioShield.muteLineout();
audioShield.muteHeadphone();
audioShield.volume(0);
// turn on post processing
audioShield.audioPostProcessorEnable();
// Initialize sound generator for warning tones when we switch modes from PTT back to Voice Activated
waveform1.begin(WAVEFORM_SINE);
// Check SD card
SPI.setMOSI(7); // Set to 7 for Teensy
SPI.setSCK(14); // Set to 14 for Teensy
// CS Pin is 10...do not change for Teensy!
if (!(SD.begin(10))) {
Serial.println("Unable to access the SD card.");
Serial.println("Using default built-in profile");
App.SD_OK = false;
beep(2);
}
// this just makes sure we get truly random numbers each time
// when choosing a file to play from the list later on...
randomSeed(analogRead(0));
// wait half a sec to give everything time to power up
delay(500);
// set volume of effects feed into master mixer
voiceMixer.gain(3, 1);
// load startup settings
startup();
}
/***
* Main program loop
*/
void loop()
{
switch (App.state) {
case STATE_NONE:
case STATE_BOOTING:
case STATE_SLEEPING:
// do nothing
break;
case STATE_RUNNING:
// normal program operation
run();
break;
}
}