[Microbit-Python] J.S.MicroBach

Damien George damien.p.george at gmail.com
Thu Sep 24 00:45:21 CEST 2015


Hi Nicholas,

I did a bit of coding and managed to reduce the parser RAM usage by
around 30%.  So now your bach.py works fine and you can dir() at the
REPL.

music.py still has memory issues, but it's no longer in the compiler.
It's the fact that you have 3 big lists containing the tune: the first
is the one in the script, the second is the one that the first is
expanded to (with note, octave and duration) and the third is the
notes list in the Tune object.

I've adjusted the script so that it plays the tune directly from the
list in the script (so only has one big list).  See attached.  It
works very well and the tune is awesome!  I love the beepy-bloopy
sound.

BTW, you'll need to git pull and recompile the firmware to take
advantage of the new RAM improvements.

Cheers,
Damien.


On Wed, Sep 23, 2015 at 11:33 PM, Michael <sparks.m at gmail.com> wrote:
> That's *really* fun :-)
>
>
> Michael.
>
> On 23 September 2015 at 21:42, Nicholas H.Tollervey <ntoll at ntoll.org> wrote:
>>
>> Hi Folks,
>>
>> So it's not exactly amazing quality sound... in fact, I've basically
>> made one of those bloody annoying bloopy-bleep-bleep birthday cards, but
>> this:
>>
>> https://www.youtube.com/watch?v=4L12BP64AQM
>>
>> :-)
>>
>> Great work Matthew (whose work I've adapted to make this work). You
>> pretty much nailed it, although I've changed the musical representation
>> a little and I feel there's a tad more to do to make it child-friendly
>> and familiar given other music representation systems on the computer.
>>
>> Damien, please find attached two scripts:
>>
>> The first script, bach.py, is what is flashed onto the device in the
>> demo. When I connect to the REPL I get this...
>>
>> >>> dir()
>> Traceback (most recent call last):
>>   File "<stdin>", line 1
>> MemoryError: parser could not allocate enough memory
>>
>> I'm guessing we've run out of RAM. Given the code (and my lack of
>> experience writing for embedded platforms with MicroPython) any hints on
>> what I could do?
>>
>> The second script, music.py, is essentially the same as the first but
>> with more of the music added to the notes list. When I try to flash the
>> device I see the following scrolling across the screen:
>>
>> memory allocation error
>>
>> I'm guessing the script is simply too big to compile given the 16k RAM
>> we have available..?
>>
>> Hey ho... I'm guessing this is a similar situation to David's pancake
>> game.
>>
>> This is a GOOD THING for us to encounter. At the very worst we'll be
>> unable to do anything about it in a technical sense so will have a heads
>> up and time to get the messaging of such states correct so users have a
>> chance to work out what's going on.
>>
>> My feeling is that we could create a whole new music based namespace
>> under microbit (i.e. microbit.music) containing things like the
>> following made up off the top of my head in a hand-wavy sort of a way:
>>
>> microbit.music.Tune - based on Matthew's class demonstrated in the video
>> but implemented in C.
>> microbit.music.play('c', 1, 1000) - play the note C in octave 1 for 1
>> second.
>> microbit.music.pitch(440, 1000) - play the pitch for 1 second. The play
>> method above is basically a friendly wrapper around this one.
>> microbit.music.stop() - what you'd expect ;-)
>>
>> The final millisecond argument to the play and pitch methods could be
>> optional (the device just keeps playing the note until it's changed). We
>> could then use the accelerometer to change the pitch etc...
>>
>> Also, we could use the wait keyword as Damien suggested with the display
>> methods to make musical things run in the background.
>>
>> Does this make sense..?
>>
>> As always, ideas, constructive critique and feedback is most welcome!
>>
>> All the best,
>>
>> Nicholas.
>>
>> _______________________________________________
>> Microbit mailing list
>> Microbit at python.org
>> https://mail.python.org/mailman/listinfo/microbit
>>
>
>
> _______________________________________________
> Microbit mailing list
> Microbit at python.org
> https://mail.python.org/mailman/listinfo/microbit
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: music.py
Type: text/x-python
Size: 3284 bytes
Desc: not available
URL: <https://mail.python.org/mailman/private/microbit/attachments/20150923/115e4dca/attachment.py>


More information about the Microbit mailing list