Oric's 8912 volume scale

Probably the most technical forum around. It does not have to be coding related, or assembly code only. Just talk about how you can use the AY chip to do cool sounding things :)
User avatar
meynaf
1st Star Corporal
Posts: 14
Joined: Mon Jul 18, 2016 6:37 pm
Location: Lyon (France)
Contact:

Re: Oric's 8912 volume scale

Post by meynaf »

The links he gives at the very end of the video are also useful.
Next time someone pretends the oric (or whatever ym emulation program) plays the ST tunes identical i'll send him to sndhrecord.atari.org for a comparison :p

Btw. Does someone know if there is a site with oric tune recordings ? Having a good reference is always useful !
Godzil
Squad Leader
Posts: 774
Joined: Sat May 21, 2011 7:21 pm
Location: Between UK and France
Contact:

Re: Oric's 8912 volume scale

Post by Godzil »

Dbug wrote:On the topic, there's some interesting details about sound on Gunstick's presentation: https://www.youtube.com/watch?v=yLDtiTS4JLg
Around the 34th minute there are some Audacity sample output of the three channels, and discussion of the shape on emulators vs real machine.
I have a friend that could explain why emulation need some clever math for giving the correct sound, I haven't seen this video yet, I can ask him to make a simple text to explain why if some of you are interested!
User avatar
meynaf
1st Star Corporal
Posts: 14
Joined: Mon Jul 18, 2016 6:37 pm
Location: Lyon (France)
Contact:

Re: Oric's 8912 volume scale

Post by meynaf »

Godzil wrote: I have a friend that could explain why emulation need some clever math for giving the correct sound, I haven't seen this video yet, I can ask him to make a simple text to explain why if some of you are interested!
I already know why emulation needs some clever math. What i don't know is what this clever math can be. If you friend knows, he's more than welcome to explain !
ThomH
Flying Officer
Posts: 238
Joined: Thu Oct 13, 2016 9:55 pm

Re: Oric's 8912 volume scale

Post by ThomH »

meynaf wrote:
Godzil wrote: I have a friend that could explain why emulation need some clever math for giving the correct sound, I haven't seen this video yet, I can ask him to make a simple text to explain why if some of you are interested!
I already know why emulation needs some clever math. What i don't know is what this clever math can be. If you friend knows, he's more than welcome to explain !
I'm probably far too late and/or answering the wrong question, and I'm learning this stuff almost as I type, but as far as I can make out there are two segments of maths involved:
  • voltage decay;
  • resampling.
Despite it being about a different chip, the simplest explanation of voltage decay that I could quickly find is under "the imperfect SN76489" here (at least, prior to about a minute ago; it's gone HTTP 503 while I was writing this post but I'm sure it'll be back later; Google has it cached), specifically:
Wherever a voltage (output) is artificially held away from zero, there will be leakage and the actual output will decay towards zero at a rate proportional to the offset from zero:
dV
-- = -kV
dt
where k is a constant.
The diagrams there are artificial but note how they match the measured waves given in the Youtube video linked earlier. So output voltage is a differential equation, a function of voltage and time since the voltage was set. The AY will hit the voltage it is supposed to, then decay until the next conscious change.

Rampling is much more trite — see any of the windowing techniques, e.g. as per here. It's also not something the original hardware does, it's just how you squeeze what the original hardware does out of your speaker. So there's more leeway.
User avatar
Chema
Game master
Posts: 3013
Joined: Tue Jan 17, 2006 10:55 am
Location: Gijón, SPAIN
Contact:

Re: Oric's 8912 volume scale

Post by Chema »

Dbug wrote: Wed Jul 20, 2016 9:43 am We are using different routines for the different demos:
- The "Welcome" in "Just Oric" is a 8bit sample replayed using three channels and Atari ST Replay log conversion tables
- The "DTS" and "20st Century Fox" in Quintessential are 4 bit samples replayed one one channel, with values very naively converted from the 8bit source. It sounds like hell on my machine as well :D
- The final sample over the flickering scroll text in Quintessential is Twilighte's routine that uses the VIA shift register, it works on some machines (my Pravetz) not on some other (my Atmos)
- The sample in Oric Tech is a variant of the DTS/20st Century, using a better 4bit conversion, but it's essentially the same code (that being said, may be the VIA selection code was tweaked, can't remember)

To summarize, what can impact the replay is:
- Using the shift register on the VIA
- Having a sound-chip with linear volume tables instead of logarithmic
Quintessential DTS and 20th effects sound like noise in my Atmos and I hear nothing over the final scrolling text, but OricTech sounds perfectly.

Sorry to up this old thread, but I'd be very interested in sorting this issue... I am curious...
User avatar
NekoNoNiaow
Flight Lieutenant
Posts: 272
Joined: Sun Jan 15, 2006 10:08 pm
Location: Montreal, Canadia

Re: Oric's 8912 volume scale

Post by NekoNoNiaow »

Hey Meynaf, funny to see you outside of the EAB.
Are you by chance writing an Oric emulator for ECS Amigas? ;)
meynaf wrote: Tue Jul 19, 2016 8:04 pm
Godzil wrote: The formula is (V1 + V2 + V3) / Number_Of_Source so here:

(1+0+0)/3 = 0.33333V
So in fact it's the same, but divided by 3 ?
But then, it's like if a single channel can't output more than 0.33V by itself.

The theory seems to say the waveforms should just get added together (averaged if you prefer), yet the sound that's heard in reality suggests otherwise...
You can mix audio sources in two ways : serial or parallel. With serial mixing, the sources are added to one another, and with parallel mixing they are averaged together.

The problem with parallel mixing is that all three outputs share a common ground line, so essentially, when one output sets itself to 0V, it drags the others to the ground as well and the chip has to fight to keep voltage up for the output lines which want to be at 1V. (Which you mentioned in one of your first posts.) The chip is technically trying to output 1V on one of its pin, but that same pin is driven to ground by two other pins at the same time so inevitably it has to give.

Serial mixing is possible and would avoid this issue but it would require the sound chip to dedicate a different ground line for each of the chip audio outputs. This comes with its own set of issues so parallel mixing is preferred as it is simpler and just works.
User avatar
jbperin
Flight Lieutenant
Posts: 480
Joined: Wed Nov 06, 2019 11:00 am
Location: Valence, France

Re: Oric's 8912 volume scale

Post by jbperin »

iss wrote: Thu Jul 21, 2016 9:11 am osc.jpg
Oric-amp.jpg
Incredible !! you are able to visualize the signal that is outputed :shock:
That's so much valuable !!

iss wrote: Thu Jul 21, 2016 1:56 pm Additionally kind of info about math interpolation (in Czech language) can be found here and here.
I arrive too late .. they are now dead links :-(
User avatar
jbperin
Flight Lieutenant
Posts: 480
Joined: Wed Nov 06, 2019 11:00 am
Location: Valence, France

Re: Oric's 8912 volume scale

Post by jbperin »

meynaf wrote: Thu Jul 28, 2016 8:14 am
First, the formula you gave was : (V1 + V2 + V3) / 3.
But the actual measured levels on an Oric (as given earlier in this thread : 0.917, 1.30, 1.58) rather suggest it is : SQR (V1² + V2² + V3²).
I agree with you, measurements provided by Iss shows that the voltage is not an affine function of the sum of all three channel level and just like you I'm surprised.
It is as though voltage were something like:

Code: Select all

V = 0.5 * SQRT (0.22 * (A + B + C))
Where A, B, and C are values set in amplitude control registers R10, R11 and R12
If I guess well, with the code of Iss, R10, R11 and R12 should be set to 0xF (15)
When only one channel is active, A+B+C = 15
and 0.5 * SQRT (0.22 * (15)) gives 0.9 (not far from 0.917)
When two channels are active, A+B = 30
and 0.5 * SQRT (0.22 * (30)) gives 1.28 (not far from 1.3)
When three channels are active, A+B+C = 45
and 0.5 * SQRT (0.22 * (45)) gives 1.57 (not far from 1.58)
User avatar
jbperin
Flight Lieutenant
Posts: 480
Joined: Wed Nov 06, 2019 11:00 am
Location: Valence, France

Re: Oric's 8912 volume scale

Post by jbperin »

When I run the code from Iss in Oricutron and that I record the output of Oricutron with audacity, I get a different result from what Iss measures on its real Oric.
Basic_3Channels.PNG
So I think that emulator doesn't behave exactly as the real Oric do for what is about 8912's output.

I analysed the pictures that Iss provided and I think I know how to explain the shape of the signal.
For the 2 channels signal, I can see 2 signals with opposed phase.
Analysis2Channels_2.png
And the 3 channels capture can be analysed the same way
Analysis3Channels_2.png
However .. the difference of phase between channels seems not to be always the same.
The 2 captures that Iss shows for 3 channels do not have exactly the same shape.
User avatar
jbperin
Flight Lieutenant
Posts: 480
Joined: Wed Nov 06, 2019 11:00 am
Location: Valence, France

Re: Oric's 8912 volume scale

Post by jbperin »

I wrote a little program to generate a triange signal on one channel. And I could test the compensation of the log stuff.
On the picture below I recorded with audacity the signal generated by my little code with and without compensation.
OneChannelTriangleCompensation.png
The top signal (uncompensated) is very similar to the one that appears in the documentation of the PSG when a triangle envelop is selected (see figure below).
The compensated signal (shown in the bottom part) is not very "straight" .. but it is more linear than the uncompensated one.
PSG_extract.PNG
User avatar
Dbug
Site Admin
Posts: 4437
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: Oric's 8912 volume scale

Post by Dbug »

The simplest is to look at the source code:
https://github.com/pete-gordon/oricutro ... ter/8912.c

The volume table is line 61:

Code: Select all

Sint32 voltab[] = { 0, 513/4, 828/4, 1239/4, 1923/4, 3238/4, 4926/4, 9110/4, 10344/4, 17876/4, 24682/4, 30442/4, 38844/4, 47270/4, 56402/4, 65535/4}
The mixer itself is a loop that compute the output of each channel by testing the tone and noise, multiplied by the volume (lines 246 to 257)

Code: Select all

  // "Output" accumulates the audio data from all sources
  output = soundsilence;

  // Loop through the channels
  for( i=0; i<3; i++ )
  {
    // Yep, calculate the squarewave signal...
    if( ay->newout & (1<<i) )
      ay->out[i] = ((ay->tonebit[i]|ay->sign[i])&(ay->noisebit[i]|ay->currnoise)) * ay->vol[i];

    // Mix in the output of this channel
    output += ay->out[i];
  }
This is code that basically what is done at the hardware level description, but there are no attempts at correcting to compensate for electronic loss, voltage/ground signal contamination, time it takes to reach a particular volume, etc... basically the code computes a perfect square, which is totally fine since the actual behavior of the chip on the Oric had not been measured, and for that you need to consider the AY chip but also the LM amplifier, because ultimately that impacts the way the sound behave.

EDIT: To add to what I wrote, there are plenty of forum threads, for the MSX, Spectrum, Amstrad, where we can learn many things, and one of these messages confirm what I wrote above: https://forums.nesdev.com/viewtopic.php?f=23&t=18639
Finally, the last issue is that every last AY-3-8910 implementation has different logarithm values.
In my experience with the 5B, the output does seem to match the logarithmic curve described by the datasheet, but then followed by its own internal amplifier which has an unfortunate nonlinear curve. I was investigating that in this thread, though the 5B's amplifier is unique and unrelated to the underlying AY/YM component, AFAIK.

So... on another system hosting an AY/YM you might be dealing with a second amplifier that messes with the curve, which could account for people wanting to tweak the values like that.
If we provide measures, we need to provided them both at the output of the YM, but also at the outputs of the internal amplifier chip, and check if the distortion is the same at the speaker level or on the DIN output socket, to see if the curve impact is identical or not.
User avatar
jbperin
Flight Lieutenant
Posts: 480
Joined: Wed Nov 06, 2019 11:00 am
Location: Valence, France

Re: Oric's 8912 volume scale

Post by jbperin »

Dbug wrote: Sat Apr 24, 2021 8:45 pm The actual behavior of the chip on the Oric had not been measured, and for that you need to consider the AY chip but also the LM amplifier, because ultimately that impacts the way the sound behave.
I am preparing a program that generates various ramp signal in order to have them measured by Iss. The goal is to find a model of how much current run through resistor R2, R3 and R4 depending on values programmed in register 10, 11 and 12 of the AY.
User avatar
Dbug
Site Admin
Posts: 4437
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: Oric's 8912 volume scale

Post by Dbug »

jbperin wrote: Sun Apr 25, 2021 12:12 am
Dbug wrote: Sat Apr 24, 2021 8:45 pm The actual behavior of the chip on the Oric had not been measured, and for that you need to consider the AY chip but also the LM amplifier, because ultimately that impacts the way the sound behave.
I am preparing a program that generates various ramp signal in order to have them measured by Iss. The goal is to find a model of how much current run through resistor R2, R3 and R4 depending on values programmed in register 10, 11 and 12 of the AY.
I don't think that would cover all the artifacts: In theory, what we have is a square signal, but in practice the level in electric signals take time to normalize, and that often depends on how much difference there was between the two values, so you may want to test for multiple things:
- How does it look when going through the same series of values but at different rates (from very slow to very fast)
- How does it look when going from low to high and high to low (overshoot and undershoot)
- How does it look when going from close values to far away values
- Do value changes done on one channel affect reads on the other channels
and probably other things :)

Another thing worth checking, is if the AY in the Oric has a 16 or 32 values volume table when using enveloppes (documentation seems to imply that this would be 32 internal values on the YM-2149 and only 16 on the AY-891x)
User avatar
jbperin
Flight Lieutenant
Posts: 480
Joined: Wed Nov 06, 2019 11:00 am
Location: Valence, France

Re: Oric's 8912 volume scale

Post by jbperin »

iss wrote: Thu Jul 21, 2016 9:11 am - Channel A = max 0.917V
- Channel A+B = max 1.30V
- Channel A+B+C = max 1.58V
Values are produced using this Basic code:

Code: Select all

10 MUSIC 1,3,6,15
20 MUSIC 2,3,6,15 <- comment to disable chan.B
30 MUSIC 3,3,6,15 <- comment to disable chan.C
40 PLAY 7,0,15,0
I think I know why you measure 1.58V but I'm not sure so .. if someone can check .. it would be cool.

I started by calculating the impedance formed by R2, R3 and R4 resistor network.
Impedance.jpg
I found that it is equivalent to a 838 Ohms resistor.

Then, since I = U / R , I deduced that the current running through this impedance was:

Code: Select all

I = 1.58 V / 838 Ohms  = 2 mA
And it turns out that this value (2mA = 2000µA) corresponds to the one that is specified in the AY-3-891x datasheet at the Analogs Channel Outputs section here below (as the maximum output current):
MaxCurrent.png
Nothing is said in the datasheet about how channels level contribute to the total output current. So I find it is difficult to figure out how the signal is going to be depending on values set in R10, R11 and R12 (amp control) registers.

For example, I still don't know where the 0.917 V and 1.30 V measured voltage come from. I only have assumptions about it.
If anyone have a clue .. I would love to know it.

I want to identify the function F that gives the current running through the impedance made by resistors R2, R3 and R4 depending on values set in amplitude control registers R10, R11 and R12.

Code: Select all

I = F (R10, R11, R12)
If anyone has an idea, I'm highly interested.

From various source code I read about playing samples, I find that most people consider that:

Code: Select all

I = f(unlog(R10) + unlog(R11) + unlog(R12)) 
with:
- f(x) being of the shape ax + b
- unlog(x) being the inverse log (something like

Code: Select all

15-log2(x²)
)

But measurements shown by iss tends to show that f(x) is not linear
Because in the code that was ran for the measurement:

Code: Select all

10 MUSIC 1,3,6,15
20 MUSIC 2,3,6,15 <- comment to disable chan.B
30 MUSIC 3,3,6,15 <- comment to disable chan.C
All three channels are at level 15 (maximum level)
When all three are simultaneously at top level, the output voltage reach 1.58 V
If the f(x) was linear:
- we would have 2/3 of 1.58 V when only 2 channels are active
- we would have 1/3 of 1.58 V when only 1 channel is active

But it's not the case.

So, from my point of view, all tables currently used to play samples on more than one channel are inaccurate because they do not integrate the non linearity of the channel mixing function.
User avatar
jbperin
Flight Lieutenant
Posts: 480
Joined: Wed Nov 06, 2019 11:00 am
Location: Valence, France

Re: Oric's 8912 volume scale

Post by jbperin »

My idea on how we could identify how channel mixing operates is to study the output voltage when a ramp signal is played on two channels : A and B
and that the ramp is generated with two different approaches.

One approach where channel's contribution are well balanced.
One approach where channel's contribution are unbalanced.

The figure below illustrates the strategy I suggest .
StrategyToUncorrelateContributions.png
This figure comes from plotting the surface :

Code: Select all

F(X,Y) = 127 * ( 2**((15-X)/2) + 2**((15-Y)/2) )
which is basically the linear sum of two uncompensated channels.

The idea is to make the ramp signal go from 0 to 127 through 2 different paths . (i.e 2 different contribution balancing approach)

My expectation is that the difference between the two measured signals for the "same'" ramp should help us to understand how the electronic renders the signal composed on two channels.
Post Reply