-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.cpp
executable file
·87 lines (71 loc) · 1.6 KB
/
player.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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
86
87
/*
* player.cpp
* rtaudiotest
*
* Created by Chris on 23/08/2011.
* Copyright 2011 Goldsmiths Creative Computing. All rights reserved.
*
*/
#include "Maximilian.hpp"
#include <vector>
#include <iostream>
using namespace Maximilian;
void play(double* output);//run dac! Very very often. Too often in fact. er...
int routing(void* outputBuffer, void* inputBuffer, unsigned int nBufferFrames,
double streamTime, AudioStreamStatus status, void* userData)
{
unsigned int i, j;
double* buffer = (double*)outputBuffer;
double* lastValues = (double*)userData;
// double currentTime = (double) streamTime; Might come in handy for control
if (status)
{
std::cout << "Stream underflow detected!" << std::endl;
}
for (i = 0; i < nBufferFrames; i++)
{
}
// Write interleaved audio data.
for (i = 0; i < nBufferFrames; i++)
{
play(lastValues);
for (j = 0; j < Settings::CHANNELS; j++)
{
*buffer++ = lastValues[j];
}
}
return 0;
}
int main()
{
Audio dac(SupportedArchitectures::Windows_Ds);
unsigned int sampleRate = Settings::SAMPLE_RATE;
unsigned int bufferFrames = Settings::BUFFER_SIZE;
std::vector <double> data(Settings::CHANNELS, 0);
try
{
dac.openStream(RTAUDIO_FLOAT64,
sampleRate, &bufferFrames, &routing, (void*)&(data[0]));
dac.startStream();
}
catch (Exception& e)
{
e.printMessage();
exit(0);
}
char input;
std::cout << "\nMaximilian is playing ... press <enter> to quit.\n";
std::cin.get(input);
try
{
// Stop the stream
dac.stopStream();
}
catch (Exception& e)
{
e.printMessage();
}
if (dac.isStreamOpen())
{ dac.closeStream(); }
return 0;
}