forked from CaptainDreamcast/prism
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sound_dc.cpp
139 lines (102 loc) · 2.43 KB
/
sound_dc.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
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
#include "prism/sound.h"
#include <kos.h>
#include <dc/sound/sound.h>
#include <vorbis/sndoggvorbis.h>
#include "prism/file.h"
#include "prism/thread.h"
#include "prism/system.h"
#define BUF_SIZE 65536 /* Size of buffer */
static struct {
int mVolume;
double mPanning;
int mIsStreamingSoundFile;
uint64_t mStreamStartTime;
} gData;
void initSound() {
gData.mVolume = 1;
gData.mPanning = 0;
snd_init();
snd_stream_init();
sndoggvorbis_init();
}
void shutdownSound(){
}
double getVolume() {
return gData.mVolume;
}
void setVolume(double tVolume) {
gData.mVolume = (int)(15*tVolume);
spu_cdda_volume(gData.mVolume, gData.mVolume);
}
double getPanningValue() {
return gData.mPanning;
}
void setPanningValue(int /*tChannel*/, double tPanning) {
gData.mPanning = tPanning;
}
void playTrack(int tTrack) {
cdrom_cdda_play(tTrack, tTrack, 15, CDDA_TRACKS);
}
void playTrackOnce(int tTrack) {
cdrom_cdda_play(tTrack, tTrack, 0, CDDA_TRACKS);
}
void stopTrack() {
cdrom_cdda_pause();
}
void pauseTrack() {
cdrom_cdda_pause();
}
void resumeTrack() {
cdrom_cdda_resume();
}
static uint64_t getCurrentTimeInMilliseconds() {
return getSystemTicks();
}
static void streamMusicFileGeneral(const char* tPath, int tLoop) {
char fullPath[1024];
getFullPath(fullPath, tPath);
sndoggvorbis_start(fullPath, tLoop);
gData.mStreamStartTime = getCurrentTimeInMilliseconds();
gData.mIsStreamingSoundFile = 1;
}
void streamMusicFile(const char* tPath) {
streamMusicFileGeneral(tPath, 1);
}
void streamMusicFileOnce(const char* tPath) {
streamMusicFileGeneral(tPath, 0);
}
void stopStreamingMusicFile() {
if(!gData.mIsStreamingSoundFile) return;
sndoggvorbis_stop();
gData.mIsStreamingSoundFile = 0;
}
uint64_t getStreamingSoundTimeElapsedInMilliseconds() {
if(!sndoggvorbis_isplaying()) {
gData.mIsStreamingSoundFile = 0;
}
return (uint64_t)(getCurrentTimeInMilliseconds() - gData.mStreamStartTime);
}
int isPlayingStreamingMusic() {
return gData.mIsStreamingSoundFile;
}
void stopMusic() {
stopTrack();
stopStreamingMusicFile();
}
void pauseMusic() {
pauseTrack();
// TODO: pause streaming
}
void resumeMusic() {
resumeTrack();
// TODO: resume streaming
}
static ActorBlueprint MicrophoneHandler; // TODO: implement microphone
ActorBlueprint getMicrophoneHandlerActorBlueprint()
{
return MicrophoneHandler;
}
double getMicrophoneVolume()
{
return 0; // TODO: implement microphone
}