Menu

#522 audio2tape writes every pause as 1 ms, whatever the recording contained

v1.9.2
closed-accepted
nobody
None
5
4 days ago
4 days ago
AJ B
No

Both places that convert T-states to milliseconds divide by source_machine_hz * 1000 where
they should multiply by 1000 / source_machine_hz — out by a factor of 10⁶. Every pause is
therefore written as 1 ms:

/* converter/romloader.cc, romloader::get_block() */
double pause_ms = ceil( blocks[number].pause_length /
                        ( source_machine_hz * 1000 ) );

/* audio2tape.cc, get_pause_block() */
double pause_ms = ceil( ( end_tstates - start_tstates ) /
                        ( source_machine_hz * 1000 ) );

A one-second pause is 3,500,000 T-states; 3500000 / (3500000 * 1000) is 0.001, and
ceil makes that 1.

Reproducing

curl -sSLO https://worldofspectrum.net/pub/sinclair/games/m/ManicMiner.tzx.zip
unzip -j ManicMiner.tzx.zip '*.tzx'
tape2wav "Manic Miner.tzx" mm.wav
audio2tape mm.wav mm-out.tzx
tzxlist "Manic Miner.tzx" | grep 'Pause length'
tzxlist mm-out.tzx        | grep 'Pause length'
Manic Miner Jet Set Willy
1000, 2000, 1000, 2000, 1000, 0 ms 769, 857, 779, 852, 765, 868, 770 ms
1, 1, 1, 1, 1, 0 1, 1, 1, 1, 1, 1, 1

The pauses are in the recording — the rendered WAV holds 1004.6 ms and 2009.3 ms of silence
between Manic Miner's blocks. The output tape is 188.2 s against the
source recording's 195.2 s.

Proposed fix

--- a/converter/romloader.cc
+++ b/converter/romloader.cc
@@ romloader::get_block

-  double pause_ms = ceil( blocks[number].pause_length /
-                          ( source_machine_hz * 1000 ) );
+  double pause_ms = ceil( blocks[number].pause_length * 1000.0 /
+                          source_machine_hz );
--- a/audio2tape.cc
+++ b/audio2tape.cc
@@ get_pause_block
-  double pause_ms = ceil( ( end_tstates - start_tstates ) /
-                          ( source_machine_hz * 1000 ) );
+  double pause_ms = ceil( ( end_tstates - start_tstates ) * 1000.0 /
+                          source_machine_hz );

With that change:

Tape original pre-patch patched
Manic Miner 1000, 2000, 1000, 2000, 1000 1, 1, 1, 1, 1 1005, 2010, 1005, 2010, 1005
Jet Set Willy 769, 857, 779, 852, 765, 868, 770 1 ×7 773, 861, 783, 856, 769, 873, 774

The extra few milliseconds are what tape2wav rendered, and the patched
output's total duration, 195.2 s, is the source WAV's duration exactly.

Discussion

  • Fredrick Meunier

    • status: open --> closed-accepted
    • Group: future --> v1.9.2
     
  • Fredrick Meunier

    Thanks, fixed in [3704b2].

     

    Related

    Commit: [3704b2]


Log in to post a comment.