Minor cleanup and correct the copyright
[Rockbox.git] / apps / pcm_recording.c
blob21ca68f4e0389edce178562e32de909ec73c32a8
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
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.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include "config.h"
22 #include <stdio.h>
23 #include <stdbool.h>
24 #include <stdlib.h>
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 #if defined(HAVE_UDA1380)
52 #include "uda1380.h"
53 #elif defined(HAVE_TLV320)
54 #include "tlv320.h"
55 #endif
56 #include "pcm_record.h"
58 #if defined(HAVE_UDA1380) || defined(HAVE_TLV320)
60 bool pcm_rec_screen(void)
62 char buf[80];
63 char filename[MAX_PATH];
64 char *rec_sources[2] = {"Line-in","Mic"};
65 int line=0;
66 int play_vol;
67 int rec_monitor, rec_gain, rec_vol, rec_source, rec_count, rec_waveform;
68 int rec_time;
69 int done, button;
70 int w, h;
72 lcd_setfont(FONT_SYSFIXED);
73 lcd_getstringsize("M", &w, &h);
74 lcd_setmargins(0, 8);
76 play_vol = 120;
78 //cpu_boost(true);
80 #if defined(HAVE_UDA1380)
81 uda1380_enable_output(true);
82 #elif defined(HAVE_TLV320)
83 tlv320_enable_output(true);
84 #endif
86 #if defined(HAVE_UDA1380)
87 uda1380_set_master_vol(play_vol, play_vol);
88 #elif defined(HAVE_TLV320)
89 tlv320_set_headphone_vol(play_vol, play_vol);
90 #endif
92 rec_monitor = 0; // No record feedback
93 rec_source = 1; // Mic
94 rec_gain = 0; // 0-15
95 rec_vol = 0; // 0-255
96 rec_count = 0;
97 rec_waveform = 0;
99 pcm_open_recording();
100 pcm_set_recording_options(rec_source, rec_waveform);
101 pcm_set_recording_gain(rec_gain, rec_vol);
103 //rec_create_directory();
105 done = 0;
106 while(!done)
108 line = 0;
110 snprintf(buf, sizeof(buf), "PlayVolume: %3d", play_vol);
111 lcd_puts(0,line++, buf);
112 snprintf(buf, sizeof(buf), "Gain : %2d Volume : %2d", rec_gain, rec_vol);
113 lcd_puts(0,line++, buf);
114 snprintf(buf, sizeof(buf), "Monitor: %2d Waveform: %2d", rec_monitor, rec_waveform);
115 lcd_puts(0,line++, buf);
117 line++;
119 rec_time = pcm_recorded_time();
121 snprintf(buf, sizeof(buf), "Status: %s", pcm_status() & AUDIO_STATUS_RECORD ? "RUNNING" : "STOPPED");
122 lcd_puts(0,line++, buf);
123 snprintf(buf, sizeof(buf), "Source: %s", rec_sources[rec_source]);
124 lcd_puts(0,line++, buf);
125 snprintf(buf, sizeof(buf), "File : %s", filename);
126 lcd_puts(0,line++, buf);
127 snprintf(buf, sizeof(buf), "Time : %02d:%02d.%02d", rec_time/HZ/60, (rec_time/HZ)%60, rec_time%HZ);
128 lcd_puts(0,line++, buf);
130 line++;
132 snprintf(buf, sizeof(buf), "MODE : Select source");
133 lcd_puts(0,line++, buf);
134 snprintf(buf, sizeof(buf), "UP/DOWN : Record volume");
135 lcd_puts(0,line++, buf);
136 snprintf(buf, sizeof(buf), "LFT/RGHT: Record gain");
137 lcd_puts(0,line++, buf);
138 snprintf(buf, sizeof(buf), "RMT MENU: Toggle monitor");
139 lcd_puts(0,line++, buf);
140 snprintf(buf, sizeof(buf), "RMT PLAY: Toggle waveform");
141 lcd_puts(0,line++, buf);
144 lcd_update();
147 button = button_get_w_tmo(HZ/8);
148 switch (button)
150 case BUTTON_OFF:
151 done = true;
152 break;
154 case BUTTON_REC:
155 if (pcm_status() & AUDIO_STATUS_RECORD)
157 pcm_stop_recording();
159 } else
161 create_numbered_filename(filename, "/", "rec_", ".wav", 4);
162 pcm_record(filename);
164 break;
166 case BUTTON_ON:
167 break;
169 case BUTTON_MODE:
170 rec_source = 1 - rec_source;
171 pcm_set_recording_options(rec_source, rec_waveform);
172 break;
174 case BUTTON_RIGHT:
175 case BUTTON_RIGHT | BUTTON_REPEAT:
176 if (rec_gain < 15)
177 rec_gain++;
179 pcm_set_recording_gain(rec_gain, rec_vol);
180 break;
182 case BUTTON_LEFT:
183 case BUTTON_LEFT | BUTTON_REPEAT:
184 if (rec_gain > 0)
185 rec_gain--;
187 pcm_set_recording_gain(rec_gain, rec_vol);
188 break;
190 case BUTTON_RC_MENU:
191 rec_monitor = 1 - rec_monitor;
192 #if defined(HAVE_UDA1380)
193 uda1380_set_monitor(rec_monitor);
194 #endif
195 break;
197 case BUTTON_RC_ON:
198 rec_waveform = 1 - rec_waveform;
199 pcm_set_recording_options(rec_source, rec_waveform);
200 break;
202 case BUTTON_UP:
203 case BUTTON_UP | BUTTON_REPEAT:
204 if (rec_vol<255)
205 rec_vol++;
206 pcm_set_recording_gain(rec_gain, rec_vol);
207 break;
209 case BUTTON_DOWN:
210 case BUTTON_DOWN | BUTTON_REPEAT:
211 if (rec_vol)
212 rec_vol--;
213 pcm_set_recording_gain(rec_gain, rec_vol);
214 break;
216 case SYS_USB_CONNECTED:
217 if (pcm_status() & AUDIO_STATUS_RECORD)
219 // ignore usb while recording
220 } else
222 pcm_stop_recording();
223 #if defined(HAVE_UDA1380)
224 uda1380_enable_output(false);
225 #elif defined(HAVE_TLV320)
226 tlv320_enable_output(false);
227 #endif
228 default_event_handler(SYS_USB_CONNECTED);
229 return false;
231 break;
237 pcm_stop_recording();
238 pcm_close_recording();
240 #if defined(HAVE_UDA1380)
241 uda1380_enable_output(false);
242 #elif defined(HAVE_TLV320)
243 tlv320_enable_output(false);
244 #endif
246 return true;
249 #endif