[Stk] Reading and writing disk wav file and the real time recorded wav file

Stephen Sinclair sinclair at music.mcgill.ca
Tue Oct 7 16:32:40 PDT 2008


Jui,

On Tue, Oct 7, 2008 at 6:26 PM, alpana jui <lpnjui at googlemail.com> wrote:

[ ... skip ... ]

> Further,  I could not manage to compute the frame length of the wav
> file. How  can I do that?

FileWvIn::getChannels() will give you the number of samples in a frame.


> I have also some questions on the sample text, is the sample is in
> vector form or it is just a single sample? How many samples in each
> frame ? How can I received the samples in a frame as a vector.

This depends on how the wav file was recorded.  If it was recorded
mono then the frame size will be 1.  If you call the tick() function
as is shown in your code, then it will average all the channels of
each frame together to give you a single sample.  If you call the
StkFrames version of tick() then you'll get an StkFrames object with
the samples for each channel.

I don't really understand why you need more than one channel for your
application however, since you are talking about analysing voice
commands.


> Can FileRead and FileWrite be directly used for my purpose of using
> Stk,, i.e., reading and writing the disk files and recorded files,  if
> so , would this be possible to get some hints on this, please?

I think FileWvIn is easier to use.


> I am not clear about the "tick " method or function or the purpose of
> this. I do not know if I need this for my purposes. Could anybody make
> comment on this, please?

It's used to step through the synthesis (in your case, reading from a
file) one sample at a time.


> Do I need to use callback function for my purposes?

Callback is used for playing real-time audio.


> I will appreciate any response and support as well as advice  for my
> success in my application while trying to use Stk-4.2.1.

As you can see from using STK so far, it is in fact a class framework
for writing audio synthesizers.  That is, you can start with simple
unit generators and call their tick() functions to produce one sample
(or frame) of audio, and pass it on to another unit generator.

Some of these unit generators such as FileWvIn and FileWvOut can
interact with .wav files, and this is a great convenience.  But...

Now, I don't want to discourage you from learning C++, but have you
considered that STK may not be the best choice for what you are trying
to do?  There are many higher-level languages that are far easier to
use and are quite robust that would probably accomplish what you want
to do faster.  I really suggest checking out things like Pure Data,
ChucK, Max/MSP.

For instance, here is some chuck code that will record a 3-second wav
file and then play it back and then print each sample to the console:


fun void record() {
   adc => WvOut w => blackhole;
   "test.wav" => w.wavFilename;
   3::second => now;
   w.closeFile();
}
fun void readit(int print) {
   WvIn w => blackhole;
   if (!print) w => dac;
   "test.wav" => w.path;
   now + 3::second => time end;
   while (now < end) {
       if (print) <<<w.last()>>>;
       1::samp => now;
   }
}
record();
readit(0);
readit(1);


Steve



More information about the Stk mailing list