ikn
Posts: 16
Joined: Sun Dec 15, 2019 1:07 pm

Scratch 1.4 Squeak is almost out of memory. Already compressed sounds

Mon Dec 30, 2019 4:29 pm

I,ve doing a Scratch project which will be used as a music player with gpio buttons. I have managed to get it to autostart etc and everything was going well. I initially tried my project with just four songs just to test how it would react to button presesses etc. I need 100 songs (ranging from approx 3 to 5 minutes long), so kept adding more, but when it got to 60 songs the following message popped up: “Warning! Squeak is almost out of memory!” Obviously because of all the songs I added. I had no idea this could happen before I started my Scratch project. I really need 100 songs. Wha t I would like to know, is there a way to expand the Scratch / Squeak memory to accommodate the extra songs. I have already compressed them to their lowest sound quality using the edit feature in Scratch which brought each song down to an average of 9000KB. I am completely stuck. Any suggestions would be appreciated.

ejolson
Posts: 4260
Joined: Tue Mar 18, 2014 11:47 am

Re: Scratch 1.4 Squeak is almost out of memory. Already compressed sounds

Tue Dec 31, 2019 12:52 am

ikn wrote:
Mon Dec 30, 2019 4:29 pm
I,ve doing a Scratch project which will be used as a music player with gpio buttons. I have managed to get it to autostart etc and everything was going well. I initially tried my project with just four songs just to test how it would react to button presesses etc. I need 100 songs (ranging from approx 3 to 5 minutes long), so kept adding more, but when it got to 60 songs the following message popped up: “Warning! Squeak is almost out of memory!” Obviously because of all the songs I added. I had no idea this could happen before I started my Scratch project. I really need 100 songs. Wha t I would like to know, is there a way to expand the Scratch / Squeak memory to accommodate the extra songs. I have already compressed them to their lowest sound quality using the edit feature in Scratch which brought each song down to an average of 9000KB. I am completely stuck. Any suggestions would be appreciated.
I'm hoping someone has a better idea, but my thought is that what you are trying to do is much more difficult using Scratch than, for example, Python. The reason for this is because Scratch was designed to get kids interested in programming, not to actually create practical programs.

My advice is no one should spend more than a couple months on Scratch before moving on. After that a person runs into limitations and spends more effort developing clumsy ways to work around them than necessary to learn a proper programming language all over.

At this point it may seem like that so much progress has been made that starting over with Python would be unbearably difficult. My experience is that things go much faster the second time around, especially when the right tool is used for the job.

timrowledge
Posts: 1317
Joined: Mon Oct 29, 2012 8:12 pm
Location: Vancouver Island
Contact: Website

Re: Scratch 1.4 Squeak is almost out of memory. Already compressed sounds

Tue Dec 31, 2019 10:34 pm

Well if your music samples are actulaly typically 9000kb - ie 9Mb, then 100 of them is almost the entirety of a Pi's memory. You can't be surprised if Scratch - or any program - complains about getting short of memory when loaded up that much!
Your problem is that the way Scratch handles sounds is to load them into memory rather than play from a file. That means there is a hard limit on the amount of sound data that can be loaded.
So, there are at least a couple of ways around this
a) the obvious one of simply reducing the number of sound samples you load into a single scratch project.
b) rewrite your system in some manner. Of course, a lot of people around here will urge you to do it in Python and you may prefer to do that. However, I suggest considering using Smalltalk, the language that Squeak is built in. All the sound handling and gpio reding that I think you're interested in are easily dealt with in Squeak Smalltalk. Let me know...
Making Smalltalk on ARM since 1986; making your Scratch better since 2012

ikn
Posts: 16
Joined: Sun Dec 15, 2019 1:07 pm

Re: Scratch 1.4 Squeak is almost out of memory. Already compressed sounds

Wed Jan 01, 2020 3:38 pm

timrowledge wrote:
Tue Dec 31, 2019 10:34 pm
Well if your music samples are actulaly typically 9000kb - ie 9Mb, then 100 of them is almost the entirety of a Pi's memory. You can't be surprised if Scratch - or any program - complains about getting short of memory when loaded up that much!
Your problem is that the way Scratch handles sounds is to load them into memory rather than play from a file. That means there is a hard limit on the amount of sound data that can be loaded.
So, there are at least a couple of ways around this
a) the obvious one of simply reducing the number of sound samples you load into a single scratch project.
b) rewrite your system in some manner. Of course, a lot of people around here will urge you to do it in Python and you may prefer to do that. However, I suggest considering using Smalltalk, the language that Squeak is built in. All the sound handling and gpio reding that I think you're interested in are easily dealt with in Squeak Smalltalk. Let me know...
Reading your post has just reminded me that I have made a mistake in my original post. When I import MP3 and WAV files , Scratch converts them and makes MP3 files larger and WAV files smaller. Strangely enough MP3 and WAV files are then exactly the same size as each other (approx 9000KB). What I should have said in my original post is that when the 60 song files are then further compressed in Scratch they are now on average 1100KB each, not 9000KB like I originally stated. It is only the Scratch program which runs out of memory (reading up about it now , it seems projects in Scratch have a limit of 50mb for some reason. I wish I had known this before I started using Scratch). The Raspberry Pi itself should handle a lot more than 100 songs even at their uncompressed size, I assume it's only limited by the particular program you use and storage space on SD card or am I mistaken. Any thoughts from anybody on that would be appreciated as well. In the meantime I will take a look at Squeak Smalltalk like you suggested.

timrowledge
Posts: 1317
Joined: Mon Oct 29, 2012 8:12 pm
Location: Vancouver Island
Contact: Website

Re: Scratch 1.4 Squeak is almost out of memory. Already compressed sounds

Thu Jan 02, 2020 2:36 am

ikn wrote:
Wed Jan 01, 2020 3:38 pm
(reading up about it now , it seems projects in Scratch have a limit of 50mb for some reason. I wish I had known this before I started using Scratch).
That's curious; I don't recall ever reading anything aobut that whilst doing the Scratch development work - but then I never tried to push the size of project files.
ikn wrote:
Wed Jan 01, 2020 3:38 pm
The Raspberry Pi itself should handle a lot more than 100 songs even at their uncompressed size, I assume it's only limited by the particular program you use and storage space on SD card or am I mistaken. Any thoughts from anybody on that would be appreciated as well. In the meantime I will take a look at Squeak Smalltalk like you suggested.
The problem here is that adding a sound sample to a Scratch project simply copies into the project and does some conversion (if needed) to a suitable data form. Then you write out the project and all the sound data as well as your scripts is written to a file.

I think what you probably want is a system where you have a directory of sound files, a program that reads some gpio attached buttons and plays the matching sound file - is that what you're really after? And IIRC you want this to start at boot, be headless and Just Work?
Making Smalltalk on ARM since 1986; making your Scratch better since 2012

ikn
Posts: 16
Joined: Sun Dec 15, 2019 1:07 pm

Re: Scratch 1.4 Squeak is almost out of memory. Already compressed sounds

Thu Jan 02, 2020 1:15 pm

timrowledge wrote:
Thu Jan 02, 2020 2:36 am

I think what you probably want is a system where you have a directory of sound files, a program that reads some gpio attached buttons and plays the matching sound file - is that what you're really after? And IIRC you want this to start at boot, be headless and Just Work?
That is correct. I have 20 momentary buttons. 10 of which are labelled with numbers and the other 10 with letters. When a certain number button and letter button are pressed at same time then it will play a particular song associated with that particular number/letter combination. There are 100 button combinations, so in total 100 different songs can be selected.

timrowledge
Posts: 1317
Joined: Mon Oct 29, 2012 8:12 pm
Location: Vancouver Island
Contact: Website

Re: Scratch 1.4 Squeak is almost out of memory. Already compressed sounds

Wed Jan 08, 2020 8:39 pm

If you’d like to post some descriptions of how you connected the buttons, which gpio pins you used etc I might be able to do something for you. It’s an interesting problem.
Perhaps zip the Scratch project file too and upload it?
Making Smalltalk on ARM since 1986; making your Scratch better since 2012

ikn
Posts: 16
Joined: Sun Dec 15, 2019 1:07 pm

Re: Scratch 1.4 Squeak is almost out of memory. Already compressed sounds

Wed Jan 15, 2020 5:34 pm

timrowledge wrote:
Wed Jan 08, 2020 8:39 pm
If you’d like to post some descriptions of how you connected the buttons, which gpio pins you used etc I might be able to do something for you. It’s an interesting problem.
Perhaps zip the Scratch project file too and upload it?
I have just tried it again with an empty project (no blocks) and with 60 songs imported and compressed and with no GPIO buttons but it still has the memory problem as soon as any more songs are added. It seems Scratch can't handle any more songs. It's a shame really because it seemed to be working well. There doesnt't seem to be any more that can be done to condense the project. I tried Scratch2 but this would only take 25 songs before the memory problem started.

timrowledge
Posts: 1317
Joined: Mon Oct 29, 2012 8:12 pm
Location: Vancouver Island
Contact: Website

Re: Scratch 1.4 Squeak is almost out of memory. Already compressed sounds

Thu Jan 16, 2020 2:28 am

Yeah, I can’t do any magic to make sound samples smaller but I probably can do some to make a way to play sounds from named files instead of samples loaded in the project file.
Failing that I can certainly make a way to do it in straight Smalltalk. Like I said, an interesting problem.
Making Smalltalk on ARM since 1986; making your Scratch better since 2012

ejolson
Posts: 4260
Joined: Tue Mar 18, 2014 11:47 am

Re: Scratch 1.4 Squeak is almost out of memory. Already compressed sounds

Thu Jan 16, 2020 3:12 am

timrowledge wrote:
Thu Jan 16, 2020 2:28 am
Yeah, I can’t do any magic to make sound samples smaller but I probably can do some to make a way to play sounds from named files instead of samples loaded in the project file.
Failing that I can certainly make a way to do it in straight Smalltalk. Like I said, an interesting problem.
How hard is it too make a new block in scratch that simply plays the specified music file from the filesystem?

timrowledge
Posts: 1317
Joined: Mon Oct 29, 2012 8:12 pm
Location: Vancouver Island
Contact: Website

Re: Scratch 1.4 Squeak is almost out of memory. Already compressed sounds

Thu Jan 16, 2020 8:46 pm

Dunno. That’s one of the options I might try. Another, possibility simpler to do, is to add it to the built-in gpio server I added way back.
Making Smalltalk on ARM since 1986; making your Scratch better since 2012

ejolson
Posts: 4260
Joined: Tue Mar 18, 2014 11:47 am

Re: Scratch 1.4 Squeak is almost out of memory. Already compressed sounds

Thu Jan 16, 2020 10:05 pm

timrowledge wrote:
Thu Jan 16, 2020 8:46 pm
Dunno. That’s one of the options I might try. Another, possibility simpler to do, is to add it to the built-in gpio server I added way back.
That sounds reasonable. I find it's always important for a GPIO server to have the ability to play arbitrary music files directly from the filesystem. Have you considered adding a feature for sending and receiving email as well?

By the way, since we haven't been frequenting the same discussion threads recently, have a Happy New Year!

ghp
Posts: 1456
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: Scratch 1.4 Squeak is almost out of memory. Already compressed sounds

Sat Jan 18, 2020 10:01 am

scratchClient allows to play sounds using Linux aplay tool, see http://www.heppg.de/download/scratchCli ... line_aplay
There is also control for sonic pi available, there is an entry in my blog http://heppg.de/ikg/wordpress/?p=960

timrowledge
Posts: 1317
Joined: Mon Oct 29, 2012 8:12 pm
Location: Vancouver Island
Contact: Website

Re: Scratch 1.4 Squeak is almost out of memory. Already compressed sounds

Sat Jan 18, 2020 9:08 pm

ejolson wrote:
Thu Jan 16, 2020 10:05 pm
By the way, since we haven't been frequenting the same discussion threads recently, have a Happy New Year!
Well thanks; same to you. Been busy the last couple of years being a CTO for an Ottawa based AI/Smalltalk company. I am hoping to do a refresh release of Scratch soon in order to update it to run in Squeak 5.3. A. bit faster, include full access to the Smalltalk behind the scenes, make sure it can be used easily for the sort of amusing script stuff that was discussed for the infamous ‘million character Fibonacci number ‘ thread.
Making Smalltalk on ARM since 1986; making your Scratch better since 2012

timrowledge
Posts: 1317
Joined: Mon Oct 29, 2012 8:12 pm
Location: Vancouver Island
Contact: Website

Re: Scratch 1.4 Squeak is almost out of memory. Already compressed sounds

Sat Jan 18, 2020 9:11 pm

ghp wrote:
Sat Jan 18, 2020 10:01 am
scratchClient allows to play sounds using Linux aplay tool,
I was just about to post a bet that you had already done this. So now the challenge is to help ikn work out installing it and converting their Scratch project. Cool!
Making Smalltalk on ARM since 1986; making your Scratch better since 2012

Return to “Scratch”