summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2006-08-28 22:38:41 +0000
committerMichael Sevakis <jethead71@rockbox.org>2006-08-28 22:38:41 +0000
commit4fc717a4c19a1fe0349977d7b9c86561c5a5cf2d (patch)
treeeb6113c7491072f7b5136e24775737764e2cdede
parent65c2c58b3aa26164bd919665e4d710efa2fa7c79 (diff)
downloadrockbox-4fc717a4c19a1fe0349977d7b9c86561c5a5cf2d.tar.gz
rockbox-4fc717a4c19a1fe0349977d7b9c86561c5a5cf2d.zip
Added FS#2939 Encoder Codec Interface + Codecs by Antonius Hellmann with additional FM Recording support and my modifications
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10789 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/codecs.c25
-rw-r--r--apps/codecs.h24
-rw-r--r--apps/codecs/Makefile3
-rw-r--r--apps/codecs/SOURCES8
-rw-r--r--apps/codecs/mp3_enc.c2860
-rw-r--r--apps/codecs/wav_enc.c172
-rw-r--r--apps/codecs/wavpack_enc.c230
-rw-r--r--apps/filetree.c5
-rw-r--r--apps/lang/english.lang17
-rw-r--r--apps/main_menu.c26
-rw-r--r--apps/playback.c215
-rw-r--r--apps/playback.h5
-rw-r--r--apps/recorder/radio.c380
-rw-r--r--apps/recorder/radio.h12
-rw-r--r--apps/recorder/recording.c578
-rw-r--r--apps/recorder/recording.h27
-rw-r--r--apps/settings.c29
-rw-r--r--apps/settings.h1
-rw-r--r--apps/sound_menu.c78
-rw-r--r--apps/status.c4
-rw-r--r--apps/talk.c2
-rw-r--r--apps/talk.h1
-rw-r--r--apps/tree.c2
-rw-r--r--firmware/drivers/power.c2
-rw-r--r--firmware/export/audio.h46
-rw-r--r--firmware/export/config-h100.h3
-rw-r--r--firmware/export/config-h120.h3
-rw-r--r--firmware/export/config-h300.h3
-rw-r--r--firmware/export/config-iaudiox5.h4
-rw-r--r--firmware/export/fmradio.h16
-rw-r--r--firmware/export/id3.h42
-rw-r--r--firmware/export/pcm_record.h14
-rw-r--r--firmware/id3.c71
-rw-r--r--firmware/mpeg.c2
-rw-r--r--firmware/pcm_record.c736
-rw-r--r--firmware/powermgmt.c3
36 files changed, 4796 insertions, 853 deletions
diff --git a/apps/codecs.c b/apps/codecs.c
index c0b4aadeb4..addb8b5e40 100644
--- a/apps/codecs.c
+++ b/apps/codecs.c
@@ -40,6 +40,7 @@
40#include "mpeg.h" 40#include "mpeg.h"
41#include "buffer.h" 41#include "buffer.h"
42#include "mp3_playback.h" 42#include "mp3_playback.h"
43#include "playback.h"
43#include "backlight.h" 44#include "backlight.h"
44#include "ata.h" 45#include "ata.h"
45#include "talk.h" 46#include "talk.h"
@@ -208,11 +209,28 @@ struct codec_api ci = {
208 profile_func_exit, 209 profile_func_exit,
209#endif 210#endif
210 211
212#if defined(HAVE_RECORDING) && !defined(SIMULATOR)
213 false,
214 enc_get_inputs,
215 enc_set_parameters,
216 enc_alloc_chunk,
217 enc_free_chunk,
218 enc_wavbuf_near_empty,
219 enc_get_wav_data,
220 &enc_set_header_callback,
221#endif
222
211 /* new stuff at the end, sort into place next time 223 /* new stuff at the end, sort into place next time
212 the API gets incompatible */ 224 the API gets incompatible */
213 225
214}; 226};
215 227
228void codec_get_full_path(char *path, const char *codec_fn)
229{
230 /* Create full codec path */
231 snprintf(path, MAX_PATH-1, ROCKBOX_DIR CODECS_DIR "/%s", codec_fn);
232}
233
216int codec_load_ram(char* codecptr, int size, void* ptr2, int bufwrap, 234int codec_load_ram(char* codecptr, int size, void* ptr2, int bufwrap,
217 struct codec_api *api) 235 struct codec_api *api)
218{ 236{
@@ -277,15 +295,18 @@ int codec_load_ram(char* codecptr, int size, void* ptr2, int bufwrap,
277int codec_load_file(const char *plugin, struct codec_api *api) 295int codec_load_file(const char *plugin, struct codec_api *api)
278{ 296{
279 char msgbuf[80]; 297 char msgbuf[80];
298 char path[MAX_PATH];
280 int fd; 299 int fd;
281 int rc; 300 int rc;
301
302 codec_get_full_path(path, plugin);
282 303
283 /* zero out codec buffer to ensure a properly zeroed bss area */ 304 /* zero out codec buffer to ensure a properly zeroed bss area */
284 memset(codecbuf, 0, CODEC_SIZE); 305 memset(codecbuf, 0, CODEC_SIZE);
285 306
286 fd = open(plugin, O_RDONLY); 307 fd = open(path, O_RDONLY);
287 if (fd < 0) { 308 if (fd < 0) {
288 snprintf(msgbuf, sizeof(msgbuf)-1, "Couldn't load codec: %s", plugin); 309 snprintf(msgbuf, sizeof(msgbuf)-1, "Couldn't load codec: %s", path);
289 logf("Codec load error:%d", fd); 310 logf("Codec load error:%d", fd);
290 gui_syncsplash(HZ*2, true, msgbuf); 311 gui_syncsplash(HZ*2, true, msgbuf);
291 return fd; 312 return fd;
diff --git a/apps/codecs.h b/apps/codecs.h
index 9ef67c4948..dde376d73c 100644
--- a/apps/codecs.h
+++ b/apps/codecs.h
@@ -46,6 +46,9 @@
46#include "profile.h" 46#include "profile.h"
47#endif 47#endif
48#if (CONFIG_CODEC == SWCODEC) 48#if (CONFIG_CODEC == SWCODEC)
49#if !defined(SIMULATOR)
50#include "pcm_record.h"
51#endif
49#include "dsp.h" 52#include "dsp.h"
50#include "playback.h" 53#include "playback.h"
51#endif 54#endif
@@ -84,7 +87,7 @@
84#define CODEC_MAGIC 0x52434F44 /* RCOD */ 87#define CODEC_MAGIC 0x52434F44 /* RCOD */
85 88
86/* increase this every time the api struct changes */ 89/* increase this every time the api struct changes */
87#define CODEC_API_VERSION 8 90#define CODEC_API_VERSION 9
88 91
89/* update this to latest version if a change to the api struct breaks 92/* update this to latest version if a change to the api struct breaks
90 backwards compatibility (and please take the opportunity to sort in any 93 backwards compatibility (and please take the opportunity to sort in any
@@ -284,6 +287,21 @@ struct codec_api {
284 void (*profile_func_enter)(void *this_fn, void *call_site); 287 void (*profile_func_enter)(void *this_fn, void *call_site);
285 void (*profile_func_exit)(void *this_fn, void *call_site); 288 void (*profile_func_exit)(void *this_fn, void *call_site);
286#endif 289#endif
290
291#if defined(HAVE_RECORDING) && !defined(SIMULATOR)
292 bool enc_codec_loaded;
293 void (*enc_get_inputs)(int *buffer_size,
294 int *channels, int *quality);
295 void (*enc_set_parameters)(int chunk_size, int num_chunks,
296 int samp_per_chunk, char *head_ptr, int head_size,
297 int enc_id);
298 unsigned int* (*enc_alloc_chunk)(void);
299 void (*enc_free_chunk)(void);
300 int (*enc_wavbuf_near_empty)(void);
301 char* (*enc_get_wav_data)(int size);
302 void (**enc_set_header_callback)(void *head_buffer,
303 int head_size, int num_samples, bool is_file_header);
304#endif
287 305
288 /* new stuff at the end, sort into place next time 306 /* new stuff at the end, sort into place next time
289 the API gets incompatible */ 307 the API gets incompatible */
@@ -317,6 +335,10 @@ extern unsigned char plugin_end_addr[];
317#endif 335#endif
318#endif 336#endif
319 337
338/* create full codec path from filenames in audio_formats[]
339 assumes buffer size is MAX_PATH */
340void codec_get_full_path(char *path, const char *codec_fn);
341
320/* defined by the codec loader (codec.c) */ 342/* defined by the codec loader (codec.c) */
321int codec_load_ram(char* codecptr, int size, void* ptr2, int bufwrap, 343int codec_load_ram(char* codecptr, int size, void* ptr2, int bufwrap,
322 struct codec_api *api); 344 struct codec_api *api);
diff --git a/apps/codecs/Makefile b/apps/codecs/Makefile
index e365698625..6e4663be41 100644
--- a/apps/codecs/Makefile
+++ b/apps/codecs/Makefile
@@ -58,6 +58,9 @@ $(OBJDIR)/wavpack.elf : $(OBJDIR)/wavpack.o $(BUILDDIR)/libwavpack.a
58$(OBJDIR)/alac.elf : $(OBJDIR)/alac.o $(BUILDDIR)/libalac.a $(BUILDDIR)/libm4a.a 58$(OBJDIR)/alac.elf : $(OBJDIR)/alac.o $(BUILDDIR)/libalac.a $(BUILDDIR)/libm4a.a
59$(OBJDIR)/aac.elf : $(OBJDIR)/aac.o $(BUILDDIR)/libfaad.a $(BUILDDIR)/libm4a.a 59$(OBJDIR)/aac.elf : $(OBJDIR)/aac.o $(BUILDDIR)/libfaad.a $(BUILDDIR)/libm4a.a
60$(OBJDIR)/shorten.elf : $(OBJDIR)/shorten.o $(BUILDDIR)/libffmpegFLAC.a 60$(OBJDIR)/shorten.elf : $(OBJDIR)/shorten.o $(BUILDDIR)/libffmpegFLAC.a
61$(OBJDIR)/mp3_enc.elf: $(OBJDIR)/mp3_enc.o
62$(OBJDIR)/wav_enc.elf: $(OBJDIR)/wav_enc.o
63$(OBJDIR)/wavpack_enc.elf: $(OBJDIR)/wavpack_enc.o $(BUILDDIR)/libwavpack.a
61 64
62$(OBJDIR)/%.elf : 65$(OBJDIR)/%.elf :
63 @echo "LD $(notdir $@)" 66 @echo "LD $(notdir $@)"
diff --git a/apps/codecs/SOURCES b/apps/codecs/SOURCES
index 3537457313..3bd09b4dae 100644
--- a/apps/codecs/SOURCES
+++ b/apps/codecs/SOURCES
@@ -1,4 +1,5 @@
1#if CONFIG_CODEC == SWCODEC 1#if CONFIG_CODEC == SWCODEC
2/* decoders */
2vorbis.c 3vorbis.c
3mpa.c 4mpa.c
4flac.c 5flac.c
@@ -13,4 +14,11 @@ aac.c
13shorten.c 14shorten.c
14aiff.c 15aiff.c
15sid.c 16sid.c
17#if defined(HAVE_RECORDING) && !defined(SIMULATOR)
18/* encoders */
19mp3_enc.c
20wav_enc.c
21wavpack_enc.c
16#endif 22#endif
23#endif
24
diff --git a/apps/codecs/mp3_enc.c b/apps/codecs/mp3_enc.c
new file mode 100644
index 0000000000..1cd84988aa
--- /dev/null
+++ b/apps/codecs/mp3_enc.c
@@ -0,0 +1,2860 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 Antonius Hellmann
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// Shine is an MP3 encoder
21// Copyright (C) 1999-2000 Gabriel Bouvigne
22//
23// This library is free software; you can redistribute it and/or
24// modify it under the terms of the GNU Library General Public
25// License as published by the Free Software Foundation; either
26// version 2 of the License, or (at your option) any later version.
27//
28// This library is distributed in the hope that it will be useful,
29// but WITHOUT ANY WARRANTY; without even the implied warranty of
30// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
31// Library General Public License for more details.
32
33#include "codeclib.h"
34
35#ifndef SIMULATOR
36
37CODEC_HEADER
38
39#define SAMP_PER_FRAME 1152
40#define SAMP_PER_FRAME2 576
41#define HAN_SIZE 512
42#define SBLIMIT 32
43#define WAVE_RIFF_PCM 0
44#define MAX_CHANNELS 2
45#define MAX_GRANULES 2
46#define HTN 34
47
48typedef unsigned long uint32;
49typedef unsigned short uint16;
50typedef unsigned char uint8;
51
52enum e_byte_order { order_unknown, order_bigEndian, order_littleEndian };
53
54#define memcpy ci->memcpy
55#define memset ci->memset
56
57typedef struct {
58 int type; /* 0=(22.05,24,16kHz) 1=(44.1,48,32kHz) */
59 int mode; /* 0=stereo, 1=jstereo, 2=dual, 3=mono */
60 int bitrate;
61 int padding;
62 long bits_per_frame;
63 long bitrate_index;
64 int smprate_index;
65} mpeg_t;
66
67/* Side information */
68typedef struct {
69 unsigned part2_3_length;
70 unsigned big_values;
71 int count1;
72 unsigned global_gain;
73 unsigned table_select[4];
74 unsigned region0_count;
75 unsigned region1_count;
76 unsigned address1;
77 unsigned address2;
78 unsigned address3;
79 long quantizerStepSize;
80} side_info_t;
81
82typedef struct {
83 enum e_byte_order byte_order;
84 side_info_t cod_info[2][2];
85 long frac_per_frame;
86 long byte_per_frame;
87 long slot_lag;
88 int sideinfo_len;
89 int mean_bits;
90 int channels;
91 long samplerate;
92 mpeg_t mpg;
93} config_t;
94
95typedef struct {
96 int bitpos; /* current bitpos for writing */
97 uint32 bbuf[263];
98} BF_Data;
99
100struct huffcodetab {
101 int xlen; /*max. x-index+ */
102 int ylen; /*max. y-index+ */
103 int linbits; /*number of linbits */
104 int linmax; /*max number stored in linbits */
105 const uint16 *table; /*pointer to array[xlen][ylen] */
106 const uint8 *hlen; /*pointer to array[xlen][ylen] */
107};
108
109/* !!!!!!!! start of IRAM area: do not insert before x_int1 array !!!!!!!!! */
110short x_int0 [HAN_SIZE] IBSS_ATTR; // 1024 Bytes
111int mdct_freq [2][2][SAMP_PER_FRAME2] IBSS_ATTR; // 9216 Bytes
112short x_int1 [HAN_SIZE] IBSS_ATTR; // 1024 Bytes
113/* !!!!!!!!!!!!!!!!!! here you may insert other data !!!!!!!!!!!!!!!!!!!!!! */
114uint8 int2idx [5000] IBSS_ATTR; // 5000 Bytes
115uint16 enc_data [2][2][SAMP_PER_FRAME2] IBSS_ATTR; // 4608 Bytes
116short y_int [64] IBSS_ATTR; // 256 Bytes
117int scalefac [23] IBSS_ATTR; // 92 Bytes
118int mdct_in [36] IBSS_ATTR; // 144 Bytes
119int sb_sample [2][3][18][SBLIMIT] IBSS_ATTR; // 13824 Bytes
120BF_Data CodedData IBSS_ATTR; // 1040 Bytes
121int ca_int [8] IBSS_ATTR; // 32 Bytes
122int cs_int [8] IBSS_ATTR; // 32 Bytes
123int win_int [18][36] IBSS_ATTR; // 2592 Bytes
124short filter_int [SBLIMIT][64] IBSS_ATTR; // 8192 Bytes
125short enwindow_int[512] IBSS_ATTR; // 1024 Bytes
126uint8 ht_count1 [2][2][16] IBSS_ATTR; // 64 Bytes
127uint16 t1HB [ 4] IBSS_ATTR; // Bytes
128uint16 t2HB [ 9] IBSS_ATTR; // Bytes
129uint16 t3HB [ 9] IBSS_ATTR; // Bytes
130uint16 t5HB [ 16] IBSS_ATTR; // Bytes
131uint16 t6HB [ 16] IBSS_ATTR; // Bytes
132uint16 t7HB [ 36] IBSS_ATTR; // Bytes
133uint16 t8HB [ 36] IBSS_ATTR; // Bytes
134uint16 t9HB [ 36] IBSS_ATTR; // Bytes
135uint16 t10HB [ 64] IBSS_ATTR; // Bytes
136uint16 t11HB [ 64] IBSS_ATTR; // Bytes
137uint16 t12HB [ 64] IBSS_ATTR; // Bytes
138uint16 t13HB [256] IBSS_ATTR; // Bytes
139uint16 t15HB [256] IBSS_ATTR; // Bytes
140uint16 t16HB [256] IBSS_ATTR; // Bytes
141uint16 t24HB [256] IBSS_ATTR; // Bytes
142uint8 t1l [ 4] IBSS_ATTR; // Bytes
143uint8 t2l [ 9] IBSS_ATTR; // Bytes
144uint8 t3l [ 9] IBSS_ATTR; // Bytes
145uint8 t5l [ 16] IBSS_ATTR; // Bytes
146uint8 t6l [ 16] IBSS_ATTR; // Bytes
147uint8 t7l [ 36] IBSS_ATTR; // Bytes
148uint8 t8l [ 36] IBSS_ATTR; // Bytes
149uint8 t9l [ 36] IBSS_ATTR; // Bytes
150uint8 t10l [ 64] IBSS_ATTR; // Bytes
151uint8 t11l [ 64] IBSS_ATTR; // Bytes
152uint8 t12l [ 64] IBSS_ATTR; // Bytes
153uint8 t13l [256] IBSS_ATTR; // Bytes
154uint8 t15l [256] IBSS_ATTR; // Bytes
155uint8 t16l [256] IBSS_ATTR; // Bytes
156uint8 t24l [256] IBSS_ATTR; // Bytes
157struct huffcodetab ht [HTN] IBSS_ATTR; // Bytes
158
159static struct codec_api *ci;
160static int enc_channels;
161static short *x_int[2];
162static config_t cfg;
163
164static const uint8 ht_count1_const[2][2][16] =
165{ { { 1, 5, 4, 5, 6, 5,4,4,7,3,6,0,7,2,3, 1 }, /* table0 */
166 { 1, 5, 5, 7, 5, 8,7,9,5,7,7,9,7,9,9,10 } }, /* hleng0 */
167 { {15,14,13,12,11,10,9,8,7,6,5,4,3,2,1, 0 }, /* table1 */
168 { 4, 5, 5, 6, 5, 6,6,7,5,6,6,7,6,7,7, 8 } } }; /* hleng1 */
169
170static const uint16 t1HB_const[4] = {1,1,1,0};
171static const uint16 t2HB_const[9] = {1,2,1,3,1,1,3,2,0};
172static const uint16 t3HB_const[9] = {3,2,1,1,1,1,3,2,0};
173static const uint16 t5HB_const[16] = {1,2,6,5,3,1,4,4,7,5,7,1,6,1,1,0};
174static const uint16 t6HB_const[16] = {7,3,5,1,6,2,3,2,5,4,4,1,3,3,2,0};
175static const uint16 t7HB_const[36] = {1,2,10,19,16,10,3,3,7,10,5,3,11,4,13,17,8,4,12,11,18,15,11,2,7,6,9,14,3,1,6,4,5,3,2,0};
176static const uint16 t8HB_const[36] = {3,4,6,18,12,5,5,1,2,16,9,3,7,3,5,14,7,3,19,17,15,13,10,4,13,5,8,11,5,1,12,4,4,1,1,0};
177static const uint16 t9HB_const[36] = {7,5,9,14,15,7,6,4,5,5,6,7,7,6,8,8,8,5,15,6,9,10,5,1,11,7,9,6,4,1,14,4,6,2,6,0};
178static const uint16 t10HB_const[64] = {1,2,10,23,35,30,12,17,3,3,8,12,18,21,12,7,11,9,15,21,32,40,19,6,14,13,22,34,46,23,18,
179 7,20,19,33,47,27,22,9,3,31,22,41,26,21,20,5,3,14,13,10,11,16,6,5,1,9,8,7,8,4 ,4,2,0};
180static const uint16 t11HB_const[64] = {3,4,10,24,34,33,21,15,5,3,4,10,32,17,11,10,11,7,13,18,30,31,20,5,25,11,19,59,27,18,12,
181 5,35,33,31,58,30,16,7,5,28,26,32,19,17,15,8,14,14,12,9,13,14,9,4,1,11,4,6,6,6,3,2,0};
182static const uint16 t12HB_const[64] = {9,6,16,33,41,39,38,26,7,5,6,9,23,16,26,11,17,7,11,14,21,30,10,7,17,10,15,12,18,28,14,
183 5,32,13,22,19,18,16,9,5,40,17,31,29,17,13,4,2,27,12,11,15,10,7,4,1,27,12,8,12,6,3,1,0};
184static const uint16 t13HB_const[256] = {1,5,14,21,34,51,46,71,42,52,68,52,67,44,43,19,3,4,12,19,31,26,44,33,31,24,32,
185 24,31,35,22,14,15,13,23,36,59,49,77,65,29,40,30,40,27,33,42,16,22,20,37,61,56,
186 79,73,64,43,76,56,37,26,31,25,14,35,16,60,57,97,75,114,91,54,73,55,41,48,53,
187 23,24,58,27,50,96,76,70,93,84,77,58,79,29,74,49,41,17,47,45,78,74,115,94,90,
188 79,69,83,71,50,59,38,36,15,72,34,56,95,92,85,91,90,86,73,77,65,51,44,43,42,43,
189 20,30,44,55,78,72,87,78,61,46,54,37,30,20,16,53,25,41,37,44,59,54,81,66,76,57,
190 54,37,18,39,11,35,33,31,57,42,82,72,80,47,58,55,21,22,26,38,22,53,25,23,38,70,
191 60,51,36,55,26,34,23,27,14,9,7,34,32,28,39,49,75,30,52,48,40,52,28,18,17,9,5,
192 45,21,34,64,56,50,49,45,31,19,12,15,10,7,6,3,48,23,20,39,36,35,53,21,16,23,13,
193 10,6,1,4,2,16,15,17,27,25,20,29,11,17,12,16,8,1,1,0,1};
194static const uint16 t15HB_const[256] = {7,12,18,53,47,76,124,108,89,123,108,119,107,81,122,63,13,5,16,27,46,36,61,51,
195 42,70,52,83,65,41,59,36,19,17,15,24,41,34,59,48,40,64,50,78,62,80,56,33,29,28,
196 25,43,39,63,55,93,76,59,93,72,54,75,50,29,52,22,42,40,67,57,95,79,72,57,89,69,
197 49,66,46,27,77,37,35,66,58,52,91,74,62,48,79,63,90,62,40,38,125,32,60,56,50,
198 92,78,65,55,87,71,51,73,51,70,30,109,53,49,94,88,75,66,122,91,73,56,42,64,44,
199 21,25,90,43,41,77,73,63,56,92,77,66,47,67,48,53,36,20,71,34,67,60,58,49,88,76,
200 67,106,71,54,38,39,23,15,109,53,51,47,90,82,58,57,48,72,57,41,23,27,62,9,86,
201 42,40,37,70,64,52,43,70,55,42,25,29,18,11,11,118,68,30,55,50,46,74,65,49,39,
202 24,16,22,13,14,7,91,44,39,38,34,63,52,45,31,52,28,19,14,8,9,3,123,60,58,53,47,
203 43,32,22,37,24,17,12,15,10,2,1,71,37,34,30,28,20,17,26,21,16,10,6,8,6,2,0};
204static const uint16 t16HB_const[256] = {1,5,14,44,74,63,110,93,172,149,138,242,225,195,376,17,3,4,12,20,35,62,53,47,
205 83,75,68,119,201,107,207,9,15,13,23,38,67,58,103,90,161,72,127,117,110,209,
206 206,16,45,21,39,69,64,114,99,87,158,140,252,212,199,387,365,26,75,36,68,65,
207 115,101,179,164,155,264,246,226,395,382,362,9,66,30,59,56,102,185,173,265,142,
208 253,232,400,388,378,445,16,111,54,52,100,184,178,160,133,257,244,228,217,385,
209 366,715,10,98,48,91,88,165,157,148,261,248,407,397,372,380,889,884,8,85,84,81,
210 159,156,143,260,249,427,401,392,383,727,713,708,7,154,76,73,141,131,256,245,
211 426,406,394,384,735,359,710,352,11,139,129,67,125,247,233,229,219,393,743,737,
212 720,885,882,439,4,243,120,118,115,227,223,396,746,742,736,721,712,706,223,436,
213 6,202,224,222,218,216,389,386,381,364,888,443,707,440,437,1728,4,747,211,210,
214 208,370,379,734,723,714,1735,883,877,876,3459,865,2,377,369,102,187,726,722,
215 358,711,709,866,1734,871,3458,870,434,0,12,10,7,11,10,17,11,9,13,12,10,7,5,3,1,3};
216static const uint16 t24HB_const[256] = {15,13,46,80,146,262,248,434,426,669,653,649,621,517,1032,88,14,12,21,38,71,
217 130,122,216,209,198,327,345,319,297,279,42,47,22,41,74,68,128,120,221,207,194,
218 182,340,315,295,541,18,81,39,75,70,134,125,116,220,204,190,178,325,311,293,
219 271,16,147,72,69,135,127,118,112,210,200,188,352,323,306,285,540,14,263,66,
220 129,126,119,114,214,202,192,180,341,317,301,281,262,12,249,123,121,117,113,
221 215,206,195,185,347,330,308,291,272,520,10,435,115,111,109,211,203,196,187,
222 353,332,313,298,283,531,381,17,427,212,208,205,201,193,186,177,169,320,303,
223 286,268,514,377,16,335,199,197,191,189,181,174,333,321,305,289,275,521,379,
224 371,11,668,184,183,179,175,344,331,314,304,290,277,530,383,373,366,10,652,346,
225 171,168,164,318,309,299,287,276,263,513,375,368,362,6,648,322,316,312,307,302,
226 292,284,269,261,512,376,370,364,359,4,620,300,296,294,288,282,273,266,515,380,
227 374,369,365,361,357,2,1033,280,278,274,267,264,259,382,378,372,367,363,360,
228 358,356,0,43,20,19,17,15,13,11,9,7,6,4,7,5,3,1,3};
229
230static const uint8 t1l_const[4] = {1,3,2,3};
231static const uint8 t2l_const[9] = {1,3,6,3,3,5,5,5,6};
232static const uint8 t3l_const[9] = {2,2,6,3,2,5,5,5,6};
233static const uint8 t5l_const[16] = {1,3,6,7,3,3,6,7,6,6,7,8,7,6,7,8};
234static const uint8 t6l_const[16] = {3,3,5,7,3,2,4,5,4,4,5,6,6,5,6,7};
235static const uint8 t7l_const[36] = {1,3,6,8,8,9,3,4,6,7,7,8,6,5,7,8,8,9,7,7,8,9,9,9,7,7,8,9,9,10,8,8,9,10,10,10};
236static const uint8 t8l_const[36] = {2,3,6,8,8,9,3,2,4,8,8,8,6,4,6,8,8,9,8,8,8,9,9,10,8,7,8,9,10,10,9,8,9,9,11,11};
237static const uint8 t9l_const[36] = {3,3,5,6,8,9,3,3,4,5,6,8,4,4,5,6,7,8,6,5,6,7,7,8,7,6,7,7,8,9,8,7,8,8,9,9};
238static const uint8 t10l_const[64] = {1,3,6,8,9,9,9,10,3,4,6,7,8,9,8,8,6,6,7,8,9,10,9,9,7,7,8,9,10,10,9,10,8,8,9,10,
239 10,10,10,10,9,9,10,10,11,11,10,11,8,8,9,10,10,10,11,11,9,8,9,10,10,11,11,11};
240static const uint8 t11l_const[64] = {2,3,5,7,8,9,8,9,3,3,4,6,8,8,7,8,5,5,6,7,8,9,8,8,7,6,7,9,8,10,8,9,8,8,8,9,9,10,
241 9,10,8,8,9,10,10,11,10,11,8,7,7,8,9,10,10,10,8,7,8,9,10,10,10,10};
242static const uint8 t12l_const[64] = {4,3,5,7,8,9,9,9,3,3,4,5,7,7,8,8,5,4,5,6,7,8,7,8,6,5,6,6,7,8,8,8,7,6,7,7,8,
243 8,8,9,8,7,8,8,8,9,8,9,8,7,7,8,8,9,9,10,9,8,8,9,9,9,9,10};
244static const uint8 t13l_const[256] = {1,4,6,7,8,9,9,10,9,10,11,11,12,12,13,13,3,4,6,7,8,8,9,9,9,9,10,10,11,12,12,12,
245 6,6,7,8,9,9,10,10,9,10,10,11,11,12,13,13,7,7,8,9,9,10,10,10,10,11,11,11,11,12,
246 13,13,8,7,9,9,10,10,11,11,10,11,11,12,12,13,13,14,9,8,9,10,10,10,11,11,11,11,
247 12,11,13,13,14,14,9,9,10,10,11,11,11,11,11,12,12,12,13,13,14,14,10,9,10,11,11,
248 11,12,12,12,12,13,13,13,14,16,16,9,8,9,10,10,11,11,12,12,12,12,13,13,14,15,15,
249 10,9,10,10,11,11,11,13,12,13,13,14,14,14,16,15,10,10,10,11,11,12,12,13,12,13,
250 14,13,14,15,16,17,11,10,10,11,12,12,12,12,13,13,13,14,15,15,15,16,11,11,11,12,
251 12,13,12,13,14,14,15,15,15,16,16,16,12,11,12,13,13,13,14,14,14,14,14,15,16,15,
252 16,16,13,12,12,13,13,13,15,14,14,17,15,15,15,17,16,16,12,12,13,14,14,14,15,14,
253 15,15,16,16,19,18,19,16};
254static const uint8 t15l_const[256] = {3,4,5,7,7,8,9,9,9,10,10,11,11,11,12,13,4,3,5,6,7,7,8,8,8,9,9,10,10,10,11,11,5,
255 5,5,6,7,7,8,8,8,9,9,10,10,11,11,11,6,6,6,7,7,8,8,9,9,9,10,10,10,11,11,11,7,6,7,
256 7,8,8,9,9,9,9,10,10,10,11,11,11,8,7,7,8,8,8,9,9,9,9,10,10,11,11,11,12,9,7,8,8,
257 8,9,9,9,9,10,10,10,11,11,12,12,9,8,8,9,9,9,9,10,10,10,10,10,11,11,11,12,9,8,8,
258 9,9,9,9,10,10,10,10,11,11,12,12,12,9,8,9,9,9,9,10,10,10,11,11,11,11,12,12,12,10,
259 9,9,9,10,10,10,10,10,11,11,11,11,12,13,12,10,9,9,9,10,10,10,10,11,11,11,11,12,
260 12,12,13,11,10,9,10,10,10,11,11,11,11,11,11,12,12,13,13,11,10,10,10,10,11,11,11,
261 11,12,12,12,12,12,13,13,12,11,11,11,11,11,11,11,12,12,12,12,13,13,12,13,12,11,
262 11,11,11,11,11,12,12,12,12,12,13,13,13,13};
263static const uint8 t16l_const[256] = {1,4,6,8,9,9,10,10,11,11,11,12,12,12,13,9,3,4,6,7,8,9,9,9,10,10,10,11,12,11,12,
264 8,6,6,7,8,9,9,10,10,11,10,11,11,11,12,12,9,8,7,8,9,9,10,10,10,11,11,12,12,12,
265 13,13,10,9,8,9,9,10,10,11,11,11,12,12,12,13,13,13,9,9,8,9,9,10,11,11,12,11,12,
266 12,13,13,13,14,10,10,9,9,10,11,11,11,11,12,12,12,12,13,13,14,10,10,9,10,10,11,
267 11,11,12,12,13,13,13,13,15,15,10,10,10,10,11,11,11,12,12,13,13,13,13,14,14,14,
268 10,11,10,10,11,11,12,12,13,13,13,13,14,13,14,13,11,11,11,10,11,12,12,12,12,13,
269 14,14,14,15,15,14,10,12,11,11,11,12,12,13,14,14,14,14,14,14,13,14,11,12,12,12,
270 12,12,13,13,13,13,15,14,14,14,14,16,11,14,12,12,12,13,13,14,14,14,16,15,15,15,
271 17,15,11,13,13,11,12,14,14,13,14,14,15,16,15,17,15,14,11,9,8,8,9,9,10,10,10,11,
272 11,11,11,11,11,11,8};
273static const uint8 t24l_const[256] = {4,4,6,7,8,9,9,10,10,11,11,11,11,11,12,9,4,4,5,6,7,8,8,9,9,9,10,10,10,10,10,8,6,
274 5,6,7,7,8,8,9,9,9,9,10,10,10,11,7,7,6,7,7,8,8,8,9,9,9,9,10,10,10,10,7,8,7,7,8,
275 8,8,8,9,9,9,10,10,10,10,11,7,9,7,8,8,8,8,9,9,9,9,10,10,10,10,10,7,9,8,8,8,8,9,
276 9,9,9,10,10,10,10,10,11,7,10,8,8,8,9,9,9,9,10,10,10,10,10,11,11,8,10,9,9,9,9,9,
277 9,9,9,10,10,10,10,11,11,8,10,9,9,9,9,9,9,10,10,10,10,10,11,11,11,8,11,9,9,9,9,
278 10,10,10,10,10,10,11,11,11,11,8,11,10,9,9,9,10,10,10,10,10,10,11,11,11,11,8,11,
279 10,10,10,10,10,10,10,10,10,11,11,11,11,11,8,11,10,10,10,10,10,10,10,11,11,11,11,
280 11,11,11,8,12,10,10,10,10,10,10,11,11,11,11,11,11,11,11,8,8,7,7,7,7,7,7,7,7,7,
281 7,8,8,8,8,4};
282
283static const struct huffcodetab ht_const[HTN] =
284{
285{ 0, 0, 0, 0, NULL, NULL},
286{ 2, 2, 0, 0, t1HB, t1l},
287{ 3, 3, 0, 0, t2HB, t2l},
288{ 3, 3, 0, 0, t3HB, t3l},
289{ 0, 0, 0, 0, NULL, NULL},// Apparently not used
290{ 4, 4, 0, 0, t5HB, t5l},
291{ 4, 4, 0, 0, t6HB, t6l},
292{ 6, 6, 0, 0, t7HB, t7l},
293{ 6, 6, 0, 0, t8HB, t8l},
294{ 6, 6, 0, 0, t9HB, t9l},
295{ 8, 8, 0, 0,t10HB, t10l},
296{ 8, 8, 0, 0,t11HB, t11l},
297{ 8, 8, 0, 0,t12HB, t12l},
298{16,16, 0, 0,t13HB, t13l},
299{ 0, 0, 0, 0, NULL, NULL},// Apparently not used
300{16,16, 0, 0,t15HB, t15l},
301{16,16, 1, 1,t16HB, t16l},
302{16,16, 2, 3,t16HB, t16l},
303{16,16, 3, 7,t16HB, t16l},
304{16,16, 4, 15,t16HB, t16l},
305{16,16, 6, 63,t16HB, t16l},
306{16,16, 8, 255,t16HB, t16l},
307{16,16,10,1023,t16HB, t16l},
308{16,16,13,8191,t16HB, t16l},
309{16,16, 4, 15,t24HB, t24l},
310{16,16, 5, 31,t24HB, t24l},
311{16,16, 6, 63,t24HB, t24l},
312{16,16, 7, 127,t24HB, t24l},
313{16,16, 8, 255,t24HB, t24l},
314{16,16, 9, 511,t24HB, t24l},
315{16,16,11,2047,t24HB, t24l},
316{16,16,13,8191,t24HB, t24l} };
317
318static const struct
319{
320 unsigned region0_count;
321 unsigned region1_count;
322} subdv_table[23] =
323{ {0, 0}, /* 0 bands */
324 {0, 0}, /* 1 bands */
325 {0, 0}, /* 2 bands */
326 {0, 0}, /* 3 bands */
327 {0, 0}, /* 4 bands */
328 {0, 1}, /* 5 bands */
329 {1, 1}, /* 6 bands */
330 {1, 1}, /* 7 bands */
331 {1, 2}, /* 8 bands */
332 {2, 2}, /* 9 bands */
333 {2, 3}, /* 10 bands */
334 {2, 3}, /* 11 bands */
335 {3, 4}, /* 12 bands */
336 {3, 4}, /* 13 bands */
337 {3, 4}, /* 14 bands */
338 {4, 5}, /* 15 bands */
339 {4, 5}, /* 16 bands */
340 {4, 6}, /* 17 bands */
341 {5, 6}, /* 18 bands */
342 {5, 6}, /* 19 bands */
343 {5, 7}, /* 20 bands */
344 {6, 7}, /* 21 bands */
345 {6, 7}, /* 22 bands */
346};
347
348/* This is table B.9: coefficients for aliasing reduction */
349static const int ca_int_const[8] = {0xffffbe25,0xffffc39e,0xffffd7e3,0xffffe8b7,0xfffff3e5,0xfffffac2,0xfffffe2f,0xffffff87};
350static const int cs_int_const[8] = {0x00006dc2,0x000070dd,0x0000798d,0x00007ddd,0x00007f6d,0x00007fe4,0x00007ffd,0x00008000};
351static const int win_int_const[18][36] = {
352{ 0x0000006b,0x00000121,0x000001a7,0x000001f9,0x00000215,0x000001f9,0x000001a7,0x00000121,0x0000006b,0xffffff8b,0xfffffe87,0xfffffd68,0xfffffc35,0xfffffaf9,0xfffff9bd,0xfffff88b,0xfffff76b,0xfffff667,0xfffff587,0xfffff4d1,0xfffff44b,0xfffff3f8,0xfffff3dd,0xfffff3f8,0xfffff44b,0xfffff4d1,0xfffff587,0xfffff667,0xfffff76b,0xfffff88b,0xfffff9bd,0xfffffaf9,0xfffffc35,0xfffffd68,0xfffffe87,0xffffff8b,},
353{ 0xffffff83,0xfffffe49,0xfffffcf3,0xfffffbc3,0xfffffaf9,0xfffffacb,0xfffffb5a,0xfffffcb0,0xfffffebf,0x0000015e,0x00000451,0x0000074d,0x00000a02,0x00000c23,0x00000d72,0x00000dc4,0x00000d06,0x00000b45,0x000008a6,0x00000565,0x000001cf,0xfffffe3b,0xfffffaf9,0xfffff853,0xfffff67c,0xfffff594,0xfffff59b,0xfffff67a,0xfffff801,0xfffff9f1,0xfffffc01,0xfffffdeb,0xffffff72,0x00000066,0x000000b5,0x00000060,},
354{ 0xffffffab,0xffffffc2,0x000000ec,0x000002e3,0x00000507,0x0000068f,0x000006c7,0x00000545,0x00000214,0xfffffdbc,0xfffff922,0xfffff55d,0xfffff366,0xfffff3dd,0xfffff6d7,0xfffffbd4,0x000001d7,0x000007a2,0x00000bfb,0x00000dfa,0x00000d3e,0x00000a00,0x00000507,0xffffff74,0xfffffa77,0xfffff70d,0xfffff5c4,0xfffff69f,0xfffff922,0xfffffc79,0xffffffb7,0x00000215,0x00000327,0x000002ef,0x000001d7,0x00000085,},
355{ 0x0000008c,0x000001d7,0x00000244,0x000000ec,0xfffffdeb,0xfffffa77,0xfffff85e,0xfffff922,0xfffffd1d,0x00000327,0x000008f3,0x00000bfb,0x00000aa3,0x00000507,0xfffffd11,0xfffff5c4,0xfffff206,0xfffff366,0xfffff971,0x000001d7,0x00000961,0x00000d3e,0x00000c23,0x000006c7,0xffffff7b,0xfffff922,0xfffff600,0xfffff6d7,0xfffffabb,0xffffffab,0x00000387,0x00000507,0x0000042c,0x00000214,0x0000003e,0xffffffb7,},
356{ 0x0000003c,0xffffff4b,0xfffffd28,0xfffffc0d,0xfffffdeb,0x00000283,0x0000070f,0x000007ff,0x000003ad,0xfffffbfd,0xfffff594,0xfffff4ec,0xfffffb2d,0x00000507,0x00000c88,0x00000cd4,0x00000565,0xfffffa91,0xfffff2e0,0xfffff2fa,0xfffffab0,0x00000530,0x00000c23,0x00000ba7,0x00000497,0xfffffbaf,0xfffff650,0xfffff720,0xfffffcb0,0x000002ec,0x00000611,0x00000507,0x000001a2,0xfffffed3,0xfffffe49,0xffffff6e,},
357{ 0xffffff69,0xfffffe87,0x00000022,0x0000039b,0x00000507,0x0000016b,0xfffffad7,0xfffff76b,0xfffffb91,0x000004d7,0x00000b2f,0x0000081a,0xfffffd46,0xfffff3dd,0xfffff490,0xffffff65,0x00000b2f,0x00000d8d,0x00000445,0xfffff76b,0xfffff221,0xfffff8b7,0x00000507,0x00000c50,0x000008d7,0xfffffe87,0xfffff6b3,0xfffff77b,0xfffffedf,0x000005a2,0x00000669,0x00000215,0xfffffdb4,0xfffffced,0xfffffedf,0x0000002f,},
358{ 0xffffffde,0x00000179,0x000002ba,0xffffffd1,0xfffffaf9,0xfffffb29,0x0000024c,0x00000895,0x00000529,0xfffffa5e,0xfffff4d1,0xfffffc65,0x0000094d,0x00000c23,0x00000097,0xfffff3b0,0xfffff4d1,0x00000313,0x00000ddf,0x00000895,0xfffff997,0xfffff273,0xfffffaf9,0x00000885,0x00000b70,0x00000179,0xfffff729,0xfffff7e6,0x00000121,0x00000749,0x0000046f,0xfffffdeb,0xfffffbbb,0xfffffe95,0x00000121,0x0000009b,},
359{ 0x0000009d,0x000000b5,0xfffffd8f,0xfffffc9c,0x00000215,0x00000682,0x000000ff,0xfffff801,0xfffffa27,0x00000662,0x00000a6c,0xfffffe70,0xfffff37f,0xfffffaf9,0x00000ac2,0x00000b04,0xfffffa9b,0xfffff1ea,0xfffffe26,0x00000d06,0x00000873,0xfffff7bf,0xfffff3dd,0x000001a5,0x00000be4,0x00000451,0xfffff7af,0xfffff861,0x00000350,0x00000793,0x000000db,0xfffffaf9,0xfffffd66,0x000001df,0x000001b7,0xffffffec,},
360{ 0x00000006,0xfffffe29,0xffffff56,0x00000414,0x00000215,0xfffffa2d,0xfffffbe5,0x000006de,0x0000067d,0xfffff8eb,0xfffff70d,0x00000671,0x00000b30,0xfffffaf9,0xfffff311,0x00000301,0x00000dfa,0xffffff62,0xfffff1cf,0xfffffe29,0x00000d8e,0x00000414,0xfffff3dd,0xfffffa2d,0x00000a1d,0x000006de,0xfffff845,0xfffff8eb,0x00000545,0x00000671,0xfffffcf8,0xfffffaf9,0x00000149,0x00000301,0xffffffc2,0xffffff62,},
361{ 0xffffff62,0x0000003e,0x00000301,0xfffffeb7,0xfffffaf9,0x00000308,0x00000671,0xfffffabb,0xfffff8eb,0x000007bb,0x000006de,0xfffff5e3,0xfffffa2d,0x00000c23,0x00000414,0xfffff272,0xfffffe29,0x00000e31,0xffffff62,0xfffff206,0x00000301,0x00000cef,0xfffffaf9,0xfffff4d0,0x00000671,0x000008f3,0xfffff8eb,0xfffff983,0x000006de,0x0000041b,0xfffffa2d,0xfffffdeb,0x00000414,0x000000aa,0xfffffe29,0xfffffffa,},
362{ 0x00000014,0x000001b7,0xfffffe21,0xfffffd66,0x00000507,0x000000db,0xfffff86d,0x00000350,0x0000079f,0xfffff7af,0xfffffbaf,0x00000be4,0xfffffe5b,0xfffff3dd,0x00000841,0x00000873,0xfffff2fa,0xfffffe26,0x00000e16,0xfffffa9b,0xfffff4fc,0x00000ac2,0x00000507,0xfffff37f,0x00000190,0x00000a6c,0xfffff99e,0xfffffa27,0x000007ff,0x000000ff,0xfffff97e,0x00000215,0x00000364,0xfffffd8f,0xffffff4b,0x0000009d,},
363{ 0x0000009b,0xfffffedf,0xfffffe95,0x00000445,0xfffffdeb,0xfffffb91,0x00000749,0xfffffedf,0xfffff7e6,0x000008d7,0x00000179,0xfffff490,0x00000885,0x00000507,0xfffff273,0x00000669,0x00000895,0xfffff221,0x00000313,0x00000b2f,0xfffff3b0,0xffffff69,0x00000c23,0xfffff6b3,0xfffffc65,0x00000b2f,0xfffffa5e,0xfffffad7,0x00000895,0xfffffdb4,0xfffffb29,0x00000507,0xffffffd1,0xfffffd46,0x00000179,0x00000022,},
364{ 0xffffffd1,0xfffffedf,0x00000313,0xfffffdb4,0xfffffdeb,0x00000669,0xfffffa5e,0xfffffedf,0x00000885,0xfffff6b3,0x00000179,0x000008d7,0xfffff3b0,0x00000507,0x00000749,0xfffff221,0x00000895,0x00000445,0xfffff273,0x00000b2f,0x0000009b,0xfffff490,0x00000c23,0xfffffd46,0xfffff7e6,0x00000b2f,0xfffffb29,0xfffffb91,0x00000895,0xfffffad7,0xfffffe95,0x00000507,0xfffffc65,0x00000022,0x00000179,0xffffff69,},
365{ 0xffffff6e,0x000001b7,0xfffffed3,0xfffffe5e,0x00000507,0xfffff9ef,0x000002ec,0x00000350,0xfffff720,0x000009b0,0xfffffbaf,0xfffffb69,0x00000ba7,0xfffff3dd,0x00000530,0x00000550,0xfffff2fa,0x00000d20,0xfffffa91,0xfffffa9b,0x00000cd4,0xfffff378,0x00000507,0x000004d3,0xfffff4ec,0x00000a6c,0xfffffbfd,0xfffffc53,0x000007ff,0xfffff8f1,0x00000283,0x00000215,0xfffffc0d,0x000002d8,0xffffff4b,0xffffffc4,},
366{ 0x00000049,0x0000003e,0xfffffdec,0x0000042c,0xfffffaf9,0x00000387,0x00000055,0xfffffabb,0x00000929,0xfffff600,0x000006de,0xffffff7b,0xfffff939,0x00000c23,0xfffff2c2,0x00000961,0xfffffe29,0xfffff971,0x00000c9a,0xfffff206,0x00000a3c,0xfffffd11,0xfffffaf9,0x00000aa3,0xfffff405,0x000008f3,0xfffffcd9,0xfffffd1d,0x000006de,0xfffff85e,0x00000589,0xfffffdeb,0xffffff14,0x00000244,0xfffffe29,0x0000008c,},
367{ 0x00000085,0xfffffe29,0x000002ef,0xfffffcd9,0x00000215,0x00000049,0xfffffc79,0x000006de,0xfffff69f,0x00000a3c,0xfffff70d,0x00000589,0xffffff74,0xfffffaf9,0x00000a00,0xfffff2c2,0x00000dfa,0xfffff405,0x000007a2,0xfffffe29,0xfffffbd4,0x00000929,0xfffff3dd,0x00000c9a,0xfffff55d,0x000006de,0xfffffdbc,0xfffffdec,0x00000545,0xfffff939,0x0000068f,0xfffffaf9,0x000002e3,0xffffff14,0xffffffc2,0x00000055,},
368{ 0xffffffa0,0x000000b5,0xffffff9a,0xffffff72,0x00000215,0xfffffc01,0x0000060f,0xfffff801,0x00000986,0xfffff59b,0x00000a6c,0xfffff67c,0x000007ad,0xfffffaf9,0x000001c5,0x000001cf,0xfffffa9b,0x000008a6,0xfffff4bb,0x00000d06,0xfffff23c,0x00000d72,0xfffff3dd,0x00000a02,0xfffff8b3,0x00000451,0xfffffea2,0xfffffebf,0x00000350,0xfffffb5a,0x00000535,0xfffffaf9,0x0000043d,0xfffffcf3,0x000001b7,0xffffff83,},
369{ 0xffffff8b,0x00000179,0xfffffd68,0x000003cb,0xfffffaf9,0x00000643,0xfffff88b,0x00000895,0xfffff667,0x00000a79,0xfffff4d1,0x00000bb5,0xfffff3f8,0x00000c23,0xfffff3f8,0x00000bb5,0xfffff4d1,0x00000a79,0xfffff667,0x00000895,0xfffff88b,0x00000643,0xfffffaf9,0x000003cb,0xfffffd68,0x00000179,0xffffff8b,0xffffff95,0x00000121,0xfffffe59,0x000001f9,0xfffffdeb,0x000001f9,0xfffffe59,0x00000121,0xffffff95,}};
370
371static const short filter_int_const[SBLIMIT][64] = {
372{ 23170, 24279, 25330, 26320, 27246, 28106, 28899, 29622, 30274, 30853, 31357, 31786, 32138, 32413, 32610, 32729, 32767, 32729, 32610, 32413, 32138, 31786, 31357, 30853, 30274, 29622, 28899, 28106, 27246, 26320, 25330, 24279, 23170, 22006, 20788, 19520, 18205, 16846, 15447, 14010, 12540, 11039, 9512, 7962, 6393, 4808, 3212, 1608, 0, -1607, -3211, -4807, -6392, -7961, -9511,-11038,-12539,-14009,-15446,-16845,-18204,-19519,-20787,-22005, },
373{ -23169,-19519,-15446,-11038, -6392, -1607, 3212, 7962, 12540, 16846, 20788, 24279, 27246, 29622, 31357, 32413, 32767, 32413, 31357, 29622, 27246, 24279, 20788, 16846, 12540, 7962, 3212, -1607, -6392,-11038,-15446,-19519,-23169,-26319,-28898,-30852,-32137,-32728,-32609,-31785,-30273,-28105,-25329,-22005,-18204,-14009, -9511, -4807, 0, 4808, 9512, 14010, 18205, 22006, 25330, 28106, 30274, 31786, 32610, 32729, 32138, 30853, 28899, 26320, },
374{ -23169,-28105,-31356,-32728,-32137,-29621,-25329,-19519,-12539, -4807, 3212, 11039, 18205, 24279, 28899, 31786, 32767, 31786, 28899, 24279, 18205, 11039, 3212, -4807,-12539,-19519,-25329,-29621,-32137,-32728,-31356,-28105,-23169,-16845, -9511, -1607, 6393, 14010, 20788, 26320, 30274, 32413, 32610, 30853, 27246, 22006, 15447, 7962, 0, -7961,-15446,-22005,-27245,-30852,-32609,-32412,-30273,-26319,-20787,-14009, -6392, 1608, 9512, 16846, },
375{ 23170, 14010, 3212, -7961,-18204,-26319,-31356,-32728,-30273,-24278,-15446, -4807, 6393, 16846, 25330, 30853, 32767, 30853, 25330, 16846, 6393, -4807,-15446,-24278,-30273,-32728,-31356,-26319,-18204, -7961, 3212, 14010, 23170, 29622, 32610, 31786, 27246, 19520, 9512, -1607,-12539,-22005,-28898,-32412,-32137,-28105,-20787,-11038, 0, 11039, 20788, 28106, 32138, 32413, 28899, 22006, 12540, 1608, -9511,-19519,-27245,-31785,-32609,-29621, },
376{ 23170, 30853, 32610, 28106, 18205, 4808, -9511,-22005,-30273,-32728,-28898,-19519, -6392, 7962, 20788, 29622, 32767, 29622, 20788, 7962, -6392,-19519,-28898,-32728,-30273,-22005, -9511, 4808, 18205, 28106, 32610, 30853, 23170, 11039, -3211,-16845,-27245,-32412,-31356,-24278,-12539, 1608, 15447, 26320, 32138, 31786, 25330, 14010, 0,-14009,-25329,-31785,-32137,-26319,-15446, -1607, 12540, 24279, 31357, 32413, 27246, 16846, 3212,-11038, },
377{ -23169, -7961, 9512, 24279, 32138, 30853, 20788, 4808,-12539,-26319,-32609,-29621,-18204, -1607, 15447, 28106, 32767, 28106, 15447, -1607,-18204,-29621,-32609,-26319,-12539, 4808, 20788, 30853, 32138, 24279, 9512, -7961,-23169,-31785,-31356,-22005, -6392, 11039, 25330, 32413, 30274, 19520, 3212,-14009,-27245,-32728,-28898,-16845, 0, 16846, 28899, 32729, 27246, 14010, -3211,-19519,-30273,-32412,-25329,-11038, 6393, 22006, 31357, 31786, },
378{ -23169,-32412,-28898,-14009, 6393, 24279, 32610, 28106, 12540, -7961,-25329,-32728,-27245,-11038, 9512, 26320, 32767, 26320, 9512,-11038,-27245,-32728,-25329, -7961, 12540, 28106, 32610, 24279, 6393,-14009,-28898,-32412,-23169, -4807, 15447, 29622, 32138, 22006, 3212,-16845,-30273,-31785,-20787, -1607, 18205, 30853, 31357, 19520, 0,-19519,-31356,-30852,-18204, 1608, 20788, 31786, 30274, 16846, -3211,-22005,-32137,-29621,-15446, 4808, },
379{ 23170, 1608,-20787,-32412,-27245, -7961, 15447, 30853, 30274, 14010, -9511,-28105,-32137,-19519, 3212, 24279, 32767, 24279, 3212,-19519,-32137,-28105, -9511, 14010, 30274, 30853, 15447, -7961,-27245,-32412,-20787, 1608, 23170, 32729, 25330, 4808,-18204,-31785,-28898,-11038, 12540, 29622, 31357, 16846, -6392,-26319,-32609,-22005, 0, 22006, 32610, 26320, 6393,-16845,-31356,-29621,-12539, 11039, 28899, 31786, 18205, -4807,-25329,-32728, },
380{ 23170, 32729, 20788, -4807,-27245,-31785,-15446, 11039, 30274, 29622, 9512,-16845,-32137,-26319, -3211, 22006, 32767, 22006, -3211,-26319,-32137,-16845, 9512, 29622, 30274, 11039,-15446,-31785,-27245, -4807, 20788, 32729, 23170, -1607,-25329,-32412,-18204, 7962, 28899, 30853, 12540,-14009,-31356,-28105, -6392, 19520, 32610, 24279, 0,-24278,-32609,-19519, 6393, 28106, 31357, 14010,-12539,-30852,-28898, -7961, 18205, 32413, 25330, 1608, },
381{ -23169, 4808, 28899, 29622, 6393,-22005,-32609,-16845, 12540, 31786, 25330, -1607,-27245,-30852, -9511, 19520, 32767, 19520, -9511,-30852,-27245, -1607, 25330, 31786, 12540,-16845,-32609,-22005, 6393, 29622, 28899, 4808,-23169,-32412,-15446, 14010, 32138, 24279, -3211,-28105,-30273, -7961, 20788, 32729, 18205,-11038,-31356,-26319, 0, 26320, 31357, 11039,-18204,-32728,-20787, 7962, 30274, 28106, 3212,-24278,-32137,-14009, 15447, 32413, },
382{ -23169,-31785, -9511, 22006, 32138, 11039,-20787,-32412,-12539, 19520, 32610, 14010,-18204,-32728,-15446, 16846, 32767, 16846,-15446,-32728,-18204, 14010, 32610, 19520,-12539,-32412,-20787, 11039, 32138, 22006, -9511,-31785,-23169, 7962, 31357, 24279, -6392,-30852,-25329, 4808, 30274, 26320, -3211,-29621,-27245, 1608, 28899, 28106, 0,-28105,-28898, -1607, 27246, 29622, 3212,-26319,-30273, -4807, 25330, 30853, 6393,-24278,-31356, -7961, },
383{ 23170,-11038,-32609,-16845, 18205, 32413, 9512,-24278,-30273, -1607, 28899, 26320, -6392,-31785,-20787, 14010, 32767, 14010,-20787,-31785, -6392, 26320, 28899, -1607,-30273,-24278, 9512, 32413, 18205,-16845,-32609,-11038, 23170, 30853, 3212,-28105,-27245, 4808, 31357, 22006,-12539,-32728,-15446, 19520, 32138, 7962,-25329,-29621, 0, 29622, 25330, -7961,-32137,-19519, 15447, 32729, 12540,-22005,-31356, -4807, 27246, 28106, -3211,-30852, },
384{ 23170, 29622, -3211,-31785,-18204, 19520, 31357, 1608,-30273,-22005, 15447, 32413, 6393,-28105,-25329, 11039, 32767, 11039,-25329,-28105, 6393, 32413, 15447,-22005,-30273, 1608, 31357, 19520,-18204,-31785, -3211, 29622, 23170,-14009,-32609, -7961, 27246, 26320, -9511,-32728,-12539, 24279, 28899, -4807,-32137,-16845, 20788, 30853, 0,-30852,-20787, 16846, 32138, 4808,-28898,-24278, 12540, 32729, 9512,-26319,-27245, 7962, 32610, 14010, },
385{ -23169, 16846, 31357, -1607,-32137,-14009, 25330, 26320,-12539,-32412, -3211, 30853, 18205,-22005,-28898, 7962, 32767, 7962,-28898,-22005, 18205, 30853, -3211,-32412,-12539, 26320, 25330,-14009,-32137, -1607, 31357, 16846,-23169,-28105, 9512, 32729, 6393,-29621,-20787, 19520, 30274, -4807,-32609,-11038, 27246, 24279,-15446,-31785, 0, 31786, 15447,-24278,-27245, 11039, 32610, 4808,-30273,-19519, 20788, 29622, -6392,-32728, -9511, 28106, },
386{ -23169,-26319, 15447, 30853, -6392,-32728, -3211, 31786, 12540,-28105,-20787, 22006, 27246,-14009,-31356, 4808, 32767, 4808,-31356,-14009, 27246, 22006,-20787,-28105, 12540, 31786, -3211,-32728, -6392, 30853, 15447,-26319,-23169, 19520, 28899,-11038,-32137, 1608, 32610, 7962,-30273,-16845, 25330, 24279,-18204,-29621, 9512, 32413, 0,-32412, -9511, 29622, 18205,-24278,-25329, 16846, 30274, -7961,-32609, -1607, 32138, 11039,-28898,-19519, },
387{ 23170,-22005,-25329, 19520, 27246,-16845,-28898, 14010, 30274,-11038,-31356, 7962, 32138, -4807,-32609, 1608, 32767, 1608,-32609, -4807, 32138, 7962,-31356,-11038, 30274, 14010,-28898,-16845, 27246, 19520,-25329,-22005, 23170, 24279,-20787,-26319, 18205, 28106,-15446,-29621, 12540, 30853, -9511,-31785, 6393, 32413, -3211,-32728, 0, 32729, 3212,-32412, -6392, 31786, 9512,-30852,-12539, 29622, 15447,-28105,-18204, 26320, 20788,-24278, },
388{ 23170, 22006,-25329,-19519, 27246, 16846,-28898,-14009, 30274, 11039,-31356, -7961, 32138, 4808,-32609, -1607, 32767, -1607,-32609, 4808, 32138, -7961,-31356, 11039, 30274,-14009,-28898, 16846, 27246,-19519,-25329, 22006, 23170,-24278,-20787, 26320, 18205,-28105,-15446, 29622, 12540,-30852, -9511, 31786, 6393,-32412, -3211, 32729, 0,-32728, 3212, 32413, -6392,-31785, 9512, 30853,-12539,-29621, 15447, 28106,-18204,-26319, 20788, 24279, },
389{ -23169, 26320, 15447,-30852, -6392, 32729, -3211,-31785, 12540, 28106,-20787,-22005, 27246, 14010,-31356, -4807, 32767, -4807,-31356, 14010, 27246,-22005,-20787, 28106, 12540,-31785, -3211, 32729, -6392,-30852, 15447, 26320,-23169,-19519, 28899, 11039,-32137, -1607, 32610, -7961,-30273, 16846, 25330,-24278,-18204, 29622, 9512,-32412, 0, 32413, -9511,-29621, 18205, 24279,-25329,-16845, 30274, 7962,-32609, 1608, 32138,-11038,-28898, 19520, },
390{ -23169,-16845, 31357, 1608,-32137, 14010, 25330,-26319,-12539, 32413, -3211,-30852, 18205, 22006,-28898, -7961, 32767, -7961,-28898, 22006, 18205,-30852, -3211, 32413,-12539,-26319, 25330, 14010,-32137, 1608, 31357,-16845,-23169, 28106, 9512,-32728, 6393, 29622,-20787,-19519, 30274, 4808,-32609, 11039, 27246,-24278,-15446, 31786, 0,-31785, 15447, 24279,-27245,-11038, 32610, -4807,-30273, 19520, 20788,-29621, -6392, 32729, -9511,-28105, },
391{ 23170,-29621, -3211, 31786,-18204,-19519, 31357, -1607,-30273, 22006, 15447,-32412, 6393, 28106,-25329,-11038, 32767,-11038,-25329, 28106, 6393,-32412, 15447, 22006,-30273, -1607, 31357,-19519,-18204, 31786, -3211,-29621, 23170, 14010,-32609, 7962, 27246,-26319, -9511, 32729,-12539,-24278, 28899, 4808,-32137, 16846, 20788,-30852, 0, 30853,-20787,-16845, 32138, -4807,-28898, 24279, 12540,-32728, 9512, 26320,-27245, -7961, 32610,-14009, },
392{ 23170, 11039,-32609, 16846, 18205,-32412, 9512, 24279,-30273, 1608, 28899,-26319, -6392, 31786,-20787,-14009, 32767,-14009,-20787, 31786, -6392,-26319, 28899, 1608,-30273, 24279, 9512,-32412, 18205, 16846,-32609, 11039, 23170,-30852, 3212, 28106,-27245, -4807, 31357,-22005,-12539, 32729,-15446,-19519, 32138, -7961,-25329, 29622, 0,-29621, 25330, 7962,-32137, 19520, 15447,-32728, 12540, 22006,-31356, 4808, 27246,-28105, -3211, 30853, },
393{ -23169, 31786, -9511,-22005, 32138,-11038,-20787, 32413,-12539,-19519, 32610,-14009,-18204, 32729,-15446,-16845, 32767,-16845,-15446, 32729,-18204,-14009, 32610,-19519,-12539, 32413,-20787,-11038, 32138,-22005, -9511, 31786,-23169, -7961, 31357,-24278, -6392, 30853,-25329, -4807, 30274,-26319, -3211, 29622,-27245, -1607, 28899,-28105, 0, 28106,-28898, 1608, 27246,-29621, 3212, 26320,-30273, 4808, 25330,-30852, 6393, 24279,-31356, 7962, },
394{ -23169, -4807, 28899,-29621, 6393, 22006,-32609, 16846, 12540,-31785, 25330, 1608,-27245, 30853, -9511,-19519, 32767,-19519, -9511, 30853,-27245, 1608, 25330,-31785, 12540, 16846,-32609, 22006, 6393,-29621, 28899, -4807,-23169, 32413,-15446,-14009, 32138,-24278, -3211, 28106,-30273, 7962, 20788,-32728, 18205, 11039,-31356, 26320, 0,-26319, 31357,-11038,-18204, 32729,-20787, -7961, 30274,-28105, 3212, 24279,-32137, 14010, 15447,-32412, },
395{ 23170,-32728, 20788, 4808,-27245, 31786,-15446,-11038, 30274,-29621, 9512, 16846,-32137, 26320, -3211,-22005, 32767,-22005, -3211, 26320,-32137, 16846, 9512,-29621, 30274,-11038,-15446, 31786,-27245, 4808, 20788,-32728, 23170, 1608,-25329, 32413,-18204, -7961, 28899,-30852, 12540, 14010,-31356, 28106, -6392,-19519, 32610,-24278, 0, 24279,-32609, 19520, 6393,-28105, 31357,-14009,-12539, 30853,-28898, 7962, 18205,-32412, 25330, -1607, },
396{ 23170, -1607,-20787, 32413,-27245, 7962, 15447,-30852, 30274,-14009, -9511, 28106,-32137, 19520, 3212,-24278, 32767,-24278, 3212, 19520,-32137, 28106, -9511,-14009, 30274,-30852, 15447, 7962,-27245, 32413,-20787, -1607, 23170,-32728, 25330, -4807,-18204, 31786,-28898, 11039, 12540,-29621, 31357,-16845, -6392, 26320,-32609, 22006, 0,-22005, 32610,-26319, 6393, 16846,-31356, 29622,-12539,-11038, 28899,-31785, 18205, 4808,-25329, 32729, },
397{ -23169, 32413,-28898, 14010, 6393,-24278, 32610,-28105, 12540, 7962,-25329, 32729,-27245, 11039, 9512,-26319, 32767,-26319, 9512, 11039,-27245, 32729,-25329, 7962, 12540,-28105, 32610,-24278, 6393, 14010,-28898, 32413,-23169, 4808, 15447,-29621, 32138,-22005, 3212, 16846,-30273, 31786,-20787, 1608, 18205,-30852, 31357,-19519, 0, 19520,-31356, 30853,-18204, -1607, 20788,-31785, 30274,-16845, -3211, 22006,-32137, 29622,-15446, -4807, },
398{ -23169, 7962, 9512,-24278, 32138,-30852, 20788, -4807,-12539, 26320,-32609, 29622,-18204, 1608, 15447,-28105, 32767,-28105, 15447, 1608,-18204, 29622,-32609, 26320,-12539, -4807, 20788,-30852, 32138,-24278, 9512, 7962,-23169, 31786,-31356, 22006, -6392,-11038, 25330,-32412, 30274,-19519, 3212, 14010,-27245, 32729,-28898, 16846, 0,-16845, 28899,-32728, 27246,-14009, -3211, 19520,-30273, 32413,-25329, 11039, 6393,-22005, 31357,-31785, },
399{ 23170,-30852, 32610,-28105, 18205, -4807, -9511, 22006,-30273, 32729,-28898, 19520, -6392, -7961, 20788,-29621, 32767,-29621, 20788, -7961, -6392, 19520,-28898, 32729,-30273, 22006, -9511, -4807, 18205,-28105, 32610,-30852, 23170,-11038, -3211, 16846,-27245, 32413,-31356, 24279,-12539, -1607, 15447,-26319, 32138,-31785, 25330,-14009, 0, 14010,-25329, 31786,-32137, 26320,-15446, 1608, 12540,-24278, 31357,-32412, 27246,-16845, 3212, 11039, },
400{ 23170,-14009, 3212, 7962,-18204, 26320,-31356, 32729,-30273, 24279,-15446, 4808, 6393,-16845, 25330,-30852, 32767,-30852, 25330,-16845, 6393, 4808,-15446, 24279,-30273, 32729,-31356, 26320,-18204, 7962, 3212,-14009, 23170,-29621, 32610,-31785, 27246,-19519, 9512, 1608,-12539, 22006,-28898, 32413,-32137, 28106,-20787, 11039, 0,-11038, 20788,-28105, 32138,-32412, 28899,-22005, 12540, -1607, -9511, 19520,-27245, 31786,-32609, 29622, },
401{ -23169, 28106,-31356, 32729,-32137, 29622,-25329, 19520,-12539, 4808, 3212,-11038, 18205,-24278, 28899,-31785, 32767,-31785, 28899,-24278, 18205,-11038, 3212, 4808,-12539, 19520,-25329, 29622,-32137, 32729,-31356, 28106,-23169, 16846, -9511, 1608, 6393,-14009, 20788,-26319, 30274,-32412, 32610,-30852, 27246,-22005, 15447, -7961, 0, 7962,-15446, 22006,-27245, 30853,-32609, 32413,-30273, 26320,-20787, 14010, -6392, -1607, 9512,-16845, },
402{ -23169, 19520,-15446, 11039, -6392, 1608, 3212, -7961, 12540,-16845, 20788,-24278, 27246,-29621, 31357,-32412, 32767,-32412, 31357,-29621, 27246,-24278, 20788,-16845, 12540, -7961, 3212, 1608, -6392, 11039,-15446, 19520,-23169, 26320,-28898, 30853,-32137, 32729,-32609, 31786,-30273, 28106,-25329, 22006,-18204, 14010, -9511, 4808, 0, -4807, 9512,-14009, 18205,-22005, 25330,-28105, 30274,-31785, 32610,-32728, 32138,-30852, 28899,-26319, },
403{ 23170,-24278, 25330,-26319, 27246,-28105, 28899,-29621, 30274,-30852, 31357,-31785, 32138,-32412, 32610,-32728, 32767,-32728, 32610,-32412, 32138,-31785, 31357,-30852, 30274,-29621, 28899,-28105, 27246,-26319, 25330,-24278, 23170,-22005, 20788,-19519, 18205,-16845, 15447,-14009, 12540,-11038, 9512, -7961, 6393, -4807, 3212, -1607, 0, 1608, -3211, 4808, -6392, 7962, -9511, 11039,-12539, 14010,-15446, 16846,-18204, 19520,-20787, 22006, } };
404
405static const int sfBand[6][23] =
406{
407/* Table B.2.b: 22.05 kHz */
408{0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576},
409/* Table B.2.c: 24 kHz */
410{0,6,12,18,24,30,36,44,54,66,80,96,114,136,162,194,232,278,330,394,464,540,576},
411/* Table B.2.a: 16 kHz */
412{0,6,12,18,24,30,36,44,45,66,80,96,116,140,168,200,238,248,336,396,464,522,576},
413/* Table B.8.b: 44.1 kHz */
414{0,4, 8,12,16,20,24,30,36,44,52,62, 74, 90,110,134,162,196,238,288,342,418,576},
415/* Table B.8.c: 48 kHz */
416{0,4, 8,12,16,20,24,30,36,42,50,60, 72, 88,106,128,156,190,230,276,330,384,576},
417/* Table B.8.a: 32 kHz */
418{0,4, 8,12,16,20,24,30,36,44,54,66, 82,102,126,156,194,240,296,364,448,550,576} };
419
420static const uint16 enwindow_int_const[512] = {
4210x0000,0x0035,0x01fd,0x066c,0x4948,0x066c,0x01fd,0x0035,0x0000,0x0037,0x01f4,0x05d2,0x493c,0x06f8,0x0204,0x0034,
4220x0000,0x0038,0x01e8,0x052a,0x491a,0x0776,0x0208,0x0032,0x0000,0x0038,0x01d9,0x0474,0x48e1,0x07e7,0x020a,0x0031,
4230x0000,0x0039,0x01c8,0x03b0,0x4892,0x084b,0x0209,0x0030,0x0000,0x0039,0x01b3,0x02de,0x482d,0x08a2,0x0207,0x002e,
4240x0000,0x0039,0x019b,0x01fd,0x47b2,0x08ed,0x0202,0x002c,0x0000,0x0039,0x0180,0x010f,0x4721,0x092b,0x01fc,0x002a,
4250x0000,0x0038,0x0161,0x0011,0x467a,0x095e,0x01f4,0x0028,0x0000,0x0037,0x0140,0xff07,0x45bf,0x0985,0x01eb,0x0026,
4260x0000,0x0036,0x011b,0xfdee,0x44f0,0x09a2,0x01e0,0x0025,0x0000,0x0034,0x00f3,0xfcc8,0x440c,0x09b4,0x01d4,0x0023,
4270x0000,0x0032,0x00c7,0xfb93,0x4315,0x09bb,0x01c6,0x0021,0x0000,0x002f,0x0097,0xfa53,0x420b,0x09ba,0x01b8,0x001f,
4280x0000,0x002c,0x0065,0xf905,0x40f0,0x09af,0x01a9,0x001d,0x0000,0x0029,0x002e,0xf7aa,0x3fc3,0x099b,0x0198,0x001c,
4290x0000,0x0025,0xfff6,0xf643,0x3e85,0x0980,0x0188,0x001a,0xffff,0x0020,0xffb9,0xf4d1,0x3d37,0x095c,0x0176,0x0018,
4300xffff,0x001b,0xff79,0xf354,0x3bda,0x0932,0x0165,0x0017,0xffff,0x0015,0xff36,0xf1cc,0x3a70,0x0901,0x0153,0x0015,
4310xffff,0x000e,0xfeef,0xf03a,0x38f7,0x08ca,0x0141,0x0014,0xffff,0x0007,0xfea6,0xee9f,0x3773,0x088d,0x012f,0x0012,
4320xfffe,0x0000,0xfe5a,0xecfb,0x35e3,0x084b,0x011c,0x0011,0xfffe,0xfff8,0xfe0b,0xeb50,0x3447,0x0804,0x010a,0x0010,
4330xfffe,0xffef,0xfdbb,0xe99d,0x32a3,0x07ba,0x00f8,0x000f,0xfffd,0xffe5,0xfd67,0xe7e4,0x30f6,0x076b,0x00e6,0x000d,
4340xfffd,0xffdb,0xfd12,0xe624,0x2f41,0x071a,0x00d4,0x000c,0xfffd,0xffd0,0xfcbb,0xe461,0x2d86,0x06c6,0x00c3,0x000b,
4350xfffc,0xffc4,0xfc63,0xe299,0x2bc5,0x066f,0x00b2,0x000a,0xfffc,0xffb8,0xfc09,0xe0ce,0x2a00,0x0617,0x00a1,0x0009,
4360xfffb,0xffaa,0xfbaf,0xdf01,0x2836,0x05be,0x0091,0x0009,0xfffb,0xff9d,0xfb54,0xdd33,0x266a,0x0563,0x0081,0x0008,
4370xfffa,0xff8e,0xfaf9,0xdb65,0x249c,0x0508,0x0073,0x0007,0xfff9,0xff80,0xfa9e,0xd997,0x22ce,0x04ad,0x0064,0x0006,
4380xfff8,0xff70,0xfa43,0xd7cb,0x2100,0x0452,0x0057,0x0006,0xfff8,0xff60,0xf9ea,0xd601,0x1f33,0x03f8,0x0049,0x0005,
4390xfff7,0xff4f,0xf992,0xd43c,0x1d68,0x039e,0x003d,0x0005,0xfff6,0xff3e,0xf93b,0xd27b,0x1ba0,0x0346,0x0031,0x0004,
4400xfff5,0xff2d,0xf8e7,0xd0c0,0x19dd,0x02ef,0x0026,0x0004,0xfff4,0xff1b,0xf896,0xcf0b,0x181d,0x029a,0x001c,0x0004,
4410xfff2,0xff09,0xf847,0xcd5e,0x1664,0x0246,0x0012,0x0003,0xfff1,0xfef7,0xf7fd,0xcbba,0x14b1,0x01f6,0x0009,0x0003,
4420xfff0,0xfee5,0xf7b6,0xca1e,0x1306,0x01a7,0x0001,0x0003,0xffef,0xfed2,0xf774,0xc88e,0x1162,0x015b,0xfffa,0x0002,
4430xffed,0xfec0,0xf737,0xc70a,0x0fc7,0x0112,0xfff3,0x0002,0xffec,0xfeae,0xf700,0xc591,0x0e35,0x00cb,0xffec,0x0002,
4440xffea,0xfe9c,0xf6cf,0xc427,0x0cad,0x0088,0xffe6,0x0002,0xffe9,0xfe8b,0xf6a5,0xc2ca,0x0b30,0x0048,0xffe1,0x0002,
4450xffe7,0xfe79,0xf681,0xc17c,0x09be,0x000b,0xffdc,0x0001,0xffe5,0xfe69,0xf666,0xc03e,0x0857,0xffd3,0xffd8,0x0001,
4460xffe4,0xfe58,0xf652,0xbf11,0x06fc,0xff9c,0xffd5,0x0001,0xffe2,0xfe49,0xf647,0xbdf6,0x05ae,0xff6a,0xffd2,0x0001,
4470xffe0,0xfe3b,0xf646,0xbcec,0x046e,0xff3a,0xffcf,0x0001,0xffde,0xfe2d,0xf64d,0xbbf5,0x0339,0xff0e,0xffcd,0x0001,
4480xffdc,0xfe21,0xf65f,0xbb11,0x0213,0xfee6,0xffcb,0x0001,0xffdb,0xfe16,0xf67c,0xba42,0x00fa,0xfec1,0xffca,0x0001,
4490xffd9,0xfe0d,0xf6a3,0xb987,0xfff0,0xfea0,0xffc9,0x0001,0xffd7,0xfe05,0xf6d6,0xb8e0,0xfef2,0xfe81,0xffc8,0x0001,
4500xffd5,0xfdff,0xf714,0xb84f,0xfe04,0xfe66,0xffc8,0x0000,0xffd3,0xfdfa,0xf75f,0xb7d4,0xfd23,0xfe4e,0xffc8,0x0000,
4510xffd1,0xfdf8,0xf7b6,0xb76f,0xfc51,0xfe39,0xffc8,0x0000,0xffd0,0xfdf7,0xf81a,0xb720,0xfb8d,0xfe28,0xffc9,0x0000,
4520xffcf,0xfdf9,0xf88b,0xb6e7,0xfad7,0xfe19,0xffc9,0x0000,0xffcd,0xfdfd,0xf909,0xb6c5,0xfa2f,0xfe0d,0xffca,0x0000,
453};
454
455static const uint8 int2idx_const[5000] = {
456 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5,
457 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
458 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11,
459 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
460 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16,
461 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 18,
462 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
463 20, 20, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23,
464 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 25, 25,
465 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27,
466 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 29, 29,
467 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 31,
468 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
469 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
470 34, 34, 34, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
471 36, 36, 36, 36, 36, 36, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, 38, 38, 38,
472 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 40, 40, 40, 40,
473 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41,
474 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43,
475 43, 43, 43, 43, 43, 43, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 45, 45, 45, 45, 45, 45, 45, 45,
476 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 47, 47,
477 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
478 48, 48, 48, 48, 48, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 50, 50, 50, 50, 50, 50, 50,
479 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
480 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53,
481 53, 53, 53, 53, 53, 53, 53, 53, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 55, 55, 55, 55,
482 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
483 56, 56, 56, 56, 56, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 58, 58, 58, 58, 58, 58, 58,
484 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59,
485 59, 59, 59, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 61, 61, 61, 61, 61, 61, 61, 61,
486 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
487 62, 62, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 64, 64, 64, 64, 64, 64, 64, 64, 64,
488 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
489 65, 65, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 67, 67, 67, 67, 67, 67, 67, 67,
490 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68,
491 68, 68, 68, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 70, 70, 70, 70, 70, 70, 70,
492 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71,
493 71, 71, 71, 71, 71, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 73, 73, 73, 73, 73,
494 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74,
495 74, 74, 74, 74, 74, 74, 74, 74, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 76, 76,
496 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
497 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78,
498 78, 78, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 80, 80, 80, 80, 80, 80, 80,
499 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81,
500 81, 81, 81, 81, 81, 81, 81, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 83,
501 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84,
502 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85,
503 85, 85, 85, 85, 85, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 87, 87, 87, 87,
504 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88,
505 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89,
506 89, 89, 89, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 91, 91, 91, 91, 91,
507 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92,
508 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
509 93, 93, 93, 93, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 95, 95, 95, 95,
510 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96,
511 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97,
512 97, 97, 97, 97, 97, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 99, 99,
513 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,100,100,100,100,100,100,100,100,100,100,
514100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,101,101,101,101,101,101,101,101,101,101,101,101,101,101,101,101,101,
515101,101,101,101,101,101,101,101,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,
516102,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,104,104,104,104,104,104,
517104,104,104,104,104,104,104,104,104,104,104,104,104,104,104,104,104,104,104,105,105,105,105,105,105,105,105,105,105,105,105,105,
518105,105,105,105,105,105,105,105,105,105,105,105,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106,
519106,106,106,106,106,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,108,
520108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,109,109,109,109,109,109,109,109,
521109,109,109,109,109,109,109,109,109,109,109,109,109,109,109,109,109,109,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
522110,110,110,110,110,110,110,110,110,110,110,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,
523111,111,111,111,111,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,113,
524113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,114,114,114,114,114,114,114,114,
525114,114,114,114,114,114,114,114,114,114,114,114,114,114,114,114,114,114,115,115,115,115,115,115,115,115,115,115,115,115,115,115,
526115,115,115,115,115,115,115,115,115,115,115,115,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
527116,116,116,116,116,116,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,
528118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,119,119,119,119,119,119,
529119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,120,120,120,120,120,120,120,120,120,120,120,
530120,120,120,120,120,120,120,120,120,120,120,120,120,120,120,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,
531121,121,121,121,121,121,121,121,121,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,
532122,122,122,122,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,124,124,
533124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,125,125,125,125,125,125,125,
534125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,126,126,126,126,126,126,126,126,126,126,126,126,
535126,126,126,126,126,126,126,126,126,126,126,126,126,126,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,
536127,127,127,127,127,127,127,127,127,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,
537128,128,128,128,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,130,
538130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,131,131,131,131,131,131,
539131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,132,132,132,132,132,132,132,132,132,132,132,
540132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,
541133,133,133,133,133,133,133,133,133,133,133,133,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,
542134,134,134,134,134,134,134,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,
543135,135,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,137,137,
544137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,138,138,138,138,138,138,138,
545138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,139,139,139,139,139,139,139,139,139,139,139,
546139,139,139,139,139,139,139,139,139,139,139,139,139,139,139,139,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,
547140,140,140,140,140,140,140,140,140,140,140,140,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,
548141,141,141,141,141,141,141,141,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,
549142,142,142,142,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,144,
550144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,145,145,145,145,145,
551145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,146,146,146,146,146,146,146,146,146,
552146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,147,147,147,147,147,147,147,147,147,147,147,147,
553147,147,147,147,147,147,147,147,147,147,147,147,147,147,147,147,148,148,148,148,148,148,148,148,148,148,148,148,148,148,148,148,
554148,148,148,148,148,148,148,148,148,148,148,148,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,
555149,149,149,149,149,149,149,149,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,
556150,150,150,150,150,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,
557151,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,153,153,153,
558153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,154,154,154,154,154,154,
559154,154,154,154,154,154,154,154,154,154,154,154,154,154,154,154,154,154,154,154,154,154,154,155,155,155,155,155,155,155,155,155,
560155,155,155,155,155,155,155,155,155,155,155,155,155,155,155,155,155,155,155,156,156,156,156,156,156,156,156,156,156,156,156,156,
561156,156,156,156,156,156,156,156,156,156,156,156,156,156,156,156,157,157,157,157,157,157,157,157,157,157,157,157,157,157,157,157,
562157,157,157,157,157,157,157,157,157,157,157,157,157,158,158,158,158,158,158,158,158,158,158,158,158,158,158,158,158,158,158,158,
563158,158,158,158,158,158,158,158,158,158,159,159,159,159,159,159,159,159,159,159,159,159,159,159,159,159,159,159,159,159,159,159,
564159,159,159,159,159,159,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,
565160,160,160,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,
566162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,163,163,163,
567163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,164,164,164,164,164,
568164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,165,165,165,165,165,165,165,165,
569165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,166,166,166,166,166,166,166,166,166,166,166,
570166,166,166,166,166,166,166,166,166,166,166,166,166,166,166,166,166,166,167,167,167,167,167,167,167,167,167,167,167,167,167,167,
571167,167,167,167,167,167,167,167,167,167,167,167,167,167,167,167,168,168,168,168,168,168,168,168,168,168,168,168,168,168,168,168,
572168,168,168,168,168,168,168,168,168,168,168,168,168,169,169,169,169,169,169,169,169,169,169,169,169,169,169,169,169,169,169,169,
573169,169,169,169,169,169,169,169,169,169,169,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,
574170,170,170,170,170,170,170,170,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,
575171,171,171,171,171,171,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,
576172,172,172,172,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,
577173,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,175,
578175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,176,176,176,
579176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,177,177,177,177,177,
580177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,178,178,178,178,178,178,178,
581178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,179,179,179,179,179,179,179,179,179,
582179,179,179,179,179,179,179,179,179,179,179,179,179,179,179,179,179,179,179,179,179,180,180,180,180,180,180,180,180,180,180,180,
583180,180,180,180,180,180,180,180,180,180,180,180,180,180,180,180,180,180,180,181,181,181,181,181,181,181,181,181,181,181,181,181,
584181,181,181,181,181,181,181,181,181,181,181,181,181,181,181,181,181,182,182,182,182,182,182,182,182,182,182,182,182,182,182,182,
585182,182,182,182,182,182,182,182,182,182,182,182,182,182,182,183,183,183,183,183,183,183,183,183,183,183,183,183,183,183,183,183,
586183,183,183,183,183,183,183,183,183,183,183,183,183,183,184,184,184,184,184,184,184,184,184,184,184,184,184,184,184,184,184,184,
587184,184,184,184,184,184,184,184,184,184,184,184,185,185,185,185,185,185,185,185,185,185,185,185,185,185,185,185,185,185,185,185,
588185,185,185,185,185,185,185,185,185,185,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,
589186,186,186,186,186,186,186,186,186,187,187,187,187,187,187,187,187,187,187,187,187,187,187,187,187,187,187,187,187,187,187,187,
590187,187,187,187,187,187,187,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,
591188,188,188,188,188,188,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,
592189,189,189,189,190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,
593190,190,190,191,191,191,191,191,191,191,191,191,191,191,191,191,191,191,191,191,191,191,191,191,191,191,191,191,191,191,191,191,
594191,191,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,
595192,193,193,193,193,193,193,193,193,193,193,193,193,193,193,193,193,193,193,193,193,193,193,193,193,193,193,193,193,193,193,194,
596194,194,194,194,194,194,194,194,194,194,194,194,194,194,194,194,194,194,194,194,194,194,194,194,194,194,194,194,194,194,195,195,
597195,195,195,195,195,195,195,195,195,195,195,195,195,195,195,195,195,195,195,195,195,195,195,195,195,195,195,195,195,196,196,196,
598196,196,196,196,196,196,196,196,196,196,196,196,196,196,196,196,196,196,196,196,196,196,196,196,196,196,196,196,197,197,197,197,
599197,197,197,197,197,197,197,197,197,197,197,197,197,197,197,197,197,197,197,197,197,197,197,197,197,197,197,198,198,198,198,198,
600198,198,198,198,198,198,198,198,198,198,198,198,198,198,198,198,198,198,198,198,198,198,198,198,198,198,199,199,199,199,199,199,
601199,199,199,199,199,199,199,199,199,199,199,199,199,199,199,199,199,199,199,199,199,199,199,199,199,200,200,200,200,200,200,200,
602200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,201,201,201,201,201,201,201,
603201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,202,202,202,202,202,202,202,202,
604202,202,202,202,202,202,202,202,202,202,202,202,202,202,202,202,202,202,202,202,202,202,202,203,203,203,203,203,203,203,203,203,
605203,203,203,203,203,203,203,203,203,203,203,203,203,203,203,203,203,203,203,203,203,203,203,204,204,204,204,204,204,204,204,204,
606204,204,204,204,204,204,204,204,204,204,204,204,204,204,204,204,204,204,204,204,204,204,205,205,205,205,205,205,205,205,205,205,
607205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,206,206,206,206,206,206,206,206,206,206,206,
608206,206,206,206,206,206,206,206,206,206,206,206,206,206,206,206,206,206,206,206,206,207,207,207,207,207,207,207,207,207,207,207,
609207,207,207,207,207,207,207,207,207,207,207,207,207,207,207,207,207,207,207,207,208,208,208,208,208,208,208,208,208,208,208,208,
610208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,209,209,209,209,209,209,209,209,209,209,209,209,
611209,209,209,209,209,209,209,209,209,209,209,209,209,209,209,209,209,209,209,209,210,210,210,210,210,210,210,210,210,210,210,210,
612210,210,210,210,210,210,210,210 };
613
614static const uint16 int3idx[32768] = {
615 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5,
616 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
617 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11,
618 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
619 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16,
620 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 18,
621 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
622 20, 20, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23,
623 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 25, 25,
624 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27,
625 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 29, 29,
626 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 31,
627 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
628 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
629 34, 34, 34, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
630 36, 36, 36, 36, 36, 36, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, 38, 38, 38,
631 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 40, 40, 40, 40,
632 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41,
633 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43,
634 43, 43, 43, 43, 43, 43, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 45, 45, 45, 45, 45, 45, 45, 45,
635 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 47, 47,
636 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
637 48, 48, 48, 48, 48, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 50, 50, 50, 50, 50, 50, 50,
638 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
639 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53,
640 53, 53, 53, 53, 53, 53, 53, 53, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 55, 55, 55, 55,
641 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
642 56, 56, 56, 56, 56, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 58, 58, 58, 58, 58, 58, 58,
643 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59,
644 59, 59, 59, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 61, 61, 61, 61, 61, 61, 61, 61,
645 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
646 62, 62, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 64, 64, 64, 64, 64, 64, 64, 64, 64,
647 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
648 65, 65, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 67, 67, 67, 67, 67, 67, 67, 67,
649 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68,
650 68, 68, 68, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 70, 70, 70, 70, 70, 70, 70,
651 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71,
652 71, 71, 71, 71, 71, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 73, 73, 73, 73, 73,
653 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74,
654 74, 74, 74, 74, 74, 74, 74, 74, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 76, 76,
655 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
656 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78,
657 78, 78, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 80, 80, 80, 80, 80, 80, 80,
658 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81,
659 81, 81, 81, 81, 81, 81, 81, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 83,
660 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84,
661 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85,
662 85, 85, 85, 85, 85, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 87, 87, 87, 87,
663 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88,
664 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89,
665 89, 89, 89, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 91, 91, 91, 91, 91,
666 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92,
667 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
668 93, 93, 93, 93, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 95, 95, 95, 95,
669 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96,
670 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97,
671 97, 97, 97, 97, 97, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 99, 99,
672 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,100,100,100,100,100,100,100,100,100,100,
673100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,101,101,101,101,101,101,101,101,101,101,101,101,101,101,101,101,101,
674101,101,101,101,101,101,101,101,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,
675102,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,104,104,104,104,104,104,
676104,104,104,104,104,104,104,104,104,104,104,104,104,104,104,104,104,104,104,105,105,105,105,105,105,105,105,105,105,105,105,105,
677105,105,105,105,105,105,105,105,105,105,105,105,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106,
678106,106,106,106,106,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,108,
679108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,109,109,109,109,109,109,109,109,
680109,109,109,109,109,109,109,109,109,109,109,109,109,109,109,109,109,109,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
681110,110,110,110,110,110,110,110,110,110,110,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,
682111,111,111,111,111,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,113,
683113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,114,114,114,114,114,114,114,114,
684114,114,114,114,114,114,114,114,114,114,114,114,114,114,114,114,114,114,115,115,115,115,115,115,115,115,115,115,115,115,115,115,
685115,115,115,115,115,115,115,115,115,115,115,115,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,
686116,116,116,116,116,116,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,
687118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,119,119,119,119,119,119,
688119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,120,120,120,120,120,120,120,120,120,120,120,
689120,120,120,120,120,120,120,120,120,120,120,120,120,120,120,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,
690121,121,121,121,121,121,121,121,121,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,
691122,122,122,122,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,124,124,
692124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,125,125,125,125,125,125,125,
693125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,126,126,126,126,126,126,126,126,126,126,126,126,
694126,126,126,126,126,126,126,126,126,126,126,126,126,126,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,
695127,127,127,127,127,127,127,127,127,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,
696128,128,128,128,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,130,
697130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,131,131,131,131,131,131,
698131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,132,132,132,132,132,132,132,132,132,132,132,
699132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,
700133,133,133,133,133,133,133,133,133,133,133,133,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,
701134,134,134,134,134,134,134,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,
702135,135,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,137,137,
703137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,138,138,138,138,138,138,138,
704138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,139,139,139,139,139,139,139,139,139,139,139,
705139,139,139,139,139,139,139,139,139,139,139,139,139,139,139,139,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,
706140,140,140,140,140,140,140,140,140,140,140,140,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,
707141,141,141,141,141,141,141,141,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,
708142,142,142,142,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,144,
709144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,145,145,145,145,145,
710145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,146,146,146,146,146,146,146,146,146,
711146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,147,147,147,147,147,147,147,147,147,147,147,147,
712147,147,147,147,147,147,147,147,147,147,147,147,147,147,147,147,148,148,148,148,148,148,148,148,148,148,148,148,148,148,148,148,
713148,148,148,148,148,148,148,148,148,148,148,148,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,
714149,149,149,149,149,149,149,149,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,
715150,150,150,150,150,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,
716151,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,153,153,153,
717153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,154,154,154,154,154,154,
718154,154,154,154,154,154,154,154,154,154,154,154,154,154,154,154,154,154,154,154,154,154,154,155,155,155,155,155,155,155,155,155,
719155,155,155,155,155,155,155,155,155,155,155,155,155,155,155,155,155,155,155,156,156,156,156,156,156,156,156,156,156,156,156,156,
720156,156,156,156,156,156,156,156,156,156,156,156,156,156,156,156,157,157,157,157,157,157,157,157,157,157,157,157,157,157,157,157,
721157,157,157,157,157,157,157,157,157,157,157,157,157,158,158,158,158,158,158,158,158,158,158,158,158,158,158,158,158,158,158,158,
722158,158,158,158,158,158,158,158,158,158,159,159,159,159,159,159,159,159,159,159,159,159,159,159,159,159,159,159,159,159,159,159,
723159,159,159,159,159,159,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,
724160,160,160,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,
725162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,163,163,163,
726163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,164,164,164,164,164,
727164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,165,165,165,165,165,165,165,165,
728165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,166,166,166,166,166,166,166,166,166,166,166,
729166,166,166,166,166,166,166,166,166,166,166,166,166,166,166,166,166,166,167,167,167,167,167,167,167,167,167,167,167,167,167,167,
730167,167,167,167,167,167,167,167,167,167,167,167,167,167,167,167,168,168,168,168,168,168,168,168,168,168,168,168,168,168,168,168,
731168,168,168,168,168,168,168,168,168,168,168,168,168,169,169,169,169,169,169,169,169,169,169,169,169,169,169,169,169,169,169,169,
732169,169,169,169,169,169,169,169,169,169,169,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,
733170,170,170,170,170,170,170,170,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,
734171,171,171,171,171,171,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,
735172,172,172,172,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,
736173,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,175,
737175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,176,176,176,
738176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,177,177,177,177,177,
739177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,178,178,178,178,178,178,178,
740178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,179,179,179,179,179,179,179,179,179,
741179,179,179,179,179,179,179,179,179,179,179,179,179,179,179,179,179,179,179,179,179,180,180,180,180,180,180,180,180,180,180,180,
742180,180,180,180,180,180,180,180,180,180,180,180,180,180,180,180,180,180,180,181,181,181,181,181,181,181,181,181,181,181,181,181,
743181,181,181,181,181,181,181,181,181,181,181,181,181,181,181,181,181,182,182,182,182,182,182,182,182,182,182,182,182,182,182,182,
744182,182,182,182,182,182,182,182,182,182,182,182,182,182,182,183,183,183,183,183,183,183,183,183,183,183,183,183,183,183,183,183,
745183,183,183,183,183,183,183,183,183,183,183,183,183,183,184,184,184,184,184,184,184,184,184,184,184,184,184,184,184,184,184,184,
746184,184,184,184,184,184,184,184,184,184,184,184,185,185,185,185,185,185,185,185,185,185,185,185,185,185,185,185,185,185,185,185,
747185,185,185,185,185,185,185,185,185,185,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,
748186,186,186,186,186,186,186,186,186,187,187,187,187,187,187,187,187,187,187,187,187,187,187,187,187,187,187,187,187,187,187,187,
749187,187,187,187,187,187,187,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,
750188,188,188,188,188,188,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,
751189,189,189,189,190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,
752190,190,190,191,191,191,191,191,191,191,191,191,191,191,191,191,191,191,191,191,191,191,191,191,191,191,191,191,191,191,191,191,
753191,191,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,
754192,193,193,193,193,193,193,193,193,193,193,193,193,193,193,193,193,193,193,193,193,193,193,193,193,193,193,193,193,193,193,194,
755194,194,194,194,194,194,194,194,194,194,194,194,194,194,194,194,194,194,194,194,194,194,194,194,194,194,194,194,194,194,195,195,
756195,195,195,195,195,195,195,195,195,195,195,195,195,195,195,195,195,195,195,195,195,195,195,195,195,195,195,195,195,196,196,196,
757196,196,196,196,196,196,196,196,196,196,196,196,196,196,196,196,196,196,196,196,196,196,196,196,196,196,196,196,197,197,197,197,
758197,197,197,197,197,197,197,197,197,197,197,197,197,197,197,197,197,197,197,197,197,197,197,197,197,197,197,198,198,198,198,198,
759198,198,198,198,198,198,198,198,198,198,198,198,198,198,198,198,198,198,198,198,198,198,198,198,198,198,199,199,199,199,199,199,
760199,199,199,199,199,199,199,199,199,199,199,199,199,199,199,199,199,199,199,199,199,199,199,199,199,200,200,200,200,200,200,200,
761200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,201,201,201,201,201,201,201,
762201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,201,202,202,202,202,202,202,202,202,
763202,202,202,202,202,202,202,202,202,202,202,202,202,202,202,202,202,202,202,202,202,202,202,203,203,203,203,203,203,203,203,203,
764203,203,203,203,203,203,203,203,203,203,203,203,203,203,203,203,203,203,203,203,203,203,203,204,204,204,204,204,204,204,204,204,
765204,204,204,204,204,204,204,204,204,204,204,204,204,204,204,204,204,204,204,204,204,204,205,205,205,205,205,205,205,205,205,205,
766205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,206,206,206,206,206,206,206,206,206,206,206,
767206,206,206,206,206,206,206,206,206,206,206,206,206,206,206,206,206,206,206,206,206,207,207,207,207,207,207,207,207,207,207,207,
768207,207,207,207,207,207,207,207,207,207,207,207,207,207,207,207,207,207,207,207,208,208,208,208,208,208,208,208,208,208,208,208,
769208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,209,209,209,209,209,209,209,209,209,209,209,209,
770209,209,209,209,209,209,209,209,209,209,209,209,209,209,209,209,209,209,209,209,210,210,210,210,210,210,210,210,210,210,210,210,
771210,210,210,210,210,210,210,210,210,210,210,210,210,210,210,210,210,210,210,211,211,211,211,211,211,211,211,211,211,211,211,211,
772211,211,211,211,211,211,211,211,211,211,211,211,211,211,211,211,211,211,211,212,212,212,212,212,212,212,212,212,212,212,212,212,
773212,212,212,212,212,212,212,212,212,212,212,212,212,212,212,212,212,212,212,213,213,213,213,213,213,213,213,213,213,213,213,213,
774213,213,213,213,213,213,213,213,213,213,213,213,213,213,213,213,213,213,213,214,214,214,214,214,214,214,214,214,214,214,214,214,
775214,214,214,214,214,214,214,214,214,214,214,214,214,214,214,214,214,214,214,215,215,215,215,215,215,215,215,215,215,215,215,215,
776215,215,215,215,215,215,215,215,215,215,215,215,215,215,215,215,215,215,215,216,216,216,216,216,216,216,216,216,216,216,216,216,
777216,216,216,216,216,216,216,216,216,216,216,216,216,216,216,216,216,216,216,217,217,217,217,217,217,217,217,217,217,217,217,217,
778217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,217,218,218,218,218,218,218,218,218,218,218,218,218,218,
779218,218,218,218,218,218,218,218,218,218,218,218,218,218,218,218,218,218,218,219,219,219,219,219,219,219,219,219,219,219,219,219,
780219,219,219,219,219,219,219,219,219,219,219,219,219,219,219,219,219,219,219,220,220,220,220,220,220,220,220,220,220,220,220,220,
781220,220,220,220,220,220,220,220,220,220,220,220,220,220,220,220,220,220,220,221,221,221,221,221,221,221,221,221,221,221,221,221,
782221,221,221,221,221,221,221,221,221,221,221,221,221,221,221,221,221,221,221,222,222,222,222,222,222,222,222,222,222,222,222,222,
783222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,223,223,223,223,223,223,223,223,223,223,223,223,
784223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,224,224,224,224,224,224,224,224,224,224,224,224,
785224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,225,225,225,225,225,225,225,225,225,225,225,
786225,225,225,225,225,225,225,225,225,225,225,225,225,225,225,225,225,225,225,225,225,226,226,226,226,226,226,226,226,226,226,226,
787226,226,226,226,226,226,226,226,226,226,226,226,226,226,226,226,226,226,226,226,226,227,227,227,227,227,227,227,227,227,227,227,
788227,227,227,227,227,227,227,227,227,227,227,227,227,227,227,227,227,227,227,227,227,227,228,228,228,228,228,228,228,228,228,228,
789228,228,228,228,228,228,228,228,228,228,228,228,228,228,228,228,228,228,228,228,228,228,228,229,229,229,229,229,229,229,229,229,
790229,229,229,229,229,229,229,229,229,229,229,229,229,229,229,229,229,229,229,229,229,229,229,230,230,230,230,230,230,230,230,230,
791230,230,230,230,230,230,230,230,230,230,230,230,230,230,230,230,230,230,230,230,230,230,230,230,231,231,231,231,231,231,231,231,
792231,231,231,231,231,231,231,231,231,231,231,231,231,231,231,231,231,231,231,231,231,231,231,231,231,232,232,232,232,232,232,232,
793232,232,232,232,232,232,232,232,232,232,232,232,232,232,232,232,232,232,232,232,232,232,232,232,232,233,233,233,233,233,233,233,
794233,233,233,233,233,233,233,233,233,233,233,233,233,233,233,233,233,233,233,233,233,233,233,233,233,233,234,234,234,234,234,234,
795234,234,234,234,234,234,234,234,234,234,234,234,234,234,234,234,234,234,234,234,234,234,234,234,234,234,234,235,235,235,235,235,
796235,235,235,235,235,235,235,235,235,235,235,235,235,235,235,235,235,235,235,235,235,235,235,235,235,235,235,235,236,236,236,236,
797236,236,236,236,236,236,236,236,236,236,236,236,236,236,236,236,236,236,236,236,236,236,236,236,236,236,236,236,236,237,237,237,
798237,237,237,237,237,237,237,237,237,237,237,237,237,237,237,237,237,237,237,237,237,237,237,237,237,237,237,237,237,237,238,238,
799238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,239,
800239,239,239,239,239,239,239,239,239,239,239,239,239,239,239,239,239,239,239,239,239,239,239,239,239,239,239,239,239,239,239,239,
801240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,240,
802240,241,241,241,241,241,241,241,241,241,241,241,241,241,241,241,241,241,241,241,241,241,241,241,241,241,241,241,241,241,241,241,
803241,241,242,242,242,242,242,242,242,242,242,242,242,242,242,242,242,242,242,242,242,242,242,242,242,242,242,242,242,242,242,242,
804242,242,242,242,243,243,243,243,243,243,243,243,243,243,243,243,243,243,243,243,243,243,243,243,243,243,243,243,243,243,243,243,
805243,243,243,243,243,244,244,244,244,244,244,244,244,244,244,244,244,244,244,244,244,244,244,244,244,244,244,244,244,244,244,244,
806244,244,244,244,244,244,245,245,245,245,245,245,245,245,245,245,245,245,245,245,245,245,245,245,245,245,245,245,245,245,245,245,
807245,245,245,245,245,245,245,245,246,246,246,246,246,246,246,246,246,246,246,246,246,246,246,246,246,246,246,246,246,246,246,246,
808246,246,246,246,246,246,246,246,246,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,247,
809247,247,247,247,247,247,247,247,247,247,247,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,248,
810248,248,248,248,248,248,248,248,248,248,248,248,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,249,
811249,249,249,249,249,249,249,249,249,249,249,249,249,249,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,
812250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,
813251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,252,252,252,252,252,252,252,252,252,252,252,252,252,252,252,
814252,252,252,252,252,252,252,252,252,252,252,252,252,252,252,252,252,252,252,253,253,253,253,253,253,253,253,253,253,253,253,253,
815253,253,253,253,253,253,253,253,253,253,253,253,253,253,253,253,253,253,253,253,254,254,254,254,254,254,254,254,254,254,254,254,
816254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,254,255,255,255,255,255,255,255,255,255,255,
817255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,256,256,256,256,256,256,256,256,
818256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,257,257,257,257,257,257,
819257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,258,258,258,258,
820258,258,258,258,258,258,258,258,258,258,258,258,258,258,258,258,258,258,258,258,258,258,258,258,258,258,258,258,258,258,259,259,
821259,259,259,259,259,259,259,259,259,259,259,259,259,259,259,259,259,259,259,259,259,259,259,259,259,259,259,259,259,259,259,259,
822260,260,260,260,260,260,260,260,260,260,260,260,260,260,260,260,260,260,260,260,260,260,260,260,260,260,260,260,260,260,260,260,
823260,260,261,261,261,261,261,261,261,261,261,261,261,261,261,261,261,261,261,261,261,261,261,261,261,261,261,261,261,261,261,261,
824261,261,261,261,262,262,262,262,262,262,262,262,262,262,262,262,262,262,262,262,262,262,262,262,262,262,262,262,262,262,262,262,
825262,262,262,262,262,262,263,263,263,263,263,263,263,263,263,263,263,263,263,263,263,263,263,263,263,263,263,263,263,263,263,263,
826263,263,263,263,263,263,263,263,264,264,264,264,264,264,264,264,264,264,264,264,264,264,264,264,264,264,264,264,264,264,264,264,
827264,264,264,264,264,264,264,264,264,264,265,265,265,265,265,265,265,265,265,265,265,265,265,265,265,265,265,265,265,265,265,265,
828265,265,265,265,265,265,265,265,265,265,265,265,265,266,266,266,266,266,266,266,266,266,266,266,266,266,266,266,266,266,266,266,
829266,266,266,266,266,266,266,266,266,266,266,266,266,266,266,267,267,267,267,267,267,267,267,267,267,267,267,267,267,267,267,267,
830267,267,267,267,267,267,267,267,267,267,267,267,267,267,267,267,267,268,268,268,268,268,268,268,268,268,268,268,268,268,268,268,
831268,268,268,268,268,268,268,268,268,268,268,268,268,268,268,268,268,268,268,268,269,269,269,269,269,269,269,269,269,269,269,269,
832269,269,269,269,269,269,269,269,269,269,269,269,269,269,269,269,269,269,269,269,269,269,270,270,270,270,270,270,270,270,270,270,
833270,270,270,270,270,270,270,270,270,270,270,270,270,270,270,270,270,270,270,270,270,270,270,270,270,271,271,271,271,271,271,271,
834271,271,271,271,271,271,271,271,271,271,271,271,271,271,271,271,271,271,271,271,271,271,271,271,271,271,271,272,272,272,272,272,
835272,272,272,272,272,272,272,272,272,272,272,272,272,272,272,272,272,272,272,272,272,272,272,272,272,272,272,272,272,272,273,273,
836273,273,273,273,273,273,273,273,273,273,273,273,273,273,273,273,273,273,273,273,273,273,273,273,273,273,273,273,273,273,273,273,
837274,274,274,274,274,274,274,274,274,274,274,274,274,274,274,274,274,274,274,274,274,274,274,274,274,274,274,274,274,274,274,274,
838274,274,274,275,275,275,275,275,275,275,275,275,275,275,275,275,275,275,275,275,275,275,275,275,275,275,275,275,275,275,275,275,
839275,275,275,275,275,275,276,276,276,276,276,276,276,276,276,276,276,276,276,276,276,276,276,276,276,276,276,276,276,276,276,276,
840276,276,276,276,276,276,276,276,277,277,277,277,277,277,277,277,277,277,277,277,277,277,277,277,277,277,277,277,277,277,277,277,
841277,277,277,277,277,277,277,277,277,277,277,278,278,278,278,278,278,278,278,278,278,278,278,278,278,278,278,278,278,278,278,278,
842278,278,278,278,278,278,278,278,278,278,278,278,278,278,279,279,279,279,279,279,279,279,279,279,279,279,279,279,279,279,279,279,
843279,279,279,279,279,279,279,279,279,279,279,279,279,279,279,279,279,280,280,280,280,280,280,280,280,280,280,280,280,280,280,280,
844280,280,280,280,280,280,280,280,280,280,280,280,280,280,280,280,280,280,280,280,281,281,281,281,281,281,281,281,281,281,281,281,
845281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,282,282,282,282,282,282,282,282,282,
846282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,283,283,283,283,283,283,
847283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,284,284,284,
848284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,
849285,285,285,285,285,285,285,285,285,285,285,285,285,285,285,285,285,285,285,285,285,285,285,285,285,285,285,285,285,285,285,285,
850285,285,285,286,286,286,286,286,286,286,286,286,286,286,286,286,286,286,286,286,286,286,286,286,286,286,286,286,286,286,286,286,
851286,286,286,286,286,286,287,287,287,287,287,287,287,287,287,287,287,287,287,287,287,287,287,287,287,287,287,287,287,287,287,287,
852287,287,287,287,287,287,287,287,287,288,288,288,288,288,288,288,288,288,288,288,288,288,288,288,288,288,288,288,288,288,288,288,
853288,288,288,288,288,288,288,288,288,288,288,288,289,289,289,289,289,289,289,289,289,289,289,289,289,289,289,289,289,289,289,289,
854289,289,289,289,289,289,289,289,289,289,289,289,289,289,289,289,290,290,290,290,290,290,290,290,290,290,290,290,290,290,290,290,
855290,290,290,290,290,290,290,290,290,290,290,290,290,290,290,290,290,290,290,291,291,291,291,291,291,291,291,291,291,291,291,291,
856291,291,291,291,291,291,291,291,291,291,291,291,291,291,291,291,291,291,291,291,291,291,292,292,292,292,292,292,292,292,292,292,
857292,292,292,292,292,292,292,292,292,292,292,292,292,292,292,292,292,292,292,292,292,292,292,292,292,292,293,293,293,293,293,293,
858293,293,293,293,293,293,293,293,293,293,293,293,293,293,293,293,293,293,293,293,293,293,293,293,293,293,293,293,293,294,294,294,
859294,294,294,294,294,294,294,294,294,294,294,294,294,294,294,294,294,294,294,294,294,294,294,294,294,294,294,294,294,294,294,294,
860295,295,295,295,295,295,295,295,295,295,295,295,295,295,295,295,295,295,295,295,295,295,295,295,295,295,295,295,295,295,295,295,
861295,295,295,295,296,296,296,296,296,296,296,296,296,296,296,296,296,296,296,296,296,296,296,296,296,296,296,296,296,296,296,296,
862296,296,296,296,296,296,296,297,297,297,297,297,297,297,297,297,297,297,297,297,297,297,297,297,297,297,297,297,297,297,297,297,
863297,297,297,297,297,297,297,297,297,297,297,298,298,298,298,298,298,298,298,298,298,298,298,298,298,298,298,298,298,298,298,298,
864298,298,298,298,298,298,298,298,298,298,298,298,298,298,298,299,299,299,299,299,299,299,299,299,299,299,299,299,299,299,299,299,
865299,299,299,299,299,299,299,299,299,299,299,299,299,299,299,299,299,299,300,300,300,300,300,300,300,300,300,300,300,300,300,300,
866300,300,300,300,300,300,300,300,300,300,300,300,300,300,300,300,300,300,300,300,300,300,301,301,301,301,301,301,301,301,301,301,
867301,301,301,301,301,301,301,301,301,301,301,301,301,301,301,301,301,301,301,301,301,301,301,301,301,301,302,302,302,302,302,302,
868302,302,302,302,302,302,302,302,302,302,302,302,302,302,302,302,302,302,302,302,302,302,302,302,302,302,302,302,302,302,303,303,
869303,303,303,303,303,303,303,303,303,303,303,303,303,303,303,303,303,303,303,303,303,303,303,303,303,303,303,303,303,303,303,303,
870303,304,304,304,304,304,304,304,304,304,304,304,304,304,304,304,304,304,304,304,304,304,304,304,304,304,304,304,304,304,304,304,
871304,304,304,304,304,305,305,305,305,305,305,305,305,305,305,305,305,305,305,305,305,305,305,305,305,305,305,305,305,305,305,305,
872305,305,305,305,305,305,305,305,305,306,306,306,306,306,306,306,306,306,306,306,306,306,306,306,306,306,306,306,306,306,306,306,
873306,306,306,306,306,306,306,306,306,306,306,306,306,307,307,307,307,307,307,307,307,307,307,307,307,307,307,307,307,307,307,307,
874307,307,307,307,307,307,307,307,307,307,307,307,307,307,307,307,307,308,308,308,308,308,308,308,308,308,308,308,308,308,308,308,
875308,308,308,308,308,308,308,308,308,308,308,308,308,308,308,308,308,308,308,308,308,309,309,309,309,309,309,309,309,309,309,309,
876309,309,309,309,309,309,309,309,309,309,309,309,309,309,309,309,309,309,309,309,309,309,309,309,309,310,310,310,310,310,310,310,
877310,310,310,310,310,310,310,310,310,310,310,310,310,310,310,310,310,310,310,310,310,310,310,310,310,310,310,310,310,311,311,311,
878311,311,311,311,311,311,311,311,311,311,311,311,311,311,311,311,311,311,311,311,311,311,311,311,311,311,311,311,311,311,311,311,
879311,312,312,312,312,312,312,312,312,312,312,312,312,312,312,312,312,312,312,312,312,312,312,312,312,312,312,312,312,312,312,312,
880312,312,312,312,312,312,313,313,313,313,313,313,313,313,313,313,313,313,313,313,313,313,313,313,313,313,313,313,313,313,313,313,
881313,313,313,313,313,313,313,313,313,313,314,314,314,314,314,314,314,314,314,314,314,314,314,314,314,314,314,314,314,314,314,314,
882314,314,314,314,314,314,314,314,314,314,314,314,314,314,315,315,315,315,315,315,315,315,315,315,315,315,315,315,315,315,315,315,
883315,315,315,315,315,315,315,315,315,315,315,315,315,315,315,315,315,315,316,316,316,316,316,316,316,316,316,316,316,316,316,316,
884316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,317,317,317,317,317,317,317,317,317,
885317,317,317,317,317,317,317,317,317,317,317,317,317,317,317,317,317,317,317,317,317,317,317,317,317,317,317,318,318,318,318,318,
886318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,319,
887319,319,319,319,319,319,319,319,319,319,319,319,319,319,319,319,319,319,319,319,319,319,319,319,319,319,319,319,319,319,319,319,
888319,319,319,319,320,320,320,320,320,320,320,320,320,320,320,320,320,320,320,320,320,320,320,320,320,320,320,320,320,320,320,320,
889320,320,320,320,320,320,320,320,321,321,321,321,321,321,321,321,321,321,321,321,321,321,321,321,321,321,321,321,321,321,321,321,
890321,321,321,321,321,321,321,321,321,321,321,321,321,322,322,322,322,322,322,322,322,322,322,322,322,322,322,322,322,322,322,322,
891322,322,322,322,322,322,322,322,322,322,322,322,322,322,322,322,322,323,323,323,323,323,323,323,323,323,323,323,323,323,323,323,
892323,323,323,323,323,323,323,323,323,323,323,323,323,323,323,323,323,323,323,323,323,323,324,324,324,324,324,324,324,324,324,324,
893324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,325,325,325,325,325,
894325,325,325,325,325,325,325,325,325,325,325,325,325,325,325,325,325,325,325,325,325,325,325,325,325,325,325,325,325,325,325,326,
895326,326,326,326,326,326,326,326,326,326,326,326,326,326,326,326,326,326,326,326,326,326,326,326,326,326,326,326,326,326,326,326,
896326,326,326,326,327,327,327,327,327,327,327,327,327,327,327,327,327,327,327,327,327,327,327,327,327,327,327,327,327,327,327,327,
897327,327,327,327,327,327,327,327,327,328,328,328,328,328,328,328,328,328,328,328,328,328,328,328,328,328,328,328,328,328,328,328,
898328,328,328,328,328,328,328,328,328,328,328,328,328,328,329,329,329,329,329,329,329,329,329,329,329,329,329,329,329,329,329,329,
899329,329,329,329,329,329,329,329,329,329,329,329,329,329,329,329,329,329,330,330,330,330,330,330,330,330,330,330,330,330,330,330,
900330,330,330,330,330,330,330,330,330,330,330,330,330,330,330,330,330,330,330,330,330,330,330,331,331,331,331,331,331,331,331,331,
901331,331,331,331,331,331,331,331,331,331,331,331,331,331,331,331,331,331,331,331,331,331,331,331,331,331,331,331,332,332,332,332,
902332,332,332,332,332,332,332,332,332,332,332,332,332,332,332,332,332,332,332,332,332,332,332,332,332,332,332,332,332,332,332,332,
903332,333,333,333,333,333,333,333,333,333,333,333,333,333,333,333,333,333,333,333,333,333,333,333,333,333,333,333,333,333,333,333,
904333,333,333,333,333,333,334,334,334,334,334,334,334,334,334,334,334,334,334,334,334,334,334,334,334,334,334,334,334,334,334,334,
905334,334,334,334,334,334,334,334,334,334,334,335,335,335,335,335,335,335,335,335,335,335,335,335,335,335,335,335,335,335,335,335,
906335,335,335,335,335,335,335,335,335,335,335,335,335,335,335,335,336,336,336,336,336,336,336,336,336,336,336,336,336,336,336,336,
907336,336,336,336,336,336,336,336,336,336,336,336,336,336,336,336,336,336,336,336,336,337,337,337,337,337,337,337,337,337,337,337,
908337,337,337,337,337,337,337,337,337,337,337,337,337,337,337,337,337,337,337,337,337,337,337,337,337,337,338,338,338,338,338,338,
909338,338,338,338,338,338,338,338,338,338,338,338,338,338,338,338,338,338,338,338,338,338,338,338,338,338,338,338,338,338,338,338,
910339,339,339,339,339,339,339,339,339,339,339,339,339,339,339,339,339,339,339,339,339,339,339,339,339,339,339,339,339,339,339,339,
911339,339,339,339,339,340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,340,
912340,340,340,340,340,340,340,340,340,340,341,341,341,341,341,341,341,341,341,341,341,341,341,341,341,341,341,341,341,341,341,341,
913341,341,341,341,341,341,341,341,341,341,341,341,341,341,341,342,342,342,342,342,342,342,342,342,342,342,342,342,342,342,342,342,
914342,342,342,342,342,342,342,342,342,342,342,342,342,342,342,342,342,342,342,342,343,343,343,343,343,343,343,343,343,343,343,343,
915343,343,343,343,343,343,343,343,343,343,343,343,343,343,343,343,343,343,343,343,343,343,343,343,343,343,344,344,344,344,344,344,
916344,344,344,344,344,344,344,344,344,344,344,344,344,344,344,344,344,344,344,344,344,344,344,344,344,344,344,344,344,344,344,345,
917345,345,345,345,345,345,345,345,345,345,345,345,345,345,345,345,345,345,345,345,345,345,345,345,345,345,345,345,345,345,345,345,
918345,345,345,345,345,346,346,346,346,346,346,346,346,346,346,346,346,346,346,346,346,346,346,346,346,346,346,346,346,346,346,346,
919346,346,346,346,346,346,346,346,346,346,347,347,347,347,347,347,347,347,347,347,347,347,347,347,347,347,347,347,347,347,347,347,
920347,347,347,347,347,347,347,347,347,347,347,347,347,347,347,347,348,348,348,348,348,348,348,348,348,348,348,348,348,348,348,348,
921348,348,348,348,348,348,348,348,348,348,348,348,348,348,348,348,348,348,348,348,348,349,349,349,349,349,349,349,349,349,349,349,
922349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,349,350,350,350,350,350,
923350,350,350,350,350,350,350,350,350,350,350,350,350,350,350,350,350,350,350,350,350,350,350,350,350,350,350,350,350,350,350,350,
924351,351,351,351,351,351,351,351,351,351,351,351,351,351,351,351,351,351,351,351,351,351,351,351,351,351,351,351,351,351,351,351,
925351,351,351,351,351,351,352,352,352,352,352,352,352,352,352,352,352,352,352,352,352,352,352,352,352,352,352,352,352,352,352,352,
926352,352,352,352,352,352,352,352,352,352,352,353,353,353,353,353,353,353,353,353,353,353,353,353,353,353,353,353,353,353,353,353,
927353,353,353,353,353,353,353,353,353,353,353,353,353,353,353,353,353,354,354,354,354,354,354,354,354,354,354,354,354,354,354,354,
928354,354,354,354,354,354,354,354,354,354,354,354,354,354,354,354,354,354,354,354,354,354,354,355,355,355,355,355,355,355,355,355,
929355,355,355,355,355,355,355,355,355,355,355,355,355,355,355,355,355,355,355,355,355,355,355,355,355,355,355,355,355,356,356,356,
930356,356,356,356,356,356,356,356,356,356,356,356,356,356,356,356,356,356,356,356,356,356,356,356,356,356,356,356,356,356,356,356,
931356,356,357,357,357,357,357,357,357,357,357,357,357,357,357,357,357,357,357,357,357,357,357,357,357,357,357,357,357,357,357,357,
932357,357,357,357,357,357,357,357,358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,358,
933358,358,358,358,358,358,358,358,358,358,358,358,358,358,359,359,359,359,359,359,359,359,359,359,359,359,359,359,359,359,359,359,
934359,359,359,359,359,359,359,359,359,359,359,359,359,359,359,359,359,359,359,359,360,360,360,360,360,360,360,360,360,360,360,360,
935360,360,360,360,360,360,360,360,360,360,360,360,360,360,360,360,360,360,360,360,360,360,360,360,360,360,361,361,361,361,361,361,
936361,361,361,361,361,361,361,361,361,361,361,361,361,361,361,361,361,361,361,361,361,361,361,361,361,361,361,361,361,361,361,361,
937362,362,362,362,362,362,362,362,362,362,362,362,362,362,362,362,362,362,362,362,362,362,362,362,362,362,362,362,362,362,362,362,
938362,362,362,362,362,362,363,363,363,363,363,363,363,363,363,363,363,363,363,363,363,363,363,363,363,363,363,363,363,363,363,363,
939363,363,363,363,363,363,363,363,363,363,363,363,364,364,364,364,364,364,364,364,364,364,364,364,364,364,364,364,364,364,364,364,
940364,364,364,364,364,364,364,364,364,364,364,364,364,364,364,364,364,364,365,365,365,365,365,365,365,365,365,365,365,365,365,365,
941365,365,365,365,365,365,365,365,365,365,365,365,365,365,365,365,365,365,365,365,365,365,365,365,366,366,366,366,366,366,366,366,
942366,366,366,366,366,366,366,366,366,366,366,366,366,366,366,366,366,366,366,366,366,366,366,366,366,366,366,366,366,366,367,367,
943367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,367,
944367,367,367,367,367,368,368,368,368,368,368,368,368,368,368,368,368,368,368,368,368,368,368,368,368,368,368,368,368,368,368,368,
945368,368,368,368,368,368,368,368,368,368,368,369,369,369,369,369,369,369,369,369,369,369,369,369,369,369,369,369,369,369,369,369,
946369,369,369,369,369,369,369,369,369,369,369,369,369,369,369,369,369,370,370,370,370,370,370,370,370,370,370,370,370,370,370,370,
947370,370,370,370,370,370,370,370,370,370,370,370,370,370,370,370,370,370,370,370,370,370,370,371,371,371,371,371,371,371,371,371,
948371,371,371,371,371,371,371,371,371,371,371,371,371,371,371,371,371,371,371,371,371,371,371,371,371,371,371,371,371,371,372,372,
949372,372,372,372,372,372,372,372,372,372,372,372,372,372,372,372,372,372,372,372,372,372,372,372,372,372,372,372,372,372,372,372,
950372,372,372,372,373,373,373,373,373,373,373,373,373,373,373,373,373,373,373,373,373,373,373,373,373,373,373,373,373,373,373,373,
951373,373,373,373,373,373,373,373,373,373,374,374,374,374,374,374,374,374,374,374,374,374,374,374,374,374,374,374,374,374,374,374,
952374,374,374,374,374,374,374,374,374,374,374,374,374,374,374,374,374,375,375,375,375,375,375,375,375,375,375,375,375,375,375,375,
953375,375,375,375,375,375,375,375,375,375,375,375,375,375,375,375,375,375,375,375,375,375,375,376,376,376,376,376,376,376,376,376,
954376,376,376,376,376,376,376,376,376,376,376,376,376,376,376,376,376,376,376,376,376,376,376,376,376,376,376,376,376,376,377,377,
955377,377,377,377,377,377,377,377,377,377,377,377,377,377,377,377,377,377,377,377,377,377,377,377,377,377,377,377,377,377,377,377,
956377,377,377,377,378,378,378,378,378,378,378,378,378,378,378,378,378,378,378,378,378,378,378,378,378,378,378,378,378,378,378,378,
957378,378,378,378,378,378,378,378,378,378,378,379,379,379,379,379,379,379,379,379,379,379,379,379,379,379,379,379,379,379,379,379,
958379,379,379,379,379,379,379,379,379,379,379,379,379,379,379,379,379,379,380,380,380,380,380,380,380,380,380,380,380,380,380,380,
959380,380,380,380,380,380,380,380,380,380,380,380,380,380,380,380,380,380,380,380,380,380,380,380,381,381,381,381,381,381,381,381,
960381,381,381,381,381,381,381,381,381,381,381,381,381,381,381,381,381,381,381,381,381,381,381,381,381,381,381,381,381,381,381,382,
961382,382,382,382,382,382,382,382,382,382,382,382,382,382,382,382,382,382,382,382,382,382,382,382,382,382,382,382,382,382,382,382,
962382,382,382,382,382,382,383,383,383,383,383,383,383,383,383,383,383,383,383,383,383,383,383,383,383,383,383,383,383,383,383,383,
963383,383,383,383,383,383,383,383,383,383,383,383,384,384,384,384,384,384,384,384,384,384,384,384,384,384,384,384,384,384,384,384,
964384,384,384,384,384,384,384,384,384,384,384,384,384,384,384,384,384,384,384,385,385,385,385,385,385,385,385,385,385,385,385,385,
965385,385,385,385,385,385,385,385,385,385,385,385,385,385,385,385,385,385,385,385,385,385,385,385,385,385,386,386,386,386,386,386,
966386,386,386,386,386,386,386,386,386,386,386,386,386,386,386,386,386,386,386,386,386,386,386,386,386,386,386,386,386,386,386,386,
967386,387,387,387,387,387,387,387,387,387,387,387,387,387,387,387,387,387,387,387,387,387,387,387,387,387,387,387,387,387,387,387,
968387,387,387,387,387,387,387,387,388,388,388,388,388,388,388,388,388,388,388,388,388,388,388,388,388,388,388,388,388,388,388,388,
969388,388,388,388,388,388,388,388,388,388,388,388,388,388,389,389,389,389,389,389,389,389,389,389,389,389,389,389,389,389,389,389,
970389,389,389,389,389,389,389,389,389,389,389,389,389,389,389,389,389,389,389,389,389,390,390,390,390,390,390,390,390,390,390,390,
971390,390,390,390,390,390,390,390,390,390,390,390,390,390,390,390,390,390,390,390,390,390,390,390,390,390,390,390,391,391,391,391,
972391,391,391,391,391,391,391,391,391,391,391,391,391,391,391,391,391,391,391,391,391,391,391,391,391,391,391,391,391,391,391,391,
973391,391,391,392,392,392,392,392,392,392,392,392,392,392,392,392,392,392,392,392,392,392,392,392,392,392,392,392,392,392,392,392,
974392,392,392,392,392,392,392,392,392,392,393,393,393,393,393,393,393,393,393,393,393,393,393,393,393,393,393,393,393,393,393,393,
975393,393,393,393,393,393,393,393,393,393,393,393,393,393,393,393,393,394,394,394,394,394,394,394,394,394,394,394,394,394,394,394,
976394,394,394,394,394,394,394,394,394,394,394,394,394,394,394,394,394,394,394,394,394,394,394,394,394,395,395,395,395,395,395,395,
977395,395,395,395,395,395,395,395,395,395,395,395,395,395,395,395,395,395,395,395,395,395,395,395,395,395,395,395,395,395,395,395,
978396,396,396,396,396,396,396,396,396,396,396,396,396,396,396,396,396,396,396,396,396,396,396,396,396,396,396,396,396,396,396,396,
979396,396,396,396,396,396,396,397,397,397,397,397,397,397,397,397,397,397,397,397,397,397,397,397,397,397,397,397,397,397,397,397,
980397,397,397,397,397,397,397,397,397,397,397,397,397,397,398,398,398,398,398,398,398,398,398,398,398,398,398,398,398,398,398,398,
981398,398,398,398,398,398,398,398,398,398,398,398,398,398,398,398,398,398,398,398,398,399,399,399,399,399,399,399,399,399,399,399,
982399,399,399,399,399,399,399,399,399,399,399,399,399,399,399,399,399,399,399,399,399,399,399,399,399,399,399,399,399,400,400,400,
983400,400,400,400,400,400,400,400,400,400,400,400,400,400,400,400,400,400,400,400,400,400,400,400,400,400,400,400,400,400,400,400,
984400,400,400,400,401,401,401,401,401,401,401,401,401,401,401,401,401,401,401,401,401,401,401,401,401,401,401,401,401,401,401,401,
985401,401,401,401,401,401,401,401,401,401,401,402,402,402,402,402,402,402,402,402,402,402,402,402,402,402,402,402,402,402,402,402,
986402,402,402,402,402,402,402,402,402,402,402,402,402,402,402,402,402,402,402,403,403,403,403,403,403,403,403,403,403,403,403,403,
987403,403,403,403,403,403,403,403,403,403,403,403,403,403,403,403,403,403,403,403,403,403,403,403,403,403,404,404,404,404,404,404,
988404,404,404,404,404,404,404,404,404,404,404,404,404,404,404,404,404,404,404,404,404,404,404,404,404,404,404,404,404,404,404,404,
989404,405,405,405,405,405,405,405,405,405,405,405,405,405,405,405,405,405,405,405,405,405,405,405,405,405,405,405,405,405,405,405,
990405,405,405,405,405,405,405,405,405,406,406,406,406,406,406,406,406,406,406,406,406,406,406,406,406,406,406,406,406,406,406,406,
991406,406,406,406,406,406,406,406,406,406,406,406,406,406,406,406,407,407,407,407,407,407,407,407,407,407,407,407,407,407,407,407,
992407,407,407,407,407,407,407,407,407,407,407,407,407,407,407,407,407,407,407,407,407,407,407,407,408,408,408,408,408,408,408,408,
993408,408,408,408,408,408,408,408,408,408,408,408,408,408,408,408,408,408,408,408,408,408,408,408,408,408,408,408,408,408,408,409,
994409,409,409,409,409,409,409,409,409,409,409,409,409,409,409,409,409,409,409,409,409,409,409,409,409,409,409,409,409,409,409,409,
995409,409,409,409,409,409,409,410,410,410,410,410,410,410,410,410,410,410,410,410,410,410,410,410,410,410,410,410,410,410,410,410,
996410,410,410,410,410,410,410,410,410,410,410,410,410,410,410,411,411,411,411,411,411,411,411,411,411,411,411,411,411,411,411,411,
997411,411,411,411,411,411,411,411,411,411,411,411,411,411,411,411,411,411,411,411,411,411,412,412,412,412,412,412,412,412,412,412,
998412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,412,413,413,
999413,413,413,413,413,413,413,413,413,413,413,413,413,413,413,413,413,413,413,413,413,413,413,413,413,413,413,413,413,413,413,413,
1000413,413,413,413,413,413,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,414,
1001414,414,414,414,414,414,414,414,414,414,414,414,414,415,415,415,415,415,415,415,415,415,415,415,415,415,415,415,415,415,415,415,
1002415,415,415,415,415,415,415,415,415,415,415,415,415,415,415,415,415,415,415,415,415,416,416,416,416,416,416,416,416,416,416,416,
1003416,416,416,416,416,416,416,416,416,416,416,416,416,416,416,416,416,416,416,416,416,416,416,416,416,416,416,416,416,417,417,417,
1004417,417,417,417,417,417,417,417,417,417,417,417,417,417,417,417,417,417,417,417,417,417,417,417,417,417,417,417,417,417,417,417,
1005417,417,417,417,417,418,418,418,418,418,418,418,418,418,418,418,418,418,418,418,418,418,418,418,418,418,418,418,418,418,418,418,
1006418,418,418,418,418,418,418,418,418,418,418,418,418,419,419,419,419,419,419,419,419,419,419,419,419,419,419,419,419,419,419,419,
1007419,419,419,419,419,419,419,419,419,419,419,419,419,419,419,419,419,419,419,419,419,420,420,420,420,420,420,420,420,420,420,420,
1008420,420,420,420,420,420,420,420,420,420,420,420,420,420,420,420,420,420,420,420,420,420,420,420,420,420,420,420,420,421,421,421,
1009421,421,421,421,421,421,421,421,421,421,421,421,421,421,421,421,421,421,421,421,421,421,421,421,421,421,421,421,421,421,421,421,
1010421,421,421,421,421,422,422,422,422,422,422,422,422,422,422,422,422,422,422,422,422,422,422,422,422,422,422,422,422,422,422,422,
1011422,422,422,422,422,422,422,422,422,422,422,422,422,423,423,423,423,423,423,423,423,423,423,423,423,423,423,423,423,423,423,423,
1012423,423,423,423,423,423,423,423,423,423,423,423,423,423,423,423,423,423,423,423,423,424,424,424,424,424,424,424,424,424,424,424,
1013424,424,424,424,424,424,424,424,424,424,424,424,424,424,424,424,424,424,424,424,424,424,424,424,424,424,424,424,424,425,425,425,
1014425,425,425,425,425,425,425,425,425,425,425,425,425,425,425,425,425,425,425,425,425,425,425,425,425,425,425,425,425,425,425,425,
1015425,425,425,425,425,426,426,426,426,426,426,426,426,426,426,426,426,426,426,426,426,426,426,426,426,426,426,426,426,426,426,426,
1016426,426,426,426,426,426,426,426,426,426,426,426,426,427,427,427,427,427,427,427,427,427,427,427,427,427,427,427,427,427,427,427,
1017427,427,427,427,427,427,427,427,427,427,427,427,427,427,427,427,427,427,427,427,427,428,428,428,428,428,428,428,428,428,428,428,
1018428,428,428,428,428,428,428,428,428,428,428,428,428,428,428,428,428,428,428,428,428,428,428,428,428,428,428,428,428,429,429,429,
1019429,429,429,429,429,429,429,429,429,429,429,429,429,429,429,429,429,429,429,429,429,429,429,429,429,429,429,429,429,429,429,429,
1020429,429,429,429,429,429,430,430,430,430,430,430,430,430,430,430,430,430,430,430,430,430,430,430,430,430,430,430,430,430,430,430,
1021430,430,430,430,430,430,430,430,430,430,430,430,430,430,431,431,431,431,431,431,431,431,431,431,431,431,431,431,431,431,431,431,
1022431,431,431,431,431,431,431,431,431,431,431,431,431,431,431,431,431,431,431,431,431,431,432,432,432,432,432,432,432,432,432,432,
1023432,432,432,432,432,432,432,432,432,432,432,432,432,432,432,432,432,432,432,432,432,432,432,432,432,432,432,432,432,432,433,433,
1024433,433,433,433,433,433,433,433,433,433,433,433,433,433,433,433,433,433,433,433,433,433,433,433,433,433,433,433,433,433,433,433,
1025433,433,433,433,433,433,433,434,434,434,434,434,434,434,434,434,434,434,434,434,434,434,434,434,434,434,434,434,434,434,434,434,
1026434,434,434,434,434,434,434,434,434,434,434,434,434,434,434,435,435,435,435,435,435,435,435,435,435,435,435,435,435,435,435,435,
1027435,435,435,435,435,435,435,435,435,435,435,435,435,435,435,435,435,435,435,435,435,435,435,435,436,436,436,436,436,436,436,436,
1028436,436,436,436,436,436,436,436,436,436,436,436,436,436,436,436,436,436,436,436,436,436,436,436,436,436,436,436,436,436,436,436,
1029437,437,437,437,437,437,437,437,437,437,437,437,437,437,437,437,437,437,437,437,437,437,437,437,437,437,437,437,437,437,437,437,
1030437,437,437,437,437,437,437,437,437,438,438,438,438,438,438,438,438,438,438,438,438,438,438,438,438,438,438,438,438,438,438,438,
1031438,438,438,438,438,438,438,438,438,438,438,438,438,438,438,438,438,439,439,439,439,439,439,439,439,439,439,439,439,439,439,439,
1032439,439,439,439,439,439,439,439,439,439,439,439,439,439,439,439,439,439,439,439,439,439,439,439,439,439,440,440,440,440,440,440,
1033440,440,440,440,440,440,440,440,440,440,440,440,440,440,440,440,440,440,440,440,440,440,440,440,440,440,440,440,440,440,440,440,
1034440,440,441,441,441,441,441,441,441,441,441,441,441,441,441,441,441,441,441,441,441,441,441,441,441,441,441,441,441,441,441,441,
1035441,441,441,441,441,441,441,441,441,441,441,442,442,442,442,442,442,442,442,442,442,442,442,442,442,442,442,442,442,442,442,442,
1036442,442,442,442,442,442,442,442,442,442,442,442,442,442,442,442,442,442,442,443,443,443,443,443,443,443,443,443,443,443,443,443,
1037443,443,443,443,443,443,443,443,443,443,443,443,443,443,443,443,443,443,443,443,443,443,443,443,443,443,443,443,444,444,444,444,
1038444,444,444,444,444,444,444,444,444,444,444,444,444,444,444,444,444,444,444,444,444,444,444,444,444,444,444,444,444,444,444,444,
1039444,444,444,444,444,445,445,445,445,445,445,445,445,445,445,445,445,445,445,445,445,445,445,445,445,445,445,445,445,445,445,445,
1040445,445,445,445,445,445,445,445,445,445,445,445,445,446,446,446,446,446,446,446,446,446,446,446,446,446,446,446,446,446,446,446,
1041446,446,446,446,446,446,446,446,446,446,446,446,446,446,446,446,446,446,446,446,446,446,447,447,447,447,447,447,447,447,447,447,
1042447,447,447,447,447,447,447,447,447,447,447,447,447,447,447,447,447,447,447,447,447,447,447,447,447,447,447,447,447,447,447,448,
1043448,448,448,448,448,448,448,448,448,448,448,448,448,448,448,448,448,448,448,448,448,448,448,448,448,448,448,448,448,448,448,448,
1044448,448,448,448,448,448,448,448,449,449,449,449,449,449,449,449,449,449,449,449,449,449,449,449,449,449,449,449,449,449,449,449,
1045449,449,449,449,449,449,449,449,449,449,449,449,449,449,449,449,449,450,450,450,450,450,450,450,450,450,450,450,450,450,450,450,
1046450,450,450,450,450,450,450,450,450,450,450,450,450,450,450,450,450,450,450,450,450,450,450,450,450,451,451,451,451,451,451,451,
1047451,451,451,451,451,451,451,451,451,451,451,451,451,451,451,451,451,451,451,451,451,451,451,451,451,451,451,451,451,451,451,451,
1048451,451,452,452,452,452,452,452,452,452,452,452,452,452,452,452,452,452,452,452,452,452,452,452,452,452,452,452,452,452,452,452,
1049452,452,452,452,452,452,452,452,452,452,452,453,453,453,453,453,453,453,453,453,453,453,453,453,453,453,453,453,453,453,453,453,
1050453,453,453,453,453,453,453,453,453,453,453,453,453,453,453,453,453,453,453,453,454,454,454,454,454,454,454,454,454,454,454,454,
1051454,454,454,454,454,454,454,454,454,454,454,454,454,454,454,454,454,454,454,454,454,454,454,454,454,454,454,454,454,455,455,455,
1052455,455,455,455,455,455,455,455,455,455,455,455,455,455,455,455,455,455,455,455,455,455,455,455,455,455,455,455,455,455,455,455,
1053455,455,455,455,455,455,456,456,456,456,456,456,456,456,456,456,456,456,456,456,456,456,456,456,456,456,456,456,456,456,456,456,
1054456,456,456,456,456,456,456,456,456,456,456,456,456,456,456,457,457,457,457,457,457,457,457,457,457,457,457,457,457,457,457,457,
1055457,457,457,457,457,457,457,457,457,457,457,457,457,457,457,457,457,457,457,457,457,457,457,457,458,458,458,458,458,458,458,458,
1056458,458,458,458,458,458,458,458,458,458,458,458,458,458,458,458,458,458,458,458,458,458,458,458,458,458,458,458,458,458,458,458,
1057458,458,459,459,459,459,459,459,459,459,459,459,459,459,459,459,459,459,459,459,459,459,459,459,459,459,459,459,459,459,459,459,
1058459,459,459,459,459,459,459,459,459,459,459,460,460,460,460,460,460,460,460,460,460,460,460,460,460,460,460,460,460,460,460,460,
1059460,460,460,460,460,460,460,460,460,460,460,460,460,460,460,460,460,460,460,460,461,461,461,461,461,461,461,461,461,461,461,461,
1060461,461,461,461,461,461,461,461,461,461,461,461,461,461,461,461,461,461,461,461,461,461,461,461,461,461,461,461,461,462,462,462,
1061462,462,462,462,462,462,462,462,462,462,462,462,462,462,462,462,462,462,462,462,462,462,462,462,462,462,462,462,462,462,462,462,
1062462,462,462,462,462,462,463,463,463,463,463,463,463,463,463,463,463,463,463,463,463,463,463,463,463,463,463,463,463,463,463,463,
1063463,463,463,463,463,463,463,463,463,463,463,463,463,463,463,463,464,464,464,464,464,464,464,464,464,464,464,464,464,464,464,464,
1064464,464,464,464,464,464,464,464,464,464,464,464,464,464,464,464,464,464,464,464,464,464,464,464,464,465,465,465,465,465,465,465,
1065465,465,465,465,465,465,465,465,465,465,465,465,465,465,465,465,465,465,465,465,465,465,465,465,465,465,465,465,465,465,465,465,
1066465,465,466,466,466,466,466,466,466,466,466,466,466,466,466,466,466,466,466,466,466,466,466,466,466,466,466,466,466,466,466,466,
1067466,466,466,466,466,466,466,466,466,466,466,466,467,467,467,467,467,467,467,467,467,467,467,467,467,467,467,467,467,467,467,467,
1068467,467,467,467,467,467,467,467,467,467,467,467,467,467,467,467,467,467,467,467,467,468,468,468,468,468,468,468,468,468,468,468,
1069468,468,468,468,468,468,468,468,468,468,468,468,468,468,468,468,468,468,468,468,468,468,468,468,468,468,468,468,468,468,469,469,
1070469,469,469,469,469,469,469,469,469,469,469,469,469,469,469,469,469,469,469,469,469,469,469,469,469,469,469,469,469,469,469,469,
1071469,469,469,469,469,469,469,469,470,470,470,470,470,470,470,470,470,470,470,470,470,470,470,470,470,470,470,470,470,470,470,470,
1072470,470,470,470,470,470,470,470,470,470,470,470,470,470,470,470,470,471,471,471,471,471,471,471,471,471,471,471,471,471,471,471,
1073471,471,471,471,471,471,471,471,471,471,471,471,471,471,471,471,471,471,471,471,471,471,471,471,471,471,471,472,472,472,472,472,
1074472,472,472,472,472,472,472,472,472,472,472,472,472,472,472,472,472,472,472,472,472,472,472,472,472,472,472,472,472,472,472,472,
1075472,472,472,472,473,473,473,473,473,473,473,473,473,473,473,473,473,473,473,473,473,473,473,473,473,473,473,473,473,473,473,473,
1076473,473,473,473,473,473,473,473,473,473,473,473,473,473,474,474,474,474,474,474,474,474,474,474,474,474,474,474,474,474,474,474,
1077474,474,474,474,474,474,474,474,474,474,474,474,474,474,474,474,474,474,474,474,474,474,474,475,475,475,475,475,475,475,475,475,
1078475,475,475,475,475,475,475,475,475,475,475,475,475,475,475,475,475,475,475,475,475,475,475,475,475,475,475,475,475,475,475,475,
1079475,476,476,476,476,476,476,476,476,476,476,476,476,476,476,476,476,476,476,476,476,476,476,476,476,476,476,476,476,476,476,476,
1080476,476,476,476,476,476,476,476,476,476,476,477,477,477,477,477,477,477,477,477,477,477,477,477,477,477,477,477,477,477,477,477,
1081477,477,477,477,477,477,477,477,477,477,477,477,477,477,477,477,477,477,477,477,478,478,478,478,478,478,478,478,478,478,478,478,
1082478,478,478,478,478,478,478,478,478,478,478,478,478,478,478,478,478,478,478,478,478,478,478,478,478,478,478,478,478,478,479,479,
1083479,479,479,479,479,479,479,479,479,479,479,479,479,479,479,479,479,479,479,479,479,479,479,479,479,479,479,479,479,479,479,479,
1084479,479,479,479,479,479,479,479,480,480,480,480,480,480,480,480,480,480,480,480,480,480,480,480,480,480,480,480,480,480,480,480,
1085480,480,480,480,480,480,480,480,480,480,480,480,480,480,480,480,480,480,481,481,481,481,481,481,481,481,481,481,481,481,481,481,
1086481,481,481,481,481,481,481,481,481,481,481,481,481,481,481,481,481,481,481,481,481,481,481,481,481,481,481,482,482,482,482,482,
1087482,482,482,482,482,482,482,482,482,482,482,482,482,482,482,482,482,482,482,482,482,482,482,482,482,482,482,482,482,482,482,482,
1088482,482,482,482,482,483,483,483,483,483,483,483,483,483,483,483,483,483,483,483,483,483,483,483,483,483,483,483,483,483,483,483,
1089483,483,483,483,483,483,483,483,483,483,483,483,483,483,483,484,484,484,484,484,484,484,484,484,484,484,484,484,484,484,484,484,
1090484,484,484,484,484,484,484,484,484,484,484,484,484,484,484,484,484,484,484,484,484,484,484,484,484,485,485,485,485,485,485,485,
1091485,485,485,485,485,485,485,485,485,485,485,485,485,485,485,485,485,485,485,485,485,485,485,485,485,485,485,485,485,485,485,485,
1092485,485,485,486,486,486,486,486,486,486,486,486,486,486,486,486,486,486,486,486,486,486,486,486,486,486,486,486,486,486,486,486,
1093486,486,486,486,486,486,486,486,486,486,486,486,486,487,487,487,487,487,487,487,487,487,487,487,487,487,487,487,487,487,487,487,
1094487,487,487,487,487,487,487,487,487,487,487,487,487,487,487,487,487,487,487,487,487,487,487,488,488,488,488,488,488,488,488,488,
1095488,488,488,488,488,488,488,488,488,488,488,488,488,488,488,488,488,488,488,488,488,488,488,488,488,488,488,488,488,488,488,488,
1096488,489,489,489,489,489,489,489,489,489,489,489,489,489,489,489,489,489,489,489,489,489,489,489,489,489,489,489,489,489,489,489,
1097489,489,489,489,489,489,489,489,489,489,489,490,490,490,490,490,490,490,490,490,490,490,490,490,490,490,490,490,490,490,490,490,
1098490,490,490,490,490,490,490,490,490,490,490,490,490,490,490,490,490,490,490,490,490,491,491,491,491,491,491,491,491,491,491,491,
1099491,491,491,491,491,491,491,491,491,491,491,491,491,491,491,491,491,491,491,491,491,491,491,491,491,491,491,491,491,491,491,492,
1100492,492,492,492,492,492,492,492,492,492,492,492,492,492,492,492,492,492,492,492,492,492,492,492,492,492,492,492,492,492,492,492,
1101492,492,492,492,492,492,492,492,492,493,493,493,493,493,493,493,493,493,493,493,493,493,493,493,493,493,493,493,493,493,493,493,
1102493,493,493,493,493,493,493,493,493,493,493,493,493,493,493,493,493,493,493,494,494,494,494,494,494,494,494,494,494,494,494,494,
1103494,494,494,494,494,494,494,494,494,494,494,494,494,494,494,494,494,494,494,494,494,494,494,494,494,494,494,494,494,495,495,495,
1104495,495,495,495,495,495,495,495,495,495,495,495,495,495,495,495,495,495,495,495,495,495,495,495,495,495,495,495,495,495,495,495,
1105495,495,495,495,495,495,495,496,496,496,496,496,496,496,496,496,496,496,496,496,496,496,496,496,496,496,496,496,496,496,496,496,
1106496,496,496,496,496,496,496,496,496,496,496,496,496,496,496,496,496,496,497,497,497,497,497,497,497,497,497,497,497,497,497,497,
1107497,497,497,497,497,497,497,497,497,497,497,497,497,497,497,497,497,497,497,497,497,497,497,497,497,497,497,497,498,498,498,498,
1108498,498,498,498,498,498,498,498,498,498,498,498,498,498,498,498,498,498,498,498,498,498,498,498,498,498,498,498,498,498,498,498,
1109498,498,498,498,498,498,499,499,499,499,499,499,499,499,499,499,499,499,499,499,499,499,499,499,499,499,499,499,499,499,499,499,
1110499,499,499,499,499,499,499,499,499,499,499,499,499,499,499,499,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,
1111500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,501,501,501,501,501,
1112501,501,501,501,501,501,501,501,501,501,501,501,501,501,501,501,501,501,501,501,501,501,501,501,501,501,501,501,501,501,501,501,
1113501,501,501,501,501,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,
1114502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,502,503,503,503,503,503,503,503,503,503,503,503,503,503,503,503,503,
1115503,503,503,503,503,503,503,503,503,503,503,503,503,503,503,503,503,503,503,503,503,503,503,503,503,503,504,504,504,504,504,504,
1116504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,504,
1117504,504,504,504,505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,
1118505,505,505,505,505,505,505,505,505,505,505,505,505,505,505,506,506,506,506,506,506,506,506,506,506,506,506,506,506,506,506,506,
1119506,506,506,506,506,506,506,506,506,506,506,506,506,506,506,506,506,506,506,506,506,506,506,506,506,507,507,507,507,507,507,507,
1120507,507,507,507,507,507,507,507,507,507,507,507,507,507,507,507,507,507,507,507,507,507,507,507,507,507,507,507,507,507,507,507,
1121507,507,507,507,508,508,508,508,508,508,508,508,508,508,508,508,508,508,508,508,508,508,508,508,508,508,508,508,508,508,508,508,
1122508,508,508,508,508,508,508,508,508,508,508,508,508,508,509,509,509,509,509,509,509,509,509,509,509,509,509,509,509,509,509,509,
1123509,509,509,509,509,509,509,509,509,509,509,509,509,509,509,509,509,509,509,509,509,509,509,509,509,510,510,510,510,510,510,510,
1124510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,510,
1125510,510,510,510,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,
1126511,511,511,511,511,511,511,511,511,511,511,511,511,511,512,512,512,512,512,512,512,512,512,512,512,512,512,512,512,512,512,512,
1127512,512,512,512,512,512,512,512,512,512,512,512,512,512,512,512,512,512,512,512,512,512,512,512,512,513,513,513,513,513,513,513,
1128513,513,513,513,513,513,513,513,513,513,513,513,513,513,513,513,513,513,513,513,513,513,513,513,513,513,513,513,513,513,513,513,
1129513,513,513,513,514,514,514,514,514,514,514,514,514,514,514,514,514,514,514,514,514,514,514,514,514,514,514,514,514,514,514,514,
1130514,514,514,514,514,514,514,514,514,514,514,514,514,514,515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,
1131515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,515,516,516,516,516,516,516,516,
1132516,516,516,516,516,516,516,516,516,516,516,516,516,516,516,516,516,516,516,516,516,516,516,516,516,516,516,516,516,516,516,516,
1133516,516,516,516,517,517,517,517,517,517,517,517,517,517,517,517,517,517,517,517,517,517,517,517,517,517,517,517,517,517,517,517,
1134517,517,517,517,517,517,517,517,517,517,517,517,517,517,517,518,518,518,518,518,518,518,518,518,518,518,518,518,518,518,518,518,
1135518,518,518,518,518,518,518,518,518,518,518,518,518,518,518,518,518,518,518,518,518,518,518,518,518,518,519,519,519,519,519,519,
1136519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,519,
1137519,519,519,519,520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,
1138520,520,520,520,520,520,520,520,520,520,520,520,520,520,520,521,521,521,521,521,521,521,521,521,521,521,521,521,521,521,521,521,
1139521,521,521,521,521,521,521,521,521,521,521,521,521,521,521,521,521,521,521,521,521,521,521,521,521,521,522,522,522,522,522,522,
1140522,522,522,522,522,522,522,522,522,522,522,522,522,522,522,522,522,522,522,522,522,522,522,522,522,522,522,522,522,522,522,522,
1141522,522,522,522,522,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,
1142523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,523,524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,
1143524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,524,525,525,525,525,525,
1144525,525,525,525,525,525,525,525,525,525,525,525,525,525,525,525,525,525,525,525,525,525,525,525,525,525,525,525,525,525,525,525,
1145525,525,525,525,525,525,526,526,526,526,526,526,526,526,526,526,526,526,526,526,526,526,526,526,526,526,526,526,526,526,526,526,
1146526,526,526,526,526,526,526,526,526,526,526,526,526,526,526,526,526,527,527,527,527,527,527,527,527,527,527,527,527,527,527,527,
1147527,527,527,527,527,527,527,527,527,527,527,527,527,527,527,527,527,527,527,527,527,527,527,527,527,527,527,527,528,528,528,528,
1148528,528,528,528,528,528,528,528,528,528,528,528,528,528,528,528,528,528,528,528,528,528,528,528,528,528,528,528,528,528,528,528,
1149528,528,528,528,528,528,528,529,529,529,529,529,529,529,529,529,529,529,529,529,529,529,529,529,529,529,529,529,529,529,529,529,
1150529,529,529,529,529,529,529,529,529,529,529,529,529,529,529,529,529,529,529,530,530,530,530,530,530,530,530,530,530,530,530,530,
1151530,530,530,530,530,530,530,530,530,530,530,530,530,530,530,530,530,530,530,530,530,530,530,530,530,530,530,530,530,530,531,531,
1152531,531,531,531,531,531,531,531,531,531,531,531,531,531,531,531,531,531,531,531,531,531,531,531,531,531,531,531,531,531,531,531,
1153531,531,531,531,531,531,531,531,531,532,532,532,532,532,532,532,532,532,532,532,532,532,532,532,532,532,532,532,532,532,532,532,
1154532,532,532,532,532,532,532,532,532,532,532,532,532,532,532,532,532,532,532,532,533,533,533,533,533,533,533,533,533,533,533,533,
1155533,533,533,533,533,533,533,533,533,533,533,533,533,533,533,533,533,533,533,533,533,533,533,533,533,533,533,533,533,533,533,534,
1156534,534,534,534,534,534,534,534,534,534,534,534,534,534,534,534,534,534,534,534,534,534,534,534,534,534,534,534,534,534,534,534,
1157534,534,534,534,534,534,534,534,534,534,534,535,535,535,535,535,535,535,535,535,535,535,535,535,535,535,535,535,535,535,535,535,
1158535,535,535,535,535,535,535,535,535,535,535,535,535,535,535,535,535,535,535,535,535,535,536,536,536,536,536,536,536,536,536,536,
1159536,536,536,536,536,536,536,536,536,536,536,536,536,536,536,536,536,536,536,536,536,536,536,536,536,536,536,536,536,536,536,536,
1160536,537,537,537,537,537,537,537,537,537,537,537,537,537,537,537,537,537,537,537,537,537,537,537,537,537,537,537,537,537,537,537,
1161537,537,537,537,537,537,537,537,537,537,537,537,537,538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,
1162538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,538,539,539,539,539,539,539,539,539,
1163539,539,539,539,539,539,539,539,539,539,539,539,539,539,539,539,539,539,539,539,539,539,539,539,539,539,539,539,539,539,539,539,
1164539,539,539,540,540,540,540,540,540,540,540,540,540,540,540,540,540,540,540,540,540,540,540,540,540,540,540,540,540,540,540,540,
1165540,540,540,540,540,540,540,540,540,540,540,540,540,540,540,541,541,541,541,541,541,541,541,541,541,541,541,541,541,541,541,541,
1166541,541,541,541,541,541,541,541,541,541,541,541,541,541,541,541,541,541,541,541,541,541,541,541,541,541,542,542,542,542,542,542,
1167542,542,542,542,542,542,542,542,542,542,542,542,542,542,542,542,542,542,542,542,542,542,542,542,542,542,542,542,542,542,542,542,
1168542,542,542,542,542,542,543,543,543,543,543,543,543,543,543,543,543,543,543,543,543,543,543,543,543,543,543,543,543,543,543,543,
1169543,543,543,543,543,543,543,543,543,543,543,543,543,543,543,543,543,544,544,544,544,544,544,544,544,544,544,544,544,544,544,544,
1170544,544,544,544,544,544,544,544,544,544,544,544,544,544,544,544,544,544,544,544,544,544,544,544,544,544,544,544,544,545,545,545,
1171545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,545,
1172545,545,545,545,545,545,545,545,546,546,546,546,546,546,546,546,546,546,546,546,546,546,546,546,546,546,546,546,546,546,546,546,
1173546,546,546,546,546,546,546,546,546,546,546,546,546,546,546,546,546,546,546,546,547,547,547,547,547,547,547,547,547,547,547,547,
1174547,547,547,547,547,547,547,547,547,547,547,547,547,547,547,547,547,547,547,547,547,547,547,547,547,547,547,547,547,547,547,547,
1175548,548,548,548,548,548,548,548,548,548,548,548,548,548,548,548,548,548,548,548,548,548,548,548,548,548,548,548,548,548,548,548,
1176548,548,548,548,548,548,548,548,548,548,548,549,549,549,549,549,549,549,549,549,549,549,549,549,549,549,549,549,549,549,549,549,
1177549,549,549,549,549,549,549,549,549,549,549,549,549,549,549,549,549,549,549,549,549,549,549,550,550,550,550,550,550,550,550,550,
1178550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,
1179550,550,550,551,551,551,551,551,551,551,551,551,551,551,551,551,551,551,551,551,551,551,551,551,551,551,551,551,551,551,551,551,
1180551,551,551,551,551,551,551,551,551,551,551,551,551,551,552,552,552,552,552,552,552,552,552,552,552,552,552,552,552,552,552,552,
1181552,552,552,552,552,552,552,552,552,552,552,552,552,552,552,552,552,552,552,552,552,552,552,552,552,552,553,553,553,553,553,553,
1182553,553,553,553,553,553,553,553,553,553,553,553,553,553,553,553,553,553,553,553,553,553,553,553,553,553,553,553,553,553,553,553,
1183553,553,553,553,553,553,554,554,554,554,554,554,554,554,554,554,554,554,554,554,554,554,554,554,554,554,554,554,554,554,554,554,
1184554,554,554,554,554,554,554,554,554,554,554,554,554,554,554,554,554,554,555,555,555,555,555,555,555,555,555,555,555,555,555,555,
1185555,555,555,555,555,555,555,555,555,555,555,555,555,555,555,555,555,555,555,555,555,555,555,555,555,555,555,555,555,555,556,556,
1186556,556,556,556,556,556,556,556,556,556,556,556,556,556,556,556,556,556,556,556,556,556,556,556,556,556,556,556,556,556,556,556,
1187556,556,556,556,556,556,556,556,556,557,557,557,557,557,557,557,557,557,557,557,557,557,557,557,557,557,557,557,557,557,557,557,
1188557,557,557,557,557,557,557,557,557,557,557,557,557,557,557,557,557,557,557,557,557,558,558,558,558,558,558,558,558,558,558,558,
1189558,558,558,558,558,558,558,558,558,558,558,558,558,558,558,558,558,558,558,558,558,558,558,558,558,558,558,558,558,558,558,558,
1190558,559,559,559,559,559,559,559,559,559,559,559,559,559,559,559,559,559,559,559,559,559,559,559,559,559,559,559,559,559,559,559,
1191559,559,559,559,559,559,559,559,559,559,559,559,559,560,560,560,560,560,560,560,560,560,560,560,560,560,560,560,560,560,560,560,
1192560,560,560,560,560,560,560,560,560,560,560,560,560,560,560,560,560,560,560,560,560,560,560,560,560,561,561,561,561,561,561,561,
1193561,561,561,561,561,561,561,561,561,561,561,561,561,561,561,561,561,561,561,561,561,561,561,561,561,561,561,561,561,561,561,561,
1194561,561,561,561,561,562,562,562,562,562,562,562,562,562,562,562,562,562,562,562,562,562,562,562,562,562,562,562,562,562,562,562,
1195562,562,562,562,562,562,562,562,562,562,562,562,562,562,562,562,562,563,563,563,563,563,563,563,563,563,563,563,563,563,563,563,
1196563,563,563,563,563,563,563,563,563,563,563,563,563,563,563,563,563,563,563,563,563,563,563,563,563,563,563,563,563,564,564,564,
1197564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,564,
1198564,564,564,564,564,564,564,564,564,565,565,565,565,565,565,565,565,565,565,565,565,565,565,565,565,565,565,565,565,565,565,565,
1199565,565,565,565,565,565,565,565,565,565,565,565,565,565,565,565,565,565,565,565,565,566,566,566,566,566,566,566,566,566,566,566,
1200566,566,566,566,566,566,566,566,566,566,566,566,566,566,566,566,566,566,566,566,566,566,566,566,566,566,566,566,566,566,566,566,
1201566,567,567,567,567,567,567,567,567,567,567,567,567,567,567,567,567,567,567,567,567,567,567,567,567,567,567,567,567,567,567,567,
1202567,567,567,567,567,567,567,567,567,567,567,567,567,567,568,568,568,568,568,568,568,568,568,568,568,568,568,568,568,568,568,568,
1203568,568,568,568,568,568,568,568,568,568,568,568,568,568,568,568,568,568,568,568,568,568,568,568,568,568,569,569,569,569,569,569,
1204569,569,569,569,569,569,569,569,569,569,569,569,569,569,569,569,569,569,569,569,569,569,569,569,569,569,569,569,569,569,569,569,
1205569,569,569,569,569,569,570,570,570,570,570,570,570,570,570,570,570,570,570,570,570,570,570,570,570,570,570,570,570,570,570,570,
1206570,570,570,570,570,570,570,570,570,570,570,570,570,570,570,570,570,570,571,571,571,571,571,571,571,571,571,571,571,571,571,571,
1207571,571,571,571,571,571,571,571,571,571,571,571,571,571,571,571,571,571,571,571,571,571,571,571,571,571,571,571,571,571,572,572,
1208572,572,572,572,572,572,572,572,572,572,572,572,572,572,572,572,572,572,572,572,572,572,572,572,572,572,572,572,572,572,572,572,
1209572,572,572,572,572,572,572,572,572,572,572,573,573,573,573,573,573,573,573,573,573,573,573,573,573,573,573,573,573,573,573,573,
1210573,573,573,573,573,573,573,573,573,573,573,573,573,573,573,573,573,573,573,573,573,573,573,574,574,574,574,574,574,574,574,574,
1211574,574,574,574,574,574,574,574,574,574,574,574,574,574,574,574,574,574,574,574,574,574,574,574,574,574,574,574,574,574,574,574,
1212574,574,574,575,575,575,575,575,575,575,575,575,575,575,575,575,575,575,575,575,575,575,575,575,575,575,575,575,575,575,575,575,
1213575,575,575,575,575,575,575,575,575,575,575,575,575,575,575,575,576,576,576,576,576,576,576,576,576,576,576,576,576,576,576,576,
1214576,576,576,576,576,576,576,576,576,576,576,576,576,576,576,576,576,576,576,576,576,576,576,576,576,576,576,576,577,577,577,577,
1215577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,577,
1216577,577,577,577,577,577,577,577,578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,
1217578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,578,579,579,579,579,579,579,579,579,579,579,579,
1218579,579,579,579,579,579,579,579,579,579,579,579,579,579,579,579,579,579,579,579,579,579,579,579,579,579,579,579,579,579,579,579,
1219579,580,580,580,580,580,580,580,580,580,580,580,580,580,580,580,580,580,580,580,580,580,580,580,580,580,580,580,580,580,580,580,
1220580,580,580,580,580,580,580,580,580,580,580,580,580,580,581,581,581,581,581,581,581,581,581,581,581,581,581,581,581,581,581,581,
1221581,581,581,581,581,581,581,581,581,581,581,581,581,581,581,581,581,581,581,581,581,581,581,581,581,581,582,582,582,582,582,582,
1222582,582,582,582,582,582,582,582,582,582,582,582,582,582,582,582,582,582,582,582,582,582,582,582,582,582,582,582,582,582,582,582,
1223582,582,582,582,582,582,582,583,583,583,583,583,583,583,583,583,583,583,583,583,583,583,583,583,583,583,583,583,583,583,583,583,
1224583,583,583,583,583,583,583,583,583,583,583,583,583,583,583,583,583,583,583,584,584,584,584,584,584,584,584,584,584,584,584,584,
1225584,584,584,584,584,584,584,584,584,584,584,584,584,584,584,584,584,584,584,584,584,584,584,584,584,584,584,584,584,584,584,584,
1226585,585,585,585,585,585,585,585,585,585,585,585,585,585,585,585,585,585,585,585,585,585,585,585,585,585,585,585,585,585,585,585,
1227585,585,585,585,585,585,585,585,585,585,585,585,585,586,586,586,586,586,586,586,586,586,586,586,586,586,586,586,586,586,586,586,
1228586,586,586,586,586,586,586,586,586,586,586,586,586,586,586,586,586,586,586,586,586,586,586,586,586,587,587,587,587,587,587,587,
1229587,587,587,587,587,587,587,587,587,587,587,587,587,587,587,587,587,587,587,587,587,587,587,587,587,587,587,587,587,587,587,587,
1230587,587,587,587,587,587,588,588,588,588,588,588,588,588,588,588,588,588,588,588,588,588,588,588,588,588,588,588,588,588,588,588,
1231588,588,588,588,588,588,588,588,588,588,588,588,588,588,588,588,588,588,588,589,589,589,589,589,589,589,589,589,589,589,589,589,
1232589,589,589,589,589,589,589,589,589,589,589,589,589,589,589,589,589,589,589,589,589,589,589,589,589,589,589,589,589,589,589,590,
1233590,590,590,590,590,590,590,590,590,590,590,590,590,590,590,590,590,590,590,590,590,590,590,590,590,590,590,590,590,590,590,590,
1234590,590,590,590,590,590,590,590,590,590,590,590,591,591,591,591,591,591,591,591,591,591,591,591,591,591,591,591,591,591,591,591,
1235591,591,591,591,591,591,591,591,591,591,591,591,591,591,591,591,591,591,591,591,591,591,591,591,591,592,592,592,592,592,592,592,
1236592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,592,
1237592,592,592,592,592,592,593,593,593,593,593,593,593,593,593,593,593,593,593,593,593,593,593,593,593,593,593,593,593,593,593,593,
1238593,593,593,593,593,593,593,593,593,593,593,593,593,593,593,593,593,593,594,594,594,594,594,594,594,594,594,594,594,594,594,594,
1239594,594,594,594,594,594,594,594,594,594,594,594,594,594,594,594,594,594,594,594,594,594,594,594,594,594,594,594,594,594,594,595,
1240595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,595,
1241595,595,595,595,595,595,595,595,595,595,595,595,596,596,596,596,596,596,596,596,596,596,596,596,596,596,596,596,596,596,596,596,
1242596,596,596,596,596,596,596,596,596,596,596,596,596,596,596,596,596,596,596,596,596,596,596,596,596,597,597,597,597,597,597,597,
1243597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,597,
1244597,597,597,597,597,597,598,598,598,598,598,598,598,598,598,598,598,598,598,598,598,598,598,598,598,598,598,598,598,598,598,598,
1245598,598,598,598,598,598,598,598,598,598,598,598,598,598,598,598,598,598,598,599,599,599,599,599,599,599,599,599,599,599,599,599,
1246599,599,599,599,599,599,599,599,599,599,599,599,599,599,599,599,599,599,599,599,599,599,599,599,599,599,599,599,599,599,599,599,
1247600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,
1248600,600,600,600,600,600,600,600,600,600,600,600,600,601,601,601,601,601,601,601,601,601,601,601,601,601,601,601,601,601,601,601,
1249601,601,601,601,601,601,601,601,601,601,601,601,601,601,601,601,601,601,601,601,601,601,601,601,601,601,602,602,602,602,602,602,
1250602,602,602,602,602,602,602,602,602,602,602,602,602,602,602,602,602,602,602,602,602,602,602,602,602,602,602,602,602,602,602,602,
1251602,602,602,602,602,602,602,603,603,603,603,603,603,603,603,603,603,603,603,603,603,603,603,603,603,603,603,603,603,603,603,603,
1252603,603,603,603,603,603,603,603,603,603,603,603,603,603,603,603,603,603,603,603,604,604,604,604,604,604,604,604,604,604,604,604,
1253604,604,604,604,604,604,604,604,604,604,604,604,604,604,604,604,604,604,604,604,604,604,604,604,604,604,604,604,604,604,604,604,
1254604,605,605,605,605,605,605,605,605,605,605,605,605,605,605,605,605,605,605,605,605,605,605,605,605,605,605,605,605,605,605,605,
1255605,605,605,605,605,605,605,605,605,605,605,605,605,605,606,606,606,606,606,606,606,606,606,606,606,606,606,606,606,606,606,606,
1256606,606,606,606,606,606,606,606,606,606,606,606,606,606,606,606,606,606,606,606,606,606,606,606,606,606,606,607,607,607,607,607,
1257607,607,607,607,607,607,607,607,607,607,607,607,607,607,607,607,607,607,607,607,607,607,607,607,607,607,607,607,607,607,607,607,
1258607,607,607,607,607,607,607,607,608,608,608,608,608,608,608,608,608,608,608,608,608,608,608,608,608,608,608,608,608,608,608,608,
1259608,608,608,608,608,608,608,608,608,608,608,608,608,608,608,608,608,608,608,608,608,609,609,609,609,609,609,609,609,609,609,609,
1260609,609,609,609,609,609,609,609,609,609,609,609,609,609,609,609,609,609,609,609,609,609,609,609,609,609,609,609,609,609,609,609,
1261609,609,609,610,610,610,610,610,610,610,610,610,610,610,610,610,610,610,610,610,610,610,610,610,610,610,610,610,610,610,610,610,
1262610,610,610,610,610,610,610,610,610,610,610,610,610,610,610,610,611,611,611,611,611,611,611,611,611,611,611,611,611,611,611,611,
1263611,611,611,611,611,611,611,611,611,611,611,611,611,611,611,611,611,611,611,611,611,611,611,611,611,611,611,611,611,612,612,612,
1264612,612,612,612,612,612,612,612,612,612,612,612,612,612,612,612,612,612,612,612,612,612,612,612,612,612,612,612,612,612,612,612,
1265612,612,612,612,612,612,612,612,612,612,613,613,613,613,613,613,613,613,613,613,613,613,613,613,613,613,613,613,613,613,613,613,
1266613,613,613,613,613,613,613,613,613,613,613,613,613,613,613,613,613,613,613,613,613,613,613,613,614,614,614,614,614,614,614,614,
1267614,614,614,614,614,614,614,614,614,614,614,614,614,614,614,614,614,614,614,614,614,614,614,614,614,614,614,614,614,614,614,614,
1268614,614,614,614,614,615,615,615,615,615,615,615,615,615,615,615,615,615,615,615,615,615,615,615,615,615,615,615,615,615,615,615,
1269615,615,615,615,615,615,615,615,615,615,615,615,615,615,615,615,615,615,616,616,616,616,616,616,616,616,616,616,616,616,616,616,
1270616,616,616,616,616,616,616,616,616,616,616,616,616,616,616,616,616,616,616,616,616,616,616,616,616,616,616,616,616,616,616,616,
1271617,617,617,617,617,617,617,617,617,617,617,617,617,617,617,617,617,617,617,617,617,617,617,617,617,617,617,617,617,617,617,617,
1272617,617,617,617,617,617,617,617,617,617,617,617,617,618,618,618,618,618,618,618,618,618,618,618,618,618,618,618,618,618,618,618,
1273618,618,618,618,618,618,618,618,618,618,618,618,618,618,618,618,618,618,618,618,618,618,618,618,618,618,618,619,619,619,619,619,
1274619,619,619,619,619,619,619,619,619,619,619,619,619,619,619,619,619,619,619,619,619,619,619,619,619,619,619,619,619,619,619,619,
1275619,619,619,619,619,619,619,619,620,620,620,620,620,620,620,620,620,620,620,620,620,620,620,620,620,620,620,620,620,620,620,620,
1276620,620,620,620,620,620,620,620,620,620,620,620,620,620,620,620,620,620,620,620,620,620,621,621,621,621,621,621,621,621,621,621,
1277621,621,621,621,621,621,621,621,621,621,621,621,621,621,621,621,621,621,621,621,621,621,621,621,621,621,621,621,621,621,621,621,
1278621,621,621,622,622,622,622,622,622,622,622,622,622,622,622,622,622,622,622,622,622,622,622,622,622,622,622,622,622,622,622,622,
1279622,622,622,622,622,622,622,622,622,622,622,622,622,622,622,622,622,623,623,623,623,623,623,623,623,623,623,623,623,623,623,623,
1280623,623,623,623,623,623,623,623,623,623,623,623,623,623,623,623,623,623,623,623,623,623,623,623,623,623,623,623,623,623,624,624,
1281624,624,624,624,624,624,624,624,624,624,624,624,624,624,624,624,624,624,624,624,624,624,624,624,624,624,624,624,624,624,624,624,
1282624,624,624,624,624,624,624,624,624,624,624,624,625,625,625,625,625,625,625,625,625,625,625,625,625,625,625,625,625,625,625,625,
1283625,625,625,625,625,625,625,625,625,625,625,625,625,625,625,625,625,625,625,625,625,625,625,625,625,626,626,626,626,626,626,626,
1284626,626,626,626,626,626,626,626,626,626,626,626,626,626,626,626,626,626,626,626,626,626,626,626,626,626,626,626,626,626,626,626,
1285626,626,626,626,626,626,626,627,627,627,627,627,627,627,627,627,627,627,627,627,627,627,627,627,627,627,627,627,627,627,627,627,
1286627,627,627,627,627,627,627,627,627,627,627,627,627,627,627,627,627,627,627,627,627,628,628,628,628,628,628,628,628,628,628,628,
1287628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,628,
1288628,628,629,629,629,629,629,629,629,629,629,629,629,629,629,629,629,629,629,629,629,629,629,629,629,629,629,629,629,629,629,629,
1289629,629,629,629,629,629,629,629,629,629,629,629,629,629,629,629,630,630,630,630,630,630,630,630,630,630,630,630,630,630,630,630,
1290630,630,630,630,630,630,630,630,630,630,630,630,630,630,630,630,630,630,630,630,630,630,630,630,630,630,630,630,630,630,631,631,
1291631,631,631,631,631,631,631,631,631,631,631,631,631,631,631,631,631,631,631,631,631,631,631,631,631,631,631,631,631,631,631,631,
1292631,631,631,631,631,631,631,631,631,631,631,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,
1293632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,633,633,633,633,633,633,633,
1294633,633,633,633,633,633,633,633,633,633,633,633,633,633,633,633,633,633,633,633,633,633,633,633,633,633,633,633,633,633,633,633,
1295633,633,633,633,633,633,633,634,634,634,634,634,634,634,634,634,634,634,634,634,634,634,634,634,634,634,634,634,634,634,634,634,
1296634,634,634,634,634,634,634,634,634,634,634,634,634,634,634,634,634,634,634,634,634,635,635,635,635,635,635,635,635,635,635,635,
1297635,635,635,635,635,635,635,635,635,635,635,635,635,635,635,635,635,635,635,635,635,635,635,635,635,635,635,635,635,635,635,635,
1298635,635,635,636,636,636,636,636,636,636,636,636,636,636,636,636,636,636,636,636,636,636,636,636,636,636,636,636,636,636,636,636,
1299636,636,636,636,636,636,636,636,636,636,636,636,636,636,636,636,636,637,637,637,637,637,637,637,637,637,637,637,637,637,637,637,
1300637,637,637,637,637,637,637,637,637,637,637,637,637,637,637,637,637,637,637,637,637,637,637,637,637,637,637,637,637,637,638,638,
1301638,638,638,638,638,638,638,638,638,638,638,638,638,638,638,638,638,638,638,638,638,638,638,638,638,638,638,638,638,638,638,638,
1302638,638,638,638,638,638,638,638,638,638,638,638,639,639,639,639,639,639,639,639,639,639,639,639,639,639,639,639,639,639,639,639,
1303639,639,639,639,639,639,639,639,639,639,639,639,639,639,639,639,639,639,639,639,639,639,639,639,639,639,640,640,640,640,640,640,
1304640,640,640,640,640,640,640,640,640,640,640,640,640,640,640,640,640,640,640,640,640,640,640,640,640,640,640,640,640,640,640,640,
1305640,640,640,640,640,640,640,640,641,641,641,641,641,641,641,641,641,641,641,641,641,641,641,641,641,641,641,641,641,641,641,641,
1306641,641,641,641,641,641,641,641,641,641,641,641,641,641,641,641,641,641,641,641,641,641,642,642,642,642,642,642,642,642,642,642,
1307642,642,642,642,642,642,642,642,642,642,642,642,642,642,642,642,642,642,642,642,642,642,642,642,642,642,642,642,642,642,642,642,
1308642,642,642,642,643,643,643,643,643,643,643,643,643,643,643,643,643,643,643,643,643,643,643,643,643,643,643,643,643,643,643,643,
1309643,643,643,643,643,643,643,643,643,643,643,643,643,643,643,643,643,643,644,644,644,644,644,644,644,644,644,644,644,644,644,644,
1310644,644,644,644,644,644,644,644,644,644,644,644,644,644,644,644,644,644,644,644,644,644,644,644,644,644,644,644,644,644,644,644,
1311645,645,645,645,645,645,645,645,645,645,645,645,645,645,645,645,645,645,645,645,645,645,645,645,645,645,645,645,645,645,645,645,
1312645,645,645,645,645,645,645,645,645,645,645,645,645,645,646,646,646,646,646,646,646,646,646,646,646,646,646,646,646,646,646,646,
1313646,646,646,646,646,646,646,646,646,646,646,646,646,646,646,646,646,646,646,646,646,646,646,646,646,646,646,646,646,647,647,647,
1314647,647,647,647,647,647,647,647,647,647,647,647,647,647,647,647,647,647,647,647,647,647,647,647,647,647,647,647,647,647,647,647,
1315647,647,647,647,647,647,647,647,647,647,647,648,648,648,648,648,648,648,648,648,648,648,648,648,648,648,648,648,648,648,648,648,
1316648,648,648,648,648,648,648,648,648,648,648,648,648,648,648,648,648,648,648,648,648,648,648,648,648,649,649,649,649,649,649,649,
1317649,649,649,649,649,649,649,649,649,649,649,649,649,649,649,649,649,649,649,649,649,649,649,649,649,649,649,649,649,649,649,649,
1318649,649,649,649,649,649,649,650,650,650,650,650,650,650,650,650,650,650,650,650,650,650,650,650,650,650,650,650,650,650,650,650,
1319650,650,650,650,650,650,650,650,650,650,650,650,650,650,650,650,650,650,650,650,650,651,651,651,651,651,651,651,651,651,651,651,
1320651,651,651,651,651,651,651,651,651,651,651,651,651,651,651,651,651,651,651,651,651,651,651,651,651,651,651,651,651,651,651,651,
1321651,651,651,652,652,652,652,652,652,652,652,652,652,652,652,652,652,652,652,652,652,652,652,652,652,652,652,652,652,652,652,652,
1322652,652,652,652,652,652,652,652,652,652,652,652,652,652,652,652,652,652,653,653,653,653,653,653,653,653,653,653,653,653,653,653,
1323653,653,653,653,653,653,653,653,653,653,653,653,653,653,653,653,653,653,653,653,653,653,653,653,653,653,653,653,653,653,653,653,
1324654,654,654,654,654,654,654,654,654,654,654,654,654,654,654,654,654,654,654,654,654,654,654,654,654,654,654,654,654,654,654,654,
1325654,654,654,654,654,654,654,654,654,654,654,654,654,654,655,655,655,655,655,655,655,655,655,655,655,655,655,655,655,655,655,655,
1326655,655,655,655,655,655,655,655,655,655,655,655,655,655,655,655,655,655,655,655,655,655,655,655,655,655,655,655,655,656,656,656,
1327656,656,656,656,656,656,656,656,656,656,656,656,656,656,656,656,656,656,656,656,656,656,656,656,656,656,656,656,656,656,656,656,
1328656,656,656,656,656,656,656,656,656,656,656,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,
1329657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,657,658,658,658,658,658,658,658,
1330658,658,658,658,658,658,658,658,658,658,658,658,658,658,658,658,658,658,658,658,658,658,658,658,658,658,658,658,658,658,658,658,
1331658,658,658,658,658,658,658,658,659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,
1332659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,659,660,660,660,660,660,660,660,660,660,660,
1333660,660,660,660,660,660,660,660,660,660,660,660,660,660,660,660,660,660,660,660,660,660,660,660,660,660,660,660,660,660,660,660,
1334660,660,660,660,660,661,661,661,661,661,661,661,661,661,661,661,661,661,661,661,661,661,661,661,661,661,661,661,661,661,661,661,
1335661,661,661,661,661,661,661,661,661,661,661,661,661,661,661,661,661,661,661,662,662,662,662,662,662,662,662,662,662,662,662,662,
1336662,662,662,662,662,662,662,662,662,662,662,662,662,662,662,662,662,662,662,662,662,662,662,662,662,662,662,662,662,662,662,662,
1337662,663,663,663,663,663,663,663,663,663,663,663,663,663,663,663,663,663,663,663,663,663,663,663,663,663,663,663,663,663,663,663,
1338663,663,663,663,663,663,663,663,663,663,663,663,663,663,663,663,664,664,664,664,664,664,664,664,664,664,664,664,664,664,664,664,
1339664,664,664,664,664,664,664,664,664,664,664,664,664,664,664,664,664,664,664,664,664,664,664,664,664,664,664,664,664,664,664,665,
1340665,665,665,665,665,665,665,665,665,665,665,665,665,665,665,665,665,665,665,665,665,665,665,665,665,665,665,665,665,665,665,665,
1341665,665,665,665,665,665,665,665,665,665,665,665,665,666,666,666,666,666,666,666,666,666,666,666,666,666,666,666,666,666,666,666,
1342666,666,666,666,666,666,666,666,666,666,666,666,666,666,666,666,666,666,666,666,666,666,666,666,666,666,666,666,667,667,667,667,
1343667,667,667,667,667,667,667,667,667,667,667,667,667,667,667,667,667,667,667,667,667,667,667,667,667,667,667,667,667,667,667,667,
1344667,667,667,667,667,667,667,667,667,667,668,668,668,668,668,668,668,668,668,668,668,668,668,668,668,668,668,668,668,668,668,668,
1345668,668,668,668,668,668,668,668,668,668,668,668,668,668,668,668,668,668,668,668,668,668,668,668,668,669,669,669,669,669,669,669,
1346669,669,669,669,669,669,669,669,669,669,669,669,669,669,669,669,669,669,669,669,669,669,669,669,669,669,669,669,669,669,669,669,
1347669,669,669,669,669,669,669,669,670,670,670,670,670,670,670,670,670,670,670,670,670,670,670,670,670,670,670,670,670,670,670,670,
1348670,670,670,670,670,670,670,670,670,670,670,670,670,670,670,670,670,670,670,670,670,670,671,671,671,671,671,671,671,671,671,671,
1349671,671,671,671,671,671,671,671,671,671,671,671,671,671,671,671,671,671,671,671,671,671,671,671,671,671,671,671,671,671,671,671,
1350671,671,671,671,671,672,672,672,672,672,672,672,672,672,672,672,672,672,672,672,672,672,672,672,672,672,672,672,672,672,672,672,
1351672,672,672,672,672,672,672,672,672,672,672,672,672,672,672,672,672,672,672,672,673,673,673,673,673,673,673,673,673,673,673,673,
1352673,673,673,673,673,673,673,673,673,673,673,673,673,673,673,673,673,673,673,673,673,673,673,673,673,673,673,673,673,673,673,673,
1353673,673,674,674,674,674,674,674,674,674,674,674,674,674,674,674,674,674,674,674,674,674,674,674,674,674,674,674,674,674,674,674,
1354674,674,674,674,674,674,674,674,674,674,674,674,674,674,674,674,674,675,675,675,675,675,675,675,675,675,675,675,675,675,675,675,
1355675,675,675,675,675,675,675,675,675,675,675,675,675,675,675,675,675,675,675,675,675,675,675,675,675,675,675,675,675,675,675,675,
1356676,676,676,676,676,676,676,676,676,676,676,676,676,676,676,676,676,676,676,676,676,676,676,676,676,676,676,676,676,676,676,676,
1357676,676,676,676,676,676,676,676,676,676,676,676,676,676,676,677,677,677,677,677,677,677,677,677,677,677,677,677,677,677,677,677,
1358677,677,677,677,677,677,677,677,677,677,677,677,677,677,677,677,677,677,677,677,677,677,677,677,677,677,677,677,677,677,678,678,
1359678,678,678,678,678,678,678,678,678,678,678,678,678,678,678,678,678,678,678,678,678,678,678,678,678,678,678,678,678,678,678,678,
1360678,678,678,678,678,678,678,678,678,678,678,678,679,679,679,679,679,679,679,679,679,679,679,679,679,679,679,679,679,679,679,679,
1361679,679,679,679,679,679,679,679,679,679,679,679,679,679,679,679,679,679,679,679,679,679,679,679,679,679,679,680,680,680,680,680,
1362680,680,680,680,680,680,680,680,680,680,680,680,680,680,680,680,680,680,680,680,680,680,680,680,680,680,680,680,680,680,680,680,
1363680,680,680,680,680,680,680,680,680,680,681,681,681,681,681,681,681,681,681,681,681,681,681,681,681,681,681,681,681,681,681,681,
1364681,681,681,681,681,681,681,681,681,681,681,681,681,681,681,681,681,681,681,681,681,681,681,681,681,682,682,682,682,682,682,682,
1365682,682,682,682,682,682,682,682,682,682,682,682,682,682,682,682,682,682,682,682,682,682,682,682,682,682,682,682,682,682,682,682,
1366682,682,682,682,682,682,682,682,683,683,683,683,683,683,683,683,683,683,683,683,683,683,683,683,683,683,683,683,683,683,683,683,
1367683,683,683,683,683,683,683,683,683,683,683,683,683,683,683,683,683,683,683,683,683,683,683,684,684,684,684,684,684,684,684,684,
1368684,684,684,684,684,684,684,684,684,684,684,684,684,684,684,684,684,684,684,684,684,684,684,684,684,684,684,684,684,684,684,684,
1369684,684,684,684,684,684,685,685,685,685,685,685,685,685,685,685,685,685,685,685,685,685,685,685,685,685,685,685,685,685,685,685,
1370685,685,685,685,685,685,685,685,685,685,685,685,685,685,685,685,685,685,685,685,685,686,686,686,686,686,686,686,686,686,686,686,
1371686,686,686,686,686,686,686,686,686,686,686,686,686,686,686,686,686,686,686,686,686,686,686,686,686,686,686,686,686,686,686,686,
1372686,686,686,686,687,687,687,687,687,687,687,687,687,687,687,687,687,687,687,687,687,687,687,687,687,687,687,687,687,687,687,687,
1373687,687,687,687,687,687,687,687,687,687,687,687,687,687,687,687,687,687,687,688,688,688,688,688,688,688,688,688,688,688,688,688,
1374688,688,688,688,688,688,688,688,688,688,688,688,688,688,688,688,688,688,688,688,688,688,688,688,688,688,688,688,688,688,688,688,
1375688,688,689,689,689,689,689,689,689,689,689,689,689,689,689,689,689,689,689,689,689,689,689,689,689,689,689,689,689,689,689,689,
1376689,689,689,689,689,689,689,689,689,689,689,689,689,689,689,689,689,690,690,690,690,690,690,690,690,690,690,690,690,690,690,690,
1377690,690,690,690,690,690,690,690,690,690,690,690,690,690,690,690,690,690,690,690,690,690,690,690,690,690,690,690,690,690,690,690,
1378691,691,691,691,691,691,691,691,691,691,691,691,691,691,691,691,691,691,691,691,691,691,691,691,691,691,691,691,691,691,691,691,
1379691,691,691,691,691,691,691,691,691,691,691,691,691,691,691,691,692,692,692,692,692,692,692,692,692,692,692,692,692,692,692,692,
1380692,692,692,692,692,692,692,692,692,692,692,692,692,692,692,692,692,692,692,692,692,692,692,692,692,692,692,692,692,692,692,693,
1381693,693,693,693,693,693,693,693,693,693,693,693,693,693,693,693,693,693,693,693,693,693,693,693,693,693,693,693,693,693,693,693,
1382693,693,693,693,693,693,693,693,693,693,693,693,693,693,694,694,694,694,694,694,694,694,694,694,694,694,694,694,694,694,694,694,
1383694,694,694,694,694,694,694,694,694,694,694,694,694,694,694,694,694,694,694,694,694,694,694,694,694,694,694,694,694,695,695,695,
1384695,695,695,695,695,695,695,695,695,695,695,695,695,695,695,695,695,695,695,695,695,695,695,695,695,695,695,695,695,695,695,695,
1385695,695,695,695,695,695,695,695,695,695,695,695,696,696,696,696,696,696,696,696,696,696,696,696,696,696,696,696,696,696,696,696,
1386696,696,696,696,696,696,696,696,696,696,696,696,696,696,696,696,696,696,696,696,696,696,696,696,696,696,696,696,697,697,697,697,
1387697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,697,
1388697,697,697,697,697,697,697,697,697,697,697,698,698,698,698,698,698,698,698,698,698,698,698,698,698,698,698,698,698,698,698,698,
1389698,698,698,698,698,698,698,698,698,698,698,698,698,698,698,698,698,698,698,698,698,698,698,698,698,698,699,699,699,699,699,699,
1390699,699,699,699,699,699,699,699,699,699,699,699,699,699,699,699,699,699,699,699,699,699,699,699,699,699,699,699,699,699,699,699,
1391699,699,699,699,699,699,699,699,699,699,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,
1392700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,701,701,701,701,701,701,701,
1393701,701,701,701,701,701,701,701,701,701,701,701,701,701,701,701,701,701,701,701,701,701,701,701,701,701,701,701,701,701,701,701,
1394701,701,701,701,701,701,701,701,702,702,702,702,702,702,702,702,702,702,702,702,702,702,702,702,702,702,702,702,702,702,702,702,
1395702,702,702,702,702,702,702,702,702,702,702,702,702,702,702,702,702,702,702,702,702,702,702,702,703,703,703,703,703,703,703,703,
1396703,703,703,703,703,703,703,703,703,703,703,703,703,703,703,703,703,703,703,703,703,703,703,703,703,703,703,703,703,703,703,703,
1397703,703,703,703,703,703,703,704,704,704,704,704,704,704,704,704,704,704,704,704,704,704,704,704,704,704,704,704,704,704,704,704,
1398704,704,704,704,704,704,704,704,704,704,704,704,704,704,704,704,704,704,704,704,704,704,704,705,705,705,705,705,705,705,705,705,
1399705,705,705,705,705,705,705,705,705,705,705,705,705,705,705,705,705,705,705,705,705,705,705,705,705,705,705,705,705,705,705,705,
1400705,705,705,705,705,705,706,706,706,706,706,706,706,706,706,706,706,706,706,706,706,706,706,706,706,706,706,706,706,706,706,706,
1401706,706,706,706,706,706,706,706,706,706,706,706,706,706,706,706,706,706,706,706,706,706,707,707,707,707,707,707,707,707,707,707,
1402707,707,707,707,707,707,707,707,707,707,707,707,707,707,707,707,707,707,707,707,707,707,707,707,707,707,707,707,707,707,707,707,
1403707,707,707,707,707,708,708,708,708,708,708,708,708,708,708,708,708,708,708,708,708,708,708,708,708,708,708,708,708,708,708,708,
1404708,708,708,708,708,708,708,708,708,708,708,708,708,708,708,708,708,708,708,708,708,709,709,709,709,709,709,709,709,709,709,709,
1405709,709,709,709,709,709,709,709,709,709,709,709,709,709,709,709,709,709,709,709,709,709,709,709,709,709,709,709,709,709,709,709,
1406709,709,709,709,710,710,710,710,710,710,710,710,710,710,710,710,710,710,710,710,710,710,710,710,710,710,710,710,710,710,710,710,
1407710,710,710,710,710,710,710,710,710,710,710,710,710,710,710,710,710,710,710,710,711,711,711,711,711,711,711,711,711,711,711,711,
1408711,711,711,711,711,711,711,711,711,711,711,711,711,711,711,711,711,711,711,711,711,711,711,711,711,711,711,711,711,711,711,711,
1409711,711,711,712,712,712,712,712,712,712,712,712,712,712,712,712,712,712,712,712,712,712,712,712,712,712,712,712,712,712,712,712,
1410712,712,712,712,712,712,712,712,712,712,712,712,712,712,712,712,712,712,712,713,713,713,713,713,713,713,713,713,713,713,713,713,
1411713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,
1412713,713,713,714,714,714,714,714,714,714,714,714,714,714,714,714,714,714,714,714,714,714,714,714,714,714,714,714,714,714,714,714,
1413714,714,714,714,714,714,714,714,714,714,714,714,714,714,714,714,714,714,715,715,715,715,715,715,715,715,715,715,715,715,715,715,
1414715,715,715,715,715,715,715,715,715,715,715,715,715,715,715,715,715,715,715,715,715,715,715,715,715,715,715,715,715,715,715,715,
1415715,715,716,716,716,716,716,716,716,716,716,716,716,716,716,716,716,716,716,716,716,716,716,716,716,716,716,716,716,716,716,716,
1416716,716,716,716,716,716,716,716,716,716,716,716,716,716,716,716,716,716,717,717,717,717,717,717,717,717,717,717,717,717,717,717,
1417717,717,717,717,717,717,717,717,717,717,717,717,717,717,717,717,717,717,717,717,717,717,717,717,717,717,717,717,717,717,717,717,
1418717,718,718,718,718,718,718,718,718,718,718,718,718,718,718,718,718,718,718,718,718,718,718,718,718,718,718,718,718,718,718,718,
1419718,718,718,718,718,718,718,718,718,718,718,718,718,718,718,718,718,719,719,719,719,719,719,719,719,719,719,719,719,719,719,719,
1420719,719,719,719,719,719,719,719,719,719,719,719,719,719,719,719,719,719,719,719,719,719,719,719,719,719,719,719,719,719,719,719,
1421719,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,
1422720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,721,721,721,721,721,721,721,721,721,721,721,721,721,721,721,
1423721,721,721,721,721,721,721,721,721,721,721,721,721,721,721,721,721,721,721,721,721,721,721,721,721,721,721,721,721,721,721,721,
1424721,722,722,722,722,722,722,722,722,722,722,722,722,722,722,722,722,722,722,722,722,722,722,722,722,722,722,722,722,722,722,722,
1425722,722,722,722,722,722,722,722,722,722,722,722,722,722,722,722,722,723,723,723,723,723,723,723,723,723,723,723,723,723,723,723,
1426723,723,723,723,723,723,723,723,723,723,723,723,723,723,723,723,723,723,723,723,723,723,723,723,723,723,723,723,723,723,723,723,
1427724,724,724,724,724,724,724,724,724,724,724,724,724,724,724,724,724,724,724,724,724,724,724,724,724,724,724,724,724,724,724,724,
1428724,724,724,724,724,724,724,724,724,724,724,724,724,724,724,724,725,725,725,725,725,725,725,725,725,725,725,725,725,725,725,725,
1429725,725,725,725,725,725,725,725,725,725,725,725,725,725,725,725,725,725,725,725,725,725,725,725,725,725,725,725,725,725,725,725,
1430726,726,726,726,726,726,726,726,726,726,726,726,726,726,726,726,726,726,726,726,726,726,726,726,726,726,726,726,726,726,726,726,
1431726,726,726,726,726,726,726,726,726,726,726,726,726,726,726,726,727,727,727,727,727,727,727,727,727,727,727,727,727,727,727,727,
1432727,727,727,727,727,727,727,727,727,727,727,727,727,727,727,727,727,727,727,727,727,727,727,727,727,727,727,727,727,727,727,727,
1433728,728,728,728,728,728,728,728,728,728,728,728,728,728,728,728,728,728,728,728,728,728,728,728,728,728,728,728,728,728,728,728,
1434728,728,728,728,728,728,728,728,728,728,728,728,728,728,728,728,729,729,729,729,729,729,729,729,729,729,729,729,729,729,729,729,
1435729,729,729,729,729,729,729,729,729,729,729,729,729,729,729,729,729,729,729,729,729,729,729,729,729,729,729,729,729,729,729,729,
1436730,730,730,730,730,730,730,730,730,730,730,730,730,730,730,730,730,730,730,730,730,730,730,730,730,730,730,730,730,730,730,730,
1437730,730,730,730,730,730,730,730,730,730,730,730,730,730,730,730,731,731,731,731,731,731,731,731,731,731,731,731,731,731,731,731,
1438731,731,731,731,731,731,731,731,731,731,731,731,731,731,731,731,731,731,731,731,731,731,731,731,731,731,731,731,731,731,731,731,
1439732,732,732,732,732,732,732,732,732,732,732,732,732,732,732,732,732,732,732,732,732,732,732,732,732,732,732,732,732,732,732,732,
1440732,732,732,732,732,732,732,732,732,732,732,732,732,732,732,732,733,733,733,733,733,733,733,733,733,733,733,733,733,733,733,733,
1441733,733,733,733,733,733,733,733,733,733,733,733,733,733,733,733,733,733,733,733,733,733,733,733,733,733,733,733,733,733,733,733,
1442734,734,734,734,734,734,734,734,734,734,734,734,734,734,734,734,734,734,734,734,734,734,734,734,734,734,734,734,734,734,734,734,
1443734,734,734,734,734,734,734,734,734,734,734,734,734,734,734,734,735,735,735,735,735,735,735,735,735,735,735,735,735,735,735,735,
1444735,735,735,735,735,735,735,735,735,735,735,735,735,735,735,735,735,735,735,735,735,735,735,735,735,735,735,735,735,735,735,735,
1445735,736,736,736,736,736,736,736,736,736,736,736,736,736,736,736,736,736,736,736,736,736,736,736,736,736,736,736,736,736,736,736,
1446736,736,736,736,736,736,736,736,736,736,736,736,736,736,736,736,736,737,737,737,737,737,737,737,737,737,737,737,737,737,737,737,
1447737,737,737,737,737,737,737,737,737,737,737,737,737,737,737,737,737,737,737,737,737,737,737,737,737,737,737,737,737,737,737,737,
1448737,738,738,738,738,738,738,738,738,738,738,738,738,738,738,738,738,738,738,738,738,738,738,738,738,738,738,738,738,738,738,738,
1449738,738,738,738,738,738,738,738,738,738,738,738,738,738,738,738,738,739,739,739,739,739,739,739,739,739,739,739,739,739,739,739,
1450739,739,739,739,739,739,739,739,739,739,739,739,739,739,739,739,739,739,739,739,739,739,739,739,739,739,739,739,739,739,739,739,
1451739,740,740,740,740,740,740,740,740,740,740,740,740,740,740,740,740,740,740,740,740,740,740,740,740,740,740,740,740,740,740,740,
1452740,740,740,740,740,740,740,740,740,740,740,740,740,740,740,740,740,740,741,741,741,741,741,741,741,741,741,741,741,741,741,741,
1453741,741,741,741,741,741,741,741,741,741,741,741,741,741,741,741,741,741,741,741,741,741,741,741,741,741,741,741,741,741,741,741,
1454741,741,742,742,742,742,742,742,742,742,742,742,742,742,742,742,742,742,742,742,742,742,742,742,742,742,742,742,742,742,742,742,
1455742,742,742,742,742,742,742,742,742,742,742,742,742,742,742,742,742,742,743,743,743,743,743,743,743,743,743,743,743,743,743,743,
1456743,743,743,743,743,743,743,743,743,743,743,743,743,743,743,743,743,743,743,743,743,743,743,743,743,743,743,743,743,743,743,743,
1457743,743,744,744,744,744,744,744,744,744,744,744,744,744,744,744,744,744,744,744,744,744,744,744,744,744,744,744,744,744,744,744,
1458744,744,744,744,744,744,744,744,744,744,744,744,744,744,744,744,744,744,744,745,745,745,745,745,745,745,745,745,745,745,745,745,
1459745,745,745,745,745,745,745,745,745,745,745,745,745,745,745,745,745,745,745,745,745,745,745,745,745,745,745,745,745,745,745,745,
1460745,745,745,746,746,746,746,746,746,746,746,746,746,746,746,746,746,746,746,746,746,746,746,746,746,746,746,746,746,746,746,746,
1461746,746,746,746,746,746,746,746,746,746,746,746,746,746,746,746,746,746,746,747,747,747,747,747,747,747,747,747,747,747,747,747,
1462747,747,747,747,747,747,747,747,747,747,747,747,747,747,747,747,747,747,747,747,747,747,747,747,747,747,747,747,747,747,747,747,
1463747,747,747,747,748,748,748,748,748,748,748,748,748,748,748,748,748,748,748,748,748,748,748,748,748,748,748,748,748,748,748,748,
1464748,748,748,748,748,748,748,748,748,748,748,748,748,748,748,748,748,748,748,748,749,749,749,749,749,749,749,749,749,749,749,749,
1465749,749,749,749,749,749,749,749,749,749,749,749,749,749,749,749,749,749,749,749,749,749,749,749,749,749,749,749,749,749,749,749,
1466749,749,749,749,749,750,750,750,750,750,750,750,750,750,750,750,750,750,750,750,750,750,750,750,750,750,750,750,750,750,750,750,
1467750,750,750,750,750,750,750,750,750,750,750,750,750,750,750,750,750,750,750,750,750,751,751,751,751,751,751,751,751,751,751,751,
1468751,751,751,751,751,751,751,751,751,751,751,751,751,751,751,751,751,751,751,751,751,751,751,751,751,751,751,751,751,751,751,751,
1469751,751,751,751,751,751,752,752,752,752,752,752,752,752,752,752,752,752,752,752,752,752,752,752,752,752,752,752,752,752,752,752,
1470752,752,752,752,752,752,752,752,752,752,752,752,752,752,752,752,752,752,752,752,752,752,753,753,753,753,753,753,753,753,753,753,
1471753,753,753,753,753,753,753,753,753,753,753,753,753,753,753,753,753,753,753,753,753,753,753,753,753,753,753,753,753,753,753,753,
1472753,753,753,753,753,753,753,754,754,754,754,754,754,754,754,754,754,754,754,754,754,754,754,754,754,754,754,754,754,754,754,754,
1473754,754,754,754,754,754,754,754,754,754,754,754,754,754,754,754,754,754,754,754,754,754,754,755,755,755,755,755,755,755,755,755,
1474755,755,755,755,755,755,755,755,755,755,755,755,755,755,755,755,755,755,755,755,755,755,755,755,755,755,755,755,755,755,755,755,
1475755,755,755,755,755,755,755,755,756,756,756,756,756,756,756,756,756,756,756,756,756,756,756,756,756,756,756,756,756,756,756,756,
1476756,756,756,756,756,756,756,756,756,756,756,756,756,756,756,756,756,756,756,756,756,756,756,756,757,757,757,757,757,757,757,757,
1477757,757,757,757,757,757,757,757,757,757,757,757,757,757,757,757,757,757,757,757,757,757,757,757,757,757,757,757,757,757,757,757,
1478757,757,757,757,757,757,757,757,757,758,758,758,758,758,758,758,758,758,758,758,758,758,758,758,758,758,758,758,758,758,758,758,
1479758,758,758,758,758,758,758,758,758,758,758,758,758,758,758,758,758,758,758,758,758,758,758,758,758,758,759,759,759,759,759,759,
1480759,759,759,759,759,759,759,759,759,759,759,759,759,759,759,759,759,759,759,759,759,759,759,759,759,759,759,759,759,759,759,759,
1481759,759,759,759,759,759,759,759,759,759,760,760,760,760,760,760,760,760,760,760,760,760,760,760,760,760,760,760,760,760,760,760,
1482760,760,760,760,760,760,760,760,760,760,760,760,760,760,760,760,760,760,760,760,760,760,760,760,760,760,760,761,761,761,761,761,
1483761,761,761,761,761,761,761,761,761,761,761,761,761,761,761,761,761,761,761,761,761,761,761,761,761,761,761,761,761,761,761,761,
1484761,761,761,761,761,761,761,761,761,761,761,761,762,762,762,762,762,762,762,762,762,762,762,762,762,762,762,762,762,762,762,762,
1485762,762,762,762,762,762,762,762,762,762,762,762,762,762,762,762,762,762,762,762,762,762,762,762,762,762,762,762,763,763,763,763,
1486763,763,763,763,763,763,763,763,763,763,763,763,763,763,763,763,763,763,763,763,763,763,763,763,763,763,763,763,763,763,763,763,
1487763,763,763,763,763,763,763,763,763,763,763,763,763,764,764,764,764,764,764,764,764,764,764,764,764,764,764,764,764,764,764,764,
1488764,764,764,764,764,764,764,764,764,764,764,764,764,764,764,764,764,764,764,764,764,764,764,764,764,764,764,764,764,764,765,765,
1489765,765,765,765,765,765,765,765,765,765,765,765,765,765,765,765,765,765,765,765,765,765,765,765,765,765,765,765,765,765,765,765,
1490765,765,765,765,765,765,765,765,765,765,765,765,765,765,765,766,766,766,766,766,766,766,766,766,766,766,766,766,766,766,766,766,
1491766,766,766,766,766,766,766,766,766,766,766,766,766,766,766,766,766,766,766,766,766,766,766,766,766,766,766,766,766,766,766,767,
1492767,767,767,767,767,767,767,767,767,767,767,767,767,767,767,767,767,767,767,767,767,767,767,767,767,767,767,767,767,767,767,767,
1493767,767,767,767,767,767,767,767,767,767,767,767,767,767,767,767,768,768,768,768,768,768,768,768,768,768,768,768,768,768,768,768,
1494768,768,768,768,768,768,768,768,768,768,768,768,768,768,768,768,768,768,768,768,768,768,768,768,768,768,768,768,768,768,768,768,
1495768,769,769,769,769,769,769,769,769,769,769,769,769,769,769,769,769,769,769,769,769,769,769,769,769,769,769,769,769,769,769,769,
1496769,769,769,769,769,769,769,769,769,769,769,769,769,769,769,769,769,769,770,770,770,770,770,770,770,770,770,770,770,770,770,770,
1497770,770,770,770,770,770,770,770,770,770,770,770,770,770,770,770,770,770,770,770,770,770,770,770,770,770,770,770,770,770,770,770,
1498770,770,770,771,771,771,771,771,771,771,771,771,771,771,771,771,771,771,771,771,771,771,771,771,771,771,771,771,771,771,771,771,
1499771,771,771,771,771,771,771,771,771,771,771,771,771,771,771,771,771,771,771,771,772,772,772,772,772,772,772,772,772,772,772,772,
1500772,772,772,772,772,772,772,772,772,772,772,772,772,772,772,772,772,772,772,772,772,772,772,772,772,772,772,772,772,772,772,772,
1501772,772,772,772,772,773,773,773,773,773,773,773,773,773,773,773,773,773,773,773,773,773,773,773,773,773,773,773,773,773,773,773,
1502773,773,773,773,773,773,773,773,773,773,773,773,773,773,773,773,773,773,773,773,773,773,774,774,774,774,774,774,774,774,774,774,
1503774,774,774,774,774,774,774,774,774,774,774,774,774,774,774,774,774,774,774,774,774,774,774,774,774,774,774,774,774,774,774,774,
1504774,774,774,774,774,774,774,775,775,775,775,775,775,775,775,775,775,775,775,775,775,775,775,775,775,775,775,775,775,775,775,775,
1505775,775,775,775,775,775,775,775,775,775,775,775,775,775,775,775,775,775,775,775,775,775,775,775,776,776,776,776,776,776,776,776,
1506776,776,776,776,776,776,776,776,776,776,776,776,776,776,776,776,776,776,776,776,776,776,776,776,776,776,776,776,776,776,776,776,
1507776,776,776,776,776,776,776,776,776,777,777,777,777,777,777,777,777,777,777,777,777,777,777,777,777,777,777,777,777,777,777,777,
1508777,777,777,777,777,777,777,777,777,777,777,777,777,777,777,777,777,777,777,777,777,777,777,777,777,777,778,778,778,778,778,778,
1509778,778,778,778,778,778,778,778,778,778,778,778,778,778,778,778,778,778,778,778,778,778,778,778,778,778,778,778,778,778,778,778,
1510778,778,778,778,778,778,778,778,778,778,778,779,779,779,779,779,779,779,779,779,779,779,779,779,779,779,779,779,779,779,779,779,
1511779,779,779,779,779,779,779,779,779,779,779,779,779,779,779,779,779,779,779,779,779,779,779,779,779,779,779,779,780,780,780,780,
1512780,780,780,780,780,780,780,780,780,780,780,780,780,780,780,780,780,780,780,780,780,780,780,780,780,780,780,780,780,780,780,780,
1513780,780,780,780,780,780,780,780,780,780,780,780,780,781,781,781,781,781,781,781,781,781,781,781,781,781,781,781,781,781,781,781,
1514781,781,781,781,781,781,781,781,781,781,781,781,781,781,781,781,781,781,781,781,781,781,781,781,781,781,781,781,781,781,782,782,
1515782,782,782,782,782,782,782,782,782,782,782,782,782,782,782,782,782,782,782,782,782,782,782,782,782,782,782,782,782,782,782,782,
1516782,782,782,782,782,782,782,782,782,782,782,782,782,782,782,783,783,783,783,783,783,783,783,783,783,783,783,783,783,783,783,783,
1517783,783,783,783,783,783,783,783,783,783,783,783,783,783,783,783,783,783,783,783,783,783,783,783,783,783,783,783,783,783,783,783,
1518784,784,784,784,784,784,784,784,784,784,784,784,784,784,784,784,784,784,784,784,784,784,784,784,784,784,784,784,784,784,784,784,
1519784,784,784,784,784,784,784,784,784,784,784,784,784,784,784,784,784,785,785,785,785,785,785,785,785,785,785,785,785,785,785,785,
1520785,785,785,785,785,785,785,785,785,785,785,785,785,785,785,785,785,785,785,785,785,785,785,785,785,785,785,785,785,785,785,785,
1521785,785,785,786,786,786,786,786,786,786,786,786,786,786,786,786,786,786,786,786,786,786,786,786,786,786,786,786,786,786,786,786,
1522786,786,786,786,786,786,786,786,786,786,786,786,786,786,786,786,786,786,786,786,787,787,787,787,787,787,787,787,787,787,787,787,
1523787,787,787,787,787,787,787,787,787,787,787,787,787,787,787,787,787,787,787,787,787,787,787,787,787,787,787,787,787,787,787,787,
1524787,787,787,787,787,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,
1525788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,788,789,789,789,789,789,789,789,789,789,789,
1526789,789,789,789,789,789,789,789,789,789,789,789,789,789,789,789,789,789,789,789,789,789,789,789,789,789,789,789,789,789,789,789,
1527789,789,789,789,789,789,789,789,790,790,790,790,790,790,790,790,790,790,790,790,790,790,790,790,790,790,790,790,790,790,790,790,
1528790,790,790,790,790,790,790,790,790,790,790,790,790,790,790,790,790,790,790,790,790,790,790,790,790,791,791,791,791,791,791,791,
1529791,791,791,791,791,791,791,791,791,791,791,791,791,791,791,791,791,791,791,791,791,791,791,791,791,791,791,791,791,791,791,791,
1530791,791,791,791,791,791,791,791,791,791,792,792,792,792,792,792,792,792,792,792,792,792,792,792,792,792,792,792,792,792,792,792,
1531792,792,792,792,792,792,792,792,792,792,792,792,792,792,792,792,792,792,792,792,792,792,792,792,792,792,792,792,793,793,793,793,
1532793,793,793,793,793,793,793,793,793,793,793,793,793,793,793,793,793,793,793,793,793,793,793,793,793,793,793,793,793,793,793,793,
1533793,793,793,793,793,793,793,793,793,793,793,793,793,794,794,794,794,794,794,794,794,794,794,794,794,794,794,794,794,794,794,794,
1534794,794,794,794,794,794,794,794,794,794,794,794,794,794,794,794,794,794,794,794,794,794,794,794,794,794,794,794,794,794,795,795,
1535795,795,795,795,795,795,795,795,795,795,795,795,795,795,795,795,795,795,795,795,795,795,795,795,795,795,795,795,795,795,795,795,
1536795,795,795,795,795,795,795,795,795,795,795,795,795,795,795,795,796,796,796,796,796,796,796,796,796,796,796,796,796,796,796,796,
1537796,796,796,796,796,796,796,796,796,796,796,796,796,796,796,796,796,796,796,796,796,796,796,796,796,796,796,796,796,796,796,796,
1538796,797,797,797,797,797,797,797,797,797,797,797,797,797,797,797,797,797,797,797,797,797,797,797,797,797,797,797,797,797,797,797,
1539797,797,797,797,797,797,797,797,797,797,797,797,797,797,797,797,797,797,797,798,798,798,798,798,798,798,798,798,798,798,798,798,
1540798,798,798,798,798,798,798,798,798,798,798,798,798,798,798,798,798,798,798,798,798,798,798,798,798,798,798,798,798,798,798,798,
1541798,798,798,798,799,799,799,799,799,799,799,799,799,799,799,799,799,799,799,799,799,799,799,799,799,799,799,799,799,799,799,799,
1542799,799,799,799,799,799,799,799,799,799,799,799,799,799,799,799,799,799,799,799,799,799,800,800,800,800,800,800,800,800,800,800,
1543800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,
1544800,800,800,800,800,800,800,801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,
1545801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,801,802,802,802,802,802,802,802,
1546802,802,802,802,802,802,802,802,802,802,802,802,802,802,802,802,802,802,802,802,802,802,802,802,802,802,802,802,802,802,802,802,
1547802,802,802,802,802,802,802,802,802,802,803,803,803,803,803,803,803,803,803,803,803,803,803,803,803,803,803,803,803,803,803,803,
1548803,803,803,803,803,803,803,803,803,803,803,803,803,803,803,803,803,803,803,803,803,803,803,803,803,803,803,803,804,804,804,804,
1549804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,804,
1550804,804,804,804,804,804,804,804,804,804,804,804,804,805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,
1551805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,805,806,
1552806,806,806,806,806,806,806,806,806,806,806,806,806,806,806,806,806,806,806,806,806,806,806,806,806,806,806,806,806,806,806,806,
1553806,806,806,806,806,806,806,806,806,806,806,806,806,806,806,806,806,807,807,807,807,807,807,807,807,807,807,807,807,807,807,807,
1554807,807,807,807,807,807,807,807,807,807,807,807,807,807,807,807,807,807,807,807,807,807,807,807,807,807,807,807,807,807,807,807,
1555807,807,808,808,808,808,808,808,808,808,808,808,808,808,808,808,808,808,808,808,808,808,808,808,808,808,808,808,808,808,808,808,
1556808,808,808,808,808,808,808,808,808,808,808,808,808,808,808,808,808,808,808,808,809,809,809,809,809,809,809,809,809,809,809,809,
1557809,809,809,809,809,809,809,809,809,809,809,809,809,809,809,809,809,809,809,809,809,809,809,809,809,809,809,809,809,809,809,809,
1558809,809,809,809,809,809,810,810,810,810,810,810,810,810,810,810,810,810,810,810,810,810,810,810,810,810,810,810,810,810,810,810,
1559810,810,810,810,810,810,810,810,810,810,810,810,810,810,810,810,810,810,810,810,810,810,810,811,811,811,811,811,811,811,811,811,
1560811,811,811,811,811,811,811,811,811,811,811,811,811,811,811,811,811,811,811,811,811,811,811,811,811,811,811,811,811,811,811,811,
1561811,811,811,811,811,811,811,811,811,812,812,812,812,812,812,812,812,812,812,812,812,812,812,812,812,812,812,812,812,812,812,812,
1562812,812,812,812,812,812,812,812,812,812,812,812,812,812,812,812,812,812,812,812,812,812,812,812,812,812,812,813,813,813,813,813,
1563813,813,813,813,813,813,813,813,813,813,813,813,813,813,813,813,813,813,813,813,813,813,813,813,813,813,813,813,813,813,813,813,
1564813,813,813,813,813,813,813,813,813,813,813,813,813,814,814,814,814,814,814,814,814,814,814,814,814,814,814,814,814,814,814,814,
1565814,814,814,814,814,814,814,814,814,814,814,814,814,814,814,814,814,814,814,814,814,814,814,814,814,814,814,814,814,814,815,815,
1566815,815,815,815,815,815,815,815,815,815,815,815,815,815,815,815,815,815,815,815,815,815,815,815,815,815,815,815,815,815,815,815,
1567815,815,815,815,815,815,815,815,815,815,815,815,815,815,815,815,816,816,816,816,816,816,816,816,816,816,816,816,816,816,816,816,
1568816,816,816,816,816,816,816,816,816,816,816,816,816,816,816,816,816,816,816,816,816,816,816,816,816,816,816,816,816,816,816,816,
1569816,816,817,817,817,817,817,817,817,817,817,817,817,817,817,817,817,817,817,817,817,817,817,817,817,817,817,817,817,817,817,817,
1570817,817,817,817,817,817,817,817,817,817,817,817,817,817,817,817,817,817,817,817,818,818,818,818,818,818,818,818,818,818,818,818,
1571818,818,818,818,818,818,818,818,818,818,818,818,818,818,818,818,818,818,818,818,818,818,818,818,818,818,818,818,818,818,818,818,
1572818,818,818,818,818,818,819,819,819,819,819,819,819,819,819,819,819,819,819,819,819,819,819,819,819,819,819,819,819,819,819,819,
1573819,819,819,819,819,819,819,819,819,819,819,819,819,819,819,819,819,819,819,819,819,819,819,819,820,820,820,820,820,820,820,820,
1574820,820,820,820,820,820,820,820,820,820,820,820,820,820,820,820,820,820,820,820,820,820,820,820,820,820,820,820,820,820,820,820,
1575820,820,820,820,820,820,820,820,820,820,821,821,821,821,821,821,821,821,821,821,821,821,821,821,821,821,821,821,821,821,821,821,
1576821,821,821,821,821,821,821,821,821,821,821,821,821,821,821,821,821,821,821,821,821,821,821,821,821,821,821,821,822,822,822,822,
1577822,822,822,822,822,822,822,822,822,822,822,822,822,822,822,822,822,822,822,822,822,822,822,822,822,822,822,822,822,822,822,822,
1578822,822,822,822,822,822,822,822,822,822,822,822,822,822,823,823,823,823,823,823,823,823,823,823,823,823,823,823,823,823,823,823,
1579823,823,823,823,823,823,823,823,823,823,823,823,823,823,823,823,823,823,823,823,823,823,823,823,823,823,823,823,823,823,823,823,
1580824,824,824,824,824,824,824,824,824,824,824,824,824,824,824,824,824,824,824,824,824,824,824,824,824,824,824,824,824,824,824,824,
1581824,824,824,824,824,824,824,824,824,824,824,824,824,824,824,824,824,824,825,825,825,825,825,825,825,825,825,825,825,825,825,825,
1582825,825,825,825,825,825,825,825,825,825,825,825,825,825,825,825,825,825,825,825,825,825,825,825,825,825,825,825,825,825,825,825,
1583825,825,825,825,826,826,826,826,826,826,826,826,826,826,826,826,826,826,826,826,826,826,826,826,826,826,826,826,826,826,826,826,
1584826,826,826,826,826,826,826,826,826,826,826,826,826,826,826,826,826,826,826,826,826,826,827,827,827,827,827,827,827,827,827,827,
1585827,827,827,827,827,827,827,827,827,827,827,827,827,827,827,827,827,827,827,827,827,827,827,827,827,827,827,827,827,827,827,827,
1586827,827,827,827,827,827,827,827,828,828,828,828,828,828,828,828,828,828,828,828,828,828,828,828,828,828,828,828,828,828,828,828,
1587828,828,828,828,828,828,828,828,828,828,828,828,828,828,828,828,828,828,828,828,828,828,828,828,828,828,829,829,829,829,829,829,
1588829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,829,
1589829,829,829,829,829,829,829,829,829,829,829,829,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,
1590830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,830,831,831,
1591831,831,831,831,831,831,831,831,831,831,831,831,831,831,831,831,831,831,831,831,831,831,831,831,831,831,831,831,831,831,831,831,
1592831,831,831,831,831,831,831,831,831,831,831,831,831,831,831,831,832,832,832,832,832,832,832,832,832,832,832,832,832,832,832,832,
1593832,832,832,832,832,832,832,832,832,832,832,832,832,832,832,832,832,832,832,832,832,832,832,832,832,832,832,832,832,832,832,832,
1594832,832,833,833,833,833,833,833,833,833,833,833,833,833,833,833,833,833,833,833,833,833,833,833,833,833,833,833,833,833,833,833,
1595833,833,833,833,833,833,833,833,833,833,833,833,833,833,833,833,833,833,833,833,834,834,834,834,834,834,834,834,834,834,834,834,
1596834,834,834,834,834,834,834,834,834,834,834,834,834,834,834,834,834,834,834,834,834,834,834,834,834,834,834,834,834,834,834,834,
1597834,834,834,834,834,834,834,835,835,835,835,835,835,835,835,835,835,835,835,835,835,835,835,835,835,835,835,835,835,835,835,835,
1598835,835,835,835,835,835,835,835,835,835,835,835,835,835,835,835,835,835,835,835,835,835,835,835,835,836,836,836,836,836,836,836,
1599836,836,836,836,836,836,836,836,836,836,836,836,836,836,836,836,836,836,836,836,836,836,836,836,836,836,836,836,836,836,836,836,
1600836,836,836,836,836,836,836,836,836,836,836,837,837,837,837,837,837,837,837,837,837,837,837,837,837,837,837,837,837,837,837,837,
1601837,837,837,837,837,837,837,837,837,837,837,837,837,837,837,837,837,837,837,837,837,837,837,837,837,837,837,837,837,838,838,838,
1602838,838,838,838,838,838,838,838,838,838,838,838,838,838,838,838,838,838,838,838,838,838,838,838,838,838,838,838,838,838,838,838,
1603838,838,838,838,838,838,838,838,838,838,838,838,838,838,838,838,839,839,839,839,839,839,839,839,839,839,839,839,839,839,839,839,
1604839,839,839,839,839,839,839,839,839,839,839,839,839,839,839,839,839,839,839,839,839,839,839,839,839,839,839,839,839,839,839,839,
1605839,839,840,840,840,840,840,840,840,840,840,840,840,840,840,840,840,840,840,840,840,840,840,840,840,840,840,840,840,840,840,840,
1606840,840,840,840,840,840,840,840,840,840,840,840,840,840,840,840,840,840,840,840,841,841,841,841,841,841,841,841,841,841,841,841,
1607841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,841,
1608841,841,841,841,841,841,841,842,842,842,842,842,842,842,842,842,842,842,842,842,842,842,842,842,842,842,842,842,842,842,842,842,
1609842,842,842,842,842,842,842,842,842,842,842,842,842,842,842,842,842,842,842,842,842,842,842,842,842,843,843,843,843,843,843,843,
1610843,843,843,843,843,843,843,843,843,843,843,843,843,843,843,843,843,843,843,843,843,843,843,843,843,843,843,843,843,843,843,843,
1611843,843,843,843,843,843,843,843,843,843,843,844,844,844,844,844,844,844,844,844,844,844,844,844,844,844,844,844,844,844,844,844,
1612844,844,844,844,844,844,844,844,844,844,844,844,844,844,844,844,844,844,844,844,844,844,844,844,844,844,844,844,844,844,845,845,
1613845,845,845,845,845,845,845,845,845,845,845,845,845,845,845,845,845,845,845,845,845,845,845,845,845,845,845,845,845,845,845,845,
1614845,845,845,845,845,845,845,845,845,845,845,845,845,845,845,845,846,846,846,846,846,846,846,846,846,846,846,846,846,846,846,846,
1615846,846,846,846,846,846,846,846,846,846,846,846,846,846,846,846,846,846,846,846,846,846,846,846,846,846,846,846,846,846,846,846,
1616846,846,846,847,847,847,847,847,847,847,847,847,847,847,847,847,847,847,847,847,847,847,847,847,847,847,847,847,847,847,847,847,
1617847,847,847,847,847,847,847,847,847,847,847,847,847,847,847,847,847,847,847,847,847,848,848,848,848,848,848,848,848,848,848,848,
1618848,848,848,848,848,848,848,848,848,848,848,848,848,848,848,848,848,848,848,848,848,848,848,848,848,848,848,848,848,848,848,848,
1619848,848,848,848,848,848,848,848,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,
1620849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,849,850,850,850,850,850,850,
1621850,850,850,850,850,850,850,850,850,850,850,850,850,850,850,850,850,850,850,850,850,850,850,850,850,850,850,850,850,850,850,850,
1622850,850,850,850,850,850,850,850,850,850,850,850,850,851,851,851,851,851,851,851,851,851,851,851,851,851,851,851,851,851,851,851,
1623851,851,851,851,851,851,851,851,851,851,851,851,851,851,851,851,851,851,851,851,851,851,851,851,851,851,851,851,851,851,851,852,
1624852,852,852,852,852,852,852,852,852,852,852,852,852,852,852,852,852,852,852,852,852,852,852,852,852,852,852,852,852,852,852,852,
1625852,852,852,852,852,852,852,852,852,852,852,852,852,852,852,852,852,852,853,853,853,853,853,853,853,853,853,853,853,853,853,853,
1626853,853,853,853,853,853,853,853,853,853,853,853,853,853,853,853,853,853,853,853,853,853,853,853,853,853,853,853,853,853,853,853,
1627853,853,853,853,854,854,854,854,854,854,854,854,854,854,854,854,854,854,854,854,854,854,854,854,854,854,854,854,854,854,854,854,
1628854,854,854,854,854,854,854,854,854,854,854,854,854,854,854,854,854,854,854,854,854,854,854,855,855,855,855,855,855,855,855,855,
1629855,855,855,855,855,855,855,855,855,855,855,855,855,855,855,855,855,855,855,855,855,855,855,855,855,855,855,855,855,855,855,855,
1630855,855,855,855,855,855,855,855,855,855,856,856,856,856,856,856,856,856,856,856,856,856,856,856,856,856,856,856,856,856,856,856,
1631856,856,856,856,856,856,856,856,856,856,856,856,856,856,856,856,856,856,856,856,856,856,856,856,856,856,856,856,857,857,857,857,
1632857,857,857,857,857,857,857,857,857,857,857,857,857,857,857,857,857,857,857,857,857,857,857,857,857,857,857,857,857,857,857,857,
1633857,857,857,857,857,857,857,857,857,857,857,857,857,857,857,858,858,858,858,858,858,858,858,858,858,858,858,858,858,858,858,858,
1634858,858,858,858,858,858,858,858,858,858,858,858,858,858,858,858,858,858,858,858,858,858,858,858,858,858,858,858,858,858,858,858,
1635858,858,859,859,859,859,859,859,859,859,859,859,859,859,859,859,859,859,859,859,859,859,859,859,859,859,859,859,859,859,859,859,
1636859,859,859,859,859,859,859,859,859,859,859,859,859,859,859,859,859,859,859,859,860,860,860,860,860,860,860,860,860,860,860,860,
1637860,860,860,860,860,860,860,860,860,860,860,860,860,860,860,860,860,860,860,860,860,860,860,860,860,860,860,860,860,860,860,860,
1638860,860,860,860,860,860,860,861,861,861,861,861,861,861,861,861,861,861,861,861,861,861,861,861,861,861,861,861,861,861,861,861 };
1639
1640/* forward declarations */
1641void encodeSideInfo( side_info_t si[2][2] );
1642void Huffmancodebits( uint16 *ix, int *xr, side_info_t *gi );
1643int HuffmanCode(int table_select, uint16 *ix, int *xr);
1644int HuffmanCount1(unsigned tbl, uint16 *ix, int *xr );
1645int new_choose_table( uint16 ix[SAMP_PER_FRAME2], uint32 begin, uint32 end );
1646void putbits(uint32 val, uint32 nbit);
1647int count_bit(uint16 ix[SAMP_PER_FRAME2], uint32 start, uint32 end, uint32 table );
1648int bigv_bitcount(uint16 ix[SAMP_PER_FRAME2], side_info_t *gi);
1649void bigv_tab_select( uint16 ix[SAMP_PER_FRAME2], side_info_t *cod_info );
1650void subdivide(side_info_t *cod_info);
1651void mdct_sub_int(int sb_sample[2][3][18][SBLIMIT], int (*mdct_freq)[2][SAMP_PER_FRAME2]);
1652void filter_subband(int s[SBLIMIT], int off, int k);
1653
1654void putbits(uint32 val, uint32 nbit)
1655{
1656 int new_bitpos = CodedData.bitpos + nbit;
1657 int ptrpos = CodedData.bitpos >> 5;
1658
1659 val = val & (0xffffffff >> (32 - nbit));
1660
1661 /* data fit in one uint32 */
1662 if(((new_bitpos - 1) >> 5) == ptrpos)
1663 CodedData.bbuf[ptrpos] |= val << ((32 - new_bitpos) & 31);
1664 else
1665 {
1666 CodedData.bbuf[ptrpos ] |= val >> ((new_bitpos - 32) & 31);
1667 CodedData.bbuf[ptrpos+1] = val << ((32 - new_bitpos) & 31);
1668 }
1669
1670 CodedData.bitpos = new_bitpos;
1671}
1672
1673/* This is called after a frame of audio has been quantized and coded.
1674 It will write the encoded audio to the bitstream. Note that from a
1675 layer3 encoder's perspective the bit stream is primarily a series
1676 of main_data() blocks, with header and side information inserted at
1677 the proper locations to maintain framing. See Figure A.7 in the IS */
1678void format_bitstream( uint16 enc[2][2][SAMP_PER_FRAME2],
1679 side_info_t side[2][2], int (*xr)[2][SAMP_PER_FRAME2] )
1680{
1681 int gr, ch;
1682
1683 encodeSideInfo( side );
1684
1685 for(gr=0; gr<2; gr++)
1686 for(ch=0; ch<cfg.channels; ch++)
1687 Huffmancodebits( &enc[gr][ch][0], &xr[gr][ch][0], &side[gr][ch] );
1688}
1689
1690void encodeSideInfo( side_info_t si[2][2] )
1691{
1692 int gr, ch, header;
1693
1694 header = 0xfff00000;
1695 header |= cfg.mpg.type << 19; /* mp3 type: 1 */
1696 header |= 1 << 17; /* mp3 layer: 1 */
1697 header |= 1 << 16; /* mp3 crc: 1 */
1698 header |= cfg.mpg.bitrate_index << 12;
1699 header |= cfg.mpg.smprate_index << 10;
1700 header |= cfg.mpg.padding << 9;
1701 header |= cfg.mpg.mode << 6;
1702 header |= 1 << 2; /* mp3 original: 1 */
1703
1704 putbits( header, 32 );
1705 putbits( 0, cfg.channels == 2 ? 20 : 18 );
1706
1707 for(gr=0; gr<2; gr++)
1708 for(ch=0; ch<cfg.channels; ch++)
1709 {
1710 side_info_t *gi = &si[gr][ch];
1711
1712 putbits( gi->part2_3_length, 12 );
1713 putbits( gi->big_values, 9 );
1714 putbits( gi->global_gain, 8 );
1715 putbits( gi->table_select[0], 10 );
1716 putbits( gi->table_select[1], 5 );
1717 putbits( gi->table_select[2], 5 );
1718 putbits( gi->region0_count, 4 );
1719 putbits( gi->region1_count, 3 );
1720 putbits( gi->table_select[3], 3 );
1721 }
1722}
1723
1724/* Note the discussion of huffmancodebits() on pages 28 and 29 of the IS,
1725 as well as the definitions of the side information on pages 26 and 27. */
1726void Huffmancodebits( uint16 *ix, int *xr, side_info_t *gi )
1727{
1728 int region1Start;
1729 int region2Start;
1730 int i, bigvalues, count1End;
1731 int stuffingBits;
1732 int bitsWritten = 0;
1733 uint32 scalefac_index;
1734
1735 /* 1: Write the bigvalues */
1736 bigvalues = gi->big_values << 1;
1737 scalefac_index = gi->region0_count + 1;
1738 region1Start = scalefac[ scalefac_index ];
1739 scalefac_index += gi->region1_count + 1;
1740 region2Start = scalefac[ scalefac_index ];
1741
1742 for(i=0; i<region1Start; i+=2)
1743 bitsWritten += HuffmanCode(gi->table_select[0], ix+i, xr+i);
1744
1745 for( ; i<region2Start; i+=2)
1746 bitsWritten += HuffmanCode(gi->table_select[1], ix+i, xr+i);
1747
1748 for( ; i<bigvalues; i+=2)
1749 bitsWritten += HuffmanCode(gi->table_select[2], ix+i, xr+i);
1750
1751 /* 2: Write count1 area */
1752 count1End = bigvalues + (gi->count1 << 2);
1753 for(i=bigvalues; i<count1End; i+=4)
1754 bitsWritten += HuffmanCount1(gi->table_select[3], ix+i, xr+i);
1755
1756 if((stuffingBits = gi->part2_3_length - bitsWritten) != 0)
1757 {
1758 int stuffingWords = stuffingBits / 32;
1759 int remainingBits = stuffingBits % 32;
1760
1761 if( remainingBits )
1762 putbits( ~0, remainingBits );
1763
1764 /* Due to the nature of the Huffman code tables, we will pad with ones */
1765 while( stuffingWords-- )
1766 putbits( ~0, 32 );
1767
1768 bitsWritten += stuffingBits;
1769 }
1770}
1771
1772int HuffmanCount1(unsigned tbl, uint16 *ix, int *xr)
1773{
1774 uint32 dat, p, s;
1775 int len, v, w, x, y;
1776 #define signv (xr[0] < 0 ? 1 : 0)
1777 #define signw (xr[1] < 0 ? 1 : 0)
1778 #define signx (xr[2] < 0 ? 1 : 0)
1779 #define signy (xr[3] < 0 ? 1 : 0)
1780
1781 v = ix[0];
1782 w = ix[1];
1783 x = ix[2];
1784 y = ix[3];
1785 p = v + (w << 1) + (x << 2) + (y << 3);
1786
1787 switch(p)
1788 {
1789 default: len = 0; s = 0; break;
1790 case 1: len = 1; s = signv; break;
1791 case 2: len = 1; s = signw; break;
1792 case 3: len = 2; s = (signv << 1) + signw; break;
1793 case 4: len = 1; s = signx; break;
1794 case 5: len = 2; s = (signv << 1) + signx; break;
1795 case 6: len = 2; s = (signw << 1) + signx; break;
1796 case 7: len = 3; s = (signv << 2) + (signw << 1) + signx; break;
1797 case 8: len = 1; s = signy; break;
1798 case 9: len = 2; s = (signv << 1) + signy; break;
1799 case 10: len = 2; s = (signw << 1) + signy; break;
1800 case 11: len = 3; s = (signv << 2) + (signw << 1) + signy; break;
1801 case 12: len = 2; s = (signx << 1) + signy; break;
1802 case 13: len = 3; s = (signv << 2) + (signx << 1) + signy; break;
1803 case 14: len = 3; s = (signw << 2) + (signx << 1) + signy; break;
1804 case 15: len = 4; s = (signv << 3) + (signw << 2) + (signx << 1) + signy; break;
1805 }
1806
1807 dat = (ht_count1[tbl][0][p] << len) + s;
1808 len = ht_count1[tbl][1][p];
1809 putbits( dat, len );
1810
1811 return len;
1812}
1813
1814/* Implements the pseudocode of page 98 of the IS */
1815int HuffmanCode(int table_select, uint16 *ix, int *xr)
1816{
1817 unsigned int linbitsx, linbitsy, linbits, idx;
1818 const struct huffcodetab *h;
1819 int x, y, bit;
1820 uint32 code;
1821 #define sign_x (xr[0] < 0 ? 1 : 0)
1822 #define sign_y (xr[1] < 0 ? 1 : 0)
1823
1824 if(table_select == 0)
1825 return 0;
1826
1827 x = ix[0];
1828 y = ix[1];
1829 h = &ht[table_select];
1830 linbits = h->linbits;
1831 linbitsx = linbitsy = 0;
1832
1833 if( table_select > 15 )
1834 { /* ESC-table is used */
1835 if(x > 14) { linbitsx = x - 15; x = 15; }
1836 if(y > 14) { linbitsy = y - 15; y = 15; }
1837
1838 idx = (x * h->ylen) + y;
1839 code = h->table[idx];
1840 bit = h->hlen [idx];
1841
1842 if(x)
1843 {
1844 if(x > 14)
1845 {
1846 code = (code << linbits) | linbitsx;
1847 bit += linbits;
1848 }
1849
1850 code = (code << 1) | sign_x;
1851 bit += 1;
1852 }
1853
1854 if(y)
1855 {
1856 if(y > 14)
1857 {
1858 code = (code << linbits) | linbitsy;
1859 bit += linbits;
1860 }
1861
1862 code = (code << 1) | sign_y;
1863 bit += 1;
1864 }
1865 }
1866 else
1867 { /* No ESC-words */
1868 idx = (x * h->ylen) + y;
1869 code = h->table[idx];
1870 bit = h->hlen [idx];
1871
1872 if(x)
1873 {
1874 code = (code << 1) | sign_x;
1875 bit += 1;
1876 }
1877
1878 if(y)
1879 {
1880 code = (code << 1) | sign_y;
1881 bit += 1;
1882 }
1883 }
1884
1885 putbits( code, bit );
1886
1887 return bit;
1888}
1889
1890/***************************************************************************/
1891/* Choose the Huffman table that will encode ix[begin..end] with */
1892/* the fewest bits. */
1893/* Note: This code contains knowledge about the sizes and characteristic */
1894/* of the Huffman tables as defined in the IS (Table B.7), and will not */
1895/* work with any arbitrary tables. */
1896/***************************************************************************/
1897int new_choose_table( uint16 ix[SAMP_PER_FRAME2], uint32 begin, uint32 end )
1898{
1899 uint32 i;
1900 int max, sum0, sum1, table0, table1;
1901
1902 for(i=begin,max=0; i<end; i++)
1903 if(ix[i] > max)
1904 max = ix[i];
1905
1906 if(!max)
1907 return 0;
1908
1909 table0 = 0;
1910 table1 = 0;
1911
1912 if(max <= 15)
1913 {
1914 /* try tables with no linbits */
1915 /* indx: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 */
1916 /* xlen: 0, 2, 3, 3, 0, 4, 4, 6, 6, 6, 8, 8, 8, 16, 0, 16 */
1917 for(table0=0; table0<14; table0++)
1918 if(ht[table0].xlen > max)
1919 break;
1920
1921 sum0 = count_bit(ix, begin, end, table0);
1922
1923 switch( table0 )
1924 {
1925 case 2: sum1 = count_bit( ix, begin, end, 3 );
1926 if(sum1 <= sum0) table0 = 3; break;
1927
1928 case 5: sum1 = count_bit( ix, begin, end, 6 );
1929 if(sum1 <= sum0) table0 = 6; break;
1930
1931 case 7: sum1 = count_bit( ix, begin, end, 8 );
1932 if(sum1 <= sum0) { table0 = 8; sum0 = sum1; }
1933 sum1 = count_bit( ix, begin, end, 9 );
1934 if(sum1 <= sum0) table0 = 9; break;
1935
1936 case 10: sum1 = count_bit( ix, begin, end, 11 );
1937 if(sum1 <= sum0) { table0 =11; sum0 = sum1; }
1938 sum1 = count_bit( ix, begin, end, 12);
1939 if(sum1 <= sum0) table0 = 12; break;
1940
1941 case 13: sum1 = count_bit( ix, begin, end, 15 );
1942 if(sum1 <= sum0) table0 = 15; break;
1943 }
1944 }
1945 else
1946 {
1947 /* try tables with linbits */
1948 max -= 15;
1949
1950 /* index : 15 16 17 18 19 20 21 22 23 */
1951 /* linmax: 0 1 3 7 15 63 255 1023 8191 */
1952 for(table0=15; table0<24; table0++)
1953 if(ht[table0].linmax >= max)
1954 break;
1955
1956 /* index : 24 25 26 27 28 29 30 31 */
1957 /* linmax: 15 31 63 127 255 511 2047 8191 */
1958 for(table1=24; table1<32; table1++)
1959 if(ht[table1].linmax >= max)
1960 break;
1961
1962 sum0 = count_bit(ix, begin, end, table0);
1963 sum1 = count_bit(ix, begin, end, table1);
1964
1965 if(sum1 < sum0)
1966 table0 = table1;
1967 }
1968 return table0;
1969}
1970
1971/*************************************************************************/
1972/* Function: Count the number of bits necessary to code the subregion. */
1973/*************************************************************************/
1974int count_bit(uint16 ix[SAMP_PER_FRAME2], uint32 start, uint32 end, uint32 table)
1975{
1976 uint32 i;
1977 int sum;
1978 int x, y;
1979 unsigned linbits, ylen;
1980 const struct huffcodetab *h;
1981
1982 h = &ht[table];
1983 sum = 0;
1984 ylen = h->ylen;
1985
1986 if(table > 15)
1987 { // ESC-table is used
1988 linbits = h->linbits;
1989 for(i=start; i<end; i+=2)
1990 {
1991 x = ix[i];
1992 y = ix[i+1];
1993
1994 if(x)
1995 {
1996 if(x > 14) { x = 15; sum += linbits; }
1997 sum++;
1998 }
1999
2000 if(y)
2001 {
2002 if(y > 14) { y = 15; sum += linbits; }
2003 sum++;
2004 }
2005
2006 sum += h->hlen[(x * ylen) + y];
2007 }
2008 }
2009 else
2010 { /* No ESC-words */
2011 for(i=start; i<end; i+=2)
2012 {
2013 x = ix[i];
2014 y = ix[i+1];
2015
2016 sum += h->hlen[(x * ylen) + y];
2017
2018 if(x) sum++;
2019 if(y) sum++;
2020 }
2021 }
2022
2023 return sum;
2024}
2025
2026/*************************************************************************/
2027/* Function: Quantization of the vector xr ( -> ix) */
2028/*************************************************************************/
2029int quantize_int(int xr[SAMP_PER_FRAME2], uint16 ix[SAMP_PER_FRAME2], side_info_t *cod_info)
2030{
2031 uint32 i, ind, step, frac_pow[] = { 0x80000, 0x6ba28, 0x5a828, 0x4c1c0 };
2032
2033 step = frac_pow[cod_info->quantizerStepSize & 3] >> cod_info->quantizerStepSize / 4;
2034
2035 for(i=SAMP_PER_FRAME2; i--; )
2036 {
2037 ind = (abs(xr[i]) * step + 32768) >> 16;
2038
2039 if(ind < 5000)
2040 ix[i] = int2idx[ind];
2041 else
2042 if(ind < 32768)
2043 ix[i] = int3idx[ind];
2044 else
2045 return 0;
2046 }
2047
2048 return 1;
2049}
2050
2051/*************************************************************************/
2052/* Function: Calculation of rzero, count1, big_values */
2053/* (Partitions ix into big values, quadruples and zeros). */
2054/*************************************************************************/
2055int calc_runlen( uint16 ix[SAMP_PER_FRAME2], side_info_t *cod_info )
2056{
2057 int p, i, sum0 = 0, sum1 = 0;
2058
2059 for(i=SAMP_PER_FRAME2; i-=2; )
2060 if(ix[i-1] | ix[i-2])
2061 break;
2062
2063 cod_info->count1 = 0;
2064
2065 for( ; i>3; i-=4)
2066 {
2067 int v = ix[i-1];
2068 int w = ix[i-2];
2069 int x = ix[i-3];
2070 int y = ix[i-4];
2071
2072 if((v | w | x | y) <= 1)
2073 {
2074 p = (y) + (x<<1) + (w<<2) + (v<<3);
2075
2076 sum0 += ht_count1[0][1][p]; /* add table0 hlength */
2077 sum1 += ht_count1[1][1][p]; /* add table1 hlength */
2078
2079 cod_info->count1++;
2080 }
2081 else break;
2082 }
2083
2084 cod_info->big_values = i >> 1;
2085
2086 if(sum0 < sum1)
2087 {
2088 cod_info->table_select[3] = 0;
2089 return sum0;
2090 }
2091 else
2092 {
2093 cod_info->table_select[3] = 1;
2094 return sum1;
2095 }
2096}
2097
2098/*************************************************************************/
2099/* presumable subdivides the bigvalue region which will use separate Huffman tables */
2100/*************************************************************************/
2101void subdivide(side_info_t *cod_info)
2102{
2103 int scfb_anz = 0;
2104 int bigvalues_region;
2105 int thiscount, index;
2106
2107 if( !cod_info->big_values )
2108 { /* no big_values region */
2109 cod_info->region0_count = 0;
2110 cod_info->region1_count = 0;
2111 }
2112 else
2113 {
2114 bigvalues_region = 2 * cod_info->big_values;
2115
2116 /* Calculate scfb_anz */
2117 while( scalefac[scfb_anz] < bigvalues_region )
2118 scfb_anz++;
2119
2120 cod_info->region0_count = subdv_table[scfb_anz].region0_count;
2121 thiscount = cod_info->region0_count;
2122 index = thiscount + 1;
2123 while(thiscount && (scalefac[index] > bigvalues_region))
2124 {
2125 thiscount--;
2126 index--;
2127 }
2128 cod_info->region0_count = thiscount;
2129 cod_info->region1_count = subdv_table[scfb_anz].region1_count;
2130 index = cod_info->region0_count + cod_info->region1_count + 2;
2131 thiscount = cod_info->region1_count;
2132 while(thiscount && (scalefac[index] > bigvalues_region))
2133 {
2134 thiscount--;
2135 index--;
2136 }
2137 cod_info->region1_count = thiscount;
2138 cod_info->address1 = scalefac[cod_info->region0_count+1];
2139 cod_info->address2 = scalefac[cod_info->region0_count+cod_info->region1_count+2];
2140 cod_info->address3 = bigvalues_region;
2141 }
2142}
2143
2144/*************************************************************************/
2145/* Function: Select huffman code tables for bigvalues regions */
2146/*************************************************************************/
2147void bigv_tab_select( uint16 ix[SAMP_PER_FRAME2], side_info_t *cod_info )
2148{
2149 cod_info->table_select[0] = 0;
2150 cod_info->table_select[1] = 0;
2151 cod_info->table_select[2] = 0;
2152
2153 if( cod_info->address1 > 0 )
2154 cod_info->table_select[0] = new_choose_table(ix, 0 , cod_info->address1);
2155
2156 if( cod_info->address2 > cod_info->address1 )
2157 cod_info->table_select[1] = new_choose_table(ix, cod_info->address1, cod_info->address2);
2158
2159 if( cod_info->big_values<<1 > cod_info->address2 )
2160 cod_info->table_select[2] = new_choose_table(ix, cod_info->address2, cod_info->big_values<<1);
2161}
2162
2163/*************************************************************************/
2164/* Function: Count the number of bits necessary to code the bigvalues region */
2165/*************************************************************************/
2166int bigv_bitcount(uint16 ix[SAMP_PER_FRAME2], side_info_t *gi)
2167{
2168 int bits = 0;
2169 uint32 table;
2170
2171 if((table=gi->table_select[0])) /* region0 */
2172 bits += count_bit(ix, 0 , gi->address1, table);
2173
2174 if((table=gi->table_select[1])) /* region1 */
2175 bits += count_bit(ix, gi->address1, gi->address2, table);
2176
2177 if((table=gi->table_select[2])) /* region2 */
2178 bits += count_bit(ix, gi->address2, gi->address3, table);
2179
2180 return bits;
2181}
2182
2183int quantcnt;
2184
2185/* Speed up the outer_loop code which is called by iteration_loop.
2186 The outer_loop function precedes the call to the function inner_loop
2187 with a call to bin_search gain defined below,
2188 which returns a good starting quantizerStepSize. */
2189int quantize_and_count_bits(int xr[SAMP_PER_FRAME2], uint16 ix[SAMP_PER_FRAME2], side_info_t *cod_info)
2190{
2191 int bits = 10000;
2192
2193 quantcnt++;
2194
2195 if(quantize_int(xr, ix, cod_info))
2196 {
2197 bits = calc_runlen(ix, cod_info); /* rzero,count1,big_values*/
2198 subdivide(cod_info); /* bigvalues sfb division */
2199 bigv_tab_select(ix,cod_info); /* codebook selection*/
2200 bits += bigv_bitcount(ix,cod_info); /* bit count */
2201 }
2202
2203 return bits;
2204}
2205
2206/******************************************************************************/
2207/* The code selects the best quantizerStepSize for a particular set of scalefacs */
2208/******************************************************************************/
2209int inner_loop_int(int xr[2][2][SAMP_PER_FRAME2], int max_bits, side_info_t *cod_info, int gr, int ch )
2210{
2211 int *xrs; /* int[SAMP_PER_FRAME2] *xr; */
2212 uint16 *ix; /* int[SAMP_PER_FRAME2] *ix; */
2213 int bits;
2214
2215 xrs = &xr[gr][ch][0];
2216 ix = enc_data[gr][ch];
2217
2218 while((bits=quantize_and_count_bits(xrs, ix, cod_info)) < max_bits-64)
2219 {
2220 if(cod_info->quantizerStepSize == 0)
2221 break;
2222
2223 if(cod_info->quantizerStepSize <= 2)
2224 cod_info->quantizerStepSize = 0;
2225 else
2226 cod_info->quantizerStepSize -= 2;
2227 }
2228
2229 while(bits > max_bits)
2230 {
2231 cod_info->quantizerStepSize++;
2232 bits = quantize_and_count_bits(xrs, ix, cod_info);
2233 }
2234
2235 return bits;
2236}
2237
2238/************************************************************************/
2239/* iteration_loop() */
2240/************************************************************************/
2241void iteration_loop(int mdct_freq_org[2][2][SAMP_PER_FRAME2], side_info_t cod_info[2][2], int mean_bits)
2242{
2243 int max_bits;
2244 int ch, gr;
2245 int ResvSize = 0; /* Layer3 bit reservoir: Described in C.1.5.4.2.2 of the IS */
2246
2247 for(gr=2; gr--; )
2248 {
2249 for(ch=cfg.channels; ch--; )
2250 {
2251 /* calculation of number of available bit( per granule ) */
2252 max_bits = mean_bits / cfg.channels;
2253
2254 cod_info[gr][ch].big_values = 0;
2255 cod_info[gr][ch].count1 = 0;
2256 cod_info[gr][ch].table_select[0] = 0;
2257 cod_info[gr][ch].table_select[1] = 0;
2258 cod_info[gr][ch].table_select[2] = 0;
2259 cod_info[gr][ch].region0_count = 0;
2260 cod_info[gr][ch].region1_count = 0;
2261 cod_info[gr][ch].table_select[3] = 0;
2262 cod_info[gr][ch].part2_3_length = inner_loop_int(mdct_freq_org, max_bits, &cod_info[gr][ch], gr, ch);
2263 cod_info[gr][ch].global_gain = cod_info[gr][ch].quantizerStepSize + 210 - 0x40;
2264
2265 /* Readjusts the size of the reservoir to reflect the granule's usage */
2266 ResvSize += max_bits - cod_info[gr][ch].part2_3_length;
2267 }
2268 }
2269
2270/* Makes sure that the reservoir size is within limits, possibly by adding
2271 stuffing bits. Note that stuffing bits are added by increasing a granule's
2272 part2_3_length */
2273 cod_info[0][0].part2_3_length += ResvSize;
2274}
2275
2276/*-------------------------------------------------------------------*/
2277/* Function: Calculation of the MDCT */
2278/* In the case of long blocks ( block_type 0,1,3 ) there are */
2279/* 36 coefficents in the time domain and 18 in the frequency */
2280/* domain. */
2281/*-------------------------------------------------------------------*/
2282
2283/* TODO: This MDCT implementation is very crude, and should be replaced by
2284 a completely different algorithm. */
2285void mdct_int( int *in, int *out )
2286{
2287 int m, tmp=0;
2288
2289 for(m=18; m--; )
2290 {
2291#ifdef CPU_COLDFIRE
2292 { int *wint = win_int[m];
2293 int *indat = in;
2294
2295 asm volatile(
2296 "movem.l (%[indat]), %%d0-%%d7\n"
2297 "move.l (%[wint])+, %%a5\n"
2298 "mac.l %%d0, %%a5, (%[wint])+, %%a5, %%acc0\n"
2299 "mac.l %%d1, %%a5, (%[wint])+, %%a5, %%acc0\n"
2300 "mac.l %%d2, %%a5, (%[wint])+, %%a5, %%acc0\n"
2301 "mac.l %%d3, %%a5, (%[wint])+, %%a5, %%acc0\n"
2302 "mac.l %%d4, %%a5, (%[wint])+, %%a5, %%acc0\n"
2303 "mac.l %%d5, %%a5, (%[wint])+, %%a5, %%acc0\n"
2304 "mac.l %%d6, %%a5, (%[wint])+, %%a5, %%acc0\n"
2305 "mac.l %%d7, %%a5, (%[wint])+, %%a5, %%acc0\n"
2306 "movem.l (32,%[indat]), %%d0-%%d7\n"
2307 "mac.l %%d0, %%a5, (%[wint])+, %%a5, %%acc0\n"
2308 "mac.l %%d1, %%a5, (%[wint])+, %%a5, %%acc0\n"
2309 "mac.l %%d2, %%a5, (%[wint])+, %%a5, %%acc0\n"
2310 "mac.l %%d3, %%a5, (%[wint])+, %%a5, %%acc0\n"
2311 "mac.l %%d4, %%a5, (%[wint])+, %%a5, %%acc0\n"
2312 "mac.l %%d5, %%a5, (%[wint])+, %%a5, %%acc0\n"
2313 "mac.l %%d6, %%a5, (%[wint])+, %%a5, %%acc0\n"
2314 "mac.l %%d7, %%a5, (%[wint])+, %%a5, %%acc0\n"
2315 "movem.l (64,%[indat]), %%d0-%%d7\n"
2316 "mac.l %%d0, %%a5, (%[wint])+, %%a5, %%acc0\n"
2317 "mac.l %%d1, %%a5, (%[wint])+, %%a5, %%acc0\n"
2318 "mac.l %%d2, %%a5, (%[wint])+, %%a5, %%acc0\n"
2319 "mac.l %%d3, %%a5, (%[wint])+, %%a5, %%acc0\n"
2320 "mac.l %%d4, %%a5, (%[wint])+, %%a5, %%acc0\n"
2321 "mac.l %%d5, %%a5, (%[wint])+, %%a5, %%acc0\n"
2322 "mac.l %%d6, %%a5, (%[wint])+, %%a5, %%acc0\n"
2323 "mac.l %%d7, %%a5, (%[wint])+, %%a5, %%acc0\n"
2324 "movem.l (96,%[indat]), %%d0-%%d7\n"
2325 "mac.l %%d0, %%a5, (%[wint])+, %%a5, %%acc0\n"
2326 "mac.l %%d1, %%a5, (%[wint])+, %%a5, %%acc0\n"
2327 "mac.l %%d2, %%a5, (%[wint])+, %%a5, %%acc0\n"
2328 "mac.l %%d3, %%a5, (%[wint])+, %%a5, %%acc0\n"
2329 "mac.l %%d4, %%a5, (%[wint])+, %%a5, %%acc0\n"
2330 "mac.l %%d5, %%a5, (%[wint])+, %%a5, %%acc0\n"
2331 "mac.l %%d6, %%a5, (%[wint])+, %%a5, %%acc0\n"
2332 "mac.l %%d7, %%a5, (%[wint])+, %%a5, %%acc0\n"
2333 "movem.l (128,%[indat]), %%d0-%%d3\n"
2334 "mac.l %%d0, %%a5, (%[wint])+, %%a5, %%acc0\n"
2335 "mac.l %%d1, %%a5, (%[wint])+, %%a5, %%acc0\n"
2336 "mac.l %%d2, %%a5, (%[wint])+, %%a5, %%acc0\n"
2337 "mac.l %%d3, %%a5, %%acc0\n"
2338 "movclr.l %%acc0, %[tmp]"
2339 : [wint] "+a" (wint), [tmp] "+r" (tmp) : [indat] "a" (indat)
2340 : "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a5");
2341 }
2342#else
2343 int k;
2344 for(k=36,tmp=0; k--; )
2345 tmp += in[k] * win_int[m][k];
2346#endif
2347 out[m] = (tmp + 16384) >> 15;
2348 }
2349}
2350
2351
2352void mdct_sub_int(int sb_sample[2][3][18][SBLIMIT], int (*mdct_freq)[2][SAMP_PER_FRAME2])
2353{
2354 int (*mdct_enc)[2][32][18] = (int (*)[2][32][18]) mdct_freq;
2355 int ch, gr, band, k, bu, bd;
2356
2357 for(gr=0; gr<2; gr++)
2358 for(ch=cfg.channels; ch--; )
2359 {
2360 /* 576=4*16*9: Compensate for inversion in the analysis filter */
2361 for(band=33; (band-=2)>0; )
2362 for(k=19; (k-=2)>0; )
2363 sb_sample[ch][gr+1][k][band] = -sb_sample[ch][gr+1][k][band];
2364
2365 /* 82944=4*32*648: Perform imdct of 18 previous subband samples + 18 current subband samples */
2366 for(band=32; band--; )
2367 {
2368 for(k=18; k--; )
2369 {
2370 mdct_in[k] = sb_sample[ch][ gr ][k][band];
2371 mdct_in[k+18] = sb_sample[ch][gr+1][k][band];
2372 }
2373
2374 mdct_int(mdct_in, &mdct_enc[gr][ch][band][0]);
2375 }
2376
2377 /* 1024=4*256: Perform aliasing reduction butterfly*/
2378 for(band=31; band--; )
2379 for(k=8; k--; )
2380 {
2381 bu = mdct_enc[gr][ch][band][17-k] * cs_int[k] + mdct_enc[gr][ch][band+1][k] * ca_int[k];
2382 bd = mdct_enc[gr][ch][band+1][k] * cs_int[k] - mdct_enc[gr][ch][band][17-k] * ca_int[k];
2383 mdct_enc[gr][ch][band][17-k] = (bu + 16384) >> 15;
2384 mdct_enc[gr][ch][band+1][k] = (bd + 16384) >> 15;
2385 }
2386 }
2387
2388 /* Save latest granule's subband samples to be used in the next mdct call */
2389 for(ch=cfg.channels ;ch--; )
2390 memcpy(sb_sample[ch][0], sb_sample[ch][2], 18 * 32 * sizeof(int));
2391}
2392
2393void fill_subband(long *buffer, int off)
2394{
2395 long i, t;
2396
2397 /* replace 32 oldest left/right samples with 32 new samples */
2398 if(enc_channels == 2)
2399 {
2400 for(i=32; i--; )
2401 {
2402 t = *buffer++;
2403 x_int0[i+off] = (short)(t >> 16);
2404 x_int1[i+off] = (short)t;
2405 }
2406 }
2407 else
2408 {
2409 for(i=32; i--; )
2410 {
2411 t = *buffer++;
2412 x_int0[i+off] = (short)((((t<<16)>>16) + (t>>16)) >> 1);
2413 }
2414 }
2415}
2416
2417void filter_subband(int s[SBLIMIT], int off, int k)
2418{
2419 short *enwindow = enwindow_int;
2420 int i, tmp = 0;
2421#ifdef CPU_COLDFIRE
2422 int reg_buff[14]; /* register storage buffer */
2423#endif
2424
2425 /* 36864=72*512: shift samples into proper window positions */
2426#ifdef CPU_COLDFIRE
2427 { short *xint = &x_int[k][off];
2428 short *yint = y_int;
2429
2430 asm volatile ("movem.l %%d0/%%d2-%%d7/%%a2-%%a7,%0\n" : "=m" (*(int*)reg_buff));
2431 asm volatile(
2432 "moveq.l #32, %%d0\n"
2433 "move.l %%d0, %[i]\n" /* set loop counter */
2434 "move.l %[xint], %%d0\n" /* d0 = x_int[k] */
2435 "or.l #0x3ff, %%d0\n"
2436 "move.l %%d0, %%mask\n" /* set address mask */
2437 "move.l (%[xint]), %%d4\n" /* d4 = x_int[k][off] */
2438
2439 "loop_start:\n"
2440 "movem.l (%[enwindow]), %%d0-%%d3\n" /* load 4 values */
2441 "mac.w %%d0u, %%d4u, (0x080,%[xint])&, %%d5, %%acc0\n"
2442 "mac.w %%d0l, %%d5u, (0x100,%[xint])&, %%d6, %%acc0\n"
2443 "mac.w %%d1u, %%d6u, (0x180,%[xint])&, %%d7, %%acc0\n"
2444 "mac.w %%d1l, %%d7u, (0x200,%[xint])&, %%a2, %%acc0\n"
2445 "mac.w %%d2u, %%a2u, (0x280,%[xint])&, %%a3, %%acc0\n"
2446 "mac.w %%d2l, %%a3u, (0x300,%[xint])&, %%a4, %%acc0\n"
2447 "mac.w %%d3u, %%a4u, (0x380,%[xint])&, %%a5, %%acc0\n"
2448 "mac.w %%d3l, %%a5u, %%acc0\n"
2449
2450 "movem.l (16,%[enwindow]), %%d0-%%d3\n" /* load 8 values */
2451 "mac.w %%d0u, %%d4l, %%acc1\n"
2452 "mac.w %%d0l, %%d5l, %%acc1\n"
2453 "mac.w %%d1u, %%d6l, %%acc1\n"
2454 "mac.w %%d1l, %%d7l, %%acc1\n"
2455 "mac.w %%d2u, %%a2l, %%acc1\n"
2456 "mac.w %%d2l, %%a3l, %%acc1\n"
2457 "mac.w %%d3u, %%a4l, %%acc1\n"
2458 "addq.l #4, %[xint]\n" /* xint += 2 */
2459 "mac.w %%d3l, %%a5l, (%[xint])&, %%d4, %%acc1\n"
2460
2461 "movclr.l %%acc0, %%d5\n"
2462 "movclr.l %%acc1, %%d6\n"
2463 "move.l #262144, %%d7\n"
2464 "add.l %%d7, %%d5\n"
2465 "add.l %%d7, %%d6\n"
2466 "moveq.l #19, %%d7\n"
2467 "asr.l %%d7, %%d5\n"
2468 "asr.l %%d7, %%d6\n"
2469 "move.w %%d5, (%[yint])+\n"
2470 "move.w %%d6, (%[yint])+\n"
2471
2472 "add.l #32, %[enwindow]\n" /* enwindow += 16 */
2473
2474 "sub.l #1, %[i]\n"
2475 "jbne loop_start\n"
2476
2477 : [xint] "+a" (xint), [yint] "+a" (yint), [i] "+m" (i)
2478 : [enwindow] "a" (enwindow)
2479 : "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a2", "a3", "a4", "a5");
2480
2481 asm volatile ("movem.l %0,%%d0/%%d2-%%d7/%%a2-%%a7\n" : : "m" (*(int*)reg_buff));
2482 }
2483#else
2484 for(i=0; i<64; i++)
2485 {
2486 for(j=0, tmp=0; j<512; j+=64)
2487 tmp += (int)x_int[k][(i+j+off)&(HAN_SIZE-1)] * (int)*(enwindow++);
2488 y_int[i] = (short)((tmp + (1<<18)) >> 19);
2489 }
2490#endif
2491
2492 /* 147456=72*2048 */
2493 for(i=SBLIMIT; i--; ) // SBLIMIT: 32
2494 {
2495 short *filt = filter_int[i];
2496
2497#ifdef CPU_COLDFIRE
2498 {
2499 asm volatile(
2500 "move.l (%[yint])+, %%a5\n"
2501 "movem.l (%[filt]), %%d0-%%d7\n"
2502 "mac.w %%d0u, %%a5u, %%acc0\n"
2503 "mac.w %%d0l, %%a5l, (%[yint])+, %%a5, %%acc0\n"
2504 "mac.w %%d1u, %%a5u, %%acc0\n"
2505 "mac.w %%d1l, %%a5l, (%[yint])+, %%a5, %%acc0\n"
2506 "mac.w %%d2u, %%a5u, %%acc0\n"
2507 "mac.w %%d2l, %%a5l, (%[yint])+, %%a5, %%acc0\n"
2508 "mac.w %%d3u, %%a5u, %%acc0\n"
2509 "mac.w %%d3l, %%a5l, (%[yint])+, %%a5, %%acc0\n"
2510 "mac.w %%d4u, %%a5u, %%acc0\n"
2511 "mac.w %%d4l, %%a5l, (%[yint])+, %%a5, %%acc0\n"
2512 "mac.w %%d5u, %%a5u, %%acc0\n"
2513 "mac.w %%d5l, %%a5l, (%[yint])+, %%a5, %%acc0\n"
2514 "mac.w %%d6u, %%a5u, %%acc0\n"
2515 "mac.w %%d6l, %%a5l, (%[yint])+, %%a5, %%acc0\n"
2516 "mac.w %%d7u, %%a5u, %%acc0\n"
2517 "mac.w %%d7l, %%a5l, (%[yint])+, %%a5, %%acc0\n"
2518 "movem.l (32,%[filt]), %%d0-%%d7\n"
2519 "mac.w %%d0u, %%a5u, %%acc0\n"
2520 "mac.w %%d0l, %%a5l, (%[yint])+, %%a5, %%acc0\n"
2521 "mac.w %%d1u, %%a5u, %%acc0\n"
2522 "mac.w %%d1l, %%a5l, (%[yint])+, %%a5, %%acc0\n"
2523 "mac.w %%d2u, %%a5u, %%acc0\n"
2524 "mac.w %%d2l, %%a5l, (%[yint])+, %%a5, %%acc0\n"
2525 "mac.w %%d3u, %%a5u, %%acc0\n"
2526 "mac.w %%d3l, %%a5l, (%[yint])+, %%a5, %%acc0\n"
2527 "mac.w %%d4u, %%a5u, %%acc0\n"
2528 "mac.w %%d4l, %%a5l, (%[yint])+, %%a5, %%acc0\n"
2529 "mac.w %%d5u, %%a5u, %%acc0\n"
2530 "mac.w %%d5l, %%a5l, (%[yint])+, %%a5, %%acc0\n"
2531 "mac.w %%d6u, %%a5u, %%acc0\n"
2532 "mac.w %%d6l, %%a5l, (%[yint])+, %%a5, %%acc0\n"
2533 "mac.w %%d7u, %%a5u, %%acc0\n"
2534 "mac.w %%d7l, %%a5l, (%[yint])+, %%a5, %%acc0\n"
2535 "movem.l (64,%[filt]), %%d0-%%d7\n"
2536 "mac.w %%d0u, %%a5u, %%acc0\n"
2537 "mac.w %%d0l, %%a5l, (%[yint])+, %%a5, %%acc0\n"
2538 "mac.w %%d1u, %%a5u, %%acc0\n"
2539 "mac.w %%d1l, %%a5l, (%[yint])+, %%a5, %%acc0\n"
2540 "mac.w %%d2u, %%a5u, %%acc0\n"
2541 "mac.w %%d2l, %%a5l, (%[yint])+, %%a5, %%acc0\n"
2542 "mac.w %%d3u, %%a5u, %%acc0\n"
2543 "mac.w %%d3l, %%a5l, (%[yint])+, %%a5, %%acc0\n"
2544 "mac.w %%d4u, %%a5u, %%acc0\n"
2545 "mac.w %%d4l, %%a5l, (%[yint])+, %%a5, %%acc0\n"
2546 "mac.w %%d5u, %%a5u, %%acc0\n"
2547 "mac.w %%d5l, %%a5l, (%[yint])+, %%a5, %%acc0\n"
2548 "mac.w %%d6u, %%a5u, %%acc0\n"
2549 "mac.w %%d6l, %%a5l, (%[yint])+, %%a5, %%acc0\n"
2550 "mac.w %%d7u, %%a5u, %%acc0\n"
2551 "mac.w %%d7l, %%a5l, (%[yint])+, %%a5, %%acc0\n"
2552 "movem.l (96,%[filt]), %%d0-%%d7\n"
2553 "mac.w %%d0u, %%a5u, %%acc0\n"
2554 "mac.w %%d0l, %%a5l, (%[yint])+, %%a5, %%acc0\n"
2555 "mac.w %%d1u, %%a5u, %%acc0\n"
2556 "mac.w %%d1l, %%a5l, (%[yint])+, %%a5, %%acc0\n"
2557 "mac.w %%d2u, %%a5u, %%acc0\n"
2558 "mac.w %%d2l, %%a5l, (%[yint])+, %%a5, %%acc0\n"
2559 "mac.w %%d3u, %%a5u, %%acc0\n"
2560 "mac.w %%d3l, %%a5l, (%[yint])+, %%a5, %%acc0\n"
2561 "mac.w %%d4u, %%a5u, %%acc0\n"
2562 "mac.w %%d4l, %%a5l, (%[yint])+, %%a5, %%acc0\n"
2563 "mac.w %%d5u, %%a5u, %%acc0\n"
2564 "mac.w %%d5l, %%a5l, (%[yint])+, %%a5, %%acc0\n"
2565 "mac.w %%d6u, %%a5u, %%acc0\n"
2566 "mac.w %%d6l, %%a5l, (%[yint]) , %%a5, %%acc0\n"
2567 "mac.w %%d7u, %%a5u, %%acc0\n"
2568 "mac.w %%d7l, %%a5l, %%acc0\n"
2569 "lea.l (-31*4, %[yint]), %[yint]\n" /* wrap yint back to start */
2570 "movclr.l %%acc0, %[tmp]"
2571 : [tmp] "=r" (tmp) : [filt] "a" (filt), [yint] "a" (y_int)
2572 : "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a5" );
2573 }
2574#else
2575 for(j=64, tmp=0; j--; )
2576 tmp += (long)filt[j] * (long)y_int[j];
2577#endif
2578 s[i] = (tmp + 16384) >> 15;
2579 }
2580}
2581
2582static int find_bitrate_index(int bitrate)
2583{
2584 static long mpeg1[15] = {0,32,40,48,56,64,80,96,112,128,160,192,224,256,320};
2585 int i;
2586
2587 for(i=0; i<15; i++)
2588 if(bitrate == mpeg1[i])
2589 return i;
2590
2591 return -1;
2592}
2593
2594static int find_samplerate_index(long freq)
2595{
2596 static long mpeg1[3] = {44100, 48000, 32000};
2597 int i;
2598
2599 for(i=0; i<3; i++)
2600 if(freq == mpeg1[i])
2601 return i;
2602
2603 return -1;
2604}
2605
2606void init_mp3_encoder_engine(bool stereo, int quality)
2607{
2608 /* keep in sync with rec_quality_info_afmt in id3.h/.c */
2609 static int bitr_s[9] = { 64, 96, 128, 160, 192, 224, 320, 64, 64 };
2610 static int bitr_m[9] = { 64, 96, 128, 160, 160, 160, 160, 64, 64 };
2611 uint32 avg_byte_per_frame;
2612
2613 cfg.byte_order = order_bigEndian;
2614 cfg.mpg.type = 1;
2615 cfg.samplerate = 44100;
2616 cfg.channels = stereo ? 2 : 1;
2617 cfg.mpg.mode = stereo ? 0 : 3; /* 0=stereo, 3=mono */
2618 cfg.mpg.bitrate = stereo ? bitr_s[quality] : bitr_m[quality];
2619 cfg.mpg.bitrate_index = find_bitrate_index(cfg.mpg.bitrate);
2620 cfg.mpg.smprate_index = find_samplerate_index(cfg.samplerate);
2621
2622 memset(x_int0 , 0 , sizeof(x_int0 ));
2623 memset(x_int1 , 0 , sizeof(x_int1 ));
2624 memset(y_int , 0 , sizeof(y_int ));
2625 memset(mdct_freq , 0 , sizeof(mdct_freq ));
2626 memset(enc_data , 0 , sizeof(enc_data ));
2627 memset(mdct_in , 0 , sizeof(mdct_in ));
2628 memset(sb_sample , 0 , sizeof(sb_sample ));
2629 memset(&CodedData , 0 , sizeof(CodedData ));
2630 memcpy(scalefac, sfBand[cfg.mpg.smprate_index + 3*cfg.mpg.type], sizeof(scalefac));
2631 memcpy(ca_int , ca_int_const , sizeof(ca_int ));
2632 memcpy(cs_int , cs_int_const , sizeof(cs_int ));
2633 memcpy(win_int , win_int_const , sizeof(win_int ));
2634 memcpy(filter_int , filter_int_const , sizeof(filter_int ));
2635 memcpy(enwindow_int, enwindow_int_const, sizeof(enwindow_int));
2636 memcpy(int2idx , int2idx_const , sizeof(int2idx ));
2637 memcpy(ht_count1 , ht_count1_const , sizeof(ht_count1 ));
2638 memcpy( t1HB , t1HB_const , sizeof(t1HB ));
2639 memcpy( t2HB , t2HB_const , sizeof(t2HB ));
2640 memcpy( t3HB , t3HB_const , sizeof(t3HB ));
2641 memcpy( t5HB , t5HB_const , sizeof(t5HB ));
2642 memcpy( t6HB , t6HB_const , sizeof(t6HB ));
2643 memcpy( t7HB , t7HB_const , sizeof(t7HB ));
2644 memcpy( t8HB , t8HB_const , sizeof(t8HB ));
2645 memcpy( t9HB , t9HB_const , sizeof(t9HB ));
2646 memcpy(t10HB , t10HB_const , sizeof(t10HB ));
2647 memcpy(t11HB , t11HB_const , sizeof(t11HB ));
2648 memcpy(t12HB , t12HB_const , sizeof(t12HB ));
2649 memcpy(t13HB , t13HB_const , sizeof(t13HB ));
2650 memcpy(t15HB , t15HB_const , sizeof(t15HB ));
2651 memcpy(t16HB , t16HB_const , sizeof(t16HB ));
2652 memcpy(t24HB , t24HB_const , sizeof(t24HB ));
2653 memcpy( t1l , t1l_const , sizeof(t1l ));
2654 memcpy( t2l , t2l_const , sizeof(t2l ));
2655 memcpy( t3l , t3l_const , sizeof(t3l ));
2656 memcpy( t5l , t5l_const , sizeof(t5l ));
2657 memcpy( t6l , t6l_const , sizeof(t6l ));
2658 memcpy( t7l , t7l_const , sizeof(t7l ));
2659 memcpy( t8l , t8l_const , sizeof(t8l ));
2660 memcpy( t9l , t9l_const , sizeof(t9l ));
2661 memcpy(t10l , t10l_const , sizeof(t10l ));
2662 memcpy(t11l , t11l_const , sizeof(t11l ));
2663 memcpy(t12l , t12l_const , sizeof(t12l ));
2664 memcpy(t13l , t13l_const , sizeof(t13l ));
2665 memcpy(t15l , t15l_const , sizeof(t15l ));
2666 memcpy(t16l , t16l_const , sizeof(t16l ));
2667 memcpy(t24l , t24l_const , sizeof(t24l ));
2668 memcpy(ht , ht_const , sizeof(ht ));
2669
2670 /* I don't know, wether this is really necessary */
2671 ht[ 0].table = NULL; ht[ 0].hlen = NULL;// Apparently not used
2672 ht[ 1].table = t1HB; ht[ 1].hlen = t1l;
2673 ht[ 2].table = t2HB; ht[ 2].hlen = t2l;
2674 ht[ 3].table = t3HB; ht[ 3].hlen = t3l;
2675 ht[ 4].table = NULL; ht[ 4].hlen = NULL;// Apparently not used
2676 ht[ 5].table = t5HB; ht[ 5].hlen = t5l;
2677 ht[ 6].table = t6HB; ht[ 6].hlen = t6l;
2678 ht[ 7].table = t7HB; ht[ 7].hlen = t7l;
2679 ht[ 8].table = t8HB; ht[ 8].hlen = t8l;
2680 ht[ 9].table = t9HB; ht[ 9].hlen = t9l;
2681 ht[10].table = t10HB; ht[10].hlen = t10l;
2682 ht[11].table = t11HB; ht[11].hlen = t11l;
2683 ht[12].table = t12HB; ht[12].hlen = t12l;
2684 ht[13].table = t13HB; ht[13].hlen = t13l;
2685 ht[14].table = NULL; ht[14].hlen = NULL;// Apparently not used
2686 ht[15].table = t15HB; ht[15].hlen = t15l;
2687 ht[16].table = t16HB; ht[16].hlen = t16l;
2688 ht[17].table = t16HB; ht[17].hlen = t16l;
2689 ht[18].table = t16HB; ht[18].hlen = t16l;
2690 ht[19].table = t16HB; ht[19].hlen = t16l;
2691 ht[20].table = t16HB; ht[20].hlen = t16l;
2692 ht[21].table = t16HB; ht[21].hlen = t16l;
2693 ht[22].table = t16HB; ht[22].hlen = t16l;
2694 ht[23].table = t16HB; ht[23].hlen = t16l;
2695 ht[24].table = t24HB; ht[24].hlen = t24l;
2696 ht[25].table = t24HB; ht[25].hlen = t24l;
2697 ht[26].table = t24HB; ht[26].hlen = t24l;
2698 ht[27].table = t24HB; ht[27].hlen = t24l;
2699 ht[28].table = t24HB; ht[28].hlen = t24l;
2700 ht[29].table = t24HB; ht[29].hlen = t24l;
2701 ht[30].table = t24HB; ht[30].hlen = t24l;
2702 ht[31].table = t24HB; ht[31].hlen = t24l;
2703
2704 x_int[0] = x_int0;
2705 x_int[1] = x_int1;
2706
2707#ifndef SIMULATOR
2708 if(((long)x_int0 | (long)x_int1) & 0x7ff)
2709 return; /* both arrays must be aligned to 0x800 boundary */
2710#endif
2711
2712 if(cfg.channels == 1)
2713 cfg.sideinfo_len = 32 + 136;
2714 else
2715 cfg.sideinfo_len = 32 + 256;
2716
2717 /* Set initial step size */
2718 cfg.cod_info[0][0].quantizerStepSize = 0x10;
2719 cfg.cod_info[0][1].quantizerStepSize = 0x10;
2720 cfg.cod_info[1][0].quantizerStepSize = 0x10;
2721 cfg.cod_info[1][1].quantizerStepSize = 0x10;
2722
2723 /* Figure average number of 'byte' per frame. */
2724 avg_byte_per_frame = (uint32)(SAMP_PER_FRAME * 8000 * cfg.mpg.bitrate) / cfg.samplerate;
2725 cfg.byte_per_frame = avg_byte_per_frame / 64;
2726 cfg.frac_per_frame = avg_byte_per_frame % 64;
2727 cfg.slot_lag = 0;
2728}
2729
2730/* this is the codec entry point */
2731enum codec_status codec_start(struct codec_api* api)
2732{
2733 int i, off=0, gr, channel;
2734 long *buffer;
2735 int chunk_size, num_chunks;
2736 int enc_buffer_size;
2737 int enc_quality;
2738 uint32 *mp3_chunk_ptr;
2739 bool cpu_boosted = true; /* start boosted */
2740
2741 /* Generic codec initialisation */
2742 ci = api;
2743
2744 if(ci->enc_get_inputs == NULL ||
2745 ci->enc_set_parameters == NULL ||
2746 ci->enc_alloc_chunk == NULL ||
2747 ci->enc_free_chunk == NULL ||
2748 ci->enc_wavbuf_near_empty == NULL ||
2749 ci->enc_get_wav_data == NULL ||
2750 ci->enc_set_header_callback == NULL )
2751 return CODEC_ERROR;
2752
2753 ci->cpu_boost(true);
2754
2755 *ci->enc_set_header_callback = NULL;
2756 ci->enc_get_inputs(&enc_buffer_size, &enc_channels, &enc_quality);
2757
2758 init_mp3_encoder_engine(enc_channels == 2, enc_quality);
2759
2760 /* must be 4byte aligned */
2761 chunk_size = (sizeof(long) + cfg.byte_per_frame + 1 + 3) & ~3;
2762 num_chunks = enc_buffer_size / chunk_size;
2763
2764 /* inform the main program about the buffer dimensions */
2765 ci->enc_set_parameters(chunk_size, num_chunks, SAMP_PER_FRAME,
2766 NULL, 0, AFMT_MPA_L3);
2767
2768#ifdef CPU_COLDFIRE
2769 asm volatile ("move.l #0, %macsr"); /* integer mode */
2770#endif
2771
2772 /* main application waits for this flag during encoder loading */
2773 ci->enc_codec_loaded = true;
2774
2775 /* main encoding loop */
2776 while(!ci->stop_codec)
2777 {
2778 while((buffer = (long*)ci->enc_get_wav_data(SAMP_PER_FRAME*4)) != NULL)
2779 {
2780 if(ci->stop_codec)
2781 break;
2782
2783 if(ci->enc_wavbuf_near_empty() == 0)
2784 {
2785 if(!cpu_boosted)
2786 {
2787 ci->cpu_boost(true);
2788 cpu_boosted = true;
2789 }
2790 }
2791
2792 /* encode one mp3 frame in this loop */
2793 CodedData.bitpos = 0;
2794 memset(CodedData.bbuf, 0, sizeof(CodedData.bbuf));
2795
2796 if((cfg.slot_lag += cfg.frac_per_frame) >= 64)
2797 { /* Padding for this frame */
2798 cfg.slot_lag -= 64;
2799 cfg.mpg.padding = 1;
2800 }
2801 else
2802 cfg.mpg.padding = 0;
2803
2804 cfg.mpg.bits_per_frame = 8 * (cfg.byte_per_frame + cfg.mpg.padding);
2805 cfg.mean_bits = (cfg.mpg.bits_per_frame - cfg.sideinfo_len) >> 1;
2806
2807 /* polyphase filtering */
2808 for(gr=0; gr<2; gr++)
2809 {
2810 for(i=0; i<18; i++)
2811 {
2812 fill_subband(buffer, off);
2813
2814 for(channel=cfg.channels; channel--; )
2815 filter_subband(&sb_sample[channel][gr+1][i][0], off, channel);
2816
2817 buffer += 32;
2818 off = (off + 480) & (HAN_SIZE-1); /* offset is modulo HAN_SIZE */
2819 }
2820 }
2821
2822 mdct_sub_int(sb_sample, mdct_freq);
2823
2824 /* bit and noise allocation */
2825 iteration_loop(mdct_freq, cfg.cod_info, cfg.mean_bits);
2826
2827 /* write the frame to the bitstream */
2828 format_bitstream(enc_data, cfg.cod_info, mdct_freq);
2829
2830 /* allocate mp3 chunk, set chunk size, copy chunk to enc_buffer */
2831 mp3_chunk_ptr = (uint32*)ci->enc_alloc_chunk();
2832 mp3_chunk_ptr[0] = (CodedData.bitpos + 7) >> 3;
2833 memcpy(&mp3_chunk_ptr[1], CodedData.bbuf, mp3_chunk_ptr[0]);
2834 ci->enc_free_chunk();
2835 ci->yield();
2836 }
2837
2838 if(ci->enc_wavbuf_near_empty())
2839 {
2840 if(cpu_boosted)
2841 {
2842 ci->cpu_boost(false);
2843 cpu_boosted = false;
2844 }
2845 }
2846 ci->yield();
2847 }
2848
2849 if(cpu_boosted) /* set initial boost state */
2850 ci->cpu_boost(false);
2851
2852 /* reset parameters to initial state */
2853 ci->enc_set_parameters(0, 0, 0, 0, 0, 0);
2854
2855 /* main application waits for this flag during encoder removing */
2856 ci->enc_codec_loaded = false;
2857
2858 return CODEC_OK;
2859}
2860#endif
diff --git a/apps/codecs/wav_enc.c b/apps/codecs/wav_enc.c
new file mode 100644
index 0000000000..5aabb5d8e8
--- /dev/null
+++ b/apps/codecs/wav_enc.c
@@ -0,0 +1,172 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 Antonius Hellmann
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#ifndef SIMULATOR
21
22#include "codeclib.h"
23
24CODEC_HEADER
25
26static struct codec_api *ci;
27static int enc_channels;
28
29#define CHUNK_SIZE 8192
30
31static unsigned char wav_header[44] =
32{'R','I','F','F',0,0,0,0,'W','A','V','E','f','m','t',' ',16,
33 0,0,0,1,0,2,0,0x44,0xac,0,0,0x10,0xb1,2,0,4,0,16,0,'d','a','t','a',0,0,0,0};
34
35static unsigned char wav_header_mono[44] =
36{'R','I','F','F',0,0,0,0,'W','A','V','E','f','m','t',' ',16,
37 0,0,0,1,0,1,0,0x44,0xac,0,0,0x88,0x58,1,0,2,0,16,0,'d','a','t','a',0,0,0,0};
38
39/* update file header info callback function (called by main application) */
40void enc_set_header(void *head_buffer, /* ptr to the file header data */
41 int head_size, /* size of this header data */
42 int num_pcm_samples, /* amount of processed pcm samples */
43 bool is_file_header)
44{
45 int num_file_bytes = num_pcm_samples * 2 * enc_channels;
46
47 if(is_file_header)
48 {
49 /* update file header before file closing */
50 if((int)sizeof(wav_header) < head_size)
51 {
52 /* update wave header size entries: special to WAV format */
53 *(long*)(head_buffer+ 4) = htole32(num_file_bytes + 36);
54 *(long*)(head_buffer+40) = htole32(num_file_bytes);
55 }
56 }
57}
58
59/* main codec entry point */
60enum codec_status codec_start(struct codec_api* api)
61{
62 int i;
63 long lr;
64 unsigned long t;
65 unsigned long *src;
66 unsigned long *dst;
67 int chunk_size, num_chunks, samp_per_chunk;
68 int enc_buffer_size;
69 int enc_quality;
70 bool cpu_boosted = true; /* start boosted */
71
72 ci = api; // copy to global api pointer
73
74 if(ci->enc_get_inputs == NULL ||
75 ci->enc_set_parameters == NULL ||
76 ci->enc_alloc_chunk == NULL ||
77 ci->enc_free_chunk == NULL ||
78 ci->enc_wavbuf_near_empty == NULL ||
79 ci->enc_get_wav_data == NULL ||
80 ci->enc_set_header_callback == NULL )
81 return CODEC_ERROR;
82
83 ci->cpu_boost(true);
84
85 *ci->enc_set_header_callback = enc_set_header;
86 ci->enc_get_inputs(&enc_buffer_size, &enc_channels, &enc_quality);
87
88 /* configure the buffer system */
89 chunk_size = sizeof(long) + CHUNK_SIZE * enc_channels / 2;
90 num_chunks = enc_buffer_size / chunk_size;
91 samp_per_chunk = CHUNK_SIZE / 4;
92
93 /* inform the main program about buffer dimensions and other params */
94 ci->enc_set_parameters(chunk_size, num_chunks, samp_per_chunk,
95 (enc_channels == 2) ? wav_header : wav_header_mono,
96 sizeof(wav_header), AFMT_PCM_WAV);
97
98 /* main application waits for this flag during encoder loading */
99 ci->enc_codec_loaded = true;
100
101 /* main encoding loop */
102 while(!ci->stop_codec)
103 {
104 while((src = (unsigned long*)ci->enc_get_wav_data(CHUNK_SIZE)) != NULL)
105 {
106 if(ci->stop_codec)
107 break;
108
109 if(ci->enc_wavbuf_near_empty() == 0)
110 {
111 if(!cpu_boosted)
112 {
113 ci->cpu_boost(true);
114 cpu_boosted = true;
115 }
116 }
117
118 dst = (unsigned long*)ci->enc_alloc_chunk();
119 *dst++ = CHUNK_SIZE * enc_channels / 2; /* set size info */
120
121 if(enc_channels == 2)
122 {
123 /* swap byte order & copy to destination */
124 for (i=0; i<CHUNK_SIZE/4; i++)
125 {
126 t = *src++;
127 *dst++ = ((t >> 8) & 0xff00ff) | ((t << 8) & 0xff00ff00);
128 }
129 }
130 else
131 {
132 /* mix left/right, swap byte order & copy to destination */
133 for (i=0; i<CHUNK_SIZE/8; i++)
134 {
135 lr = (long)*src++;
136 lr = (((lr<<16)>>16) + (lr>>16)) >> 1; /* left+right */
137 t = (lr << 16);
138 lr = (long)*src++;
139 lr = (((lr<<16)>>16) + (lr>>16)) >> 1; /* left+right */
140 t |= lr & 0xffff;
141 *dst++ = ((t >> 8) & 0xff00ff) | ((t << 8) & 0xff00ff00);
142 }
143 }
144
145 ci->enc_free_chunk();
146 ci->yield();
147 }
148
149 if(ci->enc_wavbuf_near_empty())
150 {
151 if(cpu_boosted)
152 {
153 ci->cpu_boost(false);
154 cpu_boosted = false;
155 }
156 }
157
158 ci->yield();
159 }
160
161 if(cpu_boosted) /* set initial boost state */
162 ci->cpu_boost(false);
163
164 /* reset parameters to initial state */
165 ci->enc_set_parameters(0, 0, 0, 0, 0, 0);
166
167 /* main application waits for this flag during encoder removing */
168 ci->enc_codec_loaded = false;
169
170 return CODEC_OK;
171}
172#endif
diff --git a/apps/codecs/wavpack_enc.c b/apps/codecs/wavpack_enc.c
new file mode 100644
index 0000000000..cde208739f
--- /dev/null
+++ b/apps/codecs/wavpack_enc.c
@@ -0,0 +1,230 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 Antonius Hellmann
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#ifndef SIMULATOR
21
22#include "codeclib.h"
23#include "libwavpack/wavpack.h"
24
25CODEC_HEADER
26
27typedef unsigned long uint32;
28typedef unsigned short uint16;
29typedef unsigned char uint8;
30
31static unsigned char wav_header_ster [46] =
32{33,22,'R','I','F','F',0,0,0,0,'W','A','V','E','f','m','t',' ',16,
33 0,0,0,1,0,2,0,0x44,0xac,0,0,0x10,0xb1,2,0,4,0,16,0,'d','a','t','a',0,0,0,0};
34
35static unsigned char wav_header_mono [46] =
36{33,22,'R','I','F','F',0,0,0,0,'W','A','V','E','f','m','t',' ',16,
37 0,0,0,1,0,1,0,0x44,0xac,0,0,0x88,0x58,1,0,2,0,16,0,'d','a','t','a',0,0,0,0};
38
39static struct codec_api *ci;
40static int enc_channels;
41
42#define CHUNK_SIZE 20000
43
44static long input_buffer[CHUNK_SIZE/2] IBSS_ATTR;
45
46void *memset(void *s, int c, size_t n)
47{
48 return(ci->memset(s,c,n));
49}
50
51void *memcpy(void *dest, const void *src, size_t n)
52{
53 return(ci->memcpy(dest,src,n));
54}
55
56/* update file header info callback function */
57void enc_set_header(void *head_buffer, /* ptr to the file header data */
58 int head_size, /* size of this header data */
59 int num_pcm_sampl, /* amount of processed pcm samples */
60 bool is_file_header) /* update file/chunk header */
61{
62 if(is_file_header)
63 {
64 /* update file header before file closing */
65 if(sizeof(WavpackHeader) + sizeof(wav_header_mono) < (unsigned)head_size)
66 {
67 char* riff_header = (char*)head_buffer + sizeof(WavpackHeader);
68 char* wv_header = (char*)head_buffer + sizeof(wav_header_mono);
69 int num_file_bytes = num_pcm_sampl * 2 * enc_channels;
70 unsigned long ckSize;
71
72 /* RIFF header and WVPK header have to be swapped */
73 /* copy wavpack header to file start position */
74 ci->memcpy(head_buffer, wv_header, sizeof(WavpackHeader));
75 wv_header = head_buffer; /* recalc wavpack header position */
76
77 if(enc_channels == 2)
78 ci->memcpy(riff_header, wav_header_ster, sizeof(wav_header_ster));
79 else
80 ci->memcpy(riff_header, wav_header_mono, sizeof(wav_header_mono));
81
82 /* update the Wavpack header first chunk size & total frame count */
83 ckSize = htole32(((WavpackHeader*)wv_header)->ckSize)
84 + sizeof(wav_header_mono);
85 ((WavpackHeader*)wv_header)->total_samples = htole32(num_pcm_sampl);
86 ((WavpackHeader*)wv_header)->ckSize = htole32(ckSize);
87
88 /* update the RIFF WAV header size entries */
89 *(long*)(riff_header+ 6) = htole32(num_file_bytes + 36);
90 *(long*)(riff_header+42) = htole32(num_file_bytes);
91 }
92 }
93 else
94 {
95 /* update timestamp (block_index) */
96 ((WavpackHeader*)head_buffer)->block_index = htole32(num_pcm_sampl);
97 }
98}
99
100
101enum codec_status codec_start(struct codec_api* api)
102{
103 int i;
104 long t;
105 uint32 *src;
106 uint32 *dst;
107 int chunk_size, num_chunks, samp_per_chunk;
108 int enc_buffer_size;
109 int enc_quality;
110 WavpackConfig config;
111 WavpackContext *wpc;
112 bool cpu_boosted = true; /* start boosted */
113
114 ci = api; // copy to global api pointer
115
116 if(ci->enc_get_inputs == NULL ||
117 ci->enc_set_parameters == NULL ||
118 ci->enc_alloc_chunk == NULL ||
119 ci->enc_free_chunk == NULL ||
120 ci->enc_wavbuf_near_empty == NULL ||
121 ci->enc_get_wav_data == NULL ||
122 ci->enc_set_header_callback == NULL )
123 return CODEC_ERROR;
124
125 ci->cpu_boost(true);
126
127 *ci->enc_set_header_callback = enc_set_header;
128 ci->enc_get_inputs(&enc_buffer_size, &enc_channels, &enc_quality);
129
130 /* configure the buffer system */
131 chunk_size = sizeof(long) + CHUNK_SIZE * enc_channels / 2;
132 num_chunks = enc_buffer_size / chunk_size;
133 samp_per_chunk = CHUNK_SIZE / 4;
134
135 /* inform the main program about buffer dimensions and other params */
136 /* add wav_header_mono as place holder to file start position */
137 /* wav header and wvpk header have to be reordered later */
138 ci->enc_set_parameters(chunk_size, num_chunks, samp_per_chunk,
139 wav_header_mono, sizeof(wav_header_mono),
140 AFMT_WAVPACK);
141
142 wpc = WavpackOpenFileOutput ();
143
144 memset (&config, 0, sizeof (config));
145 config.bits_per_sample = 16;
146 config.bytes_per_sample = 2;
147 config.sample_rate = 44100;
148 config.num_channels = enc_channels;
149
150 if (!WavpackSetConfiguration (wpc, &config, 1))
151 return CODEC_ERROR;
152
153 /* main application waits for this flag during encoder loading */
154 ci->enc_codec_loaded = true;
155
156 /* main encoding loop */
157 while(!ci->stop_codec)
158 {
159 while((src = (uint32*)ci->enc_get_wav_data(CHUNK_SIZE)) != NULL)
160 {
161 if(ci->stop_codec)
162 break;
163
164 if(ci->enc_wavbuf_near_empty() == 0)
165 {
166 if(!cpu_boosted)
167 {
168 ci->cpu_boost(true);
169 cpu_boosted = true;
170 }
171 }
172
173 dst = (uint32*)ci->enc_alloc_chunk() + 1;
174
175 WavpackStartBlock (wpc, (uint8*)dst, (uint8*)dst + CHUNK_SIZE);
176
177 if(enc_channels == 2)
178 {
179 for (i=0; i<CHUNK_SIZE/4; i++)
180 {
181 t = (long)*src++;
182
183 input_buffer[2*i + 0] = t >> 16;
184 input_buffer[2*i + 1] = (short)t;
185 }
186 }
187 else
188 {
189 for (i=0; i<CHUNK_SIZE/4; i++)
190 {
191 t = (long)*src++;
192 t = (((t<<16)>>16) + (t>>16)) >> 1; /* left+right */
193
194 input_buffer[i] = t;
195 }
196 }
197
198 if (!WavpackPackSamples (wpc, input_buffer, CHUNK_SIZE/4))
199 return CODEC_ERROR;
200
201 /* finish the chunk and store chunk size info */
202 dst[-1] = WavpackFinishBlock (wpc);
203
204 ci->enc_free_chunk();
205 ci->yield();
206 }
207
208 if(ci->enc_wavbuf_near_empty())
209 {
210 if(cpu_boosted)
211 {
212 ci->cpu_boost(false);
213 cpu_boosted = false;
214 }
215 }
216 ci->yield();
217 }
218
219 if(cpu_boosted) /* set initial boost state */
220 ci->cpu_boost(false);
221
222 /* reset parameters to initial state */
223 ci->enc_set_parameters(0, 0, 0, 0, 0, 0);
224
225 /* main application waits for this flag during encoder removing */
226 ci->enc_codec_loaded = false;
227
228 return CODEC_OK;
229}
230#endif
diff --git a/apps/filetree.c b/apps/filetree.c
index d3ef1e067d..9d5109ceb9 100644
--- a/apps/filetree.c
+++ b/apps/filetree.c
@@ -445,9 +445,8 @@ int ft_enter(struct tree_context* c)
445 { 445 {
446 set_file(buf, global_settings.fmr_file, MAX_FILENAME); 446 set_file(buf, global_settings.fmr_file, MAX_FILENAME);
447 radio_load_presets(global_settings.fmr_file); 447 radio_load_presets(global_settings.fmr_file);
448 if(get_radio_status() != FMRADIO_PLAYING && 448 if(!in_radio_screen())
449 get_radio_status() != FMRADIO_PAUSED) 449 radio_screen();
450 radio_screen();
451 } 450 }
452 /* 451 /*
453 * Preset outside default folder, we can choose such only 452 * Preset outside default folder, we can choose such only
diff --git a/apps/lang/english.lang b/apps/lang/english.lang
index 3d87c0cd5d..5687c81e59 100644
--- a/apps/lang/english.lang
+++ b/apps/lang/english.lang
@@ -9661,6 +9661,22 @@
9661 *: "Full Path" 9661 *: "Full Path"
9662 </voice> 9662 </voice>
9663</phrase> 9663</phrase>
9664<<<<<<< english.lang
9665<phrase>
9666 id: VOICE_KBIT_PER_SEC
9667 desc: spoken only, for file extension
9668 user:
9669 <source>
9670 *: ""
9671 </source>
9672 <dest>
9673 *: ""
9674 </dest>
9675 <voice>
9676 *: "kilobits per second"
9677 </voice>
9678</phrase>
9679=======
9664<phrase> 9680<phrase>
9665 id: LANG_RECORD_AGC_PRESET 9681 id: LANG_RECORD_AGC_PRESET
9666 desc: automatic gain control in record settings 9682 desc: automatic gain control in record settings
@@ -9778,3 +9794,4 @@
9778 *: "AGC maximum gain" 9794 *: "AGC maximum gain"
9779 </voice> 9795 </voice>
9780</phrase> 9796</phrase>
9797>>>>>>> 1.267
diff --git a/apps/main_menu.c b/apps/main_menu.c
index 04527f9329..4348d52f9e 100644
--- a/apps/main_menu.c
+++ b/apps/main_menu.c
@@ -285,9 +285,31 @@ static bool custom_theme_browse(void)
285 285
286#ifdef HAVE_RECORDING 286#ifdef HAVE_RECORDING
287 287
288static bool rec_menu_recording_screen(void)
289{
290 return recording_screen(false);
291}
292
288static bool recording_settings(void) 293static bool recording_settings(void)
289{ 294{
290 return recording_menu(false); 295 bool ret;
296#ifdef HAVE_FMRADIO_IN
297 int rec_source = global_settings.rec_source;
298#endif
299
300 ret = recording_menu(false);
301
302#ifdef HAVE_FMRADIO_IN
303 if (rec_source != global_settings.rec_source)
304 {
305 if (rec_source == AUDIO_SRC_FMRADIO)
306 radio_stop();
307 /* If AUDIO_SRC_FMRADIO was selected from something else,
308 the recording screen will start the radio */
309 }
310#endif
311
312 return ret;
291} 313}
292 314
293bool rec_menu(void) 315bool rec_menu(void)
@@ -297,7 +319,7 @@ bool rec_menu(void)
297 319
298 /* recording menu */ 320 /* recording menu */
299 static const struct menu_item items[] = { 321 static const struct menu_item items[] = {
300 { ID2P(LANG_RECORDING_MENU), recording_screen }, 322 { ID2P(LANG_RECORDING_MENU), rec_menu_recording_screen },
301 { ID2P(LANG_RECORDING_SETTINGS), recording_settings}, 323 { ID2P(LANG_RECORDING_SETTINGS), recording_settings},
302 }; 324 };
303 325
diff --git a/apps/playback.c b/apps/playback.c
index a37e0ad679..d4f3626f99 100644
--- a/apps/playback.c
+++ b/apps/playback.c
@@ -74,29 +74,18 @@
74#include "misc.h" 74#include "misc.h"
75#include "sound.h" 75#include "sound.h"
76#include "metadata.h" 76#include "metadata.h"
77#include "splash.h"
77#include "talk.h" 78#include "talk.h"
78#ifdef CONFIG_TUNER 79
79#include "radio.h" 80#ifdef HAVE_RECORDING
81#include "recording.h"
80#endif 82#endif
81#include "splash.h"
82 83
83static volatile bool audio_codec_loaded; 84static volatile bool audio_codec_loaded;
84static volatile bool voice_codec_loaded; 85static volatile bool voice_codec_loaded;
85static volatile bool playing; 86static volatile bool playing;
86static volatile bool paused; 87static volatile bool paused;
87 88
88#define CODEC_VORBIS "/.rockbox/codecs/vorbis.codec"
89#define CODEC_MPA_L3 "/.rockbox/codecs/mpa.codec"
90#define CODEC_FLAC "/.rockbox/codecs/flac.codec"
91#define CODEC_WAV "/.rockbox/codecs/wav.codec"
92#define CODEC_A52 "/.rockbox/codecs/a52.codec"
93#define CODEC_MPC "/.rockbox/codecs/mpc.codec"
94#define CODEC_WAVPACK "/.rockbox/codecs/wavpack.codec"
95#define CODEC_ALAC "/.rockbox/codecs/alac.codec"
96#define CODEC_AAC "/.rockbox/codecs/aac.codec"
97#define CODEC_SHN "/.rockbox/codecs/shorten.codec"
98#define CODEC_AIFF "/.rockbox/codecs/aiff.codec"
99#define CODEC_SID "/.rockbox/codecs/sid.codec"
100 89
101/* default point to start buffer refill */ 90/* default point to start buffer refill */
102#define AUDIO_DEFAULT_WATERMARK (1024*512) 91#define AUDIO_DEFAULT_WATERMARK (1024*512)
@@ -133,6 +122,11 @@ enum {
133 122
134 Q_CODEC_LOAD, 123 Q_CODEC_LOAD,
135 Q_CODEC_LOAD_DISK, 124 Q_CODEC_LOAD_DISK,
125
126#if defined(HAVE_RECORDING) && !defined(SIMULATOR)
127 Q_ENCODER_LOAD_DISK,
128 Q_ENCODER_RECORD,
129#endif
136}; 130};
137 131
138/* As defined in plugins/lib/xxx2wav.h */ 132/* As defined in plugins/lib/xxx2wav.h */
@@ -382,7 +376,7 @@ static bool voice_pcmbuf_insert_split_callback(
382 } 376 }
383 377
384 return true; 378 return true;
385} 379} /* voice_pcmbuf_insert_split_callback */
386 380
387static bool codec_pcmbuf_insert_split_callback( 381static bool codec_pcmbuf_insert_split_callback(
388 const void *ch1, const void *ch2, size_t length) 382 const void *ch1, const void *ch2, size_t length)
@@ -444,7 +438,7 @@ static bool codec_pcmbuf_insert_split_callback(
444 } 438 }
445 439
446 return true; 440 return true;
447} 441} /* codec_pcmbuf_insert_split_callback */
448 442
449static bool voice_pcmbuf_insert_callback(const char *buf, size_t length) 443static bool voice_pcmbuf_insert_callback(const char *buf, size_t length)
450{ 444{
@@ -649,7 +643,7 @@ static size_t codec_filebuf_callback(void *ptr, size_t size)
649 643
650 /* Return the actual amount of data copied to the buffer */ 644 /* Return the actual amount of data copied to the buffer */
651 return copy_n; 645 return copy_n;
652} 646} /* codec_filebuf_callback */
653 647
654static void* voice_request_buffer_callback(size_t *realsize, size_t reqsize) 648static void* voice_request_buffer_callback(size_t *realsize, size_t reqsize)
655{ 649{
@@ -664,7 +658,9 @@ static void* voice_request_buffer_callback(size_t *realsize, size_t reqsize)
664 while (1) 658 while (1)
665 { 659 {
666 if (voice_is_playing) 660 if (voice_is_playing)
661 {
667 queue_wait_w_tmo(&voice_codec_queue, &ev, 0); 662 queue_wait_w_tmo(&voice_codec_queue, &ev, 0);
663 }
668 else if (playing) 664 else if (playing)
669 { 665 {
670 queue_wait_w_tmo(&voice_codec_queue, &ev, 0); 666 queue_wait_w_tmo(&voice_codec_queue, &ev, 0);
@@ -679,7 +675,11 @@ static void* voice_request_buffer_callback(size_t *realsize, size_t reqsize)
679 if (playing) 675 if (playing)
680 swap_codec(); 676 swap_codec();
681 break; 677 break;
682 678#if defined(HAVE_RECORDING) && !defined(SIMULATOR)
679 case Q_ENCODER_RECORD:
680 swap_codec();
681 break;
682#endif
683 case Q_VOICE_STOP: 683 case Q_VOICE_STOP:
684 if (voice_is_playing) 684 if (voice_is_playing)
685 { 685 {
@@ -743,7 +743,7 @@ voice_play_clip:
743 return NULL; 743 return NULL;
744 744
745 return voicebuf; 745 return voicebuf;
746} 746} /* voice_request_buffer_callback */
747 747
748static void* codec_request_buffer_callback(size_t *realsize, size_t reqsize) 748static void* codec_request_buffer_callback(size_t *realsize, size_t reqsize)
749{ 749{
@@ -794,7 +794,7 @@ static void* codec_request_buffer_callback(size_t *realsize, size_t reqsize)
794 *realsize = copy_n; 794 *realsize = copy_n;
795 795
796 return (char *)&filebuf[buf_ridx]; 796 return (char *)&filebuf[buf_ridx];
797} 797} /* codec_request_buffer_callback */
798 798
799static int get_codec_base_type(int type) 799static int get_codec_base_type(int type)
800{ 800{
@@ -1531,52 +1531,24 @@ static void codec_discard_codec_callback(void)
1531#endif 1531#endif
1532} 1532}
1533 1533
1534static const char *get_codec_path(int codectype) 1534static const char * get_codec_filename(int enc_spec)
1535{ 1535{
1536 switch (codectype) { 1536 const char *fname;
1537 case AFMT_OGG_VORBIS: 1537 int type = enc_spec & CODEC_TYPE_MASK;
1538 logf("Codec: Vorbis"); 1538 int afmt = enc_spec & CODEC_AFMT_MASK;
1539 return CODEC_VORBIS; 1539
1540 case AFMT_MPA_L1: 1540 if ((unsigned)afmt >= AFMT_NUM_CODECS)
1541 case AFMT_MPA_L2: 1541 type = AFMT_UNKNOWN | (type & CODEC_TYPE_MASK);
1542 case AFMT_MPA_L3: 1542
1543 logf("Codec: MPA L1/L2/L3"); 1543 fname = (type == CODEC_TYPE_DECODER) ?
1544 return CODEC_MPA_L3; 1544 audio_formats[afmt].codec_fn : audio_formats[afmt].codec_enc_fn;
1545 case AFMT_PCM_WAV: 1545
1546 logf("Codec: PCM WAV"); 1546 logf("%s: %d - %s",
1547 return CODEC_WAV; 1547 (type == CODEC_TYPE_ENCODER) ? "Encoder" : "Decoder",
1548 case AFMT_FLAC: 1548 afmt, fname ? fname : "<unknown>");
1549 logf("Codec: FLAC"); 1549
1550 return CODEC_FLAC; 1550 return fname;
1551 case AFMT_A52: 1551} /* get_codec_filename */
1552 logf("Codec: A52");
1553 return CODEC_A52;
1554 case AFMT_MPC:
1555 logf("Codec: Musepack");
1556 return CODEC_MPC;
1557 case AFMT_WAVPACK:
1558 logf("Codec: WAVPACK");
1559 return CODEC_WAVPACK;
1560 case AFMT_ALAC:
1561 logf("Codec: ALAC");
1562 return CODEC_ALAC;
1563 case AFMT_AAC:
1564 logf("Codec: AAC");
1565 return CODEC_AAC;
1566 case AFMT_SHN:
1567 logf("Codec: SHN");
1568 return CODEC_SHN;
1569 case AFMT_AIFF:
1570 logf("Codec: PCM AIFF");
1571 return CODEC_AIFF;
1572 case AFMT_SID:
1573 logf("Codec: SID");
1574 return CODEC_SID;
1575 default:
1576 logf("Codec: Unsupported");
1577 return NULL;
1578 }
1579}
1580 1552
1581static bool loadcodec(bool start_play) 1553static bool loadcodec(bool start_play)
1582{ 1554{
@@ -1585,9 +1557,10 @@ static bool loadcodec(bool start_play)
1585 int rc; 1557 int rc;
1586 size_t copy_n; 1558 size_t copy_n;
1587 int prev_track; 1559 int prev_track;
1560 char codec_path[MAX_PATH]; /* Full path to codec */
1588 1561
1589 const char *codec_path = get_codec_path(tracks[track_widx].id3.codectype); 1562 const char * codec_fn = get_codec_filename(tracks[track_widx].id3.codectype);
1590 if (codec_path == NULL) 1563 if (codec_fn == NULL)
1591 return false; 1564 return false;
1592 1565
1593 tracks[track_widx].has_codec = false; 1566 tracks[track_widx].has_codec = false;
@@ -1603,7 +1576,7 @@ static bool loadcodec(bool start_play)
1603 ci.taginfo_ready = &cur_ti->taginfo_ready; 1576 ci.taginfo_ready = &cur_ti->taginfo_ready;
1604 ci.curpos = 0; 1577 ci.curpos = 0;
1605 playing = true; 1578 playing = true;
1606 queue_post(&codec_queue, Q_CODEC_LOAD_DISK, (void *)codec_path); 1579 queue_post(&codec_queue, Q_CODEC_LOAD_DISK, (void *)codec_fn);
1607 return true; 1580 return true;
1608 } 1581 }
1609 else 1582 else
@@ -1625,6 +1598,8 @@ static bool loadcodec(bool start_play)
1625 } 1598 }
1626 } 1599 }
1627 1600
1601 codec_get_full_path(codec_path, codec_fn);
1602
1628 fd = open(codec_path, O_RDONLY); 1603 fd = open(codec_path, O_RDONLY);
1629 if (fd < 0) 1604 if (fd < 0)
1630 { 1605 {
@@ -1973,11 +1948,8 @@ static void audio_stop_playback(void)
1973 (playlist_end && ci.stop_codec)?NULL:audio_current_track()); 1948 (playlist_end && ci.stop_codec)?NULL:audio_current_track());
1974 } 1949 }
1975 1950
1976 if (voice_is_playing) 1951 while (voice_is_playing && !queue_empty(&voice_codec_queue))
1977 { 1952 yield();
1978 while (voice_is_playing && !queue_empty(&voice_codec_queue))
1979 yield();
1980 }
1981 1953
1982 filebufused = 0; 1954 filebufused = 0;
1983 playing = false; 1955 playing = false;
@@ -1998,10 +1970,8 @@ static void audio_stop_playback(void)
1998 1970
1999static void audio_play_start(size_t offset) 1971static void audio_play_start(size_t offset)
2000{ 1972{
2001#ifdef CONFIG_TUNER 1973#if defined(HAVE_RECORDING) || defined(CONFIG_TUNER)
2002 /* check if radio is playing */ 1974 rec_set_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK);
2003 if (get_radio_status() != FMRADIO_OFF)
2004 radio_stop();
2005#endif 1975#endif
2006 1976
2007 /* Wait for any previously playing audio to flush - TODO: Not necessary? */ 1977 /* Wait for any previously playing audio to flush - TODO: Not necessary? */
@@ -2483,6 +2453,20 @@ static void codec_thread(void)
2483 mutex_unlock(&mutex_codecthread); 2453 mutex_unlock(&mutex_codecthread);
2484 break ; 2454 break ;
2485 2455
2456#if defined(HAVE_RECORDING) && !defined(SIMULATOR)
2457 case Q_ENCODER_LOAD_DISK:
2458 logf("Encoder load disk");
2459 audio_codec_loaded = false;
2460 if (voice_codec_loaded && current_codec == CODEC_IDX_VOICE)
2461 queue_post(&voice_codec_queue, Q_ENCODER_RECORD, NULL);
2462 mutex_lock(&mutex_codecthread);
2463 current_codec = CODEC_IDX_AUDIO;
2464 ci.stop_codec = false;
2465 status = codec_load_file((const char *)ev.data, &ci);
2466 mutex_unlock(&mutex_codecthread);
2467 break;
2468#endif
2469
2486#ifndef SIMULATOR 2470#ifndef SIMULATOR
2487 case SYS_USB_CONNECTED: 2471 case SYS_USB_CONNECTED:
2488 queue_clear(&codec_queue); 2472 queue_clear(&codec_queue);
@@ -2511,8 +2495,6 @@ static void codec_thread(void)
2511 case Q_CODEC_LOAD: 2495 case Q_CODEC_LOAD:
2512 if (playing) 2496 if (playing)
2513 { 2497 {
2514 const char *codec_path;
2515
2516 if (ci.new_track || status != CODEC_OK) 2498 if (ci.new_track || status != CODEC_OK)
2517 { 2499 {
2518 if (!ci.new_track) 2500 if (!ci.new_track)
@@ -2523,7 +2505,8 @@ static void codec_thread(void)
2523 2505
2524 if (!load_next_track()) 2506 if (!load_next_track())
2525 { 2507 {
2526 queue_post(&codec_queue, Q_AUDIO_STOP, 0); 2508 // queue_post(&codec_queue, Q_AUDIO_STOP, 0);
2509 queue_post(&audio_queue, Q_AUDIO_STOP, 0);
2527 break; 2510 break;
2528 } 2511 }
2529 } 2512 }
@@ -2545,12 +2528,12 @@ static void codec_thread(void)
2545 queue_post(&codec_queue, Q_CODEC_LOAD, 0); 2528 queue_post(&codec_queue, Q_CODEC_LOAD, 0);
2546 else 2529 else
2547 { 2530 {
2548 codec_path = get_codec_path(cur_ti->id3.codectype); 2531 const char *codec_fn = get_codec_filename(cur_ti->id3.codectype);
2549 queue_post(&codec_queue, 2532 queue_post(&codec_queue, Q_CODEC_LOAD_DISK,
2550 Q_CODEC_LOAD_DISK, (void *)codec_path); 2533 (void *)codec_fn);
2551 } 2534 }
2552 } 2535 }
2553 } 2536 } /* end switch */
2554 } 2537 }
2555} 2538}
2556 2539
@@ -2596,6 +2579,37 @@ static void reset_buffer(void)
2596 filebuflen &= ~3; 2579 filebuflen &= ~3;
2597} 2580}
2598 2581
2582void audio_load_encoder(int enc_id)
2583{
2584#if defined(HAVE_RECORDING) && !defined(SIMULATOR)
2585 const char *enc_fn = get_codec_filename(enc_id | CODEC_TYPE_ENCODER);
2586 if (!enc_fn)
2587 return;
2588
2589 audio_remove_encoder();
2590
2591 queue_post(&codec_queue, Q_ENCODER_LOAD_DISK, (void *)enc_fn);
2592
2593 while (!ci.enc_codec_loaded)
2594 yield();
2595#endif
2596 return;
2597 (void)enc_id;
2598} /* audio_load_encoder */
2599
2600void audio_remove_encoder(void)
2601{
2602#if defined(HAVE_RECORDING) && !defined(SIMULATOR)
2603 /* force encoder codec unload (if previously loaded) */
2604 if (!ci.enc_codec_loaded)
2605 return;
2606
2607 ci.stop_codec = true;
2608 while (ci.enc_codec_loaded)
2609 yield();
2610#endif
2611} /* audio_remove_encoder */
2612
2599static void voice_codec_thread(void) 2613static void voice_codec_thread(void)
2600{ 2614{
2601 while (1) 2615 while (1)
@@ -2608,13 +2622,13 @@ static void voice_codec_thread(void)
2608 voice_remaining = 0; 2622 voice_remaining = 0;
2609 voice_getmore = NULL; 2623 voice_getmore = NULL;
2610 2624
2611 codec_load_file(CODEC_MPA_L3, &ci_voice); 2625 codec_load_file(get_codec_filename(AFMT_MPA_L3), &ci_voice);
2612 2626
2613 logf("Voice codec finished"); 2627 logf("Voice codec finished");
2614 mutex_unlock(&mutex_codecthread);
2615 voice_codec_loaded = false; 2628 voice_codec_loaded = false;
2629 mutex_unlock(&mutex_codecthread);
2616 } 2630 }
2617} 2631} /* voice_codec_thread */
2618 2632
2619void voice_init(void) 2633void voice_init(void)
2620{ 2634{
@@ -2642,7 +2656,20 @@ void voice_init(void)
2642 2656
2643 while (!voice_codec_loaded) 2657 while (!voice_codec_loaded)
2644 yield(); 2658 yield();
2645} 2659} /* voice_init */
2660
2661void voice_stop(void)
2662{
2663 /* Messages should not be posted to voice codec queue unless it is the
2664 current codec or deadlocks happen. This will be addressed globally soon.
2665 -- jhMikeS */
2666 if (current_codec != CODEC_IDX_VOICE)
2667 return;
2668
2669 mp3_play_stop();
2670 while (voice_is_playing && !queue_empty(&voice_codec_queue))
2671 yield();
2672} /* voice_stop */
2646 2673
2647struct mp3entry* audio_current_track(void) 2674struct mp3entry* audio_current_track(void)
2648{ 2675{
@@ -2803,9 +2830,19 @@ int audio_status(void)
2803 if (paused) 2830 if (paused)
2804 ret |= AUDIO_STATUS_PAUSE; 2831 ret |= AUDIO_STATUS_PAUSE;
2805 2832
2833#ifdef HAVE_RECORDING
2834 /* Do this here for constitency with mpeg.c version */
2835 ret |= pcm_rec_status();
2836#endif
2837
2806 return ret; 2838 return ret;
2807} 2839}
2808 2840
2841bool audio_query_poweroff(void)
2842{
2843 return !(playing && paused);
2844}
2845
2809int audio_get_file_pos(void) 2846int audio_get_file_pos(void)
2810{ 2847{
2811 return 0; 2848 return 0;
diff --git a/apps/playback.h b/apps/playback.h
index 3e501333c1..73cd0ccfaf 100644
--- a/apps/playback.h
+++ b/apps/playback.h
@@ -27,8 +27,8 @@
27#include "id3.h" 27#include "id3.h"
28#include "mp3data.h" 28#include "mp3data.h"
29 29
30#define CODEC_IDX_AUDIO 0 30#define CODEC_IDX_AUDIO 0
31#define CODEC_IDX_VOICE 1 31#define CODEC_IDX_VOICE 1
32 32
33/* Not yet implemented. */ 33/* Not yet implemented. */
34#define CODEC_SET_AUDIOBUF_WATERMARK 4 34#define CODEC_SET_AUDIOBUF_WATERMARK 4
@@ -66,6 +66,7 @@ void audio_set_track_unbuffer_event(void (*handler)(struct mp3entry *id3,
66 bool last_track)); 66 bool last_track));
67void audio_invalidate_tracks(void); 67void audio_invalidate_tracks(void);
68void voice_init(void); 68void voice_init(void);
69void voice_stop(void);
69 70
70#if CONFIG_CODEC == SWCODEC /* This #ifdef is better here than gui/gwps.c */ 71#if CONFIG_CODEC == SWCODEC /* This #ifdef is better here than gui/gwps.c */
71extern void audio_next_dir(void); 72extern void audio_next_dir(void);
diff --git a/apps/recorder/radio.c b/apps/recorder/radio.c
index c292909b33..208e7b67fa 100644
--- a/apps/recorder/radio.c
+++ b/apps/recorder/radio.c
@@ -24,7 +24,6 @@
24#include "mas.h" 24#include "mas.h"
25#include "settings.h" 25#include "settings.h"
26#include "button.h" 26#include "button.h"
27#include "fmradio.h"
28#include "status.h" 27#include "status.h"
29#include "kernel.h" 28#include "kernel.h"
30#include "mpeg.h" 29#include "mpeg.h"
@@ -63,17 +62,6 @@
63 62
64#ifdef CONFIG_TUNER 63#ifdef CONFIG_TUNER
65 64
66#if CONFIG_CODEC == SWCODEC
67#ifdef HAVE_UDA1380
68#include "uda1380.h"
69#endif
70#ifdef HAVE_TLV320
71#include "tlv320.h"
72#endif
73
74#include "pcm_record.h"
75#endif
76
77#if CONFIG_KEYPAD == RECORDER_PAD 65#if CONFIG_KEYPAD == RECORDER_PAD
78#define FM_MENU BUTTON_F1 66#define FM_MENU BUTTON_F1
79#define FM_PRESET BUTTON_F2 67#define FM_PRESET BUTTON_F2
@@ -165,6 +153,7 @@ static int curr_freq;
165static int radio_mode = RADIO_SCAN_MODE; 153static int radio_mode = RADIO_SCAN_MODE;
166 154
167static int radio_status = FMRADIO_OFF; 155static int radio_status = FMRADIO_OFF;
156static bool in_screen = false;
168 157
169#define MAX_PRESETS 64 158#define MAX_PRESETS 64
170static bool presets_loaded = false, presets_changed = false; 159static bool presets_loaded = false, presets_changed = false;
@@ -239,22 +228,87 @@ int get_radio_status(void)
239 return radio_status; 228 return radio_status;
240} 229}
241 230
231bool in_radio_screen(void)
232{
233 return in_screen;
234}
235
236/* secret flag for starting paused - prevents unmute */
237#define FMRADIO_START_PAUSED 0x8000
238void radio_start(void)
239{
240 bool start_paused;
241 int mute_timeout;
242
243 if(radio_status == FMRADIO_PLAYING)
244 return;
245
246 start_paused = radio_status & FMRADIO_START_PAUSED;
247 /* clear flag before any yielding */
248 radio_status &= ~FMRADIO_START_PAUSED;
249
250 if(radio_status == FMRADIO_OFF)
251 radio_power(true);
252
253 curr_freq = global_settings.last_frequency * FREQ_STEP + MIN_FREQ;
254
255 radio_set(RADIO_SLEEP, 0); /* wake up the tuner */
256 radio_set(RADIO_FREQUENCY, curr_freq);
257
258 if(radio_status == FMRADIO_OFF)
259 {
260 radio_set(RADIO_IF_MEASUREMENT, 0);
261 radio_set(RADIO_SENSITIVITY, 0);
262 radio_set(RADIO_FORCE_MONO, global_settings.fm_force_mono);
263 mute_timeout = current_tick + 1*HZ;
264 }
265 else
266 {
267 /* paused */
268 mute_timeout = current_tick + 2*HZ;
269 }
270
271 while(!radio_get(RADIO_STEREO) && !radio_get(RADIO_TUNED))
272 {
273 if(TIME_AFTER(current_tick, mute_timeout))
274 break;
275 yield();
276 }
277
278 /* keep radio from sounding initially */
279 if(!start_paused)
280 radio_set(RADIO_MUTE, 0);
281
282 radio_status = FMRADIO_PLAYING;
283} /* radio_start */
284
285void radio_pause(void)
286{
287 if(radio_status == FMRADIO_PAUSED)
288 return;
289
290 if(radio_status == FMRADIO_OFF)
291 {
292 radio_status |= FMRADIO_START_PAUSED;
293 radio_start();
294 }
295
296 radio_set(RADIO_MUTE, 1);
297 radio_set(RADIO_SLEEP, 1);
298
299 radio_status = FMRADIO_PAUSED;
300} /* radio_pause */
301
242void radio_stop(void) 302void radio_stop(void)
243{ 303{
304 if(radio_status == FMRADIO_OFF)
305 return;
306
244 radio_set(RADIO_MUTE, 1); 307 radio_set(RADIO_MUTE, 1);
245 radio_set(RADIO_SLEEP, 1); /* low power mode, if available */ 308 radio_set(RADIO_SLEEP, 1); /* low power mode, if available */
246 radio_status = FMRADIO_OFF; 309 radio_status = FMRADIO_OFF;
247 radio_power(false); /* status update, power off if avail. */ 310 radio_power(false); /* status update, power off if avail. */
248 311} /* radio_stop */
249#ifndef SIMULATOR /* SIMULATOR. Catch FMRADIO_OFF status for the sim. */
250#if CONFIG_CODEC == SWCODEC
251#ifdef HAVE_TLV320
252 tlv320_set_monitor(false);
253#endif
254 pcm_rec_mux(0); /* Line In */
255#endif
256#endif /* SIMULATOR */
257}
258 312
259bool radio_hardware_present(void) 313bool radio_hardware_present(void)
260{ 314{
@@ -297,18 +351,16 @@ static int find_closest_preset(int freq)
297 return i; 351 return i;
298 if(diff < 0) 352 if(diff < 0)
299 diff = -diff; 353 diff = -diff;
300 if(diff < min_diff) 354 if(diff < min_diff)
301 { 355 {
302 preset = i; 356 preset = i;
303 min_diff = diff; 357 min_diff = diff;
304 } 358 }
305 } 359 }
306 360
307 return preset; 361 return preset;
308} 362}
309 363
310
311
312static void remember_frequency(void) 364static void remember_frequency(void)
313{ 365{
314 global_settings.last_frequency = (curr_freq - MIN_FREQ) / FREQ_STEP; 366 global_settings.last_frequency = (curr_freq - MIN_FREQ) / FREQ_STEP;
@@ -366,13 +418,15 @@ bool radio_screen(void)
366#endif 418#endif
367 bool keep_playing = false; 419 bool keep_playing = false;
368 bool statusbar = global_settings.statusbar; 420 bool statusbar = global_settings.statusbar;
369 int mute_timeout = current_tick;
370 int button_timeout = current_tick + (2*HZ); 421 int button_timeout = current_tick + (2*HZ);
371#ifdef HAS_BUTTONBAR 422#ifdef HAS_BUTTONBAR
372 struct gui_buttonbar buttonbar; 423 struct gui_buttonbar buttonbar;
373 gui_buttonbar_init(&buttonbar); 424 gui_buttonbar_init(&buttonbar);
374 gui_buttonbar_set_display(&buttonbar, &(screens[SCREEN_MAIN]) ); 425 gui_buttonbar_set_display(&buttonbar, &(screens[SCREEN_MAIN]) );
375#endif 426#endif
427 /* change status to "in screen" */
428 in_screen = true;
429
376 /* always display status bar in radio screen for now */ 430 /* always display status bar in radio screen for now */
377 global_settings.statusbar = true; 431 global_settings.statusbar = true;
378 FOR_NB_SCREENS(i) 432 FOR_NB_SCREENS(i)
@@ -396,80 +450,44 @@ bool radio_screen(void)
396 } 450 }
397 451
398#ifndef SIMULATOR 452#ifndef SIMULATOR
453 if(radio_status == FMRADIO_OFF)
454 audio_stop();
455
399#if CONFIG_CODEC != SWCODEC 456#if CONFIG_CODEC != SWCODEC
400 if(rec_create_directory() > 0) 457 if(rec_create_directory() > 0)
401 have_recorded = true; 458 have_recorded = true;
402#endif
403 459
404 if(radio_status == FMRADIO_PLAYING_OUT)
405 radio_status = FMRADIO_PLAYING;
406 else if(radio_status == FMRADIO_PAUSED_OUT)
407 radio_status = FMRADIO_PAUSED;
408
409 if(radio_status == FMRADIO_OFF)
410 audio_stop();
411
412#if CONFIG_CODEC != SWCODEC
413 audio_init_recording(talk_get_bufsize()); 460 audio_init_recording(talk_get_bufsize());
414 461
415 sound_settings_apply(); 462 sound_settings_apply();
416 /* Yes, we use the D/A for monitoring */ 463 /* Yes, we use the D/A for monitoring */
417 peak_meter_playback(true); 464 peak_meter_playback(true);
418
419 peak_meter_enabled = true;
420 465
421 if (global_settings.rec_prerecord_time) 466 peak_meter_enabled = true;
422 talk_buffer_steal(); /* will use the mp3 buffer */
423 467
424 audio_set_recording_options(global_settings.rec_frequency, 468 rec_set_recording_options(global_settings.rec_frequency,
425 global_settings.rec_quality, 469 global_settings.rec_quality,
426 1, /* Line In */ 470 AUDIO_SRC_LINEIN, 0,
427 global_settings.rec_channels, 471 global_settings.rec_channels,
428 global_settings.rec_editable, 472 global_settings.rec_editable,
429 global_settings.rec_prerecord_time); 473 global_settings.rec_prerecord_time);
430 474
431 475 audio_set_recording_gain(sound_default(SOUND_LEFT_GAIN),
432#else 476 sound_default(SOUND_RIGHT_GAIN), AUDIO_GAIN_LINEIN);
433 peak_meter_enabled = false;
434 477
435#ifdef HAVE_UDA1380 478#endif /* CONFIG_CODEC != SWCODEC */
436 uda1380_enable_recording(false); 479#endif /* ndef SIMULATOR */
437 uda1380_set_monitor(true);
438#elif defined(HAVE_TLV320)
439 //tlv320_enable_recording(false);
440 tlv320_set_recvol(23, 23, AUDIO_GAIN_LINEIN); /* 0dB */
441 tlv320_set_monitor(true);
442#endif
443 480
444 /* Set the input multiplexer to FM */ 481 /* turn on radio */
445 pcm_rec_mux(1); 482#if CONFIG_CODEC == SWCODEC
446#endif 483 rec_set_source(AUDIO_SRC_FMRADIO, (radio_status == FMRADIO_PAUSED) ?
447 audio_set_recording_gain(sound_default(SOUND_LEFT_GAIN), 484 SRCF_FMRADIO_PAUSED : SRCF_FMRADIO_PLAYING);
448 sound_default(SOUND_RIGHT_GAIN), AUDIO_GAIN_LINEIN); 485#else
486 if (radio_status == FMRADIO_OFF)
487 radio_start();
449#endif 488#endif
450 489
451 curr_freq = global_settings.last_frequency * FREQ_STEP + MIN_FREQ; 490 /* I hate this thing with vehement passion (jhMikeS): */
452
453 if(radio_status == FMRADIO_OFF)
454 {
455 radio_power(true);
456 radio_set(RADIO_SLEEP, 0); /* wake up the tuner */
457 radio_set(RADIO_FREQUENCY, curr_freq);
458 radio_set(RADIO_IF_MEASUREMENT, 0);
459 radio_set(RADIO_SENSITIVITY, 0);
460 radio_set(RADIO_FORCE_MONO, global_settings.fm_force_mono);
461 mute_timeout = current_tick + (1*HZ);
462 while( !radio_get(RADIO_STEREO)
463 &&!radio_get(RADIO_TUNED) )
464 {
465 if(TIME_AFTER(current_tick, mute_timeout))
466 break;
467 yield();
468 }
469 radio_set(RADIO_MUTE, 0);
470 radio_status = FMRADIO_PLAYING;
471 }
472
473 if(num_presets == 0 && yesno_pop(str(LANG_FM_FIRST_AUTOSCAN))) 491 if(num_presets == 0 && yesno_pop(str(LANG_FM_FIRST_AUTOSCAN)))
474 scan_presets(); 492 scan_presets();
475 493
@@ -478,8 +496,8 @@ bool radio_screen(void)
478 radio_mode = RADIO_PRESET_MODE; 496 radio_mode = RADIO_PRESET_MODE;
479 497
480#ifdef HAS_BUTTONBAR 498#ifdef HAS_BUTTONBAR
481 gui_buttonbar_set(&buttonbar, str(LANG_BUTTONBAR_MENU), str(LANG_FM_BUTTONBAR_PRESETS), 499 gui_buttonbar_set(&buttonbar, str(LANG_BUTTONBAR_MENU),
482 str(LANG_FM_BUTTONBAR_RECORD)); 500 str(LANG_FM_BUTTONBAR_PRESETS), str(LANG_FM_BUTTONBAR_RECORD));
483#endif 501#endif
484 502
485 cpu_idle_mode(true); 503 cpu_idle_mode(true);
@@ -535,7 +553,7 @@ bool radio_screen(void)
535 if (lastbutton != FM_STOP_PRE) 553 if (lastbutton != FM_STOP_PRE)
536 break; 554 break;
537#endif 555#endif
538#ifndef SIMULATOR 556#if CONFIG_CODEC != SWCODEC && !defined(SIMULATOR)
539 if(audio_status() == AUDIO_STATUS_RECORD) 557 if(audio_status() == AUDIO_STATUS_RECORD)
540 { 558 {
541 audio_stop(); 559 audio_stop();
@@ -548,7 +566,7 @@ bool radio_screen(void)
548 { 566 {
549 if(yesno_pop(str(LANG_FM_SAVE_CHANGES))) 567 if(yesno_pop(str(LANG_FM_SAVE_CHANGES)))
550 { 568 {
551 if(filepreset[0] == '\0') 569 if(filepreset[0] == '\0')
552 save_preset_list(); 570 save_preset_list();
553 else 571 else
554 radio_save_presets(); 572 radio_save_presets();
@@ -577,14 +595,13 @@ bool radio_screen(void)
577#ifndef SIMULATOR 595#ifndef SIMULATOR
578 if(audio_status() == AUDIO_STATUS_RECORD) 596 if(audio_status() == AUDIO_STATUS_RECORD)
579 { 597 {
580 audio_new_file(rec_create_filename(buf)); 598 rec_new_file();
581 update_screen = true; 599 update_screen = true;
582 } 600 }
583 else 601 else
584 { 602 {
585 have_recorded = true; 603 have_recorded = true;
586 talk_buffer_steal(); /* we use the mp3 buffer */ 604 rec_record();
587 audio_record(rec_create_filename(buf));
588 update_screen = true; 605 update_screen = true;
589 } 606 }
590#endif 607#endif
@@ -604,7 +621,7 @@ bool radio_screen(void)
604 ) 621 )
605 break; 622 break;
606#endif 623#endif
607#ifndef SIMULATOR 624#if CONFIG_CODEC != SWCODEC && !defined(SIMULATOR)
608 if(audio_status() == AUDIO_STATUS_RECORD) 625 if(audio_status() == AUDIO_STATUS_RECORD)
609 audio_stop(); 626 audio_stop();
610#endif 627#endif
@@ -615,7 +632,7 @@ bool radio_screen(void)
615 { 632 {
616 if(yesno_pop(str(LANG_FM_SAVE_CHANGES))) 633 if(yesno_pop(str(LANG_FM_SAVE_CHANGES)))
617 { 634 {
618 if(filepreset[0] == '\0') 635 if(filepreset[0] == '\0')
619 save_preset_list(); 636 save_preset_list();
620 else 637 else
621 radio_save_presets(); 638 radio_save_presets();
@@ -734,27 +751,11 @@ bool radio_screen(void)
734 ) 751 )
735 break; 752 break;
736#endif 753#endif
737 if(radio_status != FMRADIO_PLAYING) 754 if (radio_status == FMRADIO_PLAYING)
738 { 755 radio_pause();
739 radio_set(RADIO_SLEEP, 0);
740 radio_set(RADIO_FREQUENCY, curr_freq);
741 mute_timeout = current_tick + (2*HZ);
742 while( !radio_get(RADIO_STEREO)
743 &&!radio_get(RADIO_TUNED) )
744 {
745 if(TIME_AFTER(current_tick, mute_timeout))
746 break;
747 yield();
748 }
749 radio_set(RADIO_MUTE, 0);
750 radio_status = FMRADIO_PLAYING;
751 }
752 else 756 else
753 { 757 radio_start();
754 radio_set(RADIO_MUTE, 1); 758
755 radio_set(RADIO_SLEEP, 1);
756 radio_status = FMRADIO_PAUSED;
757 }
758 update_screen = true; 759 update_screen = true;
759 break; 760 break;
760#endif 761#endif
@@ -917,13 +918,17 @@ bool radio_screen(void)
917 if(TIME_AFTER(current_tick, timeout)) 918 if(TIME_AFTER(current_tick, timeout))
918 { 919 {
919 timeout = current_tick + HZ; 920 timeout = current_tick + HZ;
920 921
921 stereo = radio_get(RADIO_STEREO) && 922 /* keep "mono" from always being displayed when paused */
922 !global_settings.fm_force_mono; 923 if (radio_status != FMRADIO_PAUSED)
923 if(stereo != last_stereo_status)
924 { 924 {
925 update_screen = true; 925 stereo = radio_get(RADIO_STEREO) &&
926 last_stereo_status = stereo; 926 !global_settings.fm_force_mono;
927 if(stereo != last_stereo_status)
928 {
929 update_screen = true;
930 last_stereo_status = stereo;
931 }
927 } 932 }
928 } 933 }
929 934
@@ -952,9 +957,6 @@ bool radio_screen(void)
952 FOR_NB_SCREENS(i) 957 FOR_NB_SCREENS(i)
953 screens[i].puts_scroll(0, top_of_screen + 1, buf); 958 screens[i].puts_scroll(0, top_of_screen + 1, buf);
954 959
955 strcat(buf, stereo?str(LANG_CHANNEL_STEREO):
956 str(LANG_CHANNEL_MONO));
957
958 snprintf(buf, 128, stereo?str(LANG_CHANNEL_STEREO): 960 snprintf(buf, 128, stereo?str(LANG_CHANNEL_STEREO):
959 str(LANG_CHANNEL_MONO)); 961 str(LANG_CHANNEL_MONO));
960 FOR_NB_SCREENS(i) 962 FOR_NB_SCREENS(i)
@@ -1005,9 +1007,9 @@ bool radio_screen(void)
1005 done = true; 1007 done = true;
1006 } 1008 }
1007 if (TIME_AFTER(current_tick, button_timeout)) 1009 if (TIME_AFTER(current_tick, button_timeout))
1008 { 1010 {
1009 cpu_idle_mode(true); 1011 cpu_idle_mode(true);
1010 } 1012 }
1011 } /*while(!done)*/ 1013 } /*while(!done)*/
1012 1014
1013#ifndef SIMULATOR 1015#ifndef SIMULATOR
@@ -1033,28 +1035,26 @@ bool radio_screen(void)
1033 1035
1034 sound_settings_apply(); 1036 sound_settings_apply();
1035#endif /* SIMULATOR */ 1037#endif /* SIMULATOR */
1038
1036 if(keep_playing) 1039 if(keep_playing)
1037 { 1040 {
1038/* Catch FMRADIO_PLAYING_OUT status for the sim. */ 1041/* Catch FMRADIO_PLAYING status for the sim. */
1039#ifndef SIMULATOR 1042#ifndef SIMULATOR
1040#if CONFIG_CODEC != SWCODEC 1043#if CONFIG_CODEC != SWCODEC
1041 /* Enable the Left and right A/D Converter */ 1044 /* Enable the Left and right A/D Converter */
1042 audio_set_recording_gain(sound_default(SOUND_LEFT_GAIN), 1045 audio_set_recording_gain(sound_default(SOUND_LEFT_GAIN),
1043 sound_default(SOUND_RIGHT_GAIN), AUDIO_GAIN_LINEIN); 1046 sound_default(SOUND_RIGHT_GAIN),
1047 AUDIO_GAIN_LINEIN);
1044 mas_codec_writereg(6, 0x4000); 1048 mas_codec_writereg(6, 0x4000);
1045#endif 1049#endif
1046#endif 1050#endif
1047 if(radio_status == FMRADIO_PAUSED)
1048 radio_status = FMRADIO_PAUSED_OUT;
1049 else
1050 radio_status = FMRADIO_PLAYING_OUT;
1051
1052 } 1051 }
1053 else 1052 else
1054 { 1053 {
1055 radio_stop();
1056#if CONFIG_CODEC == SWCODEC 1054#if CONFIG_CODEC == SWCODEC
1057 peak_meter_enabled = true; 1055 rec_set_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK);
1056#else
1057 radio_stop();
1058#endif 1058#endif
1059 } 1059 }
1060 1060
@@ -1062,9 +1062,11 @@ bool radio_screen(void)
1062 1062
1063 /* restore status bar settings */ 1063 /* restore status bar settings */
1064 global_settings.statusbar = statusbar; 1064 global_settings.statusbar = statusbar;
1065
1066 in_screen = false;
1065 1067
1066 return have_recorded; 1068 return have_recorded;
1067} 1069} /* radio_screen */
1068 1070
1069void radio_save_presets(void) 1071void radio_save_presets(void)
1070{ 1072{
@@ -1106,16 +1108,16 @@ void radio_load_presets(char *filename)
1106 1108
1107/* No Preset in configuration. */ 1109/* No Preset in configuration. */
1108 if(filename[0] == '\0') 1110 if(filename[0] == '\0')
1109 { 1111 {
1110 filepreset[0] = '\0'; 1112 filepreset[0] = '\0';
1111 return; 1113 return;
1112 } 1114 }
1113/* Temporary preset, loaded until player shuts down. */ 1115/* Temporary preset, loaded until player shuts down. */
1114 else if(filename[0] == '/') 1116 else if(filename[0] == '/')
1115 strncpy(filepreset, filename, sizeof(filepreset)); 1117 strncpy(filepreset, filename, sizeof(filepreset));
1116/* Preset from default directory. */ 1118/* Preset from default directory. */
1117 else 1119 else
1118 snprintf(filepreset, sizeof(filepreset), "%s/%s.fmr", 1120 snprintf(filepreset, sizeof(filepreset), "%s/%s.fmr",
1119 FMPRESET_PATH, filename); 1121 FMPRESET_PATH, filename);
1120 1122
1121 fd = open(filepreset, O_RDONLY); 1123 fd = open(filepreset, O_RDONLY);
@@ -1466,30 +1468,6 @@ bool handle_radio_presets(void)
1466 return reload_dir; 1468 return reload_dir;
1467} 1469}
1468 1470
1469#ifndef SIMULATOR
1470#if CONFIG_CODEC != SWCODEC
1471static bool fm_recording_settings(void)
1472{
1473 bool ret;
1474
1475 ret = recording_menu(true);
1476 if(!ret)
1477 {
1478 if (global_settings.rec_prerecord_time)
1479 talk_buffer_steal(); /* will use the mp3 buffer */
1480
1481 audio_set_recording_options(global_settings.rec_frequency,
1482 global_settings.rec_quality,
1483 1, /* Line In */
1484 global_settings.rec_channels,
1485 global_settings.rec_editable,
1486 global_settings.rec_prerecord_time);
1487 }
1488 return ret;
1489}
1490#endif
1491#endif
1492
1493char monomode_menu_string[32]; 1471char monomode_menu_string[32];
1494 1472
1495static void create_monomode_menu(void) 1473static void create_monomode_menu(void)
@@ -1628,6 +1606,55 @@ int radio_menu_cb(int key, int m)
1628 return key; 1606 return key;
1629} 1607}
1630 1608
1609#ifndef SIMULATOR
1610#if defined(HAVE_FMRADIO_IN) || CONFIG_CODEC != SWCODEC
1611static bool fm_recording_screen(void)
1612{
1613 bool ret;
1614
1615#ifdef HAVE_FMRADIO_IN
1616 /* switch recording source to FMRADIO for the duration */
1617 int rec_source = global_settings.rec_source;
1618 global_settings.rec_source = AUDIO_SRC_FMRADIO;
1619
1620 /* clearing queue seems to cure a spontaneous abort during record */
1621 while (button_get(false) != BUTTON_NONE);
1622#endif
1623
1624 ret = recording_screen(true);
1625
1626#ifdef HAVE_FMRADIO_IN
1627 /* safe to reset as changing sources is prohibited here */
1628 global_settings.rec_source = rec_source;
1629#endif
1630
1631 return ret;
1632}
1633
1634static bool fm_recording_settings(void)
1635{
1636 bool ret = recording_menu(true);
1637
1638 if (!ret)
1639 {
1640 rec_set_recording_options(global_settings.rec_frequency,
1641 global_settings.rec_quality,
1642#if CONFIG_CODEC == SWCODEC
1643 AUDIO_SRC_FMRADIO, SRCF_FMRADIO_PLAYING,
1644#else
1645 AUDIO_SRC_LINEIN, 0,
1646#endif
1647 global_settings.rec_channels,
1648 global_settings.rec_editable,
1649 global_settings.rec_prerecord_time);
1650 }
1651
1652 return ret;
1653}
1654#endif
1655#endif /* SIMULATOR */
1656
1657
1631/* main menu of the radio screen */ 1658/* main menu of the radio screen */
1632bool radio_menu(void) 1659bool radio_menu(void)
1633{ 1660{
@@ -1637,24 +1664,27 @@ bool radio_menu(void)
1637 static const struct menu_item items[] = { 1664 static const struct menu_item items[] = {
1638/* Add functions not accessible via buttons */ 1665/* Add functions not accessible via buttons */
1639#ifndef FM_PRESET 1666#ifndef FM_PRESET
1640 { ID2P(LANG_FM_BUTTONBAR_PRESETS), handle_radio_presets }, 1667 { ID2P(LANG_FM_BUTTONBAR_PRESETS), handle_radio_presets },
1641#endif 1668#endif
1642#ifndef FM_PRESET_ADD 1669#ifndef FM_PRESET_ADD
1643 { ID2P(LANG_FM_ADD_PRESET) , radio_add_preset }, 1670 { ID2P(LANG_FM_ADD_PRESET) , radio_add_preset },
1644#endif 1671#endif
1645 { ID2P(LANG_FM_PRESET_LOAD) , load_preset_list }, 1672 { ID2P(LANG_FM_PRESET_LOAD) , load_preset_list },
1646 { ID2P(LANG_FM_PRESET_SAVE) , save_preset_list }, 1673 { ID2P(LANG_FM_PRESET_SAVE) , save_preset_list },
1647 { ID2P(LANG_FM_PRESET_CLEAR) , clear_preset_list }, 1674 { ID2P(LANG_FM_PRESET_CLEAR) , clear_preset_list },
1648 1675
1649 { monomode_menu_string , toggle_mono_mode }, 1676 { monomode_menu_string , toggle_mono_mode },
1650#ifndef FM_MODE 1677#ifndef FM_MODE
1651 { radiomode_menu_string , toggle_radio_mode }, 1678 { radiomode_menu_string , toggle_radio_mode },
1679#endif
1680 { ID2P(LANG_SOUND_SETTINGS) , sound_menu },
1681#ifndef SIMULATOR
1682#if defined(HAVE_FMRADIO_IN) || CONFIG_CODEC != SWCODEC
1683 { ID2P(LANG_RECORDING_MENU) , fm_recording_screen },
1684 { ID2P(LANG_RECORDING_SETTINGS) , fm_recording_settings },
1652#endif 1685#endif
1653 { ID2P(LANG_SOUND_SETTINGS) , sound_menu },
1654#if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
1655 { ID2P(LANG_RECORDING_SETTINGS) , fm_recording_settings},
1656#endif 1686#endif
1657 { ID2P(LANG_FM_SCAN_PRESETS) , scan_presets }, 1687 { ID2P(LANG_FM_SCAN_PRESETS) , scan_presets },
1658 }; 1688 };
1659 1689
1660 create_monomode_menu(); 1690 create_monomode_menu();
diff --git a/apps/recorder/radio.h b/apps/recorder/radio.h
index 86ce04c4b9..fdf446dc0a 100644
--- a/apps/recorder/radio.h
+++ b/apps/recorder/radio.h
@@ -20,19 +20,19 @@
20#define RADIO_H 20#define RADIO_H
21#define FMPRESET_PATH ROCKBOX_DIR "/fmpresets" 21#define FMPRESET_PATH ROCKBOX_DIR "/fmpresets"
22 22
23#define FMRADIO_OFF 0 23#ifndef FMRADIO_H
24#define FMRADIO_PLAYING 1 24#include "fmradio.h"
25#define FMRADIO_PLAYING_OUT 2 25#endif
26#define FMRADIO_PAUSED 3
27#define FMRADIO_PAUSED_OUT 4
28 26
29#ifdef CONFIG_TUNER 27#ifdef CONFIG_TUNER
30void radio_load_presets(char *filename); 28void radio_load_presets(char *filename);
31void radio_init(void); 29void radio_init(void);
32bool radio_screen(void); 30bool radio_screen(void);
31void radio_start(void);
32void radio_pause(void);
33void radio_stop(void); 33void radio_stop(void);
34bool radio_hardware_present(void); 34bool radio_hardware_present(void);
35int get_radio_status(void); 35bool in_radio_screen(void);
36 36
37#define MAX_FMPRESET_LEN 27 37#define MAX_FMPRESET_LEN 27
38 38
diff --git a/apps/recorder/recording.c b/apps/recorder/recording.c
index e6b06d56dc..080cafcf2f 100644
--- a/apps/recorder/recording.c
+++ b/apps/recorder/recording.c
@@ -24,12 +24,14 @@
24#include <stdlib.h> 24#include <stdlib.h>
25 25
26#include "system.h" 26#include "system.h"
27#include "power.h"
27#include "lcd.h" 28#include "lcd.h"
28#include "led.h" 29#include "led.h"
29#include "mpeg.h" 30#include "mpeg.h"
30#include "audio.h" 31#include "audio.h"
31#if CONFIG_CODEC == SWCODEC 32#if CONFIG_CODEC == SWCODEC
32#include "pcm_record.h" 33#include "pcm_record.h"
34#include "playback.h"
33#endif 35#endif
34#ifdef HAVE_UDA1380 36#ifdef HAVE_UDA1380
35#include "uda1380.h" 37#include "uda1380.h"
@@ -37,7 +39,7 @@
37#ifdef HAVE_TLV320 39#ifdef HAVE_TLV320
38#include "tlv320.h" 40#include "tlv320.h"
39#endif 41#endif
40 42#include "recording.h"
41#include "mp3_playback.h" 43#include "mp3_playback.h"
42#include "mas.h" 44#include "mas.h"
43#include "button.h" 45#include "button.h"
@@ -66,6 +68,7 @@
66#include "splash.h" 68#include "splash.h"
67#include "screen_access.h" 69#include "screen_access.h"
68#include "action.h" 70#include "action.h"
71#include "radio.h"
69#ifdef HAVE_RECORDING 72#ifdef HAVE_RECORDING
70 73
71#define PM_HEIGHT ((LCD_HEIGHT >= 72) ? 2 : 1) 74#define PM_HEIGHT ((LCD_HEIGHT >= 72) ? 2 : 1)
@@ -73,21 +76,6 @@
73bool f2_rec_screen(void); 76bool f2_rec_screen(void);
74bool f3_rec_screen(void); 77bool f3_rec_screen(void);
75 78
76#define SOURCE_MIC 0
77#define SOURCE_LINE 1
78#ifdef HAVE_SPDIF_IN
79#define SOURCE_SPDIF 2
80#define MAX_SOURCE SOURCE_SPDIF
81#else
82#define MAX_SOURCE SOURCE_LINE
83#endif
84
85#if CONFIG_CODEC == SWCODEC
86#define REC_FILE_ENDING ".wav"
87#else
88#define REC_FILE_ENDING ".mp3"
89#endif
90
91#define MAX_FILE_SIZE 0x7F800000 /* 2 GB - 4 MB */ 79#define MAX_FILE_SIZE 0x7F800000 /* 2 GB - 4 MB */
92 80
93int screen_update = NB_SCREENS; 81int screen_update = NB_SCREENS;
@@ -102,6 +90,19 @@ const char* const freq_str[6] =
102 "16kHz" 90 "16kHz"
103}; 91};
104 92
93#if CONFIG_CODEC == SWCODEC
94#define REC_ENCODER_ID(q) \
95 rec_quality_info_afmt[q]
96#define REC_QUALITY_LABEL(q) \
97 (audio_formats[REC_ENCODER_ID(q)].label)
98#define REC_FILE_ENDING(q) \
99 (audio_formats[REC_ENCODER_ID(q)].ext)
100#else
101/* default record file extension for HWCODEC */
102#define REC_QUALITY_LABEL(q) "MP3"
103#define REC_FILE_ENDING(q) ".mp3"
104#endif
105
105#ifdef HAVE_AGC 106#ifdef HAVE_AGC
106/* Timing counters: 107/* Timing counters:
107 * peak_time is incremented every 0.2s, every 2nd run of record screen loop. 108 * peak_time is incremented every 0.2s, every 2nd run of record screen loop.
@@ -161,13 +162,14 @@ static short agc_maxgain;
161 162
162static void set_gain(void) 163static void set_gain(void)
163{ 164{
164 if(global_settings.rec_source == SOURCE_MIC) 165 if(global_settings.rec_source == AUDIO_SRC_MIC)
165 { 166 {
166 audio_set_recording_gain(global_settings.rec_mic_gain, 167 audio_set_recording_gain(global_settings.rec_mic_gain,
167 0, AUDIO_GAIN_MIC); 168 0, AUDIO_GAIN_MIC);
168 } 169 }
169 else 170 else
170 { 171 {
172 /* AUDIO_SRC_LINEIN, AUDIO_SRC_SPDIF, AUDIO_SRC_FMRADIO */
171 audio_set_recording_gain(global_settings.rec_left_gain, 173 audio_set_recording_gain(global_settings.rec_left_gain,
172 global_settings.rec_right_gain, 174 global_settings.rec_right_gain,
173 AUDIO_GAIN_LINEIN); 175 AUDIO_GAIN_LINEIN);
@@ -217,12 +219,16 @@ bool agc_gain_is_max(bool left, bool right)
217 if (agc_preset == 0) 219 if (agc_preset == 0)
218 return false; 220 return false;
219 221
220 if (global_settings.rec_source == SOURCE_LINE) 222 switch (global_settings.rec_source)
221 { 223 {
224 case AUDIO_SRC_LINEIN:
225#ifdef HAVE_FMRADIO_IN
226 case AUDIO_SRC_FMRADIO:
227#endif
222 gain_current_l = global_settings.rec_left_gain; 228 gain_current_l = global_settings.rec_left_gain;
223 gain_current_r = global_settings.rec_right_gain; 229 gain_current_r = global_settings.rec_right_gain;
224 } else 230 break;
225 { 231 default:
226 gain_current_l = global_settings.rec_mic_gain; 232 gain_current_l = global_settings.rec_mic_gain;
227 gain_current_r = global_settings.rec_mic_gain; 233 gain_current_r = global_settings.rec_mic_gain;
228 } 234 }
@@ -235,13 +241,16 @@ void change_recording_gain(bool increment, bool left, bool right)
235{ 241{
236 int factor = (increment ? 1 : -1); 242 int factor = (increment ? 1 : -1);
237 243
238 if (global_settings.rec_source == SOURCE_LINE) 244 switch (global_settings.rec_source)
239 { 245 {
246 case AUDIO_SRC_LINEIN:
247#ifdef HAVE_FMRADIO_IN
248 case AUDIO_SRC_FMRADIO:
249#endif
240 if(left) global_settings.rec_left_gain += factor; 250 if(left) global_settings.rec_left_gain += factor;
241 if (right) global_settings.rec_right_gain += factor; 251 if (right) global_settings.rec_right_gain += factor;
242 } 252 break;
243 else 253 default:
244 {
245 global_settings.rec_mic_gain += factor; 254 global_settings.rec_mic_gain += factor;
246 } 255 }
247} 256}
@@ -443,12 +452,15 @@ void adjust_cursor(void)
443#ifdef HAVE_AGC 452#ifdef HAVE_AGC
444 switch(global_settings.rec_source) 453 switch(global_settings.rec_source)
445 { 454 {
446 case SOURCE_MIC: 455 case AUDIO_SRC_MIC:
447 if(cursor == 2) 456 if(cursor == 2)
448 cursor = 4; 457 cursor = 4;
449 else if(cursor == 3) 458 else if(cursor == 3)
450 cursor = 1; 459 cursor = 1;
451 case SOURCE_LINE: 460 case AUDIO_SRC_LINEIN:
461#ifdef HAVE_FMRADIO_IN
462 case AUDIO_SRC_FMRADIO:
463#endif
452 max_cursor = 5; 464 max_cursor = 5;
453 break; 465 break;
454 default: 466 default:
@@ -458,10 +470,13 @@ void adjust_cursor(void)
458#else 470#else
459 switch(global_settings.rec_source) 471 switch(global_settings.rec_source)
460 { 472 {
461 case SOURCE_MIC: 473 case AUDIO_SRC_MIC:
462 max_cursor = 1; 474 max_cursor = 1;
463 break; 475 break;
464 case SOURCE_LINE: 476 case AUDIO_SRC_LINEIN:
477#ifdef HAVE_FMRADIO_IN
478 case AUDIO_SRC_FMRADIO:
479#endif
465 max_cursor = 3; 480 max_cursor = 3;
466 break; 481 break;
467 default: 482 default:
@@ -481,10 +496,13 @@ char *rec_create_filename(char *buffer)
481 else 496 else
482 strncpy(buffer, rec_base_directory, MAX_PATH); 497 strncpy(buffer, rec_base_directory, MAX_PATH);
483 498
499
484#ifdef CONFIG_RTC 500#ifdef CONFIG_RTC
485 create_datetime_filename(buffer, buffer, "R", REC_FILE_ENDING); 501 create_datetime_filename(buffer, buffer, "R",
502 REC_FILE_ENDING(global_settings.rec_quality));
486#else 503#else
487 create_numbered_filename(buffer, buffer, "rec_", REC_FILE_ENDING, 4); 504 create_numbered_filename(buffer, buffer, "rec_",
505 REC_FILE_ENDING(global_settings.rec_quality), 4);
488#endif 506#endif
489 return buffer; 507 return buffer;
490} 508}
@@ -515,8 +533,190 @@ int rec_create_directory(void)
515 return 0; 533 return 0;
516} 534}
517 535
536#if CONFIG_CODEC == SWCODEC && !defined(SIMULATOR)
537/**
538 * Selects an audio source for recording or playback
539 * powers/unpowers related devices.
540 * Here because it calls app code and used only for HAVE_RECORDING atm.
541 * Would like it in pcm_record.c.
542 */
543#if defined(HAVE_UDA1380)
544#define ac_disable_recording uda1380_disable_recording
545#define ac_enable_recording uda1380_enable_recording
546#define ac_set_monitor uda1380_set_monitor
547#elif defined(HAVE_TLV320)
548#define ac_disable_recording tlv320_disable_recording
549#define ac_enable_recording tlv320_enable_recording
550#define ac_set_monitor tlv320_set_monitor
551#endif
552
553void rec_set_source(int source, int flags)
554{
555 /* Prevent pops from unneeded switching */
556 static int last_source = AUDIO_SRC_PLAYBACK;
557#ifdef HAVE_TLV320
558 static bool last_recording = false;
559#endif
560
561 bool recording = flags & SRCF_RECORDING;
562 /* Default to peakmeter record. */
563 bool pm_playback = false;
564 bool pm_enabled = true;
565
566 /** Do power up/down of associated device(s) **/
567
568#ifdef HAVE_SPDIF_IN
569 if ((source == AUDIO_SRC_SPDIF) != (source == last_source))
570 cpu_boost(source == AUDIO_SRC_SPDIF);
571
572#ifdef HAVE_SPDIF_POWER
573 /* Check if S/PDIF output power should be switched off or on. NOTE: assumes
574 both optical in and out is controlled by the same power source, which is
575 the case on H1x0. */
576 spdif_power_enable((source == AUDIO_SRC_SPDIF) ||
577 global_settings.spdif_enable);
578#endif
579#endif
580
581#ifdef CONFIG_TUNER
582 /* Switch radio off or on per source and flags. */
583 if (source != AUDIO_SRC_FMRADIO)
584 radio_stop();
585 else if (flags & SRCF_FMRADIO_PAUSED)
586 radio_pause();
587 else
588 radio_start();
589#endif
590
591 switch (source)
592 {
593 default: /* playback - no recording */
594 pm_playback = true;
595 if (source == last_source)
596 break;
597 ac_disable_recording();
598 ac_set_monitor(false);
599 pcm_rec_mux(0); /* line in */
600 break;
601
602 case AUDIO_SRC_MIC: /* recording only */
603 if (source == last_source)
604 break;
605 ac_enable_recording(true); /* source mic */
606 pcm_rec_mux(0); /* line in */
607 break;
608
609 case AUDIO_SRC_LINEIN: /* recording only */
610 if (source == last_source)
611 break;
612 pcm_rec_mux(0); /* line in */
613 ac_enable_recording(false); /* source line */
614 break;
615
616#ifdef HAVE_SPDIF_IN
617 case AUDIO_SRC_SPDIF: /* recording only */
618 if (recording)
619 {
620 /* This was originally done in audio_set_recording_options only */
621#ifdef HAVE_SPDIF_POWER
622 EBU1CONFIG = global_settings.spdif_enable ? (1 << 2) : 0;
623 /* Input source is EBUin1, Feed-through monitoring if desired */
624#else
625 EBU1CONFIG = (1 << 2);
626 /* Input source is EBUin1, Feed-through monitoring */
627#endif
628 }
629
630 if (source != last_source)
631 uda1380_disable_recording();
632 break;
633#endif /* HAVE_SPDIF_IN */
634
635#ifdef HAVE_FMRADIO_IN
636 case AUDIO_SRC_FMRADIO:
637 if (!recording)
638 {
639 audio_set_recording_gain(sound_default(SOUND_LEFT_GAIN),
640 sound_default(SOUND_RIGHT_GAIN), AUDIO_GAIN_LINEIN);
641 pm_playback = true;
642 pm_enabled = false;
643 }
644
645 pcm_rec_mux(1); /* fm radio */
646
647#ifdef HAVE_UDA1380
648 if (source == last_source)
649 break;
650 /* I2S recording and playback */
651 uda1380_enable_recording(false); /* source line */
652 uda1380_set_monitor(true);
653#endif
654#ifdef HAVE_TLV320
655 /* I2S recording and analog playback */
656 if (source == last_source && recording == last_recording)
657 break;
658
659 last_recording = recording;
660
661 if (recording)
662 tlv320_enable_recording(false); /* source line */
663 else
664 {
665 tlv320_disable_recording();
666 tlv320_set_monitor(true); /* analog bypass */
667 }
668#endif
669 break;
670/* #elif defined(CONFIG_TUNER) */
671/* Have radio but cannot record it */
672/* case AUDIO_SRC_FMRADIO: */
673/* break; */
674#endif /* HAVE_FMRADIO_IN */
675 } /* end switch */
676
677 peak_meter_playback(pm_playback);
678 peak_meter_enabled = pm_enabled;
679
680 last_source = source;
681} /* rec_set_source */
682#endif /* CONFIG_CODEC == SWCODEC && !defined(SIMULATOR) */
683
684/* steal the mp3 buffer then actually set options */
685void rec_set_recording_options(int frequency, int quality,
686 int source, int source_flags,
687 int channel_mode, bool editable,
688 int prerecord_time)
689{
690#if CONFIG_CODEC != SWCODEC
691 if (global_settings.rec_prerecord_time)
692#endif
693 talk_buffer_steal(); /* will use the mp3 buffer */
694
695#if CONFIG_CODEC == SWCODEC
696 rec_set_source(source, source_flags | SRCF_RECORDING);
697#else
698 (void)source_flags;
699#endif
700
701 audio_set_recording_options(frequency, quality, source,
702 channel_mode, editable, prerecord_time);
703}
704
518static char path_buffer[MAX_PATH]; 705static char path_buffer[MAX_PATH];
519 706
707/* steals mp3 buffer, creates unique filename and starts recording */
708void rec_record(void)
709{
710 talk_buffer_steal(); /* we use the mp3 buffer */
711 audio_record(rec_create_filename(path_buffer));
712}
713
714/* creates unique filename and starts recording */
715void rec_new_file(void)
716{
717 audio_new_file(rec_create_filename(path_buffer));
718}
719
520/* used in trigger_listerner and recording_screen */ 720/* used in trigger_listerner and recording_screen */
521static unsigned int last_seconds = 0; 721static unsigned int last_seconds = 0;
522 722
@@ -533,16 +733,16 @@ static void trigger_listener(int trigger_status)
533 if((audio_status() & AUDIO_STATUS_RECORD) != AUDIO_STATUS_RECORD) 733 if((audio_status() & AUDIO_STATUS_RECORD) != AUDIO_STATUS_RECORD)
534 { 734 {
535 talk_buffer_steal(); /* we use the mp3 buffer */ 735 talk_buffer_steal(); /* we use the mp3 buffer */
536 audio_record(rec_create_filename(path_buffer)); 736 rec_record();
537 737 /* give control to mpeg thread so that it can start
538 /* give control to mpeg thread so that it can start recording*/ 738 recording */
539 yield(); yield(); yield(); 739 yield(); yield(); yield();
540 } 740 }
541 741
542 /* if we're already recording this is a retrigger */ 742 /* if we're already recording this is a retrigger */
543 else 743 else
544 { 744 {
545 audio_new_file(rec_create_filename(path_buffer)); 745 rec_new_file();
546 /* tell recording_screen to reset the time */ 746 /* tell recording_screen to reset the time */
547 last_seconds = 0; 747 last_seconds = 0;
548 } 748 }
@@ -563,10 +763,9 @@ static void trigger_listener(int trigger_status)
563 } 763 }
564} 764}
565 765
566bool recording_screen(void) 766bool recording_screen(bool no_source)
567{ 767{
568 long button; 768 long button;
569 long lastbutton = BUTTON_NONE;
570 bool done = false; 769 bool done = false;
571 char buf[32]; 770 char buf[32];
572 char buf2[32]; 771 char buf2[32];
@@ -575,11 +774,19 @@ bool recording_screen(void)
575 bool have_recorded = false; 774 bool have_recorded = false;
576 unsigned int seconds; 775 unsigned int seconds;
577 int hours, minutes; 776 int hours, minutes;
578 char path_buffer[MAX_PATH];
579 char filename[13]; 777 char filename[13];
580 bool been_in_usb_mode = false; 778 bool been_in_usb_mode = false;
581 int last_audio_stat = -1; 779 int last_audio_stat = -1;
582 int audio_stat; 780 int audio_stat;
781#ifdef HAVE_FMRADIO_IN
782 /* Radio is left on if:
783 * 1) Is was on at the start and the initial source is FM Radio
784 * 2) 1) and the source was never changed to something else
785 */
786 int radio_status = (global_settings.rec_source != AUDIO_SRC_FMRADIO) ?
787 FMRADIO_OFF : get_radio_status();
788#endif
789 int talk_menu = global_settings.talk_menu;
583#if CONFIG_LED == LED_REAL 790#if CONFIG_LED == LED_REAL
584 bool led_state = false; 791 bool led_state = false;
585 int led_countdown = 2; 792 int led_countdown = 2;
@@ -608,6 +815,18 @@ bool recording_screen(void)
608 ata_set_led_enabled(false); 815 ata_set_led_enabled(false);
609#endif 816#endif
610 817
818#if CONFIG_CODEC == SWCODEC
819 audio_stop();
820 voice_stop();
821 /* recording_menu gets messed up: so reset talk_menu */
822 talk_menu = global_settings.talk_menu;
823 global_settings.talk_menu = 0;
824#else
825 /* Yes, we use the D/A for monitoring */
826 peak_meter_enabled = true;
827 peak_meter_playback(true);
828#endif
829
611#ifndef SIMULATOR 830#ifndef SIMULATOR
612 audio_init_recording(talk_get_bufsize()); 831 audio_init_recording(talk_get_bufsize());
613#else 832#else
@@ -616,44 +835,19 @@ bool recording_screen(void)
616 835
617 sound_set_volume(global_settings.volume); 836 sound_set_volume(global_settings.volume);
618 837
619#if CONFIG_CODEC == SWCODEC
620 audio_stop();
621 /* Set peak meter to recording mode */
622 peak_meter_playback(false);
623
624#if defined(HAVE_SPDIF_IN) && !defined(SIMULATOR)
625 if (global_settings.rec_source == SOURCE_SPDIF)
626 cpu_boost(true);
627#endif
628
629#else
630 /* Yes, we use the D/A for monitoring */
631 peak_meter_playback(true);
632#endif
633 peak_meter_enabled = true;
634#ifdef HAVE_AGC 838#ifdef HAVE_AGC
635 peak_meter_get_peakhold(&peak_l, &peak_r); 839 peak_meter_get_peakhold(&peak_l, &peak_r);
636#endif 840#endif
637 841
638#if CONFIG_CODEC != SWCODEC 842 rec_set_recording_options(global_settings.rec_frequency,
639 if (global_settings.rec_prerecord_time) 843 global_settings.rec_quality,
640#endif 844 global_settings.rec_source,
641 talk_buffer_steal(); /* will use the mp3 buffer */ 845 0,
642 846 global_settings.rec_channels,
643#if defined(HAVE_SPDIF_POWER) && !defined(SIMULATOR) 847 global_settings.rec_editable,
644 /* Tell recording whether we want S/PDIF power enabled at all times */ 848 global_settings.rec_prerecord_time);
645 audio_set_spdif_power_setting(global_settings.spdif_enable);
646#endif
647
648 audio_set_recording_options(global_settings.rec_frequency,
649 global_settings.rec_quality,
650 global_settings.rec_source,
651 global_settings.rec_channels,
652 global_settings.rec_editable,
653 global_settings.rec_prerecord_time);
654 849
655 set_gain(); 850 set_gain();
656
657 settings_apply_trigger(); 851 settings_apply_trigger();
658 852
659#ifdef HAVE_AGC 853#ifdef HAVE_AGC
@@ -663,7 +857,7 @@ bool recording_screen(void)
663 agc_preset_str[3] = str(LANG_AGC_DJSET); 857 agc_preset_str[3] = str(LANG_AGC_DJSET);
664 agc_preset_str[4] = str(LANG_AGC_MEDIUM); 858 agc_preset_str[4] = str(LANG_AGC_MEDIUM);
665 agc_preset_str[5] = str(LANG_AGC_VOICE); 859 agc_preset_str[5] = str(LANG_AGC_VOICE);
666 if (global_settings.rec_source == SOURCE_MIC) { 860 if (global_settings.rec_source == AUDIO_SRC_MIC) {
667 agc_preset = global_settings.rec_agc_preset_mic; 861 agc_preset = global_settings.rec_agc_preset_mic;
668 agc_maxgain = global_settings.rec_agc_maxgain_mic; 862 agc_maxgain = global_settings.rec_agc_maxgain_mic;
669 } 863 }
@@ -697,11 +891,7 @@ bool recording_screen(void)
697 891
698 while(!done) 892 while(!done)
699 { 893 {
700#if CONFIG_CODEC == SWCODEC
701 audio_stat = pcm_rec_status();
702#else
703 audio_stat = audio_status(); 894 audio_stat = audio_status();
704#endif
705 895
706#if CONFIG_LED == LED_REAL 896#if CONFIG_LED == LED_REAL
707 897
@@ -794,8 +984,8 @@ bool recording_screen(void)
794 } 984 }
795 else 985 else
796 { 986 {
797 peak_meter_playback(true);
798#if CONFIG_CODEC != SWCODEC 987#if CONFIG_CODEC != SWCODEC
988 peak_meter_playback(true);
799 peak_meter_enabled = false; 989 peak_meter_enabled = false;
800#endif 990#endif
801 done = true; 991 done = true;
@@ -815,14 +1005,13 @@ bool recording_screen(void)
815 /* manual recording */ 1005 /* manual recording */
816 have_recorded = true; 1006 have_recorded = true;
817 talk_buffer_steal(); /* we use the mp3 buffer */ 1007 talk_buffer_steal(); /* we use the mp3 buffer */
818 audio_record(rec_create_filename(path_buffer)); 1008 rec_record();
819 last_seconds = 0; 1009 last_seconds = 0;
820 if (global_settings.talk_menu) 1010 if (talk_menu)
821 { /* no voice possible here, but a beep */ 1011 { /* no voice possible here, but a beep */
822 audio_beep(HZ/2); /* longer beep on start */ 1012 audio_beep(HZ/2); /* longer beep on start */
823 } 1013 }
824 } 1014 }
825
826 /* this is triggered recording */ 1015 /* this is triggered recording */
827 else 1016 else
828 { 1017 {
@@ -838,7 +1027,7 @@ bool recording_screen(void)
838 /*if new file button pressed, start new file */ 1027 /*if new file button pressed, start new file */
839 if (button == ACTION_REC_NEWFILE) 1028 if (button == ACTION_REC_NEWFILE)
840 { 1029 {
841 audio_new_file(rec_create_filename(path_buffer)); 1030 rec_new_file();
842 last_seconds = 0; 1031 last_seconds = 0;
843 } 1032 }
844 else 1033 else
@@ -847,7 +1036,7 @@ bool recording_screen(void)
847 if(audio_stat & AUDIO_STATUS_PAUSE) 1036 if(audio_stat & AUDIO_STATUS_PAUSE)
848 { 1037 {
849 audio_resume_recording(); 1038 audio_resume_recording();
850 if (global_settings.talk_menu) 1039 if (talk_menu)
851 { /* no voice possible here, but a beep */ 1040 { /* no voice possible here, but a beep */
852 audio_beep(HZ/4); /* short beep on resume */ 1041 audio_beep(HZ/4); /* short beep on resume */
853 } 1042 }
@@ -883,7 +1072,7 @@ bool recording_screen(void)
883 sound_set_volume(global_settings.volume); 1072 sound_set_volume(global_settings.volume);
884 break; 1073 break;
885 case 1: 1074 case 1:
886 if(global_settings.rec_source == SOURCE_MIC) 1075 if(global_settings.rec_source == AUDIO_SRC_MIC)
887 { 1076 {
888 if(global_settings.rec_mic_gain < 1077 if(global_settings.rec_mic_gain <
889 sound_max(SOUND_MIC_GAIN)) 1078 sound_max(SOUND_MIC_GAIN))
@@ -913,7 +1102,7 @@ bool recording_screen(void)
913 case 4: 1102 case 4:
914 agc_preset = MIN(agc_preset + 1, AGC_MODE_SIZE); 1103 agc_preset = MIN(agc_preset + 1, AGC_MODE_SIZE);
915 agc_enable = (agc_preset != 0); 1104 agc_enable = (agc_preset != 0);
916 if (global_settings.rec_source == SOURCE_MIC) { 1105 if (global_settings.rec_source == AUDIO_SRC_MIC) {
917 global_settings.rec_agc_preset_mic = agc_preset; 1106 global_settings.rec_agc_preset_mic = agc_preset;
918 agc_maxgain = global_settings.rec_agc_maxgain_mic; 1107 agc_maxgain = global_settings.rec_agc_maxgain_mic;
919 } else { 1108 } else {
@@ -922,7 +1111,7 @@ bool recording_screen(void)
922 } 1111 }
923 break; 1112 break;
924 case 5: 1113 case 5:
925 if (global_settings.rec_source == SOURCE_MIC) 1114 if (global_settings.rec_source == AUDIO_SRC_MIC)
926 { 1115 {
927 agc_maxgain = MIN(agc_maxgain + 1, 1116 agc_maxgain = MIN(agc_maxgain + 1,
928 sound_max(SOUND_MIC_GAIN)); 1117 sound_max(SOUND_MIC_GAIN));
@@ -951,7 +1140,7 @@ bool recording_screen(void)
951 sound_set_volume(global_settings.volume); 1140 sound_set_volume(global_settings.volume);
952 break; 1141 break;
953 case 1: 1142 case 1:
954 if(global_settings.rec_source == SOURCE_MIC) 1143 if(global_settings.rec_source == AUDIO_SRC_MIC)
955 { 1144 {
956 if(global_settings.rec_mic_gain > 1145 if(global_settings.rec_mic_gain >
957 sound_min(SOUND_MIC_GAIN)) 1146 sound_min(SOUND_MIC_GAIN))
@@ -981,7 +1170,7 @@ bool recording_screen(void)
981 case 4: 1170 case 4:
982 agc_preset = MAX(agc_preset - 1, 0); 1171 agc_preset = MAX(agc_preset - 1, 0);
983 agc_enable = (agc_preset != 0); 1172 agc_enable = (agc_preset != 0);
984 if (global_settings.rec_source == SOURCE_MIC) { 1173 if (global_settings.rec_source == AUDIO_SRC_MIC) {
985 global_settings.rec_agc_preset_mic = agc_preset; 1174 global_settings.rec_agc_preset_mic = agc_preset;
986 agc_maxgain = global_settings.rec_agc_maxgain_mic; 1175 agc_maxgain = global_settings.rec_agc_maxgain_mic;
987 } else { 1176 } else {
@@ -990,7 +1179,7 @@ bool recording_screen(void)
990 } 1179 }
991 break; 1180 break;
992 case 5: 1181 case 5:
993 if (global_settings.rec_source == SOURCE_MIC) 1182 if (global_settings.rec_source == AUDIO_SRC_MIC)
994 { 1183 {
995 agc_maxgain = MAX(agc_maxgain - 1, 1184 agc_maxgain = MAX(agc_maxgain - 1,
996 sound_min(SOUND_MIC_GAIN)); 1185 sound_min(SOUND_MIC_GAIN));
@@ -1012,49 +1201,73 @@ bool recording_screen(void)
1012 case ACTION_STD_MENU: 1201 case ACTION_STD_MENU:
1013 if(audio_stat != AUDIO_STATUS_RECORD) 1202 if(audio_stat != AUDIO_STATUS_RECORD)
1014 { 1203 {
1204#ifdef HAVE_FMRADIO_IN
1205 const int prev_rec_source = global_settings.rec_source;
1206#endif
1207
1015#if CONFIG_LED == LED_REAL 1208#if CONFIG_LED == LED_REAL
1016 /* led is restored at begin of loop / end of function */ 1209 /* led is restored at begin of loop / end of function */
1017 led(false); 1210 led(false);
1018#endif 1211#endif
1019 if (recording_menu(false)) 1212 if (recording_menu(no_source))
1020 { 1213 {
1021 return SYS_USB_CONNECTED; 1214 done = true;
1215 been_in_usb_mode = true;
1216#ifdef HAVE_FMRADIO_IN
1217 radio_status = FMRADIO_OFF;
1218#endif
1022 } 1219 }
1023 settings_save(); 1220 else
1221 {
1222 settings_save();
1223
1224#ifdef HAVE_FMRADIO_IN
1225 /* If input changes away from FM Radio, radio will
1226 remain off when recording screen closes. */
1227 if (global_settings.rec_source != prev_rec_source
1228 && prev_rec_source == AUDIO_SRC_FMRADIO)
1229 radio_status = FMRADIO_OFF;
1230#endif
1024 1231
1025#if CONFIG_CODEC != SWCODEC 1232#if CONFIG_CODEC == SWCODEC
1026 if (global_settings.rec_prerecord_time) 1233 /* reinit after submenu exit */
1234 audio_close_recording();
1235 audio_init_recording(talk_get_bufsize());
1027#endif 1236#endif
1028 talk_buffer_steal(); /* will use the mp3 buffer */ 1237 rec_set_recording_options(
1029 1238 global_settings.rec_frequency,
1030 audio_set_recording_options(global_settings.rec_frequency, 1239 global_settings.rec_quality,
1031 global_settings.rec_quality, 1240 global_settings.rec_source,
1032 global_settings.rec_source, 1241 0,
1033 global_settings.rec_channels, 1242 global_settings.rec_channels,
1034 global_settings.rec_editable, 1243 global_settings.rec_editable,
1035 global_settings.rec_prerecord_time); 1244 global_settings.rec_prerecord_time);
1245
1036#ifdef HAVE_AGC 1246#ifdef HAVE_AGC
1037 if (global_settings.rec_source == SOURCE_MIC) { 1247 if (global_settings.rec_source == AUDIO_SRC_MIC) {
1038 agc_preset = global_settings.rec_agc_preset_mic; 1248 agc_preset = global_settings.rec_agc_preset_mic;
1039 agc_maxgain = global_settings.rec_agc_maxgain_mic; 1249 agc_maxgain = global_settings.rec_agc_maxgain_mic;
1040 } 1250 }
1041 else { 1251 else {
1042 agc_preset = global_settings.rec_agc_preset_line; 1252 agc_preset = global_settings.rec_agc_preset_line;
1043 agc_maxgain = global_settings.rec_agc_maxgain_line; 1253 agc_maxgain = global_settings.rec_agc_maxgain_line;
1044 } 1254 }
1045#endif 1255#endif
1046 1256
1047 adjust_cursor(); 1257 adjust_cursor();
1048 set_gain(); 1258 set_gain();
1049 update_countdown = 1; /* Update immediately */ 1259 update_countdown = 1; /* Update immediately */
1050 1260
1051 FOR_NB_SCREENS(i) 1261 FOR_NB_SCREENS(i)
1052 { 1262 {
1053 screens[i].setfont(FONT_SYSFIXED); 1263 screens[i].setfont(FONT_SYSFIXED);
1054 screens[i].setmargins(global_settings.invert_cursor ? 0 : w, 8); 1264 screens[i].setmargins(
1265 global_settings.invert_cursor ? 0 : w, 8);
1266 }
1055 } 1267 }
1056 } 1268 }
1057 break; 1269 break;
1270
1058#if CONFIG_KEYPAD == RECORDER_PAD 1271#if CONFIG_KEYPAD == RECORDER_PAD
1059 case ACTION_REC_F2: 1272 case ACTION_REC_F2:
1060 if(audio_stat != AUDIO_STATUS_RECORD) 1273 if(audio_stat != AUDIO_STATUS_RECORD)
@@ -1076,7 +1289,7 @@ bool recording_screen(void)
1076 case ACTION_REC_F3: 1289 case ACTION_REC_F3:
1077 if(audio_stat & AUDIO_STATUS_RECORD) 1290 if(audio_stat & AUDIO_STATUS_RECORD)
1078 { 1291 {
1079 audio_new_file(rec_create_filename(path_buffer)); 1292 rec_new_file();
1080 last_seconds = 0; 1293 last_seconds = 0;
1081 } 1294 }
1082 else 1295 else
@@ -1097,7 +1310,7 @@ bool recording_screen(void)
1097 } 1310 }
1098 } 1311 }
1099 break; 1312 break;
1100#endif 1313#endif /* CONFIG_KEYPAD == RECORDER_PAD */
1101 1314
1102 case SYS_USB_CONNECTED: 1315 case SYS_USB_CONNECTED:
1103 /* Only accept USB connection when not recording */ 1316 /* Only accept USB connection when not recording */
@@ -1106,6 +1319,9 @@ bool recording_screen(void)
1106 default_event_handler(SYS_USB_CONNECTED); 1319 default_event_handler(SYS_USB_CONNECTED);
1107 done = true; 1320 done = true;
1108 been_in_usb_mode = true; 1321 been_in_usb_mode = true;
1322#ifdef HAVE_FMRADIO_IN
1323 radio_status = FMRADIO_OFF;
1324#endif
1109 } 1325 }
1110 break; 1326 break;
1111 1327
@@ -1113,8 +1329,6 @@ bool recording_screen(void)
1113 default_event_handler(button); 1329 default_event_handler(button);
1114 break; 1330 break;
1115 } 1331 }
1116 if (button != BUTTON_NONE)
1117 lastbutton = button;
1118 1332
1119#ifdef HAVE_AGC 1333#ifdef HAVE_AGC
1120 peak_read = !peak_read; 1334 peak_read = !peak_read;
@@ -1230,7 +1444,7 @@ bool recording_screen(void)
1230 if (!(global_settings.rec_split_type) 1444 if (!(global_settings.rec_split_type)
1231 || (num_recorded_bytes >= MAX_FILE_SIZE)) 1445 || (num_recorded_bytes >= MAX_FILE_SIZE))
1232 { 1446 {
1233 audio_new_file(rec_create_filename(path_buffer)); 1447 rec_new_file();
1234 last_seconds = 0; 1448 last_seconds = 0;
1235 } 1449 }
1236 else 1450 else
@@ -1259,8 +1473,9 @@ bool recording_screen(void)
1259 screens[i].puts(0, filename_offset[i] + PM_HEIGHT + 2, buf); 1473 screens[i].puts(0, filename_offset[i] + PM_HEIGHT + 2, buf);
1260 } 1474 }
1261 1475
1262 if(global_settings.rec_source == SOURCE_MIC) 1476 if(global_settings.rec_source == AUDIO_SRC_MIC)
1263 { 1477 {
1478 /* Draw MIC recording gain */
1264 snprintf(buf, 32, "%s:%s", str(LANG_SYSFONT_RECORDING_GAIN), 1479 snprintf(buf, 32, "%s:%s", str(LANG_SYSFONT_RECORDING_GAIN),
1265 fmt_gain(SOUND_MIC_GAIN, 1480 fmt_gain(SOUND_MIC_GAIN,
1266 global_settings.rec_mic_gain, 1481 global_settings.rec_mic_gain,
@@ -1278,8 +1493,13 @@ bool recording_screen(void)
1278 PM_HEIGHT + 3, buf); 1493 PM_HEIGHT + 3, buf);
1279 } 1494 }
1280 } 1495 }
1281 else if(global_settings.rec_source == SOURCE_LINE) 1496 else if(global_settings.rec_source == AUDIO_SRC_LINEIN
1497#ifdef HAVE_FMRADIO_IN
1498 || global_settings.rec_source == AUDIO_SRC_FMRADIO
1499#endif
1500 )
1282 { 1501 {
1502 /* Draw LINE or FMRADIO recording gain */
1283 snprintf(buf, 32, "%s:%s", 1503 snprintf(buf, 32, "%s:%s",
1284 str(LANG_SYSFONT_RECORDING_LEFT), 1504 str(LANG_SYSFONT_RECORDING_LEFT),
1285 fmt_gain(SOUND_LEFT_GAIN, 1505 fmt_gain(SOUND_LEFT_GAIN,
@@ -1319,14 +1539,23 @@ bool recording_screen(void)
1319 1539
1320 FOR_NB_SCREENS(i) 1540 FOR_NB_SCREENS(i)
1321 { 1541 {
1322 if (global_settings.rec_source == SOURCE_LINE) 1542 switch (global_settings.rec_source)
1543 {
1544 case AUDIO_SRC_LINEIN:
1545#ifdef HAVE_FMRADIO_IN
1546 case AUDIO_SRC_FMRADIO:
1547#endif
1323 line[i] = 5; 1548 line[i] = 5;
1324 else if (global_settings.rec_source == SOURCE_MIC) 1549 break;
1550 case AUDIO_SRC_MIC:
1325 line[i] = 4; 1551 line[i] = 4;
1552 break;
1326#ifdef HAVE_SPDIF_IN 1553#ifdef HAVE_SPDIF_IN
1327 else if (global_settings.rec_source == SOURCE_SPDIF) 1554 case AUDIO_SRC_SPDIF:
1328 line[i] = 3; 1555 line[i] = 3;
1556 break;
1329#endif 1557#endif
1558 } /* end switch */
1330#ifdef HAVE_AGC 1559#ifdef HAVE_AGC
1331 if (screens[i].height < h * (2 + filename_offset[i] + PM_HEIGHT + line[i])) 1560 if (screens[i].height < h * (2 + filename_offset[i] + PM_HEIGHT + line[i]))
1332 { 1561 {
@@ -1358,7 +1587,7 @@ bool recording_screen(void)
1358 snprintf(buf, 32, "%s: %s", 1587 snprintf(buf, 32, "%s: %s",
1359 str(LANG_RECORDING_AGC_PRESET), 1588 str(LANG_RECORDING_AGC_PRESET),
1360 agc_preset_str[agc_preset]); 1589 agc_preset_str[agc_preset]);
1361 else if (global_settings.rec_source == SOURCE_MIC) 1590 else if (global_settings.rec_source == AUDIO_SRC_MIC)
1362 snprintf(buf, 32, "%s: %s%s", 1591 snprintf(buf, 32, "%s: %s%s",
1363 str(LANG_RECORDING_AGC_PRESET), 1592 str(LANG_RECORDING_AGC_PRESET),
1364 agc_preset_str[agc_preset], 1593 agc_preset_str[agc_preset],
@@ -1382,8 +1611,12 @@ bool recording_screen(void)
1382 screens[i].puts_style_offset(0, filename_offset[i] + 1611 screens[i].puts_style_offset(0, filename_offset[i] +
1383 PM_HEIGHT + line[i], buf, STYLE_INVERT,0); 1612 PM_HEIGHT + line[i], buf, STYLE_INVERT,0);
1384 } 1613 }
1385 else if ((global_settings.rec_source == SOURCE_MIC) 1614 else if (global_settings.rec_source == AUDIO_SRC_MIC
1386 || (global_settings.rec_source == SOURCE_LINE)) 1615 || global_settings.rec_source == AUDIO_SRC_LINEIN
1616#ifdef HAVE_FMRADIO_IN
1617 || global_settings.rec_source == AUDIO_SRC_FMRADIO
1618#endif
1619 )
1387 { 1620 {
1388 for(i = 0; i < screen_update; i++) { 1621 for(i = 0; i < screen_update; i++) {
1389 if (display_agc[i]) { 1622 if (display_agc[i]) {
@@ -1393,7 +1626,7 @@ bool recording_screen(void)
1393 } 1626 }
1394 } 1627 }
1395 1628
1396 if (global_settings.rec_source == SOURCE_MIC) 1629 if (global_settings.rec_source == AUDIO_SRC_MIC)
1397 { 1630 {
1398 if(agc_maxgain < (global_settings.rec_mic_gain)) 1631 if(agc_maxgain < (global_settings.rec_mic_gain))
1399 change_recording_gain(false, true, true); 1632 change_recording_gain(false, true, true);
@@ -1418,7 +1651,7 @@ bool recording_screen(void)
1418 filename_offset[i] + 1651 filename_offset[i] +
1419 PM_HEIGHT + 3, true); 1652 PM_HEIGHT + 3, true);
1420 1653
1421 if(global_settings.rec_source != SOURCE_MIC) 1654 if(global_settings.rec_source != AUDIO_SRC_MIC)
1422 { 1655 {
1423 for(i = 0; i < screen_update; i++) 1656 for(i = 0; i < screen_update; i++)
1424 screen_put_cursorxy(&screens[i], 0, 1657 screen_put_cursorxy(&screens[i], 0,
@@ -1456,14 +1689,14 @@ bool recording_screen(void)
1456 } 1689 }
1457/* Can't measure S/PDIF sample rate on Archos yet */ 1690/* Can't measure S/PDIF sample rate on Archos yet */
1458#if (CONFIG_CODEC != MAS3587F) && defined(HAVE_SPDIF_IN) && !defined(SIMULATOR) 1691#if (CONFIG_CODEC != MAS3587F) && defined(HAVE_SPDIF_IN) && !defined(SIMULATOR)
1459 if (global_settings.rec_source == SOURCE_SPDIF) 1692 if (global_settings.rec_source == AUDIO_SRC_SPDIF)
1460 snprintf(spdif_sfreq, 8, "%dHz", audio_get_spdif_sample_rate()); 1693 snprintf(spdif_sfreq, 8, "%dHz", audio_get_spdif_sample_rate());
1461#else 1694#else
1462 (void)spdif_sfreq; 1695 (void)spdif_sfreq;
1463#endif 1696#endif
1464 snprintf(buf, 32, "%s %s", 1697 snprintf(buf, 32, "%s %s",
1465#if (CONFIG_CODEC != MAS3587F) && defined(HAVE_SPDIF_IN) && !defined(SIMULATOR) 1698#if (CONFIG_CODEC != MAS3587F) && defined(HAVE_SPDIF_IN) && !defined(SIMULATOR)
1466 global_settings.rec_source == SOURCE_SPDIF ? 1699 global_settings.rec_source == AUDIO_SRC_SPDIF ?
1467 spdif_sfreq : 1700 spdif_sfreq :
1468#endif 1701#endif
1469 freq_str[global_settings.rec_frequency], 1702 freq_str[global_settings.rec_frequency],
@@ -1473,8 +1706,8 @@ bool recording_screen(void)
1473 1706
1474 for(i = 0; i < screen_update; i++) { 1707 for(i = 0; i < screen_update; i++) {
1475#ifdef HAVE_AGC 1708#ifdef HAVE_AGC
1476 if ((global_settings.rec_source == SOURCE_MIC) 1709 if ((global_settings.rec_source == AUDIO_SRC_MIC)
1477 || (global_settings.rec_source == SOURCE_LINE)) 1710 || (global_settings.rec_source == AUDIO_SRC_LINEIN))
1478 screens[i].puts(0, filename_offset[i] + PM_HEIGHT + line[i] + 1, buf); 1711 screens[i].puts(0, filename_offset[i] + PM_HEIGHT + line[i] + 1, buf);
1479 else 1712 else
1480#endif 1713#endif
@@ -1484,6 +1717,14 @@ bool recording_screen(void)
1484#ifdef HAVE_AGC 1717#ifdef HAVE_AGC
1485 hist_time++; 1718 hist_time++;
1486#endif 1719#endif
1720
1721#if CONFIG_CODEC == SWCODEC
1722 snprintf(buf, 32, "%s",
1723 REC_QUALITY_LABEL(global_settings.rec_quality));
1724 for(i = 0; i < screen_update; i++)
1725 screens[i].puts(0, filename_offset[i] + PM_HEIGHT + 6, buf);
1726#endif
1727
1487 for(i = 0; i < screen_update; i++) 1728 for(i = 0; i < screen_update; i++)
1488 { 1729 {
1489 gui_statusbar_draw(&(statusbars.statusbars[i]), true); 1730 gui_statusbar_draw(&(statusbars.statusbars[i]), true);
@@ -1506,7 +1747,7 @@ bool recording_screen(void)
1506 { 1747 {
1507 done = true; 1748 done = true;
1508 } 1749 }
1509 } 1750 } /* end while(!done) */
1510 1751
1511 1752
1512#if CONFIG_CODEC == SWCODEC 1753#if CONFIG_CODEC == SWCODEC
@@ -1531,18 +1772,26 @@ bool recording_screen(void)
1531 } 1772 }
1532 } 1773 }
1533 1774
1534#if CONFIG_CODEC == SWCODEC 1775#if CONFIG_CODEC == SWCODEC
1535 audio_stop_recording(); 1776 audio_stop_recording();
1536 audio_close_recording(); 1777 audio_close_recording();
1537 1778
1538#if defined(HAVE_SPDIF_IN) && !defined(SIMULATOR) 1779#ifdef HAVE_FMRADIO_IN
1539 if (global_settings.rec_source == SOURCE_SPDIF) 1780 if (radio_status != FMRADIO_OFF)
1540 cpu_boost(false); 1781 /* Restore radio playback - radio_status should be unchanged if started
1782 through fm radio screen (barring usb connect) */
1783 rec_set_source(AUDIO_SRC_FMRADIO, (radio_status & FMRADIO_PAUSED) ?
1784 SRCF_FMRADIO_PAUSED : SRCF_FMRADIO_PLAYING);
1785 else
1541#endif 1786#endif
1787 /* Go back to playback mode */
1788 rec_set_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK);
1542 1789
1543#else 1790 /* restore talk_menu setting */
1791 global_settings.talk_menu = talk_menu;
1792#else /* !SWCODEC */
1544 audio_init_playback(); 1793 audio_init_playback();
1545#endif 1794#endif /* CONFIG_CODEC == SWCODEC */
1546 1795
1547 /* make sure the trigger is really turned off */ 1796 /* make sure the trigger is really turned off */
1548 peak_meter_trigger(false); 1797 peak_meter_trigger(false);
@@ -1560,7 +1809,7 @@ bool recording_screen(void)
1560 ata_set_led_enabled(true); 1809 ata_set_led_enabled(true);
1561#endif 1810#endif
1562 return been_in_usb_mode; 1811 return been_in_usb_mode;
1563} 1812} /* recording_screen */
1564 1813
1565#if CONFIG_KEYPAD == RECORDER_PAD 1814#if CONFIG_KEYPAD == RECORDER_PAD
1566bool f2_rec_screen(void) 1815bool f2_rec_screen(void)
@@ -1680,15 +1929,13 @@ bool f2_rec_screen(void)
1680 } 1929 }
1681 } 1930 }
1682 1931
1683 if (global_settings.rec_prerecord_time) 1932 rec_set_recording_options(global_settings.rec_frequency,
1684 talk_buffer_steal(); /* will use the mp3 buffer */ 1933 global_settings.rec_quality,
1685 1934 global_settings.rec_source,
1686 audio_set_recording_options(global_settings.rec_frequency, 1935 0,
1687 global_settings.rec_quality, 1936 global_settings.rec_channels,
1688 global_settings.rec_source, 1937 global_settings.rec_editable,
1689 global_settings.rec_channels, 1938 global_settings.rec_prerecord_time);
1690 global_settings.rec_editable,
1691 global_settings.rec_prerecord_time);
1692 1939
1693 set_gain(); 1940 set_gain();
1694 1941
@@ -1760,7 +2007,7 @@ bool f3_rec_screen(void)
1760 case BUTTON_LEFT: 2007 case BUTTON_LEFT:
1761 case BUTTON_F3 | BUTTON_LEFT: 2008 case BUTTON_F3 | BUTTON_LEFT:
1762 global_settings.rec_source++; 2009 global_settings.rec_source++;
1763 if(global_settings.rec_source > MAX_SOURCE) 2010 if(global_settings.rec_source > AUDIO_SRC_MAX)
1764 global_settings.rec_source = 0; 2011 global_settings.rec_source = 0;
1765 used = true; 2012 used = true;
1766 break; 2013 break;
@@ -1782,16 +2029,13 @@ bool f3_rec_screen(void)
1782 } 2029 }
1783 } 2030 }
1784 2031
1785 if (global_settings.rec_prerecord_time) 2032 rec_set_recording_options(global_settings.rec_frequency,
1786 talk_buffer_steal(); /* will use the mp3 buffer */ 2033 global_settings.rec_quality,
1787 2034 global_settings.rec_source,
1788 audio_set_recording_options(global_settings.rec_frequency, 2035 0,
1789 global_settings.rec_quality, 2036 global_settings.rec_channels,
1790 global_settings.rec_source, 2037 global_settings.rec_editable,
1791 global_settings.rec_channels, 2038 global_settings.rec_prerecord_time);
1792 global_settings.rec_editable,
1793 global_settings.rec_prerecord_time);
1794
1795 2039
1796 set_gain(); 2040 set_gain();
1797 2041
@@ -1801,7 +2045,7 @@ bool f3_rec_screen(void)
1801 2045
1802 return false; 2046 return false;
1803} 2047}
1804#endif /* #ifdef RECORDER_PAD */ 2048#endif /* CONFIG_KEYPAD == RECORDER_PAD */
1805 2049
1806#if CONFIG_CODEC == SWCODEC 2050#if CONFIG_CODEC == SWCODEC
1807void audio_beep(int duration) 2051void audio_beep(int duration)
@@ -1831,6 +2075,14 @@ unsigned long audio_num_recorded_bytes(void)
1831 return 5 * 1024 * 1024; 2075 return 5 * 1024 * 1024;
1832} 2076}
1833 2077
2078#if CONFIG_CODEC == SWCODEC
2079void rec_set_source(int source, int flags)
2080{
2081 source = source;
2082 flags = flags;
2083}
2084#endif
2085
1834void audio_set_recording_options(int frequency, int quality, 2086void audio_set_recording_options(int frequency, int quality,
1835 int source, int channel_mode, 2087 int source, int channel_mode,
1836 bool editable, int prerecord_time) 2088 bool editable, int prerecord_time)
diff --git a/apps/recorder/recording.h b/apps/recorder/recording.h
index 384b34f5bf..aa216e757f 100644
--- a/apps/recorder/recording.h
+++ b/apps/recorder/recording.h
@@ -19,8 +19,33 @@
19#ifndef RECORDING_H 19#ifndef RECORDING_H
20#define RECORDING_H 20#define RECORDING_H
21 21
22bool recording_screen(void); 22bool recording_screen(bool no_source);
23char *rec_create_filename(char *buf); 23char *rec_create_filename(char *buf);
24int rec_create_directory(void); 24int rec_create_directory(void);
25 25
26#if CONFIG_CODEC == SWCODEC
27/* selects an audio source for recording or playback */
28#define SRCF_PLAYBACK 0x0000 /* default */
29#define SRCF_RECORDING 0x1000
30#ifdef CONFIG_TUNER
31/* for AUDIO_SRC_FMRADIO */
32#define SRCF_FMRADIO_PLAYING 0x0000 /* default */
33#define SRCF_FMRADIO_PAUSED 0x2000
34#endif
35void rec_set_source(int source, int flags);
36#endif /* CONFIG_CODEC == SW_CODEC */
37
38/* steals mp3 buffer, sets source and then options */
39/* SRCF_RECORDING is implied */
40void rec_set_recording_options(int frequency, int quality,
41 int source, int source_flags,
42 int channel_mode, bool editable,
43 int prerecord_time);
44
45/* steals mp3 buffer, creates unique filename and starts recording */
46void rec_record(void);
47
48/* creates unique filename and starts recording */
49void rec_new_file(void);
50
26#endif 51#endif
diff --git a/apps/settings.c b/apps/settings.c
index 49b8f9826b..acaeedcbd9 100644
--- a/apps/settings.c
+++ b/apps/settings.c
@@ -92,7 +92,7 @@ const char rec_base_directory[] = REC_BASE_DIR;
92#include "dsp.h" 92#include "dsp.h"
93#endif 93#endif
94 94
95#define CONFIG_BLOCK_VERSION 50 95#define CONFIG_BLOCK_VERSION 51
96#define CONFIG_BLOCK_SIZE 512 96#define CONFIG_BLOCK_SIZE 512
97#define RTC_BLOCK_SIZE 44 97#define RTC_BLOCK_SIZE 44
98 98
@@ -473,11 +473,21 @@ static const struct bit_entry hd_bits[] =
473 {1, S_O(rec_split_type), 0, "rec split type", "Split, Stop" }, 473 {1, S_O(rec_split_type), 0, "rec split type", "Split, Stop" },
474 {1, S_O(rec_split_method), 0, "rec split method", "Time,Filesize" }, 474 {1, S_O(rec_split_method), 0, "rec split method", "Time,Filesize" },
475 475
476#ifdef HAVE_SPDIF_IN 476 {
477 {2, S_O(rec_source), 0 /* 0=mic */, "rec source", "mic,line,spdif" }, 477#if defined(HAVE_SPDIF_IN) || defined(HAVE_FMRADIO_IN)
478 2,
478#else 479#else
479 {1, S_O(rec_source), 0 /* 0=mic */, "rec source", "mic,line" }, 480 1,
481#endif
482 S_O(rec_source), 0 /* 0=mic */, "rec source",
483 "mic,line"
484#ifdef HAVE_SPDIF_IN
485 ",spdif"
480#endif 486#endif
487#ifdef HAVE_FMRADIO_IN
488 ",fmradio"
489#endif
490 },
481 {5, S_O(rec_prerecord_time), 0, "prerecording time", NULL }, /* 0...30 */ 491 {5, S_O(rec_prerecord_time), 0, "prerecording time", NULL }, /* 0...30 */
482 {1, S_O(rec_directory), 0, /* rec_base_directory */ 492 {1, S_O(rec_directory), 0, /* rec_base_directory */
483 "rec directory", REC_BASE_DIR ",current" }, 493 "rec directory", REC_BASE_DIR ",current" },
@@ -490,14 +500,21 @@ static const struct bit_entry hd_bits[] =
490 {4, S_O(rec_right_gain), 2 /* 0dB */, "rec right gain", NULL }, /* 0...15 */ 500 {4, S_O(rec_right_gain), 2 /* 0dB */, "rec right gain", NULL }, /* 0...15 */
491 {3, S_O(rec_frequency), 0, /* 0=44.1kHz */ 501 {3, S_O(rec_frequency), 0, /* 0=44.1kHz */
492 "rec frequency", "44,48,32,22,24,16" }, 502 "rec frequency", "44,48,32,22,24,16" },
503 {3, S_O(rec_quality), 5 /* 192 kBit/s max */, "rec quality", NULL },
493 {1, S_O(rec_editable), false, "editable recordings", off_on }, 504 {1, S_O(rec_editable), false, "editable recordings", off_on },
494 {3, S_O(rec_quality), 5, "rec quality", NULL }, 505#elif defined(HAVE_UDA1380) || defined(HAVE_TLV320)
495#elif defined(HAVE_UDA1380) 506#ifdef HAVE_UDA1380
496 {8|SIGNED, S_O(rec_mic_gain), 16 /* 8 dB */, "rec mic gain", NULL }, /* -128...+108 */ 507 {8|SIGNED, S_O(rec_mic_gain), 16 /* 8 dB */, "rec mic gain", NULL }, /* -128...+108 */
508#endif
509#ifdef HAVE_TLV320
510 /* TLV320 only has no mic boost or 20db mic boost */
511 {1, S_O(rec_mic_gain), 0 /* 0 dB */, "rec mic gain", NULL }, /* 0db or 20db */
512#endif
497 {8|SIGNED, S_O(rec_left_gain), 0, "rec left gain", NULL }, /* -128...+96 */ 513 {8|SIGNED, S_O(rec_left_gain), 0, "rec left gain", NULL }, /* -128...+96 */
498 {8|SIGNED, S_O(rec_right_gain), 0, "rec right gain", NULL }, /* -128...+96 */ 514 {8|SIGNED, S_O(rec_right_gain), 0, "rec right gain", NULL }, /* -128...+96 */
499 {3, S_O(rec_frequency), 0, /* 0=44.1kHz */ 515 {3, S_O(rec_frequency), 0, /* 0=44.1kHz */
500 "rec frequency", "44,48,32,22,24,16" }, 516 "rec frequency", "44,48,32,22,24,16" },
517 {4, S_O(rec_quality), 4 /* MP3 L3 192 kBit/s */, "rec quality", NULL },
501#endif 518#endif
502 519
503 /* values for the trigger */ 520 /* values for the trigger */
diff --git a/apps/settings.h b/apps/settings.h
index d87bc5ee06..af0eef57b1 100644
--- a/apps/settings.h
+++ b/apps/settings.h
@@ -42,6 +42,7 @@
42#define BACKDROP_DIR ROCKBOX_DIR"/backdrops" 42#define BACKDROP_DIR ROCKBOX_DIR"/backdrops"
43#define REC_BASE_DIR "/recordings" 43#define REC_BASE_DIR "/recordings"
44#define EQS_DIR ROCKBOX_DIR "/eqs" 44#define EQS_DIR ROCKBOX_DIR "/eqs"
45#define CODECS_DIR "/codecs"
45 46
46#define MAX_FILENAME 20 47#define MAX_FILENAME 20
47 48
diff --git a/apps/sound_menu.c b/apps/sound_menu.c
index 34ed9af000..179951a17d 100644
--- a/apps/sound_menu.c
+++ b/apps/sound_menu.c
@@ -39,6 +39,12 @@
39#include "talk.h" 39#include "talk.h"
40#include "misc.h" 40#include "misc.h"
41#include "sound.h" 41#include "sound.h"
42#ifdef HAVE_RECORDING
43#include "audio.h"
44#ifdef CONFIG_TUNER
45#include "radio.h"
46#endif
47#endif
42#if CONFIG_CODEC == MAS3587F 48#if CONFIG_CODEC == MAS3587F
43#include "peakmeter.h" 49#include "peakmeter.h"
44#include "mas.h" 50#include "mas.h"
@@ -290,19 +296,68 @@ static bool avc(void)
290#ifdef HAVE_RECORDING 296#ifdef HAVE_RECORDING
291static bool recsource(void) 297static bool recsource(void)
292{ 298{
293 static const struct opt_items names[] = { 299 int n_opts = AUDIO_NUM_SOURCES;
300
301 struct opt_items names[AUDIO_NUM_SOURCES] = {
294 { STR(LANG_RECORDING_SRC_MIC) }, 302 { STR(LANG_RECORDING_SRC_MIC) },
295 { STR(LANG_RECORDING_SRC_LINE) }, 303 { STR(LANG_RECORDING_SRC_LINE) },
296#ifdef HAVE_SPDIF_IN 304#ifdef HAVE_SPDIF_IN
297 { STR(LANG_RECORDING_SRC_DIGITAL) }, 305 { STR(LANG_RECORDING_SRC_DIGITAL) },
298#endif 306#endif
299 }; 307 };
308
309 /* caveat: assumes it's the last item! */
310#ifdef HAVE_FMRADIO_IN
311 if (radio_hardware_present())
312 {
313 names[AUDIO_SRC_FMRADIO].string = ID2P(LANG_FM_RADIO);
314 names[AUDIO_SRC_FMRADIO].voice_id = LANG_FM_RADIO;
315 }
316 else
317 n_opts--;
318#endif
319
300 return set_option(str(LANG_RECORDING_SOURCE), 320 return set_option(str(LANG_RECORDING_SOURCE),
301 &global_settings.rec_source, INT, names, 321 &global_settings.rec_source, INT, names,
302 sizeof(names)/sizeof(struct opt_items), NULL ); 322 n_opts, NULL );
303} 323}
304 324
305/* To be removed when we add support for sample rates and channel settings */ 325/* To be removed when we add support for sample rates and channel settings */
326#if CONFIG_CODEC == SWCODEC
327static bool recquality(void)
328{
329 static const struct opt_items names[] = {
330 { "MP3 64 kBit/s", TALK_ID( 64, UNIT_KBIT) },
331 { "MP3 96 kBit/s", TALK_ID( 96, UNIT_KBIT) },
332 { "MP3 128 kBit/s", TALK_ID( 128, UNIT_KBIT) },
333 { "MP3 160 kBit/s", TALK_ID( 160, UNIT_KBIT) },
334 { "MP3 192 kBit/s", TALK_ID( 192, UNIT_KBIT) },
335 { "MP3 224 kBit/s", TALK_ID( 224, UNIT_KBIT) },
336 { "MP3 320 kBit/s", TALK_ID( 320, UNIT_KBIT) },
337 { "WV 900 kBit/s", TALK_ID( 900, UNIT_KBIT) },
338 { "WAV 1411 kBit/s", TALK_ID(1411, UNIT_KBIT) }
339 };
340
341 return set_option(str(LANG_RECORDING_QUALITY),
342 &global_settings.rec_quality, INT,
343 names, sizeof (names)/sizeof(struct opt_items),
344 NULL );
345}
346#elif CONFIG_CODEC == MAS3587F
347static bool recquality(void)
348{
349 return set_int(str(LANG_RECORDING_QUALITY), "", UNIT_INT,
350 &global_settings.rec_quality,
351 NULL, 1, 0, 7, NULL );
352}
353
354static bool receditable(void)
355{
356 return set_bool(str(LANG_RECORDING_EDITABLE),
357 &global_settings.rec_editable);
358}
359#endif
360
306#ifndef HAVE_UDA1380 361#ifndef HAVE_UDA1380
307static bool recfrequency(void) 362static bool recfrequency(void)
308{ 363{
@@ -331,21 +386,6 @@ static bool recchannels(void)
331} 386}
332#endif 387#endif
333 388
334#if CONFIG_CODEC == MAS3587F
335static bool recquality(void)
336{
337 return set_int(str(LANG_RECORDING_QUALITY), "", UNIT_INT,
338 &global_settings.rec_quality,
339 NULL, 1, 0, 7, NULL );
340}
341
342static bool receditable(void)
343{
344 return set_bool(str(LANG_RECORDING_EDITABLE),
345 &global_settings.rec_editable);
346}
347#endif
348
349static bool rectimesplit(void) 389static bool rectimesplit(void)
350{ 390{
351 static const struct opt_items names[] = { 391 static const struct opt_items names[] = {
@@ -1011,13 +1051,13 @@ bool recording_menu(bool no_source)
1011 struct menu_item items[13]; 1051 struct menu_item items[13];
1012 bool result; 1052 bool result;
1013 1053
1014#if CONFIG_CODEC == MAS3587F 1054#if CONFIG_CODEC == MAS3587F || CONFIG_CODEC == SWCODEC
1015 items[i].desc = ID2P(LANG_RECORDING_QUALITY); 1055 items[i].desc = ID2P(LANG_RECORDING_QUALITY);
1016 items[i++].function = recquality; 1056 items[i++].function = recquality;
1017#endif 1057#endif
1058#ifndef HAVE_UDA1380
1018/* We don't support frequency selection for UDA1380 yet. Let it just stay at 1059/* We don't support frequency selection for UDA1380 yet. Let it just stay at
1019 the default 44100 Hz. */ 1060 the default 44100 Hz. */
1020#ifndef HAVE_UDA1380
1021 items[i].desc = ID2P(LANG_RECORDING_FREQUENCY); 1061 items[i].desc = ID2P(LANG_RECORDING_FREQUENCY);
1022 items[i++].function = recfrequency; 1062 items[i++].function = recfrequency;
1023#endif 1063#endif
diff --git a/apps/status.c b/apps/status.c
index ad4cb7232b..2a57db0f89 100644
--- a/apps/status.c
+++ b/apps/status.c
@@ -103,10 +103,10 @@ int current_playmode(void)
103#ifdef CONFIG_TUNER 103#ifdef CONFIG_TUNER
104 audio_stat = get_radio_status(); 104 audio_stat = get_radio_status();
105 105
106 if(audio_stat == FMRADIO_PLAYING) 106 if(audio_stat & FMRADIO_PLAYING)
107 return STATUS_RADIO; 107 return STATUS_RADIO;
108 108
109 if(audio_stat == FMRADIO_PAUSED) 109 if(audio_stat & FMRADIO_PAUSED)
110 return STATUS_RADIO_PAUSE; 110 return STATUS_RADIO_PAUSE;
111#endif 111#endif
112 112
diff --git a/apps/talk.c b/apps/talk.c
index cf68cdf021..21c6f4bb1a 100644
--- a/apps/talk.c
+++ b/apps/talk.c
@@ -554,6 +554,7 @@ int talk_buffer_steal(void)
554 } 554 }
555#endif 555#endif
556 reset_state(); 556 reset_state();
557
557 return 0; 558 return 0;
558} 559}
559 560
@@ -728,6 +729,7 @@ int talk_value(long n, int unit, bool enqueue)
728 VOICE_PIXEL, 729 VOICE_PIXEL,
729 VOICE_PER_SEC, 730 VOICE_PER_SEC,
730 VOICE_HERTZ, 731 VOICE_HERTZ,
732 VOICE_KBIT_PER_SEC,
731 }; 733 };
732 734
733#if CONFIG_CODEC != SWCODEC 735#if CONFIG_CODEC != SWCODEC
diff --git a/apps/talk.h b/apps/talk.h
index 0dc6996f39..2f2099a8c4 100644
--- a/apps/talk.h
+++ b/apps/talk.h
@@ -41,6 +41,7 @@ enum {
41 UNIT_PER_SEC, /* per second */ 41 UNIT_PER_SEC, /* per second */
42 UNIT_HERTZ, /* hertz */ 42 UNIT_HERTZ, /* hertz */
43 UNIT_MB, /* Megabytes */ 43 UNIT_MB, /* Megabytes */
44 UNIT_KBIT, /* kilobits per sec */
44 UNIT_LAST /* END MARKER */ 45 UNIT_LAST /* END MARKER */
45}; 46};
46 47
diff --git a/apps/tree.c b/apps/tree.c
index 4558cd59a4..2d9b1bf7b4 100644
--- a/apps/tree.c
+++ b/apps/tree.c
@@ -577,7 +577,7 @@ static bool dirbrowse(void)
577 if (global_settings.rec_startup) { 577 if (global_settings.rec_startup) {
578 /* We fake being in the menu structure by calling 578 /* We fake being in the menu structure by calling
579 the appropriate parent when we drop out of each screen */ 579 the appropriate parent when we drop out of each screen */
580 recording_screen(); 580 recording_screen(false);
581 rec_menu(); 581 rec_menu();
582 main_menu(); 582 main_menu();
583 } 583 }
diff --git a/firmware/drivers/power.c b/firmware/drivers/power.c
index 67f34e2f30..d5b75a130d 100644
--- a/firmware/drivers/power.c
+++ b/firmware/drivers/power.c
@@ -38,7 +38,7 @@ bool charger_enabled;
38 38
39static bool powered = false; 39static bool powered = false;
40 40
41bool radio_powered() 41bool radio_powered(void)
42{ 42{
43 return powered; 43 return powered;
44} 44}
diff --git a/firmware/export/audio.h b/firmware/export/audio.h
index 9e3499e81f..2ee7f89dbd 100644
--- a/firmware/export/audio.h
+++ b/firmware/export/audio.h
@@ -31,6 +31,9 @@
31#define AUDIO_STATUS_PRERECORD 8 31#define AUDIO_STATUS_PRERECORD 8
32#define AUDIO_STATUS_ERROR 16 32#define AUDIO_STATUS_ERROR 16
33 33
34#define AUDIO_STATUS_STAYON_FLAGS \
35 (AUDIO_STATUS_PLAY | AUDIO_STATUS_PAUSE | AUDIO_STATUS_RECORD | AUDIO_)
36
34#define AUDIOERR_DISK_FULL 1 37#define AUDIOERR_DISK_FULL 1
35 38
36#define AUDIO_GAIN_LINEIN 0 39#define AUDIO_GAIN_LINEIN 0
@@ -69,6 +72,7 @@ void audio_resume(void);
69void audio_next(void); 72void audio_next(void);
70void audio_prev(void); 73void audio_prev(void);
71int audio_status(void); 74int audio_status(void);
75bool audio_query_poweroff(void);
72int audio_track_count(void); /* SWCODEC only */ 76int audio_track_count(void); /* SWCODEC only */
73void audio_pre_ff_rewind(void); /* SWCODEC only */ 77void audio_pre_ff_rewind(void); /* SWCODEC only */
74void audio_ff_rewind(long newtime); 78void audio_ff_rewind(long newtime);
@@ -93,14 +97,56 @@ void audio_stop_recording(void);
93void audio_pause_recording(void); 97void audio_pause_recording(void);
94void audio_resume_recording(void); 98void audio_resume_recording(void);
95void audio_new_file(const char *filename); 99void audio_new_file(const char *filename);
100
101/* audio sources */
102enum
103{
104 AUDIO_SRC_PLAYBACK = -1, /* for audio playback (default) */
105 AUDIO_SRC_MIC, /* monitor mic */
106 AUDIO_SRC_LINEIN, /* monitor line in */
107#ifdef HAVE_SPDIF_IN
108 AUDIO_SRC_SPDIF, /* monitor spdif */
109#endif
110#if defined(HAVE_FMRADIO_IN) || defined(CONFIG_TUNER)
111 AUDIO_SRC_FMRADIO, /* monitor fm radio */
112#endif
113 /* define new audio sources above this line */
114 AUDIO_SOURCE_LIST_END,
115 /* AUDIO_SRC_FMRADIO must be declared #ifdef CONFIG_TUNER but is not in
116 the list of recordable sources. HAVE_FMRADIO_IN implies CONFIG_TUNER. */
117#if defined(HAVE_FMRADIO_IN) || !defined(CONFIG_TUNER)
118 AUDIO_NUM_SOURCES = AUDIO_SOURCE_LIST_END,
119#else
120 AUDIO_NUM_SOURCES = AUDIO_SOURCE_LIST_END-1,
121#endif
122 AUDIO_SRC_MAX = AUDIO_NUM_SOURCES-1
123};
124
125/* channel modes */
126enum
127{
128 CHN_MODE_MONO = 1,
129 CHN_MODE_STEREO,
130};
96void audio_set_recording_options(int frequency, int quality, 131void audio_set_recording_options(int frequency, int quality,
97 int source, int channel_mode, 132 int source, int channel_mode,
98 bool editable, int prerecord_time); 133 bool editable, int prerecord_time);
99void audio_set_recording_gain(int left, int right, int type); 134void audio_set_recording_gain(int left, int right, int type);
100unsigned long audio_recorded_time(void); 135unsigned long audio_recorded_time(void);
101unsigned long audio_num_recorded_bytes(void); 136unsigned long audio_num_recorded_bytes(void);
137#if 0
138#ifdef HAVE_SPDIF_POWER
102void audio_set_spdif_power_setting(bool on); 139void audio_set_spdif_power_setting(bool on);
140#endif
141#endif
103unsigned long audio_get_spdif_sample_rate(void); 142unsigned long audio_get_spdif_sample_rate(void);
143#if CONFIG_CODEC == SWCODEC
144/* audio encoder functions (defined in playback.c) */
145int audio_get_encoder_id(void);
146void audio_load_encoder(int enc_id);
147void audio_remove_encoder(void);
148#endif /* CONFIG_CODEC == SWCODEC */
149
104 150
105 151
106 152
diff --git a/firmware/export/config-h100.h b/firmware/export/config-h100.h
index c21c8a1dcd..8f936866cc 100644
--- a/firmware/export/config-h100.h
+++ b/firmware/export/config-h100.h
@@ -135,6 +135,9 @@
135/* Someone with H100 and BDM, please verify if this works. */ 135/* Someone with H100 and BDM, please verify if this works. */
136/* #define HAVE_EEPROM */ 136/* #define HAVE_EEPROM */
137 137
138/* Define this for FM radio input available (not for SIMULATOR) */
139#define HAVE_FMRADIO_IN
140
138#endif /* !SIMULATOR */ 141#endif /* !SIMULATOR */
139 142
140/* Define this for S/PDIF input available */ 143/* Define this for S/PDIF input available */
diff --git a/firmware/export/config-h120.h b/firmware/export/config-h120.h
index 5ff567cae4..4ac4b2b699 100644
--- a/firmware/export/config-h120.h
+++ b/firmware/export/config-h120.h
@@ -132,6 +132,9 @@
132/* Define this if the EEPROM chip is used */ 132/* Define this if the EEPROM chip is used */
133#define HAVE_EEPROM_SETTINGS 133#define HAVE_EEPROM_SETTINGS
134 134
135/* Define this for FM radio input available (not for SIMULATOR) */
136#define HAVE_FMRADIO_IN
137
135#endif /* !SIMULATOR */ 138#endif /* !SIMULATOR */
136 139
137/* Define this for S/PDIF input available */ 140/* Define this for S/PDIF input available */
diff --git a/firmware/export/config-h300.h b/firmware/export/config-h300.h
index d5c54d858f..c9c0b04bcb 100644
--- a/firmware/export/config-h300.h
+++ b/firmware/export/config-h300.h
@@ -140,4 +140,7 @@
140/* Define this if there is an EEPROM chip */ 140/* Define this if there is an EEPROM chip */
141#define HAVE_EEPROM 141#define HAVE_EEPROM
142 142
143/* Define this for FM radio input available (not for SIMULATOR) */
144#define HAVE_FMRADIO_IN
145
143#endif /* SIMULATOR */ 146#endif /* SIMULATOR */
diff --git a/firmware/export/config-iaudiox5.h b/firmware/export/config-iaudiox5.h
index 8a2ed7a29d..d5c67c0a1c 100644
--- a/firmware/export/config-iaudiox5.h
+++ b/firmware/export/config-iaudiox5.h
@@ -17,6 +17,7 @@
17 17
18/* define this if you have access to the quickscreen */ 18/* define this if you have access to the quickscreen */
19#define HAVE_QUICKSCREEN 19#define HAVE_QUICKSCREEN
20
20/* define this if you have access to the pitchscreen */ 21/* define this if you have access to the pitchscreen */
21#define HAVE_PITCHSCREEN 22#define HAVE_PITCHSCREEN
22 23
@@ -81,6 +82,9 @@
81 should be defined as well. */ 82 should be defined as well. */
82#define HAVE_LCD_SLEEP 83#define HAVE_LCD_SLEEP
83 84
85/* Define this for FM radio input available (not for SIMULATOR) */
86#define HAVE_FMRADIO_IN
87
84/* Define this if you have a Motorola SCF5250 */ 88/* Define this if you have a Motorola SCF5250 */
85#define CONFIG_CPU MCF5250 89#define CONFIG_CPU MCF5250
86 90
diff --git a/firmware/export/fmradio.h b/firmware/export/fmradio.h
index 3c55fb7672..73113237c0 100644
--- a/firmware/export/fmradio.h
+++ b/firmware/export/fmradio.h
@@ -20,6 +20,22 @@
20#ifndef FMRADIO_H 20#ifndef FMRADIO_H
21#define FMRADIO_H 21#define FMRADIO_H
22 22
23/** declare some stuff here so powermgmt.c can properly tell if the radio is
24 actually playing and not just paused. This break in heirarchy is allowed
25 for audio_status(). **/
26
27/* set when radio is playing or paused within fm radio screen */
28#define FMRADIO_OFF 0x0
29#define FMRADIO_PLAYING 0x1
30#define FMRADIO_PAUSED 0x2
31
32/* returns the IN flag */
33#define FMRADIO_IN_SCREEN(s) ((s) & FMRADIO_IN_FLAG)
34#define FMRADIO_STATUS_PLAYING(s) ((s) & FMRADIO_PLAYING_OUT)
35#define FMRADIO_STATUS_PAUSED(s) ((s) & FMRADIO_PAUSED_OUT)
36
37extern int get_radio_status(void);
38
23extern int fmradio_read(int addr); 39extern int fmradio_read(int addr);
24extern void fmradio_set(int addr, int data); 40extern void fmradio_set(int addr, int data);
25 41
diff --git a/firmware/export/id3.h b/firmware/export/id3.h
index 7930cd9b70..dc58178d50 100644
--- a/firmware/export/id3.h
+++ b/firmware/export/id3.h
@@ -24,7 +24,6 @@
24#include "file.h" 24#include "file.h"
25 25
26/* Audio file types. */ 26/* Audio file types. */
27/* NOTE: When adding new audio types, also add to codec_labels[] in id3.c */
28enum { 27enum {
29 AFMT_UNKNOWN = 0, /* Unknown file format */ 28 AFMT_UNKNOWN = 0, /* Unknown file format */
30 29
@@ -46,9 +45,48 @@ enum {
46 45
47 /* New formats must be added to the end of this list */ 46 /* New formats must be added to the end of this list */
48 47
49 AFMT_NUM_CODECS 48 AFMT_NUM_CODECS,
49
50#if CONFIG_CODEC == SWCODEC
51 /* masks to decompose parts */
52 CODEC_AFMT_MASK = 0x0fff,
53 CODEC_TYPE_MASK = 0x7000,
54
55 /* switch for specifying codec type when requesting a filename */
56 CODEC_TYPE_DECODER = (0 << 12), /* default */
57 CODEC_TYPE_ENCODER = (1 << 12)
58#endif
50}; 59};
51 60
61#if CONFIG_CODEC == SWCODEC
62#define AFMT_ENTRY(label, codec_fname, codec_enc_fname, enc_ext) \
63 { label, codec_fname, codec_enc_fname, enc_ext }
64#else
65#define AFMT_ENTRY(label, codec_fname, codec_enc_fname, enc_ext) \
66 { label }
67#endif
68
69/* record describing the audio format */
70struct afmt_entry
71{
72#if CONFIG_CODEC == SWCODEC
73 char label[8]; /* format label */
74 char *codec_fn; /* filename of decoder codec */
75 char *codec_enc_fn; /* filename of encoder codec */
76 char *ext; /* default extension for file (enc only for now) */
77#else
78 char label[4];
79#endif
80};
81
82/* database of labels and codecs. add formats per above enum */
83extern const struct afmt_entry audio_formats[AFMT_NUM_CODECS];
84
85#if CONFIG_CODEC == SWCODEC
86/* recording quality to AFMT_* */
87extern const int rec_quality_info_afmt[9];
88#endif
89
52struct mp3entry { 90struct mp3entry {
53 char path[MAX_PATH]; 91 char path[MAX_PATH];
54 char* title; 92 char* title;
diff --git a/firmware/export/pcm_record.h b/firmware/export/pcm_record.h
index 5e2d7b7929..b217335340 100644
--- a/firmware/export/pcm_record.h
+++ b/firmware/export/pcm_record.h
@@ -20,10 +20,22 @@
20#ifndef PCM_RECORD_H 20#ifndef PCM_RECORD_H
21#define PCM_RECORD_H 21#define PCM_RECORD_H
22 22
23void enc_set_parameters(int chunk_size, int num_chunks,
24 int samp_per_chunk, char *head_ptr, int head_size,
25 int enc_id);
26void enc_get_inputs(int *buffer_size, int *channels, int *quality);
27unsigned int* enc_alloc_chunk(void);
28void enc_free_chunk(void);
29int enc_wavbuf_near_empty(void);
30char* enc_get_wav_data(int size);
31extern void (*enc_set_header_callback)(void *head_buffer, int head_size,
32 int num_pcm_samples, bool is_file_header);
33
23unsigned long pcm_rec_status(void); 34unsigned long pcm_rec_status(void);
24void pcm_rec_init(void); 35void pcm_rec_init(void);
25void pcm_rec_mux(int source); 36void pcm_rec_mux(int source);
26 37int pcm_rec_current_bitrate(void);
38int pcm_get_num_unprocessed(void);
27void pcm_rec_get_peaks(int *left, int *right); 39void pcm_rec_get_peaks(int *left, int *right);
28 40
29/* audio.h contains audio recording functions */ 41/* audio.h contains audio recording functions */
diff --git a/firmware/id3.c b/firmware/id3.c
index 35e0517769..3f2ba23684 100644
--- a/firmware/id3.c
+++ b/firmware/id3.c
@@ -85,28 +85,59 @@ static const char* const genres[] = {
85 "Synthpop" 85 "Synthpop"
86}; 86};
87 87
88static const char* const codec_labels[] = { 88/* database of audio formats */
89 "???", /* Unknown file format */ 89const struct afmt_entry audio_formats[AFMT_NUM_CODECS] =
90 90{
91 "MP1", /* MPEG Audio layer 1 */ 91 /* Unknown file format */
92 "MP2", /* MPEG Audio layer 2 */ 92 AFMT_ENTRY("???", NULL, NULL, NULL ),
93 "MP3", /* MPEG Audio layer 3 */ 93 /* MPEG Audio layer 1 */
94 94 AFMT_ENTRY("MP1", "mpa.codec", NULL, NULL ),
95 /* MPEG Audio layer 2 */
96 AFMT_ENTRY("MP2", "mpa.codec", NULL, NULL ),
97 /* MPEG Audio layer 3 */
98 AFMT_ENTRY("MP3", "mpa.codec", "mp3_enc.codec", ".mp3"),
95#if CONFIG_CODEC == SWCODEC 99#if CONFIG_CODEC == SWCODEC
96 "WAV", /* Uncompressed PCM in a WAV file */ 100 /* Uncompressed PCM in a WAV file */
97 "Ogg", /* Ogg Vorbis */ 101 AFMT_ENTRY("WAV", "wav.codec", "wav_enc.codec", ".wav"),
98 "FLAC", /* FLAC */ 102 /* Ogg Vorbis */
99 "MPC", /* Musepack */ 103 AFMT_ENTRY("Ogg", "vorbis.codec", NULL, NULL ),
100 "AC3", /* A/52 (aka AC3) audio */ 104 /* FLAC */
101 "WV", /* WavPack */ 105 AFMT_ENTRY("FLAC", "flac.codec", NULL, NULL ),
102 "ALAC", /* Apple Lossless Audio Codec */ 106 /* Musepack */
103 "AAC", /* Advanced Audio Coding in M4A container */ 107 AFMT_ENTRY("MPC", "mpc.codec", NULL, NULL ),
104 "SHN", /* Shorten */ 108 /* A/52 (aka AC3) audio */
105 "AIFF", /* Audio Interchange File Format */ 109 AFMT_ENTRY("AC3", "a52.codec", NULL, NULL ),
106 "SID", /* SID File Format */ 110 /* WavPack */
111 AFMT_ENTRY("WV", "wavpack.codec", "wavpack_enc.codec", ".wv" ),
112 /* Apple Lossless Audio Codec */
113 AFMT_ENTRY("ALAC", "alac.codec", NULL, NULL ),
114 /* Advanced Audio Coding in M4A container */
115 AFMT_ENTRY("AAC", "aac.codec", NULL, NULL ),
116 /* Shorten */
117 AFMT_ENTRY("SHN", "shorten.codec", NULL, NULL ),
118 /* Audio Interchange File Format */
119 AFMT_ENTRY("AIFF", "aiff.codec", NULL, NULL ),
120 /* SID File Format */
121 AFMT_ENTRY("SID", "sid.codec", NULL, NULL ),
107#endif 122#endif
108}; 123};
109 124
125#if CONFIG_CODEC == SWCODEC
126/* recording quality to AFMT_* */
127const int rec_quality_info_afmt[9] =
128{
129 AFMT_MPA_L3, /* MPEG L3 64 kBit/s */
130 AFMT_MPA_L3, /* MPEG L3 96 kBit/s */
131 AFMT_MPA_L3, /* MPEG L3 128 kBit/s */
132 AFMT_MPA_L3, /* MPEG L3 160 kBit/s */
133 AFMT_MPA_L3, /* MPEG L3 192 kBit/s */
134 AFMT_MPA_L3, /* MPEG L3 224 kBit/s */
135 AFMT_MPA_L3, /* MPEG L3 320 kBit/s */
136 AFMT_WAVPACK, /* WavPack 909 kBit/s */
137 AFMT_PCM_WAV, /* PCM Wav 1411 kBit/s */
138};
139#endif /* SWCODEC */
140
110char* id3_get_genre(const struct mp3entry* id3) 141char* id3_get_genre(const struct mp3entry* id3)
111{ 142{
112 if( id3->genre_string ) 143 if( id3->genre_string )
@@ -119,8 +150,8 @@ char* id3_get_genre(const struct mp3entry* id3)
119 150
120char* id3_get_codec(const struct mp3entry* id3) 151char* id3_get_codec(const struct mp3entry* id3)
121{ 152{
122 if (id3->codectype < sizeof(codec_labels)/sizeof(char*)) { 153 if (id3->codectype < AFMT_NUM_CODECS) {
123 return (char*)codec_labels[id3->codectype]; 154 return (char*)audio_formats[id3->codectype].label;
124 } else { 155 } else {
125 return NULL; 156 return NULL;
126 } 157 }
diff --git a/firmware/mpeg.c b/firmware/mpeg.c
index 7034f3896b..df0cbbad12 100644
--- a/firmware/mpeg.c
+++ b/firmware/mpeg.c
@@ -2484,7 +2484,7 @@ void audio_set_recording_options(int frequency, int quality,
2484 2484
2485 DEBUGF("mas_writemem(MAS_BANK_D0, IO_CONTROL_MAIN, %x)\n", shadow_io_control_main); 2485 DEBUGF("mas_writemem(MAS_BANK_D0, IO_CONTROL_MAIN, %x)\n", shadow_io_control_main);
2486 2486
2487 if(source == 0) /* Mic */ 2487 if(source == AUDIO_SRC_MIC)
2488 { 2488 {
2489 /* Copy left channel to right (mono mode) */ 2489 /* Copy left channel to right (mono mode) */
2490 mas_codec_writereg(8, 0x8000); 2490 mas_codec_writereg(8, 0x8000);
diff --git a/firmware/pcm_record.c b/firmware/pcm_record.c
index fee2bbd35b..4e4d5f25a0 100644
--- a/firmware/pcm_record.c
+++ b/firmware/pcm_record.c
@@ -50,6 +50,8 @@
50#include "lcd.h" 50#include "lcd.h"
51#include "lcd-remote.h" 51#include "lcd-remote.h"
52#include "pcm_playback.h" 52#include "pcm_playback.h"
53#include "sound.h"
54#include "id3.h"
53#include "pcm_record.h" 55#include "pcm_record.h"
54 56
55extern int boost_counter; /* used for boost check */ 57extern int boost_counter; /* used for boost check */
@@ -57,43 +59,26 @@ extern int boost_counter; /* used for boost check */
57/***************************************************************************/ 59/***************************************************************************/
58 60
59static bool is_recording; /* We are recording */ 61static bool is_recording; /* We are recording */
60static bool is_stopping; /* Are we going to stop */
61static bool is_paused; /* We have paused */ 62static bool is_paused; /* We have paused */
62static bool is_error; /* An error has occured */ 63static bool is_error; /* An error has occured */
63 64
64static unsigned long num_rec_bytes; /* Num bytes recorded */ 65static unsigned long num_rec_bytes; /* Num bytes recorded */
65static unsigned long num_file_bytes; /* Num bytes written to current file */ 66static unsigned long num_file_bytes; /* Num bytes written to current file */
66static int error_count; /* Number of DMA errors */ 67static int error_count; /* Number of DMA errors */
68static unsigned long num_pcm_samples; /* Num pcm samples written to current file */
67 69
68static long record_start_time; /* Value of current_tick when recording was started */ 70static long record_start_time; /* current_tick when recording was started */
69static long pause_start_time; /* Value of current_tick when pause was started */ 71static long pause_start_time; /* current_tick when pause was started */
70static volatile int buffered_chunks; /* number of valid chunks in buffer */ 72static unsigned int sample_rate; /* Sample rate at time of recording start */
71static unsigned int sample_rate; /* Sample rate at time of recording start */ 73static int rec_source; /* Current recording source */
72static int rec_source; /* Current recording source */
73 74
74static int wav_file; 75static int wav_file;
75static char recording_filename[MAX_PATH]; 76static char recording_filename[MAX_PATH];
76 77
77static bool init_done, close_done, record_done, stop_done, pause_done, resume_done, new_file_done; 78static volatile bool init_done, close_done, record_done;
79static volatile bool stop_done, pause_done, resume_done, new_file_done;
78 80
79static short peak_left, peak_right; 81static int peak_left, peak_right;
80
81/***************************************************************************/
82
83/*
84 Some estimates:
85 Normal recording rate: 44100 HZ * 4 = 176 KB/s
86 Total buffer size: 32 MB / 176 KB/s = 181s before writing to disk
87*/
88
89#define CHUNK_SIZE 8192 /* Multiple of 4 */
90#define WRITE_THRESHOLD 250 /* (2 MB) Write when this many chunks (or less) until buffer full */
91
92#define GET_CHUNK(x) (short*)(&rec_buffer[CHUNK_SIZE*(x)])
93
94static unsigned int rec_buffer_offset;
95static unsigned char *rec_buffer; /* Circular recording buffer */
96static int num_chunks; /* Number of chunks available in rec_buffer */
97 82
98#ifdef IAUDIO_X5 83#ifdef IAUDIO_X5
99#define SET_IIS_PLAY(x) IIS1CONFIG = (x); 84#define SET_IIS_PLAY(x) IIS1CONFIG = (x);
@@ -103,27 +88,71 @@ static int num_chunks; /* Number of chunks available in rec_buffer *
103#define SET_IIS_REC(x) IIS1CONFIG = (x); 88#define SET_IIS_REC(x) IIS1CONFIG = (x);
104#endif 89#endif
105 90
106/* 91/****************************************************************************
107 Overrun occures when DMA needs to write a new chunk and write_index == read_index 92 use 2 circular buffers of same size:
108 Solution to this is to optimize pcmrec_callback, use cpu_boost or save to disk 93 rec_buffer=DMA output buffer: chunks (8192 Bytes) of raw pcm audio data
109 more often. 94 enc_buffer=encoded audio buffer: storage for encoder output data
110*/ 95
111 96 Flow:
112static int write_index; /* Current chunk the DMA is writing to */ 97 1. when entering recording_screen DMA feeds the ringbuffer rec_buffer
113static int read_index; /* Oldest chunk that is not written to disk */ 98 2. if enough pcm data are available the encoder codec does encoding of pcm
114static int read2_index; /* Latest chunk that has not been converted to little endian */ 99 chunks (4-8192 Bytes) into ringbuffer enc_buffer in codec_thread
115static long pre_record_ticks; /* pre-record time expressed in ticks */ 100 3. pcmrec_callback detects enc_buffer 'near full' and writes data to disk
116static int pre_record_chunks; /* pre-record time expressed in chunks */ 101
102 Functions calls:
103 1.main: codec_load_encoder(); start the encoder
104 2.encoder: enc_get_inputs(); get encoder buffsize, mono/stereo, quality
105 3.encoder: enc_set_parameters(); set the encoder parameters (max.chunksize)
106 4.encoder: enc_get_wav_data(); get n bytes of unprocessed pcm data
107 5.encoder: enc_wavbuf_near_empty();if true: reduce cpu_boost
108 6.encoder: enc_alloc_chunk(); get a ptr to next enc chunk
109 7.encoder: <process enc chunk> compress and store data to enc chunk
110 8.encoder: enc_free_chunk(); inform main about chunk process finished
111 9.encoder: repeat 4. to 8.
112 A.main: enc_set_header_callback(); create the current format header (file)
113****************************************************************************/
114#define NUM_CHUNKS 256 /* Power of 2 */
115#define CHUNK_SIZE 8192 /* Power of 2 */
116#define MAX_FEED_SIZE 20000 /* max pcm size passed to encoder */
117#define CHUNK_MASK (NUM_CHUNKS * CHUNK_SIZE - 1)
118#define WRITE_THRESHOLD (44100 * 5 / enc_samp_per_chunk) /* 5sec */
119#define GET_CHUNK(x) (long*)(&rec_buffer[x])
120#define GET_ENC_CHUNK(x) (long*)(&enc_buffer[enc_chunk_size*(x)])
121
122static int audio_enc_id; /* current encoder id */
123static unsigned char *rec_buffer; /* Circular recording buffer */
124static unsigned char *enc_buffer; /* Circular encoding buffer */
125static unsigned char *enc_head_buffer; /* encoder header buffer */
126static int enc_head_size; /* used size in header buffer */
127static int write_pos; /* Current chunk pos for DMA writing */
128static int read_pos; /* Current chunk pos for encoding */
129static long pre_record_ticks;/* pre-record time expressed in ticks */
130static int enc_wr_index; /* Current encoding chunk write index */
131static int enc_rd_index; /* Current encoding chunk read index */
132static int enc_chunk_size; /* maximum encoder chunk size */
133static int enc_num_chunks; /* number of chunks in ringbuffer */
134static int enc_buffer_size; /* encode buffer size */
135static int enc_channels; /* 1=mono 2=stereo */
136static int enc_quality; /* mp3: 64,96,128,160,192,320 kBit */
137static int enc_samp_per_chunk;/* pcm samples per encoder chunk */
138static bool wav_queue_empty; /* all wav chunks processed? */
139static unsigned long avrg_bit_rate; /* average bit rates from chunks */
140static unsigned long curr_bit_rate; /* cumulated bit rates from chunks */
141static unsigned long curr_chunk_cnt; /* number of processed chunks */
142
143void (*enc_set_header_callback)(void *head_buffer, int head_size,
144 int num_pcm_samples, bool is_file_header);
117 145
118/***************************************************************************/ 146/***************************************************************************/
119 147
120static struct event_queue pcmrec_queue; 148static struct event_queue pcmrec_queue;
121static long pcmrec_stack[(DEFAULT_STACK_SIZE + 0x1000)/sizeof(long)]; 149static long pcmrec_stack[2*DEFAULT_STACK_SIZE/sizeof(long)];
122static const char pcmrec_thread_name[] = "pcmrec"; 150static const char pcmrec_thread_name[] = "pcmrec";
123 151
124static void pcmrec_thread(void); 152static void pcmrec_thread(void);
125static void pcmrec_dma_start(void); 153static void pcmrec_dma_start(void);
126static void pcmrec_dma_stop(void); 154static void pcmrec_dma_stop(void);
155static void close_wave(void);
127 156
128/* Event IDs */ 157/* Event IDs */
129#define PCMREC_INIT 1 /* Enable recording */ 158#define PCMREC_INIT 1 /* Enable recording */
@@ -144,10 +173,16 @@ static void pcmrec_dma_stop(void);
144void pcm_rec_init(void) 173void pcm_rec_init(void)
145{ 174{
146 queue_init(&pcmrec_queue); 175 queue_init(&pcmrec_queue);
147 create_thread(pcmrec_thread, pcmrec_stack, sizeof(pcmrec_stack), pcmrec_thread_name); 176 create_thread(pcmrec_thread, pcmrec_stack, sizeof(pcmrec_stack),
177 pcmrec_thread_name);
148} 178}
149 179
150 180
181int audio_get_encoder_id(void)
182{
183 return audio_enc_id;
184}
185
151/* Initializes recording: 186/* Initializes recording:
152 * - Set up the UDA1380/TLV320 for recording 187 * - Set up the UDA1380/TLV320 for recording
153 * - Prepare for DMA transfers 188 * - Prepare for DMA transfers
@@ -155,13 +190,14 @@ void pcm_rec_init(void)
155 190
156void audio_init_recording(unsigned int buffer_offset) 191void audio_init_recording(unsigned int buffer_offset)
157{ 192{
158 rec_buffer_offset = buffer_offset; 193 (void)buffer_offset;
194
159 init_done = false; 195 init_done = false;
160 queue_post(&pcmrec_queue, PCMREC_INIT, 0); 196 queue_post(&pcmrec_queue, PCMREC_INIT, 0);
161 197
162 while(!init_done) 198 while(!init_done)
163 sleep_thread(); 199 sleep_thread();
164 wake_up_thread(); 200 wake_up_thread();
165} 201}
166 202
167void audio_close_recording(void) 203void audio_close_recording(void)
@@ -171,7 +207,9 @@ void audio_close_recording(void)
171 207
172 while(!close_done) 208 while(!close_done)
173 sleep_thread(); 209 sleep_thread();
174 wake_up_thread(); 210 wake_up_thread();
211
212 audio_remove_encoder();
175} 213}
176 214
177unsigned long pcm_rec_status(void) 215unsigned long pcm_rec_status(void)
@@ -184,10 +222,17 @@ unsigned long pcm_rec_status(void)
184 ret |= AUDIO_STATUS_PAUSE; 222 ret |= AUDIO_STATUS_PAUSE;
185 if (is_error) 223 if (is_error)
186 ret |= AUDIO_STATUS_ERROR; 224 ret |= AUDIO_STATUS_ERROR;
225 if (!is_recording && pre_record_ticks && init_done && !close_done)
226 ret |= AUDIO_STATUS_PRERECORD;
187 227
188 return ret; 228 return ret;
189} 229}
190 230
231int pcm_rec_current_bitrate(void)
232{
233 return avrg_bit_rate;
234}
235
191unsigned long audio_recorded_time(void) 236unsigned long audio_recorded_time(void)
192{ 237{
193 if (is_recording) 238 if (is_recording)
@@ -248,6 +293,8 @@ unsigned long audio_get_spdif_sample_rate(void)
248} 293}
249#endif 294#endif
250 295
296#if 0
297/* not needed atm */
251#ifdef HAVE_SPDIF_POWER 298#ifdef HAVE_SPDIF_POWER
252static bool spdif_power_setting; 299static bool spdif_power_setting;
253 300
@@ -256,21 +303,18 @@ void audio_set_spdif_power_setting(bool on)
256 spdif_power_setting = on; 303 spdif_power_setting = on;
257} 304}
258#endif 305#endif
306#endif
259 307
260/** 308/**
261 * Sets the audio source 309 * Sets recording parameters
262 * 310 *
263 * This functions starts feeding the CPU with audio data over the I2S bus 311 * This functions starts feeding the CPU with audio data over the I2S bus
264 *
265 * @param source 0=mic, 1=line-in, 2=spdif
266 */ 312 */
267void audio_set_recording_options(int frequency, int quality, 313void audio_set_recording_options(int frequency, int quality,
268 int source, int channel_mode, 314 int source, int channel_mode,
269 bool editable, int prerecord_time) 315 bool editable, int prerecord_time)
270{ 316{
271 /* TODO: */ 317 /* TODO: */
272 (void)quality;
273 (void)channel_mode;
274 (void)editable; 318 (void)editable;
275 319
276 /* NOTE: Coldfire UDA based recording does not yet support anything other 320 /* NOTE: Coldfire UDA based recording does not yet support anything other
@@ -278,69 +322,30 @@ void audio_set_recording_options(int frequency, int quality,
278 * based recording will overwrite this value with the proper sample rate in 322 * based recording will overwrite this value with the proper sample rate in
279 * audio_record(), and will not be affected by this. 323 * audio_record(), and will not be affected by this.
280 */ 324 */
281 frequency = 44100; 325 frequency = 44100;
326 enc_quality = quality;
327 rec_source = source;
328 enc_channels = channel_mode == CHN_MODE_MONO ? 1 : 2;
282 pre_record_ticks = prerecord_time * HZ; 329 pre_record_ticks = prerecord_time * HZ;
283 pre_record_chunks = ((frequency * prerecord_time * 4)/CHUNK_SIZE)+1;
284 if(pre_record_chunks >= (num_chunks-250))
285 {
286 /* we can't prerecord more than our buffersize minus treshold to write to disk! */
287 pre_record_chunks = num_chunks-250;
288 /* don't forget to recalculate that time! */
289 pre_record_ticks = ((pre_record_chunks * CHUNK_SIZE)/(4*frequency)) * HZ;
290 }
291
292 //logf("pcmrec: src=%d", source);
293 330
294 rec_source = source;
295#ifdef HAVE_SPDIF_POWER
296 /* Check if S/PDIF output power should be switched off or on. NOTE: assumes
297 both optical in and out is controlled by the same power source, which is
298 the case on H1x0. */
299 spdif_power_enable((source == 2) || spdif_power_setting);
300#endif
301 switch (source) 331 switch (source)
302 { 332 {
303 /* mic */ 333 case AUDIO_SRC_MIC:
304 case 0: 334 case AUDIO_SRC_LINEIN:
305 /* Generate int. when 6 samples in FIFO, PDIR2 src = IIS1recv */ 335#ifdef HAVE_FMRADIO_IN
306 DATAINCONTROL = 0xc020; 336 case AUDIO_SRC_FMRADIO:
307
308#ifdef HAVE_UDA1380
309 uda1380_enable_recording(true);
310#endif 337#endif
311#ifdef HAVE_TLV320
312 tlv320_enable_recording(true);
313#endif
314 break;
315
316 /* line-in */
317 case 1:
318 /* Generate int. when 6 samples in FIFO, PDIR2 src = IIS1recv */ 338 /* Generate int. when 6 samples in FIFO, PDIR2 src = IIS1recv */
319 DATAINCONTROL = 0xc020; 339 DATAINCONTROL = 0xc020;
320
321#ifdef HAVE_UDA1380
322 uda1380_enable_recording(false);
323#endif
324#ifdef HAVE_TLV320
325 tlv320_enable_recording(false);
326#endif
327 break; 340 break;
328#ifdef HAVE_SPDIF_IN 341
329 /* SPDIF */ 342#ifdef HAVE_SPDIF_IN
330 case 2: 343 case AUDIO_SRC_SPDIF:
331 /* Int. when 6 samples in FIFO. PDIR2 source = ebu1RcvData */ 344 /* Int. when 6 samples in FIFO. PDIR2 source = ebu1RcvData */
332 DATAINCONTROL = 0xc038; 345 DATAINCONTROL = 0xc038;
333#ifdef HAVE_SPDIF_POWER
334 EBU1CONFIG = spdif_power_setting ? (1 << 2) : 0;
335 /* Input source is EBUin1, Feed-through monitoring if desired */
336#else
337 EBU1CONFIG = (1 << 2);
338 /* Input source is EBUin1, Feed-through monitoring */
339#endif
340 uda1380_disable_recording();
341 break; 346 break;
342#endif 347#endif /* HAVE_SPDIF_IN */
343 } 348 }
344 349
345 sample_rate = frequency; 350 sample_rate = frequency;
346 351
@@ -349,7 +354,8 @@ void audio_set_recording_options(int frequency, int quality,
349 SET_IIS_PLAY(0x800); /* Reset before reprogram */ 354 SET_IIS_PLAY(0x800); /* Reset before reprogram */
350 355
351#ifdef HAVE_SPDIF_IN 356#ifdef HAVE_SPDIF_IN
352 if (source == 2) { 357 if (source == AUDIO_SRC_SPDIF)
358 {
353 /* SCLK2 = Audioclk/4 (can't use EBUin clock), TXSRC = EBU1rcv, 64 bclk/wclk */ 359 /* SCLK2 = Audioclk/4 (can't use EBUin clock), TXSRC = EBU1rcv, 64 bclk/wclk */
354 IIS2CONFIG = (6 << 12) | (7 << 8) | (4 << 2); 360 IIS2CONFIG = (6 << 12) | (7 << 8) | (4 << 2);
355 /* S/PDIF feed-through already configured */ 361 /* S/PDIF feed-through already configured */
@@ -367,6 +373,8 @@ void audio_set_recording_options(int frequency, int quality,
367 /* SCLK2 follow IIS1 (UDA clock), TXSRC = IIS1rcv, 64 bclk/wclk */ 373 /* SCLK2 follow IIS1 (UDA clock), TXSRC = IIS1rcv, 64 bclk/wclk */
368 SET_IIS_PLAY( (8 << 12) | (4 << 8) | (4 << 2) ); 374 SET_IIS_PLAY( (8 << 12) | (4 << 8) | (4 << 2) );
369#endif 375#endif
376
377 audio_load_encoder(rec_quality_info_afmt[quality]);
370} 378}
371 379
372 380
@@ -380,10 +388,9 @@ void audio_set_recording_options(int frequency, int quality,
380void audio_set_recording_gain(int left, int right, int type) 388void audio_set_recording_gain(int left, int right, int type)
381{ 389{
382 //logf("rcmrec: t=%d l=%d r=%d", type, left, right); 390 //logf("rcmrec: t=%d l=%d r=%d", type, left, right);
383#ifdef HAVE_UDA1380 391#if defined(HAVE_UDA1380)
384 uda1380_set_recvol(left, right, type); 392 uda1380_set_recvol(left, right, type);
385#endif 393#elif defined (HAVE_TLV320)
386#ifdef HAVE_TLV320
387 tlv320_set_recvol(left, right, type); 394 tlv320_set_recvol(left, right, type);
388#endif 395#endif
389} 396}
@@ -406,7 +413,7 @@ void audio_record(const char *filename)
406 recording_filename[MAX_PATH - 1] = 0; 413 recording_filename[MAX_PATH - 1] = 0;
407 414
408#ifdef HAVE_SPDIF_IN 415#ifdef HAVE_SPDIF_IN
409 if (rec_source == 2) 416 if (rec_source == AUDIO_SRC_SPDIF)
410 sample_rate = audio_get_spdif_sample_rate(); 417 sample_rate = audio_get_spdif_sample_rate();
411#endif 418#endif
412 419
@@ -447,6 +454,7 @@ void audio_stop_recording(void)
447 454
448 logf("pcm_stop"); 455 logf("pcm_stop");
449 456
457 is_paused = true; /* fix pcm write ptr at current position */
450 stop_done = false; 458 stop_done = false;
451 queue_post(&pcmrec_queue, PCMREC_STOP, 0); 459 queue_post(&pcmrec_queue, PCMREC_STOP, 0);
452 460
@@ -499,9 +507,9 @@ void audio_resume_recording(void)
499void pcm_rec_get_peaks(int *left, int *right) 507void pcm_rec_get_peaks(int *left, int *right)
500{ 508{
501 if (left) 509 if (left)
502 *left = (int)peak_left; 510 *left = peak_left;
503 if (right) 511 if (right)
504 *right = (int)peak_right; 512 *right = peak_right;
505 peak_left = 0; 513 peak_left = 0;
506 peak_right = 0; 514 peak_right = 0;
507} 515}
@@ -511,7 +519,7 @@ void pcm_rec_get_peaks(int *left, int *right)
511/***************************************************************************/ 519/***************************************************************************/
512 520
513/** 521/**
514 * Process the chunks using read_index and write_index. 522 * Process the chunks
515 * 523 *
516 * This function is called when queue_get_w_tmo times out. 524 * This function is called when queue_get_w_tmo times out.
517 * 525 *
@@ -519,70 +527,24 @@ void pcm_rec_get_peaks(int *left, int *right)
519 * they want to save everything in the buffers to disk. 527 * they want to save everything in the buffers to disk.
520 * 528 *
521 */ 529 */
522
523static void pcmrec_callback(bool flush) ICODE_ATTR;
524static void pcmrec_callback(bool flush) 530static void pcmrec_callback(bool flush)
525{ 531{
526 int num_ready, num_free, num_new; 532 int i, num_ready, size_yield;
527 short *ptr; 533 long *enc_chunk, chunk_size;
528 short value;
529 int i, j, w;
530
531 w = write_index;
532
533 num_new = w - read2_index;
534 if (num_new < 0)
535 num_new += num_chunks;
536
537 for (i=0; i<num_new; i++)
538 {
539 /* Convert the samples to little-endian so we only have to write later
540 (Less hd-spinning time), also do peak detection while we're at it
541 */
542 ptr = GET_CHUNK(read2_index);
543 for (j=0; j<CHUNK_SIZE/4; j++)
544 {
545 value = *ptr;
546 if(value > peak_left)
547 peak_left = value;
548 else if (-value > peak_left)
549 peak_left = -value;
550
551 *ptr = htole16(value);
552 ptr++;
553
554 value = *ptr;
555 if(value > peak_right)
556 peak_right = value;
557 else if (-value > peak_right)
558 peak_right = -value;
559
560 *ptr = htole16(value);
561 ptr++;
562 }
563 534
564 if(is_recording && !is_paused) 535 if (!is_recording && !flush)
565 num_rec_bytes += CHUNK_SIZE;
566
567 read2_index++;
568 if (read2_index >= num_chunks)
569 read2_index = 0;
570 }
571
572 if ((!is_recording || is_paused) && !flush)
573 {
574 /* not recording = no saving to disk, fake buffer clearing */
575 read_index = write_index;
576 return; 536 return;
577 }
578 537
579 num_ready = w - read_index; 538 num_ready = enc_wr_index - enc_rd_index;
580 if (num_ready < 0) 539 if (num_ready < 0)
581 num_ready += num_chunks; 540 num_ready += enc_num_chunks;
582 541
583 num_free = num_chunks - num_ready; 542 /* calculate an estimate of recorded bytes */
584 543 num_rec_bytes = num_file_bytes + num_ready * /* enc_chunk_size */
585 if (num_free <= WRITE_THRESHOLD || flush) 544 ((avrg_bit_rate * 1000 / 8 * enc_samp_per_chunk + 22050) / 44100);
545
546 /* near full state reached: less than 5sec remaining space */
547 if (enc_num_chunks - num_ready < WRITE_THRESHOLD || flush)
586 { 548 {
587 bool must_boost = (boost_counter ? false : true); 549 bool must_boost = (boost_counter ? false : true);
588 550
@@ -591,23 +553,41 @@ static void pcmrec_callback(bool flush)
591 if(must_boost) 553 if(must_boost)
592 cpu_boost(true); 554 cpu_boost(true);
593 555
556 size_yield = 0;
594 for (i=0; i<num_ready; i++) 557 for (i=0; i<num_ready; i++)
595 { 558 {
596 if (write(wav_file, GET_CHUNK(read_index), CHUNK_SIZE) != CHUNK_SIZE) 559 enc_chunk = GET_ENC_CHUNK(enc_rd_index);
560 chunk_size = *enc_chunk++;
561
562 /* safety net: if size entry got corrupted => limit */
563 if (chunk_size > (long)(enc_chunk_size - sizeof(long)))
564 chunk_size = enc_chunk_size - sizeof(long);
565
566 if (enc_set_header_callback != NULL)
567 enc_set_header_callback(enc_chunk, enc_chunk_size,
568 num_pcm_samples, false);
569
570 if (write(wav_file, enc_chunk, chunk_size) != chunk_size)
597 { 571 {
572 close_wave();
598 if(must_boost) 573 if(must_boost)
599 cpu_boost(false); 574 cpu_boost(false);
600 logf("pcmrec: write err"); 575 logf("pcmrec: write err");
601 pcmrec_dma_stop(); 576 is_error = true;
602 return; 577 break;
603 } 578 }
604 579
605 num_file_bytes += CHUNK_SIZE; 580 num_file_bytes += chunk_size;
606 581 num_pcm_samples += enc_samp_per_chunk;
607 read_index++; 582 size_yield += chunk_size;
608 if (read_index >= num_chunks) 583
609 read_index = 0; 584 if (size_yield >= 32768)
610 yield(); 585 { /* yield when 32kB written */
586 size_yield = 0;
587 yield();
588 }
589
590 enc_rd_index = (enc_rd_index + 1) % enc_num_chunks;
611 } 591 }
612 592
613 if(must_boost) 593 if(must_boost)
@@ -623,36 +603,33 @@ static void pcmrec_callback(bool flush)
623/* Abort dma transfer */ 603/* Abort dma transfer */
624static void pcmrec_dma_stop(void) 604static void pcmrec_dma_stop(void)
625{ 605{
626 DCR1 = 0; 606 DCR1 = 0;
627 607
628 is_error = true;
629 is_recording = false;
630
631 error_count++; 608 error_count++;
632 609
610 DSR1 = 1; /* Clear interrupt */
611 IPR |= (1<<15); /* Clear pending interrupt request */
612
633 logf("dma1 stopped"); 613 logf("dma1 stopped");
634} 614}
635 615
636static void pcmrec_dma_start(void) 616static void pcmrec_dma_start(void)
637{ 617{
638 DAR1 = (unsigned long)GET_CHUNK(write_index); /* Destination address */ 618 DAR1 = (unsigned long)GET_CHUNK(write_pos); /* Destination address */
639 SAR1 = (unsigned long)&PDIR2; /* Source address */ 619 SAR1 = (unsigned long)&PDIR2; /* Source address */
640 BCR1 = CHUNK_SIZE; /* Bytes to transfer */ 620 BCR1 = CHUNK_SIZE; /* Bytes to transfer */
641 621
642 /* Start the DMA transfer.. */ 622 /* Start the DMA transfer.. */
643 DCR1 = DMA_INT | DMA_EEXT | DMA_CS | DMA_DINC | DMA_START;
644
645#ifdef HAVE_SPDIF_IN 623#ifdef HAVE_SPDIF_IN
646 INTERRUPTCLEAR = 0x03c00000; 624 INTERRUPTCLEAR = 0x03c00000;
647#endif 625#endif
648 626
649 /* pre-recording: buffer count */ 627 /* 16Byte transfers prevents from sporadic errors during cpu_boost() */
650 buffered_chunks = 0; 628 DCR1 = DMA_INT | DMA_EEXT | DMA_CS | DMA_DINC | DMA_DSIZE(3) | DMA_START;
651 629
652 logf("dma1 started"); 630 logf("dma1 started");
653} 631}
654 632
655
656/* DMA1 Interrupt is called when the DMA has finished transfering a chunk */ 633/* DMA1 Interrupt is called when the DMA has finished transfering a chunk */
657void DMA1(void) __attribute__ ((interrupt_handler, section(".icode"))); 634void DMA1(void) __attribute__ ((interrupt_handler, section(".icode")));
658void DMA1(void) 635void DMA1(void)
@@ -668,62 +645,64 @@ void DMA1(void)
668 645
669 logf("dma1 err: 0x%x", res); 646 logf("dma1 err: 0x%x", res);
670 647
671 DAR1 = (unsigned long)GET_CHUNK(write_index); /* Destination address */ 648 DAR1 = (unsigned long)GET_CHUNK(write_pos); /* Destination address */
672 BCR1 = CHUNK_SIZE; 649 BCR1 = CHUNK_SIZE;
673 DCR1 = DMA_INT | DMA_EEXT | DMA_CS | DMA_DINC | DMA_START; 650 DCR1 = DMA_INT | DMA_EEXT | DMA_CS | DMA_DINC | DMA_START;
651
652 /* Flush recorded data to disk and stop recording */
653 queue_post(&pcmrec_queue, PCMREC_STOP, NULL);
674 } 654 }
675#ifdef HAVE_SPDIF_IN 655#ifdef HAVE_SPDIF_IN
676 else if ((rec_source == 2) && (INTERRUPTSTAT & 0x01c00000)) /* valnogood, symbolerr, parityerr */ 656 else if ((rec_source == AUDIO_SRC_SPDIF) &&
657 (INTERRUPTSTAT & 0x01c00000)) /* valnogood, symbolerr, parityerr */
677 { 658 {
678 INTERRUPTCLEAR = 0x03c00000; 659 INTERRUPTCLEAR = 0x03c00000;
679 error_count++; 660 error_count++;
680 661
681 logf("spdif err"); 662 logf("spdif err");
682 663
683 if (is_stopping) 664 DAR1 = (unsigned long)GET_CHUNK(write_pos); /* Destination address */
684 { 665 BCR1 = CHUNK_SIZE;
685 DCR1 = 0; /* Stop DMA transfer */
686 is_stopping = false;
687
688 logf("dma1 stopping");
689 }
690 else
691 {
692 DAR1 = (unsigned long)GET_CHUNK(write_index); /* Destination address */
693 BCR1 = CHUNK_SIZE;
694 }
695 } 666 }
696#endif 667#endif
697 else 668 else
698 { 669 {
699 write_index++; 670 long peak_l, peak_r;
700 if (write_index >= num_chunks) 671 long *ptr, j;
701 write_index = 0;
702 672
703 /* update number of valid chunks for pre-recording */ 673 ptr = GET_CHUNK(write_pos);
704 if(buffered_chunks < num_chunks)
705 buffered_chunks++;
706 674
707 if (is_stopping) 675 if (!is_paused) /* advance write position */
708 { 676 write_pos = (write_pos + CHUNK_SIZE) & CHUNK_MASK;
709 DCR1 = 0; /* Stop DMA transfer */
710 is_stopping = false;
711 677
712 logf("dma1 stopping"); 678 DAR1 = (unsigned long)GET_CHUNK(write_pos); /* Destination address */
713 } 679 BCR1 = CHUNK_SIZE;
714 else if (write_index == read_index)
715 {
716 DCR1 = 0; /* Stop DMA transfer */
717 is_recording = false;
718 680
719 logf("dma1 overrun"); 681 peak_l = peak_r = 0;
720 682
721 } 683 /* only peak every 4th sample */
722 else 684 for (j=0; j<CHUNK_SIZE/4; j+=4)
723 { 685 {
724 DAR1 = (unsigned long)GET_CHUNK(write_index); /* Destination address */ 686 long value = ptr[j];
725 BCR1 = CHUNK_SIZE; 687#ifdef ROCKBOX_BIG_ENDIAN
688 if (value > peak_l) peak_l = value;
689 else if (-value > peak_l) peak_l = -value;
690
691 value <<= 16;
692 if (value > peak_r) peak_r = value;
693 else if (-value > peak_r) peak_r = -value;
694#else
695 if (value > peak_r) peak_r = value;
696 else if (-value > peak_r) peak_r = -value;
697
698 value <<= 16;
699 if (value > peak_l) peak_l = value;
700 else if (-value > peak_l) peak_l = -value;
701#endif
726 } 702 }
703
704 peak_left = (int)(peak_l >> 16);
705 peak_right = (int)(peak_r >> 16);
727 } 706 }
728 707
729 IPR |= (1<<15); /* Clear pending interrupt request */ 708 IPR |= (1<<15); /* Clear pending interrupt request */
@@ -733,15 +712,8 @@ void DMA1(void)
733/* Sets returns 0 if success, -1 on failure */ 712/* Sets returns 0 if success, -1 on failure */
734static int start_wave(void) 713static int start_wave(void)
735{ 714{
736 unsigned char header[44] =
737 {
738 'R','I','F','F',0,0,0,0,'W','A','V','E','f','m','t',' ',
739 0x10,0,0,0,1,0,2,0,0,0,0,0,0,0,0,0,
740 4,0,0x10,0,'d','a','t','a',0,0,0,0
741 };
742 unsigned long avg_bytes_per_sec;
743
744 wav_file = open(recording_filename, O_RDWR|O_CREAT|O_TRUNC); 715 wav_file = open(recording_filename, O_RDWR|O_CREAT|O_TRUNC);
716
745 if (wav_file < 0) 717 if (wav_file < 0)
746 { 718 {
747 wav_file = -1; 719 wav_file = -1;
@@ -749,19 +721,9 @@ static int start_wave(void)
749 is_error = true; 721 is_error = true;
750 return -1; 722 return -1;
751 } 723 }
752 /* Now set the sample rate field of the WAV header to what it should be */
753 header[24] = (unsigned char)(sample_rate & 0xff);
754 header[25] = (unsigned char)(sample_rate >> 8);
755 header[26] = (unsigned char)(sample_rate >> 16);
756 header[27] = (unsigned char)(sample_rate >> 24);
757 /* And then the average bytes per second field */
758 avg_bytes_per_sec = sample_rate*4; /* Hard coded to 16 bit stereo */
759 header[28] = (unsigned char)(avg_bytes_per_sec & 0xff);
760 header[29] = (unsigned char)(avg_bytes_per_sec >> 8);
761 header[30] = (unsigned char)(avg_bytes_per_sec >> 16);
762 header[31] = (unsigned char)(avg_bytes_per_sec >> 24);
763 724
764 if (sizeof(header) != write(wav_file, header, sizeof(header))) 725 /* add main file header (enc_head_size=0 for encoders without) */
726 if (enc_head_size != write(wav_file, enc_head_buffer, enc_head_size))
765 { 727 {
766 close(wav_file); 728 close(wav_file);
767 wav_file = -1; 729 wav_file = -1;
@@ -776,18 +738,22 @@ static int start_wave(void)
776/* Update header and set correct length values */ 738/* Update header and set correct length values */
777static void close_wave(void) 739static void close_wave(void)
778{ 740{
779 long l; 741 unsigned char head[100]; /* assume maximum 100 bytes for file header */
742 int size_read;
780 743
781 if (wav_file != -1) 744 if (wav_file != -1)
782 { 745 {
783 l = htole32(num_file_bytes + 36); 746 /* update header before closing the file (wav+wv encoder will do) */
784 lseek(wav_file, 4, SEEK_SET); 747 if (enc_set_header_callback != NULL)
785 write(wav_file, &l, 4); 748 {
786 749 lseek(wav_file, 0, SEEK_SET);
787 l = htole32(num_file_bytes); 750 /* try to read the head size (but we'll accept less) */
788 lseek(wav_file, 40, SEEK_SET); 751 size_read = read(wav_file, head, sizeof(head));
789 write(wav_file, &l, 4); 752
790 753 enc_set_header_callback(head, size_read, num_pcm_samples, true);
754 lseek(wav_file, 0, SEEK_SET);
755 write(wav_file, head, size_read);
756 }
791 close(wav_file); 757 close(wav_file);
792 wav_file = -1; 758 wav_file = -1;
793 } 759 }
@@ -795,8 +761,7 @@ static void close_wave(void)
795 761
796static void pcmrec_start(void) 762static void pcmrec_start(void)
797{ 763{
798 int pre_chunks = pre_record_chunks; /* recalculate every time! */ 764 long max_pre_chunks, pre_ticks, max_pre_ticks;
799 long pre_ticks = pre_record_ticks; /* recalculate every time! */
800 765
801 logf("pcmrec_start"); 766 logf("pcmrec_start");
802 767
@@ -808,7 +773,7 @@ static void pcmrec_start(void)
808 } 773 }
809 774
810 if (wav_file != -1) 775 if (wav_file != -1)
811 close(wav_file); 776 close_wave();
812 777
813 if (start_wave() != 0) 778 if (start_wave() != 0)
814 { 779 {
@@ -817,32 +782,29 @@ static void pcmrec_start(void)
817 return; 782 return;
818 } 783 }
819 784
820 /* pre-recording calculation */ 785 /* calculate maximum available chunks & resulting ticks */
821 if(buffered_chunks < pre_chunks) 786 max_pre_chunks = (enc_wr_index - enc_rd_index +
822 { 787 enc_num_chunks) % enc_num_chunks;
823 /* not enough good chunks available - limit pre-record time */ 788 if (max_pre_chunks > enc_num_chunks - WRITE_THRESHOLD)
824 pre_chunks = buffered_chunks; 789 max_pre_chunks = enc_num_chunks - WRITE_THRESHOLD;
825 pre_ticks = ((buffered_chunks * CHUNK_SIZE)/(4*sample_rate)) * HZ; 790 max_pre_ticks = max_pre_chunks * HZ * enc_samp_per_chunk / 44100;
826 }
827 record_start_time = current_tick - pre_ticks;
828 791
829 read_index = write_index - pre_chunks; 792 /* limit prerecord if not enough data available */
830 if(read_index < 0) 793 pre_ticks = pre_record_ticks > max_pre_ticks ?
831 { 794 max_pre_ticks : pre_record_ticks;
832 read_index += num_chunks; 795 max_pre_chunks = 44100 * pre_ticks / HZ / enc_samp_per_chunk;
833 } 796 enc_rd_index = (enc_wr_index - max_pre_chunks +
797 enc_num_chunks) % enc_num_chunks;
834 798
835 peak_left = 0; 799 record_start_time = current_tick - pre_ticks;
836 peak_right = 0; 800
837 801 num_rec_bytes = enc_num_chunks * CHUNK_SIZE;
838 num_rec_bytes = pre_chunks * CHUNK_SIZE;
839 num_file_bytes = 0; 802 num_file_bytes = 0;
803 num_pcm_samples = 0;
840 pause_start_time = 0; 804 pause_start_time = 0;
841 805
842 is_stopping = false;
843 is_paused = false; 806 is_paused = false;
844 is_recording = true; 807 is_recording = true;
845
846 record_done = true; 808 record_done = true;
847} 809}
848 810
@@ -850,36 +812,24 @@ static void pcmrec_stop(void)
850{ 812{
851 logf("pcmrec_stop"); 813 logf("pcmrec_stop");
852 814
853 if (!is_recording) 815 if (is_recording)
854 { 816 {
855 stop_done = true; 817 /* wait for encoding finish */
856 return; 818 is_paused = true;
857 } 819 while(!wav_queue_empty)
858
859 if (!is_paused)
860 {
861 /* wait for recording to finish */
862 is_stopping = true;
863
864 while (is_stopping && is_recording)
865 sleep_thread(); 820 sleep_thread();
866 wake_up_thread();
867
868 is_stopping = false;
869 }
870
871 is_recording = false;
872
873 /* Flush buffers to file */
874 pcmrec_callback(true);
875 821
876 close_wave(); 822 wake_up_thread();
823 is_recording = false;
877 824
825 /* Flush buffers to file */
826 pcmrec_callback(true);
827 close_wave();
828 }
829
830 is_paused = false;
878 stop_done = true; 831 stop_done = true;
879 832
880 /* Finally start dma again for peakmeters and pre-recoding to work. */
881 pcmrec_dma_start();
882
883 logf("pcmrec_stop done"); 833 logf("pcmrec_stop done");
884} 834}
885 835
@@ -898,7 +848,6 @@ static void pcmrec_new_file(void)
898 here is a good approximation when recording to the new file starts 848 here is a good approximation when recording to the new file starts
899 */ 849 */
900 record_start_time = current_tick; 850 record_start_time = current_tick;
901 num_rec_bytes = 0;
902 851
903 if (is_paused) 852 if (is_paused)
904 pause_start_time = record_start_time; 853 pause_start_time = record_start_time;
@@ -908,7 +857,9 @@ static void pcmrec_new_file(void)
908 857
909 close_wave(); 858 close_wave();
910 859
860 num_rec_bytes = 0;
911 num_file_bytes = 0; 861 num_file_bytes = 0;
862 num_pcm_samples = 0;
912 863
913 /* start the new file */ 864 /* start the new file */
914 if (start_wave() != 0) 865 if (start_wave() != 0)
@@ -932,20 +883,8 @@ static void pcmrec_pause(void)
932 return; 883 return;
933 } 884 }
934 885
935 /* Abort DMA transfer and flush to file? */
936
937 is_stopping = true;
938
939 while (is_stopping && is_recording)
940 sleep_thread();
941 wake_up_thread();
942
943 pause_start_time = current_tick; 886 pause_start_time = current_tick;
944 is_paused = true; 887 is_paused = true;
945
946 /* Flush what we got in buffers to file */
947 pcmrec_callback(true);
948
949 pause_done = true; 888 pause_done = true;
950 889
951 logf("pcmrec_pause done"); 890 logf("pcmrec_pause done");
@@ -973,10 +912,7 @@ static void pcmrec_resume(void)
973 pause_start_time = 0; 912 pause_start_time = 0;
974 } 913 }
975 914
976 pcmrec_dma_start();
977
978 resume_done = true; 915 resume_done = true;
979
980 logf("pcmrec_resume done"); 916 logf("pcmrec_resume done");
981} 917}
982 918
@@ -986,50 +922,47 @@ static void pcmrec_resume(void)
986 */ 922 */
987static void pcmrec_init(void) 923static void pcmrec_init(void)
988{ 924{
989 unsigned long buffer_size;
990
991 wav_file = -1; 925 wav_file = -1;
992 read_index = 0; 926 read_pos = 0;
993 read2_index = 0; 927 write_pos = 0;
994 write_index = 0; 928 enc_wr_index = 0;
995 pre_record_chunks = 0; 929 enc_rd_index = 0;
996 pre_record_ticks = 0; 930
931 avrg_bit_rate = 0;
932 curr_bit_rate = 0;
933 curr_chunk_cnt = 0;
997 934
998 peak_left = 0; 935 peak_left = 0;
999 peak_right = 0; 936 peak_right = 0;
1000 937
1001 num_rec_bytes = 0; 938 num_rec_bytes = 0;
1002 num_file_bytes = 0; 939 num_file_bytes = 0;
940 num_pcm_samples = 0;
1003 record_start_time = 0; 941 record_start_time = 0;
1004 pause_start_time = 0; 942 pause_start_time = 0;
1005 buffered_chunks = 0; 943
1006 944 close_done = false;
1007 is_recording = false; 945 is_recording = false;
1008 is_stopping = false;
1009 is_paused = false; 946 is_paused = false;
1010 is_error = false; 947 is_error = false;
1011 948
1012 rec_buffer = (unsigned char*)(((unsigned long)audiobuf + rec_buffer_offset) & ~3); 949 rec_buffer = (unsigned char*)(((long)audiobuf + 15) & ~15);
1013 buffer_size = (long)audiobufend - (long)audiobuf - rec_buffer_offset - 16; 950 enc_buffer = rec_buffer + NUM_CHUNKS * CHUNK_SIZE + MAX_FEED_SIZE;
1014 951 /* 8000Bytes at audiobufend */
1015 logf("buf size: %d kb", buffer_size/1024); 952 enc_buffer_size = audiobufend - enc_buffer - 8000;
1016
1017 num_chunks = buffer_size / CHUNK_SIZE;
1018
1019 logf("num_chunks: %d", num_chunks);
1020 953
1021 SET_IIS_PLAY(0x800); /* Stop any playback */ 954 SET_IIS_PLAY(0x800); /* Stop any playback */
1022 AUDIOGLOB |= 0x180; /* IIS1 fifo auto sync = on, PDIR2 auto sync = on */ 955 AUDIOGLOB |= 0x180; /* IIS1 fifo auto sync = on, PDIR2 auto sync = on */
1023 DATAINCONTROL = 0xc000; /* Generate Interrupt when 6 samples in fifo */ 956 DATAINCONTROL = 0xc000; /* Generate Interrupt when 6 samples in fifo */
1024 957
1025 DIVR1 = 55; /* DMA1 is mapped into vector 55 in system.c */ 958 DIVR1 = 55; /* DMA1 is mapped into vector 55 in system.c */
1026 DMACONFIG = 1; /* DMA0Req = PDOR3, DMA1Req = PDIR2 */ 959 DMACONFIG = 1; /* DMA0Req = PDOR3, DMA1Req = PDIR2 */
1027 DMAROUTE = (DMAROUTE & 0xffff00ff) | DMA1_REQ_AUDIO_2; 960 DMAROUTE = (DMAROUTE & 0xffff00ff) | DMA1_REQ_AUDIO_2;
1028 ICR7 = 0x1c; /* Enable interrupt at level 7, priority 0 */ 961 ICR7 = 0x1c; /* Enable interrupt at level 7, priority 0 */
1029 IMR &= ~(1<<15); /* bit 15 is DMA1 */ 962 IMR &= ~(1<<15); /* bit 15 is DMA1 */
1030 963
1031#ifdef HAVE_SPDIF_IN 964#ifdef HAVE_SPDIF_IN
1032 PHASECONFIG = 0x34; /* Gain = 3*2^13, source = EBUIN */ 965 PHASECONFIG = 0x34; /* Gain = 3*2^13, source = EBUIN */
1033#endif 966#endif
1034 pcmrec_dma_start(); 967 pcmrec_dma_start();
1035 968
@@ -1038,23 +971,16 @@ static void pcmrec_init(void)
1038 971
1039static void pcmrec_close(void) 972static void pcmrec_close(void)
1040{ 973{
1041#ifdef HAVE_UDA1380
1042 uda1380_disable_recording();
1043#endif
1044#ifdef HAVE_TLV320
1045 tlv320_disable_recording();
1046#endif
1047
1048#ifdef HAVE_SPDIF_POWER
1049 spdif_power_enable(spdif_power_setting);
1050#endif
1051 DMAROUTE = (DMAROUTE & 0xffff00ff); 974 DMAROUTE = (DMAROUTE & 0xffff00ff);
1052 ICR7 = 0x00; /* Disable interrupt */ 975 ICR7 = 0x00; /* Disable interrupt */
1053 IMR |= (1<<15); /* bit 15 is DMA1 */ 976 IMR |= (1<<15); /* bit 15 is DMA1 */
1054 977
978 pcmrec_dma_stop();
979
1055 /* Reset PDIR2 data flow */ 980 /* Reset PDIR2 data flow */
1056 DATAINCONTROL = 0x200; 981 DATAINCONTROL = 0x200;
1057 close_done = true; 982 close_done = true;
983 init_done = false;
1058} 984}
1059 985
1060static void pcmrec_thread(void) 986static void pcmrec_thread(void)
@@ -1064,10 +990,10 @@ static void pcmrec_thread(void)
1064 logf("thread pcmrec start"); 990 logf("thread pcmrec start");
1065 991
1066 error_count = 0; 992 error_count = 0;
1067 993
1068 while (1) 994 while(1)
1069 { 995 {
1070 queue_wait_w_tmo(&pcmrec_queue, &ev, HZ / 40); 996 queue_wait_w_tmo(&pcmrec_queue, &ev, HZ / 4);
1071 997
1072 switch (ev.id) 998 switch (ev.id)
1073 { 999 {
@@ -1104,8 +1030,9 @@ static void pcmrec_thread(void)
1104 break; 1030 break;
1105 1031
1106 case SYS_USB_CONNECTED: 1032 case SYS_USB_CONNECTED:
1107 if (!is_recording && !is_stopping) 1033 if (!is_recording)
1108 { 1034 {
1035 pcmrec_close();
1109 usb_acknowledge(SYS_USB_CONNECTED_ACK); 1036 usb_acknowledge(SYS_USB_CONNECTED_ACK);
1110 usb_wait_for_disconnect(&pcmrec_queue); 1037 usb_wait_for_disconnect(&pcmrec_queue);
1111 } 1038 }
@@ -1148,3 +1075,102 @@ void pcm_rec_mux(int source)
1148 /* iAudio x5 */ 1075 /* iAudio x5 */
1149#endif 1076#endif
1150} 1077}
1078
1079
1080/****************************************************************************/
1081/* */
1082/* following functions will be called by the encoder codec */
1083/* */
1084/****************************************************************************/
1085
1086/* pass the encoder buffer pointer/size, mono/stereo, quality to the encoder */
1087void enc_get_inputs(int *buffer_size, int *channels, int *quality)
1088{
1089 *buffer_size = enc_buffer_size;
1090 *channels = enc_channels;
1091 *quality = enc_quality;
1092}
1093
1094/* set the encoder dimensions (called by encoder codec at initialization) */
1095void enc_set_parameters(int chunk_size, int num_chunks, int samp_per_chunk,
1096 char *head_ptr, int head_size, int enc_id)
1097{
1098 /* set read_pos just in front of current write_pos */
1099 read_pos = (write_pos - CHUNK_SIZE) & CHUNK_MASK;
1100
1101 enc_rd_index = 0; /* reset */
1102 enc_wr_index = 0; /* reset */
1103 enc_chunk_size = chunk_size; /* max chunk size */
1104 enc_num_chunks = num_chunks; /* total number of chunks */
1105 enc_samp_per_chunk = samp_per_chunk; /* pcm samples / encoderchunk */
1106 enc_head_buffer = head_ptr; /* optional file header data (wav) */
1107 enc_head_size = head_size; /* optional file header data (wav) */
1108 audio_enc_id = enc_id; /* AFMT_* id */
1109}
1110
1111/* allocate encoder chunk */
1112unsigned int *enc_alloc_chunk(void)
1113{
1114 return (unsigned int*)(enc_buffer + enc_wr_index * enc_chunk_size);
1115}
1116
1117/* free previously allocated encoder chunk */
1118void enc_free_chunk(void)
1119{
1120 unsigned long *enc_chunk;
1121
1122 enc_chunk = GET_ENC_CHUNK(enc_wr_index);
1123 curr_chunk_cnt++;
1124/* curr_bit_rate += *enc_chunk * 44100 * 8 / (enc_samp_per_chunk * 1000); */
1125 curr_bit_rate += *enc_chunk * 441 * 8 / (enc_samp_per_chunk * 10 );
1126 avrg_bit_rate = (curr_bit_rate + curr_chunk_cnt / 2) / curr_chunk_cnt;
1127
1128 /* advance enc_wr_index to the next chunk */
1129 enc_wr_index = (enc_wr_index + 1) % enc_num_chunks;
1130
1131 /* buffer full: advance enc_rd_index (for prerecording purpose) */
1132 if (enc_rd_index == enc_wr_index)
1133 {
1134 enc_rd_index = (enc_rd_index + 1) % enc_num_chunks;
1135 }
1136}
1137
1138/* checks near empty state on wav input buffer */
1139int enc_wavbuf_near_empty(void)
1140{
1141 /* less than 1sec raw data? => unboost encoder */
1142 if (((write_pos - read_pos) & CHUNK_MASK) < 44100*4)
1143 return 1;
1144 else
1145 return 0;
1146}
1147
1148/* passes a pointer to next chunk of unprocessed wav data */
1149char *enc_get_wav_data(int size)
1150{
1151 char *ptr;
1152 int avail;
1153
1154 /* limit the requested pcm data size */
1155 if(size > MAX_FEED_SIZE)
1156 size = MAX_FEED_SIZE;
1157
1158 avail = (write_pos - read_pos) & CHUNK_MASK;
1159
1160 if (avail >= size)
1161 {
1162 ptr = rec_buffer + read_pos;
1163 read_pos = (read_pos + size) & CHUNK_MASK;
1164
1165 /* ptr must point to continous data at wraparound position */
1166 if (read_pos < size)
1167 memcpy(rec_buffer + NUM_CHUNKS * CHUNK_SIZE,
1168 rec_buffer, read_pos);
1169
1170 wav_queue_empty = false;
1171 return ptr;
1172 }
1173
1174 wav_queue_empty = true;
1175 return NULL;
1176}
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c
index 3dd4c607a2..377c34a628 100644
--- a/firmware/powermgmt.c
+++ b/firmware/powermgmt.c
@@ -424,6 +424,7 @@ static void battery_status_update(void)
424 * 1) The USB is connected 424 * 1) The USB is connected
425 * 2) The charger is connected 425 * 2) The charger is connected
426 * 3) We are recording, or recording with pause 426 * 3) We are recording, or recording with pause
427 * 4) The radio is playing
427 */ 428 */
428static void handle_auto_poweroff(void) 429static void handle_auto_poweroff(void)
429{ 430{
@@ -442,7 +443,7 @@ static void handle_auto_poweroff(void)
442 443
443 if(timeout && 444 if(timeout &&
444#ifdef CONFIG_TUNER 445#ifdef CONFIG_TUNER
445 (!radio_powered()) && 446 (!(get_radio_status() & FMRADIO_PLAYING)) &&
446#endif 447#endif
447 !usb_inserted() && 448 !usb_inserted() &&
448 ((audio_stat == 0) || 449 ((audio_stat == 0) ||