VGM playback library for Common Lisp
修訂 | 6cc221fe7d63ae26dadcbc00cb86cc8ace1693bd (tree) |
---|---|
時間 | 2023-08-19 22:51:14 |
作者 | Remilia Scarlet <remilia@post...> |
Commiter | Remilia Scarlet |
Change fill-buffers so that it matches YunoSynth's behavior
@@ -582,8 +582,11 @@ | ||
582 | 582 | #-satou-wd40 (safety 1))) |
583 | 583 | |
584 | 584 | (let ((cur-volume (truncate (%player-output-volume player))) |
585 | - (buf (%player-temp-buf player))) | |
586 | - (declare (type fixnum cur-volume)) | |
585 | + (buf (%player-temp-buf player)) | |
586 | + (out-l 0) | |
587 | + (out-r 0)) | |
588 | + (declare (type fixnum cur-volume) | |
589 | + (type t/int32 out-l out-r)) | |
587 | 590 | |
588 | 591 | #-satou-wd40 (unless (= (length left) (length right)) |
589 | 592 | (error "Buffer size mismatch")) |
@@ -594,14 +597,20 @@ | ||
594 | 597 | (%player-interpret-file player 1) |
595 | 598 | (resampler-resample (%player-resampler player) (%player-chip-table player) buf 1) |
596 | 599 | |
597 | - ;; Adjust the volume. | |
598 | - (setf (sample-left buf) (ash (coerce-to-int32 (* (ash (sample-left buf) -5) cur-volume)) -11)) | |
599 | - (setf (sample-right buf) (ash (coerce-to-int32 (* (ash (sample-right buf) -5) cur-volume)) -11)) | |
600 | + ;; Adjust the volume for the output | |
601 | + (setf out-l (sdm:clamp (* (sample-left buf) cur-volume) #.(- (expt 2 31)) #.(1- (expt 2 31)))) | |
602 | + (setf out-r (sdm:clamp (* (sample-right buf) cur-volume) #.(- (expt 2 31)) #.(1- (expt 2 31)))) | |
600 | 603 | |
601 | 604 | ;; Store the new sample |
602 | 605 | (muffling |
603 | - (setf (aref left sample-num) (* (%player-clamp-int32-to-int16 (sample-left buf)) +inv-int-16+)) | |
604 | - (setf (aref right sample-num) (* (%player-clamp-int32-to-int16 (sample-right buf)) +inv-int-16+))))) | |
606 | + (setf (aref left sample-num) (* out-l #.(/ 1.0 (1- (expt 2 31))))) | |
607 | + (setf (aref right sample-num) (* out-r #.(/ 1.0 (1- (expt 2 31)))))) | |
608 | + ;; (* (%player-clamp-int32-to-int16 (sample-left buf)) +inv-int-16+)) | |
609 | + ;;(setf (aref right sample-num) out-r)) ;; (* (%player-clamp-int32-to-int16 (sample-right buf)) +inv-int-16+))) | |
610 | + | |
611 | + ;; Still needs to be adjusted for the resampler | |
612 | + (setf (sample-left buf) (ash (coerce-to-int32 (* (ash (sample-left buf) -5) cur-volume)) -11)) | |
613 | + (setf (sample-right buf) (ash (coerce-to-int32 (* (ash (sample-right buf) -5) cur-volume)) -11)))) | |
605 | 614 | nil) |
606 | 615 | |
607 | 616 | (define-typed-fn %player-reset-chips ((vgm-player player)) |