Class: Portaudio
- Inherits:
-
Object
- Object
- Portaudio
- Defined in:
- ext/portaudio/portaudio.c
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.new ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'ext/portaudio/portaudio.c', line 54
VALUE rb_portaudio_new(VALUE klass)
{
PaStreamParameters outputParameters;
const PaDeviceInfo *deviceInfo;
PaError err;
int device, numDevices;
VALUE self;
Portaudio *portaudio = (Portaudio *) malloc(sizeof(Portaudio));
pthread_mutex_init(&portaudio->mutex, NULL);
pthread_cond_init(&portaudio->cond, NULL);
portaudio->size = 4096 * 2;
portaudio->buffer = (float *) malloc(sizeof(float) * portaudio->size);
err = Pa_OpenDefaultStream(&portaudio->stream,
0, /* no input channels */
2, /* stereo output */
paFloat32, /* 32 bit floating point output */
44100, /* 44100 sample rate*/
4096, /* frames per buffer */
paCallback, /* this is your callback function */
(void*) portaudio);
if (err != paNoError) {
rb_raise(rb_eStandardError, "%s", Pa_GetErrorText(err));
}
self = Data_Wrap_Struct(rb_cPortaudio, 0, free_portaudio, portaudio);
return self;
}
|
Instance Method Details
#start ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'ext/portaudio/portaudio.c', line 118
VALUE rb_portaudio_start(VALUE self)
{
Portaudio *portaudio;
Data_Get_Struct(self, Portaudio, portaudio);
int err = Pa_StartStream(portaudio->stream);
pthread_cond_broadcast(&portaudio->cond);
if (err != paNoError) {
rb_raise(rb_eStandardError, "%s", Pa_GetErrorText(err));
}
return self;
}
|
#stop ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'ext/portaudio/portaudio.c', line 133
VALUE rb_portaudio_stop(VALUE self)
{
Portaudio *portaudio;
Data_Get_Struct(self, Portaudio, portaudio);
int err = Pa_StopStream(portaudio->stream);
pthread_cond_broadcast(&portaudio->cond);
if (err != paNoError) {
rb_raise(rb_eStandardError, "%s", Pa_GetErrorText(err));
}
return self;
}
|
#write(buffer) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'ext/portaudio/portaudio.c', line 97
VALUE rb_portaudio_write(VALUE self, VALUE buffer)
{
int i;
Portaudio *portaudio;
Data_Get_Struct(self, Portaudio, portaudio);
Check_Type(buffer, T_ARRAY);
for (i = 0; i < portaudio->size; i++) {
portaudio->buffer[i] = NUM2DBL(rb_ary_entry(buffer, i));
}
#ifdef RUBY_UBF_IO
rb_thread_blocking_region(portaudio_wait, portaudio, RUBY_UBF_IO, NULL);
#else
portaudio_wait(portaudio);
#endif
return self;
}
|