31static std::string_view getLaserDiscPlayerName()
33 return "laserdiscplayer";
38LaserdiscPlayer::Command::Command(
39 CommandController& commandController_,
40 StateChangeDistributor& stateChangeDistributor_,
41 Scheduler& scheduler_)
42 : RecordedCommand(commandController_, stateChangeDistributor_,
43 scheduler_, getLaserDiscPlayerName())
47void LaserdiscPlayer::Command::execute(
48 std::span<const TclObject> tokens, TclObject& result, EmuTime::param time)
50 auto& laserdiscPlayer =
OUTER(LaserdiscPlayer, laserdiscCommand);
51 if (tokens.size() == 1) {
54 result.addListElement(
tmpStrCat(getName(),
':'),
55 laserdiscPlayer.getImageName().getResolved());
56 }
else if (tokens[1] ==
"eject") {
57 checkNumArgs(tokens, 2, Prefix{2},
nullptr);
58 result =
"Ejecting laserdisc.";
59 laserdiscPlayer.eject(time);
60 }
else if (tokens[1] ==
"insert") {
61 checkNumArgs(tokens, 3,
"filename");
63 result =
"Changing laserdisc.";
64 laserdiscPlayer.setImageName(
string(tokens[2].getString()), time);
65 }
catch (MSXException& e) {
66 throw CommandException(std::move(e).getMessage());
73string LaserdiscPlayer::Command::help(std::span<const TclObject> tokens)
const
75 if (tokens.size() >= 2) {
76 if (tokens[1] ==
"insert") {
77 return "Inserts the specified laserdisc image into "
78 "the laserdisc player.";
79 }
else if (tokens[1] ==
"eject") {
80 return "Eject the laserdisc.";
83 return "laserdiscplayer insert <filename> "
84 ": insert a (different) laserdisc image\n"
85 "laserdiscplayer eject "
86 ": eject the laserdisc\n";
89void LaserdiscPlayer::Command::tabCompletion(std::vector<string>& tokens)
const
91 if (tokens.size() == 2) {
92 using namespace std::literals;
93 static constexpr std::array extra = {
"eject"sv,
"insert"sv};
94 completeString(tokens, extra);
95 }
else if (tokens.size() == 3 && tokens[1] ==
"insert") {
102static constexpr unsigned DUMMY_INPUT_RATE = 44100;
104LaserdiscPlayer::LaserdiscPlayer(
107 "Laserdisc Player", 1, DUMMY_INPUT_RATE, true)
108 , syncAck (hwConf.getMotherBoard().getScheduler())
109 , syncOdd (hwConf.getMotherBoard().getScheduler())
110 , syncEven(hwConf.getMotherBoard().getScheduler())
111 , motherBoard(hwConf.getMotherBoard())
112 , ldControl(ldControl_)
113 , laserdiscCommand(motherBoard.getCommandController(),
114 motherBoard.getStateChangeDistributor(),
115 motherBoard.getScheduler())
117 motherBoard.getCommandController(),
"autorunlaserdisc",
118 "automatically try to run Laserdisc", true)
120 motherBoard.getReactor().getGlobalSettings().getThrottleManager())
129 scheduleDisplayStart(getCurrentTime());
133 auto* result = doc.allocateElement(
string(getLaserDiscPlayerName()).c_str());
134 result->setFirstChild(doc.allocateElement(
"sound"))
135 ->setFirstChild(doc.allocateElement(
"volume",
"30000"));
154string LaserdiscPlayer::getStateString()
const
156 switch (playerState) {
158 case STOPPED:
return "stopped";
159 case PLAYING:
return "playing";
161 case PAUSED:
return "paused";
162 case STILL:
return "still";
170 "state", getStateString());
173void LaserdiscPlayer::scheduleDisplayStart(EmuTime::param time)
178 syncOdd .setSyncPoint(frameClock + 1);
179 syncEven.setSyncPoint(frameClock + 2);
195 if (remoteLastBit == bit)
return;
200 remoteLastEdge = time;
203 switch (remoteState) {
207 remoteBits = remoteBitNr = 0;
212 if (5800 <= usec && usec < 11200) {
219 if (3400 <= usec && usec < 6200) {
226 if (usec >= 380 && usec < 1070) {
233 if (1260 <= usec && usec < 4720) {
235 remoteBits |= 1 << remoteBitNr;
236 }
else if (usec < 300 || usec >= 1065) {
245 if (++remoteBitNr == 32) {
246 auto custom = narrow_cast<byte>(( remoteBits >> 0) & 0xff);
247 auto customCompl = narrow_cast<byte>((~remoteBits >> 8) & 0xff);
248 auto code = narrow_cast<byte>(( remoteBits >> 16) & 0xff);
249 auto codeCompl = narrow_cast<byte>((~remoteBits >> 24) & 0xff);
250 if (custom == customCompl &&
264void LaserdiscPlayer::submitRemote(RemoteProtocol protocol, uint8_t code)
268 if (protocol != remoteProtocol || code != remoteCode ||
270 remoteProtocol = protocol;
272 remoteVblanksBack = 0;
273 remoteExecuteDelayed =
true;
276 remoteVblanksBack = 0;
277 remoteExecuteDelayed =
false;
283 return renderer->getRawFrame();
286void LaserdiscPlayer::setAck(EmuTime::param time,
int wait)
289 syncAck.removeSyncPoint();
294void LaserdiscPlayer::remoteButtonNEC(uint8_t code, EmuTime::param time)
299 case 0x47: f =
"C+";
break;
300 case 0x46: f =
"C-";
break;
301 case 0x43: f =
"D+";
break;
302 case 0x4b: f =
"L+";
break;
303 case 0x49: f =
"L-";
break;
304 case 0x4a: f =
"L@";
break;
305 case 0x58: f =
"M+";
break;
306 case 0x55: f =
"M-";
break;
307 case 0x17: f =
"P+";
break;
308 case 0x16: f =
"P@";
break;
309 case 0x18: f =
"P/";
break;
310 case 0x54: f =
"S+";
break;
311 case 0x50: f =
"S-";
break;
312 case 0x45: f =
"X+";
break;
313 case 0x41: f =
'F';
break;
314 case 0x40: f =
'C';
break;
315 case 0x42: f =
"END";
break;
316 case 0x00: f =
'0';
break;
317 case 0x01: f =
'1';
break;
318 case 0x02: f =
'2';
break;
319 case 0x03: f =
'3';
break;
320 case 0x04: f =
'4';
break;
321 case 0x05: f =
'5';
break;
322 case 0x06: f =
'6';
break;
323 case 0x07: f =
'7';
break;
324 case 0x08: f =
'8';
break;
325 case 0x09: f =
'9';
break;
326 case 0x5f: f =
"WAIT FRAME";
break;
334 std::cerr <<
"LaserdiscPlayer::remote " << f <<
'\n';
336 std::cerr <<
"LaserdiscPlayer::remote unknown " << std::hex << code <<
'\n';
345 if (code ==
one_of(0x49u, 0x4au, 0x4bu)) {
365 "ejecting laserdisc");
377 bool nonSeekAck =
true;
384 stillOnWaitFrame =
false;
394 nonSeekAck = video->getChapter(0) != 0;
406 seekNum = seekNum * 10 + code;
412 seekFrame(seekNum % 100000, time);
417 seekChapter(seekNum % 100, time);
422 waitFrame = seekNum % 100000;
423 if (waitFrame >= 101 && waitFrame < 200) {
424 auto frame = video->getChapter(
425 int(waitFrame - 100));
426 if (frame) waitFrame = frame;
435 if (seekState !=
NONE && seekNum != 0) {
460 if (seekState ==
WAIT) {
461 stillOnWaitFrame =
true;
472 "The Laserdisc player received a command to "
473 "play backwards (M-). This is currently not "
482 if (playingSpeed >= SPEED_STEP1) {
488 if (playingSpeed <= SPEED_X2) {
495 "The Laserdisc player received an unknown "
496 "command 0x", hex_string<2>(code));
509void LaserdiscPlayer::execSyncAck(EmuTime::param time)
521void LaserdiscPlayer::execSyncFrame(EmuTime::param time,
bool odd)
525 if (!odd || (video && video->getFrameRate() == 60)) {
527 (currentFrame > video->getFrames())) {
531 if (
auto* rawFrame = renderer->getRawFrame()) {
532 renderer->frameStart(time);
534 if (isVideoOutputAvailable(time)) {
535 auto frame = currentFrame;
536 if (video->getFrameRate() == 60) {
541 video->getFrameNo(*rawFrame, frame);
547 renderer->drawBlank(0, 128, 196);
549 renderer->frameEnd();
553 loadingIndicator.
update(seeking || sampleReads > 500);
557 scheduleDisplayStart(time);
564 if (remoteExecuteDelayed) {
565 remoteButtonNEC(remoteCode, time);
568 if (++remoteVblanksBack > 6) {
572 remoteExecuteDelayed =
false;
575void LaserdiscPlayer::setFrameStep()
577 switch (playingSpeed) {
604void LaserdiscPlayer::nextFrame(EmuTime::param time)
607 if (waitFrame && waitFrame == currentFrame) {
612 if (stillOnWaitFrame) {
613 playingFromSample = getCurrentSample(time);
615 stillOnWaitFrame =
false;
624 switch (playingSpeed) {
636 }
else if (playerState ==
PLAYING) {
642 && video->stopFrame(currentFrame)) {
644 playingFromSample = getCurrentSample(time);
649void LaserdiscPlayer::setImageName(
string newImage, EmuTime::param time)
655 unsigned inputRate = video->getSampleRate();
656 sampleClock.
setFreq(inputRate);
663bool LaserdiscPlayer::signalEvent(
const Event& event)
671void LaserdiscPlayer::autoRun()
679 string var =
"::auto_run_ld_counter";
681 "if ![info exists ", var,
"] { set ", var,
" 0 }\n"
683 "after time 2 \"if $", var,
"==\\$", var,
" { "
684 "type_via_keyboard 1CALLLD\\\\r }\"");
687 }
catch (CommandException& e) {
689 "Error executing loading instruction for AutoRun: ",
690 e.getMessage(),
"\n Please report a bug.");
694void LaserdiscPlayer::generateChannels(std::span<float*> buffers,
unsigned num)
697 assert(buffers.size() == 1);
699 buffers[0] =
nullptr;
704 size_t currentSample;
706 if (!sampleClock.
before(start)) [[unlikely]] {
708 EmuDuration duration = sampleClock.
getTime() - start;
709 unsigned len = duration.getTicksAt(video->getSampleRate());
711 buffers[0] =
nullptr;
715 for (; pos < len; ++pos) {
716 buffers[0][pos * 2 + 0] = 0.0f;
717 buffers[0][pos * 2 + 1] = 0.0f;
720 currentSample = playingFromSample;
722 currentSample = getCurrentSample(start);
725 unsigned drift = video->getSampleRate() / 30;
727 if (currentSample > (lastPlayedSample + drift) ||
728 (currentSample + drift) < lastPlayedSample) {
730 lastPlayedSample = currentSample;
737 const AudioFragment* audio = video->getAudio(lastPlayedSample);
741 buffers[0] =
nullptr;
744 for (; pos < num; ++pos) {
745 buffers[0][pos * 2 + 0] = 0.0f;
746 buffers[0][pos * 2 + 1] = 0.0f;
750 auto offset = unsigned(lastPlayedSample - audio->position);
751 unsigned len = std::min(audio->length - offset, num - pos);
754 for (
unsigned i = 0; i < len; ++i, ++pos) {
755 buffers[0][pos * 2 + 0] = muteLeft ? 0.0f :
756 audio->pcm[left][offset + i];
757 buffers[0][pos * 2 + 1] = muteRight ? 0.0f :
758 audio->pcm[right][offset + i];
761 lastPlayedSample += len;
766float LaserdiscPlayer::getAmplificationFactorImpl()
const
771bool LaserdiscPlayer::updateBuffer(
size_t length,
float* buffer,
786void LaserdiscPlayer::play(EmuTime::param time)
795 }
else if (playerState ==
STOPPED) {
800 lastPlayedSample = 0;
801 playingFromSample = 0;
810 playingSpeed = SPEED_1IN4;
811 }
else if (playerState ==
PLAYING) {
818 playingFromSample = (currentFrame - 1LL) * 1001LL *
819 video->getSampleRate() / 30000LL;
830size_t LaserdiscPlayer::getCurrentSample(EmuTime::param time)
832 switch(playerState) {
835 return playingFromSample;
837 return playingFromSample + sampleClock.
getTicksTill(time);
841void LaserdiscPlayer::pause(EmuTime::param time)
844 if (playerState ==
STOPPED)
return;
849 playingFromSample = getCurrentSample(time);
851 playingFromSample = (currentFrame - 1LL) * 1001LL *
852 video->getSampleRate() / 30000LL;
860void LaserdiscPlayer::stop(EmuTime::param time)
868void LaserdiscPlayer::eject(EmuTime::param time)
877void LaserdiscPlayer::stepFrame(
bool forwards)
879 bool needSeek =
false;
885 if (currentFrame < video->getFrames()) {
889 if (currentFrame > 1) {
897 auto samplePos = (currentFrame - 1LL) * 1001LL *
898 video->getSampleRate() / 30000LL;
899 playingFromSample = samplePos;
902 if (video->getFrameRate() == 60)
903 video->seek(currentFrame * 2, samplePos);
905 video->seek(currentFrame, samplePos);
909void LaserdiscPlayer::seekFrame(
size_t toFrame, EmuTime::param time)
915 if (toFrame <= 0) toFrame = 1;
916 if (toFrame > video->getFrames()) toFrame = video->getFrames();
925 auto dist = std::abs(int64_t(toFrame) - int64_t(currentFrame));
926 int seekTime = (dist < 1000)
927 ? narrow<int>(dist + 300)
928 : narrow<int>(1800 + dist / 12);
930 auto samplePos = (toFrame - 1LL) * 1001LL *
931 video->getSampleRate() / 30000LL;
933 if (video->getFrameRate() == 60) {
934 video->seek(toFrame * 2, samplePos);
936 video->seek(toFrame, samplePos);
939 playingFromSample = samplePos;
940 currentFrame = toFrame;
946 setAck(time, seekTime);
949void LaserdiscPlayer::seekChapter(
int chapter, EmuTime::param time)
953 auto frameNo = video->getChapter(chapter);
954 if (!frameNo)
return;
955 seekFrame(frameNo, time);
965 auto sample = getCurrentSample(time);
969 return narrow_cast<int16_t>
970 (audio->pcm[channel][sample - audio->position]
977bool LaserdiscPlayer::isVideoOutputAvailable(EmuTime::param time)
981 bool videoOut = [&] {
982 switch (playerState) {
996void LaserdiscPlayer::preVideoSystemChange() noexcept
1001void LaserdiscPlayer::postVideoSystemChange() noexcept
1006void LaserdiscPlayer::createRenderer()
1009 renderer = RendererFactory::createLDRenderer(*
this, display);
1012static constexpr std::initializer_list<enum_string<LaserdiscPlayer::RemoteState>> RemoteStateInfo = {
1021static constexpr std::initializer_list<enum_string<LaserdiscPlayer::PlayerState>> PlayerStateInfo = {
1030static constexpr std::initializer_list<enum_string<LaserdiscPlayer::SeekState>> SeekStateInfo = {
1038static constexpr std::initializer_list<enum_string<LaserdiscPlayer::StereoMode>> StereoModeInfo = {
1045static constexpr std::initializer_list<enum_string<LaserdiscPlayer::RemoteProtocol>> RemoteProtocolInfo = {
1055template<
typename Archive>
1059 ar.serialize(
"RemoteState", remoteState);
1061 ar.serialize(
"RemoteBitNr", remoteBitNr,
1062 "RemoteBits", remoteBits);
1063 if (ar.versionBelow(version, 3)) {
1064 assert(Archive::IS_LOADER);
1068 ar.serialize(
"RemoteLastBit", remoteLastBit,
1069 "RemoteLastEdge", remoteLastEdge,
1070 "RemoteProtocol", remoteProtocol);
1072 ar.serialize(
"RemoteCode", remoteCode);
1073 if (ar.versionBelow(version, 3)) {
1074 assert(Archive::IS_LOADER);
1077 ar.serialize(
"RemoteExecuteDelayed", remoteExecuteDelayed,
1078 "RemoteVblanksBack", remoteVblanksBack);
1082 ar.serialize(
"OggImage", oggImage);
1083 if constexpr (Archive::IS_LOADER) {
1085 if (!oggImage.
empty()) {
1086 setImageName(oggImage.
getResolved(), getCurrentTime());
1091 ar.serialize(
"PlayerState", playerState);
1095 ar.serialize(
"SeekState", seekState);
1097 ar.serialize(
"SeekNum", seekNum);
1099 ar.serialize(
"seeking", seeking);
1102 ar.serialize(
"WaitFrame", waitFrame);
1105 if (ar.versionAtLeast(version, 2)) {
1106 ar.serialize(
"StillOnWaitFrame", stillOnWaitFrame);
1109 ar.serialize(
"ACK", ack,
1110 "PlayingSpeed", playingSpeed);
1113 ar.serialize(
"CurrentFrame", currentFrame);
1115 ar.serialize(
"FrameStep", frameStep);
1119 ar.serialize(
"StereoMode", stereoMode,
1120 "FromSample", playingFromSample,
1121 "SampleClock", sampleClock);
1123 if constexpr (Archive::IS_LOADER) {
1125 if (video->getSampleRate() != sampleClock.
getFreq()) {
1126 uint64_t pos = playingFromSample;
1128 pos *= video->getSampleRate();
1131 playingFromSample = pos;
1132 sampleClock.
setFreq(video->getSampleRate());
1135 auto sample = getCurrentSample(getCurrentTime());
1136 if (video->getFrameRate() == 60)
1137 video->seek(currentFrame * 2, sample);
1139 video->seek(currentFrame, sample);
1140 lastPlayedSample = sample;
1144 if (ar.versionAtLeast(version, 4)) {
1145 ar.serialize(
"syncEven", syncEven,
1147 "syncAck", syncAck);
1152 if constexpr (Archive::IS_LOADER) {
1153 (void)isVideoOutputAvailable(getCurrentTime());
bool getBoolean() const noexcept
void printWarning(std::string_view message)
Represents a clock with a fixed frequency.
virtual TclObject executeCommand(zstring_view command, CliConnection *connection=nullptr)=0
Execute the given command.
void detach(VideoSystemChangeListener &listener)
void attach(VideoSystemChangeListener &listener)
bool before(EmuTime::param e) const
Checks whether this clock's last tick is or is not before the given time stamp.
unsigned getTicksTill(EmuTime::param e) const
Calculate the number of ticks for this clock until the given time.
unsigned getFreq() const
Returns the frequency (in Hz) at which this clock ticks.
void advance(EmuTime::param e)
Advance this clock in time until the last tick which is not past the given time.
void setFreq(unsigned freq)
Change the frequency at which this clock ticks.
EmuTime::param getTime() const
Gets the time at which the last clock tick occurred.
static constexpr EmuDuration msec(unsigned x)
constexpr unsigned getTicksAt(unsigned freq) const
void unregisterEventListener(EventType type, EventListener &listener)
Unregisters a previously registered event listener.
void registerEventListener(EventType type, EventListener &listener, Priority priority=Priority::OTHER)
Registers a given object to receive certain events.
bool empty() const
Convenience method to test for empty filename.
const std::string & getResolved() const &
void setMuting(bool left, bool right, EmuTime::param time)
int16_t readSample(EmuTime::param time)
void extControl(bool bit, EmuTime::param time)
MSXMotherBoard & getMotherBoard()
const RawFrame * getRawFrame() const
void getMediaInfo(TclObject &result) override
This method gets called when information is required on the media inserted in the media slot of the p...
void serialize(Archive &ar, unsigned version)
void update(bool newState)
Called by the device to indicate its loading state may have changed.
void update(UpdateType type, std::string_view name, std::string_view value) override
void registerMediaInfo(std::string_view name, MediaInfoProvider &provider)
Register and unregister providers of media info, for the media info topic.
CommandController & getCommandController()
void unregisterMediaInfo(MediaInfoProvider &provider)
MSXCliComm & getMSXCliComm()
ReverseManager & getReverseManager()
CassettePortInterface & getCassettePort()
void videoIn(bool enabled)
A video frame as output by the VDP scanline conversion unit, before any postprocessing filters are ap...
Contains the main loop of openMSX.
EventDistributor & getEventDistributor()
bool updateBuffer(size_t length, float *buffer, EmuTime::param time) override
Generate sample data.
static void restoreOld(Archive &ar, std::vector< Schedulable * > schedulables)
void updateStream(EmuTime::param time)
unsigned getInputRate() const
void setInputRate(unsigned sampleRate)
void unregisterSound()
Unregisters this sound device with the Mixer.
void registerSound(const DeviceConfig &config)
Registers this sound device with the Mixer.
void addDictKeyValues(Args &&... args)
static XMLDocument & getStaticDocument()
constexpr unsigned reverseNBits(unsigned x, unsigned bits)
Reverse the lower N bits of a given value.
constexpr uint8_t reverseByte(uint8_t a)
Reverse the bits in a byte.
This file implemented 3 utility functions:
EventType getType(const Event &event)
const FileContext & userFileContext()
FileContext userFileContext(string_view savePath)
std::variant< KeyUpEvent, KeyDownEvent, MouseMotionEvent, MouseButtonUpEvent, MouseButtonDownEvent, MouseWheelEvent, JoystickAxisMotionEvent, JoystickHatEvent, JoystickButtonUpEvent, JoystickButtonDownEvent, OsdControlReleaseEvent, OsdControlPressEvent, WindowEvent, TextEvent, FileDropEvent, QuitEvent, FinishFrameEvent, CliCommandEvent, GroupEvent, BootEvent, FrameDrawnEvent, BreakEvent, SwitchRendererEvent, TakeReverseSnapshotEvent, AfterTimedEvent, MachineLoadedEvent, MachineActivatedEvent, MachineDeactivatedEvent, MidiInReaderEvent, MidiInWindowsEvent, MidiInCoreMidiEvent, MidiInCoreMidiVirtualEvent, MidiInALSAEvent, Rs232TesterEvent, Rs232NetEvent, ImGuiDelayedActionEvent, ImGuiActiveEvent > Event
#define OUTER(type, member)
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
#define SERIALIZE_ENUM(TYPE, INFO)
TemporaryString tmpStrCat(Ts &&... ts)