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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
/*
a wrapper for the audioDevice.
Copyright (C) 1998 Martin Vogt
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation.
For more information look at the file COPYRIGHT in this package
*/
#include "dspWrapper.h"
#include "audioIO.h"
#include "../../frame/pcmFrame.h"
#include "../../frame/floatFrame.h"
#include <iostream>
using namespace std;
DSPWrapper::DSPWrapper() {
currentFormat=new PCMFrame(0);
lopenDevice=false;
lopenMixer=false;
audioConstruct();
}
DSPWrapper::~DSPWrapper() {
if (lopenDevice) {
audioClose();
}
if (lopenMixer) {
mixerClose();
}
audioDestruct();
delete currentFormat;
}
int DSPWrapper::isOpenDevice() {
return lopenDevice;
}
int DSPWrapper::openDevice() {
if (lopenDevice==true) {
return true;
}
lopenDevice=audioOpen();
return lopenDevice;
}
int DSPWrapper::closeDevice() {
if (isOpenDevice() == true) {
audioClose();
currentFormat->setFrameFormat(-1,-1);
lopenDevice=false;
}
return true;
}
int DSPWrapper::isOpenMixer() {
return lopenMixer;
}
int DSPWrapper::getAudioBufferSize() {
return ::getAudioBufferSize();
}
int DSPWrapper::openMixer() {
lopenMixer=mixerOpen();
return lopenMixer;
}
int DSPWrapper::closeMixer() {
if (isOpenMixer() == true) {
mixerClose();
lopenMixer=false;
}
return true;
}
int DSPWrapper::audioPlay(char *buf, int len) {
return audioWrite(buf,len);
}
int DSPWrapper::audioSetup(int stereo,int sampleSize,int lSigned,
int lBigEndian,int freq) {
if (isOpenDevice()==false) {
cout << "device not open"<<endl;
exit(-1);
}
/*
cout << "sampleSize:"<<sampleSize<<endl;
cout << "freq:"<<freq<<endl;
cout << "stereo:"<<stereo<<endl;
cout << "lSigned:"<<lSigned<<endl;
cout << "lBigEndian:"<<lBigEndian<<endl;
*/
audioInit(sampleSize,freq,stereo,lSigned,lBigEndian);
if (currentFormat->getSampleSize() != sampleSize) {
cout << "FIXME: pcmFrame with sampleSize:"<<sampleSize<<endl;
}
currentFormat->setFrameFormat(stereo,freq);
return true;
}
int DSPWrapper::audioSetup(AudioFrame* audioFrame) {
if (audioFrame == NULL) {
cout << "audioFrame NULL: DSPWrapper:audioSetup"<<endl;
exit(0);
}
if(audioFrame->isFormatEqual(currentFormat)==false) {
audioSetup(audioFrame->getStereo(),audioFrame->getSampleSize(),
audioFrame->getSigned(),audioFrame->getBigEndian(),
audioFrame->getFrequenceHZ());
}
return true;
}
int DSPWrapper::audioPlay(PCMFrame* pcmFrame) {
if (pcmFrame == NULL) {
cout << "pcmFrame NULL: DSPWrapper:audioPlay"<<endl;
exit(0);
}
if(pcmFrame->isFormatEqual(currentFormat)==false) {
audioSetup(pcmFrame->getStereo(),pcmFrame->getSampleSize(),
pcmFrame->getSigned(),pcmFrame->getBigEndian(),
pcmFrame->getFrequenceHZ());
}
int len=pcmFrame->getLen()*2;
int played=audioPlay((char*)pcmFrame->getData(),len);
return (len == played);
}
//
// Misuse our internal currentFormat for the float->int conversion.
//
int DSPWrapper::audioPlay(FloatFrame* floatFrame) {
if (floatFrame == NULL) {
cout << "floatFrame NULL: DSPWrapper:audioPlay"<<endl;
exit(0);
}
if(floatFrame->isFormatEqual(currentFormat)==false) {
audioSetup(floatFrame->getStereo(),floatFrame->getSampleSize(),
floatFrame->getSigned(),floatFrame->getBigEndian(),
floatFrame->getFrequenceHZ());
}
int tmpLen=currentFormat->getLen();
if (tmpLen < floatFrame->getLen()) {
delete currentFormat;
currentFormat=new PCMFrame(floatFrame->getLen());
floatFrame->copyFormat(currentFormat);
}
currentFormat->clearrawdata();
currentFormat->putFloatData(floatFrame->getData(),floatFrame->getLen());
return audioPlay(currentFormat);
}
void DSPWrapper::audioFlush() {
closeDevice();
}
void DSPWrapper::setVolume(float leftPercent,float rightPercent) {
if (isOpenMixer()) {
mixerSetVolume((int)leftPercent,(int)rightPercent);
} else {
cout << "cannot set Mixer settings:not open!"<<endl;
}
}
void DSPWrapper::print() {
cout<<"lopenDevice:"<<lopenDevice<<endl;
cout<<"lopenMixer:"<<lopenMixer<<endl;
currentFormat->print("currentFormat");
}
|