forked from openframeworks/openFrameworks
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathofxEmscriptenSoundPlayer.cpp
More file actions
159 lines (128 loc) · 4.13 KB
/
ofxEmscriptenSoundPlayer.cpp
File metadata and controls
159 lines (128 loc) · 4.13 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
* ofxEmscriptenSoundPlayer.cpp
*
* Created on: May 15, 2014
* Author: arturo
*/
#include "ofFileUtils.h"
#include "ofxEmscriptenSoundPlayer.h"
// #include "html5audio.h"
using namespace std;
vector<float> ofxEmscriptenSoundPlayer::systemSpectrum;
int ofxEmscriptenAudioContext(){
static bool initialized=false;
static int context = -1;
if(!initialized){
context = //html5audio_context_create();
initialized = true;
}
return context;
}
ofxEmscriptenSoundPlayer::ofxEmscriptenSoundPlayer()
:context(ofxEmscriptenAudioContext())
,multiplay(false)
,volume(0.5)
,speed(1)
,pan(0)
,playing(false)
,player_id(0){
//,player_id(//html5audio_player_create()){
}
ofxEmscriptenSoundPlayer::~ofxEmscriptenSoundPlayer(){
//html5audio_sound_free(player_id);
}
bool ofxEmscriptenSoundPlayer::load(const of::filesystem::path& filePath, bool stream){
auto soundFilePath = filePath.string();
if ( soundFilePath.substr(0, 7) != "http://" && soundFilePath.substr(0, 8) != "https://"){
soundFilePath = ofToDataPath(soundFilePath);
}
//html5audio_sound_load(player_id, soundFilePath.c_str());
return true;
}
//bool ofxEmscriptenSoundPlayer::load(const std::string& fileName, bool stream){
// //html5audio_sound_load(player_id, fileName.c_str());
// return true;
//}
void ofxEmscriptenSoundPlayer::unload(){
//html5audio_sound_free(player_id);
}
void ofxEmscriptenSoundPlayer::play(){
// if(playing && !multiplay && !//html5audio_sound_done(player_id)){
//html5audio_sound_stop(player_id);
// }
//html5audio_sound_play(player_id, multiplay, volume, speed, pan, 0);
//html5audio_sound_set_rate(player_id, speed);
//html5audio_sound_set_volume(player_id, volume);
playing = true;
}
void ofxEmscriptenSoundPlayer::stop(){
//html5audio_sound_stop(player_id);
playing = false;
}
void ofxEmscriptenSoundPlayer::setVolume(float vol){
volume = vol;
//html5audio_sound_set_volume(player_id, vol);
}
void ofxEmscriptenSoundPlayer::setPan(float panorama){
pan = panorama;
//html5audio_sound_set_pan(player_id, pan);
}
void ofxEmscriptenSoundPlayer::setSpeed(float spd){
speed = spd;
//html5audio_sound_set_rate(player_id, spd);
}
void ofxEmscriptenSoundPlayer::setPaused(bool bP){
// if(bP) //html5audio_sound_pause(player_id);
// else //html5audio_sound_play(player_id, multiplay, volume, speed, pan, 0);
}
void ofxEmscriptenSoundPlayer::setLoop(bool bLp){
//html5audio_sound_set_loop(player_id, bLp);
}
void ofxEmscriptenSoundPlayer::setMultiPlay(bool bMp){
multiplay = bMp;
}
void ofxEmscriptenSoundPlayer::setPosition(float pct){
//html5audio_sound_set_position(player_id, pct);
}
void ofxEmscriptenSoundPlayer::setPositionMS(int ms){
//html5audio_sound_set_position(player_id, ms / //html5audio_sound_duration(player_id) / 1000);
}
float ofxEmscriptenSoundPlayer::getPosition() const{
return 0;//html5audio_sound_position(player_id);
}
int ofxEmscriptenSoundPlayer::getPositionMS() const{
return 0;//html5audio_sound_position(player_id) * //html5audio_sound_duration(player_id) * 1000;
}
bool ofxEmscriptenSoundPlayer::isPlaying() const{
return false;
//return playing && !//html5audio_sound_done(player_id);
}
float ofxEmscriptenSoundPlayer::getSpeed() const{
return 0;//html5audio_sound_rate(player_id);
}
float ofxEmscriptenSoundPlayer::getPan() const{
return 0;//html5audio_sound_pan(player_id);
}
bool ofxEmscriptenSoundPlayer::isLoaded() const{
return false;//html5audio_sound_is_loaded(player_id);
}
float ofxEmscriptenSoundPlayer::getVolume() const{
return 0;//html5audio_sound_volume(player_id);
}
float ofxEmscriptenSoundPlayer::getDuration() const {
return 0;//html5audio_sound_duration(player_id);
}
unsigned int ofxEmscriptenSoundPlayer::getDurationMS() const{
return 0;//html5audio_sound_duration(player_id) * 1000;
}
double ofxEmscriptenSoundPlayer::getDurationSecs() const{
return 0;//html5audio_sound_duration(player_id);
}
float * ofxEmscriptenSoundPlayer::getSystemSpectrum(int bands){
systemSpectrum.resize(bands);
//html5audio_context_spectrum(bands, &systemSpectrum[0]);
for(size_t i = 0; i < systemSpectrum.size(); i++){
systemSpectrum[i] = (systemSpectrum[i]+100) * 0.01;
}
return &systemSpectrum[0];
}