CPCWiki forum

General Category => Programming => Topic started by: mr_lou on 18:43, 30 September 11

Title: Can the CPC do this?
Post by: mr_lou on 18:43, 30 September 11
Can the CPC do this?
Experimental one-line algorithmic music - the 2nd iteration (http://www.youtube.com/watch?v=qlrs2Vorw2Y#)
Title: Re: Can the CPC do this?
Post by: TFM on 19:50, 30 September 11
Quote from: mr_lou on 18:43, 30 September 11
Can the CPC do this?


Yes, the CPC can do that, suggested help is the CPC-Booster+.
Title: Re: Can the CPC do this?
Post by: norecess on 00:03, 01 October 11
I don't care actually if CPC can or can not do this.


But the real thing is : wow, this is awesome! The guys who thought about generating PCM such a way (and finding the right algorithm sounding good) are just pure geniouses !


Thanks for sharing this link.
Title: Re: Can the CPC do this?
Post by: Devilmarkus on 10:07, 01 October 11
Hmmm tried this in BASIC:
10 a=((t OR (t/512 OR t/128))*t AND (t/2048 OR t/512))
20 OUT &FF10,a
30 t=t+1
40 GOTO 10


But after a while I get an Overflow in 10
Whats wrong here?
Title: Re: Can the CPC do this?
Post by: Cosi on 10:37, 01 October 11
Maybe the problem is that in BASIC t is represented as a long real number, while C "clears the counter" every time t reaches 65536.

(I'm not into Amstrad's BASIC, so please don't kill me if I'm wrong :) )
Title: Re: Can the CPC do this?
Post by: Devilmarkus on 11:29, 01 October 11
Quote from: Cosi on 10:37, 01 October 11
Maybe the problem is that in BASIC t is represented as a long real number, while C "clears the counter" every time t reaches 65536.

(I'm not into Amstrad's BASIC, so please don't kill me if I'm wrong :) )

Sure right,
but the Overflow happens when t=182  :'(
Title: Re: Can the CPC do this?
Post by: Cosi on 11:48, 01 October 11
Well... :(

Could you please try to replace those divisions with integer divisions (int(x/y) or something)?
Title: Re: Can the CPC do this?
Post by: Devilmarkus on 12:33, 01 October 11
Sure, this makes no difference  ???
Title: Re: Can the CPC do this?
Post by: tastefulmrship on 13:07, 01 October 11
BASIC will not complete a logical expression with a number over 32767.
Title: Re: Can the CPC do this?
Post by: Devilmarkus on 13:34, 01 October 11
Quote from: tastefulmrship on 13:07, 01 October 11
BASIC will not complete a logical expression with a number over 32767.

I see... But why? This makes no sense :(
Title: Re: Can the CPC do this?
Post by: tastefulmrship on 13:51, 01 October 11
Quote from: Devilmarkus on 13:34, 01 October 11
I see... But why? This makes no sense :(

PRINT 32768 AND 1 fails, but
PRINT &8000 AND 1 works fine.

Is this because BASIC treats numbers over 7FFF as negative; ie &8000 (-32768) to &FFFF (-1).

If you view this program in DEBUG, you'll see where I'm coming from... but why it refuses to complete logical expressions beyond my technical knowledge.

10 a=65535
20 b=&FFFF



EDIT: Here's a slightly updated version of Devilmarkus's BASIC program. This brings the value of t% to 255 before failing (due to numbers beyond FFFF).

10 WHILE t%<256
20 a$=HEX$((t% OR (t%/512 OR t%/128))*t%)
30 b$=HEX$(t% OR (t%/2048 OR t%/512))
40 c$=HEX$(VAL("&"+a$) AND VAL("&"+b$))
50 OUT &FF10,VAL("&"+c$)
60 t%=t%+1
70 WEND

And, of course, you can always add a PRINT statement in the routine to see what a$, b$, c$ and t% are doing as you require.

EDIT2: Is there a non-CPCBooster OUT command direct to the chip? WinAPE loves silence, but I don't.
Title: Re: Can the CPC do this?
Post by: Devilmarkus on 20:21, 01 October 11
Thankyou.
Tried it, also poked the values into RAM, and then played it through Amdrum / Digiblaster.
But sounds strange :D
10 adr=&1000
20 WHILE t%<256
30 a$=HEX$((t% OR (t%/512 OR t%/128))*t%)
40 b$=HEX$(t% OR (t%/2048 OR t%/512))
50 c$=HEX$(VAL("&"+a$) AND VAL("&"+b$))
60 POKE adr,VAL("&"+c$):adr=adr+1
70 t%=t%+1
80 WEND
90 FOR t=0 TO 255:OUT &FF10,PEEK(&1000+t):NEXT:GOTO 90

Amdrum! Digiblaster needs port &EF10

http://cpc-live.com/bastest (http://cpc-live.com/bastest)

Perhaps an ASM playback routine would be clearer?

Title: Re: Can the CPC do this?
Post by: tastefulmrship on 21:24, 01 October 11
Yes, it needs a lot more samples than 256 to sound like those in the original one-liner, but it's surely getting there!
Maybe if someone could run a C program on PC that creates more samples, then take those results and play them through Amdrum or Digiblaster... but that's kinda missing the point!

If you amend the program with these lines
60 SOUND 1,VAL("&"+c$),10,15:SOUND 2,VAL("&"+c$)*10,10,15:SOUND 4,VAL("&"+c$),10,15
90 t%=0:GOTO 20
you get a pretty weird tune... which actually sounds quite good further in.
Title: Re: Can the CPC do this?
Post by: Devilmarkus on 21:41, 01 October 11
Indeed...
Well I "tried" the routines shown in the video and combined 3 loops to a stereo sound.
Result: (Don't regard the "Ready", I quickly tweaked the audio routine, so no CPC was really used for!)
http://cpc-live.com/craptest (http://cpc-live.com/craptest)

Code was like this:
        ppo++;
        if (ppo == 6) {
            r = ((t >> 6 | t | t >> (t >> 16)) * 10 + ((t >> 11) & 7));
            q = (t | (t >> 9 | t >> 7)) * t & (t >> 11 | t >> 9);
            p = ((t & 4096) != 0) ? ((t * (t ^ t % 255) | (t >> 4)) >> 1)
                    : (t >> 3) | (((t & 8192) != 0) ? t << 2 : t);
            t++;
            ppo = 0;
        }
        leftO = ((r & 0x07f) + (q & 0x07f));
        rightO = ((q & 0x07f) + (p & 0x07f));
        player.writeStereo(leftO ^ 0x80, rightO ^ 0x80);
Title: Re: Can the CPC do this?
Post by: Devilmarkus on 21:59, 01 October 11
Goal should be a oneliner ;)
So in BASIC:
10 FOR t%=0 TO 255:a$=HEX$((t% OR (t%/512 OR t%/128))*t%):b$=HEX$(t% OR (t%/2048 OR t%/512)):c$=HEX$(VAL("&"+a$) AND VAL("&"+b$)):SOUND 3,VAL("&"+c$)*10,10,15:t%=t%+1:NEXT:GOTO 10

But it's really completely different :D
Title: Re: Can the CPC do this?
Post by: tastefulmrship on 22:14, 01 October 11
Quote from: Devilmarkus on 21:41, 01 October 11
        ppo++;
        if (ppo == 6) {
            r = ((t >> 6 | t | t >> (t >> 16)) * 10 + ((t >> 11) & 7));
            q = (t | (t >> 9 | t >> 7)) * t & (t >> 11 | t >> 9);
            p = ((t & 4096) != 0) ? ((t * (t ^ t % 255) | (t >> 4)) >> 1)
                    : (t >> 3) | (((t & 8192) != 0) ? t << 2 : t);
            t++;
            ppo = 0;
        }
        leftO = ((r & 0x07f) + (q & 0x07f));
        rightO = ((q & 0x07f) + (p & 0x07f));
        player.writeStereo(leftO ^ 0x80, rightO ^ 0x80);

Ok, what happens if you collate a number of results (I dunno, 1000? Maybe even 1000 per channel) from the above code on PC and copy them into CPC memory (as long as they are 8bit, of course), then play them through external audio hardware (Amdrum, Digiblaster)? Does it sound similar to the original? If so, all we need is assem code that can deal with numbers over &FFFF (possible?) and run it through PSG/external hardware.
Title: Re: Can the CPC do this?
Post by: Devilmarkus on 22:17, 01 October 11
Well, this could work...
Dunno... Who can code it?
Title: Re: Can the CPC do this?
Post by: tastefulmrship on 22:24, 01 October 11
Can you get get C code to send results to screen/file rather than to PCM?
I don't mind converting the results to CPC and seeing what happens...

If someone could get this programmed in assem, we could send it back to the 32/64 bit community before the C64 lot get their mitts on it! One-up for the Amstrad posse!
Title: Re: Can the CPC do this?
Post by: Devilmarkus on 22:37, 01 October 11
Well I did this:
A little routine in Java:
    public void doSong(){
        for (int t=0; t< 0x4000;t++){
            POKE(0x4000+t,((t >> 6 | t | t >> (t >> 16)) * 10 + ((t >> 11) & 7)));
        }


This produced a 16k samplefile.
This DATA I played via digiblaster with 8khz.
Result:
http://cpc-live.com/sampletest (http://cpc-live.com/sampletest)

now we need someone who does ALL in realtime in ASM ;)

Title: Re: Can the CPC do this?
Post by: Devilmarkus on 23:04, 01 October 11
My DSK:
RUN"64" -> 32k sample to AY
RUN"64D" -> 32k sample to digiblaster
(both use screen ram!)

RUN"128" / RUN"128D" same but using 2 BANKs
Title: Re: Can the CPC do this?
Post by: Devilmarkus on 23:17, 01 October 11
We should do this instead:
Floppy music DUO - Imperial march (http://www.youtube.com/watch?v=yHJOz_y9rZE#)
Title: Re: Can the CPC do this?
Post by: tastefulmrship on 09:05, 02 October 11
Isn't that the same principle as this;
Renault F1 Car playing God Save The Queen (http://www.youtube.com/watch?v=1JPBdBIFGNQ#)


I tried to get some "tonal music" from the TAPE loading noise, but it only produces 10 or so original tones and so I had to quit!
Title: Re: Can the CPC do this?
Post by: SyX on 11:59, 02 October 11
Hi ;)

I have cheated because i'm using the expansion ram how storage for the datas generated by the equation (t>>7|t|t>>6)*10+4*(t&t>>13|t>>6)  (t = 0 - 65535) , mainly because i'm lazy today :P , but for a fast testing you only have to replace the datas in the expansion ram, by the new datas generated for other equation ;)

Of course, the source code for the player:    ORG  $2000

start
    DI

replay
    LD   BC,$7FC4
    OUT  (C),C
    CALL play
    LD   BC,$7FC5
    OUT  (C),C
    CALL play
    LD   BC,$7FC6
    OUT  (C),C
    CALL play
    LD   BC,$7FC7
    OUT  (C),C
    CALL play
    JR   replay

play
    LD   HL,$4000
    LD   B,$EF
loop_play
    DEFS 64 - 14
    LD   A,(HL)
    OUT  (C),A

    INC  HL
    LD   A,H
    CP   $80
    JP   NZ,loop_play
    RET

    END
PD: digi2 replay signed bytes and digi3 unsigned bytes (an extra XOR $80 between LD A,(HL) and OUT (C),A ).
Title: Re: Can the CPC do this?
Post by: Devilmarkus on 14:08, 02 October 11
Something seem to be weird with your asm source...
Compiled it many times but only 1x I was able to hear the sound?!?

Hummmm... Edit:
I see: you did not generate the data! That was just the playback :D
Title: Re: Can the CPC do this?
Post by: SyX on 14:39, 02 October 11
Yes, Markus, it's only the playback, sorry, jejeje... but i generated the datas using Protext, PhrozenC and Maxam, that it must be a +1 cpc geek point  ;D
Title: Re: Can the CPC do this?
Post by: TFM on 04:24, 03 October 11
Quote from: SyX on 14:39, 02 October 11
Yes, Markus, it's only the playback, sorry, jejeje... but i generated the datas using Protext, PhrozenC and Maxam, that it must be a +1 cpc geek point  ;D

At least one point :-)))
Powered by SMFPacks Menu Editor Mod