-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSongbirdRecorder.ino
More file actions
146 lines (125 loc) · 3.38 KB
/
SongbirdRecorder.ino
File metadata and controls
146 lines (125 loc) · 3.38 KB
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
/*
* SongbirdRecorder.ino
*
* Songbird Phone Call Recorder - Main Application File
*
* Simple phone call recorder demonstrating:
* - Recording phone calls to SD card in WAV format
* - Playing back recorded calls through headset
* - Basic file management and navigation
* - Real-time audio level monitoring
*
* Hardware Setup:
* - Phone connects via USB-C (provides power and audio interface)
* - Headset connects via 3.5mm jack (microphone and headphones)
* - SD card for storage
* - OLED display for status
* - 4 buttons for control
*/
#include "SongbirdRecorder.h"
// Global state variables
RecorderState currentState = STATE_IDLE;
unsigned long recordStartTime = 0;
int currentFileIndex = 0;
int totalFiles = 0;
String currentFilename = "";
bool sdCardReady = false;
File recordingFile;
uint32_t recordingBytesWritten = 0;
// Audio objects
AudioInputUSB inputFromPhone;
AudioInputI2S inputFromHeadset;
AudioOutputUSB outputToPhone;
AudioOutputI2S outputToHeadset;
AudioMixer4 phoneMixer;
AudioMixer4 phoneOutputMixer;
AudioMixer4 leftHeadphonesMixer;
AudioMixer4 rightHeadphonesMixer;
AudioRecordQueue recordQueue;
AudioPlaySdWav playWav;
AudioAnalyzeRMS inputLevel;
AudioControlSGTL5000 audioShield;
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire1, OLED_RESET);
AudioSynthWaveformSine recordBeep;
void setup()
{
Serial.begin(9600);
Serial.println("Songbird Phone Call Recorder Starting...");
// Initialize hardware pins
// LEDs
pinMode(LED_1_PIN, OUTPUT);
pinMode(LED_2_PIN, OUTPUT);
// Buttons
pinMode(BTN_UP_PIN, INPUT_PULLUP);
pinMode(BTN_DOWN_PIN, INPUT_PULLUP);
pinMode(BTN_LEFT_PIN, INPUT_PULLUP);
pinMode(BTN_RIGHT_PIN, INPUT_PULLUP);
// Turn off LEDs initially
digitalWrite(LED_1_PIN, LOW);
digitalWrite(LED_2_PIN, LOW);
// Initialize I2C for display
Wire1.begin();
Wire1.setSDA(OLED_SDA_PIN);
Wire1.setSCL(OLED_SCL_PIN);
setupAudioProcessing();
initializeSDCard();
initializeDisplay();
updateDisplay();
Serial.println("Songbird Recorder is ready.");
Serial.println("Commands: LIST, DELETE filename.wav, DELETEALL, HELP");
}
void loop()
{
// Handle button presses
handleButtons();
// Handle active recording
if (currentState == STATE_RECORDING)
{
// static unsigned long lastReminderBeep = 0;
// if (millis() - lastReminderBeep > 30000) { // Every 30 seconds
// playRecordingBeep();
// lastReminderBeep = millis();
// }
handleRecording();
}
// Check if playback is finished
if (currentState == STATE_PLAYBACK && !playWav.isPlaying())
{
stopPlayback();
}
// Update the display periodically
static unsigned long lastDisplayUpdate = 0;
if (millis() - lastDisplayUpdate > 250)
{
// Updates 4 times per second
updateDisplay();
lastDisplayUpdate = millis();
}
// Check SD card status periodically
static unsigned long lastSDCheck = 0;
if (millis() - lastSDCheck > 2000) // Check every 2 seconds
{
checkSDCardStatus();
lastSDCheck = millis();
}
handleSerialCommands();
// Update LED brightness based on audio level
if (currentState == STATE_RECORDING)
{
float level = getInputLevel();
analogWrite(LED_1_PIN, (int)(level * 255));
}
else
{
digitalWrite(LED_1_PIN, LOW);
}
// Playback LED
if (currentState == STATE_PLAYBACK)
{
digitalWrite(LED_2_PIN, HIGH);
}
else
{
digitalWrite(LED_2_PIN, LOW);
}
}