1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2004 Jörg Hohensohn
12 * This module collects the Talkbox and voice UI functions.
13 * (Talkbox reads directory names from mp3 clips called thumbnails,
14 * the voice UI lets menus and screens "talk" from a voicefile in memory.
16 * All files in this archive are subject to the GNU General Public License.
17 * See the file COPYING in the source tree root for full license agreement.
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
22 ****************************************************************************/
32 #include "mp3_playback.h"
40 #if CONFIG_CODEC == SWCODEC
46 /* Memory layout varies between targets because the
47 Archos (MASCODEC) devices cannot mix voice and audio playback
49 MASCODEC | MASCODEC | SWCODEC
50 (playing) | (stopped) |
51 audiobuf-----------+-----------+------------
52 audio | voice | thumbnail
53 |-----------|------------
59 audiobufend----------+-----------+------------
61 SWCODEC allocates dedicated buffers, MASCODEC reuses audiobuf. */
64 /***************** Constants *****************/
66 #define QUEUE_SIZE 64 /* must be a power of two */
67 #define QUEUE_MASK (QUEUE_SIZE-1)
68 const char* const dir_thumbnail_name
= "_dirname.talk";
69 const char* const file_thumbnail_ext
= ".talk";
71 /***************** Functional Macros *****************/
73 #define QUEUE_LEVEL ((queue_write - queue_read) & QUEUE_MASK)
75 #define LOADED_MASK 0x80000000 /* MSB */
77 #if CONFIG_CODEC == SWCODEC
78 #define MAX_THUMBNAIL_BUFSIZE 0x10000
81 /***************** Data types *****************/
83 struct clip_entry
/* one entry of the index table */
85 int offset
; /* offset from start of voicefile file */
86 int size
; /* size of the clip */
89 struct voicefile
/* file format of our voice file */
91 int version
; /* version of the voicefile */
92 int target_id
; /* the rockbox target the file was made for */
93 int table
; /* offset to index table, (=header size) */
94 int id1_max
; /* number of "normal" clips contained in above index */
95 int id2_max
; /* number of "voice only" clips contained in above index */
96 struct clip_entry index
[]; /* followed by the index tables */
97 /* and finally the mp3 clips, not visible here, bitswapped
98 for SH based players */
101 struct queue_entry
/* one entry of the internal queue */
108 /***************** Globals *****************/
110 static unsigned char* p_thumbnail
= NULL
; /* buffer for thumbnail */
111 static long size_for_thumbnail
; /* leftover buffer size for it */
112 static struct voicefile
* p_voicefile
; /* loaded voicefile */
113 static bool has_voicefile
; /* a voicefile file is present */
114 static struct queue_entry queue
[QUEUE_SIZE
]; /* queue of scheduled clips */
115 static bool force_enqueue_next
; /* enqueue next utterance even if enqueue is false */
116 static int queue_write
; /* write index of queue, by application */
117 static int queue_read
; /* read index of queue, by ISR context */
118 static int sent
; /* how many bytes handed over to playback, owned by ISR */
119 static unsigned char curr_hd
[3]; /* current frame header, for re-sync */
120 static int filehandle
= -1; /* global, so the MMC variant can keep the file open */
121 static unsigned char* p_silence
; /* VOICE_PAUSE clip, used for termination */
122 static long silence_len
; /* length of the VOICE_PAUSE clip */
123 static unsigned char* p_lastclip
; /* address of latest clip, for silence add */
124 static unsigned long voicefile_size
= 0; /* size of the loaded voice file */
125 static unsigned char last_lang
[MAX_FILENAME
+1]; /* name of last used lang file (in talk_init) */
126 static bool talk_initialized
; /* true if talk_init has been called */
127 static int talk_temp_disable_count
; /* if positive, temporarily disable voice UI (not saved) */
130 /***************** Private implementation *****************/
132 static int open_voicefile(void)
135 char* p_lang
= "english"; /* default */
137 if ( global_settings
.lang_file
[0] &&
138 global_settings
.lang_file
[0] != 0xff )
139 { /* try to open the voice file of the selected language */
140 p_lang
= (char *)global_settings
.lang_file
;
143 snprintf(buf
, sizeof(buf
), LANG_DIR
"/%s.voice", p_lang
);
145 return open(buf
, O_RDONLY
);
149 /* fetch a clip from the voice file */
150 static unsigned char* get_clip(long id
, long* p_size
)
153 unsigned char* clipbuf
;
155 if (id
> VOICEONLY_DELIMITER
)
156 { /* voice-only entries use the second part of the table */
157 id
-= VOICEONLY_DELIMITER
+ 1;
158 if (id
>= p_voicefile
->id2_max
)
159 return NULL
; /* must be newer than we have */
160 id
+= p_voicefile
->id1_max
; /* table 2 is behind table 1 */
163 { /* normal use of the first table */
164 if (id
>= p_voicefile
->id1_max
)
165 return NULL
; /* must be newer than we have */
168 clipsize
= p_voicefile
->index
[id
].size
;
169 if (clipsize
== 0) /* clip not included in voicefile */
171 clipbuf
= (unsigned char *) p_voicefile
+ p_voicefile
->index
[id
].offset
;
173 #ifdef HAVE_MMC /* dynamic loading, on demand */
174 if (!(clipsize
& LOADED_MASK
))
175 { /* clip used for the first time, needs loading */
176 lseek(filehandle
, p_voicefile
->index
[id
].offset
, SEEK_SET
);
177 if (read(filehandle
, clipbuf
, clipsize
) != clipsize
)
178 return NULL
; /* read error */
180 p_voicefile
->index
[id
].size
|= LOADED_MASK
; /* mark as loaded */
183 { /* clip is in memory already */
184 clipsize
&= ~LOADED_MASK
; /* without the extra bit gives true size */
193 /* load the voice file into the mp3 buffer */
194 static void load_voicefile(void)
199 #ifdef ROCKBOX_LITTLE_ENDIAN
203 filehandle
= open_voicefile();
204 if (filehandle
< 0) /* failed to open */
207 file_size
= filesize(filehandle
);
208 if (file_size
> audiobufend
- audiobuf
) /* won't fit? */
211 #ifdef HAVE_MMC /* load only the header for now */
212 load_size
= offsetof(struct voicefile
, index
);
213 #else /* load the full file */
214 load_size
= file_size
;
217 got_size
= read(filehandle
, audiobuf
, load_size
);
218 if (got_size
!= load_size
/* failure */)
221 #ifdef ROCKBOX_LITTLE_ENDIAN
222 logf("Byte swapping voice file");
223 structec_convert(audiobuf
, "lllll", 1, true);
226 if (((struct voicefile
*)audiobuf
)->table
/* format check */
227 == offsetof(struct voicefile
, index
))
229 p_voicefile
= (struct voicefile
*)audiobuf
;
231 if (p_voicefile
->version
!= VOICE_VERSION
||
232 p_voicefile
->target_id
!= TARGET_ID
)
234 logf("Incompatible voice file");
237 #if CONFIG_CODEC != SWCODEC
238 /* MASCODEC: now use audiobuf for voice then thumbnail */
239 p_thumbnail
= audiobuf
+ file_size
;
240 p_thumbnail
+= (long)p_thumbnail
% 2; /* 16-bit align */
241 size_for_thumbnail
= audiobufend
- p_thumbnail
;
247 #ifdef ROCKBOX_LITTLE_ENDIAN
248 for (i
= 0; i
< p_voicefile
->id1_max
+ p_voicefile
->id2_max
; i
++)
249 structec_convert(&p_voicefile
->index
[i
], "ll", 1, true);
253 /* load the index table, now that we know its size from the header */
254 load_size
= (p_voicefile
->id1_max
+ p_voicefile
->id2_max
)
255 * sizeof(struct clip_entry
);
256 got_size
= read(filehandle
,
257 (unsigned char *) p_voicefile
+ offsetof(struct voicefile
, index
), load_size
);
258 if (got_size
!= load_size
) /* read error */
261 close(filehandle
); /* only the MMC variant leaves it open */
265 /* make sure to have the silence clip, if available */
266 p_silence
= get_clip(VOICE_PAUSE
, &silence_len
);
272 has_voicefile
= false; /* don't try again */
282 /* called in ISR context if mp3 data got consumed */
283 static void mp3_callback(unsigned char** start
, size_t* size
)
285 queue
[queue_read
].len
-= sent
; /* we completed this */
286 queue
[queue_read
].buf
+= sent
;
288 if (queue
[queue_read
].len
> 0) /* current clip not finished? */
289 { /* feed the next 64K-1 chunk */
290 #if CONFIG_CODEC != SWCODEC
291 sent
= MIN(queue
[queue_read
].len
, 0xFFFF);
293 sent
= queue
[queue_read
].len
;
295 *start
= queue
[queue_read
].buf
;
299 else if (sent
> 0) /* go to next entry */
301 queue_read
= (queue_read
+ 1) & QUEUE_MASK
;
306 if (QUEUE_LEVEL
!= 0) /* queue is not empty? */
307 { /* start next clip */
308 #if CONFIG_CODEC != SWCODEC
309 sent
= MIN(queue
[queue_read
].len
, 0xFFFF);
311 sent
= queue
[queue_read
].len
;
313 *start
= p_lastclip
= queue
[queue_read
].buf
;
315 curr_hd
[0] = p_lastclip
[1];
316 curr_hd
[1] = p_lastclip
[2];
317 curr_hd
[2] = p_lastclip
[3];
319 else if (p_silence
!= NULL
/* silence clip available */
320 && p_lastclip
!= p_silence
/* previous clip wasn't silence */
321 && p_lastclip
!= p_thumbnail
) /* ..or thumbnail */
322 { /* add silence clip when queue runs empty playing a voice clip */
323 queue
[queue_write
].buf
= p_silence
;
324 queue
[queue_write
].len
= silence_len
;
325 queue_write
= (queue_write
+ 1) & QUEUE_MASK
;
331 *size
= 0; /* end of data */
335 /***************** Public routines *****************/
337 /* stop the playback and the pending clips */
338 void talk_force_shutup(void)
340 /* Most of this is MAS only */
341 #if CONFIG_CODEC != SWCODEC
346 unsigned char* search
;
348 if (QUEUE_LEVEL
== 0) /* has ended anyway */
351 #if CONFIG_CPU == SH7034
352 CHCR3
&= ~0x0001; /* disable the DMA (and therefore the interrupt also) */
353 #endif /* CONFIG_CPU == SH7034 */
354 /* search next frame boundary and continue up to there */
355 pos
= search
= mp3_get_pos();
356 end
= queue
[queue_read
].buf
+ queue
[queue_read
].len
;
358 if (pos
>= queue
[queue_read
].buf
359 && pos
<= end
) /* really our clip? */
360 { /* (for strange reasons this isn't nesessarily the case) */
361 /* find the next frame boundary */
362 while (search
< end
) /* search the remaining data */
364 if (*search
++ != 0xFF) /* quick search for frame sync byte */
365 continue; /* (this does the majority of the job) */
367 /* look at the (bitswapped) rest of header candidate */
368 if (search
[0] == curr_hd
[0] /* do the quicker checks first */
369 && search
[2] == curr_hd
[2]
370 && (search
[1] & 0x30) == (curr_hd
[1] & 0x30)) /* sample rate */
372 search
--; /* back to the sync byte */
373 break; /* From looking at it, this is our header. */
378 { /* play old data until the frame end, to keep the MAS in sync */
381 queue_write
= (queue_read
+ 1) & QUEUE_MASK
; /* will be empty after next callback */
382 queue
[queue_read
].len
= sent
; /* current one ends after this */
384 #if CONFIG_CPU == SH7034
385 DTCR3
= sent
; /* let the DMA finish this frame */
386 CHCR3
|= 0x0001; /* re-enable DMA */
387 #endif /* CONFIG_CPU == SH7034 */
391 #endif /* CONFIG_CODEC != SWCODEC */
393 /* Either SWCODEC, or MAS had nothing to do (was frame boundary or not our clip) */
395 queue_write
= queue_read
= 0; /* reset the queue */
399 /* Shutup the voice, except if force_enqueue_next is set. */
400 void talk_shutup(void)
402 if (!force_enqueue_next
)
406 /* schedule a clip, at the end or discard the existing queue */
407 static void queue_clip(unsigned char* buf
, long size
, bool enqueue
)
412 talk_shutup(); /* cut off all the pending stuff */
413 /* Something is being enqueued, force_enqueue_next override is no
415 force_enqueue_next
= false;
418 return; /* safety check */
419 #if CONFIG_CPU == SH7034
420 /* disable the DMA temporarily, to be safe of race condition */
423 queue_level
= QUEUE_LEVEL
; /* check old level */
425 if (queue_level
< QUEUE_SIZE
- 1) /* space left? */
427 queue
[queue_write
].buf
= buf
; /* populate an entry */
428 queue
[queue_write
].len
= size
;
429 queue_write
= (queue_write
+ 1) & QUEUE_MASK
;
432 if (queue_level
== 0)
433 { /* queue was empty, we have to do the initial start */
435 #if CONFIG_CODEC != SWCODEC
436 sent
= MIN(size
, 0xFFFF); /* DMA can do no more */
440 mp3_play_data(buf
, sent
, mp3_callback
);
444 mp3_play_pause(true); /* kickoff audio */
448 #if CONFIG_CPU == SH7034
449 CHCR3
|= 0x0001; /* re-enable DMA */
457 /* common code for talk_init() and talk_buffer_steal() */
458 static void reset_state(void)
460 queue_write
= queue_read
= 0; /* reset the queue */
461 p_voicefile
= NULL
; /* indicate no voicefile (trashed) */
462 #if CONFIG_CODEC == SWCODEC
463 /* Allocate a dedicated thumbnail buffer - once */
464 if (p_thumbnail
== NULL
)
466 size_for_thumbnail
= audiobufend
- audiobuf
;
467 if (size_for_thumbnail
> MAX_THUMBNAIL_BUFSIZE
)
468 size_for_thumbnail
= MAX_THUMBNAIL_BUFSIZE
;
469 p_thumbnail
= buffer_alloc(size_for_thumbnail
);
472 /* Just use the audiobuf, without allocating anything */
473 p_thumbnail
= audiobuf
;
474 size_for_thumbnail
= audiobufend
- audiobuf
;
476 p_silence
= NULL
; /* pause clip not accessible */
480 /***************** Public implementation *****************/
484 talk_temp_disable_count
= 0;
485 if (talk_initialized
&& !strcasecmp(last_lang
, global_settings
.lang_file
))
487 /* not a new file, nothing to do */
492 if (filehandle
>= 0) /* MMC: An old voice file might still be open */
499 talk_initialized
= true;
500 strncpy((char *) last_lang
, (char *)global_settings
.lang_file
,
503 #if CONFIG_CODEC == SWCODEC
504 audio_get_buffer(false, NULL
); /* Must tell audio to reinitialize */
506 reset_state(); /* use this for most of our inits */
508 filehandle
= open_voicefile();
509 has_voicefile
= (filehandle
>= 0); /* test if we can open it */
514 voicefile_size
= filesize(filehandle
);
515 close(filehandle
); /* close again, this was just to detect presence */
521 #if CONFIG_CODEC == SWCODEC
522 /* return if a voice codec is required or not */
523 bool talk_voice_required(void)
525 return (voicefile_size
!= 0) /* Voice file is available */
526 || (global_settings
.talk_dir_clip
) /* Thumbnail clips are required */
527 || (global_settings
.talk_file_clip
);
531 /* return size of voice file */
532 int talk_get_bufsize(void)
534 return voicefile_size
;
537 /* somebody else claims the mp3 buffer, e.g. for regular play/record */
538 void talk_buffer_steal(void)
540 #if CONFIG_CODEC != SWCODEC
544 if (filehandle
>= 0) /* only relevant for MMC */
554 /* play a voice ID from voicefile */
555 int talk_id(int32_t id
, bool enqueue
)
558 unsigned char* clipbuf
;
561 if (talk_temp_disable_count
> 0)
562 return -1; /* talking has been disabled */
563 #if CONFIG_CODEC != SWCODEC
564 if (audio_status()) /* busy, buffer in use */
568 if (p_voicefile
== NULL
&& has_voicefile
)
569 load_voicefile(); /* reload needed */
571 if (p_voicefile
== NULL
) /* still no voices? */
574 if (id
== -1) /* -1 is an indication for silence */
577 /* check if this is a special ID, with a value */
578 unit
= ((uint32_t)id
) >> UNIT_SHIFT
;
580 { /* sign-extend the value */
581 id
= (uint32_t)id
<< (32-UNIT_SHIFT
);
582 id
>>= (32-UNIT_SHIFT
);
583 talk_value(id
, unit
, enqueue
); /* speak it */
584 return 0; /* and stop, end of special case */
587 clipbuf
= get_clip(id
, &clipsize
);
589 return -1; /* not present */
591 queue_clip(clipbuf
, clipsize
, enqueue
);
596 /* Speaks zero or more IDs (from an array). */
597 int talk_idarray(long *ids
, bool enqueue
)
602 while(*ids
!= TALK_FINAL_ID
)
604 if((r
= talk_id(*ids
++, enqueue
)) <0)
611 /* Make sure the current utterance is not interrupted by the next one. */
612 void talk_force_enqueue_next(void)
614 force_enqueue_next
= true;
617 /* play a thumbnail from file */
618 int talk_file(const char* filename
, bool enqueue
)
622 #if CONFIG_CODEC != SWCODEC
623 struct mp3entry info
;
626 if (talk_temp_disable_count
> 0)
627 return -1; /* talking has been disabled */
628 #if CONFIG_CODEC != SWCODEC
629 if (audio_status()) /* busy, buffer in use */
633 if (p_thumbnail
== NULL
|| size_for_thumbnail
<= 0)
636 #if CONFIG_CODEC != SWCODEC
637 if(mp3info(&info
, filename
)) /* use this to find real start */
639 return 0; /* failed to open, or invalid */
643 fd
= open(filename
, O_RDONLY
);
644 if (fd
< 0) /* failed to open */
649 #if CONFIG_CODEC != SWCODEC
650 lseek(fd
, info
.first_frame_offset
, SEEK_SET
); /* behind ID data */
653 size
= read(fd
, p_thumbnail
, size_for_thumbnail
);
656 /* ToDo: find audio, skip ID headers and trailers */
658 if (size
> 0 && size
!= size_for_thumbnail
) /* Don't play missing or truncated clips */
660 #if CONFIG_CODEC != SWCODEC && !defined(SIMULATOR)
661 bitswap(p_thumbnail
, size
);
663 queue_clip(p_thumbnail
, size
, enqueue
);
670 /* say a numeric value, this word ordering works for english,
671 but not necessarily for other languages (e.g. german) */
672 int talk_number(long n
, bool enqueue
)
674 int level
= 2; /* mille count */
675 long mil
= 1000000000; /* highest possible "-illion" */
677 if (talk_temp_disable_count
> 0)
678 return -1; /* talking has been disabled */
679 #if CONFIG_CODEC != SWCODEC
680 if (audio_status()) /* busy, buffer in use */
685 talk_shutup(); /* cut off all the pending stuff */
689 talk_id(VOICE_ZERO
, true);
695 talk_id(VOICE_MINUS
, true);
701 int segment
= n
/ mil
; /* extract in groups of 3 digits */
702 n
-= segment
* mil
; /* remove the used digits from number */
703 mil
/= 1000; /* digit place for next round */
707 int hundreds
= segment
/ 100;
708 int ones
= segment
% 100;
712 talk_id(VOICE_ZERO
+ hundreds
, true);
713 talk_id(VOICE_HUNDRED
, true);
716 /* combination indexing */
719 int tens
= ones
/10 + 18;
720 talk_id(VOICE_ZERO
+ tens
, true);
724 /* direct indexing */
726 talk_id(VOICE_ZERO
+ ones
, true);
728 /* add billion, million, thousand */
730 talk_id(VOICE_THOUSAND
+ level
, true);
738 /* Say time duration/interval. Input is time in seconds,
739 say hours,minutes,seconds. */
740 static int talk_time_unit(long secs
, bool exact
, bool enqueue
)
745 if((hours
= secs
/3600)) {
747 talk_value(hours
, UNIT_HOUR
, true);
749 if((mins
= secs
/60)) {
752 talk_value(mins
, UNIT_MIN
, true);
753 else talk_number(mins
, true); /* don't say "minutes" */
755 if((exact
&& secs
) || (!hours
&& !mins
))
756 talk_value(secs
, UNIT_SEC
, true);
757 else if(!hours
&& secs
)
758 talk_number(secs
, true);
762 /* singular/plural aware saying of a value */
763 int talk_value(long n
, int unit
, bool enqueue
)
766 static const int unit_voiced
[] =
767 { /* lookup table for the voice ID of the units */
768 [0 ... UNIT_LAST
-1] = -1, /* regular ID, int, signed */
770 = VOICE_MILLISECONDS
, /* here come the "real" units */
784 = VOICE_MILLIAMPHOURS
,
794 = VOICE_KBIT_PER_SEC
,
796 = VOICE_PM_UNITS_PER_TICK
,
799 if (talk_temp_disable_count
> 0)
800 return -1; /* talking has been disabled */
801 #if CONFIG_CODEC != SWCODEC
802 if (audio_status()) /* busy, buffer in use */
806 /* special case for time duration */
807 if (unit
== UNIT_TIME
|| unit
== UNIT_TIME_EXACT
)
808 return talk_time_unit(n
, unit
== UNIT_TIME_EXACT
, enqueue
);
810 if (unit
< 0 || unit
>= UNIT_LAST
)
813 unit_id
= unit_voiced
[unit
];
815 if ((n
==1 || n
==-1) /* singular? */
816 && unit_id
>= VOICE_SECONDS
&& unit_id
<= VOICE_HOURS
)
818 unit_id
--; /* use the singular for those units which have */
821 /* special case with a "plus" before */
822 if (n
> 0 && (unit
== UNIT_SIGNED
|| unit
== UNIT_DB
))
824 talk_id(VOICE_PLUS
, enqueue
);
828 talk_number(n
, enqueue
); /* say the number */
829 talk_id(unit_id
, true); /* say the unit, if any */
835 int talk_spell(const char* spell
, bool enqueue
)
837 char c
; /* currently processed char */
839 if (talk_temp_disable_count
> 0)
840 return -1; /* talking has been disabled */
841 #if CONFIG_CODEC != SWCODEC
842 if (audio_status()) /* busy, buffer in use */
847 talk_shutup(); /* cut off all the pending stuff */
849 while ((c
= *spell
++) != '\0')
851 /* if this grows into too many cases, I should use a table */
852 if (c
>= 'A' && c
<= 'Z')
853 talk_id(VOICE_CHAR_A
+ c
- 'A', true);
854 else if (c
>= 'a' && c
<= 'z')
855 talk_id(VOICE_CHAR_A
+ c
- 'a', true);
856 else if (c
>= '0' && c
<= '9')
857 talk_id(VOICE_ZERO
+ c
- '0', true);
859 talk_id(VOICE_MINUS
, true);
861 talk_id(VOICE_PLUS
, true);
863 talk_id(VOICE_DOT
, true);
865 talk_id(VOICE_PAUSE
, true);
871 void talk_disable(bool disable
)
874 talk_temp_disable_count
++;
876 talk_temp_disable_count
--;
880 void talk_date(struct tm
*tm
, bool enqueue
)
882 talk_id(LANG_MONTH_JANUARY
+ tm
->tm_mon
, enqueue
);
883 talk_number(tm
->tm_mday
, true);
884 talk_number(1900 + tm
->tm_year
, true);
887 void talk_time(struct tm
*tm
, bool enqueue
)
889 if (global_settings
.timeformat
== 1)
892 long am_pm_id
= VOICE_AM
;
893 int hour
= tm
->tm_hour
;
901 talk_number(hour
, enqueue
);
903 /* Voice the minutes */
906 /* Say o'clock if the minute is 0. */
907 talk_id(VOICE_OCLOCK
, true);
911 /* Pronounce the leading 0 */
913 talk_id(VOICE_OH
, true);
914 talk_number(tm
->tm_min
, true);
916 talk_id(am_pm_id
, true);
920 /* Voice the time in 24 hour format */
921 talk_number(tm
->tm_hour
, enqueue
);
924 talk_id(VOICE_HUNDRED
, true);
925 talk_id(VOICE_HOUR
, true);
929 /* Pronounce the leading 0 */
931 talk_id(VOICE_OH
, true);
932 talk_number(tm
->tm_min
, true);