Ejemplo n.º 1
0
 size_t read(float* buffer, size_t numFrames)
 {
     ensureInitialized();
     size_t outNumFrames;
     detail::checkReturnCode(methcla_soundfile_read_float(m_file, buffer, numFrames, &outNumFrames));
     return outNumFrames;
 }
Ejemplo n.º 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);
}