forked from BVLC/caffe
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add libsndfile to project (fix BVLC#16)
- Loading branch information
1 parent
793c840
commit 95203b5
Showing
6 changed files
with
86 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# - Find sndfile | ||
# Find the native sndfile includes and libraries | ||
# | ||
# SNDFILE_INCLUDE_DIR - where to find sndfile.h, etc. | ||
# SNDFILE_LIBRARIES - List of libraries when using libsndfile. | ||
# SNDFILE_FOUND - True if libsndfile found. | ||
|
||
FIND_PATH(SNDFILE_INCLUDE_DIR NAMES sndfile.h PATHS ${CMAKE_SOURCE_DIR}/libs/libsndfile/src/) | ||
|
||
FIND_LIBRARY(SNDFILE_LIBRARY NAMES libsndfile.a PATHS ${CMAKE_SOURCE_DIR}/libs/libsndfile/src/.libs/) | ||
|
||
MESSAGE( STATUS "SNDFILE_INCLUDE_DIR = \"${SNDFILE_INCLUDE_DIR}\"" ) | ||
MESSAGE( STATUS "SNDFILE_LIBRARY = \"${SNDFILE_LIBRARY}\"" ) | ||
|
||
|
||
include(FindPackageHandleStandardArgs) | ||
find_package_handle_standard_args(SNDFILE DEFAULT_MSG | ||
SNDFILE_INCLUDE_DIR SNDFILE_LIBRARY) | ||
|
||
if(SNDFILE_FOUND) | ||
set(SNDFILE_LIBRARIES ${SNDFILE_LIBRARY}) | ||
else(SNDFILE_FOUND) | ||
set(SNDFILE_LIBRARIES) | ||
endif(SNDFILE_FOUND) | ||
|
||
mark_as_advanced(SNDFILE_INCLUDE_DIR SNDFILE_LIBRARY) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
src/caffe/util/read_audio.cpp → src/caffe/util/read_audio_apple.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Created by Aidan Gomez on 2015-08-19. | ||
// Copyright (c) 2015 Venture Media. All rights reserved. | ||
|
||
#include "caffe/util/read_audio.hpp" | ||
#include "caffe/common.hpp" | ||
|
||
#include <sndfile.h> | ||
|
||
namespace caffe { | ||
|
||
int ReadAudioFile(const std::string& filePath, float* data, int capacity, int offset) { | ||
auto info = SF_INFO{}; | ||
|
||
auto file = sf_open(filePath.c_str(), SFM_READ, &info); | ||
CHECK_EQ(sf_error(file), SF_ERR_NO_ERROR); | ||
|
||
auto status = sf_seek(file, offset, SEEK_SET); | ||
CHECK_NE(status, -1) << "Can't seek to offset in: " << filePath; | ||
|
||
auto numberOfFrames = sf_read_float(file, data, capacity); | ||
CHECK_EQ(numberOfFrames, capacity) << "File could not fill provided array"; | ||
|
||
return numberOfFrames; | ||
} | ||
|
||
int ReadAudioFile(const std::string& filePath, double* data, int capacity, int offset) { | ||
auto info = SF_INFO{}; | ||
|
||
auto file = sf_open(filePath.c_str(), SFM_READ, &info); | ||
CHECK_EQ(sf_error(file), SF_ERR_NO_ERROR); | ||
|
||
auto status = sf_seek(file, offset, SEEK_SET); | ||
CHECK_NE(status, -1) << "Can't seek to offset in: " << filePath; | ||
|
||
auto numberOfFrames = sf_read_double(file, data, capacity); | ||
CHECK_EQ(numberOfFrames, capacity) << "File could not fill provided array"; | ||
|
||
return numberOfFrames; | ||
} | ||
|
||
} // namespace caffe |