Simple 4-channel sample player

For anything related to sound (YM2612, PSG, Z80, PCM...)

Moderator: BigEvilCorporation

User avatar
TmEE co.(TM)
Very interested
Posts: 2285
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) » Tue May 01, 2007 9:00 am

I just tested your updated code, and it works perfectly !!! No static, no startup trouble !!! Is there any possibility to increase sound volume ? It is very quiet...
Mida sa loed ? Nagunii aru ei saa ;)
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen

Shiru
Very interested
Posts: 786
Joined: Sat Apr 07, 2007 3:11 am
Location: Russia, Moscow
Contact:

Post by Shiru » Tue May 01, 2007 9:56 am

TmEE co.(TM) wrote:I meant this: I meant IF there would have been several PCM channels and reprogrammable timer for each, there would not be need for software mixing...
If you imagine that you have these several DAC's and timers, and try to make sample player for it, you get what I meant.

You don't need to have many DAC's to make multichannel 'resampling' with timers - you can write value in memory (accumulate) and output to DAC this value at fixed rate, instead of output it immediately. Main problem with resampling by timers is unavoidable jitter. You can't proccess all channels simultaneously (because you process them by only one CPU), and you can't predict order and delays between outputs on each channel. Timers works good for resampling (although without interpolation) only if you have timers-driven multichannel DMA (Amiga's way).
TmEE co.(TM) wrote:Also, I think that one demo uses 2ch MOD like playback, Censor movie trailer... got it from Eidolon's inn's freeware Genesis ROMs section. ROM itself is less than half a MB and it plays back movie and minute long tune, there must be a MOD player in it.
Not necessary. 60sec*8000Hz =~480K; in 2-bit ADPCM - 60*2000=~120K (or twice more with twice higher samplerate). Also, it possible to cut music to some short loops and use it without resampling and volume control (repeating sample with bassline and drums, and some samples as parts of melody, for example), something like Stef mentioned above.
TmEE co.(TM) wrote:Is there any possibility to increase sound volume ? It is very quiet...
It's quiet because only 6 bits per sample with simplest mixing (just one add operation) used. It's possible to make slightly complicated mixing which raise overall volume, but with distortions when all channels plays loud samples (i.e. mixing with limiter). There is also strange method which I tried long ago: if one channel plays, full 8-bit range used; when two sample plays at once, they crops to 7 bit and adds together; and so on. But that can give strange results, I don't think it can sounds good.

User avatar
Stef
Very interested
Posts: 2627
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Tue May 01, 2007 1:12 pm

Shiru wrote:
Stef wrote:]I wasn't speaking about these wait states, just about the Z80 behavior.
...
It should take 7 cycles as mentionned in the zilog manual.
But in fact this is the "lucky case" : the instruction is 2 bytes lenght which means it need 2 bus cycles (1 bus cycle = 4 Z80 cycles) so it can takes up to 8 cycles. The same is true for the LD A, (HL) instruction as we need one bus cycle to fetch the instruction and another one to fetch data from (HL).
Why you think than one bus cycle is 4 Z80 cycles? It's exactly known, or you just assume?
Z80 always execute instructions in time which specified in Zilog manual. Depending from bus implementation (mainly from active devices which use this bus too, like DMA controllers) in different computers/consoles, execution of instructions can be slower, because bus logic generate /WAIT signal (add wait-states).
It's something exactly known and independant from the system.
Z80 instruction are always counted in T cycles (Z80 cycles) and M cycles (bus cycles).
The real instruction execution is Z80 cycles is:
T cycles <= X <= (M cycles) * 4
Depend about how you are organizing your Z80 instructions.
I'm not a Z80 guru at all, i started Z80 programming very few time ago but if read many documents and saw this behavior in severals places :)
Of course on certain system you will have some extras wait cycles but it will never be faster than the base "T cyles and M cycles logic".
Stef wrote:I though the Z80 was working in "bus steal mode" then very dependent from the current 68000 instruction execution...
If it so, we can't do anything with it. Although I almost sure that time of execution Z80 instruction are fixed and not depends from current 68000 state.
Hmm not sure... when i did some tests on real hardware with my simple 2 ch Z80 player, i saw the 68000 performance was impacted by the Z80 bus use :
- When i was playing 0 channel on Z80 the 68k executed 160 FPS.
- When i was playing 1 channel on Z80 the 68k executed 157 FPS.
- When i was playing 2 channels on Z80 the 68k executed 153 FPS.
I guess only a "cycle steal mode" can affect the 68000 in this way...

B the way, awesome job on your 4 channels players ! I'm impatient to test it on real hardware :)
It's quiet because only 6 bits per sample with simplest mixing (just one add operation) used. It's possible to make slightly complicated mixing which raise overall volume, but with distortions when all channels plays loud samples (i.e. mixing with limiter). There is also strange method which I tried long ago: if one channel plays, full 8-bit range used; when two sample plays at once, they crops to 7 bit and adds together; and so on. But that can give strange results, I don't think it can sounds good.
4 channels with 7 bits samples and limiter or 2 channels with 8 samples and limiter should give the best results, but that eat some extra cycles.
I also tried your method : playing one sample with full 8 bits and doing 7 bits when 2 channels are played... but that give weird volume decreases and increases when you change the number of played channels (sic).

User avatar
TmEE co.(TM)
Very interested
Posts: 2285
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) » Tue May 01, 2007 5:26 pm

shiru wrote:Not necessary. 60sec*8000Hz =~480K; in 2-bit ADPCM - 60*2000=~120K (or twice more with twice higher samplerate). Also, it possible to cut music to some short loops and use it without resampling and volume control (repeating sample with bassline and drums, and some samples as parts of melody, for example), something like Stef mentioned above.
There is definately a 2ch software mixer used, doing weird stuff with hardware I came to this conclusion... also the z80 code looked quite complex.
Mida sa loed ? Nagunii aru ei saa ;)
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen

User avatar
Gerrie
Interested
Posts: 16
Joined: Tue Dec 12, 2006 9:33 pm
Contact:

Post by Gerrie » Tue May 01, 2007 6:43 pm

Ok, this is very offtopic.. but if you want a MOD player, why not use the SegaCD ??

User avatar
evildragon
Very interested
Posts: 326
Joined: Mon Mar 12, 2007 1:53 am
Contact:

Post by evildragon » Tue May 01, 2007 6:46 pm

i agree the SegaCD would be a better thing.. more storage for sounds.. but, it's harder to program..

(now, what I do want to see is a SID player ;) )

Shiru
Very interested
Posts: 786
Joined: Sat Apr 07, 2007 3:11 am
Location: Russia, Moscow
Contact:

Post by Shiru » Tue May 01, 2007 9:24 pm

Stef wrote:It's something exactly known and independant from the system.
...
Maybe I not understand clearly what you're saying. But I can say - M cycle not always take 4T, it has range of 3..5T - look here for additional info. And I can't be wrong about instructions timing in case with no-wait systems because very many things on ZX (multicolors, sample or beeper players) is strongly based on timings, which I use.

I'm not a Z80 guru too (I mean, I don't know absolutely everything), so if I wrong about something, I want to know it.

Stef wrote:Hmm not sure... when i did some tests on real hardware with my simple 2 ch Z80 player, i saw the 68000 performance was impacted by the Z80 bus use
You're saying that M68K slowdowns when Z80 access to ROM much. It can mean that Z80 has priority on bus, so Z80 can work without slowdowns or with minimal fixed slowdowns (it seems logically, because sound CPU must work with predictable timings).

Stef wrote:4 channels with 7 bits samples and limiter or 2 channels with 8 samples and limiter should give the best results, but that eat some extra cycles.
It's not a big problem, even my 4-ch player has some free time.
Stef wrote:I also tried your method : playing one sample with full 8 bits and doing 7 bits when 2 channels are played... but that give weird volume decreases and increases when you change the number of played channels (sic).
Yeah, this works bad, because this is a automatic gain control simplified up to limit. To get better results, more smart algo of reducing volume must be used, but it require volume control (so we need multiplications or big table).

TmEE co.(TM) wrote:There is definately a 2ch software mixer used, doing weird stuff with hardware I came to this conclusion... also the z80 code looked quite complex.
It's easy to check. In case with MOD-like player samples will be not packed (because fast resampling of packed samples is impossible), so it's will be easy to listen when open ROM in any sound editor as raw 8 bit file.

Gerrie wrote:Ok, this is very offtopic.. but if you want a MOD player, why not use the SegaCD ??
Who needs lo-fi MOD player when have CDDA, which is much better and does not require CPU and hardware resources? Anyway, you have nothing else to fill CD in homebrew game.

evildragon wrote:(now, what I do want to see is a SID player ;) )
For SMD's Z80 @3.5MHz only very simple PSG emulator is possible, definitely not SID-like. Although it's possible to make some SID-like effects on SN76489 with software modulation, like in Atari ST AY music. But who needs such sound, which take all Z80 time when have YM2612, which can produce much complicated sounds.

User avatar
Stef
Very interested
Posts: 2627
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Tue May 01, 2007 9:45 pm

Gerrie wrote:Ok, this is very offtopic.. but if you want a MOD player, why not use the SegaCD ??
Hey Gerrie :)

SegaCD ? the goal is to have that working on a simple genesis =)
At least it's mine :p

Edit :
And as said Shiru, we can just use CDDA instead in this case :-/

Shiru
Very interested
Posts: 786
Joined: Sat Apr 07, 2007 3:11 am
Location: Russia, Moscow
Contact:

Post by Shiru » Tue May 01, 2007 9:52 pm

Stef wrote:SegaCD ? the goal is to have that working on a simple genesis =)
At least it's mine :p
I also share this point, but mainly because I can easily go and buy new SMD clone for ~$20 (or get an used one for free), but I must spend very many time and money to get a SegaCD (by the way, I had one long ago, but never seen CDs for it, that was time before widespread of internet).

User avatar
Stef
Very interested
Posts: 2627
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Tue May 01, 2007 10:02 pm

Shiru wrote: Maybe I not understand clearly what you're saying. But I can say - M cycle not always take 4T, it has range of 3..5T - look here for additional info. And I can't be wrong about instructions timing in case with no-wait systems because very many things on ZX (multicolors, sample or beeper players) is strongly based on timings, which I use.

I'm not a Z80 guru too (I mean, I don't know absolutely everything), so if I wrong about something, I want to know it.
Well in fact as you said, from your document (very interesting by the way :p), the M-cycle can varie between 3 and 5 T-cycles. I don't have these infos on mine, i saw only someone mentionning a sort of M cycle alignement in the instruction flow, which made them taking an average 4 cycles... anyway, i've some ways to test it on real hardware ;)

Stef wrote:Hmm not sure... when i did some tests on real hardware with my simple 2 ch Z80 player, i saw the 68000 performance was impacted by the Z80 bus use
You're saying that M68K slowdowns when Z80 access to ROM much. It can mean that Z80 has priority on bus, so Z80 can work without slowdowns or with minimal fixed slowdowns (it seems logically, because sound CPU must work with predictable timings).
Yeah M68K is impacted, i was wrong by saying that *do* mean it's necessary "cycle steal mode" but we can't affirm that Z80 has priority (master bus mode) too for now. Cycle steal mode also reduce the M68K performance but less than "z80 bus master". Again, i think that need some tests with the hardware ;)
Stef wrote:4 channels with 7 bits samples and limiter or 2 channels with 8 samples and limiter should give the best results, but that eat some extra cycles.
It's not a big problem, even my 4-ch player has some free time.
Yep, nice piece of code indeed :)

User avatar
TmEE co.(TM)
Very interested
Posts: 2285
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) » Wed May 02, 2007 5:38 am

Your code doesn't work perfectly... after "stressing" it, it went silent. Only reset helps, I don't know if it happens on emulators.
Mida sa loed ? Nagunii aru ei saa ;)
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen

Shiru
Very interested
Posts: 786
Joined: Sat Apr 07, 2007 3:11 am
Location: Russia, Moscow
Contact:

Post by Shiru » Wed May 02, 2007 6:05 am

TmEE co.(TM) wrote:Your code doesn't work perfectly... after "stressing" it, it went silent. Only reset helps, I don't know if it happens on emulators.
I tried to stress it in KMod, Gens32, Fusion, by some minutes each - without success (still works). Is it stable problem on real hardware? If so, I can make some test code.

User avatar
TmEE co.(TM)
Very interested
Posts: 2285
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) » Wed May 02, 2007 6:36 am

It is unstable on real hardware, 10seconds of stressing and silence.
Mida sa loed ? Nagunii aru ei saa ;)
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen

Shiru
Very interested
Posts: 786
Joined: Sat Apr 07, 2007 3:11 am
Location: Russia, Moscow
Contact:

Post by Shiru » Wed May 02, 2007 6:49 am

TmEE co.(TM) wrote:It is unstable on real hardware, 10seconds of stressing and silence.
I mean, it's happens every time when you tried to stress program? Or it's happens only sometimes?

User avatar
TmEE co.(TM)
Very interested
Posts: 2285
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) » Wed May 02, 2007 7:26 am

It happens every time
Mida sa loed ? Nagunii aru ei saa ;)
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest