49
54
static int16 ResampBuffer[588 * 2][2]; // Resampler input buffer, * 2 for resampler leftovers
50
55
static uint32 ResampBufferPos;
51
56
static uint32 PrevRate;
57
static unsigned int CurrentDisc;
59
static std::vector<CDIF *> *cdifs;
53
61
static int32 CurrentATLI;
55
static std::vector<int32> AudioTrackList;
65
inline AudioTrackInfo(unsigned disc_, int32 track_, int32 lba_, int32 final_lba_)
70
final_lba = final_lba_;
76
int32 final_lba; // Inclusive.
79
static std::vector<AudioTrackInfo> AudioTrackList;
57
81
static void InitLUT(void);
59
static int LoadCD(void)
83
static int LoadCD(std::vector<CDIF *> *CDInterfaces)
61
if(!CDIF_ReadTOC(&toc))
63
puts("Error reading TOC");
67
87
AudioTrackList.clear();
69
for(int32 track = toc.first_track; track <= toc.last_track; track++)
89
for(unsigned disc = 0; disc < cdifs->size(); disc++)
71
if(!(toc.tracks[track].control & 0x4))
72
AudioTrackList.push_back(track);
93
(*cdifs)[disc]->ReadTOC(&toc);
95
for(int32 track = toc.first_track; track <= toc.last_track; track++)
97
if(!(toc.tracks[track].control & 0x4))
99
AudioTrackList.push_back(AudioTrackInfo(disc, track, toc.tracks[track].lba, toc.tracks[track + 1].lba - 1));
75
104
if(!AudioTrackList.size())
100
static bool TestMagicCD(void)
128
static bool TestMagicCD(std::vector<CDIF *> *CDInterfaces)
104
if(!CDIF_ReadTOC(&magic_toc))
107
// If any audio track is found, return true.
108
for(int32 track = magic_toc.first_track; track <= magic_toc.last_track; track++)
109
if(!(magic_toc.tracks[track].control & 0x4))
130
CDUtility::TOC magic_toc;
132
for(unsigned i = 0; i < CDInterfaces->size(); i++)
134
(*CDInterfaces)[i]->ReadTOC(&magic_toc);
136
// If any audio track is found, return true.
137
for(int32 track = magic_toc.first_track; track <= magic_toc.last_track; track++)
138
if(!(magic_toc.tracks[track].control & 0x4))
147
179
static const int oversample = 1 << oversample_shift;
148
180
static const int oversample_mo = oversample - 1;
150
static double sqrt_lut[65536];
151
static double sin_lut[65536];
153
182
static void InitLUT(void)
155
for(int i = 0; i < 65536; i++)
156
sqrt_lut[i] = sqrt((double)i / 65536);
158
for(int i = 0; i < 65536; i++)
159
sin_lut[i] = sin((double)i * M_PI * 2 / 65536);
184
sqrt_lut.resize(65536);
185
sin_lut.resize(65536);
187
for(int i = 0; i < 65536; i++)
188
sqrt_lut[i] = sqrt((double)i / 65536);
190
for(int i = 0; i < 65536; i++)
191
sin_lut[i] = sin((double)i * M_PI * 2 / 65536);
162
194
static void Emulate(EmulateSpecStruct *espec)
169
201
//printf("%d %d\n", toc.tracks[100].lba, AudioTrackList[AudioTrackList.size() - 1] + 1);
171
if(PlaySector >= toc.tracks[100].lba || PlaySector >= toc.tracks[AudioTrackList[AudioTrackList.size() - 1] + 1].lba)
203
if(PlaySector > AudioTrackList[CurrentATLI].final_lba)
174
PlayMode = PLAYMODE_STOP;
205
if((CurrentATLI + 1) < AudioTrackList.size())
210
PlayMode = PLAYMODE_STOP;
177
PlaySector = toc.tracks[AudioTrackList[CurrentATLI]].lba;
179
else if(AudioTrackList[CurrentATLI] < toc.last_track && PlaySector >= toc.tracks[AudioTrackList[CurrentATLI] + 1].lba)
181
puts("CurrentATLI++");
183
PlaySector = toc.tracks[AudioTrackList[CurrentATLI]].lba;
213
PlaySector = AudioTrackList[CurrentATLI].lba;
187
216
if(PlayMode == PLAYMODE_STOP || PlayMode == PLAYMODE_PAUSE)
189
218
//memset(CDDABuffer, 0, sizeof(CDDABuffer));
335
trio_snprintf(tmpbuf, 256, "Track: %d/%d", cur_track, toc.last_track);
336
DrawTextTransShadow(pixels, espec->surface->pitch32 * 4, 320, (UTF8 *)tmpbuf, text_color, text_shadow_color, 0, MDFN_FONT_9x18_18x18);
337
pixels += 22 * espec->surface->pitch32;
339
trio_snprintf(tmpbuf, 256, "Sector: %d/%d", cur_sector, toc.tracks[100].lba - 1);
340
DrawTextTransShadow(pixels, espec->surface->pitch32 * 4, 320, (UTF8 *)tmpbuf, text_color, text_shadow_color, 0, MDFN_FONT_9x18_18x18);
341
pixels += 22 * espec->surface->pitch32;
367
(*cdifs)[AudioTrackList[CurrentATLI].disc]->ReadTOC(&toc);
369
trio_snprintf(tmpbuf, 256, "Disc: %d/%d", AudioTrackList[CurrentATLI].disc + 1, cdifs->size());
370
DrawTextTransShadow(pixels, espec->surface->pitch32 * 4, 320, (UTF8 *)tmpbuf, text_color, text_shadow_color, 0, MDFN_FONT_9x18_18x18);
371
pixels += 22 * espec->surface->pitch32;
373
trio_snprintf(tmpbuf, 256, "Track: %d/%d", AudioTrackList[CurrentATLI].track, toc.last_track);
374
DrawTextTransShadow(pixels, espec->surface->pitch32 * 4, 320, (UTF8 *)tmpbuf, text_color, text_shadow_color, 0, MDFN_FONT_9x18_18x18);
375
pixels += 22 * espec->surface->pitch32;
377
trio_snprintf(tmpbuf, 256, "Sector: %d/%d", cur_sector, toc.tracks[100].lba - 1);
378
DrawTextTransShadow(pixels, espec->surface->pitch32 * 4, 320, (UTF8 *)tmpbuf, text_color, text_shadow_color, 0, MDFN_FONT_9x18_18x18);
379
pixels += 22 * espec->surface->pitch32;
344
382
pixels += 22 * espec->surface->pitch32;
351
389
//DrawTextTransShadow(pixels, espec->surface->pitch32 * 4, 320, (UTF8 *)tmpbuf, text_color, text_shadow_color, 0, MDFN_FONT_9x18_18x18);
352
390
//pixels += 22 * espec->surface->pitch32;
354
trio_snprintf(tmpbuf, 256, "Track: %d", BCD_TO_INT(SubQBuf[1][1]));
355
DrawTextTransShadow(pixels, espec->surface->pitch32 * 4, 320, (UTF8 *)tmpbuf, text_color, text_shadow_color, 0, MDFN_FONT_9x18_18x18);
356
pixels += 22 * espec->surface->pitch32;
358
trio_snprintf(tmpbuf, 256, "Index: %d", BCD_TO_INT(SubQBuf[1][2]));
359
DrawTextTransShadow(pixels, espec->surface->pitch32 * 4, 320, (UTF8 *)tmpbuf, text_color, text_shadow_color, 0, MDFN_FONT_9x18_18x18);
360
pixels += 22 * espec->surface->pitch32;
363
trio_snprintf(tmpbuf, 256, "Relative: %02d:%02d:%02d", BCD_TO_INT(SubQBuf[1][3]), BCD_TO_INT(SubQBuf[1][4]), BCD_TO_INT(SubQBuf[1][5]));
364
DrawTextTransShadow(pixels, espec->surface->pitch32 * 4, 320, (UTF8 *)tmpbuf, text_color, text_shadow_color, 0, MDFN_FONT_9x18_18x18);
365
pixels += 22 * espec->surface->pitch32;
367
trio_snprintf(tmpbuf, 256, "Absolute: %02d:%02d:%02d", BCD_TO_INT(SubQBuf[1][7]), BCD_TO_INT(SubQBuf[1][8]), BCD_TO_INT(SubQBuf[1][9]));
392
trio_snprintf(tmpbuf, 256, "Track: %d", BCD_to_U8(SubQBuf[1][1]));
393
DrawTextTransShadow(pixels, espec->surface->pitch32 * 4, 320, (UTF8 *)tmpbuf, text_color, text_shadow_color, 0, MDFN_FONT_9x18_18x18);
394
pixels += 22 * espec->surface->pitch32;
396
trio_snprintf(tmpbuf, 256, "Index: %d", BCD_to_U8(SubQBuf[1][2]));
397
DrawTextTransShadow(pixels, espec->surface->pitch32 * 4, 320, (UTF8 *)tmpbuf, text_color, text_shadow_color, 0, MDFN_FONT_9x18_18x18);
398
pixels += 22 * espec->surface->pitch32;
401
trio_snprintf(tmpbuf, 256, "Relative: %02d:%02d:%02d", BCD_to_U8(SubQBuf[1][3]), BCD_to_U8(SubQBuf[1][4]), BCD_to_U8(SubQBuf[1][5]));
402
DrawTextTransShadow(pixels, espec->surface->pitch32 * 4, 320, (UTF8 *)tmpbuf, text_color, text_shadow_color, 0, MDFN_FONT_9x18_18x18);
403
pixels += 22 * espec->surface->pitch32;
405
trio_snprintf(tmpbuf, 256, "Absolute: %02d:%02d:%02d", BCD_to_U8(SubQBuf[1][7]), BCD_to_U8(SubQBuf[1][8]), BCD_to_U8(SubQBuf[1][9]));
368
406
DrawTextTransShadow(pixels, espec->surface->pitch32 * 4, 320, (UTF8 *)tmpbuf, text_color, text_shadow_color, 0, MDFN_FONT_9x18_18x18);
369
407
pixels += 22 * espec->surface->pitch32;
399
PlaySector = toc.tracks[AudioTrackList[CurrentATLI]].lba;
437
PlaySector = AudioTrackList[CurrentATLI].lba;
440
if(!(last_controller & 0x10) && (new_controller & 0x10))
442
CurrentATLI = std::min<int>(CurrentATLI + 10, AudioTrackList.size() - 1);
443
PlaySector = AudioTrackList[CurrentATLI].lba;
446
if(!(last_controller & 0x20) && (new_controller & 0x20))
448
CurrentATLI = std::max<int>(CurrentATLI - 10, 0);
449
PlaySector = AudioTrackList[CurrentATLI].lba;
402
453
last_controller = new_controller;