M src/SimpleWavFileReadStream.cpp +18 -3
@@ 64,9 64,24 @@ SimpleWavFileReadStream::SimpleWavFileRe
m_dataReadOffset(0),
m_dataReadStart(0)
{
- m_file = new std::ifstream(filename.c_str(),
- std::ios::in | std::ios::binary);
-
+#ifdef _MSC_VER
+ // This is behind _MSC_VER not _WIN32 because the fstream
+ // constructors from wchar bufs are an MSVC extension not
+ // available in e.g. MinGW
+ int wlen = MultiByteToWideChar
+ (CP_UTF8, 0, m_path.c_str(), m_path.length(), 0, 0);
+ if (wlen > 0) {
+ wchar_t *buf = new wchar_t[wlen+1];
+ (void)MultiByteToWideChar
+ (CP_UTF8, 0, m_path.c_str(), m_path.length(), buf, wlen);
+ buf[wlen] = L'\0';
+ m_file = new std::ifstream(buf, std::ios::in | std::ios::binary);
+ delete[] buf;
+ }
+#else
+ m_file = new std::ifstream(m_path.c_str(), std::ios::in | std::ios::binary);
+#endif
+
if (!*m_file) {
delete m_file;
m_file = 0;
M src/SimpleWavFileReadStream.h +4 -0
@@ 40,6 40,10 @@
// If we have libsndfile, we shouldn't be using this class
#if ! (defined(HAVE_LIBSNDFILE) || defined(HAVE_SNDFILE))
+#ifdef _MSC_VER
+#include <windows.h>
+#endif
+
#include <fstream>
#include <string>
#include <vector>
M src/SimpleWavFileWriteStream.cpp +21 -3
@@ 63,14 63,32 @@ SimpleWavFileWriteStream::SimpleWavFileW
m_bitDepth(24),
m_file(0)
{
- m_file = new std::ofstream(getPath().c_str(), std::ios::out | std::ios::binary);
+ std::string path = getPath();
+
+#ifdef _MSC_VER
+ // This is behind _MSC_VER not _WIN32 because the fstream
+ // constructors from wchar bufs are an MSVC extension not
+ // available in e.g. MinGW
+ int wlen = MultiByteToWideChar
+ (CP_UTF8, 0, path.c_str(), path.length(), 0, 0);
+ if (wlen > 0) {
+ wchar_t *buf = new wchar_t[wlen+1];
+ (void)MultiByteToWideChar
+ (CP_UTF8, 0, path.c_str(), path.length(), buf, wlen);
+ buf[wlen] = L'\0';
+ m_file = new std::ofstream(buf, std::ios::out | std::ios::binary);
+ delete[] buf;
+ }
+#else
+ m_file = new std::ofstream(path.c_str(), std::ios::out | std::ios::binary);
+#endif
if (!*m_file) {
delete m_file;
m_file = 0;
m_error = std::string("Failed to open audio file '") +
- getPath() + "' for writing";
- throw FailedToWriteFile(getPath());
+ path + "' for writing";
+ throw FailedToWriteFile(path);
}
writeFormatChunk();
M src/SimpleWavFileWriteStream.h +4 -0
@@ 40,6 40,10 @@
// If we have libsndfile, we shouldn't be using this class
#if ! (defined(HAVE_LIBSNDFILE) || defined(HAVE_SNDFILE))
+#ifdef _MSC_VER
+#include <windows.h>
+#endif
+
#include <fstream>
#include <string>