///////////////////////////////////////////////////////
| 93 | |
| 94 | //////////////////////////////////////////////////////////// |
| 95 | bool InputSoundFile::openFromFile(const std::filesystem::path& filename) |
| 96 | { |
| 97 | // If the file is already open, first close it |
| 98 | close(); |
| 99 | |
| 100 | // Find a suitable reader for the file type |
| 101 | auto reader = SoundFileFactory::createReaderFromFilename(filename); |
| 102 | if (!reader) |
| 103 | return false; |
| 104 | |
| 105 | // Wrap the file into a stream |
| 106 | auto file = std::make_unique<FileInputStream>(); |
| 107 | |
| 108 | // Open it |
| 109 | if (!file->open(filename)) |
| 110 | { |
| 111 | err() << "Failed to open input sound file from file (couldn't open file input stream)\n" |
| 112 | << formatDebugPathInfo(filename) << std::endl; |
| 113 | |
| 114 | return false; |
| 115 | } |
| 116 | |
| 117 | // Pass the stream to the reader |
| 118 | const auto info = reader->open(*file); |
| 119 | if (!info) |
| 120 | { |
| 121 | err() << "Failed to open input sound file from file (reader open failure)\n" |
| 122 | << formatDebugPathInfo(filename) << std::endl; |
| 123 | |
| 124 | return false; |
| 125 | } |
| 126 | |
| 127 | // Take ownership of successfully opened reader and stream |
| 128 | m_reader = std::move(reader); |
| 129 | m_stream = std::move(file); |
| 130 | |
| 131 | // Retrieve the attributes of the open sound file |
| 132 | m_sampleCount = info->sampleCount; |
| 133 | m_sampleRate = info->sampleRate; |
| 134 | m_channelMap = info->channelMap; |
| 135 | |
| 136 | return true; |
| 137 | } |
| 138 | |
| 139 | |
| 140 | //////////////////////////////////////////////////////////// |
nothing calls this directly
no test coverage detected