3

I want to make a really simple synth.

In short, i want to play a wav file, and have it loop at certain points until touch is released.

I am looking for some example code, (doesn't need to be free).

Sorry for such a basic question, i have been googling this, though there seems to be nothing on this exact topic, unless I'm missing some important term.

Also, is what i'm describing, a wavetable synth, or a soundboard?

afk5min
  • 1,856
  • 19
  • 32

2 Answers2

3

I'd call it a sampler.

Here's a sample project that will get you started:

https://sites.google.com/site/iphonecoreaudiodevelopment/remoteio-playback

See also:

The Audio Programming Book

The Core Audio Book

A sample project of mine

morgancodes
  • 24,113
  • 35
  • 128
  • 186
0

You need to store the sound data in memory, and have some sort of read() command that fills an array of bytes to send to the sound card. The read() command has to keep track of its position between reads, so a persistent pointer must be maintained. You will test the position of the pointer and see if you've reached the end or not, and reset to the beginning when needed.

The specifics are going to depend upon your chosen language, of course.

I did this with Java, with the added the possibility of playback at different speeds. http://www.hexara.com/VSL/VSL2.htm It's a little laggy. I've learned a bit since posting that, but haven't gone back to fix it yet. The program asks permission and has you load a wav file from your computer. It should be 16-bit, stereo, 44100fps, little-endian.

WaveTable synthesis is a bit different, in that only a single iteration of a wave is stored and used as source data.

Here is a short discussion, from Stanford's CCRMA website: https://ccrma.stanford.edu/~bilbao/booktop/node9.html I used this method to make a Java "Theremin" http://www.hexara.com/VSL/JTheremin.htm

With a WaveTable, you decide on the size of the array. If it is a power of 2, one can bitmask the pointer after every increment, which is faster than doing a comparison and reset.

Phil Freihofner
  • 6,203
  • 1
  • 13
  • 35