Advice for first DIY project (MIDI sample playing instrument)

This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.

This is my first post here on diyAudio. I am interested in getting started with microcontrollers and hardware, and combined with my general interest in music I'd like to make an instrument and I need advice on where to start. The project is for fun and for learning about embedded hardware and software, some electronics and possibly some DSP. I am already a software developer with experience with C/C++/Python/Java, etc, but I'm new to assembler and embedded systems.

My idea is to create a MIDI module that has a MIDI input and line audio output. It should play a sample in the right pitch and amplitude (velocity) based on the NOTE ON / NOTE OFF messages. The dream end-product would be something that plays a high quality multi-sampled Fender Rhodes with possibly some DSP effects on it, controlled by knobs.

I understand I need to start somewhere much simpler. My idea is a simple MIDI-playing device that will play a sine wave or a short sample in the right pitch.

Do you guys have any advice on where I should start? My first question is what development board could be a good fit. I have been looking at three alternative approaches so far, but I am not sure I am looking for the right boards at all.

- Arduino. It sounds like people think it's not fast enough for DSP work, but maybe coupled with a shield like Audio Codec Shield I could offload the processor from the heavy work? I don't know much about DSP yet, so I am not sure if this is a viable option. In the long run, to play high quality samples (i.e. maybe 2-300 mb worth of samples), would require quite a bit of both storage and RAM. I guess, in this case I will also need to build some kind of a MIDI interface or write the code to interface with a USB midi keyboard.

- Raspberry PI with Linux. In this case I could just write a C program that listens to MIDI events and plays samples. But I am not sure if the performance penalty of using Linux is worth it. Especially startup time. There is a project, Raspberry Pi Synthesizer that does a similar thing (although it's not sample based). Also, it would be more fun to be closer to the hardware for learning purposes.

- Raspberry Pi "bare metal". I am not sure how hard this is, but there are plenty of people who are running Raspberry Pi without Linux and doing fun things with it. It has plenty of power, so it should probably be fast enough for this. There is one guy who has done something similar: Baremetal MIDI file player so it seems doable.

But I am still not sure if Raspberry Pi is the right option for this. The audio output is presumably not good. Maybe there is some other processor (/development board) that is more suitable for audio work?

Any advice very much appreciated!
I think that if you want to use a RPi then you need intimate knowledge of the onboard components. If you already have such knowledge then its probably a good system to go with as the hardware development will be negligible, but if you don't, then learning the ins and outs of the system will almost certainly involve more effort than building a system from scratch.

The Arduino is a popular solution with people with no or little previous computing experience. It uses a cut-down version of C which is supposed to be easier to come to terms with for 'artists', 'musicians' and others with a non-technical background. I don't recommend it to anyone with previous software development experience, these systems tend to have non-standard implementations of the more difficult-to-program aspects of any system, and this means that you are tied to the systems non-standard aspects once you have learned it. It's better to learn a generic system targetted at engineering usage in the long run, you may need to put in a bit more effort at the learning stage, but it will stand you in good stead in terms of versatility.

I like PIC microcontrollers for quick-and-dirty projects. They're a complete system-on-a-chip. There's a big engineering community out there for the PIC micro, and you will be able to get advice from a real engineer when the chips are down. If you go with a PIC, it's best to buy a PICKit2 or 3 (USB) to program your board with. The PICKit is fully compatible with Microchip's IDE (Integrated Development Environment) which is freely downloadable, and comes with Assembly language, and C support. The C support defaults to a slightly poorer (less efficient) coding engine after about a month, but this is rarely of significance in anything but a professional environment where the ultimate execution speed or program compaction is called for. You can program the uprocs off-board in a small socketed board or In-System by building a 6-pin header on your boards.

Microchip PICs come in 8- 16- and 32-bit flavours, with many varieties all having slightly different capabilities, such as built-in serial communication modules, A/D converters, timers, DSP, CANBus and even Radio-specific functions. The problem with these sophisticated features is that implementations using them can be difficult to debug, so it's sometimes preferable to sidestep them and use well-known and understood programming devices such as bit-banging either to get things up and running or even as a final solution if performance is not an issue.

If I was going to build a basic MIDI-based device, I'd develop it in stages, perhaps shifting from one of the more primitive 8-bit uprocs to a 16-bit one as required, or even by bolting on more processors, which is an option with these cheap devices. You can develop a system and then use it as a sub-system in a more complex device.

Initially you just want to work up a basic system that will allow you to replay samples or synthesized waveforms. The PIC will give you the opportunity to to develop an understanding of the most basic building blocks of such a system.

One area where the PIC is somewhat deficient for such applications is that users tend to lean on the built-in flash memory, certainly for program code. Before you have gone very far, you will probably find that you will want to find a way to bolt on some external static RAM, if only to store audio samples.

You want the 'F' (flash) devices. The 12F508 (8-pin), the 16F628A(18-pin) and the 16F887 (40-pin PDIP or 44-pin TQFP) all have built in RC clock oscillators which simplify building basic systems, although obviously a crystal oscillator will be preferred for audio timing once the system gets more developed.
Thanks for your feedback! It is very, very much appreciated.

I wasn't aware of that Arduino is so much non-standard and didn't consider the issues with knowing the RPi onboard components. I think you're right that I should build something myself using simpler/more standard components. I actually have an AVR development board somewhere in storage, but I haven't used in years. I guess it could do as a start. Or do you see any reason for not using AVR in this case as opposed to PIC? I understand they're quite similar (let's not start a holy war).

I also really like your idea of building the device in stages. I am probably going to start by just actually being able to program a chip at all, flashing a LED or something, then move on to either audio output or MIDI input and read up on that. This will be fun!

I'll keep you posted on my progress and I'll probably ask more questions later on.
PIC VS AVR is like Apple VS Microsoft there is no right answer but a whole lot of strong opinion. I use PIC chips because I started working with the tiny 16C54 when it came out in the early 90's, so that's what I use.

The Arduino......uses a cut-down version of C which is supposed to be easier to come to terms with for 'artists', 'musicians' and others with a non-technical background.

The Arduino compiler is based on GNU C so it should compile standard C code without complaint. I have been using the Microchip C compiler and the Arduino compiler eats most of my old code with only header changes.

I never really looked too hard at the Arduino offerings because they were based on relatively low powered processor chips. Recently there have been a new crop of 'Arduino on Roids" devices appearing on the market that claim some degree of Arduino compatibility. I have been using the ChipKit MAX 32 from Digilent. It is $50 and Is the same footprint as the Arduino Mega. It works with most Arduino shields and has a complier and IDE compatible with Arduino sketches. It will also eat standard C code. It is powered by a 32 bit PIC chip running at 80 MHz so there is plenty of processing power.

Digilent Inc. - Digital Design Engineer's Source

I also wanted to build a simple sample player some day....don't have the time right now, but this is what I will need for mine. Yours may be similar, or not, but take the time to figure out each block of the puzzle before starting the assembly process. It will save you time and money in the long run.

I want to be able to use a lot of existing samples. There are tons of free sample libraries out there, often associated with some of the music magazines. I find that the British magazine "Computer Music" sticks a DVD to the front of their mag every month. The DVD contains samples and apps for PC, MAC and iPAD in various formats. Many of the adds in the mag contain links to more samples. These will be in several formats but the most popular seems to be WAV which is one of the easiest to deal with.

You will need a method for saving the samples, and playing them back. I figured that I could collect what I wanted in my PC and save it all on an SD card. Then I would need a small microcomputer to play them into a D/A converter board at 16 bit 44.1 KHz, the CD standard, or a higher rate. There are SD card and audio interface "shields" for many of the popular chip dev boards. You will also need some means of triggering the samples for playback. This can be a MIDI interface or a box full of multi collored buttons which seems to be rather popular with the DJ crowd right now. I still want to make all of this in a tiny package some day, but for now....

It suddenly dawned on me that designing all of the hardware to operate with a Chip Kit (or whatever) board was doing things the hard way. I decided to start with a basic PC mother board, one of the Mini ITX sized (6.7 X 6.7 inch) boards with one PCI express slot for a high quality sound card. Video is onboard so you can use a small PC screen or one of the small touch screens for automotive PC applications, and you can get a USB MIDI interface cheap.

I have already built up a small system using an Intel motherboard that runs off of a 19 volt laptop power supply, a 20 inch flat screen that also runs off of 19 volts, a MOTU Microbook II guitar interface, a MOTU FastLane USB MIDI interface, and several software packages, many of which were free. I am using a 22 volt LIPO battery from the hobby model hellicopter industry to power it all, and a DIY Class D chip amp for a battery operated MIDI player, recording studio, and guitar amp. I find that Overloud's TH2 guitar amp/effects simulator is awesome for a full metal racket in a small box.
This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.