Commit graph

81 commits

Author SHA1 Message Date
Fabian 497f618cab Merge branch 'wasm' into master 2021-01-03 02:07:20 -06:00
github-jane-doe 15ff296628
Typos (#371)
Fix typos
2020-10-04 19:46:41 +02:00
Ernest Wong 19b8ac4799 Fix sound volume after state restore
Several volume mixer settings are mapped to two different mixer register
addresses: one for higher precision, and a lower precision one for
legacy reasons.

Windows 98 uses the new registers and leaves the legacy registers
untouched (which have a value of zero), but when v86 restores from a
state file, the old legacy registers are being re-written to and
incorrectly overwrites the new register values with zero.

mixer_full_update now skips over legacy register values. The new, higher
precision registers are the single source of truth and legacy register
values should be calculated from the new registers.

Fixes the Windows 98 sound demo.
2019-05-18 13:17:29 -05:00
Ernest Wong bd791d2339 Call mixer_reset, pcspeaker.start at known times 2018-04-08 14:38:24 -07:00
Ernest Wong 1081a83c1a Fix and clarify treble/bass mixer value calculation 2018-04-08 14:38:24 -07:00
Ernest Wong 8aa4a7c8a7 Replace magic strings enums with integer constants 2018-04-08 14:38:24 -07:00
Ernest Wong 1b55e633c2 Minor: semicolons 2018-04-08 14:38:24 -07:00
Ernest Wong 2c982a6645 Minor: tidy up 2018-04-08 14:38:24 -07:00
Ernest Wong d0729d9b24 Suppress unimplemented speaker mixer messages 2018-04-08 14:38:24 -07:00
Ernest Wong cb3fd14901 Use compiler type casting instead of array hack 2018-04-08 14:38:24 -07:00
Ernest Wong 7438f93b6d Refactor SpeakerAdapter
There were too many things happening under the same umbrella.
2018-04-08 14:38:24 -07:00
Ernest Wong 41f313b7c5 Ensure sample rate is not too low
Some web browsers e.g. Firefox has yet to implement sample rate
conversion for rates less than 8000, and they are not required to by the
web standards
2018-04-08 14:38:24 -07:00
Ernest Wong 7117630293 Revert correct sample rate from time constant calculation
Tip: read the manuals properly and don't underestimate your algebra
2018-04-08 14:38:24 -07:00
Ernest Wong 43c3aa4842 Simplify: let speaker_adapter drive all timings
Previously:
 _____         ______         _________
|     | .->-. |      | .->-. |         |
| DMA | |   | | SB16 | |   | | Speaker |
|_____| '-<-' |______| '-<-' |_________|

- Speaker adapter regularly requests sb16.js to send audio samples
  immediately, until enough samples gets scheduled.

- SB16 continuously pulls data from DMA independently from Speaker until
  enough samples gets buffered.

- Due to timing issues, SB16 may not have enough data to reply to
  Speaker when Speaker asks for them.

Now:
 _____         ______         _________
|     | .->---|      |--->-. |         |
| DMA | |     | SB16 |     | | Speaker |
|_____| '-<---|______|---<-' |_________|

- Speaker still regularly requests SB16 to prepare new audio, but no
  longer expects a reply immediately.

- SB16 uses Speaker's requests to time its transfers from DMA
2018-04-08 14:38:24 -07:00
Ernest Wong f654c331d9 Ensure transfers can be divided into stereo channels
Previous sb16 dma transfer size heuristic led to block sizes that were
not divisible into the two channels, resulting in the Right audio
channel missing a single sample, and samples getting mixed up between
the two channels.

This commit fixes some nasty sound distortion.
2018-04-08 14:38:24 -07:00
Ernest Wong 4d3b88e712 Convert sb16 sample rate from time constant correctly
Tip: Don't skip your algebra classes.
2018-04-08 14:38:24 -07:00
Ernest Wong 6d2c9f6c24 Use audiobuffers instead of scriptprocessor (speaker)
Fixes sample rate conversion problem.
Introduces new timing problems: to be fixed by letting speaker drive the
timings for dma.
Todo: reuse audio buffers - keep them in a pool.
2018-04-08 14:38:24 -07:00
Ernest Wong 40a1c3c70d Implement sb16 mixer chip + tidy up 2018-04-08 14:38:24 -07:00
Ernest Wong a546fd49a3 Ensure dma transfer takes multiple reads for sb16
That way, programs using sb16 can detect changes in the dma counters and
prepare its sound data before the next underflow / autoinit.
2018-02-18 12:14:39 -06:00
Ernest Wong 90c050304a Do sb16 transfer immediately if already unmasked 2018-02-18 12:14:39 -06:00
Ernest Wong bf8f6fdd3e Allow 16/32-bit sb16 port read/write 2018-02-18 12:14:39 -06:00
Ernest Wong a3a1414b5a Avoid unnecessary audio recalculations in a loop 2017-12-16 22:51:40 -06:00
Ernest Wong c017373c76 Avoid unnecessary copying of buffers. 2017-12-16 22:51:40 -06:00
Ernest Wong 9fa0fcd9b2 Reduce audio processor overhead when paused
First attempt: when pausing, clear the output buffers once using .fill(0)
during the onaudioprocess event, and set a flag so that it doesn't
have to continuously .fill(0) the buffers when paused.

Problem with first attempt: It appears that performing .fill(0) once does
not guarantee clearing all the buffer that is given to the onaudioprocess
event, probably because the output buffers given are a subarray of a larger
buffer.

In this second attempt, we simply disconnect the processor node from the
destination node, and reconnect them when unpaused.
2017-12-16 22:51:40 -06:00
Ernest Wong a185fd13bc Tidy up: spacing, quotes, and line length.
- Space before ? in ternary operators
- Double quotes ' -> "
- Line length of 100
2017-12-16 22:51:40 -06:00
Ernest Wong 0ec16f5a03 Tidyup: use underscore naming 2017-12-16 22:51:40 -06:00
Ernest Wong 833bc52df1 Move samplerate broadcast out of hot code 2017-12-16 22:51:40 -06:00
Ernest Wong dfd3202149 Send audio data only through bus
Problem: transferring ownership of the audio Float32Array buffers from
the speaker adapter to sb16 does not appear to work.

Demo: https://jsbin.com/vilafof/edit?html,js,output

This is probably because:

> the returned AudioBuffer is only valid in the scope of the
> onaudioprocess function.
(https://developer.mozilla.org/en-US/docs/Web/API/AudioProcessingEvent)

and probably because transferring ownership will make the buffer
unreadable in the non-worker thread.

Solution: send data through to the speaker adapter directly using the
bus. The sb16.dac_buffers has been modified to allow shifting out a chunk of
consequtive elements more efficiently.
2017-12-16 22:51:40 -06:00
Ernest Wong da0ffc4c20 Transfer ownership of buffers to sb16 onprocess
Don't send entire event object through as that is not compatible with
worker_bus.
2017-12-16 22:51:40 -06:00
Ernest Wong 1f8cfb41ff Pause sb16 when cpu is paused or via pause command
Previously, when the cpu is paused, sb16 continues to perform dma
transfers and the speaker continues to play the audio stored in the
buffer (looping), which is not what we want.

More importantly, when we pause the cpu to save the machine state,
because sb16 was continuing with its dma transfers, the machine might
restore back into a confused and muddled state.
2017-12-16 22:51:40 -06:00
Ernest Wong eb7c333a2e Tidy up unimplemented FM Synthesizer code 2017-12-16 22:51:40 -06:00
Ernest Wong 27789b7797 Realign sb16 state variables 2017-12-16 22:51:40 -06:00
Ernest Wong f30ddbd400 Prefix constants & avoid contextless magic numbers 2017-12-16 22:51:40 -06:00
Ernest Wong dd7f845e57 Make DMA on_unmask states restorable
Instead of registering an on_unmask listener every time we want a
transfer, and unregistering the listener every time we're done with it,
SB16 now registers a handler during init, and keeps this handler
registered throughout the session. The handler function is moved to SB16's
prototype.

The dma_waiting_transfer flag indicates whether the handler should
actually carry out the transfer.
2017-12-16 22:51:40 -06:00
Ernest Wong ac8284f893 Remove DMA identification routine
Reasons:
- Incompatible licensing with dosbox's GPL license
- Couldn't find documentation
- Routine not used yet
- Not understood by me
2017-12-16 22:51:40 -06:00
Ernest Wong 584548de5c Tidy code
- Constant variable names to uppercase.
- Consistent use of spacing and semicolons.
- Avoid recursion.
- Prefer bitwise operators.
- Place operators before line continuation (to disambiguate problems
associated with automatic semicolon insertion).
2017-12-16 22:51:40 -06:00
Ernest Wong 0c439694b1 Begin plan for FM synthesizer 2017-12-16 22:51:40 -06:00
Ernest Wong 0a5d5430d3 Improve consistent style and clarity 2017-12-16 22:51:40 -06:00
Ernest Wong 72f3a89e8f Disable stereo byte counting. Sound is now working!
Not just working, but super smooth and crisp with no distortion.
Well, except for the wrong pitch due to a very cheap method of sampling
rate conversion. However, that's an aesthetic problem for the future.

🎉 Celebrate? 🎉
2017-12-16 22:51:40 -06:00
Ernest Wong c43a21ad1b Add reminder todo for sb16 set transfer size. 2017-12-16 22:51:40 -06:00
Ernest Wong d0d96497f6 Changed sb16 dma block size. Investigate effect.
After "fixing" the dma address incrementation, the sounds are now
highly distorted with seemingly garbage signal. The dma block size is
increased to investigate this newly formed bug.
2017-12-16 22:51:40 -06:00
Ernest Wong 42c5ddc1bd Fix: whitespace 2017-12-16 22:51:40 -06:00
Ernest Wong 8d75fd1555 Separate speaker process samples and dma block size
That way, speaker process samples can be large to reduce the clicking
noises, while at the same time the dma block size can be small to
improve counter accuracy.
2017-12-16 22:51:40 -06:00
Ernest Wong 061b1657d9 Update use of irq_triggered register (sb16) 2017-12-16 22:51:40 -06:00
Ernest Wong a4fdf027dd Fix: remove auto semicolon insertion bug 2017-12-16 22:51:40 -06:00
Ernest Wong f1b0c99240 Improve code clarity. 2017-12-16 22:51:40 -06:00
Ernest Wong 6b653cfdea Make sure enough audio is transferred each time
Fix: forgot to double the sample count to get the dac size needed.
Increased DMA_BLOCK_SAMPLES to reduce distortion caused by some lag in
the scriptprocessornode
2017-12-16 22:51:40 -06:00
Ernest Wong ac21d725a1 Always overwrite audio proccess buffer (sb16) 2017-12-16 22:51:40 -06:00
Ernest Wong cb704b9563 Implement state restoration for sb16 and new dma 2017-12-16 22:51:40 -06:00
Ernest Wong 34d60d42bc Add debug logs when not enough audio (sb16) 2017-12-16 22:51:40 -06:00