|Re: [hatari-devel] Cracks in the sound (YM+DMA)|
[ Thread Index |
| More lists.tuxfamily.org/hatari-devel Archives
On Saturday 16 March 2013 16:33, Nicolas Pomarède wrote:
> On 03/03/2013 15:23, Nicolas Pomarède wrote:
> > On 03/03/2013 05:41, David Savinkoff wrote:
> >> Hi Nicolas,
> >> This patch has sound clipping for LMC1992 saturation distortion
> >> (same code as before for expedience, change it to your liking).
> >> See hunk at line 642 (dmaSnd.c).
> >> This patch also fixes the sound overflow when DMA samples and
> >> YM2149 are summed on the STe.
> >> See all other hunks.
> >> The sound overflow fix incurs no performance penalty because
> >> the YM2149 volume table is scaled by 1/2 in sound.c for the
> >> STe; and the LMC1992 gain is doubled in dmaSnd.c to compensate
> >> afterwards. DMA sound samples are scaled and summed
> >> with 1/2 attenuated YM2149 to avoid overflow. DC filtering
> >> removes the large dc offset before the gain is scaled up by 2.
> >> David
> > Hi
> > that's great, thanks for the patch ; I will check it later to head the
> > difference.
> > Nicolas
> I applied the patch ; sound seems ok, but despite the comments you added
> in the source about doubling gain to compensate for halving dma, volume
> is much lower than before.
> For example, try the demo Music Dream II by Phenomena
> http://pouet.net/prod.php?which=3418 ; it's dma sound only and volume is
> lower with your latest patch (try to restore a memory snapshot of music
> dream II with 2 versions of Hatari with/without patch to quickly hear
> the difference)
> Is this expected ?
This patch works well, but is incompatible with older snapshots.
Hatari plays DMA sound at the same level as before (unless you
use an old snapshot). New snapshots made with the newly patched
version will work properly with the newly patched version.
The problem is with using an old memory snapshot as the old gain
is used (in your case: 1.0/(65536.0*65536.0) ) which makes the
gain half as much as required.
If you did the snapshot with the patched version (the other way
around), you would get double the volume: 2.0/(65536.0*65536.0)
As can be seen in the preliminary observations, the patch was
Note that DmaSnd_Init_Bass_and_Treble_Tables() can be executed
after all MemorySnapShot are restored, thus, overwriting the
erroneous gain from old snapshots. If this were done then
would not be necessary. (see dmaSnd.c)
**** preliminary observations ****
The problem you mention is not expected, and I cannot see how this
patch causes this problem. I also cannot download the demo.
I expect the demo should play at the same volume with this patch as
it would without.
Both YM2149 and DMA levels are each divided by 2, then added, then
multiplied by 2.
Here are some possibilities that I can imagine:
1) There always was a problem that needs resolving, and you finally
(edit: not the case)
2) Somehow, my patch doesn't do what is expected, and I could be
assisted. I do not see how not applying the patch is better.
(edit: patch is good, but incompatible with older snapshots)
3) Maybe you could double check your results. Note that the loudness
change that you mention would not be subtle as it would be -6 dB.
(edit: not required)
Note that my patch assumes that All YM2149 and All DMA sound (which
is assumed to be All possible sound on the STe) is routed through
DmaSnd_GenerateSamples() and DmaSnd_Apply_LMC() in dmaSnd.c
In the patch:
# -((256*3/4)/4)/4 is used to half the volume (to avoid overflow)
# (2.0/(65536.0*65536.0)) is used to double the volume afterwards.
**** end of preliminary observations ****