mirror of
https://github.com/thestk/stk
synced 2026-01-17 14:41:53 +00:00
Version 3.0
This commit is contained in:
committed by
Stephen Sinclair
parent
7c0ee03d60
commit
868787a5f9
58
STK/RTWvOut.cpp
Normal file
58
STK/RTWvOut.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
/*******************************************/
|
||||
/* Real-Time Wave File Output Class, */
|
||||
/* by Perry R. Cook, 1996 */
|
||||
/* revised by Gary P. Scavone, 1999 */
|
||||
/* */
|
||||
/* This object opens a realtime soundout */
|
||||
/* device, and pokes buffers of samples */
|
||||
/* into it. */
|
||||
/*******************************************/
|
||||
|
||||
#include "RTWvOut.h"
|
||||
|
||||
#if defined(__STK_REALTIME_)
|
||||
|
||||
RTWvOut :: RTWvOut(MY_FLOAT srate, int chans)
|
||||
{
|
||||
// We'll let RTSoundIO deal with channel and srate limitations.
|
||||
channels = chans;
|
||||
soundIO = new RTSoundIO(srate, channels, "play");
|
||||
counter = 0;
|
||||
}
|
||||
|
||||
RTWvOut :: ~RTWvOut()
|
||||
{
|
||||
soundIO->playBuffer(data,counter);
|
||||
counter = 0;
|
||||
while (counter<RT_BUFFER_SIZE) {
|
||||
data[counter++] = 0;
|
||||
}
|
||||
soundIO->playBuffer(data,counter);
|
||||
soundIO->playBuffer(data,counter); // Are these extra writes necessary?
|
||||
soundIO->playBuffer(data,counter);
|
||||
delete soundIO;
|
||||
}
|
||||
|
||||
void RTWvOut :: tick(MY_FLOAT sample)
|
||||
{
|
||||
for (int i=0;i<channels;i++)
|
||||
data[counter++] = (short) (sample * 32000.0);
|
||||
|
||||
if (counter >= RT_BUFFER_SIZE) {
|
||||
soundIO->playBuffer(data,counter);
|
||||
counter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void RTWvOut :: mtick(MY_MULTI samples)
|
||||
{
|
||||
for (int i=0;i<channels;i++)
|
||||
data[counter++] = (short) (*samples++ * 32000.0);
|
||||
|
||||
if (counter >= RT_BUFFER_SIZE) {
|
||||
soundIO->playBuffer(data,counter);
|
||||
counter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user