[z88dk-dev] sound/bit

Bridge to the z88dk-developers mailing list
Post Reply
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

[z88dk-dev] sound/bit

Post by alvin »

I've put together a new version of the 1-bit sound library in the new clib dir structure:

header
http://z88dk.cvs.sourceforge.net/viewvc ... iew=markup

source
http://z88dk.cvs.sourceforge.net/viewvc ... d/bit/z80/

typical target defines
http://z88dk.cvs.sourceforge.net/viewvc ... iew=markup

I like the way the sound bit is handled on various machines -- that is not changed although I did change a couple of names and added a read/write mask when storing the last sound byte written (bit_open and bit_close). I rewrote any C bits in assembler and made a change in how bit_fx() works. We'd been dividing up the sound effects into groups of eight in order to help reduce program size and had four bit_fx functions as a result but I've changed that to one bit_fx() function and instead of passing an integer to identify a sound effect to play, we now pass a pointer to the sound effect function. This means there are no more tables of sound effect pointers and only sound effect code that is actually used gets attached to the program.

I've not had a chance to test it yet but will make an example program later on. There are a few sound effects functions that may be buggy in that they don't initialize some registers they are using. This includes bit_synth() where when a particular "voice" is deactivated (freq_n = 0), the delay value used for the corresponding loop continues to be whatever it was from the last call.



------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/NeoTech
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

The 1-bit sound community has been doing a lot of things in the past couple of years, including some pretty amazing music players with songs for some of those players being editable on windows trackers. Unfortunately the players have been written with a very narrow view, mainly for the spectrum, but it looks like we can do a good job of modifying the code to work on any cpu at any speed and, in some cases, remove the self-modifying code to boot.

My first try at incorporating some of these things into z88dk is BeepFX by Shiru: http://shiru.untergrund.net/software.shtml (under current projects). This is a 1-bit sound effects generator with a windows editor. The effects are data driven (versus procedural in bit_fx) so that I only had to attempt to modify the code in one place. Anyway I was successful:

* Self modifying code was removed to make it ROMable
* Changed so that only one index register is used rather than two.
* Sound output via 8-bit port, 16-bit port or memory mapped device (the z88dk method)
* Sound output does not disturb other port bits (the z88dk method)
* For fast cpus, cycle accurate delays are added so that sound effects still play correctly.

So along with bit_beep, bit_play, etc, bit_beepfx is cpu speed independent.

Anyway here's a test program that plays the built-in effects, along with source:
https://drive.google.com/file/d/0B6XhJJ ... sp=sharing

Yeah, the colours are bad and so is the font selection.



------------------------------------------------------------------------------
Start Your Social Network Today - Download eXo Platform
Build your Enterprise Intranet with eXo Platform Software
Java Based Open Source Intranet - Social, Extensible, Cloud Ready
Get Started Now And Turn Your Intranet Into A Collaboration Platform
http://p.sf.net/sfu/ExoPlatform
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

I successfully modified the tritone beeper engine for z88dk. You can give it a try here:

https://drive.google.com/file/d/0B6XhJJ ... sp=sharing

The source is there along with a tap for the spectrum. Modifying it not to alter border colour and to output using any method slowed down the main loop and causes existing songs to play lower. The slowdown also drops the first PWM harmonic so you can hear a high pitched whine more audibly than the original engine.



------------------------------------------------------------------------------
Start Your Social Network Today - Download eXo Platform
Build your Enterprise Intranet with eXo Platform Software
Java Based Open Source Intranet - Social, Extensible, Cloud Ready
Get Started Now And Turn Your Intranet Into A Collaboration Platform
http://p.sf.net/sfu/ExoPlatform
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Post by stefano »

I successfully modified the tritone beeper engine for z88dk. You can give it a try here:
Wonderful, I should, sooner or later try to make a bit_play version based on bit_synth.. the polyphonic demo is a bit improper (it works on the "harmonics"), I thought at bit_synth as a way to play different sound "patches" and to provide a sound bank fpr it, but it is quite difficult to bend the sound to the right pitches.
Another thing I was trying to make portable is the PSG stuff, but I'm stuck with the Amstrad CPC version.
Probably it is better to begin porting a protracker player, the target enthusiasts will then probably provide the hints ;)



------------------------------------------------------------------------------
Start Your Social Network Today - Download eXo Platform
Build your Enterprise Intranet with eXo Platform Software
Java Based Open Source Intranet - Social, Extensible, Cloud Ready
Get Started Now And Turn Your Intranet Into A Collaboration Platform
http://p.sf.net/sfu/ExoPlatform
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

Another thing I was trying to make portable is the PSG stuff, but I'm stuck with the Amstrad CPC version.
Probably it is better to begin porting a protracker player, the target enthusiasts will then probably provide the hints ;)
There is a lot of AY code out there too but the problem with all of it is that it's written specifically for one machine or other and it takes many hours to understand what they've done so that it can be rewritten for all machines. But yeah, I would agree we should use what is being used by the active musicians now. Anything with a PC editor is important, such as VortexTracker and the AY sound effects engine (again by Shiru). Some hardware also has more than one AY chip so that has to be figured out and there are new engines emerging that fiddle with the volume envelope in real-time to shape waveforms. This last one presents the same problem as the beeper engines in trying to minimize divergences caused by differences in cpu speed and ay chip frequency. The first instance of this I've seen for z80 machines was done on the spectrum but no information came out so it just died. Someone is doing the same for the CPC now but again the code is very target specific, which can!
drive
someone nuts trying to make it general. Very few people think big picture :)

I also think we should have a look at the C embedded tech report and what it says about hardware. I haven't really read it yet but before doing too much for external ICs I think we should see how it fits with the direction of the language.



------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos. Get
unparalleled scalability from the best Selenium testing platform available.
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Post by stefano »

Well, the PSG interface functions are already in the z88dk library tree, but they're still naked.
I think that supporting a single PSG will permit quite a good portability, those sound chips are so similar that probably a lot of functions can be easily made general, the only real problem I see with the sound is the fact that most of the players are bound to the interrupts or to some sort of "background player"infrastructure, which I prefer to remove at the earlier stage.

The CPC case is a bit borderline because of the trickiness to get to the PSG address and data ports, that's it,



------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos. Get
unparalleled scalability from the best Selenium testing platform available.
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
Neuxsone1984
Member
Posts: 30
Joined: Fri Feb 10, 2017 3:36 pm

Post by Neuxsone1984 »

I been looking on and off at this code and modify for embedded applications.

Wonder if there are just a couple of raw write routines that need hardware information and the rest is just code for timing and play back that is not hardware specific.

What are the core raw routines where I need to add my port information, example something like a bit_on and bit_off where I tell it what port to use and port bit to mask in which to toggle?



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

I been looking on and off at this code and modify for embedded applications.
Wonder if there are just a couple of raw write routines that need hardware information and the rest is just code for timing and play back that is not hardware specific.
What are the core raw routines where I need to add my port information, example something like a bit_on and bit_off where I tell it what port to use and port bit to mask in which to toggle?
For the newlib, library configuration is handled on a per target basis by config files in the z88dk/libsrc/_DEVELOPMENT/target/TARGETNAME/config directory.

As an example, the zx spectrum target (zx) does have the 1-bit routines available and it is configured by:

z88dk/libsrc/_DEVELOPMENT/target/zx/config/config_sound_bit.m4
https://github.com/z88dk/z88dk/blob/mas ... und_bit.m4

All of its config files are brought together into a single file that is read at library build time z88dk/libsrc/_DEVELOPMENT/target/zx/config.m4
https://github.com/z88dk/z88dk/blob/mas ... fig.m4#L36

Then the sound routines are added to the target's libraries in directory z88dk/libsrc/_DEVELOPMENT/target/zx/library/
https://github.com/z88dk/z88dk/blob/mas ... iy.lst#L23


The first file above defines how the sound output happens:

define(`__SOUND_BIT_METHOD', 1) # 1 = port_8, 2 = port_16, 3 = memory
define(`__SOUND_BIT_PORT', 0xfe) # port or memory address
define(`__SOUND_BIT_TOGGLE', 0x10) # bits to toggle to make noise
define(`__SOUND_BIT_TOGGLE_POS', 4) # bit position to test state of output
define(`__SOUND_BIT_READ_MASK', 0x17) # part of state byte to be used in output
define(`__SOUND_BIT_WRITE_MASK', 0xe8) # part of state byte to be preserved on write

__SOUND_BIT_METHOD chooses 8-bit io port, 16-bit io port or memory mapped.
__SOUND_BIT_PORT defines the port or address to use
...

The port is assumed to contain active bits other than just a sound toggle and the routines keep a single byte mirror of the port's contents in a single byte variable in memory. __SOUND_BIT_READ_MASK indicates which bits of the stored byte will be used during the output and __SOUND_BIT_WRITE_MASK indicates which bits will not change in the stored byte when the last output is recorded.

Making the changes to the files indicated is enough to get the target to generate sound. The more complicated sound output routines (in particular the multi-voice ones and the sound effects) have not been adjusted for cpu clock yet and are timed for 3.5-4 MHz. They will work but may be out of tune and wrong tempo.


The embedded z80 target is intentionally generic so there is no hardware specific code in it. It does not have a config file for 1-bit sound. You could add it in but if you are headed in the direction of making a custom target for your hardware, you may just want to go ahead with adding a new target instead of modifying an existing one.



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
Post Reply