summaryrefslogtreecommitdiff
path: root/tests/play_saw.cpp
diff options
context:
space:
mode:
authorGary Scavone <gary@music.mcgill.ca>2013-10-09 23:46:54 +0200
committerStephen Sinclair <sinclair@music.mcgill.ca>2013-10-10 01:08:39 +0200
commit8cd04dd6b77f05fe0f032959dfefda58b2ce38ae (patch)
tree05ea4287636967811199897e9f6b23fedd87f946 /tests/play_saw.cpp
parent45906f9f72aaf6578431e68a06a0cdb0bf6ccec8 (diff)
Version 3.0
Diffstat (limited to 'tests/play_saw.cpp')
-rw-r--r--tests/play_saw.cpp60
1 files changed, 31 insertions, 29 deletions
diff --git a/tests/play_saw.cpp b/tests/play_saw.cpp
index d028be5..4b2cbdd 100644
--- a/tests/play_saw.cpp
+++ b/tests/play_saw.cpp
@@ -10,57 +10,56 @@
/******************************************/
#include "RtAudio.h"
-#include <iostream.h>
+#include <iostream>
/*
typedef signed long MY_TYPE;
-#define FORMAT RtAudio::RTAUDIO_SINT24
+#define FORMAT RTAUDIO_SINT24
#define SCALE 2147483647.0
-*/
typedef char MY_TYPE;
-#define FORMAT RtAudio::RTAUDIO_SINT8
+#define FORMAT RTAUDIO_SINT8
#define SCALE 127.0
+*/
-/*
typedef signed short MY_TYPE;
-#define FORMAT RtAudio::RTAUDIO_SINT16
+#define FORMAT RTAUDIO_SINT16
#define SCALE 32767.0
-
+/*
typedef signed long MY_TYPE;
-#define FORMAT RtAudio::RTAUDIO_SINT32
+#define FORMAT RTAUDIO_SINT32
#define SCALE 2147483647.0
typedef float MY_TYPE;
-#define FORMAT RtAudio::RTAUDIO_FLOAT32
+#define FORMAT RTAUDIO_FLOAT32
#define SCALE 1.0
typedef double MY_TYPE;
-#define FORMAT RtAudio::RTAUDIO_FLOAT64
+#define FORMAT RTAUDIO_FLOAT64
#define SCALE 1.0
*/
#define BASE_RATE 0.005
-#define TIME 1.0
+#define TIME 4.0
void usage(void) {
// Error function in case of incorrect command-line
// argument specifications.
- cout << "\nuseage: play_saw N fs <device>\n";
- cout << " where N = number of channels,\n";
- cout << " fs = the sample rate,\n";
- cout << " and device = the device to use (default = 0).\n\n";
+ std::cout << "\nuseage: play_saw N fs <device>\n";
+ std::cout << " where N = number of channels,\n";
+ std::cout << " fs = the sample rate,\n";
+ std::cout << " and device = the device to use (default = 0).\n\n";
exit(0);
}
int main(int argc, char *argv[])
{
- int chans, fs, buffer_size, stream, device = 0;
+ int chans, fs, buffer_size, device = 0;
long frames, counter = 0, i, j;
MY_TYPE *buffer;
RtAudio *audio;
- double *data;
+ double *data = 0;
// minimal command-line checking
if (argc != 3 && argc != 4 ) usage();
@@ -73,10 +72,11 @@ int main(int argc, char *argv[])
// Open the realtime output device
buffer_size = 512;
try {
- audio = new RtAudio(&stream, device, chans, 0, 0,
+ audio = new RtAudio(device, chans, 0, 0,
FORMAT, fs, &buffer_size, 4);
}
- catch (RtError &) {
+ catch (RtError &error) {
+ error.printMessage();
exit(EXIT_FAILURE);
}
@@ -84,14 +84,15 @@ int main(int argc, char *argv[])
data = (double *) calloc(chans, sizeof(double));
try {
- buffer = (MY_TYPE *) audio->getStreamBuffer(stream);
- audio->startStream(stream);
+ buffer = (MY_TYPE *) audio->getStreamBuffer();
+ audio->startStream();
}
- catch (RtError &) {
+ catch (RtError &error) {
+ error.printMessage();
goto cleanup;
}
- cout << "\nPlaying for " << TIME << " seconds ... buffer size = " << buffer_size << "." << endl;
+ std::cout << "\nPlaying for " << TIME << " seconds ... buffer size = " << buffer_size << "." << std::endl;
while (counter < frames) {
for (i=0; i<buffer_size; i++) {
for (j=0; j<chans; j++) {
@@ -102,10 +103,10 @@ int main(int argc, char *argv[])
}
try {
- //cout << "frames until no block = " << audio->streamWillBlock(stream) << endl;
- audio->tickStream(stream);
+ audio->tickStream();
}
- catch (RtError &) {
+ catch (RtError &error) {
+ error.printMessage();
goto cleanup;
}
@@ -113,13 +114,14 @@ int main(int argc, char *argv[])
}
try {
- audio->stopStream(stream);
+ audio->stopStream();
}
- catch (RtError &) {
+ catch (RtError &error) {
+ error.printMessage();
}
cleanup:
- audio->closeStream(stream);
+ audio->closeStream();
delete audio;
if (data) free(data);