forked from openframeworks/openFrameworks
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathofxEmscriptenSoundStream.cpp
More file actions
98 lines (76 loc) · 2.6 KB
/
ofxEmscriptenSoundStream.cpp
File metadata and controls
98 lines (76 loc) · 2.6 KB
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
88
89
90
91
92
93
94
95
96
97
98
/*
* ofxEmscriptenSoundStream.cpp
*
* Created on: May 16, 2014
* Author: arturo
*/
#include "ofxEmscriptenSoundStream.h"
// #include "html5audio.h"
#include "ofBaseApp.h"
#include "ofLog.h"
using namespace std;
int ofxEmscriptenAudioContext();
ofxEmscriptenSoundStream::ofxEmscriptenSoundStream()
:context(ofxEmscriptenAudioContext())
,tickCount(0)
{
}
ofxEmscriptenSoundStream::~ofxEmscriptenSoundStream() {
close();
}
std::vector<ofSoundDevice> ofxEmscriptenSoundStream::getDeviceList(ofSoundDevice::Api api) const{
//html5audio_list_devices();
return vector<ofSoundDevice>();
}
bool ofxEmscriptenSoundStream::setup(const ofSoundStreamSettings & settings) {
inbuffer.allocate(settings.bufferSize, settings.numInputChannels);
outbuffer.allocate(settings.bufferSize, settings.numOutputChannels);
this->settings = settings;
//html5audio_stream_create(settings.bufferSize,settings.numInputChannels,settings.numOutputChannels,inbuffer.getBuffer().data(),outbuffer.getBuffer().data(),&audio_cb,this);
return true;
}
void ofxEmscriptenSoundStream::setInput(ofBaseSoundInput* soundInput) {
this->settings.setInListener(soundInput);
}
void ofxEmscriptenSoundStream::setOutput(ofBaseSoundOutput* soundOutput) {
this->settings.setOutListener(soundOutput);
}
ofSoundDevice ofxEmscriptenSoundStream::getInDevice() const{
return ofSoundDevice();
}
ofSoundDevice ofxEmscriptenSoundStream::getOutDevice() const{
return ofSoundDevice();
}
void ofxEmscriptenSoundStream::start() {
//html5audio_context_start();
}
void ofxEmscriptenSoundStream::stop() {
//html5audio_context_stop();
}
void ofxEmscriptenSoundStream::close() {
//html5audio_stream_free();
}
uint64_t ofxEmscriptenSoundStream::getTickCount() const{
return tickCount;
}
int ofxEmscriptenSoundStream::getNumInputChannels() const{
return settings.numInputChannels;
}
int ofxEmscriptenSoundStream::getNumOutputChannels() const{
return settings.numOutputChannels;
}
int ofxEmscriptenSoundStream::getSampleRate() const{
return 0;//html5audio_context_samplerate();
}
int ofxEmscriptenSoundStream::getBufferSize() const{
return settings.bufferSize;
}
void ofxEmscriptenSoundStream::audio_cb( int bufferSize, int inputChannels, int outputChannels, void * userData){
ofxEmscriptenSoundStream * stream = (ofxEmscriptenSoundStream*) userData;
stream->audioCB(bufferSize,inputChannels,outputChannels);
}
void ofxEmscriptenSoundStream::audioCB(int bufferSize, int inputChannels, int outputChannels){
if(inputChannels>0 && settings.inCallback) settings.inCallback(inbuffer);
if(outputChannels>0 && settings.outCallback) settings.outCallback(outbuffer);
tickCount++;
}