Skip to content

Commit f49a07b

Browse files
committed
[app-isoldr] Improved CDDA and video playback.
- Add volume fading. - Add cover show timeout. - Reduce fading time for video. - Disable log for CDDA play.
1 parent 556b8f2 commit f49a07b

4 files changed

Lines changed: 60 additions & 14 deletions

File tree

applications/games_menu/modules/utils.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ void PlayCDDATrack(const char *file, int loop)
718718
ds_printf("DS_ERROR: Can't play file: %s\n", file);
719719
return;
720720
}
721-
ds_printf("DS_OK: Start playing: %s\n", file);
721+
// ds_printf("DS_OK: Start playing: %s\n", file);
722722

723723
int volume = GetVolumeFromSettings();
724724
if(volume >= 0) {

applications/iso_loader/modules/app_utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ void PlayCDDATrack(const char *file, int loop);
4848
void StopCDDATrack();
4949
void PauseCDDATrack();
5050
void ResumeCDDATrack();
51+
int IsCDDATrackPlaying();
52+
void SetCDDAVolume(int vol);
5153

5254
char *lib_get_name();
5355
uint32 lib_get_version();

applications/iso_loader/modules/module.c

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ DEFAULT_MODULE_EXPORTS(app_iso_loader);
2424
#define SCREENSHOT_HOTKEY (CONT_START | CONT_A | CONT_B)
2525
#define ALT_BOOT_FILE "2ND_READ.BIN"
2626
#define FFMPEG_MODULES_COUNT 1
27+
#define AUDIO_FADE_STEPS 10
28+
#define AUDIO_FADE_STEP_MS 30
29+
#define COVER_DISPLAY_MS 1000
30+
#define COVER_DISPLAY_STEP_MS 50
2731

2832
static const char *ffmpeg_module_names[FFMPEG_MODULES_COUNT] = {
2933
// "bzip2",
@@ -150,6 +154,7 @@ static struct {
150154
void (*ffplay_toggle_pause)(void);
151155
int (*ffplay_is_playing)(void);
152156
int (*ffplay_is_paused)(void);
157+
void (*ffplay_set_volume)(int vol);
153158

154159
kthread_t *select_thd;
155160
mutex_t select_mutex;
@@ -1483,6 +1488,7 @@ static void loadFFmpegModules() {
14831488
self.ffplay_toggle_pause = (void (*)(void))GET_EXPORT_ADDR("ffplay_toggle_pause");
14841489
self.ffplay_is_playing = (int (*)(void))GET_EXPORT_ADDR("ffplay_is_playing");
14851490
self.ffplay_is_paused = (int (*)(void))GET_EXPORT_ADDR("ffplay_is_paused");
1491+
self.ffplay_set_volume = (void (*)(int))GET_EXPORT_ADDR("ffplay_set_volume");
14861492
}
14871493
}
14881494

@@ -1492,6 +1498,7 @@ static void *selectFile_worker(void *p) {
14921498
uint32_t last_id = 0;
14931499
int trailer_playing = 0;
14941500
char *trailer_path = NULL;
1501+
int trailer_exists = 0;
14951502

14961503
mutex_lock(&self.select_mutex);
14971504

@@ -1511,6 +1518,17 @@ static void *selectFile_worker(void *p) {
15111518

15121519
mutex_unlock(&self.select_mutex);
15131520

1521+
if(IsCDDATrackPlaying() || (self.ffplay && self.ffplay_is_playing())) {
1522+
int vol = GetVolumeFromSettings();
1523+
if(vol < 0) vol = 240;
1524+
1525+
for(int i = AUDIO_FADE_STEPS - 1; i >= 0; i--) {
1526+
int new_vol = vol * i / AUDIO_FADE_STEPS;
1527+
if(IsCDDATrackPlaying()) SetCDDAVolume(new_vol);
1528+
if(self.ffplay && self.ffplay_is_playing()) self.ffplay_set_volume(new_vol);
1529+
thd_sleep(AUDIO_FADE_STEP_MS);
1530+
}
1531+
}
15141532
StopCDDATrack();
15151533
if(self.ffplay && self.ffplay_is_playing()) {
15161534
self.ffplay_shutdown();
@@ -1522,6 +1540,7 @@ static void *selectFile_worker(void *p) {
15221540

15231541
strncpy(self.filename, filename, NAME_MAX);
15241542
trailer_path = relativeFilename("trailer.avi");
1543+
trailer_exists = FileExists(trailer_path);
15251544

15261545
showCover();
15271546
isoLoader_LoadPreset(NULL);
@@ -1535,16 +1554,30 @@ static void *selectFile_worker(void *p) {
15351554

15361555
trailer_playing = 0;
15371556

1538-
if(FileExists(trailer_path)) {
1557+
if(trailer_exists) {
15391558
loadFFmpegModules();
15401559

15411560
if(self.ffplay) {
1542-
1561+
if(self.current_cover != self.default_cover) {
1562+
int cover_elapsed = 0;
1563+
1564+
while(cover_elapsed < COVER_DISPLAY_MS) {
1565+
thd_sleep(COVER_DISPLAY_STEP_MS);
1566+
cover_elapsed += COVER_DISPLAY_STEP_MS;
1567+
mutex_lock(&self.select_mutex);
1568+
1569+
if(last_id != self.select_id) {
1570+
mutex_unlock(&self.select_mutex);
1571+
goto next_item;
1572+
}
1573+
mutex_unlock(&self.select_mutex);
1574+
}
1575+
}
15431576
ffplay_params_t params;
15441577
memset(&params, 0, sizeof(params));
15451578
params.scale = 1.0f;
15461579
params.loop = 1;
1547-
params.fade_in = 2000;
1580+
params.fade_in = 1000;
15481581

15491582
getWidgetAbsolutePosition(self.cover_widget,
15501583
&params.x, &params.y,
@@ -1566,8 +1599,8 @@ static void *selectFile_worker(void *p) {
15661599
do {
15671600
track_size = GetCDDATrackFilename((random() % 15) + 4,
15681601
GUI_FileManagerGetPath(self.filebrowser), filename, filepath);
1569-
} while(track_size == 0);
1570-
PlayCDDATrack(filepath, 3);
1602+
} while(track_size < (5 << 10));
1603+
PlayCDDATrack(filepath, 0);
15711604
}
15721605
}
15731606

@@ -2155,18 +2188,16 @@ int isoLoader_LoadPreset(GUI_Widget *widget) {
21552188

21562189
if (strlen(device) > 0) {
21572190
GUI_TextEntrySetText(self.device, device);
2158-
} else {
2191+
}
2192+
else {
21592193
GUI_TextEntrySetText(self.device, "auto");
21602194
}
21612195

21622196
if (hardware_sys_mode(NULL) != HW_TYPE_RETAIL && self.image_type != IMAGE_TYPE_ROM_NAOMI) {
21632197
/* NAOMI platform with non-DNI image: use 0x8dfe0000 */
2164-
i = 13;
2165-
boot_mode = BOOT_MODE_IPBIN;
2166-
2167-
if(bin_type == BIN_TYPE_AUTO) {
2168-
/* Without WinCE support, IRQ is not needed yet. */
2169-
use_irq = 0;
2198+
if(bin_type != BIN_TYPE_WINCE) {
2199+
i = 13;
2200+
boot_mode = BOOT_MODE_IPBIN;
21702201
}
21712202
GUI_WidgetSetState(self.memory_chk[i], 1);
21722203
isoLoader_toggleMemory(self.memory_chk[i]);

applications/iso_loader/modules/utils.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,19 @@ void ResumeCDDATrack() {
237237
}
238238
}
239239

240+
int IsCDDATrackPlaying() {
241+
if(wav_inited && wav_hnd != SND_STREAM_INVALID) {
242+
return wav_is_playing(wav_hnd);
243+
}
244+
return 0;
245+
}
246+
247+
void SetCDDAVolume(int vol) {
248+
if(wav_inited && wav_hnd != SND_STREAM_INVALID) {
249+
wav_volume(wav_hnd, vol);
250+
}
251+
}
252+
240253
void StopCDDATrack() {
241254
if(wav_inited) {
242255
wav_shutdown();
@@ -255,7 +268,7 @@ void PlayCDDATrack(const char *file, int loop) {
255268
ds_printf("DS_ERROR: Can't play file: %s\n", file);
256269
return;
257270
}
258-
ds_printf("DS_OK: Start playing: %s\n", file);
271+
// ds_printf("DS_OK: Start playing: %s\n", file);
259272

260273
int volume = GetVolumeFromSettings();
261274
if(volume >= 0) {

0 commit comments

Comments
 (0)