justin = { main feed , music , code , askjf , pubkey };
Ask Justin Frankel
No reasonable question unanswered since 2009!

Suggested topics: programming, music, sleep, coffee, etc.

Note: please do not ask questions about REAPER features, bugs or scheduling, use the forums instead.


Name: Ask: Human (enter yes):
[back to index] | [unreplied] | [replied] | [recent comments] | [all]

Question: What's the best way to incorporate WDL_FileRead to a C written library, like ogg/vorbis? I have a few thoughts on how to but I like neither and I would like to hear your opinion on the subject. Thanks :)
Asked by gio (94.66.33.x) on November 1 2013, 2:47pm
Reply on November 1 2013, 4:06pm (edited at November 8 2013, 2:44pm):
    This is what we do:
    
    static size_t wdlfileread_read(void *ptr, size_t size, size_t nmemb, void *fr)
    {
      WDL_FileRead *_fr=(WDL_FileRead *)fr;
      if (!size||!_fr) return 0;
      size_t v=(size_t) _fr->Read(ptr,size*nmemb);
      return v/size;
    }
    
    static int wdlfileread_seek(void *fr, ogg_int64_t offset, int whence)
    {
      WDL_FileRead *_fr=(WDL_FileRead *)fr;
      if (whence == SEEK_SET) return _fr->SetPosition(offset)?-1:0;
      if (whence == SEEK_END) return _fr->SetPosition(_fr->GetSize()+offset)?-1:0;
      return _fr->SetPosition(_fr->GetPosition()+offset)?-1:0;
    }
    
    static int wdlfileread_close(void *fr) {   delete (WDL_FileRead *)fr;  return fr?0:EOF; }
    static long wdlfileread_tell(void *fr) { return (long)((WDL_FileRead *)fr)->GetPosition(); }
    
    ov_callbacks cb={wdlfileread_read,wdlfileread_seek,wdlfileread_close,wdlfileread_tell};
    

Comment:
    Your Name:   -- Site Owner's Name:  (for human-verification)

    Comment:    

    
  
[back to index] | [unreplied] | [replied] | [recent comments] | [all]
Copyright 2025 Justin Frankel. | RSS