mirror of
https://github.com/SFML/SFML.git
synced 2025-02-19 06:39:59 +08:00
Fix saving FLAC files to non-ASCII paths
This commit is contained in:
parent
41dc238981
commit
2241bee942
@ -137,14 +137,16 @@ bool SoundFileWriterFlac::open(const std::filesystem::path& filename,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Open file
|
||||||
|
m_file = openFile(filename, "w+b");
|
||||||
|
|
||||||
// Setup the encoder
|
// Setup the encoder
|
||||||
FLAC__stream_encoder_set_channels(m_encoder.get(), channelCount);
|
FLAC__stream_encoder_set_channels(m_encoder.get(), channelCount);
|
||||||
FLAC__stream_encoder_set_bits_per_sample(m_encoder.get(), 16);
|
FLAC__stream_encoder_set_bits_per_sample(m_encoder.get(), 16);
|
||||||
FLAC__stream_encoder_set_sample_rate(m_encoder.get(), sampleRate);
|
FLAC__stream_encoder_set_sample_rate(m_encoder.get(), sampleRate);
|
||||||
|
|
||||||
// Initialize the output stream
|
// Initialize the output stream
|
||||||
if (FLAC__stream_encoder_init_file(m_encoder.get(), filename.string().c_str(), nullptr, nullptr) !=
|
if (FLAC__stream_encoder_init_FILE(m_encoder.get(), m_file, nullptr, nullptr) != FLAC__STREAM_ENCODER_INIT_STATUS_OK)
|
||||||
FLAC__STREAM_ENCODER_INIT_STATUS_OK)
|
|
||||||
{
|
{
|
||||||
err() << "Failed to write flac file (failed to open the file)\n" << formatDebugPathInfo(filename) << std::endl;
|
err() << "Failed to write flac file (failed to open the file)\n" << formatDebugPathInfo(filename) << std::endl;
|
||||||
m_encoder.reset();
|
m_encoder.reset();
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
|
|
||||||
namespace sf::priv
|
namespace sf::priv
|
||||||
@ -90,6 +91,7 @@ private:
|
|||||||
{
|
{
|
||||||
void operator()(FLAC__StreamEncoder* encoder) const;
|
void operator()(FLAC__StreamEncoder* encoder) const;
|
||||||
};
|
};
|
||||||
|
std::FILE* m_file{};
|
||||||
std::unique_ptr<FLAC__StreamEncoder, FlacStreamEncoderDeleter> m_encoder; //!< FLAC stream encoder
|
std::unique_ptr<FLAC__StreamEncoder, FlacStreamEncoderDeleter> m_encoder; //!< FLAC stream encoder
|
||||||
unsigned int m_channelCount{}; //!< Number of channels
|
unsigned int m_channelCount{}; //!< Number of channels
|
||||||
std::array<std::size_t, 8> m_remapTable{}; //!< Table we use to remap source to target channel order
|
std::array<std::size_t, 8> m_remapTable{}; //!< Table we use to remap source to target channel order
|
||||||
|
@ -17,7 +17,7 @@ TEST_CASE("[Audio] sf::OutputSoundFile")
|
|||||||
}
|
}
|
||||||
|
|
||||||
const std::u32string stem = GENERATE(U"tmp", U"tmp-ń", U"tmp-🐌");
|
const std::u32string stem = GENERATE(U"tmp", U"tmp-ń", U"tmp-🐌");
|
||||||
const std::u32string extension = GENERATE(U".wav", U".ogg"); // , U".flac"); FLAC fails to handle Unicode strings
|
const std::u32string extension = GENERATE(U".wav", U".ogg", U".flac");
|
||||||
const auto filename = std::filesystem::temp_directory_path() / std::filesystem::path(stem + extension);
|
const auto filename = std::filesystem::temp_directory_path() / std::filesystem::path(stem + extension);
|
||||||
const std::vector<sf::SoundChannel> channelMap{sf::SoundChannel::FrontLeft, sf::SoundChannel::FrontRight};
|
const std::vector<sf::SoundChannel> channelMap{sf::SoundChannel::FrontLeft, sf::SoundChannel::FrontRight};
|
||||||
|
|
||||||
|
@ -183,12 +183,13 @@ TEST_CASE("[Audio] sf::SoundBuffer", runAudioDeviceTests())
|
|||||||
|
|
||||||
SECTION("saveToFile()")
|
SECTION("saveToFile()")
|
||||||
{
|
{
|
||||||
const auto filename = std::filesystem::temp_directory_path() / "ding.flac";
|
const std::u32string stem = GENERATE(U"tmp", U"tmp-ń", U"tmp-🐌");
|
||||||
|
const std::u32string extension = GENERATE(U".wav", U".ogg", U".flac");
|
||||||
|
const auto filename = std::filesystem::temp_directory_path() / std::filesystem::path(stem + extension);
|
||||||
|
|
||||||
{
|
INFO("Filename: " << reinterpret_cast<const char*>(filename.u8string().c_str()));
|
||||||
const sf::SoundBuffer soundBuffer("Audio/ding.flac");
|
|
||||||
REQUIRE(soundBuffer.saveToFile(filename));
|
REQUIRE(sf::SoundBuffer("Audio/ding.flac").saveToFile(filename));
|
||||||
}
|
|
||||||
|
|
||||||
const sf::SoundBuffer soundBuffer(filename);
|
const sf::SoundBuffer soundBuffer(filename);
|
||||||
CHECK(soundBuffer.getSamples() != nullptr);
|
CHECK(soundBuffer.getSamples() != nullptr);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user