Page 1 of 1

2 eurocents question about AY-8912 possibilities

Posted: Sat Aug 04, 2007 1:17 am
by waskol
Do you think it would be technically possible to play the raw data of a wav file with a ay-8912 ???
Of course, I imagine that the main limitation is the sample rate frequency...

what do you think ?

Re: 2 eurocents question about AY-8912 possibilities

Posted: Sat Aug 04, 2007 5:10 am
by JamesD
waskol wrote:Do you think it would be technically possible to play the raw data of a wav file with a ay-8912 ???
Of course, I imagine that the main limitation is the sample rate frequency...

what do you think ?
Yes. It was common on the Atari ST.

Posted: Sat Aug 04, 2007 3:14 pm
by waskol
hmm, that is pretty interesting...
Therefore, I wonder if an Oric could play a wav file, or at least the raw data of a wav file...

I will try to see on the internet if I find something about how people realized it with an Atari ST :wink:

Posted: Sat Aug 04, 2007 3:41 pm
by waskol
hmmm, it seems that someone did it for spectrum :wink:
http://www.zxdemo.org/extra/src/samplepack-20070527.zip

the zip file contains nice piece of source code in order ti realize a wav player for a zx-spectrum (and for an Oric maybe ?) :P

Posted: Sat Aug 04, 2007 6:38 pm
by Dbug
Well, it's "trivial" to adapt to the Oric all the methods used on other AY/YM based machines.

I did my first 8 bit replay routine in 1997, for the "Oric Mega Demo" - mega only in the name -, making it replay the "Welcome" sample of the Barbarian 2 game "Welcome to the Dungeon of Drax: Please choose your warrior".

Performance wise, 8 bits is not very efficient, it's easier and way less CPU intensive to replay 4 bits samples. It also takes half the memory, since you can pack 2 samples on one byte.

The idea is just to play with the volume registers on the chanels. On one chanel you can get a value between 0 and 15 (0 to 1volt), and by using two or three chanels, you can get a larger value which increase the number of potential values and the volume (from 0 to 3 volts), giving a nearly 8 bit quality by using the cumulated 12 bits creatively.

I used the conversion tables from ST Replay, and they worked fine on the Oric as well.

Twilighte can provide good code for replaying samples. Mine is very crappy, I did that a very long time ago.

Posted: Thu Aug 09, 2007 7:17 pm
by Twilighte
Thanks Dbug, Pure WAV files from the PC contain about 16 or 32 bytes of header info, which is not so cool at the start of a sample when played on the Oric.

Their are several ways to play samples on the Oric, some are faster than others but remember, the faster the routine the more memory the sample may use.
I have written sample players from 200Hz up to 44Khz.
If you need a routine, let me know and i'll see if i can find time to find one.

Posted: Fri Aug 10, 2007 1:09 am
by waskol
The idea can be to remove the header and keep just the chunks (I mean, only the raw data, the wave form...).
For this we can assume a default sample rate, mono, 8 bits, and so forth :wink:

Posted: Wed Aug 22, 2007 7:35 am
by JamesD
I found some decent info on an MSX page.
It has info on playing 8 bit samples and there is supposedly even a link to a read wave program to test it out.
http://map.tni.nl/articles/psg_sample.php#8bitsamples

Posted: Sun Nov 04, 2007 10:35 pm
by waskol
OK, let'see it in this way :
How could it be possible to "translate" some raw datas of a wav file into Oric asm code ???

If we can sort out an algorithm, it might be possible :
- to compose on PC
- "Translate" the resulting wav file into oric asm (on the PC)
- compile with OSDK
- hear the result on Oric ;)

I am pretty sure it is possible, but my skills in asm and moreover of how to address the AY-8912 are, hummm... well :lol:

Posted: Sun Nov 04, 2007 11:31 pm
by Dbug
I packaged in a OSDK compliant the code of the "Welcome" from my Oric Mega Demo of 1997:

http://www.defence-force.org/ftp/forum/ ... lSound.zip

- welcome.s is a 8bit sample saved in raw/unsigned format
- digit.s is the replay code, including three 256 bytes tables used to convert the 8 bit sample to a single 4 bits value for each separate chanel.

(I'm using the old tables from the Atari ST ST-Replay software)

Posted: Mon Nov 05, 2007 12:51 am
by waskol
DBUG, I am afraid but... you are the best !!!!
It is really impressive.

This demo shows that it is possible to get anything out of the oric...
really impressive... (my jaw is still on the floor...)

Posted: Mon Nov 05, 2007 8:06 pm
by Dbug
waskol wrote:DBUG, I am afraid but... you are the best !!!!
It is really impressive.

This demo shows that it is possible to get anything out of the oric...
really impressive... (my jaw is still on the floor...)
Well, I only adapted what we did on the Atari ST (same sound chip).

And both Fabrice and Twilighte made sample sound, and there is this Rambo demo of the Tivoli Pirat as well, so please give the credits to other people :)

Posted: Tue Nov 06, 2007 10:32 am
by waskol
Dbug wrote:
waskol wrote:DBUG, I am afraid but... you are the best !!!!
It is really impressive.

This demo shows that it is possible to get anything out of the oric...
really impressive... (my jaw is still on the floor...)
Well, I only adapted what we did on the Atari ST (same sound chip).

And both Fabrice and Twilighte made sample sound, and there is this Rambo demo of the Tivoli Pirat as well, so please give the credits to other people :)
Well, a last technical question about this wonderfull "welcome".

what is the sample rate of this ?

For example, imagine that I want to digitalize a sound effect and play it back :
- First I convert my little wav file to an unsigned 8 bits (but at which sample rate ?)
- then I extract the raw data (it is just a question of removing the wav header, and convert the binaries to a text file)
- finally I compile with OSDK

thank you

Posted: Tue Nov 06, 2007 8:51 pm
by Dbug
Good question.
I think it's 8khz, but I'm not sure.

Thing is, this routine does not use any timer, it is just disabling the interruptions and try to send stuff to the soundchip as fast as possible.

You probably noticed the 7 "nop" instructions, it's to slow down the replay.

The faster the loop, the higher the frequency :)

If you use a sample at a different (lower) frequency, you can just change the number of nop, or use instructions that take more time, this way you can play longer samples.

Also you can probably optimise the code quite a lot :)

If you use one channel instead of 3, the sound quality is a lot worse, but then you can use 4 bit samples, meaning that you store twice as many sample data in the same number of bytes, and you speedup the code by a HUGE factor (not x3, a lot more) because you can remove almost all the VIA register switching. Just need to select the volume register and write values in here as fast as you can :) - the methid we used to replay the 20th century fox and Digital DTS jingles in the other demos -

Posted: Sat Feb 09, 2008 11:17 pm
by Twilighte
I wonder (Not tried it) what the effect on the sample would be if played alongside another channel setup with a high volume but not connected to tone generators?

I know (thru soundtracker) that when you play a sample in two channels it will sound more wholesome and louder.

Re:

Posted: Thu Apr 15, 2021 7:06 pm
by jbperin
Dbug wrote: Sun Nov 04, 2007 11:31 pm I packaged in a OSDK compliant the code of the "Welcome" from my Oric Mega Demo of 1997:

http://www.defence-force.org/ftp/forum/ ... lSound.zip
Thank you for sharing. It's a very interesting and instructive code snippet.
Dbug wrote: Sun Nov 04, 2007 11:31 pm (I'm using the old tables from the Atari ST ST-Replay software)
Have you ever tested the tables provided in the link by JamesD ?
http://map.tni.nl/articles/psg_sample.php#8bitsamples

They look better shaped than the ones provided in your DigitalSound
And I wonder if it could enhance the sound quality.

when i draw the function

Code: Select all

y = conv(tab1[x]) + conv(tab2[x]) + conv(tab3[x]) 
with 
conv(x) = 2^-((15-x)/2)
with msx replay tables, i get :
msx_replay.png
and with your atari replay tables, i get:
atari_replay.png
Dbug wrote: Tue Nov 06, 2007 8:51 pm You probably noticed the 7 "nop" instructions, it's to slow down the replay.
I also wonder if it could enhance the sound quality to spread the nop along the loop content, multiplexed with register writing rather then gather them at the end of the loop content.

What do you think ?

Re: 2 eurocents question about AY-8912 possibilities

Posted: Thu Apr 15, 2021 8:18 pm
by jbperin
I made a quick build of 4 various version of the sample player function.
DIGIT.tap
On oricutron I find the best sounding version is number 2

Which one do people prefer on real hardware ?

Re: 2 eurocents question about AY-8912 possibilities

Posted: Thu Apr 15, 2021 8:36 pm
by Dbug
jbperin wrote: Thu Apr 15, 2021 7:06 pm I also wonder if it could enhance the sound quality to spread the nop along the loop content, multiplexed with register writing rather then gather them at the end of the loop content.
What do you think ?
On msx they did exactly that, using some Viterbi encoding.
https://www.msx.org/forum/development/m ... s-poor-psg

Basically the idea is that on the Atari ST, it's so fast to change registers that basically you can consider that writing to channels A, B and C is almost happening at the same time, while on the Oric it's so slow, that ideally the values for A, B and C should take into consideration the temporal delay.

Re: 2 eurocents question about AY-8912 possibilities

Posted: Fri Apr 16, 2021 1:15 pm
by jbperin
Dbug wrote: Thu Apr 15, 2021 8:36 pm On msx they did exactly that, using some Viterbi encoding.
https://www.msx.org/forum/development/m ... s-poor-psg
That's truly fascinating ..

What an interesting approach !!

Do we have the same on Oric ?

Re: 2 eurocents question about AY-8912 possibilities

Posted: Fri Apr 16, 2021 2:29 pm
by Dbug
I had plans, but did not really act on it, so feel free to experiment :)

My idea was to find an encoding to basically generate a series to write on A, B, C, A, B, C, A, B, C, ... computing the best combination of values to write to generate a 8 bit quality sample by just changing the volume value, so basically 4 bit encoding, two values per byte, but high quality, but did not have the time.

Re: 2 eurocents question about AY-8912 possibilities

Posted: Fri Apr 16, 2021 5:01 pm
by jbperin
Dbug wrote: Fri Apr 16, 2021 2:29 pm feel free to experiment :)
You should not say things like that to someone who is struggling to find the courage to finish a game.
That is not kind of you.
Dbug wrote: Fri Apr 16, 2021 2:29 pm My idea was to find an encoding to basically generate a series to write on A, B, C, A, B, C, A, B, C, ... computing the best combination of values to write to generate a 8 bit quality sample by just changing the volume value, so basically 4 bit encoding, two values per byte, but high quality, but did not have the time.
Well, it sounds good .. but I wonder if there could be a more efficient approach by considering that we don't necessary have to cycle around A, B and C
Because, in the end, what's matter is the sum : conv(A)+conv(B)+conv(C) (with conv() being the reverse logarithmic scale thing)
The goal is to make this sum follows (as much as possible) the sampled signal.
It may happen that, for some reason, the best way to follow the signal is to only make one or two channel change rather than systematically update all three channels.

In such a perspective, the encoding would consist in finding a sequence of couple (channel, value) .
A, 2, B, 3, B, 4, B, 5, A, 3, etc .. ect ..

And the player loop would look like:

Code: Select all

#define VIA_1	$30f
#define VIA_2	$30c

#define LATCH_REG_NUMBER  sta VIA_1:lda #$EE:sta VIA_2:stx VIA_2
#define LATCH_REG_VALUE  sta VIA_1:lda #$EC:sta	VIA_2:stx VIA_2

playnote_loop

    
   ;; ... read sample whatever way 
adr_samp
	lda	_Sample

    ;; insert here code get channel register in register A
    sta reg_number + 1
    ;; insert here code to get channel value in register A
    sta reg_value + 1
    
reg_number
	lda	#0: LATCH_REG_NUMBER
reg_value
	lda	#0: LATCH_REG_VALUE

	inc	adr_samp+1
	bne	playnote_loop

	inc	adr_samp+2
	dec	_Counter
	bne	playnote_loop
Only one channel amplitude register writing in the loop in order to make sure that changes of output level (A+B+C) occur on an hyper periodic basis.

It could even be possible to use some NOP to help making sure that the loop content is always the same duration and does not depend on branching condition.

The goal here would be that the writing in amplitude register are made hyper regularly .. Regularity is more important than speed for sound fidelity.

Re: 2 eurocents question about AY-8912 possibilities

Posted: Fri Apr 16, 2021 5:30 pm
by Dbug
Well, the problem with the nop method of synchronisation is basically you can only do things like my "Welcome", which does some sound but you can't do anything else during that time (or the only you can do is to run something that takes a fixed amount of time).

What you want is something that ideally would run from the IRQ, which obviously comes with its own set of challenges (that's what I did in NyAtmos and OricTech).

The idea of doing ABCABCABC.. was to not lose any room to encode information about which register to update, but obviously that only work if you can get a data generator able to compute a lot of combinations of permutations to see if it's possible to do something close enough to the original signal just by changing fixed values, but yeah, there are many possible ways of doing that.

Another thing to investigate is also the Tivoli pirat method, which just uses 2 bit samples, and achieve good quality by using a higher frequency replay.

See: https://forum.defence-force.org/viewtop ... oli#p16219

Re: 2 eurocents question about AY-8912 possibilities

Posted: Fri Apr 16, 2021 6:01 pm
by jbperin
Dbug wrote: Fri Apr 16, 2021 5:30 pm that's what I did in NyAtmos and OricTech


waou !! :shock:

How the hell is that possible to play sampled music on interrupt (100Hz) ?

That's not PCM.

Is it possible to see the source code of this magic ?

Re: 2 eurocents question about AY-8912 possibilities

Posted: Fri Apr 16, 2021 6:04 pm
by jbperin
jbperin wrote: Fri Apr 16, 2021 6:01 pm
Is it possible to see the source code of this magic ?
Yes .. I realize it is already on my hard drive LOL !!! :D