1 Bit Sound

Post your nifty GP projects here!

Moderator: MSandro

Post Reply
mguzdial
Posts: 70
Joined: Sep 15th, '15, 11:21

1 Bit Sound

Post by mguzdial » Oct 4th, '15, 00:27

This one involves a little bit of block-dragging to get the full effect.

(1) Drag the get samples from thisisatest into the "array" slot of the play samples from block, connected to "Go." Press Go. That's our original sound.

(2) Drag the getSamples block out and click on it. Notice that what's inside those samples are real numbers between -1.0 and +1.0.

(3) Click the button to set newsound to a list with only a "1" in it.

(4) Now, drag the getSamples block into the array slot of the for loop block, with the two ifs in it. This loop will create a new sound with *ONLY* -1 and +1 in it. Click to execute the block script.

(5) Now click on the newsound block by itself. It ONLY has -1 and +1 in it.

(6) Drag the newsound block into the play block. BEFORE YOU HIT "Go," ask yourself, "Will you hear the words 'this is a test'?"
Attachments
1bitsound.gpp
(137.5 KiB) Downloaded 54 times

mguzdial
Posts: 70
Joined: Sep 15th, '15, 11:21

Re: 1 Bit-per-sample Sound - now with display

Post by mguzdial » Oct 5th, '15, 17:00

The 1-bit-per-sample sound story works better if you can see the sound, so I put together a simple sound visualization script.

Here's the original "this is a test" sound.
thisisatest.png
Here's the 1 bit per sample version.
1-bit-sound.png
Side note: I'd love a "video" format where I could record the actions needed to make this work, but freezable/modifiable at any point, and the student could play from there. I think that this is how the programming recordings in Khan Academy work, but I've not tried them.
Attachments
1bitsound-v2.gpp
(138.58 KiB) Downloaded 61 times

JohnM
Posts: 379
Joined: Sep 11th, '15, 14:42

Re: 1 Bit Sound

Post by JohnM » Oct 6th, '15, 15:34

This is SO cool! I love that you were able to create your own sound visualizations in GP.

I just recently learned how to make a screen recording using Quicktime Player, which comes with Mac OS. You start Quicktime Player and select "New Screen Recording" in the menu. You can record the entire screen, the contents of one window, or just a section. To stop recording, click the stop button in the Mac menu bar. (When I first did this, I recorded only a portion of the screen and the stop button in the menu bar appeared to be grayed out, so it took me a while to figure out how to stop recording.) Once you've got the recording, you can actually do some simple video editing using the "split clip" command in the Edit menu. I assume you could add narration or a background music using iMovie, although I haven't tried that.

mguzdial
Posts: 70
Joined: Sep 15th, '15, 11:21

Re: 1 Bit Sound

Post by mguzdial » Oct 7th, '15, 17:00

I'll try the Quicktime recorder -- thanks!

An item for the wishlist: I now have this script that can (crudely) let me see a waveform. I'd love to be able to encapsulate this script in a block that I could put into the block pane -- across projects. There are lots of places where I'd like to be able to visualize a sound.

mguzdial
Posts: 70
Joined: Sep 15th, '15, 11:21

Re: 1 Bit Sound, or, how to make an extension block from a blocks script

Post by mguzdial » Oct 7th, '15, 18:30

I wanted to see how hard it was to go from blocks into an extension, so I tried it with the sound display code. It really wasn't hard at all!

Here's my original script, and the new block that I created.
set-costume-from.png
I converted the script to text, then copy-pasted it into my samples extension. Here's what that looked like:

Code: Select all

whenKeyPressed 'space'
local 'sound' (getSamples 'bassoon-g4')
self_createCostume 500 300
self_fillWithColor (colorSwatch 231 231 231 255)
local 'x' 10
for sample (stepSample ((count sound) / 500) sound) {
  h = (100 * sample)
  self_fillRect x (150 + h) 2 2 (colorSwatch 32 107 221 255)
  x += 1
}

To turn this into a callable script, I made these modifications:

Code: Select all

to displaySound s1 {
  self_createCostume 500 300
  self_fillWithColor (colorSwatch 231 231 231 255)
  local 'x' 10
  for sample (stepSample ((count s1) / 500) s1) {
    h = (100 * sample)
    self_fillRect x (150 + h) 2 2 (colorSwatch 32 107 221 255)
    x += 1}
}
And added to the AuthoringSpecs array:

Code: Select all

  (array ' '	'displaySound'		'set costume from samples _' 'array' nil)
It worked! It's super cool to have this block anywhere now. (I've attached the project where I'm playing with this, and the version of samplesExtension with the new set costume block.)
Attachments
1bitsound-v3.gpp
(598.96 KiB) Downloaded 55 times
samplesExtension.gp
(5.37 KiB) Downloaded 59 times

Post Reply