-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
32 floppy drives problem (and help with some program improvements) #224
Comments
I don't know if this is true because ChatGPT said it, but this is how it "can" be implemented. I don't really know how to code, so I'm sending it for checking, and if it's useful for something, I don't know where to implement it in the code, but here it is: To implement an envelope effect (ADSR) for floppy drives in Moppy, we need to simulate the dynamics of sound by modulating the motor's behavior over time. Here's how it can be done, with a focus on creating a customizable Attack, Decay, Sustain, and Release envelope effect.
An ADSR envelope shapes the volume or pitch of a sound over time
For floppy drives
We can define parameters for each stage of the envelope:
Envelope Calculation The envelope will be applied by adjusting the motor's pulse frequency dynamically in the loop() function or a dedicated timing interrupt.
Using the Envelope to Control the Drive We map the envelope level to the drive's pitch (step frequency). Here's an example:
For vibrato (pitch modulation), add a sine wave oscillation to the base frequency:
In the envelope function, replace:
With:
Here’s a minimal example of ADSR applied to a floppy drive:
|
Just some initial thoughts and I might respond more later if I have time.
Yes, it is possible. You would need to create your own instrument class in the microcontroller code. The easiest way to do this would be to copy the existing Floppy class and add your changes. You should not need to implement anything on the GUI / Server side.
Sammy would know off the top of his head but I would have to recheck the core code. Moppy might not implement velocity which means no ADSR. I did not see it in my quick scan through the code. My project Mechanical Midi Music does have velocity built in and I use it for controlling LEDs but it is still a work in progress with some bugs and limitations. I will talk about it more below.
Floppytron had a custom hardware solution and higher resolution processors than the Arduino Uno does. I also assume he used some hardware-specific code optimizations as well. This leads to a limitation in the microcontroller. The interrupt is only toggled every 40 us on the Arduino Uno meaning you lose resolution with higher frequency notes and they become out of tune. Moppy might not have modulation control but it does have pitch bend. Pitch bend only works with low notes bc freq is logarithmic and you have more intermediate freq between low notes. For high notes, you hear stair stepping or it can't even play the note. I use an ESP32 which gets me down to 7-8 us which can handle mid-high notes well but it is still not enough for the highest notes and smooth pitch bends. I have a solution I am working on with SPI signal generators but you need a custom PCB and Amplifiers. I have not done automatic ADSR shaping but I have manually duplicated MIDI tracks on my setup to play multiple of the same notes across floppy drives amplifying sound.
Scanners while working will be slightly out of tune with high notes on Arduino for the reasons listed above mid notes should be fine. The code should already be implemented for the scanners. Scanners are typically stepper motors so you will need a L29HN or easy driver for use with Moppy's existing instruments. Drums should also be already implemented as a different instrument class but I haven't looked into it.
I didn't look at the GPT code but it should be easy to implement ADSR on the microcontroller in my opinion. The problem lies in whether Moppy implements velocity control and if the microcontroller is fast enough to handle ADSR. I haven't worked on my codebase in the past few months after moving and getting a Job only filming videos every so often and working on Hardware. The main limitation of Mechanical Midi Music is It is written in Cpp 17 so only works on new microcontrollers primarily ESP32. I have plans to make a backward-compatible version but It is low on my to-do list. One benefit is my program is extremely easy to set up (potentially easier than Moppy I dare say) but the GUI is also web-based at the moment. I have a Desktop version that works but it is command line only and very poorly written in a hurry. I can fast-track my work on it if you are interested. The Main difference to Moppy is my Distributors run on the microcontroller vs Moppy mappers which map notes on the server. This means I have access to all midi controls on the microcontroller even breath control. For your use case you would need some shift registers to control 8 floppy drives off of one esp32 but it is theoretically doable. My Youtube Channel https://www.youtube.com/watch?v=2lvIQnV8SYk&ab_channel=DJthefirst |
It is possible. You'd end up with Device Addresses 1-4, and each would have two Sub Addresses. So you could map the notes like:
As @DJthefirst mentioned though, you'll need to create a custom instrument here in order to combine four drives into a single Sub Address.
Velocity is actually already being sent to the Arduino (see message construction here) but as far as I know isn't being consumed by any of the existing instruments. When you create a new custom instrument to combine the four drives into a single Sub Address, you can read the velocity value to set the appropriate number of drives to play.
Hardware is probably the way to go here. If you want to control e.g. a scanner or hard drive via software, you'll need to have a device driver for your OS that, essentially, can accept Moppy messages. There's no practical way to control the via software from an Arduino because it would be exceedingly difficult to make a USB scanner driver that ran on an Arduino. ESP chips might get closer as they can more easily do some USB communication, but you're still looking at reverse engineering the drivers.
It is not true. Right out of the gate ChatGPT says: (The sine vibrato bit in theory could work, but is unnecessary as Moppy already supports MIDI pitch bending, so you can just vibrato that way.)
You can certainly try this with four drives, but that's the equivalent of 2-bit audio, so you don't have a lot of range to work with, and certainly nothing exponential (i.e. "exponentially" decaying from 4 drives at once would look like 4 -> 2 -> OFF, which, is not only linear anyway, but doesn't even really use 1 or 3 drives-- might as well do linear decay 4->3->2->1->OFF). This, again, could be done using MIDI velocity, so if you add support for velocity in your instrument you can at least test it out by just editing your MIDI file and seeing how it sounds from there without having to implement any ADRS stuff in the embedded code at least at first. I think adding an instrument with velocity support is a great idea. If you've got 32 drives, you could even group them as 4 instruments with 8 volume levels for some very expressive quartet playing. But I think writing the ADSR stuff for the Arduino may not be worth the effort. (I guess you could implement it in Java and just send additional messages that aren't mapped directly from the MIDI file, but that might start to get messy too) |
For the scanner if you plan to control it directly over the usb of the scanner you would need the driver stuff Sammy was talking about, but if you just control the internal stepper motor which most people do by splicing the wires to a stepper driver and Arduino you should be fine with the small caveat of high notes being out of tune on an uno. Originally I missed the velocity data hidden in the payload[] bytes. It should be easy to implement the velocity volume control with the four drives. You could even do the fade in an out with a little extra effort though that might start getting risky with the processing power of an Arduino Uno. I don't think you should / can implement pitch ADSR or vibrato on the Uno due to the lack of frequency resolution. Moppy already has pitch bending though it is unusable at mid-high notes. |
As I mentioned before, I don't know much about programming and I rely 99% on chatGPT knowledge when it comes to this. If you can call it that, I'm more of a hardware type. But now, instead of chatGPT, I took AI strictly for programming and wrote longer and more comprehensive prompts, but I can't say whether it's perfect (I've already noticed an error related to the definition of 16 pins, while Uno has them from D0 to D13). If you have time, it would be a great help if you could check the code and tell me what's wrong with it @Sammy1Am @DJthefirst . Modified FloppyDrives.h:
Modified FloppyDrives.cpp:
Thanks in advance |
I, unfortunately, don't have the time or resources to write this all for you at the moment. I can sort of steer you in the correct direction, but at the end of the day you're going to need to be able to do some troubleshooting and coding yourself. The AI's attempt doesn't seem super far off though, so a few notes in case it's enough to get you there:
More importantly: what happens when you try to run this code? Is it close to doing what you'd like? |
Ok, let's simplify things a bit: Each Arduino is a separate voice (midi track). I won't bother with separating floppy drives anymore, so instead of 4 Arduinos, I'll buy 4 more. Why? I want to use this floppy shield: https://hackaday.com/2014/10/12/a-simple-floppy-music-controller/ . I want to use more durable, dedicated 34-pin cables for the floppy drive and make the wiring on the Arduino side more aesthetic. However, I still want to implement the velocity function and I will try to do it using the knowledge acquired here. My question is: Will moppy work the same with this floppy shield? |
It looks like the creator of the shield says it will, but also there doesn't seem to be any chips or anything on there so it should work fine. |
I meant, do I need to make any changes to the code, e.g. different pin definitions, etc.? |
Ah, it looks like it should be fine. Could be STEP and DIRECTION are swapped, but there aren't any other pins in between so the loop math should still work.
|
Sammy does the mapper support velocity where you can specify to only send notes to a sub address when the velocity is above a certain value? |
I have a skill issue so the AI has once again extended the Floppy Drives.cpp code a bit to:
Decay – time of the amplitude decay from the maximum level to the sustain level i.e. "voice drop" by reducing the number of floppy disk drives. I asked him in the prompt to keep the code as close to the original as possible, but once again I don't know how he managed it. Anyway, here it is:
|
Sorry, I accidentally closed it |
Oh! It does! Velocity is assigned to the variable I'll try to come up with the script tonight if you haven't got it by then. |
Alright, give this a try with one Arduino and 4 drives:
This should play everything from MIDI channel 1 (I'm fairly sure they're 0-indexed, but if nothing happens, try replacing the 0 with a 1) on the first Arduino. Every note will be played on the first drive, notes with velocity over 32 on the first and second, etc. Basically should accomplish what you're after without having to make any modifications to the code (thanks @DJthefirst , great idea) |
That sounds cool! @DJthefirst I have a question about your comment from a few days ago:
Can Arduino handle sounds with + - the same frequency as your stepper motors in this video https://www.youtube.com/watch?v=2lvIQnV8SYk |
Thanks, it finally worked! And how to make each subsequent Arduino a separate midi track but also with velocity support? it seems to me that: Condition: and Device Address: am I right? |
C is channel which Sammy is saying is 0-15 or 1-16 for midi where ch0 = ch1 or ch1 =ch1 Address is Arduino 1,2,3,etc.. SubAddress is Floppy 1,2,3,etc.. on a given Arduino So on 1 Arduino you will have 2 channels As for the note resolution Arduino is 40us a c3 note is 130hz or 7692us c3# is 7216us a 476us difference or 4% off between notes. Barely notable to most people. But only 11 pitch bend steps between notes. I use esp32 which are faster with an 8us resolution < 1% accuracy a c5 note is 523hz or 1912us and c5# 1804us difference of 72us you can be off by 1/4 of a note at 40us very noticeable. pitch bend is 2 steps between notes. Esp32 is 9 steps Now c6 is 956us and c6# is 902us a difference of 54us. With only a 40us resolution this means the note can be up to +- 1/2 a note. A pitch bend would almost be a whole note entirely unusable. Esp32 6 steps. |
@DJthefirst Do you think it's worth replacing all the Arduinos in this project with esp32? If so, how to connect floppy drives, a4988 drivers for stepper motors and hdd drives (everything I have in Arduino so far) to esp32? How many pieces of esp32 do I need? Does esp32 work with Moppy2? |
I don't think it is worth replacing for floppy drives. Moppy I think has support for esp32 but it might not be very well tested. You also have less pins. I was just making you aware of problems you might run into or to look out for. If you run into problems it might be worth looking into something like the Arduino due but I haven't used it to know what the minimum resolution is. Either way you still won't be able to pitch bend well on esp or Arduino with Moppy as is. |
What about your Mechanical-Midi-Music? |
Hello, I have a problem with setting the program for this specific floppy drive configuration and some additional improvements.
I have 4 pcs Arduino UNO:
The velocity parameter in MIDI decided how many stations (of the 4 in each midi channel) were to be turned on.
Make ADSR-like shape and simulate a musical instrument, like a piano (exponential decay) or string instrument (sine, "vibrato"). Floppotron 2.0 had this option.
And most importantly:
I would like to thank everyone in advance for their help and interest. If I succeed, I promise that I will expand the project to insane proportions (it's my passion) and the videos will be available on YouTube and anyone who helps me in this post will definitely be tagged.
The text was updated successfully, but these errors were encountered: