Go Down

Topic: rgb ledstring lightsaber (Read 13629 times) previous topic - next topic

racemaniac

#45
May 09, 2016, 07:18 pm Last Edit: May 09, 2016, 09:19 pm by racemaniac
Hi what do you use to calculate the swing duration?
I have a adxl335 and i start the swing on any acceleration. But this algorithm is quite to simple i think
I currently use the gyro values for detecting swings (since, lets face it, a lightsaber swing is almost always rotating). And the gyro values give real time feedback to the sound (currently only its pitch, but i'll have to improve on that).
I've ofcourse had to implement some filter to cancel the noise out a bit, still experimenting with that a bit, but so far i've made a filter that rises quickly when the saber starts to move, and dies down a bit slower so you'll have a bit of an afterbuzz, and it also filters the noise out a bit :).

And i'm using this: Sound stretch to try to generate some samples i can use for my project :).
I take a swing sound, stretch it with this tool (or actually the audacity implementation of it), and make a repeatable sample of it :).
I'm really wondering what the end result will be :). I quickly did a fade in/out of such a sample in audacity, and it sounds okay, i'm wondering how it'll work when responding to the motion sensor and being mixed in by the microcontroller :).

racemaniac

#46
May 14, 2016, 02:27 pm Last Edit: May 16, 2016, 11:12 am by racemaniac
Okay, first videos 1, 2 3 of what i'm working on

This is a demo of it streaming 2 sounds simultaneously (a hum sound & a swing sound), and mixing them dynamically based on the feedback of the motion sensor :).

This is the first somewhat showable thing of all the work i've done so far, but i'm glad it's finally starting to give a result :).
Still tons of work to do (volume control, the dynamic sampling rate that i had working, but started doing strange things once i started mixing the sounds, ...)

But i think it'll be awesome once it's done XD.

bodtx

nice, the synchronisation is good. do you play the sound faster or slower depending the acceleration?

racemaniac

nice, the synchronisation is good. do you play the sound faster or slower depending the acceleration?
currently it's mixing between a swing sound and an idle sound (so it's playing 2 sounds at the same time, and depending on the motion the swing sound will become louder, and the idle sound more silent).
I can also change the sampling rate, but having it react to the motion gives more a car engine kind of sound rather than a saber sound. I think i'll keep the dynamic sampling rate for some more subtle effects (the saber "warming up" or "cooling down" a bit while in use or being swung often), and not try to use it for very direct feedback too much

Protonerd

Do you use PWM to drive the Audio Amp? Is it a direct drive from the processor output pins to the audio amp? I'm curious if 2 chips could also parallel drive the audio amp, simply shorting 1 pin from a controller (thinking about Arduino) and one from a dedicated MP3/WAV codec chip. I did not think it through but just curious if it would work...?

racemaniac

Do you use PWM to drive the Audio Amp? Is it a direct drive from the processor output pins to the audio amp? I'm curious if 2 chips could also parallel drive the audio amp, simply shorting 1 pin from a controller (thinking about Arduino) and one from a dedicated MP3/WAV codec chip. I did not think it through but just curious if it would work...?
It's an I2C DAC. But the arduino is alas poorly suited to drive such a DAC :s.

Protonerd

Why is that? Care to explain? What does a uC need to drive a dac?

racemaniac

#52
Jun 16, 2016, 08:07 pm Last Edit: Jun 16, 2016, 09:39 pm by racemaniac
Why is that? Care to explain? What does a uC need to drive a dac?
hmm, i'm reading the atmega documentation again, it might also be well suited, but it's not so well documented, and i can't find much info when googling :s.

How i do it on the stm32: I initiate a transfer, with clockstretching (as the master) enabled. This means the bus will pause the transmission when no new data is available. And this makes it very easy to send data to the DAC at whichever sampling rate i want :). Also sending new data is as simple as doing 2 writes to the Data register (no pause in between needed), making for very lightweight communication :).

For the AVR, i'm not sure if it supports that mode.

Also on the stm32 i overclock the bus (it can go to 1.2Mhz, which enables me to go to 60 khz sampling rates, rather than the 20khz max on normal speed).

Using the arduino framework I2C is a complete no go, you'd have to set up a transfer for every sample, and would at max achieve a 14khz sampling rate, and that's at 100% cpu usage for just sending those samples, that's hopeless. Maybe if you custom make a framework (either something similar to what i have, or something interrupt driven) you'd get to something decent, but you'd have to experiment with which modes.

After reading the AVR documentation, i do have some more appreciation for the stm32 i2c port, it seems to pack quite a bit more power :). (even though the documentation of it drove me mad at times :p)

*edit*
spent a bit more time on the avr documentation, and it may be possible to pull off, but someone would have to experiment :)
I think a similar mode to what i described is possible (although you'd still have a pause between the 2 bytes you need to send per sample, but that's not that hard to deal with). I'm also wondering which speed you'd be able to get out of the bus. The manual describes the clock frequency of the controller should be at least 16 times that of the I2C bus, so maybe you'd be able to push the bus to 1Mhz, which would give you a decent sampling rate.

There are some ifs in this story, but maybe you can pull off a good lib to drive the mcp4725 :).
And if you could at the same time use the spi port to read some data from a flash chip, you could make your own sound player :). (but you'd still need a second arduino to then tell this module what to play & how :) ).

racemaniac

Okay, spent some time looking into the wire implementation, and if i find some time, i may have a look if i can implement some way of driving a I2C dac properly on an arduino :)
Then maybe a seperate sound module could be made of an arduino micro/nano with specific features for what lightsaber sounds need, and that could be used instead of the standard mp3 modules

but i'd still have a lot of investigating to do :).

Go Up