This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
TomyLobo's profile picture

[1.4.7] [CC 1.481] CCNoise - generate custom sounds

Started by TomyLobo, 01 May 2013 - 08:08 PM
TomyLobo #1
Posted 01 May 2013 - 10:08 PM
Purpose:
Adds a speaker peripheral that can generate sounds given a formula and also play any minecraft sound.

Download:
0.0.4c (Beta)

Video:
Spoilerhttp://www.youtube.com/watch?v=yu2eT2yygW8

Interface:
Spoilerspeaker.generateFunctional(soundName, expression, length)
- Generate a sound using the "functional" method.

Sound names prefixed with a '#' are local sounds specific to the speaker/computer pair.

Example: speaker.generateFunctional("#sin440hz", "sin(2*pi*440*t)", length) – Generates a 400 Hz tone

The expression library is described here: http://wiki.sk89q.co...pression_syntax
In addition to the functions there, I added some functions specific to waveform generation:
- sine(state, frequency) – sine wave -1..1
- rect(state, frequency) – rectangular wave -1..1
- triangle(state, frequency) – triangular wave -1..1
- sawtooth(state, frequency) – sawtooth wave 0..1

In these, "state" is supposed to be a variable containing the last phase value for the generator

I also have some badly implemented noise functions. Help with doing these properly would be appreciated :)/>/>/>/>
- whitenoise() – basically random()*2-1
- pinknoise() – copied the algo from some page - might be broken
- last = brownnoise(last, factor) – might be correct, but I'm not sure

speaker.playSound(soundName, volume, pitch)
- Plays the given Minecraft sound or generated sound.

Example: speaker.playSound("mob.ghast.moan", 1, 1) – Scares everyone around
Example: speaker.playSound("#sin440hz", 1, 1) – Plays the 400 Hz tone we generated above

speaker.eval(expression)
- This is for testing purposes only and I'll probably remove it in a future version

Config:
Spoilerblock.speakerBlockID
- The block ID for the speaker block (default=1310)

speaker.allowPlayRegularSounds
- Allow speaker.playSound to play regular sounds (default=true)

speaker.allowGenerateSounds
- Enable the speaker.generate* functions (default=true)

speaker.allowGenerateGlobalSounds
- Allow the speaker.generate* functions to generate globally accessible sounds and potentially override existing sounds (default=true)

Credits:
- Texture by MrFaul
- build.xml taken from OpenCCSensors
- tiny bits and pieces as well as some concepts from PortablePeripherals by mentlerd

Changelog:
Spoiler0.0.4c (Beta)
- REALLY fixed sound playing in the nether this time.

0.0.4b (Beta)
- Fixed sound playing in the nether.

0.0.4a (Beta)
- No longer crashing everyone who is out of range or in another dimension when generating a sound.

0.0.4 (Beta)
- Clamped output to -1..1.
- The sawtooth function's output is now 0..1 instead of -1..1.

0.0.3 (Beta)
- First public release

Known issues:
- Sound names cannot end in a digit.
- In SMP, generated sounds might not be unloaded on the client after a computer reboots.
- Other players get jumpy when I run my ghast sound simulator.
- The speaker block has two front sides when dropped to the floor as an item.
- CCNoise does not behave well when the sound is set to 0%. If you connect to a server that has generated sounds loaded, the client crashes.

Source:
The source code is available at https://github.com/TomyLobo/ccnoise under the LGPLv3 (until someone makes a valid case for another license)
sci4me #2
Posted 01 May 2013 - 10:46 PM
cool!
TomyLobo #3
Posted 02 May 2013 - 08:02 AM
0.0.4 (Beta)
- Clamped output to -1..1.
- The sawtooth function's output is now 0..1 instead of -1..1.
TomyLobo #4
Posted 02 May 2013 - 09:50 AM
0.0.4a (Beta)
- No longer crashing everyone who is out of range or in another dimension when generating a sound.
TomyLobo #5
Posted 02 May 2013 - 11:54 AM
CCNoise does not behave well when the sound is set to 0%. If you connect to a server that has generated sounds loaded, the client crashes.

Seriously, Mojang, wtf?
TomyLobo #6
Posted 02 May 2013 - 01:14 PM
0.0.4b (Beta)
- Fixed sound playing in the nether.
TomyLobo #7
Posted 02 May 2013 - 08:01 PM
0.0.4c (Beta)
- REALLY fixed sound playing in the nether this time.
Tiin57 #8
Posted 02 May 2013 - 08:12 PM
This is pretty cool. +1.
TecmagDiams #9
Posted 02 May 2013 - 10:01 PM
Looks awesome! Would love to see a screenshot of what the speaker looks like, and a CCDesk plugin for it, but I can't wait to try it out and mess around with it!
TomyLobo #10
Posted 03 May 2013 - 06:54 AM
CCDesk? the HTTP server thingie?

I made a demonstration video btw:
http://www.youtube.com/watch?v=yu2eT2yygW8
immibis #11
Posted 03 May 2013 - 07:37 PM
CCDesk is a CC emulator.
TomyLobo #12
Posted 04 May 2013 - 08:24 AM
and people emulate their programs end-to-end in that?

I'm asking because if they don't, I don't see much point in doing a minor detail like sound output in CCDesk.
I'd also need to write sound output from scratch, which seems like a huge waste of time for such a tiny benefit.

Sure, I guess I could make a peripheral that just has the interface and does nothing
TecmagDiams #13
Posted 04 May 2013 - 08:59 AM
By no means do I think you need to push to make a CCDesk plugin, but it's just a nice extra to have. I personally enjoy emulators, because if I'm working from a computer that isn't mine, I can still boot up my GoogleDrive and an emulator like CCDesk (because of it's online version) and keep coding things for my server. It's also nice because if I wanted to play around with a peripheral, without actually adding it to my server, I could see how the peripheral works and then add it to my server if I've coded some really fun stuff with it, that I could really put to use.

And yes, people can emulate programs end-to-end. I usually like to use an emulator like CCDesk while working on programs that have little physical effect on my world.

If you get around to adding support for it, or finding someone that would for you, really think about it. If it's not something you have much desire to do, or don't want to put the work in, that's really no issue, it looks like you already have something great going. ^.^
TomyLobo #14
Posted 04 May 2013 - 10:04 PM
You can use MagicLauncher to run minecraft from any folder you want. (the path needs to end in .../.minecraft though, but that can be anywhere)
xuma202 #15
Posted 09 May 2013 - 05:48 PM
The link is down.
TomyLobo #16
Posted 10 May 2013 - 08:45 PM
The link is down.
The link is back up

Sorry for not replying earlier. I only just found out that email notifications are off by default.
xuma202 #17
Posted 11 May 2013 - 07:38 AM
The link is down.
The link is back up

Sorry for not replying earlier. I only just found out that email notifications are off by default.

No problem, I was able to build it myself but I thought of the others too.
Zudo #18
Posted 06 July 2013 - 10:43 AM
This looks nice!

When ComputerCraft for 1.6 comes out, there will be no need to play Minecraft sounds with this as you can do that with command blocks:

/playsound random.chestopen @p
TomyLobo #19
Posted 06 July 2013 - 11:40 AM
This looks nice!

When ComputerCraft for 1.6 comes out, there will be no need to play Minecraft sounds with this as you can do that with command blocks:

/playsound random.chestopen @p
That's only a tiny part of the functionality of this mod.
The major part is the generation of custom sounds.
But thanks for the info, I wasn't aware of this command :)/>
Win7yes #20
Posted 14 May 2014 - 07:07 PM
Can you update to CC 1.63?
TomyLobo #21
Posted 15 May 2014 - 10:19 PM
You can do that yourself.
The source is available at https://github.com/TomyLobo/ccnoise
If you have any specific questions only I can answer, ask away :)/>