Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

OT: Looking for pointers to wav file processing

2 views
Skip to first unread message

Bruce Varley

unread,
Mar 13, 2013, 7:38:58 AM3/13/13
to
Presumably some MIDI people will also know something about my query and
hopefully be kind enough to give me an initial pointer.....

I want to get set up for processing WAV files in real time and outputting
the result as audio, under linux. The objective is to create by modifying
and combining 'ordinary' sounds.

Any info on how to get started appreciated. I'm not scared of working at
source code level, lots of C/C++ background, but surely some reasonable
tools exist already somewhere.


Bob Masta

unread,
Mar 13, 2013, 10:40:51 AM3/13/13
to
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!

Pete

unread,
Mar 14, 2013, 4:27:53 PM3/14/13
to
In article <28CdnXrCBsPL-N3M...@westnet.com.au>,
For jobs like this, I tend to recommend Csound. I believe it can do
whatever you're thinking of (and probably what you haven't yet! (:-)).

If you're not familiar with it, Csound is a cross-platform audio
synthesis/analysis suite [I think it's not right to call it an "app"
any more] that has been around a long time, but is still in very
active development. (Version 6 is in testing now and should be out
in a month or so. I think the latest prebuilt distribution on Ubuntu
is 5.17, but it is very adequate.)

The basic idea is that you write an "Orchestra" file that contains
various "Instruments" to generate the audio. These can be driven
by a "Score" file for pre-programmed performance, or by MIDI for
real-time stuff. Instruments are built from "Opcodes" that are
the basic construction blocks of the system. These can be anything
from simple oscillators, through sample-players (what you're probably
looking for, I expect), and complex filtering and other manipulations.
There are a lot of plugins (sometimes more platform-specific) that
give you GUI widgets, Python and Lua control and opcodes, and so on.
Basic Csound is command-line driven, but there are several front-ends
for various preferences.

If your WAV files are short enough to all fit into memory -- and if
they're just short sound to be played on demand, I suspect they will --
you can load them into tables and play them with an opcode like 'loscil'
which lets you control the playback pitch/speed and looping if you want.
If you have to play from disc, you can use, say, 'soundin'; I don't think
modern systems will be bothered by having to do that.

As it happens, I'm currently playing with something that sounds close
to what you intend. I have a short "found sound" (which I actually
clipped from a tape I made as a teen! (:-)) that is I suppose really
modulated pink noise, that I am using both to generate musical notes
-- with variable timbre controlled by joystick -- and to create some
gutsy percussion. Both a work still-in-progress, but I'm quite
pleased with the results so far.

The percussion version is quite simple: I just add an envelope with a
decay to the sample played at a pitch determined by the MIDI note.
Generating a note from "noise' is more complex. Essentially I play
the sample at a speed according to the note, then heavily Butterworth
filter it with appropriate centre-frequency and bandwidth. Bandwidth
and the mix of percussive/non-percussive envelopes is controlled by
joyystick-driven MIDI controllers.

The place to find out about Csound is www.csounds.com. (Despite the
website name, Csound is LGPL.) At the top of the page are links to
the SourceForge download site, the [very necessary!] manual, and a
very helpful FLOSS manual that is much more readable than the often
terse official one. There are also mailing lists that have links there
(the Nabble forums).

HTH,
-- Pete --


--
============================================================================
The address in the header is a Spam Bucket -- replies will not be seen...
(If you do need to email, replace the account name with my true name.)
============================================================================
0 new messages