Digitized sound effects on Next - in Basic and Machine Code

Discuss game and other programming topics not specifically covered in another forum

Moderator: Programming Moderators

User avatar
SpectrumOldi
Posts: 20
Joined: Tue Aug 21, 2018 12:00 pm

Digitized sound effects on Next - in Basic and Machine Code

Postby SpectrumOldi » Tue Oct 09, 2018 8:42 am

I guess the sound chip support digitized sound effects? Are digitized sound effects loaded from the "disk" and put into memory when you start a program or is it "baked" into the compiled or machine coded file.
"Spectrum Oldie"

Szk
Posts: 36
Joined: Mon May 29, 2017 11:20 pm
Location: São Paulo, Brazil

Re: Digitized sound effects on Next - in Basic and Machine Code

Postby Szk » Wed Oct 10, 2018 2:43 pm

Yes, a SpecDrum/Covox style 8-bit DAC is included in the ZX Next core, so your program can load sampled data from the SD card to play along with the 3x AY "chips" and beeper.

See David Saphier's demo and the comments here: https://www.facebook.com/groups/specnex ... 501722540/

PiyoTaro
Posts: 111
Joined: Thu Jun 01, 2017 11:13 am

Re: Digitized sound effects on Next - in Basic and Machine Code

Postby PiyoTaro » Sat Oct 13, 2018 8:11 am

If the OS manages the FIFO buffer, the DAC is substituted for the PCM sound generator. It became possible to multiply and divide by Z80 CPU, and it became easy to expand wavetable. Will MOD format music player be integrated into OS? 8-)

"DMA audio" installed in the OS assumes a machine clock of 3.5 MHz. When used in 14MHz mode of "Next", sampling data of 13KHz * 4 = 52KHz is required. :(


I would like to use the "Copper Sound System" rather than DMA, because I want to run the application of "Next" in 14 MHz mode, and the memory bank switching and interference with DMA become troublesome when debugging.

By the way, "Copper" can count 312 scanlines on the screen. However, with current firmware Copper does not have interrupt function.
When looking at the current document, first specify the "START, then reset at next VBlank" command in the control register of "Copper". And it seems to upload data programmed to Copper every Vblank period.
I am worried whether the program can be executed at a certain timing. I want sample code.

Alcoholics Anonymous
Posts: 397
Joined: Mon May 29, 2017 7:00 pm

Re: Digitized sound effects on Next - in Basic and Machine Code

Postby Alcoholics Anonymous » Mon Oct 15, 2018 12:18 am

PiyoTaro wrote:
Sat Oct 13, 2018 8:11 am
"DMA audio" installed in the OS assumes a machine clock of 3.5 MHz. When used in 14MHz mode of "Next", sampling data of 13KHz * 4 = 52KHz is required. :(
This has been fixed now. The DMA sampled audio will run at constant rate no matter what the CPU speed is. Sample rates can now be set as low as 3.4kHz.

The version of the core for production was frozen long ago so this change is in a later version.
By the way, "Copper" can count 312 scanlines on the screen. However, with current firmware Copper does not have interrupt function.
When looking at the current document, first specify the "START, then reset at next VBlank" command in the control register of "Copper". And it seems to upload data programmed to Copper every Vblank period.
I am worried whether the program can be executed at a certain timing. I want sample code.
The copper operates in exact lockstep with the display generation. Its instructions allow the copper to wait for a specific line and horizontal byte position. Running an effective "nop" instruction allows the copper to delay past individual pixels in that byte.

Its program is stored in a 2k space on the fpga. Each instruction is 16-bits so that's an instruction space of 1k instructions. The instructions are no reloaded each frame; the internal program counter is just reset to zero (in vbi mode) or allowed to wrap around (in loop mode).

PiyoTaro
Posts: 111
Joined: Thu Jun 01, 2017 11:13 am

The ZXN PRESCALAR / Re: Digitized sound effects on Next - in Basic and Machine Code

Postby PiyoTaro » Wed Oct 17, 2018 9:37 am

"The ZXN PRESCALAR"

The article "THE ZXNDMA" registered at the official site resource at the end of September. Let's see the paragraph "WR2" in the article "zxn DMA Registers" chapter.

In the explanation of the prescaler, "sampled audio" is used as an example and numerical values ​​are written in bold.
THE ZXNDMA
September 26, 2018 Phoebus Dokos

The ZXN PRESCALAR is a feature of the zxnDMA implementation. If non-zero, a delay will be inserted after each byte is transferred such that the total time needed for the transfer is at least the number of cycles indicated by the prescalar. This works in both the continuous mode and the burst mode.
The zxnDMA‘s speed matches the current CPU speed so it can operate at 3.5MHz, 7MHz or 14MHz. Since the prescalar delay is a cycle count, the actual duration depends on the speed of the DMA. A prescalar delay set to N cycles will result in a real time transfer taking N/f CPU seconds. For example, if the DMA is operating at 3.5MHz and the max prescalar of 255 is set, the transfer time for each byte will be 255/3.5MHz = 72.9μs. If the DMA is used to send sampled audio, the sample rate would be 13.7kHz and this is the lowest sample rate possible using the prescalar.
Alcoholics Anonymous wrote:
Mon Oct 15, 2018 12:18 am
PiyoTaro wrote:
Sat Oct 13, 2018 8:11 am
"DMA audio" installed in the OS assumes a machine clock of 3.5 MHz. When used in 14MHz mode of "Next", sampling data of 13KHz * 4 = 52KHz is required. :(
This has been fixed now. The DMA sampled audio will run at constant rate no matter what the CPU speed is. Sample rates can now be set as low as 3.4kHz.

The version of the core for production was frozen long ago so this change is in a later version.
There was a reply that it will be improved by future update of ZXNEXTOS. :o

We had misunderstood :shock: that Z8410 (Z80B DMA) has a function to adjust the data transfer rate with "prescaler". However, this seems to be "extension with ZXSpectrum Next". 8-)

Originally Z80 DMA was able to specify "the operation cycle length" and lower the transfer speed. Using "prescaler" at the same time it was possible to realize a lower transfer rate.


By the way, in order to realize our "PCM sound by FIFO buffer", the OS needs to know that the data transfer is over.
Is interrupt implemented in 'zxnDMA'?

Alcoholics Anonymous
Posts: 397
Joined: Mon May 29, 2017 7:00 pm

Re: The ZXN PRESCALAR / Re: Digitized sound effects on Next - in Basic and Machine Code

Postby Alcoholics Anonymous » Wed Oct 17, 2018 3:08 pm

PiyoTaro wrote:
Wed Oct 17, 2018 9:37 am
We had misunderstood :shock: that Z8410 (Z80B DMA) has a function to adjust the data transfer rate with "prescaler". However, this seems to be "extension with ZXSpectrum Next". 8-)

Originally Z80 DMA was able to specify "the operation cycle length" and lower the transfer speed. Using "prescaler" at the same time it was possible to realize a lower transfer rate.
The zxn dma has the same feature - this is the cycle length adjustment that controls the length of a read or write cycle to 2, 3 or 4 cycles so that bus transactions are not too fast for slow io or slow memory. The adjustment is measured in microseconds so it's only suitable for interfacing.

Yes the prescalar is a new feature of the zxn dma. The recent change internally multiplies the prescalar by 4 so that the effective sample rate is "F = 875kHz / prescalar" and this prescalar value applies no matter what the cpu speed is.
By the way, in order to realize our "PCM sound by FIFO buffer", the OS needs to know that the data transfer is over.
Is interrupt implemented in 'zxnDMA'?
Not yet. What happens now (for example in playwav) is that the program polls the current dma source address to find out if it's half-way through its buffer. If it is, it loads the half of the buffer that has already been passed with new data from disk. The dma is operated in auto-reload mode (see WR5) which means it just keeps sending the same buffer over and over while the program polls it to find out when it's time to reload from disk the half of the buffer passed by the dma.

In the context of a game, you'd know from the sample rate approximately when you'd need to reload the dma buffer or you might put a couple of line interrupts in to poll the dma to see if it's time to reload its buffer. Rather than loading from disk, you might have the entire sample in memory so that you can just map in a new memory page for the next part of the sample. What works best really depends on what you are doing; currently several people are using copper audio because they need the dma for other things. "pogie2.sna" on the distro is a good example of copper audio in a game.

PiyoTaro
Posts: 111
Joined: Thu Jun 01, 2017 11:13 am

Re: Digitized sound effects on Next - in Basic and Machine Code

Postby PiyoTaro » Wed Oct 17, 2018 7:35 pm

The title of the thread is "Digitized sound effects".
So I am assuming how to use "DMA Sound" as a general "PCM sound generator" instead of "streaming audio".

Scenes using sampled sounds in games may be "explosion sounds" or scenes that synchronize percussion sounds with music played in AY.
"DMA Sound" uses a fixed memory bank on a limited memory map.
Usage as a sound effect usually expands huge "sampling data" placed in an array variable or external memory bank into a small "buffer" per unit time. (I wrote "FIFO", but here we will switch between two buffers.)

I thought it would be nice if the OS managed "wavetable buffer", and that such a library would be supported.

Alcoholics Anonymous
Posts: 397
Joined: Mon May 29, 2017 7:00 pm

Re: Digitized sound effects on Next - in Basic and Machine Code

Postby Alcoholics Anonymous » Wed Oct 24, 2018 3:47 am

I regard streaming audio as a more difficult problem :) For sound effects you can just set the dma to play one and when it's finished it will stop all by itself. So it's "set it and forget it". If you need to mix sound effects, that's a different thing. You may need to prepare a buffer by adding the sources together. However, I have found from other projects that simply stopping a current sound effect and starting a new one instead of mixing worked out well. An example is pietro bros ( https://www.youtube.com/watch?v=wD-6I_F4xMU&t=4229s ) which uses all three voices of the AY to play sampled wavs for sound effects. It plays one sound effect at a time and simply stops and plays a new one when a new one is triggered.

About the OS - this is really something too specialized for the operating system. A library, otoh, makes sense.


Who is online

Users browsing this forum: No registered users and 1 guest