Skip to content

Commit 4a268e4

Browse files
committed
Replaced SNAP_XXX options by function parameters
1 parent f759870 commit 4a268e4

22 files changed

+311
-363
lines changed

Core/Components/Amiga.cpp

Lines changed: 37 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,6 @@ Amiga::getOption(Opt option) const
159159
case Opt::AMIGA_VSYNC: return (i64)config.vsync;
160160
case Opt::AMIGA_SPEED_BOOST: return (i64)config.speedBoost;
161161
case Opt::AMIGA_RUN_AHEAD: return (i64)config.runAhead;
162-
case Opt::AMIGA_SNAP_AUTO: return (i64)config.autoSnapshots;
163-
case Opt::AMIGA_SNAP_DELAY: return (i64)config.snapshotDelay;
164-
case Opt::AMIGA_SNAP_COMPRESSOR: return (i64)config.snapshotCompressor;
165162
case Opt::AMIGA_WS_COMPRESSION: return (i64)config.compressWorkspaces;
166163

167164
default:
@@ -209,25 +206,7 @@ Amiga::checkOption(Opt opt, i64 value)
209206
throw AppError(Fault::OPT_INV_ARG, "-7...7");
210207
}
211208
return;
212-
213-
case Opt::AMIGA_SNAP_AUTO:
214-
215-
return;
216-
217-
case Opt::AMIGA_SNAP_DELAY:
218-
219-
if (value < 10 || value > 3600) {
220-
throw AppError(Fault::OPT_INV_ARG, "10...3600");
221-
}
222-
return;
223-
224-
case Opt::AMIGA_SNAP_COMPRESSOR:
225-
226-
if (!CompressorEnum::isValid(value)) {
227-
throw AppError(Fault::OPT_INV_ARG, CompressorEnum::keyList());
228-
}
229-
return;
230-
209+
231210
case Opt::AMIGA_WS_COMPRESSION:
232211

233212
return;
@@ -275,23 +254,6 @@ Amiga::setOption(Opt option, i64 value)
275254

276255
config.runAhead = isize(value);
277256
return;
278-
279-
case Opt::AMIGA_SNAP_AUTO:
280-
281-
config.autoSnapshots = bool(value);
282-
scheduleNextSnpEvent();
283-
return;
284-
285-
case Opt::AMIGA_SNAP_DELAY:
286-
287-
config.snapshotDelay = isize(value);
288-
scheduleNextSnpEvent();
289-
return;
290-
291-
case Opt::AMIGA_SNAP_COMPRESSOR:
292-
293-
config.snapshotCompressor = Compressor(value);
294-
return;
295257

296258
case Opt::AMIGA_WS_COMPRESSION:
297259

@@ -1149,9 +1111,39 @@ Amiga::takeSnapshot()
11491111
return result;
11501112
}
11511113

1114+
MediaFile *
1115+
Amiga::takeSnapshot(Compressor compressor, isize delay, bool repeat)
1116+
{
1117+
if (delay != 0) {
1118+
1119+
i64 payload = (i64)compressor << 24 | repeat << 16 | delay;
1120+
agnus.scheduleRel<SLOT_SNP>(Amiga::sec(delay), SNP_TAKE, payload);
1121+
return nullptr;
1122+
}
1123+
1124+
// Take the snapshot
1125+
Snapshot *result = new Snapshot(*this);
1126+
1127+
// Compress the snapshot if requested
1128+
result->compress(compressor);
1129+
1130+
return result;
1131+
}
1132+
11521133
void
11531134
Amiga::serviceSnpEvent(EventID eventId)
11541135
{
1136+
// Ignore the run-ahead instance
1137+
if (objid != 0) { agnus.cancel<SLOT_SNP>(); return; }
1138+
1139+
// Take snapshot and hand it over to the GUI
1140+
auto *snapshot = takeSnapshot(Compressor(agnus.data[SLOT_SNP] >> 24));
1141+
msgQueue.put( Message { .type = Msg::SNAPSHOT_TAKEN, .snapshot = { snapshot } } );
1142+
1143+
// Schedule the next event
1144+
scheduleNextSnpEvent();
1145+
1146+
/*
11551147
// Check for the main instance (ignore the run-ahead instance)
11561148
if (objid == 0) {
11571149
@@ -1161,16 +1153,17 @@ Amiga::serviceSnpEvent(EventID eventId)
11611153
11621154
// Schedule the next event
11631155
scheduleNextSnpEvent();
1156+
*/
11641157
}
11651158

11661159
void
11671160
Amiga::scheduleNextSnpEvent()
11681161
{
1169-
auto snapshots = emulator.get(Opt::AMIGA_SNAP_AUTO);
1170-
auto delay = emulator.get(Opt::AMIGA_SNAP_DELAY);
1162+
auto repeat = bool(agnus.data[SLOT_SNP] >> 16 & 0xFF);
1163+
auto delay = double(agnus.data[SLOT_SNP] & 0xFFFF);
11711164

1172-
if (snapshots) {
1173-
agnus.scheduleRel<SLOT_SNP>(SEC(double(delay)), SNP_TAKE);
1165+
if (repeat) {
1166+
agnus.scheduleRel<SLOT_SNP>(Amiga::sec(delay), SNP_TAKE, agnus.data[SLOT_SNP]);
11741167
} else {
11751168
agnus.cancel<SLOT_SNP>();
11761169
}
@@ -1185,13 +1178,8 @@ Amiga::loadSnapshot(const fs::path &path)
11851178
void
11861179
Amiga::loadSnapshot(const MediaFile &file)
11871180
{
1188-
const Snapshot &snapshot = dynamic_cast<const Snapshot &>(file);
1189-
loadSnapshot(snapshot);
1190-
}
1181+
const Snapshot &snap = dynamic_cast<const Snapshot &>(file);
11911182

1192-
void
1193-
Amiga::loadSnapshot(const Snapshot &snap)
1194-
{
11951183
// Make a copy so we can modify the snapshot
11961184
Snapshot snapshot(snap);
11971185

Core/Components/Amiga.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ class Amiga final : public CoreComponent, public Inspectable<AmigaInfo> {
7575
Opt::AMIGA_VSYNC,
7676
Opt::AMIGA_SPEED_BOOST,
7777
Opt::AMIGA_RUN_AHEAD,
78-
Opt::AMIGA_SNAP_AUTO,
79-
Opt::AMIGA_SNAP_DELAY,
80-
Opt::AMIGA_SNAP_COMPRESSOR,
8178
Opt::AMIGA_WS_COMPRESSION,
8279
};
8380

@@ -441,12 +438,13 @@ class Amiga final : public CoreComponent, public Inspectable<AmigaInfo> {
441438
public:
442439

443440
// Takes a snapshot
444-
MediaFile *takeSnapshot();
441+
[[deprecated]] MediaFile *takeSnapshot();
442+
MediaFile *takeSnapshot(Compressor compressor, isize delay = 0, bool repeat = false);
445443

446444
// Loads a snapshot from a file
447445
void loadSnapshot(const fs::path &path) throws;
448446
void loadSnapshot(const MediaFile &file) throws;
449-
void loadSnapshot(const class Snapshot &snapshot) throws;
447+
// void loadSnapshot(const class Snapshot &snapshot) throws;
450448

451449
// Saves a snapshot to a file
452450
void saveSnapshot(const fs::path &path) throws;

Core/Infrastructure/Defaults.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ Defaults::Defaults()
2929
setFallback(Opt::AMIGA_SPEED_BOOST, 100);
3030
setFallback(Opt::AMIGA_RUN_AHEAD, 0);
3131

32-
setFallback(Opt::AMIGA_SNAP_AUTO, false);
33-
setFallback(Opt::AMIGA_SNAP_DELAY, 10);
34-
setFallback(Opt::AMIGA_SNAP_COMPRESSOR, (i64)Compressor::LZ4);
3532
setFallback(Opt::AMIGA_WS_COMPRESSION, true);
3633

3734
setFallback(Opt::AGNUS_REVISION, (i64)AgnusRevision::ECS_1MB);
@@ -184,7 +181,7 @@ Defaults::Defaults()
184181
setFallback(Opt::AUD_VOLL, 50);
185182
setFallback(Opt::AUD_VOLR, 50);
186183
setFallback(Opt::AUD_FILTER_TYPE, (i64)FilterType::A500);
187-
setFallback(Opt::AUD_BUFFER_SIZE, (i64)4096);
184+
setFallback(Opt::AUD_BUFFER_SIZE, 4096);
188185
setFallback(Opt::AUD_SAMPLING_METHOD, (i64)SamplingMethod::NONE);
189186
setFallback(Opt::AUD_ASR, true);
190187
setFallback(Opt::AUD_FASTPATH, true);

Core/Infrastructure/Option.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ OptionParser::create(Opt opt, i64 arg)
3636
case Opt::AMIGA_VSYNC: return boolParser();
3737
case Opt::AMIGA_SPEED_BOOST: return numParser("%");
3838
case Opt::AMIGA_RUN_AHEAD: return numParser(" frames");
39-
case Opt::AMIGA_SNAP_AUTO: return boolParser();
40-
case Opt::AMIGA_SNAP_DELAY: return numParser(" sec");
41-
case Opt::AMIGA_SNAP_COMPRESSOR: return enumParser.template operator()<CompressorEnum,Compressor>();
4239
case Opt::AMIGA_WS_COMPRESSION: return boolParser();
4340

4441
case Opt::AGNUS_REVISION: return enumParser.template operator()<AgnusRevisionEnum,AgnusRevision>();

Core/Infrastructure/OptionTypes.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ enum class Opt : long
3232
AMIGA_VSYNC, ///< Derive the frame rate to the VSYNC signal
3333
AMIGA_SPEED_BOOST, ///< Speed adjustment in percent
3434
AMIGA_RUN_AHEAD, ///< Number of run-ahead frames
35-
36-
// Snapshots
37-
AMIGA_SNAP_AUTO, ///< Automatically take a snapshots
38-
AMIGA_SNAP_DELAY, ///< Delay between two snapshots in seconds
39-
AMIGA_SNAP_COMPRESSOR, ///< Snapshot compression method
4035

4136
// Workspaces
4237
AMIGA_WS_COMPRESSION, ///< Workspace media file compression
@@ -243,9 +238,6 @@ struct OptEnum : Reflection<OptEnum, Opt>
243238
case Opt::AMIGA_VSYNC: return "AMIGA.VSYNC";
244239
case Opt::AMIGA_SPEED_BOOST: return "AMIGA.SPEED_BOOST";
245240
case Opt::AMIGA_RUN_AHEAD: return "AMIGA.RUN_AHEAD";
246-
case Opt::AMIGA_SNAP_AUTO: return "AMIGA.SNAP_AUTO";
247-
case Opt::AMIGA_SNAP_DELAY: return "AMIGA.SNAP_DELAY";
248-
case Opt::AMIGA_SNAP_COMPRESSOR: return "AMIGA.SNAP_COMPRESSOR";
249241
case Opt::AMIGA_WS_COMPRESSION: return "AMIGA.WS_COMPRESSION";
250242

251243
case Opt::AGNUS_REVISION: return "AGNUS.REVISION";
@@ -425,9 +417,6 @@ struct OptEnum : Reflection<OptEnum, Opt>
425417
case Opt::AMIGA_VSYNC: return "VSYNC mode";
426418
case Opt::AMIGA_SPEED_BOOST: return "Speed adjustment";
427419
case Opt::AMIGA_RUN_AHEAD: return "Run-ahead frames";
428-
case Opt::AMIGA_SNAP_AUTO: return "Automatically take snapshots";
429-
case Opt::AMIGA_SNAP_DELAY: return "Time span between two snapshots";
430-
case Opt::AMIGA_SNAP_COMPRESSOR: return "Snapshot compression method";
431420
case Opt::AMIGA_WS_COMPRESSION: return "Compress workspaces";
432421

433422
case Opt::AGNUS_REVISION: return "Chip revision";

Core/Ports/AudioPort.cpp

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,6 @@ AudioPort::_dump(Category category, std::ostream &os) const
7676
}
7777
}
7878

79-
void
80-
AudioPort::_initialize()
81-
{
82-
83-
}
84-
8579
void
8680
AudioPort::_didReset(bool hard)
8781
{
@@ -306,7 +300,7 @@ AudioPort::cacheInfo(AudioPortInfo &result) const
306300
void
307301
AudioPort::cacheStats(AudioPortStats &result) const
308302
{
309-
stats.fillLevel = stream.fillLevel();
303+
result.fillLevel = stream.fillLevel();
310304
}
311305

312306
void
@@ -397,8 +391,8 @@ AudioPort::synthesize(Cycle clock, long count, double cyclesPerSample)
397391
stream.mutex.lock();
398392

399393
// Check for a buffer overflow
400-
if (stream.count() + count >= stream.cap()) handleBufferOverflow();
401-
394+
if (stream.free() < count) handleBufferOverflow();
395+
402396
// Check if we can take a fast path
403397
if (config.idleFastPath) {
404398

@@ -494,11 +488,6 @@ AudioPort::synthesize(Cycle clock, long count, double cyclesPerSample)
494488
void
495489
AudioPort::handleBufferUnderflow()
496490
{
497-
// There are two common scenarios in which buffer underflows occur:
498-
//
499-
// (1) The consumer runs slightly faster than the producer
500-
// (2) The producer is halted or not startet yet
501-
502491
// Wipe out the buffer and reset the write pointer
503492
stream.clear(SamplePair{0,0});
504493
stream.alignWritePtr();
@@ -507,7 +496,7 @@ AudioPort::handleBufferUnderflow()
507496
auto elapsedTime = util::Time::now() - lastAlignment;
508497
lastAlignment = util::Time::now();
509498

510-
// Adjust the sample rate, if condition (1) holds
499+
// Adjust the sample rate if the emulator runs under normal conditions
511500
if (emulator.isRunning() && !emulator.isWarping()) {
512501

513502
stats.bufferUnderflows++;
@@ -522,19 +511,14 @@ AudioPort::handleBufferUnderflow()
522511
void
523512
AudioPort::handleBufferOverflow()
524513
{
525-
// There are two common scenarios in which buffer overflows occur:
526-
//
527-
// (1) The consumer runs slightly slower than the producer
528-
// (2) The consumer is halted or not startet yet
529-
530514
// Reset the write pointer
531515
stream.alignWritePtr();
532516

533517
// Determine the number of elapsed seconds since the last adjustment
534518
auto elapsedTime = util::Time::now() - lastAlignment;
535519
lastAlignment = util::Time::now();
536520

537-
// Adjust the sample rate, if condition (1) holds
521+
// Adjust the sample rate if the emulator runs under normal conditions
538522
if (emulator.isRunning() && !emulator.isWarping()) {
539523

540524
stats.bufferOverflows++;
@@ -555,6 +539,9 @@ AudioPort::ignoreNextUnderOrOverflow()
555539
isize
556540
AudioPort::copyMono(float *buffer, isize n)
557541
{
542+
// Inform the sample rate detector about the number of requested samples
543+
detector.feed(n);
544+
558545
// Copy sound samples
559546
auto cnt = stream.copyMono(buffer, n);
560547
stats.consumedSamples += cnt;
@@ -584,6 +571,9 @@ AudioPort::copyStereo(float *left, float *right, isize n)
584571
isize
585572
AudioPort::copyInterleaved(float *buffer, isize n)
586573
{
574+
// Inform the sample rate detector about the number of requested samples
575+
detector.feed(n);
576+
587577
// Copy sound samples
588578
auto cnt = stream.copyInterleaved(buffer, n);
589579
stats.consumedSamples += cnt;

Core/Ports/AudioPort.h

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,15 @@ namespace vamiga {
4545
class AudioPort final : public SubComponent, public Inspectable<AudioPortInfo, AudioPortStats> {
4646

4747
friend class AudioFilter;
48+
friend class Paula;
4849

49-
Descriptions descriptions = {
50-
{
51-
.type = Class::AudioPort,
52-
.name = "AudioPort",
53-
.description = "Audio Port",
54-
.shell = "audio"
55-
},
56-
{
57-
.type = Class::AudioPort,
58-
.name = "RecAudioPort",
59-
.description = "Audio Port (Recorder)",
60-
.shell = ""
61-
},
62-
};
50+
Descriptions descriptions = {{
51+
52+
.type = Class::AudioPort,
53+
.name = "AudioPort",
54+
.description = "Audio Port",
55+
.shell = "audio"
56+
}};
6357

6458
Options options = {
6559

@@ -79,8 +73,6 @@ class AudioPort final : public SubComponent, public Inspectable<AudioPortInfo, A
7973
Opt::AUD_FASTPATH
8074
};
8175

82-
friend class Paula;
83-
8476
// Current configuration
8577
AudioPortConfig config = { };
8678

@@ -101,13 +93,13 @@ class AudioPort final : public SubComponent, public Inspectable<AudioPortInfo, A
10193
float vol[4] = { };
10294

10395
// Panning factors
104-
float pan[4] ={ };
96+
float pan[4] = { };
10597

10698
// Master volumes (fadable)
10799
util::Animated<float> volL;
108100
util::Animated<float> volR;
109101

110-
// Used to determine if a Msg::MUTE should be send
102+
// Used to determine if Msg::MUTE should be send
111103
bool wasMuted = false;
112104

113105

@@ -157,7 +149,6 @@ class AudioPort final : public SubComponent, public Inspectable<AudioPortInfo, A
157149
return *this;
158150
}
159151

160-
161152
// Resets the output buffer and the two audio filters
162153
void clear();
163154

@@ -201,7 +192,6 @@ class AudioPort final : public SubComponent, public Inspectable<AudioPortInfo, A
201192
void _dump(Category category, std::ostream &os) const override;
202193
void _didLoad() override;
203194
void _didReset(bool hard) override;
204-
void _initialize() override;
205195
void _powerOn() override;
206196
void _run() override;
207197
void _pause() override;

0 commit comments

Comments
 (0)