- A C library for programming cognitive experiments on Windows
/* __ / /_______________ ____ ___ / __/ ___/ ___/ __ \/ __ \/ _ \ / /_(__ ) /__/ /_/ / /_/ / __/ \__/____/\___/\____/ .___/\___/ /_/ newsound5.c record, play and save a wav file (non blocking API) unlimited length (dump recording to file) (no need to open a graphics window) */ #include <tscope.h> int main() { // make a sample pointer snd2_sample *samp; // allocate memory for a 15000 ms recording samp=snd2_makesample(15000); // make a stream pointer snd2_stream *stream; // start recording the sample stream = snd2_recordsample(samp); float onset_opname=snd2_getstreamtime(stream); // give the recorder some time to start ts_wait(mtt(1000)); float streammarkers[5]; __int64 samplemarkers[5]; int i; for (i=0; i<5; i++) { // onset of the 'trial' streammarkers[i]=snd2_getstreamtime(stream) - onset_opname; samplemarkers[i]=snd2_getsampletime(samp); // run a trial printf ("trial %d onset: %f %lld\n", i, streammarkers[i], samplemarkers[i]); ts_wait(mtt(1000)); // after each trial dump the recording buffer to disk snd2_tobuffer(samp); } // at the end of the experiment stop recording snd2_stopsample(stream); // and dump the final buffer to disk snd2_tobuffer(samp); // kill the sample snd2_killsample(samp); // read the buffer and write it to a wave file snd2_frombuffer(samp); snd2_writesample(samp, "sample.wav"); snd2_playsample_blocking(samp); remove("buff.raw"); return 0; } END_OF_MAIN();