User Tools

Site Tools


user:dgirard3:portfolio:project4

Project: Drum Machine

A project for HPC by Derek Girardi during the Fall 2012.

This project was begun on September 25th and is anticipated to take 3+ weeks.

Objectives

The purpose of this project is to get more familiar with the mechanics of making a drum machine of some sort and how the audio works in the linux environment.

Prerequisites

In order to successfully accomplish/perform this project, the listed resources/experiences need to be consulted/achieved:

  • C programming
  • Musical knowledge of some sort
  • Teacher Help
  • Arduino Hardware

Background

The reason i want to undergo this project is because music is one of my biggest passions. I love listening to it and playing it, so i decided why not make my own within the linux area! There are many many drum machines and soundboards out there that have already been created and used by many. This is for personal gain only and i dont plan on it being big, I just want to be able to make one from scratch and see if it will even work! The hardest part will be getting the sound that is needed to be produced to make an accurate drum sound.

Scope

If i was to be finishing this project i would show the steps and code that i am writing to finish this program.

Procedure

Here are the first steps that should be taken to get this project going:

Step 1: Find a sample program or write up your to see how to implement it into your system so you can actually produce sound. Step 2: Find your sound card and see what it is, it will most likely have ALSA protocols so you will need to work around that complex work. Step 3: Get your hands on some arduino software so you can create your own sound samples and play that back as an audio test and use the samples Step 4: Start getting the psudocode typed or written so you have a general idea of how you want to go about writing your code.

Code

Upon completion of the project, if there is an applicable collection of created code, place a copy of your finished code within <code> </code> blocks here.

parrot.c
  3 *Program to illustrate /dev/dsp device
  4 *Records several seconds of sound, then echoes it back
  5 *runs until Control-c pressed.
  6 */
  7 
  8 #include <unistd.h>
  9 #include <fcntl.h>
 10 #include <sys/types.h>
 11 #include <sys/ioctl.h>
 12 #include <stdlib.h>
 13 #include <stdio.h>
 14 #include <linux/soundcard.h>
 15 
 16 #define LENGTH 3  /*how many seconds of speech to store */
 17 #define RATE 8000 /*the sampling rate*/
 18 #define SIZE 8 /*sample size: 8 or 16 bits */
 19 #define CHANNELS 1 /* 1 = mono, 2 = stereo */
 20 
 21 /*this buffer holds the digitized audio*/
 22 unsigned char buf[LENGTH*RATE*SIZE*CHANNELS/8];
 23 
 24 int main()
 25 {
 26     int fd;
 27     int arg;
 28     int status;
 29 
 30     /*open sound device*/
 31     fd = open("/dev/dsp", O_RDWR);
 32 
 33     if(fd < 0)
 34         {
 35             perror("open of /dev/dsp failed");
 36             exit(1);
 37         }
 38 
 39     /*set sampling parameters */
 40     arg = SIZE;      /*sample size*/
 41                                                                                                                             1,1           Top
 42     status = ioctl(fd, SOUND_PCM_WRITE_BITS, &arg);
 43 
 44     if (status == -1)
 45         perror("SOUND_PCM_WRITE_CHANNELS ioctl failed");
 46     if (arg != SIZE)
 47         perror("unable to set sample size");
 48 
 49     arg = CHANNELS; /*mono or stereo*/
 50 
 51     status = ioctl(fd, SOUND_PCM_WRITE_CHANNELS, &arg);
 52 
 53     if (status == -1)
 54         perror("SOUND_PCM_WRITE_CHANNELS ioctl failed");
 55     if (arg != CHANNELS)
 56         perror("Unable to set number of channels");
 57 
 58     arg = RATE;  /*sampling rate*/
 59     status = ioctl(fd, SOUND_PCM_WRITE_RATE, &arg);
 60     if(status == -1)
 61         perror("SOUND_PCM_WRITE_WRITE ioctl failed");
 62     while (1)    /*loop until ctr-c*/
 63         {
 64             printf("say something:\n");
 65             status = read(fd, buf, sizeof(buf)); /*record some sound*/
 66             if(status != sizeof(buf))
 67                 perror("read wrong number of bytes");
 68             printf("you said:\n");
 69             status = write(fd, buf, sizeof(buf)); /*play it back*/
 70             if (status != sizeof(buf))
 71                 perror("Wrote wrong number of bytes");
 72         /*wait for playback to complete before recording again*/
 73             status = ioctl(fd, SOUND_PCM_SYNC, 0);
 74         if (status == -1)
 75             perror("SOUND_PCMSYNC ioctl failed");
 76         }
 77 }
 78 
 79

Here is some code that could help get you started!

Reflection

This is going to e a tough project but will be pretty amazing when it is finished.

References

In performing this project, the following resources were referenced:

Some places that might get some ideas flowing/help

user/dgirard3/portfolio/project4.txt · Last modified: 2012/12/13 19:00 by dgirard3