News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_lightforce6128

Multi-channel sample playback

Started by lightforce6128, Today at 03:02

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

lightforce6128

This thread is about a technique to play back multiple samples in parallel. A friend who is more interested into another 8-bit system brought this up. But the CPC can do this as well, even better. The idea is simply to mix several samples:

LD H,instrument1 : LD A,(HL)  ;; 4
LD H,instrument2 : ADD A,(HL) ;; 4
LD H,instrument3 : ADD A,(HL) ;; 4
;; ...
INC L                         ;; 1

With this technique easily 10 digital channels can be played in parallel.

The drawback: Frequency and volume are fixed. This means: If the same instrument is needed at three different frequencies, then three samples are needed. While this is unfeasible for some music styles, it might be acceptable for others. E.g. a simple bass line in the background (3-4 samples), continuous strings as support (also 3-4 samples), and synthetic sounds as main melody (8 samples). Also some samples for drums are needed. With a good tracker this would be sufficient to create complex sounds, although by far not every music style can be reproduced with this.

My first question is: Does anybody know if this technique was used somewhere?

The second question is: Does it bring something new? We already have a wide variety of sounds, from default PSG sounds, complex modulations (e.g. the RUN! demo), 1-channel sample playback, up to 3-channel sample playback with adjustable frequency and volume (DigiTracker).

lightforce6128

To do some experiments with samples, I created a RSX that provides several commands to set up and play back samples. To create a sample, additive synthesis is used. This allows to create a sample of 1000s of numbers based on only a few numbers. Although I tried my best to optimize sample creation, it still needs some time. And it needs much memory. Intermediately I even had to use screen memory as buffer. But all is controlled by a few lines of BASIC code what allows easily to do several experiments.

The repository can be found here: https://codeberg.org/lightforce6128/cpc-sample

It contains instructions how to install the RSX and also offers some BASIC programs. The program that builds up an organ-like sound step by step starts with low volume, so the first two iterations may be inaudible.

The extension can use the internal PSG for playback as well as the DigiBlaster on the printer port. What clearly can be noticed is the quantization noise created by the low 4-bit resolution of the PSG. Sometimes it is really annoying, but with other examples it almost vanishes. Until now I did not find out which sounds (besides the default rectangle waves) fit well to the PSG. Are there any experiences?

m_dr_m

Quote from: lightforce6128 on Today at 03:02My first question is: Does anybody know if this technique was used somewhere?
Well digitracker and protracker did such software mixing.

Targhan

#3
Check the Orion Prime digisong in the introduction for a Digitracker/Protracker kind of music (running at 18+Khz). Arkos Tracker also has a out-of-the box MOD player (source available).

The Imperial Mahjong introduction has a different technique, with one small sample per note, but using three channels, instead of mixing on one like the aforementioned players.

And as you mentioned, @BSC has also made some very cool experimentations too.
Targhan/Arkos

Arkos Tracker 3.2.7 now released! - Follow the news on Twitter!
CPC Scene Radio! 24/7 CPC music only! Website Stream
Disark - A cross-platform Z80 disassembler/source converter
FDC Tool 1.2 - Read Amsdos files without the system

Imperial Mahjong
Orion Prime

GUNHED

Look how @Prodatron did it with his Digitracker, the Source Code is available on his homepage (iirc), he uses three channels too. 

In brief, use three channels of 7 bits ADD them up, but keep an eye on Overflow (Carry flag).
http://futureos.de --> Get the revolutionary FutureOS (Update: 2024.10.27)
http://futureos.cpc-live.com/files/LambdaSpeak_RSX_by_TFM.zip --> Get the RSX-ROM for LambdaSpeak :-) (Updated: 2021.12.26)

lightforce6128

Thank you for the hints to different software.

I have to admit that I did not choose a good visualization for the idea. Showing exactly three instruments and then some continuation points directly leads to a comparison to other 3-channel trackers. But the idea is to use much more channels, although with limited effects (there are no effects in the playback loop itself, but at least some effects can be added by other means).

LD H,instrument1  : LD A,(HL)  ;;  4
LD H,instrument2  : ADD A,(HL) ;;  4
LD H,instrument3  : ADD A,(HL) ;;  4
LD H,instrument4  : ADD A,(HL) ;;  4
LD H,instrument5  : ADD A,(HL) ;;  4
LD H,instrument6  : ADD A,(HL) ;;  4
LD H,instrument7  : ADD A,(HL) ;;  4
LD H,instrument8  : ADD A,(HL) ;;  4
LD H,instrument9  : ADD A,(HL) ;;  4
LD H,instrument10 : ADD A,(HL) ;;  4
;; ...                         ;;
INC L                          ;;  1
;;                             ;; --
;;                             ;; 41 ;; => Still 23 NOPs free to output the sample with 12.8 kHz or more.

I checked DigiTracker, Protracker, and Arkos Tracker. The inner loops are optimized to play back three channels with frequency and volume effects by making perfect use of the processor registers. With this technique there is a limit to three channels (what is already tremendous for the CPC). More channels can only be reached by lowering the playback frequency.

The question is: Can a different kind of sampled music be created with more channels, but less effects?
Does it has any impact on sound quality that there are no interpolation artifacts (because there is no interpolation)?

I still have to check how Orion Prime and Imperial Mahjong create the music output. Does anyone know?

andycadley

How do you scale the results back into 4-bits? And do the original samples still need to be 4-bit?

lightforce6128

Quote from: andycadley on Today at 18:10How do you scale the results back into 4-bits? And do the original samples still need to be 4-bit?

The 8-bit accumulator is used to sum up the samples and this is done 10 times. This allows the samples to use a range of -12 to +12 (something like 4.7 bits) to make an overflow impossible. In most situations a bigger range might be used and still will not cause an overflow.

After the final result is stored in A, it can be converted with a table lookup to a 4-bit logarithmic value. The used table might be changed during playback to optimize volume dynamics. To simplify output, the table values should not only contain the volume itself, but also the PPI command bits.

A bit more elaborated example:

mix_ten_samples:                         ;; |        ;;
    loop:                                ;; +----+   ;;
        ;;                               ;; |    |   ;;
        LD H,instrument_1  : LD A,(HL)   ;; |    4   ;; Mix ten samples.
        LD H,instrument_2  : ADD A,(HL)  ;; |    4   ;;
        LD H,instrument_3  : ADD A,(HL)  ;; |    4   ;;
        LD H,instrument_4  : ADD A,(HL)  ;; |    4   ;;
        LD H,instrument_5  : ADD A,(HL)  ;; |    4   ;;
        LD H,instrument_6  : ADD A,(HL)  ;; |    4   ;;
        LD H,instrument_7  : ADD A,(HL)  ;; |    4   ;;
        LD H,instrument_8  : ADD A,(HL)  ;; |    4   ;;
        LD H,instrument_9  : ADD A,(HL)  ;; |    4   ;;
        LD H,instrument_10 : ADD A,(HL)  ;; |    4   ;;
        INC L                            ;; |    1   ;; Go to next sample byte.
        ;;                               ;; |    |   ;;
        LD E,A : LD A,(DE)               ;; |    3   ;; Convert linear value to logarithmic value.
        ;;                               ;; |    |   ;;
        LD B,#F4 : OUT (C),A             ;; |    6   ;; Bits 7+6 of A are ignored.
        LD B,#F6 : OUT (C),A : OUT (C),0 ;; |   10   ;; Bits 3-0 of A are ignored.
        ;;                               ;; |    |   ;;
    DEC C : JR NZ,loop                   ;; +--- 4-1 ;; Repeat this multiple times.
    ;;                                   ;; |        ;;
    RET                                  ;; 3        ;;
    ;;                                   ;; -------- ;;
    ;;                                   ;; 2+n*64   ;;

If the loop counter is set to 4 and 5 alternating, 256 sample bytes are output per frame (i.e. 12.8 kHz) and 56 lines can be used for something else (e.g. change the instruments, change the volume table, program the other two channels of the PSG with normal, non-sampled sound, ...).

andycadley

Interesting. I was more thinking of generating DMA lists and let the Plus hardware take the strain of outputting values at the right frequency...

Powered by SMFPacks Menu Editor Mod