Sound for Squeak/Scratch
Rick Murray (539) 13857 posts |
I think you’ve just tripped over yourself there. Compare C with PHP. Both can be counted as “high level language”. One compiles to machine code, one compiles (if not interpreted) to a sort of p-code. One requires you to write (or use library) functions and do your own housekeeping. The other… provides a fairly sanitised environment for your “program” and does a lot of stuff for itself. It is worth pointing out that C’s use of pointers and some of the things you can do – while not assembler – are very low level. Show me an HLL that does that sort of stuff. The primary difference, however, is that while assembler is a list of instructions to the machine, a C program is a description of what is supposed to happen. The compiler looks at this description and attempts to make code from it. Due to a myriad of boring reasons, this code may or may not be what you had in mind. This low-level aspect of C is why I (and others) tend to think of it as a sort of assembler-lite. This document explains what I mean.
Not read that, sounds interesting. Converting C to assembly is dead easy. Create the directory “s” and then pass
Pointers.
Are you sure you read that correctly? Unless you are comparing with FORTRAN or some PDP-8 language I’ve never heard of, C is much closer to the hardware than most languages. Reference: Huge swathes of the C spec; but two off the top of my head: That said, C does attempt some degree of hardware abstraction, along with the often lauded (but fairly flawed in reality) concept of portable code. This is to be expected, for it is pretending to be a high level language after all! I will close from a quote from Wiki on the C page :
|
Tim Rowledge (1742) 170 posts |
Looks like scratch works ok on the pi. A bit slow I have to admit but cats meow, circles honk like geese, saving a project changes the window title, trying to record sounds doesn’t crash (somebody made a right mess of the sound record code in that ancient image) and loading new image and sound samples works. And C? C is just a jumped-up bastardised PDP assembler with delusions of adequacy. Don’t get me started on c++, c# or java. |
nemo (145) 2563 posts |
Rick said:
Pity the book didn’t mention that C++ was originally a preprocessor stage feeding existing C compilers. But as Turing would be quick to point out, there is nothing in <language A> that can’t be done in <language B> – that’s sort of the point. It’s just that certain tasks are easier in certain languages. |
nemo (145) 2563 posts |
Rick also mentioned:
What I think is more amusing is that <insert C compiler of choice> is written in C. Trace that back! |
Rick Murray (539) 13857 posts |
;-)
How is this different to converting
I’m not sure what you are trying to say here – weren’t we talking about porting C to assembler? Actually, I would imagine it would be possible to implement stdlib in C without assembler – at least under RISC OS with a wide range of OS routines to call using _kernel_swi() – however doesn’t that rather defeat the purpose of a library?
You have to bend over backwards to get object pointers out of VB – and they’re only there because parts of the Win32 API require it.
I remember CFront. Its code output was…interesting.
I’ll await a bootloader written in Ruby. ;-)
Logically the first was written in code until it was capable of compiling itself, and then cross compilation, and… Although personally I prefer the “chicken or egg” conundrum. It’s more fun. |
Rick Murray (539) 13857 posts |
I should add, a long time ago I wrote a broken, horrid, partial C interpreter in BASIC. T’was the product of too much free time… |
Tim Rowledge (1742) 170 posts |
Good idea :-) The next part, and one that may well not be possible any time soon, is getting sound input to Squeak. Anybody have clue about that? Bonus points if it can be done using any of the nice stream and buffer management code John Duffell provided for the output, because that is nice code. |
Rick Murray (539) 13857 posts |
Whoa. Could you try this MIDI file and let me know how it plays? http://www.mediafire.com/?apana50y9sqhkey Also: Sheet music (PDF), the transcriber’s website, and a YouTube of the guy playing it on his piano – epic win (let’s just say I reckon I’ll never be that good…). It is simpler than a many-instrument MIDI, however some of the notation is pretty fast – as can be seen from the sheet (you don’t have to be able to read music, just look at all those lumpy things piled on top of each other!).
That makes a lot more sense. Busy-waits are optimal if your system if running at full capacity. For instance, the little I have looked at the FileStore E01S code, it appears to busy-wait floppy accesses because there’s a danger of losing data if the system has to rely on interrupts.
Well, the first thought is that it will depend upon the hardware. For instance, the Beagle has an audio input. The RPi does not. Of the audio input, this sort of presupposes something in the OMAP3 (or that JackOfAllTrades helper chip!) is capable of accepting audio input, which means there may well be a defined API like “set up some registers and await the thing interrupting to read out raw sample data”.
Don’t know this code (never looked). If the API is extensible/open enough to cater for input as well as output, it may be possible? |
Tim Rowledge (1742) 170 posts |
Ok Rick,I’ll give your midi file a go tomorrow. Assuming that I can get past whatever stupid bug is making things annoying this evening. I’ve been trying to hook up the (supposed) pollword stuff and I’ve clearly grabbed the wrong stick, let alone the wrong end. And for DavidS, there isn’t any sort of official Scratch for RISC OS yet. I’ve seen reports of a few people trying the unix image out on ancient Squeak virtual machines with some apparent success but once I’ve got his sound sorted out I’ll release a more set up system. I got the Scratch support code working yesterday, which makes a few graphics operations faster, supports Scratch’s rather odd idea of where files live, lets it open URLs in Netsurf and change the window title to match your project name. Nothing big but it stops some silly bugs that the Scratch guys could have handled a lot better with some thought. Just a thought – your tutorials really ought to mention at least in passing that there has been 25 years of Smalltalk on RISC OS! All my fault… |
Rick Murray (539) 13857 posts |
Are you it using a module-supplied pollword, or an application-supplied one? If the latter case, remember the pollword must be allocated in the module area (so it can be set even when your application has been paged out). |
Dave Higton (1515) 3535 posts |
Tim: are you being given a pollword, or a pointer to a pollword? Are you nulling a pointer? |
Tim Rowledge (1742) 170 posts |
I’m (trying ) using the module provided pollword, which on examining the doc provided more carefully is described as ‘should be treated as an opaque word and only compared with 0’. So with code changed to not zero it after polling, less goes wrong. if (available space < smallish number of samples) { wait until ReadySemaphore is signalled} The problem with the current poll word setting scheme is that the sound system sets it when an internal buffer has been read – i.e. there is now at least one buffer available. Which reminds of another faintly related problem that should probably go in another thread – I have a small module that works with Rik Griffin’s HALTimer (see relevant thread on the fun we had with that) to keep a millisecond timer up to date. I lost the source code BASIC file. I can’t find any simple explanation or tutorial on writing a trivial module. I can’t compile any of the example module code in the nutPi DDE examples because some libraries are not provided. Any advice? Anyon by any chance stashed away a copy of the source BASIC prog for ‘MillisecondTimer’ ? |
Rick Murray (539) 13857 posts |
Yes, I see that there is an HTML document that is better than the text file:
Does John not fully understand what a PollWord is for? Non-zero means the foreground application is polled, zero means it is not. Things signalled by the pollword can be specified by the pollword value (specific bits, etc). When the action has been performed, the pollword should be reset to zero or else, as you noticed:
[reference: https://www.riscosopen.org/wiki/documentation/show/PollWord_NonZero ] As the sources are provided, I would suggest that you Something that concerns me is “it will be cleared when a block cannot be fitted into the buffer” – surely this is something you want to notify to the foreground application? Clearing the pollword will result in the foreground application not being polled.
Pure assembler: http://www.heyrick.co.uk/blog/index.php?diary=20120528 |
Rick Murray (539) 13857 posts |
I have a little something for you… I was bored and forgot I had Chihayafuru to watch, so I figured a smallish module shouldn’t take to long to unpick. [whinge]It annoys the hell out of me when you are spending half the time looking at code and half the time looking in literature and half the time trying to work out where loops and other constructs begin and end as the formatting is crappy (one of my pet hates is the school of C programming where the braces are on the same line as the code, like “int myfunc(void) {”. Yuck! Yuck! Yuck! I use the Allman style; the K&R style is horrible IMHO). And yes, I know I listed three halves. That’s what it is like reading unclear code! Anyway, Tim, here’s the start…
Interested? You’ll find the rest here: http://www.heyrick.co.uk/random/MillisecondTimerReassemblyText.txt TEXTLOAD it into BASIC and run it, it should create a module that matches the original. Note 1: I can’t guarantee the MSR syntax is correct for BASIC. I’m using an emulator with a much older RISC OS (doesn’t do MSR at all!) so I used EQUD to drop in the instruction coding directly. Note 2: All those (annoying?) “##TODO##” markers are things in the code that seem “unusual”. Explanations given. I just dropped these in as I was transcribing it from a raw disassembly. Feel free to ignore the commentary. ;-) Have fun! |
Tim Rowledge (1742) 170 posts |
Wow, thanks Rick. Umm, doesn’t/didn’t ARMalyser do some of the “making vaguely sensible ASM file” part of unpicking a module/aif ? The good news is this is a really simple module with a whole not (or two? I forget) SWIs and a just one command. At least we don’t need to unpickSharedStreamBuffer :-) What’s really scary to recall is that I used to be able to make reasonable sense of ARM object code in hex. Worse yet, for a short while in the mid 90s I could debug PPC hex code – I had to do that once at Apple HQ in order to get a version of our Smalltalk product running on the newer memory model; no source code to hand, find where something went wrong, recognise the pattern, recall the earlier talk about the change, manually insert the correct bytes to fix the instruction and… it worked. Scary what a mind can manage at times. So progress today is curious; I cleaned up a load of code and made a RMA allocation for my very own pollword space, tried to remember the details of what &(int **)foo might mean and.. it didn’t work properly. Much swearing and debugging later, my subconscious decided to remind me that I had in fact looked at the ask code for this part of the module and maybe I should check it again; yup – the flag usage for "module supplies pollword " vs “user supplies address of their poll word” was flipped in the doc. Sigh. RIght now it’s running a lot more smoothly but I’ve broken something to do with pausing the system when there is no more to play and then restarting when new sounds come in. Oh well. And yes, I agree about proper documentation. My old boss – a formidable lady by the name of Adele Goldberg, who could stop Jobs in his tracks with a glance – used to point out that “if it isn’t documented it might as well not exist and if it doesn’t exist then why, exactly, did we pay you?” More progress tomorrow. |
Ralph Barrett (1603) 154 posts |
Ahem. Just downloaded Rick’s code as I’m trying to get back into ARM assembler again after a similar break of time. In case others are downloading the full code, there appear to be a couple of very minor typos in Rick’s code. Missing “$” on one “CHR” and an extra “$” on another CHR$. These are just normal BBC BASIC functions but used in the assembler to insert a character. .title CHR should be CHR$(0) later… CHR$$(0) should be CHR$(0) Apart from that, the module appears to be created when the programme is run from BASIC (I’ve not checked the actual module in any way). Ralph |
Rick Murray (539) 13857 posts |
You’re welcome.
Yes, but it is only good for large projects where manual work is unfeasible. If you look at my code vs ARMalyser, you’ll be able to get on better with mine – things have sensible names (instead of being labelled by address) and there is a much deeper level of commentary as I can see what API calls are being made. Or, in short, there is a vast gulf between seeing the code and understanding the code. ;-)
True. That’s why I did it.
Hehe, I’m having enough trouble reading the source thanks to K&R formatting.
Whoa! Impressive! I did know some 6502 in hex, namely where to fiddle comparisons and insert NOPs. But not being word-aligned and not having as powerful disassembly tools, it was necessary to do more in your head.
Anybody who can speak a foreign language dissimilar to their own is impressive. Double points if they are able to read/write Japanese/Chinese (ideographic languages). Those people who can “hear” something once and then play it correctly on the instrument of their preference. We program the ARM. A whole different class of awesome are the people who make the ARM. Lastly, but not least, anybody who delves into Quantum Physics and doesn’t freak out within the first hour when they realise their perceptions of reality are a thin illusion. Yeah, there’re a ton of people way smarter than me. ;-) Pretty amazing what can happen inside one person’s brain. …but, have you ever had one of those dreams with a cast of dozens and dozens of people all working autonomously (like real people) and you wake up and think “who the hell were they?!”?
Hehe… I try hard to avoid stuff like that in my code. Err… the address of a pointer-to-a-pointer pointed to by “foo” (which is cast as an int)?
Oh, yes. The “documentation errors”. The bane of programmers everywhere. |
Rick Murray (539) 13857 posts |
Fixed. ;-)
|
Tim Rowledge (1742) 170 posts |
Ugh. Well, I think sound is now working with all the plausible combinations that Squeak can throw at it. I’m not entirely convinced that there isn’t a pointer to the RMA space I’m using for the poll word getting, shall we say, a little confused. A few times I’ve had a ‘not a heap block’ error come up and it isn’t very easy to trace. There’s also a chance it is a buglet in the sound stream/buffer code but let’s see what happens to other users. It plays the SparklingDaydream midi with no problems and in fact copes perfectly well with simultaneously playing that, tubular bells, poker face and random hits on the piano keyboard. Not a noise you want to hear too often! A testable package coming soon. Ish. |
Tim Rowledge (1742) 170 posts |
Righty-ho; try http://www.rowledge.org/tim/squeak/Squeak3-9c-RISCOS.zip to download a bundle of the entire squeak setup, including the DeepKeys and SharedSoundBuffer modules, the Squeak .source file already installed and the image/changes file ready to go. For a very sketchy Scratch try-out, try downloading http://www.rowledge.org/tim/squeak/Scratch-RISCOS.zip – but you’ll need to have grabbed theSqueak package first in order to have the deepkeys/ssb modules. Let me know how it works on your machines… |
nemo (145) 2563 posts |
Rick frothed:
Well, that’s what style guides are for. Brace yourself. In my experience, anyone whinging about where braces are doesn’t know perl. In fact, anyone complaining about any language that isn’t perl, doesn’t know perl. |
Steve Pampling (1551) 8175 posts |
Don’t know it, just keep having to do things with it. I swear the Perl FAQ is longer than the RO documentation. |
nemo (145) 2563 posts |
perl’s great crime is having slightly more utility than its copious faults, so it sits there as though butter wouldn’t melt in its mouth promising “use me, I’ll make that job so easy” while maintaining the total amount of entropy in the universe by substituting the difficulty of the job for the difficulty of its syntax. |
Rick Murray (539) 13857 posts |
No, that’s what Holy Wars are for. ;-)
Boom-boom! I take it perl is an obnoxious language? It could be worse. The Funge98 version of Befunge is apparently Turing Complete – imagine if utility scripts for Internet things looked like this:
It is actually part of a Sudoku solver. Full version here (and dig that domain name). My head hurts. You were saying what about perl? ;-) |
patric aristide (434) 418 posts |
Bah, could be worse ;-P
|