Digital audio boosting examples

Basic and Machine Language

Moderator: Moderators

User avatar
pixel
Vic 20 Scientist
Posts: 1342
Joined: Fri Feb 28, 2014 3:56 am
Website: http://hugbox.org/
Location: Berlin, Germany
Occupation: Pan–galactic shaman

Re: Digital audio boosting examples

Post by pixel »

Boray wrote:Does this sound as good as only using the volume register, but just louder? Have you tried sampling the output and looked at the waveform?
No idea. Got no real machine to check that out. Could you grab http://hugbox.org/pixel/external/denial/boost.prg and try it yourself? I'd love to know either. :)

The VIC distorts everything starting with volume 8, so chances are that it's not as good.
A man without talent or ambition is most easily pleased. Others set his path and he is content.
https://github.com/SvenMichaelKlose
Boray
Musical Smurf
Posts: 4064
Joined: Mon May 03, 2004 10:47 am

Re: Digital audio boosting examples

Post by Boray »

I guess "0" is just the volume register?

If you fix the program to eliminate contact bounces of the joystick button then I can record it from my Vic for you.

Anyway, this doesn't sound like VICE. The only number that's a little louder than 0 is 4, but sometimes it gives a high pitched tone as well.
PRG Starter - a VICE helper / Vic Software (Boray Gammon, SD2IEC music player, Vic Disk Menu, Tribbles, Mega Omega, How Many 8K etc.)
User avatar
pixel
Vic 20 Scientist
Posts: 1342
Joined: Fri Feb 28, 2014 3:56 am
Website: http://hugbox.org/
Location: Berlin, Germany
Occupation: Pan–galactic shaman

Re: Digital audio boosting examples

Post by pixel »

Boray wrote:I guess "0" is just the volume register?
Yep!
Boray wrote:If you fix the program to eliminate contact bounces of the joystick button then I can record it from my Vic for you.
Will do right after dinner. Thanks!
Boray wrote:Anyway, this doesn't sound like VICE. The only number that's a little louder than 0 is 4, but sometimes it gives a high pitched tone as well.
Odd, unexpected and really disappointing. :(
A man without talent or ambition is most easily pleased. Others set his path and he is content.
https://github.com/SvenMichaelKlose
User avatar
Mike
Herr VC
Posts: 4831
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Digital audio boosting examples

Post by Mike »

Actually, not quite unexpected. I gave it some thought about this morning.

I think the generators work as timers: given the low 7 bits of the sound register as latch value, they count up until they reach 127, where they clock out the next bit from the shift register (or 0 if the EN bit is clear) and re-load the counter from the latch value. That also explains why 255=128(EN=1)+127 is actually the lowest note: after re-load, the counter immediately wraps to 0 with the next count and so needs 128 steps to reach 127.

Now, the $900C generator increments that internal counter every 4 cycles, and $900B does so every 8 cycles. Only then they might recognize a change in their latch register, when the internal counter is reloaded. While $900C follows the change within 1..4 cycles after the store, $900B might only do so within 1..8 cycles. :evil:

Especially, when those counters are synchronised, $900B will see the change either synchronous to $900C, or 4 cycles later - which means those spikes, if they appear, are 4 µs long. With a 50% chance for each outcome.
User avatar
Mike
Herr VC
Posts: 4831
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Digital audio boosting examples

Post by Mike »

Even with a fairly recent version of VICE, I could reproduce that behaviour with a small test program (download).

There either is silence (with a silent sample, volume set at 15), or a very faint 8 kHz tone with some subharmonics supposedly caused by aliasing in the PC's audio hardware. But it is not as pronounced as with pixel's example.

I will use this program tomorrow to make some scope pics:

Code: Select all

1 FORT=673TO705:READA:POKET,A:NEXT:S=36875
2 DATA 120,238,14,144,162,11,202,208,253,234,234,76,162,2,120,169,253,141,12,144,162,11
3 DATA 202,208,253,234,169,254,141,11,144,88,96
4 :
5 POKES,126:POKES+1,126:POKES+2,15:SYS687
6 SYS673
Line 5 enables the digi boost, and line 6 starts a ~1 kHz sawtooth waveform. By commenting out either of these two lines, I can check their function independently. It's also a good opportunity to check the linearity of the volume register. :)

Here's the code listing:

Code: Select all

.02A1  78        SEI
.02A2  EE 0E 90  INC $900E
.02A5  A2 0B     LDX #$0B
.02A7  CA        DEX
.02A8  D0 FD     BNE $02A7
.02AA  EA        NOP
.02AB  EA        NOP
.02AC  4C A2 02  JMP $02A2
.02AF  78        SEI
.02B0  A9 FD     LDA #$FD
.02B2  8D 0C 90  STA $900C
.02B5  A2 0B     LDX #$0B
.02B7  CA        DEX
.02B8  D0 FD     BNE $02B7
.02BA  EA        NOP
.02BB  A9 FE     LDA #$FE
.02BD  8D 0B 90  STA $900B
.02C0  58        CLI
.02C1  60        RTS
Cheers,

Michael
User avatar
pixel
Vic 20 Scientist
Posts: 1342
Joined: Fri Feb 28, 2014 3:56 am
Website: http://hugbox.org/
Location: Berlin, Germany
Occupation: Pan–galactic shaman

Re: Digital audio boosting examples

Post by pixel »

VICE seems to confirm the 4-cycles off theory, because when I cycled around boost.prg it was a matter of chance if the high pitched noise appeared. That the amplification doesn't work out on real VICs makes me grumpy, dampening my motivation to further investigate. Maybe it's that dinner I didn't get. Will debounce the demo tomorrow. However, got a sleeping place including breakfast in London as expensive as the two underground train tickets one needs to get there and get away again (off-topic payback ;)).

How many cycles do those NTSC and PAL frames have again? Maybe that's a chance to synchronize, assuming that most people reset their VIC before starting a program…

Or if that won't calculate, perhaps them noisy waveforms can bring on some boost at lower frequencies?
A man without talent or ambition is most easily pleased. Others set his path and he is content.
https://github.com/SvenMichaelKlose
User avatar
Mike
Herr VC
Posts: 4831
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Digital audio boosting examples

Post by Mike »

The amplification effect *is* there, but I would judge it at around 3 .. 6 dB (i.e. 1 1/2 .. 2 times the amplitude). More could not be expected - more quantified results tomorrow. :)
pixel wrote:How many cycles do those NTSC and PAL frames have again? Maybe that's a chance to synchronize, assuming that most people reset their VIC before starting a program…
That would require a frame cycle count divisible by 8, as there's no way to count the frames since last power on - VIC isn't connected to the reset line, so it wouldn't care anyway.

PAL has 312 lines, those are already divisible by 8, so is the frame cycle count. But NTSC doesn't do us the favour: 65 Cycles/line x 261 lines = 16965 Cycles. Two odd factors for sure can't make a multiple of 8. :(
User avatar
pixel
Vic 20 Scientist
Posts: 1342
Joined: Fri Feb 28, 2014 3:56 am
Website: http://hugbox.org/
Location: Berlin, Germany
Occupation: Pan–galactic shaman

Re: Digital audio boosting examples

Post by pixel »

please also try booster nr. 1 at lower frequencies!
A man without talent or ambition is most easily pleased. Others set his path and he is content.
https://github.com/SvenMichaelKlose
User avatar
Mike
Herr VC
Posts: 4831
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Digital audio boosting examples

Post by Mike »

So. Here are the scope readouts as *.zip archive (download). Done on a Hameg HM1508 CombiScope, and beautifully photographed with my Digicam. :lol:

Anyhow, here are the results in plain English:

* Shot 1 shows the low-pass filtered 1 kHz sawtooth waveform. The 1.6 kHz low-pass makes a good job 'hiding' the 16 voltage levels. I didn't put the lower cursor at some 'imagined' lowest voltage where the negative edge 'crosses' the continuation of the sawtooth slope, rather I chose the minimum of the curve as visible: U = 0.930 Vpp

* Shot 2 shows the boosted sawtooth. Same measurement method => U = 1.21 Vpp. This means an amplification by 1.30, so that's just around 2 dB. Clearly not worth the trouble, but hey, it was worth a try. :)

* Shot 3 show the sawtooth with distorted boost. At ~40 mVpp the distortion produces an 'error' that's even less than the quantisation error of (1.2 V)/(15 steps) = 80 mV/step. Put on audio, you don't hear the distortion. Even with a 'silent' sample, the bus noise is louder.

* Shots 4 and 5 show pixel's Saxophone Jam example, unboosted and boosted with #4: 1.57 Vpp vs. 1.26 Vpp. An amplification of 1.25, again around 2 dB.

Sometimes that 8 kHz tone was clearly audible with Boost #4, *much* more pronounced than with my boost routine - at roughly 300 mVpp! I suppose there must still be some programming error. Maybe an interrupt (IRQ or NMI) of the sample routine firing during the delay loop between the writes to $900C and $900B?

Cheers,

Michael
User avatar
pixel
Vic 20 Scientist
Posts: 1342
Joined: Fri Feb 28, 2014 3:56 am
Website: http://hugbox.org/
Location: Berlin, Germany
Occupation: Pan–galactic shaman

Re: Digital audio boosting examples

Post by pixel »

Mike wrote: * Shot 2 shows the boosted sawtooth. Same measurement method => U = 1.21 Vpp. This means an amplification by 1.30, so that's just around 2 dB. Clearly not worth the trouble, but hey, it was worth a try. :)
I'm in Halloween character… :[ But thanks a million for the measurements!
Mike wrote: * Shot 3 show the sawtooth with distorted boost. At ~40 mVpp the distortion produces an 'error' that's even less than the quantisation error of (1.2 V)/(15 steps) = 80 mV/step. Put on audio, you don't hear the distortion. Even with a 'silent' sample, the bus noise is louder.
So that's the way to go?
Mike wrote: * Shots 4 and 5 show pixel's Saxophone Jam example, unboosted and boosted with #4: 1.57 Vpp vs. 1.26 Vpp. An amplification of 1.25, again around 2 dB.
You're so wrong. It was a _concert_. The beginning of "Girl from Ipanema". :D

I wish the low amplification would make sense. :(
Mike wrote: Sometimes that 8 kHz tone was clearly audible with Boost #4, *much* more pronounced than with my boost routine - at roughly 300 mVpp! I suppose there must still be some programming error. Maybe an interrupt (IRQ or NMI) of the sample routine firing during the delay loop between the writes to $900C and $900B?
There's now an updated version with interrupts disabled and a delay to "unbounce" the joystick. And the new boosters are booster 1 with $fd-$fb written to $900c after setting the waveform. Just in case.
A man without talent or ambition is most easily pleased. Others set his path and he is content.
https://github.com/SvenMichaelKlose
User avatar
Mike
Herr VC
Posts: 4831
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Digital audio boosting examples

Post by Mike »

pixel wrote:So that's the way to go?
In principle, yes.
I wish the low amplification would make sense. :(
There is already a bias present, when all voices are turned off. Otherwise you wouldn't hear anything from changing the volume register alone. Putting out a permanent "1" over two voices just happens to increase that bias by 30%. rga24 also did some investigations here:

http://sleepingelephant.com/ipw-web/bul ... php?t=4956
User avatar
eslapion
ultimate expander
Posts: 5458
Joined: Fri Jun 23, 2006 7:50 pm
Location: Canada
Occupation: 8bit addict

Re: Digital audio boosting examples

Post by eslapion »

I have no clue if what I'm going to post here has any usefulness. If not, just disregard...

I noticed long ago the output of the VIC (chip) audio output is a form of open-collector output. When playing polyphonic, if you set the volume higher than 8 then the waveforms start clipping and the result is turning to junk as you raise the volume.

To me, this makes sense as internally, the audio out is probably the output of 4 digital buffers which each pull down through a resistor so its easy to mix by just putting a pull-up resistor on the outside

I tried setting the soprano voice (36876) to 254 to playing a ultrasonic sound and see what impact it has on a note playing on the tenor (36874) voice. As expected, all it does is artificially reduce the volume. The reason is simple; all the soprano voice does is introduce a DC offset into the current amplifier/RC filter built into the VIC-20's audio out.

Didn't try it on an emulator. I'm using a PET style keyboard VIC with NTSC timing.
Be normal.
User avatar
Mike
Herr VC
Posts: 4831
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Digital audio boosting examples

Post by Mike »

eslapion wrote:I noticed long ago the output of the VIC (chip) audio output is a form of open-collector output.
The data sheet explicitly states 'Composite Sound (Pin 19)' is a high impedance output with R_out ~= 1 kOhm, and needs to be buffered. It can't really be open-collector as there is no pull-up present on both common PCB revisions.

I would suspect the four bits of the volume register form part of a variable internal current source, the four bits of the sound generators form part of a variable current drain, and both sides playing 'tug of war' during operation. The FETs of the current drain have inverted inputs, so they conduct when the corresponding output of the generator is off.

The booster now takes two of those current drains and works by ensuring that one of them is always blocked.
User avatar
pixel
Vic 20 Scientist
Posts: 1342
Joined: Fri Feb 28, 2014 3:56 am
Website: http://hugbox.org/
Location: Berlin, Germany
Occupation: Pan–galactic shaman

Re: Digital audio boosting examples

Post by pixel »

Am glad we got it sorted out down to the metal. :D Didn't get tugged on the floor for too long, though. How about distorting two channels then? What would be the highest frequency that can make it through the capacitor or whatever is in the way?

And how would one fix VICE? The audio code is a thing of beauty. How much volume should be subtracted for each blocked channel? I guess the lowpass/highpass filter settings in there could be adjusted to get rid of the ear piercings?
A man without talent or ambition is most easily pleased. Others set his path and he is content.
https://github.com/SvenMichaelKlose
User avatar
Mike
Herr VC
Posts: 4831
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Digital audio boosting examples

Post by Mike »

I don't think there is any need to 'fix' the VICE sound engine, in regard to our experiments.

If you switch on "VIC Audio leak" in VICE you get audio output very much comparable to the original hardware, including bus noise (noticible changing hissing upon different CPU activities) and a 50/60 Hz hum from the video circuitry. Even when the two voices are misaligned by 4 µs, this leak effectively masks the 4 µs@8kHz spikes. There is no ear-piercing tone.
pixel wrote:What would be the highest frequency that can make it through the capacitor or whatever is in the way?
The audio low-pass consists of a capacitor-resistor-capacitor network. It has its lower transition frequency at 1.6 kHz. A sine wave at that frequency is already attenuated with 3 dB, and will only have 70% of the amplitude of a sine wave with much lower frequency. Between 1.6 kHz and 16 kHz, the attenuation increases to 20 dB, and from there with 40 dB/decade (due to the second capacitor). So there is no 'highest' frequency after which audio is blocked.
Last edited by Mike on Sun Nov 01, 2015 7:15 am, edited 1 time in total.
Post Reply