Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-daemon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
jami-daemon
Commits
c756f41e
Commit
c756f41e
authored
14 years ago
by
Alexandre Savard
Browse files
Options
Downloads
Patches
Plain Diff
[#3757] Add wave file open method
parent
fafd327d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
sflphone-common/src/audio/sound/audiofile.cpp
+136
-0
136 additions, 0 deletions
sflphone-common/src/audio/sound/audiofile.cpp
sflphone-common/src/audio/sound/audiofile.h
+70
-0
70 additions, 0 deletions
sflphone-common/src/audio/sound/audiofile.h
with
206 additions
and
0 deletions
sflphone-common/src/audio/sound/audiofile.cpp
+
136
−
0
View file @
c756f41e
...
...
@@ -175,3 +175,139 @@ AudioFile::loadFile (const std::string& filename, AudioCodec* codec , unsigned i
return
true
;
}
WavFile
::
WavFile
()
:
AudioLoop
(),
_filename
(),
_codec
(
NULL
),
_start
(
false
)
{
}
WavFile
::~
WavFile
()
{
}
bool
WavFile
::
loadFile
(
const
std
::
string
&
filename
,
AudioCodec
*
codec
,
unsigned
int
sampleRate
)
{
std
::
fstream
file
;
printf
(
"WavFile: Open %s"
,
filename
.
c_str
());
file
.
open
(
filename
.
c_str
(),
std
::
ios
::
in
|
std
::
ios
::
binary
);
char
riff
[
4
]
=
{};
file
.
read
(
riff
,
4
);
if
(
strncmp
(
"RIFF"
,
riff
,
4
)
!=
0
)
{
_error
(
"WavFile: File is not of RIFF format"
);
return
false
;
}
// Find the "fmt " chunk
char
fmt
[
4
]
=
{};
while
(
strncmp
(
"fmt "
,
fmt
,
4
)
!=
0
)
{
file
.
read
(
fmt
,
4
);
_debug
(
"WavFile: Searching... %s"
,
fmt
);
}
SINT32
chunkSize
;
// fmt chunk size
unsigned
short
formatTag
;
// data compression tag
file
.
read
((
char
*
)
&
chunkSize
,
4
);
// Read fmt chunk size.
file
.
read
((
char
*
)
&
formatTag
,
2
);
_debug
(
"Chunk size: %d
\n
"
,
chunkSize
);
_debug
(
"Format tag: %d
\n
"
,
formatTag
);
if
(
formatTag
!=
1
)
{
// PCM = 1, FLOAT = 3 {
_error
(
"WaveFile: File contains an unsupported data format type"
);
return
false
;
}
// Get number of channels from the header.
SINT16
chan
;
file
.
read
((
char
*
)
&
chan
,
2
);
_channels
=
chan
;
_debug
(
"WavFile: channel %d"
,
_channels
);
// Get file sample rate from the header.
SINT32
srate
;
file
.
read
((
char
*
)
&
srate
,
4
);
_fileRate
=
(
double
)
srate
;
printf
(
"WavFile: srate %d"
,
srate
);
SINT32
avgb
;
file
.
read
((
char
*
)
&
avgb
,
4
);
_debug
(
"WavFile: Average byte %i
\n
"
,
avgb
);
SINT16
blockal
;
file
.
read
((
char
*
)
&
blockal
,
2
);
_debug
(
"WaveFile: block alignment %d"
,
blockal
);
// Determine the data type
_dataType
=
0
;
SINT16
dt
;
file
.
read
((
char
*
)
&
dt
,
2
);
_debug
(
"WaveFile: dt %d"
,
dt
);
if
(
formatTag
==
1
)
{
if
(
dt
==
8
)
_dataType
=
1
;
// SINT8;
else
if
(
dt
==
16
)
_dataType
=
2
;
// SINT16;
else
if
(
dt
==
32
)
_dataType
=
3
;
// SINT32;
}
/*
else if ( formatTag == 3 )
{
if (temp == 32)
dataType_ = FLOAT32;
else if (temp == 64)
dataType_ = FLOAT64;
}
*/
else
{
_debug
(
"WavFile: File's bits per sample is not supported"
);
return
false
;
}
// Find the "data" chunk
char
data
[
4
]
=
{};
while
(
strncmp
(
"data"
,
data
,
4
)
)
{
file
.
read
(
data
,
4
);
_debug
(
"WavFile: Searching data"
);
}
// Get length of data from the header.
SINT32
bytes
;
file
.
read
((
char
*
)
&
bytes
,
4
);
_debug
(
"WavFile: Data size in byte %ld"
,
bytes
);
_fileSize
=
8
*
bytes
/
dt
/
_channels
;
// sample frames
_debug
(
"WavFile: Data size in frames %ld"
,
_fileSize
);
_debug
(
"WavFile: File successfully opened"
);
return
true
;
}
This diff is collapsed.
Click to expand it.
sflphone-common/src/audio/sound/audiofile.h
+
70
−
0
View file @
c756f41e
...
...
@@ -100,4 +100,74 @@ private:
bool
_start
;
};
/**
* @file audiofile.h
* @brief A class to manage wave files
*/
class
WavFile
:
public
AudioLoop
{
public:
/**
* Constructor
*/
WavFile
();
/**
* Destructor
*/
~
WavFile
();
/**
* Load a sound file in memory
* @param filename The absolute path to the file
* @param codec The codec to decode and encode it
* @param sampleRate The sample rate to read it
* @return bool True on success
*/
bool
loadFile
(
const
std
::
string
&
filename
,
AudioCodec
*
codec
,
unsigned
int
sampleRate
=
44100
);
/**
* Start the sound file
*/
void
start
()
{
_start
=
true
;
}
/**
* Stop the sound file
*/
void
stop
()
{
_start
=
false
;
}
/**
* Tells whether or not the file is playing
* @return bool True if yes
* false otherwise
*/
bool
isStarted
()
{
return
_start
;
}
private
:
// Copy Constructor
WavFile
(
const
AudioFile
&
rh
);
// Assignment Operator
WavFile
&
operator
=
(
const
AudioFile
&
rh
);
/** The absolute path to the sound file */
std
::
string
_filename
;
/** Your preferred codec */
AudioCodec
*
_codec
;
/** Start or not */
bool
_start
;
int
_channels
;
int
_fileRate
;
int
_dataType
;
int
_fileSize
;
};
#endif // __AUDIOFILE_H__
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment