示例#1
0
 SoundFile(const Methcla_Host* host, const std::string& path, const SoundFileInfo& info)
     : m_info(info)
 {
     detail::checkReturnCode(
         methcla_host_soundfile_open(host, path.c_str(), kMethcla_FileModeWrite, &m_file, &m_info)
     );
 }
示例#2
0
static void load_sound_file(const Methcla_Host* host, void* data)
{
//    std::cout << "load_sound_file\n";
    LoadMessage* msg = (LoadMessage*)data;
    assert( msg != nullptr );

    Methcla_SoundFile* file = nullptr;
    Methcla_SoundFileInfo info;
    memset(&info, 0, sizeof(info));

    Methcla_Error err = methcla_host_soundfile_open(host, msg->path, kMethcla_FileModeRead, &file, &info);

    if (err == kMethcla_NoError) {
        msg->numFrames = msg->numFrames < 0 ? info.frames : std::min<int64_t>(msg->numFrames, info.frames);
        msg->numChannels = info.channels;
        msg->buffer = (float*)malloc(msg->numChannels * msg->numFrames * sizeof(float));
        // std::cout << "load_sound_file: " << msg->path << " " << info.channels << " " << info.frames << "\n";
        // TODO: error handling
        if (msg->buffer != nullptr) {
            size_t numFrames;
            err = methcla_soundfile_read_float(file, msg->buffer, msg->numFrames, &numFrames);
        }
        methcla_soundfile_close(file);
    }

    methcla_host_perform_command(host, set_buffer, msg);
}