Not sure exactly what you intend. I'll assume you are not
talking about modifying live input sounds (since you said
WAV files), so presumably you have a number of .WAV files
that you want to modify and mix.
My Daqarta for Windows software does real-time signal
generation, which is somewhat similar to this, and it also
does real-time input processing. In fact, the signal
generator will allow you to combine up to 8 separate .WAV
files, including various sorts of modulation and with
independent playback speed and direction for each, or you
can modulate one stream with another, etc. The signal
generator is not oriented toward music, however, but if you
have access to Windows you might want to take a look.
Daqarta's free trial period lasts forever for the signal
generator (only *input* processing expires). (There is also
a whole 'nother pitch-to-MIDI section that *is* oriented
toward music, which is why I prowl this group.)
Anyway, there are two parts to your project: Dealing with
the OS, and actually doing the modify/mix operations. I'm a
Windows guy, but I'll guess that Linux uses similar
mechanisms.
In Windows there are two general approaches: The original
method (which I use) with multiple buffers, and the modern
method with a single large circular buffer. The basic idea
is that you have to keep the buffer or buffers full, ahead
of the OS sending that data to the sound card. You start by
filling the whole works with your waveform, then the OS
notifies you (or you read the buffer pointer) when it's time
to refill.
So your code will need to "chunk" the data processing, or
you will need some kind of synchronized multi-threading. I
use the chunk method. I generate and read or modify a chunk
of data whenever a buffer is freed by the OS. In may case
there are 4 separate threads per Left/Right output channel,
so each chunk consists of 8 separate components that are
subsequently combined. Normally they are just mixed by
addition. However, a low-numbered stream may be elected to
be used as a modulator by a higher-numbered stream, in which
case the modulator is not added directly but used to apply
AM, FM, or whatever.
Of course, in your case you may want to do much more
sophisticated things than simple modulation of your WAV
files. I don't know what you have in mind here, but one
idea might be to modify the spectrum with filters or FFT
approaches. These can get pretty involved. A Finite
Impulse Response (FIR) filter is like a long shift register
with (say) 1024 stages. Each stage has an associated
multiplier constant, and the map of all of these is the same
as the impulse response of the filter you want to apply.
Your waveform starts at one end and then steps its way
along; at each step every stage applies its multiplier to
its sample, and all the products are summed to create one
output sample in a separate stream.
Once it gets started (the first 1024 samples have gone
through) the output of the FIR is continuous.
Alternatively, there are ways to filter using FFTs. Those
are not continuous processes, so you have to do "Windowed
Overlap and Add"... you take the first 1024 samples and
apply a tapered window that goes from zeroes at the ends to
unity in the middle. You do your FFT stuff and produce 1024
windowed output samples, also zero on the ends and unity in
the middle. Then you advance by 512 samples and do
everything all over with an new 1024 samples that include
512 overlapping samples, and when you finally add this
windowed output to the prior the overlapping parts add to
unity. Rinse and repeat.
As far as actually getting going, I'd find some simple WAV
player source code and start tinkering. Again, dunno about
Linux but in Windows there is a high-level system that
allows you to just play the file, and a low-level system
that deals with the separate chunks... that's what you'll
want to experiment with. Petzold has a bunch of this in his
Windows book, but I'm sure there are similar tutorials for
Linux.
Hope this helps!
Bob Masta
DAQARTA v7.21
Data AcQuisition And Real-Time Analysis
www.daqarta.com
Scope, Spectrum, Spectrogram, Sound Level Meter
Frequency Counter, Pitch Track, Pitch-to-MIDI
FREE Signal Generator, DaqMusic generator
Science with your sound card!