summaryrefslogtreecommitdiff
path: root/apps/pcm_recording.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/pcm_recording.c')
-rw-r--r--apps/pcm_recording.c226
1 files changed, 226 insertions, 0 deletions
diff --git a/apps/pcm_recording.c b/apps/pcm_recording.c
new file mode 100644
index 0000000000..dbaf4e0c2a
--- /dev/null
+++ b/apps/pcm_recording.c
@@ -0,0 +1,226 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#include "config.h"
21
22#include <stdio.h>
23#include <stdbool.h>
24#include <stdlib.h>
25
26#include "system.h"
27#include "lcd.h"
28#include "led.h"
29#include "audio.h"
30#include "button.h"
31#include "kernel.h"
32#include "settings.h"
33#include "lang.h"
34#include "font.h"
35#include "icons.h"
36#include "screens.h"
37#include "status.h"
38#include "menu.h"
39#include "sound_menu.h"
40#include "timefuncs.h"
41#include "debug.h"
42#include "misc.h"
43#include "tree.h"
44#include "string.h"
45#include "dir.h"
46#include "errno.h"
47#include "atoi.h"
48#include "sound.h"
49#include "ata.h"
50#include "logf.h"
51#include "uda1380.h"
52#include "pcm_record.h"
53
54
55bool pcm_rec_screen(void)
56{
57 char buf[80];
58 char filename[MAX_PATH];
59 char *rec_sources[2] = {"Line-in","Mic"};
60 int line=0;
61 int play_vol;
62 int rec_monitor, rec_gain, rec_vol, rec_source, rec_count, rec_waveform;
63 int rec_time;
64 int done, button;
65 int w, h;
66
67 lcd_setfont(FONT_SYSFIXED);
68 lcd_getstringsize("M", &w, &h);
69 lcd_setmargins(global_settings.invert_cursor ? 0 : w, 8);
70
71 play_vol = 120;
72
73 //cpu_boost(true);
74
75 uda1380_enable_output(true);
76 uda1380_setvol(play_vol, play_vol);
77
78 rec_monitor = 0; // No record feedback
79 rec_source = 1; // Mic
80 rec_gain = 0; // 0-15
81 rec_vol = 0; // 0-255
82 rec_count = 0;
83 rec_waveform = 0;
84
85 pcm_open_recording();
86 pcm_set_recording_options(rec_source, rec_waveform);
87 pcm_set_recording_gain(rec_gain, rec_vol);
88
89 //rec_create_directory();
90
91 done = 0;
92 while(!done)
93 {
94 line = 0;
95
96 snprintf(buf, sizeof(buf), "PlayVolume: %3d", play_vol);
97 lcd_puts(0,line++, buf);
98 snprintf(buf, sizeof(buf), "Gain : %2d Volume : %2d", rec_gain, rec_vol);
99 lcd_puts(0,line++, buf);
100 snprintf(buf, sizeof(buf), "Monitor: %2d Waveform: %2d", rec_monitor, rec_waveform);
101 lcd_puts(0,line++, buf);
102
103 line++;
104
105 rec_time = pcm_recorded_time();
106
107 snprintf(buf, sizeof(buf), "Status: %s", pcm_status() & AUDIO_STATUS_RECORD ? "RUNNING" : "STOPPED");
108 lcd_puts(0,line++, buf);
109 snprintf(buf, sizeof(buf), "Source: %s", rec_sources[rec_source]);
110 lcd_puts(0,line++, buf);
111 snprintf(buf, sizeof(buf), "File : %s", filename);
112 lcd_puts(0,line++, buf);
113 snprintf(buf, sizeof(buf), "Time : %02d:%02d.%02d", rec_time/HZ/60, (rec_time/HZ)%60, rec_time%HZ);
114 lcd_puts(0,line++, buf);
115
116 line++;
117
118 snprintf(buf, sizeof(buf), "MODE : Select source");
119 lcd_puts(0,line++, buf);
120 snprintf(buf, sizeof(buf), "UP/DOWN : Record volume");
121 lcd_puts(0,line++, buf);
122 snprintf(buf, sizeof(buf), "LFT/RGHT: Record gain");
123 lcd_puts(0,line++, buf);
124 snprintf(buf, sizeof(buf), "RMT MENU: Toggle monitor");
125 lcd_puts(0,line++, buf);
126 snprintf(buf, sizeof(buf), "RMT PLAY: Toggle waveform");
127 lcd_puts(0,line++, buf);
128
129
130 lcd_update();
131
132
133 button = button_get_w_tmo(HZ/8);
134 switch (button)
135 {
136 case BUTTON_OFF:
137 done = true;
138 break;
139
140 case BUTTON_REC:
141 if (pcm_status() & AUDIO_STATUS_RECORD)
142 {
143 pcm_stop_recording();
144
145 } else
146 {
147 snprintf(filename, MAX_PATH, "/record-%0d.wav", rec_count++);
148 pcm_record(filename);
149 }
150 break;
151
152 case BUTTON_ON:
153 break;
154
155 case BUTTON_MODE:
156 rec_source = 1 - rec_source;
157 pcm_set_recording_options(rec_source, rec_waveform);
158 break;
159
160 case BUTTON_RIGHT:
161 case BUTTON_RIGHT | BUTTON_REPEAT:
162 if (rec_gain < 15)
163 rec_gain++;
164
165 pcm_set_recording_gain(rec_gain, rec_vol);
166 break;
167
168 case BUTTON_LEFT:
169 case BUTTON_LEFT | BUTTON_REPEAT:
170 if (rec_gain > 0)
171 rec_gain--;
172
173 pcm_set_recording_gain(rec_gain, rec_vol);
174 break;
175
176 case BUTTON_RC_MENU:
177 rec_monitor = 1 - rec_monitor;
178 uda1380_set_monitor(rec_monitor);
179 break;
180
181 case BUTTON_RC_ON:
182 rec_waveform = 1 - rec_waveform;
183 pcm_set_recording_options(rec_source, rec_waveform);
184 break;
185
186 case BUTTON_UP:
187 case BUTTON_UP | BUTTON_REPEAT:
188 if (rec_vol<255)
189 rec_vol++;
190 pcm_set_recording_gain(rec_gain, rec_vol);
191 break;
192
193 case BUTTON_DOWN:
194 case BUTTON_DOWN | BUTTON_REPEAT:
195 if (rec_vol)
196 rec_vol--;
197 pcm_set_recording_gain(rec_gain, rec_vol);
198 break;
199
200 case SYS_USB_CONNECTED:
201 if (pcm_status() & AUDIO_STATUS_RECORD)
202 {
203 // ignore usb while recording
204 } else
205 {
206 pcm_stop_recording();
207
208 uda1380_enable_output(false);
209
210 default_event_handler(SYS_USB_CONNECTED);
211 return false;
212 }
213 break;
214
215 }
216
217 }
218
219 pcm_stop_recording();
220 pcm_close_recording();
221
222 uda1380_enable_output(false);
223
224 return true;
225}
226