Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
savoirfairelinux
jami-daemon
Commits
6aceecc3
Commit
6aceecc3
authored
Oct 05, 2011
by
Tristan Matthews
Browse files
* #7097: cleanup, removed redundant code in audio backend
parent
6456ab37
Changes
14
Hide whitespace changes
Inline
Side-by-side
daemon/src/audio/audioloop.cpp
View file @
6aceecc3
...
...
@@ -37,23 +37,21 @@
#include
<cstring>
#include
<cassert>
AudioLoop
::
AudioLoop
()
:
_
buffer
(
0
),
_
size
(
0
),
_
pos
(
0
),
_
sampleRate
(
0
)
AudioLoop
::
AudioLoop
()
:
buffer
_
(
0
),
size
_
(
0
),
pos
_
(
0
),
sampleRate
_
(
0
)
{
}
AudioLoop
::~
AudioLoop
()
{
delete
[]
_
buffer
;
delete
[]
buffer
_
;
}
void
AudioLoop
::
getNext
(
SFLDataFormat
*
output
,
size_t
total_samples
,
short
volume
)
{
size_t
pos
=
_
pos
;
size_t
pos
=
pos
_
;
assert
(
_size
);
if
(
_size
==
0
)
{
if
(
size_
==
0
)
{
_error
(
"AudioLoop: Error: Audio loop size is 0"
);
return
;
}
...
...
@@ -61,26 +59,26 @@ AudioLoop::getNext (SFLDataFormat* output, size_t total_samples, short volume)
while
(
total_samples
)
{
size_t
samples
=
total_samples
;
if
(
samples
>
(
_size
-
pos
))
{
samples
=
_size
-
pos
;
}
if
(
samples
>
(
size_
-
pos
))
samples
=
size_
-
pos
;
memcpy
(
output
,
_buffer
+
pos
,
samples
*
sizeof
(
SFLDataFormat
));
// short>char conversion
// short->char conversion
memcpy
(
output
,
buffer_
+
pos
,
samples
*
sizeof
(
SFLDataFormat
));
if
(
volume
!=
100
)
{
for
(
size_t
i
=
0
;
i
<
samples
;
i
++
)
{
*
output
=
(
*
output
*
volume
)
/
100
;
if
(
volume
!=
100
)
{
double
gain
=
volume
*
0.01
;
for
(
size_t
i
=
0
;
i
<
samples
;
i
++
)
{
*
output
*=
gain
;
output
++
;
}
}
else
{
}
else
output
+=
samples
;
// this is the destination...
}
pos
=
(
pos
+
samples
)
%
_
size
;
pos
=
(
pos
+
samples
)
%
size
_
;
total_samples
-=
samples
;
}
_
pos
=
pos
;
pos
_
=
pos
;
}
daemon/src/audio/audioloop.h
View file @
6aceecc3
...
...
@@ -61,36 +61,36 @@ class AudioLoop
* @param nb of int16 to send
* @param volume The volume
*/
void
getNext
(
SFLDataFormat
*
output
,
size_t
samples
,
short
volume
=
100
);
void
getNext
(
SFLDataFormat
*
output
,
size_t
samples
,
short
volume
=
100
);
/**
* Reset the pointer position
*/
void
reset
()
{
_
pos
=
0
;
pos
_
=
0
;
}
/**
* Accessor to the size of the buffer
* @return unsigned int The size
*/
size_t
getSize
()
{
return
_
size
;
size_t
getSize
()
const
{
return
size
_
;
}
protected:
/** The data buffer */
SFLDataFormat
*
_
buffer
;
SFLDataFormat
*
buffer
_
;
/** Number of samples inside the buffer */
size_t
_
size
;
size_t
size
_
;
/** current position, set to 0, when initialize */
size_t
_
pos
;
size_t
pos
_
;
/** Sample rate */
unsigned
int
_
sampleRate
;
unsigned
int
sampleRate
_
;
private:
...
...
daemon/src/audio/audiorecord.cpp
View file @
6aceecc3
...
...
@@ -73,17 +73,9 @@ AudioRecord::AudioRecord() : fp (NULL)
AudioRecord
::~
AudioRecord
()
{
if
(
mixBuffer_
)
{
delete
[]
mixBuffer_
;
}
if
(
micBuffer_
)
{
delete
[]
micBuffer_
;
}
if
(
spkBuffer_
)
{
delete
[]
spkBuffer_
;
}
delete
[]
mixBuffer_
;
delete
[]
micBuffer_
;
delete
[]
spkBuffer_
;
}
void
AudioRecord
::
setSndSamplingRate
(
int
smplRate
)
...
...
@@ -96,16 +88,12 @@ int AudioRecord::getSndSamplingRate() const
return
sndSmplRate_
;
}
void
AudioRecord
::
setRecordingOption
(
FILE_TYPE
type
,
SOUND_FORMAT
format
,
int
sndSmplRate
,
std
::
string
path
)
void
AudioRecord
::
setRecordingOption
(
FILE_TYPE
type
,
int
sndSmplRate
,
const
std
::
string
&
path
)
{
fileType_
=
type
;
sndFormat_
=
format
;
channels_
=
1
;
sndSmplRate_
=
sndSmplRate
;
savePath_
=
path
+
"/"
;
}
...
...
@@ -309,11 +297,6 @@ bool AudioRecord::setRawFile()
return
false
;
}
if
(
sndFormat_
!=
INT16
)
{
// TODO need to change INT16 to SINT16
sndFormat_
=
INT16
;
_debug
(
"AudioRecord::setRawFile() : using 16-bit signed integer data format for file."
);
}
_debug
(
"AudioRecord:setRawFile() : created RAW file."
);
return
true
;
...
...
@@ -342,9 +325,7 @@ bool AudioRecord::setWavFile()
hdr
.
num_chans
=
channels_
;
if
(
sndFormat_
==
INT16
)
{
// TODO need to write INT16 to SINT16
hdr
.
bits_per_samp
=
16
;
}
hdr
.
bits_per_samp
=
16
;
hdr
.
bytes_per_samp
=
(
SINT16
)
(
channels_
*
hdr
.
bits_per_samp
/
8
);
...
...
@@ -499,15 +480,11 @@ void AudioRecord::recData (SFLDataFormat* buffer, int nSamples)
return
;
}
if
(
sndFormat_
==
INT16
)
{
// TODO change INT16 to SINT16
if
(
fwrite
(
buffer
,
sizeof
(
SFLDataFormat
),
nSamples
,
fp
)
!=
(
unsigned
int
)
nSamples
)
_warn
(
"AudioRecord: Could not record data! "
);
else
{
fflush
(
fp
);
byteCounter_
+=
(
unsigned
long
)
(
nSamples
*
sizeof
(
SFLDataFormat
));
}
if
(
fwrite
(
buffer
,
sizeof
(
SFLDataFormat
),
nSamples
,
fp
)
!=
(
unsigned
int
)
nSamples
)
_warn
(
"AudioRecord: Could not record data! "
);
else
{
fflush
(
fp
);
byteCounter_
+=
(
unsigned
long
)
(
nSamples
*
sizeof
(
SFLDataFormat
));
}
}
...
...
@@ -527,25 +504,16 @@ void AudioRecord::recData (SFLDataFormat* buffer_1, SFLDataFormat* buffer_2, int
return
;
}
for
(
int
k
=
0
;
k
<
nSamples_1
;
k
++
)
{
mixBuffer_
[
k
]
=
(
buffer_1
[
k
]
+
buffer_2
[
k
]);
if
(
sndFormat_
==
INT16
)
{
// TODO change INT16 to SINT16
for
(
int
k
=
0
;
k
<
nSamples_1
;
k
++
)
{
mixBuffer_
[
k
]
=
(
buffer_1
[
k
]
+
buffer_2
[
k
]);
if
(
fwrite
(
&
mixBuffer_
[
k
],
2
,
1
,
fp
)
!=
1
)
_warn
(
"AudioRecord: Could not record data!"
);
else
{
fflush
(
fp
);
}
}
if
(
fwrite
(
&
mixBuffer_
[
k
],
2
,
1
,
fp
)
!=
1
)
_warn
(
"AudioRecord: Could not record data!"
);
else
fflush
(
fp
);
}
byteCounter_
+=
(
unsigned
long
)
(
nSamples_1
*
sizeof
(
SFLDataFormat
));
byteCounter_
+=
(
unsigned
long
)
(
nSamples_1
*
sizeof
(
SFLDataFormat
));
}
return
;
}
daemon/src/audio/audiorecord.h
View file @
6aceecc3
...
...
@@ -40,25 +40,19 @@ class AudioRecord
{
public:
enum
FILE_TYPE
{
FILE_RAW
,
FILE_WAV
};
AudioRecord
();
~
AudioRecord
();
/**
* Set the sampling rate for this recorder
*/
void
setSndSamplingRate
(
int
smplRate
);
/**
* Get the recrding sampling rate
*/
void
setSndSamplingRate
(
int
smplRate
);
/**
* Get the recrding sampling rate
*/
int
getSndSamplingRate
(
void
)
const
;
/**
* Set the recording option
*/
void
setRecordingOption
(
FILE_TYPE
type
,
SOUND_FORMAT
format
,
int
sndSmplRate
,
std
::
string
path
);
void
setRecordingOption
(
FILE_TYPE
type
,
int
sndSmplRate
,
const
std
::
string
&
path
);
/**
* Init recording file path
...
...
@@ -184,11 +178,6 @@ class AudioRecord
*/
FILE_TYPE
fileType_
;
/**
* Sound format (SINT16/SINT32)
*/
SOUND_FORMAT
sndFormat_
;
/**
* Number of channels
*/
...
...
daemon/src/audio/audiortp/AudioZrtpSession.cpp
View file @
6aceecc3
...
...
@@ -27,6 +27,8 @@
* shall include the source code for the parts of OpenSSL used as well
* as that of the covered work.
*/
#include
"config.h"
#include
"AudioZrtpSession.h"
#include
"ZrtpSessionCallback.h"
...
...
@@ -49,14 +51,13 @@ namespace sfl
{
AudioZrtpSession
::
AudioZrtpSession
(
SIPCall
*
sipcall
,
const
std
::
string
&
zidFilename
)
:
// ost::SymmetricZRTPSession (ost::InetHostAddress (sipcall->getLocalIp().c_str()), sipcall->getLocalAudioPort()),
AudioRtpSession
(
sipcall
,
Zrtp
,
static_cast
<
ost
::
RTPDataQueue
*>
(
this
),
static_cast
<
ost
::
Thread
*>
(
this
))
,
ost
::
TRTPSessionBase
<
ost
::
SymmetricRTPChannel
,
ost
::
SymmetricRTPChannel
,
ost
::
ZrtpQueue
>
(
ost
::
InetHostAddress
(
sipcall
->
getLocalIp
().
c_str
()),
sipcall
->
getLocalAudioPort
(),
0
,
ost
::
MembershipBookkeeping
::
defaultMembersHashSize
,
ost
::
defaultApplication
())
,
_zidFilename
(
zidFilename
)
AudioRtpSession
(
sipcall
,
Zrtp
,
this
,
this
),
ost
::
TRTPSessionBase
<
ost
::
SymmetricRTPChannel
,
ost
::
SymmetricRTPChannel
,
ost
::
ZrtpQueue
>
(
ost
::
InetHostAddress
(
sipcall
->
getLocalIp
().
c_str
()),
sipcall
->
getLocalAudioPort
(),
0
,
ost
::
MembershipBookkeeping
::
defaultMembersHashSize
,
ost
::
defaultApplication
()),
_zidFilename
(
zidFilename
)
{
_debug
(
"AudioZrtpSession initialized"
);
initializeZid
();
...
...
@@ -96,7 +97,7 @@ void AudioZrtpSession::initializeZid (void)
// xdg_config = std::string (HOMEDIR) + DIR_SEPARATOR_STR + ".cache/sflphone";
std
::
string
xdg_config
=
std
::
string
(
HOMEDIR
)
+
DIR_SEPARATOR_STR
+
".cache"
+
DIR_SEPARATOR_STR
+
P
ROGDIR
+
"/"
+
_zidFilename
;
std
::
string
xdg_config
=
std
::
string
(
HOMEDIR
)
+
DIR_SEPARATOR_STR
+
".cache"
+
DIR_SEPARATOR_STR
+
P
ACKAGE
+
"/"
+
_zidFilename
;
_debug
(
" xdg_config %s"
,
xdg_config
.
c_str
());
...
...
daemon/src/audio/codecs/audiocodecfactory.cpp
View file @
6aceecc3
...
...
@@ -31,6 +31,7 @@
* as that of the covered work.
*/
#include
"config.h"
#include
"audiocodecfactory.h"
#include
<cstdlib>
#include
<algorithm>
// for std::find
...
...
@@ -142,7 +143,7 @@ std::vector<sfl::Codec*> AudioCodecFactory::scanCodecDirectory()
std
::
vector
<
sfl
::
Codec
*>
codecs
;
std
::
vector
<
std
::
string
>
dirToScan
;
dirToScan
.
push_back
(
std
::
string
(
HOMEDIR
)
+
DIR_SEPARATOR_STR
"."
P
ROGDIR
"/"
);
dirToScan
.
push_back
(
std
::
string
(
HOMEDIR
)
+
DIR_SEPARATOR_STR
"."
P
ACKAGE
"/"
);
dirToScan
.
push_back
(
CODECS_DIR
"/"
);
const
char
*
envDir
=
getenv
(
"CODECS_PATH"
);
if
(
envDir
)
...
...
@@ -162,7 +163,7 @@ std::vector<sfl::Codec*> AudioCodecFactory::scanCodecDirectory()
dirent
*
dirStruct
;
while
(
(
dirStruct
=
readdir
(
dir
)))
{
std
::
string
file
=
dirStruct
->
d_name
;
if
(
file
==
CURRENT_DIR
or
file
==
PARENT_DIR
)
if
(
file
==
"."
or
file
==
".."
)
continue
;
if
(
seemsValid
(
file
)
&&
!
alreadyInCache
(
file
))
{
...
...
@@ -243,8 +244,9 @@ bool AudioCodecFactory::seemsValid (const std::string &lib)
{
// The name of the shared library seems valid <==> it looks like libcodec_xxx.so
// We check this
std
::
string
prefix
=
SFL_CODEC_VALID_PREFIX
;
std
::
string
suffix
=
SFL_CODEC_VALID_EXTEN
;
static
const
std
::
string
prefix
(
"libcodec_"
);
static
const
std
::
string
suffix
(
".so"
);
ssize_t
len
=
lib
.
length
()
-
prefix
.
length
()
-
suffix
.
length
();
if
(
len
<
0
)
...
...
@@ -257,17 +259,17 @@ bool AudioCodecFactory::seemsValid (const std::string &lib)
#ifndef HAVE_SPEEX_CODEC
if
(
lib
.
substr
(
prefix
.
length
()
,
len
)
==
SPEEX_STRING_DESCRIPTION
)
if
(
lib
.
substr
(
prefix
.
length
()
,
len
)
==
"speex"
)
return
false
;
#endif
#ifndef HAVE_GSM_CODEC
if
(
lib
.
substr
(
prefix
.
length
()
,
len
)
==
GSM_STRING_DESCRIPTION
)
if
(
lib
.
substr
(
prefix
.
length
()
,
len
)
==
"gsm"
)
return
false
;
#endif
#ifndef BUILD_ILBC
if
(
lib
.
substr
(
prefix
.
length
()
,
len
)
==
ILBC_STRING_DESCRIPTION
)
if
(
lib
.
substr
(
prefix
.
length
()
,
len
)
==
"ilbc"
)
return
false
;
#endif
...
...
daemon/src/audio/recordable.cpp
View file @
6aceecc3
...
...
@@ -32,13 +32,8 @@
Recordable
::
Recordable
()
:
recorder
(
&
recAudio
,
Manager
::
instance
().
getMainBuffer
())
{
_debug
(
"-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Recordable Constructor -=-=-=-=-=-=-=-=-=--=-=-=-"
);
FILE_TYPE
fileType
=
FILE_WAV
;
SOUND_FORMAT
soundFormat
=
INT16
;
recAudio
.
setRecordingOption
(
fileType
,
soundFormat
,
8000
,
Manager
::
instance
().
audioPreference
.
getRecordpath
());
recAudio
.
setRecordingOption
(
AudioRecord
::
FILE_WAV
,
8000
,
Manager
::
instance
().
audioPreference
.
getRecordpath
());
}
...
...
daemon/src/audio/samplerateconverter.cpp
View file @
6aceecc3
...
...
@@ -39,8 +39,8 @@ SamplerateConverter::SamplerateConverter (int freq) : _maxFreq(freq)
_samples
=
(
freq
*
20
)
/
1000
;
// start with 20 ms buffers
_floatBufferIn
=
new
float
32
[
_samples
];
_floatBufferOut
=
new
float
32
[
_samples
];
_floatBufferIn
=
new
float
[
_samples
];
_floatBufferOut
=
new
float
[
_samples
];
}
SamplerateConverter
::~
SamplerateConverter
(
void
)
...
...
@@ -61,7 +61,6 @@ SamplerateConverter::Short2FloatArray (const short *in, float *out, int len)
out
[
len
]
=
(
float
)
in
[
len
]
*
.000030517578125
f
;
}
//TODO Add ifdef for int16 or float32 type
void
SamplerateConverter
::
resample
(
SFLDataFormat
*
dataIn
,
SFLDataFormat
*
dataOut
,
int
inputFreq
,
int
outputFreq
,
int
nbSamples
)
{
double
sampleFactor
=
(
double
)
outputFreq
/
inputFreq
;
...
...
@@ -77,8 +76,8 @@ void SamplerateConverter::resample (SFLDataFormat* dataIn , SFLDataFormat* dataO
_samples
=
maxSamples
;
delete
[]
_floatBufferIn
;
delete
[]
_floatBufferOut
;
_floatBufferIn
=
new
float
32
[
_samples
];
_floatBufferOut
=
new
float
32
[
_samples
];
_floatBufferIn
=
new
float
[
_samples
];
_floatBufferOut
=
new
float
[
_samples
];
}
SRC_DATA
src_data
;
...
...
daemon/src/audio/samplerateconverter.h
View file @
6aceecc3
...
...
@@ -78,8 +78,8 @@ class SamplerateConverter
SamplerateConverter
&
operator
=
(
const
SamplerateConverter
&
rh
);
/* temporary buffers */
float
32
*
_floatBufferIn
;
float
32
*
_floatBufferOut
;
float
*
_floatBufferIn
;
float
*
_floatBufferOut
;
size_t
_samples
;
// size in samples of temporary buffers
int
_maxFreq
;
// maximal output frequency
...
...
daemon/src/audio/sound/audiofile.cpp
View file @
6aceecc3
...
...
@@ -73,51 +73,40 @@ RawFile::RawFile(const std::string& name, sfl::AudioCodec* codec, unsigned int s
SFLDataFormat
*
monoBuffer
=
new
SFLDataFormat
[
decodedSize
];
SFLDataFormat
*
bufpos
=
monoBuffer
;
unsigned
char
*
filepos
=
reinterpret_cast
<
unsigned
char
*>
(
fileBuffer
);
_
size
=
decodedSize
;
while
(
length
>=
encFrameSize
)
{
size
_
=
decodedSize
;
while
(
length
>=
encFrameSize
)
{
bufpos
+=
audioCodec
->
decode
(
bufpos
,
filepos
,
encFrameSize
);
filepos
+=
encFrameSize
;
length
-=
encFrameSize
;
}
delete
[]
fileBuffer
;
if
(
sampleRate
==
audioRate
)
{
#ifdef DATAFORMAT_IS_FLOAT
_buffer
=
new
SFLDataFormat
[
_size
];
src_short_to_float_array
(
monoBuffer
,
_buffer
,
_size
);
delete
[]
monoBuffer
;
#else
_buffer
=
monoBuffer
;
#endif
}
else
{
delete
[]
fileBuffer
;
if
(
sampleRate
==
audioRate
)
buffer_
=
monoBuffer
;
else
{
double
factord
=
(
double
)
sampleRate
/
audioRate
;
float
*
floatBufferIn
=
new
float
[
_size
];
int
sizeOut
=
ceil
(
factord
*
_size
);
src_short_to_float_array
(
monoBuffer
,
floatBufferIn
,
_size
);
delete
[]
monoBuffer
;
SFLDataFormat
*
_buffer
=
new
SFLDataFormat
[
sizeOut
];
float
*
floatBufferIn
=
new
float
[
size_
];
int
sizeOut
=
ceil
(
factord
*
size_
);
src_short_to_float_array
(
monoBuffer
,
floatBufferIn
,
size_
);
delete
[]
monoBuffer
;
delete
[]
buffer_
;
buffer_
=
new
SFLDataFormat
[
sizeOut
];
SRC_DATA
src_data
;
src_data
.
data_in
=
floatBufferIn
;
src_data
.
input_frames
=
_
size
;
src_data
.
input_frames
=
size
_
;
src_data
.
output_frames
=
sizeOut
;
src_data
.
src_ratio
=
factord
;
#ifdef DATAFORMAT_IS_FLOAT
src_data
.
data_out
=
_buffer
;
src_simple
(
&
src_data
,
SRC_SINC_BEST_QUALITY
,
1
);
#else
float
*
floatBufferOut
=
new
float
[
sizeOut
];
src_data
.
data_out
=
floatBufferOut
;
src_simple
(
&
src_data
,
SRC_SINC_BEST_QUALITY
,
1
);
src_float_to_short_array
(
floatBufferOut
,
_
buffer
,
src_data
.
output_frames_gen
);
src_float_to_short_array
(
floatBufferOut
,
buffer
_
,
src_data
.
output_frames_gen
);
delete
[]
floatBufferOut
;
#endif
delete
[]
floatBufferIn
;
_
size
=
src_data
.
output_frames_gen
;
size
_
=
src_data
.
output_frames_gen
;
}
}
...
...
@@ -148,8 +137,8 @@ WaveFile::WaveFile (const std::string& fileName, unsigned int audioSamplingRate)
SINT32
chunk_size
;
// fmt chunk size
unsigned
short
formatTag
;
// data compression tag
fileStream
.
read
(
(
char
*
)
&
chunk_size
,
4
);
// Read fmt chunk size.
fileStream
.
read
(
(
char
*
)
&
formatTag
,
2
);
fileStream
.
read
(
reinterpret_cast
<
char
*
>
(
&
chunk_size
)
,
4
);
// Read fmt chunk size.
fileStream
.
read
(
reinterpret_cast
<
char
*
>
(
&
formatTag
)
,
2
);
if
(
formatTag
!=
1
)
// PCM = 1, FLOAT = 3
throw
AudioFileException
(
"File contains an unsupported data format type"
);
...
...
@@ -158,12 +147,12 @@ WaveFile::WaveFile (const std::string& fileName, unsigned int audioSamplingRate)
SINT16
chan
;
fileStream
.
read
(
(
char
*
)
&
chan
,
2
);
if
(
chan
>
2
)
if
(
chan
>
2
)
throw
AudioFileException
(
"WaveFile: unsupported number of channels"
);
// Get file sample rate from the header.
SINT32
srate
;
fileStream
.
read
(
(
char
*
)
&
srate
,
4
);
fileStream
.
read
(
(
char
*
)
&
srate
,
4
);
SINT32
avgb
;
fileStream
.
read
(
(
char
*
)
&
avgb
,
4
);
...
...
@@ -185,7 +174,7 @@ WaveFile::WaveFile (const std::string& fileName, unsigned int audioSamplingRate)
// Sample rate converter initialized with 88200 sample long
int
converterSamples
=
((
unsigned
int
)
srate
>
audioSamplingRate
)
?
srate
:
audioSamplingRate
;
SamplerateConverter
_
converter
(
converterSamples
);
SamplerateConverter
converter
_
(
converterSamples
);
// Get length of data from the header.
SINT32
bytes
;
...
...
@@ -197,31 +186,28 @@ WaveFile::WaveFile (const std::string& fileName, unsigned int audioSamplingRate)
nbSamples
,
bytes
,
blockal
,
srate
,
avgb
,
chunk_size
,
dt
);
// Should not be longer than a minute
if
(
nbSamples
>
(
unsigned
int
)
(
60
*
srate
))
nbSamples
=
60
*
srate
;
if
(
nbSamples
>
static_cast
<
unsigned
int
>
(
60
*
srate
))
nbSamples
=
60
*
srate
;
SFLDataFormat
*
tempBuffer
=
new
SFLDataFormat
[
nbSamples
];
if
(
!
tempBuffer
)
throw
AudioFileException
(
"Could not allocate temporary buffer"
);
fileStream
.
read
(
(
char
*
)
tempBuffer
,
nbSamples
*
sizeof
(
SFLDataFormat
));
fileStream
.
read
(
reinterpret_cast
<
char
*
>
(
tempBuffer
)
,
nbSamples
*
sizeof
(
SFLDataFormat
));
// mix two channels together if stereo
if
(
chan
==
2
)
{
for
(
unsigned
int
i
=
0
;
i
<
nbSamples
-
1
;
i
+=
2
)
tempBuffer
[
i
/
2
]
=
(
tempBuffer
[
i
]
+
tempBuffer
[
i
+
1
])
/
2
;
nbSamples
/
=
2
;
if
(
chan
==
2
)
{
for
(
unsigned
int
i
=
0
;
i
<
nbSamples
-
1
;
i
+=
2
)
tempBuffer
[
static_cast
<
size_t
>
(
i
*
0.5
)
]
=
(
tempBuffer
[
i
]
+
tempBuffer
[
i
+
1
])
*
0.5
;
nbSamples
*
=
0.5
;
}
if
((
unsigned
int
)
srate
!=
audioSamplingRate
)
{
if
((
unsigned
int
)
srate
!=
audioSamplingRate
)
{
int
outSamples
=
((
float
)
nbSamples
*
(
(
float
)
audioSamplingRate
/
(
float
)
srate
));
_buffer
=
new
SFLDataFormat
[
outSamples
];
_converter
.
resample
(
tempBuffer
,
_buffer
,
srate
,
audioSamplingRate
,
nbSamples
);
delete
[]
tempBuffer
;
}
else
{
_buffer
=
tempBuffer
;
}
_size
=
nbSamples
;
_sampleRate
=
audioSamplingRate
;
buffer_
=
new
SFLDataFormat
[
outSamples
];
converter_
.
resample
(
tempBuffer
,
buffer_
,
srate
,
audioSamplingRate
,
nbSamples
);
delete
[]
tempBuffer
;
}
else
buffer_
=
tempBuffer
;
size_
=
nbSamples
;
sampleRate_
=
audioSamplingRate
;
}
daemon/src/audio/sound/tone.cpp
View file @
6aceecc3
...
...
@@ -35,31 +35,26 @@
* YM: 2006-11-15: changes unsigned int to std::string::size_type, thanks to Pierre Pomes (AMD64 compilation)
*/
#include
"tone.h"
#include
<math
.h
>
#include
<
c
math>
#include
<cstdlib>
#include
<cstring>
#define TABLE_LENGTH 4096
double
TWOPI
=
2
*
M_PI
;
static
const
double
TWOPI
=
2.0
*
M_PI
;
Tone
::
Tone
(
const
std
::
string
&
definition
,
unsigned
int
sampleRate
)
:
AudioLoop
(),
_sampleRate
(
sampleRate
),
_xhigher
(
0.0
),
_xlower
(
0.0
)
Tone
::
Tone
(
const
std
::
string
&
definition
,
unsigned
int
sampleRate
)
:
sampleRate_
(
sampleRate
),
xhigher_
(
0.0
),
xlower_
(
0.0
)
{
fillWavetable
();
genBuffer
(
definition
);
// allocate memory with definition parameter
}
Tone
::~
Tone
()
{
genBuffer
(
definition
);
// allocate memory with definition parameter
}
void
Tone
::
genBuffer
(
const
std
::
string
&
definition
)
Tone
::
genBuffer
(
const
std
::
string
&
definition
)
{
if
(
definition
.
empty
())
{
if
(
definition
.
empty
())
return
;